-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Api: return users details by groups #8904
Conversation
// Check subadmin has access to this group | ||
if($this->groupManager->isAdmin($user->getUID()) | ||
|| $isSubadminOfGroup) { | ||
$users = $this->groupManager->get($groupId)->getUsers(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you already got the group in 210,
also here the null check is missing.
$user = $this->userSession->getUser(); | ||
|
||
// Check the group exists | ||
if(!$this->groupManager->groupExists($groupId)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest to get the group here and use the check for null to error out.
If you got a group don't check it any further
cac9609
to
0db5c79
Compare
Codecov Report
@@ Coverage Diff @@
## master #8904 +/- ##
===========================================
- Coverage 51.97% 51.87% -0.1%
+ Complexity 25287 25285 -2
===========================================
Files 1601 1602 +1
Lines 94984 94996 +12
Branches 1388 1388
===========================================
- Hits 49366 49283 -83
- Misses 45618 45713 +95
|
0db5c79
to
e92f640
Compare
Ready for review again. |
@@ -42,6 +42,7 @@ | |||
// Users | |||
['root' => '/cloud', 'name' => 'Users#getUsers', 'url' => '/users', 'verb' => 'GET'], | |||
['root' => '/cloud', 'name' => 'Users#getUsersDetails', 'url' => '/users/details', 'verb' => 'GET'], | |||
['root' => '/cloud', 'name' => 'Users#getUsersGroupDetails', 'url' => '/users/{groupId}/details', 'verb' => 'GET'], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The route doesn't really fit the schema of the others. Maybe something like /groups/{groupId}/users
would make more sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I asked myself the same question, and was rather confuse, do we extract tehe users by groups or do we get the users in group :)
Therefore my current choice, especially since the getUsersData function is in the UsersController :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And since /groups/{groupId}/
actually return the users, shouldn't we go for something like /groups/{groupId}/details
? It really lokks like groups-informations related data. I would prefer something like /groups/{groupId}/users/details
but /groups/{groupId}/users
doesn't exists :/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/groups/{groupId}/details
sounds good to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Such url is supposed to return the details of the group, like we have in /groups/details :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had teh same weird feeling on the url,
it doesn't feel right to me, maybe a ?group=<filter>
on the current endpoint is the better option?
$isSubadminOfGroup = false; | ||
$group = $this->groupManager->get($groupId); | ||
if ($group !== null) { | ||
$isSubadminOfGroup = $this->groupManager->getSubAdmin()->isSubAdminofGroup($user, $group); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isSubAdminofGroup -> isSubAdminOfGroup
if ($group !== null) { | ||
$isSubadminOfGroup = $this->groupManager->getSubAdmin()->isSubAdminofGroup($user, $group); | ||
} else { | ||
throw new OCSException('The requested group could not be found', \OCP\API::RESPOND_NOT_FOUND); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
\OCP\API
is deprecated, see OCSNotFoundException
}, $users); | ||
$users = array_slice(array_values($users), $offset, $limit); | ||
} else { | ||
throw new OCSException('User does not have access to specified group', \OCP\API::RESPOND_UNAUTHORISED); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
\OCP\API
is deprecated, see OCSForbiddenException
f428a0b
to
d473653
Compare
Ready for reviews again! :) $.get(OC.linkToOCS('cloud/groups/admin/users',2)+'details').then((response)=>console.log(response))
$.get(OC.linkToOCS('cloud/groups/admin/users',2)+'details?limit=10').then((response)=>console.log(response))
$.get(OC.linkToOCS('cloud/groups/admin/users',2)+'details?limit=2&offset=2').then((response)=>console.log(response)) |
@@ -36,6 +36,8 @@ | |||
['root' => '/cloud', 'name' => 'Groups#getGroups', 'url' => '/groups', 'verb' => 'GET'], | |||
['root' => '/cloud', 'name' => 'Groups#getGroupsDetails', 'url' => '/groups/details', 'verb' => 'GET'], | |||
['root' => '/cloud', 'name' => 'Groups#getGroup', 'url' => '/groups/{groupId}', 'verb' => 'GET'], | |||
['root' => '/cloud', 'name' => 'Groups#getGroupUsers', 'url' => '/groups/{groupId}/users', 'verb' => 'GET'], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fallback to proper url design, above one is deprecated!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add a note about this to #7827? But I guess it's not easily possible to drop this as it is part of the OCS standard 😉
*/ | ||
public function __construct( | ||
string $appName, | ||
IRequest $request, | ||
IGroupManager $groupManager, | ||
IUserSession $userSession, | ||
ILogger $logger) { | ||
ILogger $logger, | ||
UsersController $userController) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead extract the shared logic in a subclass/trait?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nickvergessen what would you suggest to have a clean logic?
use OCP\AppFramework\OCSController; | ||
use OCP\IGroup; | ||
use OCP\IGroupManager; | ||
use OCP\ILogger; | ||
use OCP\IRequest; | ||
use OCP\IUserSession; | ||
use OCP\IUser; | ||
use OCA\Provisioning_API\Controller\UsersController; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should not be needed
$offset = (int)$offset; | ||
} | ||
|
||
public function getGroupsDetails(string $search = '', int $limit = null, int $offset = 0): DataResponse { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
limit is not checked for null anymore?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we use slice to cut our arrays, null will be ignored. :)
array array_slice ( array $array , int $offset [, int $length = NULL [, bool $preserve_keys = FALSE ]] )
https://secure.php.net/manual/en/function.array-slice.php
4b4f4dc
to
9b081c8
Compare
* @throws OCSException | ||
*/ | ||
public function getUserData(string $userId): array { | ||
$currentLoggedInUser = $this->userSession->getUser(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm php storm doesn't know userSession
. I guess you need to declare it in this trait too.
1663ec5
to
5d13464
Compare
Bump, failure unrelated (swift) :) |
* @return DataResponse | ||
* @throws OCSException | ||
* | ||
* @deprecated 14 Use getGroupUsers |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add a note about this to #7827? But I guess it's not easily possible to drop this as it is part of the OCS standard 😉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I thought it was the better way. It's not that bad tough :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added to the changelog in #7827
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested and works 👍
CONFLICTS!!! |
Signed-off-by: John Molakvoæ (skjnldsv) <[email protected]>
Signed-off-by: John Molakvoæ (skjnldsv) <[email protected]>
Signed-off-by: John Molakvoæ (skjnldsv) <[email protected]>
Signed-off-by: John Molakvoæ (skjnldsv) <[email protected]>
Signed-off-by: John Molakvoæ (skjnldsv) <[email protected]>
Signed-off-by: John Molakvoæ (skjnldsv) <[email protected]>
Signed-off-by: Joas Schilling <[email protected]>
Signed-off-by: John Molakvoæ (skjnldsv) <[email protected]>
5d13464
to
eb4d7fb
Compare
Failure unrelated: swift :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets do this!
This allows to get the users detailed data directly by requesting the groupid