Пример #1
0
 /**
  * returns a list of users
  *
  * @return OC_OCS_Result
  */
 public function getUsers()
 {
     $search = !empty($_GET['search']) ? $_GET['search'] : '';
     $limit = !empty($_GET['limit']) ? $_GET['limit'] : null;
     $offset = !empty($_GET['offset']) ? $_GET['offset'] : null;
     // Check if user is logged in
     $user = $this->userSession->getUser();
     if ($user === null) {
         return new OC_OCS_Result(null, \OCP\API::RESPOND_UNAUTHORISED);
     }
     // Admin? Or SubAdmin?
     if ($this->groupManager->isAdmin($user->getUID())) {
         $users = $this->userManager->search($search, $limit, $offset);
     } else {
         if (\OC_SubAdmin::isSubAdmin($user->getUID())) {
             $subAdminOfGroups = \OC_SubAdmin::getSubAdminsGroups($user->getUID());
             if ($offset === null) {
                 $offset = 0;
             }
             $users = [];
             foreach ($subAdminOfGroups as $group) {
                 $users = array_merge($users, $this->groupManager->displayNamesInGroup($group, $search));
             }
             $users = array_slice($users, $offset, $limit);
         } else {
             return new OC_OCS_Result(null, \OCP\API::RESPOND_UNAUTHORISED);
         }
     }
     $users = array_keys($users);
     return new OC_OCS_Result(['users' => $users]);
 }
Пример #2
0
 /**
  * @NoAdminRequired
  *
  * @param int $offset
  * @param int $limit
  * @param string $gid GID to filter for
  * @param string $pattern Pattern to search for in the username
  * @param string $backend Backend to filter for (class-name)
  * @return DataResponse
  *
  * TODO: Tidy up and write unit tests - code is mainly static method calls
  */
 public function index($offset = 0, $limit = 10, $gid = '', $pattern = '', $backend = '')
 {
     // FIXME: The JS sends the group '_everyone' instead of no GID for the "all users" group.
     if ($gid === '_everyone') {
         $gid = '';
     }
     // Remove backends
     if (!empty($backend)) {
         $activeBackends = $this->userManager->getBackends();
         $this->userManager->clearBackends();
         foreach ($activeBackends as $singleActiveBackend) {
             if ($backend === get_class($singleActiveBackend)) {
                 $this->userManager->registerBackend($singleActiveBackend);
                 break;
             }
         }
     }
     $users = [];
     if ($this->isAdmin) {
         if ($gid !== '') {
             $batch = $this->getUsersForUID($this->groupManager->displayNamesInGroup($gid, $pattern, $limit, $offset));
         } else {
             $batch = $this->userManager->search($pattern, $limit, $offset);
         }
         foreach ($batch as $user) {
             $users[] = $this->formatUserForIndex($user);
         }
     } else {
         $subAdminOfGroups = $this->groupManager->getSubAdmin()->getSubAdminsGroups($this->userSession->getUser());
         // New class returns IGroup[] so convert back
         $gids = [];
         foreach ($subAdminOfGroups as $group) {
             $gids[] = $group->getGID();
         }
         $subAdminOfGroups = $gids;
         // Set the $gid parameter to an empty value if the subadmin has no rights to access a specific group
         if ($gid !== '' && !in_array($gid, $subAdminOfGroups)) {
             $gid = '';
         }
         // Batch all groups the user is subadmin of when a group is specified
         $batch = [];
         if ($gid === '') {
             foreach ($subAdminOfGroups as $group) {
                 $groupUsers = $this->groupManager->displayNamesInGroup($group, $pattern, $limit, $offset);
                 foreach ($groupUsers as $uid => $displayName) {
                     $batch[$uid] = $displayName;
                 }
             }
         } else {
             $batch = $this->groupManager->displayNamesInGroup($gid, $pattern, $limit, $offset);
         }
         $batch = $this->getUsersForUID($batch);
         foreach ($batch as $user) {
             // Only add the groups, this user is a subadmin of
             $userGroups = array_values(array_intersect($this->groupManager->getUserGroupIds($user), $subAdminOfGroups));
             $users[] = $this->formatUserForIndex($user, $userGroups);
         }
     }
     return new DataResponse($users);
 }
Пример #3
0
 /**
  * @param string $search
  */
 protected function getUsers($search)
 {
     $this->result['users'] = $this->result['exact']['users'] = $users = [];
     $userGroups = [];
     if ($this->shareWithGroupOnly) {
         // Search in all the groups this user is part of
         $userGroups = $this->groupManager->getUserGroupIds($this->userSession->getUser());
         foreach ($userGroups as $userGroup) {
             $usersTmp = $this->groupManager->displayNamesInGroup($userGroup, $search, $this->limit, $this->offset);
             foreach ($usersTmp as $uid => $userDisplayName) {
                 $users[$uid] = $userDisplayName;
             }
         }
     } else {
         // Search in all users
         $usersTmp = $this->userManager->searchDisplayName($search, $this->limit, $this->offset);
         foreach ($usersTmp as $user) {
             $users[$user->getUID()] = $user->getDisplayName();
         }
     }
     if (!$this->shareeEnumeration || sizeof($users) < $this->limit) {
         $this->reachedEndFor[] = 'users';
     }
     $foundUserById = false;
     foreach ($users as $uid => $userDisplayName) {
         if (strtolower($uid) === $search || strtolower($userDisplayName) === $search) {
             if (strtolower($uid) === $search) {
                 $foundUserById = true;
             }
             $this->result['exact']['users'][] = ['label' => $userDisplayName, 'value' => ['shareType' => Share::SHARE_TYPE_USER, 'shareWith' => $uid]];
         } else {
             $this->result['users'][] = ['label' => $userDisplayName, 'value' => ['shareType' => Share::SHARE_TYPE_USER, 'shareWith' => $uid]];
         }
     }
     if ($this->offset === 0 && !$foundUserById) {
         // On page one we try if the search result has a direct hit on the
         // user id and if so, we add that to the exact match list
         $user = $this->userManager->get($search);
         if ($user instanceof IUser) {
             $addUser = true;
             if ($this->shareWithGroupOnly) {
                 // Only add, if we have a common group
                 $commonGroups = array_intersect($userGroups, $this->groupManager->getUserGroupIds($user));
                 $addUser = !empty($commonGroups);
             }
             if ($addUser) {
                 array_push($this->result['exact']['users'], ['label' => $user->getDisplayName(), 'value' => ['shareType' => Share::SHARE_TYPE_USER, 'shareWith' => $user->getUID()]]);
             }
         }
     }
     if (!$this->shareeEnumeration) {
         $this->result['users'] = [];
     }
 }