Skip to content

Commit

Permalink
Fix user and group listing with users that have an integer user id
Browse files Browse the repository at this point in the history
Signed-off-by: Joas Schilling <coding@schilljs.com>
  • Loading branch information
nickvergessen committed Sep 12, 2018
1 parent 039145c commit f3fba2f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 18 deletions.
3 changes: 2 additions & 1 deletion apps/provisioning_api/lib/Controller/AUserData.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
use OCP\IConfig;
use OCP\IGroupManager;
use OCP\IRequest;
use OCP\IUser;
use OCP\IUserManager;
use OCP\IUserSession;

Expand Down Expand Up @@ -74,7 +75,7 @@ public function __construct(string $appName,
/**
* creates a array with all user data
*
* @param $userId
* @param string $userId
* @return array
* @throws OCSException
*/
Expand Down
17 changes: 8 additions & 9 deletions apps/provisioning_api/lib/Controller/GroupsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,27 +186,26 @@ public function getGroupUsers(string $groupId): DataResponse {
* @throws OCSException
*/
public function getGroupUsersDetails(string $groupId, string $search = '', int $limit = null, int $offset = 0): DataResponse {
$user = $this->userSession->getUser();
$isSubadminOfGroup = false;
$currentUser = $this->userSession->getUser();

// Check the group exists
$group = $this->groupManager->get($groupId);
if ($group !== null) {
$isSubadminOfGroup =$this->groupManager->getSubAdmin()->isSubAdminOfGroup($user, $group);
$isSubadminOfGroup = $this->groupManager->getSubAdmin()->isSubAdminOfGroup($currentUser, $group);
} else {
throw new OCSException('The requested group could not be found', \OCP\API::RESPOND_NOT_FOUND);
}

// Check subadmin has access to this group
if($this->groupManager->isAdmin($user->getUID())
|| $isSubadminOfGroup) {
$users = $this->groupManager->get($groupId)->searchUsers($search, $limit, $offset);
if($this->groupManager->isAdmin($currentUser->getUID()) || $isSubadminOfGroup) {
$users = $group->searchUsers($search, $limit, $offset);

// Extract required number
$users = array_keys($users);
$usersDetails = [];
foreach ($users as $userId) {
$userData = $this->getUserData($userId);
foreach ($users as $user) {
/** @var IUser $user */
$userId = $user->getUID();
$userData = $this->getUserData((string) $user->getUID());
// Do not insert empty entry
if(!empty($userData)) {
$usersDetails[$userId] = $userData;
Expand Down
18 changes: 10 additions & 8 deletions apps/provisioning_api/lib/Controller/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
use OCP\IGroupManager;
use OCP\ILogger;
use OCP\IRequest;
use OCP\IUser;
use OCP\IUserManager;
use OCP\IUserSession;
use OCP\L10N\IFactory;
Expand Down Expand Up @@ -154,30 +155,31 @@ public function getUsers(string $search = '', $limit = null, $offset = 0): DataR
* returns a list of users and their data
*/
public function getUsersDetails(string $search = '', $limit = null, $offset = 0): DataResponse {
$user = $this->userSession->getUser();
$currentUser = $this->userSession->getUser();
$users = [];

// Admin? Or SubAdmin?
$uid = $user->getUID();
$uid = $currentUser->getUID();
$subAdminManager = $this->groupManager->getSubAdmin();
if ($this->groupManager->isAdmin($uid)){
$users = $this->userManager->search($search, $limit, $offset);
} else if ($subAdminManager->isSubAdmin($user)) {
$subAdminOfGroups = $subAdminManager->getSubAdminsGroups($user);
$users = array_keys($users);
} else if ($subAdminManager->isSubAdmin($currentUser)) {
$subAdminOfGroups = $subAdminManager->getSubAdminsGroups($currentUser);
foreach ($subAdminOfGroups as $key => $group) {
$subAdminOfGroups[$key] = $group->getGID();
}

$users = [];
foreach ($subAdminOfGroups as $group) {
$users = array_merge($users, $this->groupManager->displayNamesInGroup($group, $search, $limit, $offset));
$users[] = array_keys($this->groupManager->displayNamesInGroup($group, $search, $limit, $offset));
}
$users = array_merge(...$users);
}

$users = array_keys($users);
$usersDetails = [];
foreach ($users as $key => $userId) {
$userData = $this->getUserData($userId);
foreach ($users as $userId) {
$userData = $this->getUserData((string) $userId);
// Do not insert empty entry
if (!empty($userData)) {
$usersDetails[$userId] = $userData;
Expand Down

0 comments on commit f3fba2f

Please sign in to comment.