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

feat: add ability to sort by last login #45249

Merged
merged 25 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
0ee676c
feat: add ability to sort users by last_login, uid or displayName. on…
yemkareems May 6, 2024
87a8013
feat: cs fix run on the changed files and default order by last_login…
yemkareems May 6, 2024
c8c68c3
fix: sort the user getDisplayNames based on lastLogin. Default sort o…
yemkareems May 8, 2024
33b38c6
fix: cs fix and psalm ci related changes
yemkareems May 8, 2024
76c875a
fix: change orderBy and sort to sortMode and sortOrder. default it to…
yemkareems May 28, 2024
4cb85f7
fix: rebased the branch with master and resolved conflicts
yemkareems Jun 6, 2024
3615b1f
fix: removed csrf check for the recent end point and ran cs fix
yemkareems Jun 26, 2024
dc6e8c9
fix: search and searchDisplayNames reverted to how it was initially a…
yemkareems Jun 26, 2024
695bd04
fix: search and searchDisplayNames reverted to how it was initially a…
yemkareems Jun 26, 2024
5b249df
fix: doc blocks added
yemkareems Jun 26, 2024
c701ef1
fix: since added to doc blocks
yemkareems Jun 26, 2024
afa5136
fix: removed the params related to sortMode and order since it sorts …
yemkareems Jul 2, 2024
4c62f78
fix: removed NoCSRFRequired used for testing locally
yemkareems Jul 2, 2024
cfafbc8
fix: removed references to old disabled users code. refactored query …
yemkareems Jul 4, 2024
ceedfb4
fix: removed default limit of 25. if null is given all users are fetc…
yemkareems Jul 4, 2024
ae95e46
fix: limit and fixLimit removed. negative limit handled in controller…
yemkareems Jul 4, 2024
0e60402
fix: query refactored to support both the search by email and sort by…
yemkareems Jul 4, 2024
3dee8a2
fix: second join and where conditions added only when search param is…
yemkareems Jul 4, 2024
0df1a29
fix: return type doc block added as per psalm
yemkareems Jul 4, 2024
53e3644
fix: return type doc block added as per psalm
yemkareems Jul 4, 2024
357786f
fix: return type doc block added as per psalm
yemkareems Jul 4, 2024
710dc43
fix: doc block corrected
yemkareems Jul 5, 2024
6ac49e5
fix: ran bash build/openapi-checker.sh and commit the result
yemkareems Jul 5, 2024
4eba967
fix: getLastLoggedInUsers moved from AllConfig/IConfig to IUserManage…
yemkareems Jul 8, 2024
68d60fc
fix(OpenAPI): Regenerate
provokateurin Jul 8, 2024
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
1 change: 1 addition & 0 deletions apps/provisioning_api/appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
['root' => '/cloud', 'name' => 'Users#getUsers', 'url' => '/users', 'verb' => 'GET'],
['root' => '/cloud', 'name' => 'Users#getUsersDetails', 'url' => '/users/details', 'verb' => 'GET'],
['root' => '/cloud', 'name' => 'Users#getDisabledUsersDetails', 'url' => '/users/disabled', 'verb' => 'GET'],
['root' => '/cloud', 'name' => 'Users#getLastLoggedInUsers', 'url' => '/users/recent', 'verb' => 'GET'],
['root' => '/cloud', 'name' => 'Users#searchByPhoneNumbers', 'url' => '/users/search/by-phone', 'verb' => 'POST'],
['root' => '/cloud', 'name' => 'Users#addUser', 'url' => '/users', 'verb' => 'POST'],
['root' => '/cloud', 'name' => 'Users#getUser', 'url' => '/users/{userId}', 'verb' => 'GET'],
Expand Down
56 changes: 56 additions & 0 deletions apps/provisioning_api/lib/Controller/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,62 @@ public function getDisabledUsersDetails(string $search = '', ?int $limit = null,
]);
}

/**
* Gets the list of users sorted by lastLogin, from most recent to least recent
*
* @param string $search Text to search for
* @param ?int $limit Limit the amount of users returned
* @param int $offset Offset
* @return DataResponse<Http::STATUS_OK, array{users: array<string, Provisioning_APIUserDetails|array{id: string}>}, array{}>
*
* 200: Users details returned based on last logged in information
*/
public function getLastLoggedInUsers(string $search = '',
?int $limit = null,
int $offset = 0,
): DataResponse {
$currentUser = $this->userSession->getUser();
if ($currentUser === null) {
return new DataResponse(['users' => []]);
}
if ($limit !== null && $limit < 0) {
throw new InvalidArgumentException("Invalid limit value: $limit");
}
if ($offset < 0) {
throw new InvalidArgumentException("Invalid offset value: $offset");
}

$users = [];

// For Admin alone user sorting based on lastLogin. For sub admin and groups this is not supported
$users = $this->userManager->getLastLoggedInUsers($limit, $offset, $search);

$usersDetails = [];
foreach ($users as $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 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 {
// Currently logged-in user does not have permissions to see this user
// only showing its id
$usersDetails[$userId] = ['id' => $userId];
}
}

return new DataResponse([
'users' => $usersDetails
]);
}



/**
* @NoAdminRequired
Expand Down
Loading
Loading