Skip to content

Api: return users details by groups - #8904

Merged
rullzer merged 8 commits into
masterfrom
ocs-api-get-users-details-per-groups
Apr 6, 2018
Merged

Api: return users details by groups#8904
rullzer merged 8 commits into
masterfrom
ocs-api-get-users-details-per-groups

Conversation

@skjnldsv

@skjnldsvskjnldsv commented Mar 20, 2018

Copy link
Copy Markdown
Member

This allows to get the users detailed data directly by requesting the groupid

$.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))

@skjnldsvskjnldsv added this to the Nextcloud 14 milestone Mar 20, 2018
@skjnldsvskjnldsv self-assigned this Mar 20, 2018
@skjnldsvskjnldsv mentioned this pull request Mar 21, 2018
34 tasks
// Check subadmin has access to this group
if($this->groupManager->isAdmin($user->getUID())
|| $isSubadminOfGroup) {
$users = $this->groupManager->get($groupId)->getUsers();

Copy link
Copy Markdown
Member

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)) {

Copy link
Copy Markdown
Member

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

@skjnldsv
skjnldsvforce-pushed the ocs-api-get-users-details-per-groups branch from cac9609 to 0db5c79CompareMarch 22, 2018 14:40
@codecov

codecovBot commented Mar 22, 2018

Copy link
Copy Markdown

Codecov Report

Merging #8904 into master will decrease coverage by 0.09%.
The diff coverage is 58.4%.

@@ 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
Impacted FilesCoverage ΔComplexity Δ
...isioning_api/composer/composer/autoload_static.php0% <ø> (ø)1 <0> (ø)⬇️
apps/provisioning_api/appinfo/routes.php0% <0%> (ø)0 <0> (ø)⬇️
...ioning_api/composer/composer/autoload_classmap.php0% <0%> (ø)0 <0> (ø)⬇️
...rovisioning_api/lib/Controller/UsersController.php75% <100%> (+1.63%)127 <0> (-13)⬇️
...ovisioning_api/lib/Controller/GroupsController.php68.88% <38.63%> (-23.97%)27 <14> (+2)
apps/provisioning_api/lib/Controller/AUserData.php68.11% <68.11%> (ø)12 <12> (?)
lib/private/Files/ObjectStore/Swift.php0% <0%> (-72.42%)9% <0%> (ø)
lib/private/Files/ObjectStore/SwiftFactory.php0% <0%> (-51%)37% <0%> (ø)
apps/files/lib/Controller/ViewController.php77.19% <0%> (-1.15%)18% <0%> (ø)
lib/private/Files/Mount/Manager.php100% <0%> (ø)23% <0%> (-2%)⬇️
... and 6 more

@skjnldsv
skjnldsvforce-pushed the ocs-api-get-users-details-per-groups branch from 0db5c79 to e92f640CompareMarch 22, 2018 14:52
@skjnldsv

Copy link
Copy Markdown
MemberAuthor

Ready for review again.
@nickvergessen

juliusknorr
juliusknorr previously requested changes Mar 22, 2018
// 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'],

Copy link
Copy Markdown
Member

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.

Copy link
Copy Markdown
MemberAuthor

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 :)

@skjnldsvskjnldsvMar 23, 2018

Copy link
Copy Markdown
MemberAuthor

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 :/

Copy link
Copy Markdown
Member

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.

Copy link
Copy Markdown
MemberAuthor

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 :)

Copy link
Copy Markdown
Member

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);

Copy link
Copy Markdown
Member

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);

Copy link
Copy Markdown
Member

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);

Copy link
Copy Markdown
Member

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

@skjnldsv
skjnldsvforce-pushed the ocs-api-get-users-details-per-groups branch 8 times, most recently from f428a0b to d473653CompareMarch 23, 2018 17:02
@skjnldsv

skjnldsv commented Mar 23, 2018

Copy link
Copy Markdown
MemberAuthor

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))

@skjnldsv
skjnldsv dismissed stale reviews from juliusknorr and nickvergessenMarch 23, 2018 17:25

Fixed

['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'],

Copy link
Copy Markdown
MemberAuthor

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!

Copy link
Copy Markdown
Member

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 😉

IUserSession $userSession,
ILogger $logger) {
ILogger $logger,
UsersController $userController) {

Copy link
Copy Markdown
Member

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?

Copy link
Copy Markdown
MemberAuthor

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\IRequest;
use OCP\IUserSession;
use OCP\IUser;
use OCA\Provisioning_API\Controller\UsersController;

Copy link
Copy Markdown
Member

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 {

Copy link
Copy Markdown
Member

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?

Copy link
Copy Markdown
MemberAuthor

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

@skjnldsv
skjnldsvforce-pushed the ocs-api-get-users-details-per-groups branch 2 times, most recently from 4b4f4dc to 9b081c8CompareMarch 27, 2018 07:48
* @throws OCSException
*/
public function getUserData(string $userId): array {
$currentLoggedInUser = $this->userSession->getUser();

Copy link
Copy Markdown
Member

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.

@nickvergessen
nickvergessenforce-pushed the ocs-api-get-users-details-per-groups branch from 1663ec5 to 5d13464CompareMarch 27, 2018 09:07
@skjnldsv

Copy link
Copy Markdown
MemberAuthor

Bump, failure unrelated (swift) :)

* @return DataResponse
* @throws OCSException
*
* @deprecated 14 Use getGroupUsers

Copy link
Copy Markdown
Member

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 😉

Copy link
Copy Markdown
MemberAuthor

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 :)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay 👍

Copy link
Copy Markdown
MemberAuthor

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

@MorrisJobkeMorrisJobke left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested and works 👍

@rullzer

Copy link
Copy Markdown
Member

CONFLICTS!!! ⚠️ 😱 🙀

skjnldsvand others added 8 commits April 5, 2018 17:08
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
Signed-off-by: Joas Schilling <coding@schilljs.com>
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
@skjnldsv
skjnldsvforce-pushed the ocs-api-get-users-details-per-groups branch from 5d13464 to eb4d7fbCompareApril 5, 2018 15:13
@skjnldsv

skjnldsv commented Apr 5, 2018

Copy link
Copy Markdown
MemberAuthor

Failure unrelated: swift :)
@rullzer

@rullzerrullzer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets do this!

@rullzer
rullzer merged commit 4a6e31c into masterApr 6, 2018
@rullzer
rullzer deleted the ocs-api-get-users-details-per-groups branch April 6, 2018 08:52
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

@skjnldsv@rullzer@nickvergessen@MorrisJobke@juliusknorr