Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(provisioning_api): Show warning but do not fail when listing accounts in case of users removed from backend but still in database #44982

Merged
merged 1 commit into from
Apr 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions apps/provisioning_api/lib/Controller/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\OCS\OCSException;
use OCP\AppFramework\OCS\OCSForbiddenException;
use OCP\AppFramework\OCS\OCSNotFoundException;
use OCP\AppFramework\OCSController;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\HintException;
Expand Down Expand Up @@ -196,7 +197,14 @@ public function getUsersDetails(string $search = '', ?int $limit = null, int $of
$usersDetails = [];
foreach ($users as $userId) {
$userId = (string) $userId;
$userData = $this->getUserData($userId);
try {
$userData = $this->getUserData($userId);
} catch (OCSNotFoundException $e) {
// We still want to return all other accounts, but this one was removed from the backends
// yet they are still in our database. Might be a LDAP remnant.
$userData = null;
$this->logger->warning('Found one enabled account that is removed from its backend, but still exists in Nextcloud database', ['accountId' => $userId]);
}
// Do not insert empty entry
if ($userData !== null) {
$usersDetails[$userId] = $userData;
Expand Down Expand Up @@ -269,12 +277,19 @@ public function getDisabledUsersDetails(?int $limit = null, int $offset = 0): Da

$usersDetails = [];
foreach ($users as $userId) {
$userData = $this->getUserData($userId);
try {
$userData = $this->getUserData($userId);
} catch (OCSNotFoundException $e) {
// We still want to return all other accounts, but this one was removed from the backends
// yet they are still in our database. Might be a LDAP remnant.
$userData = null;
$this->logger->warning('Found one disabled account that was removed from its backend, but still exists in Nextcloud database', ['accountId' => $userId]);
}
// Do not insert empty entry
if ($userData !== null) {
$usersDetails[$userId] = $userData;
} else {
// Logged user does not have permissions to see this user
// Currently logged in user does not have permissions to see this user
// only showing its id
$usersDetails[$userId] = ['id' => $userId];
}
Expand Down
Loading