| @@ -39,172 +39,172 @@ | ||
| 39 | 39 | |
| 40 | 40 |  abstract class AUserData extends OCSController { | 
| 41 | 41 | |
| 42 | - /** @var IUserManager */ | |
| 43 | - protected $userManager; | |
| 44 | - /** @var IConfig */ | |
| 45 | - protected $config; | |
| 46 | - /** @var IGroupManager|\OC\Group\Manager */ // FIXME Requires a method that is not on the interface | |
| 47 | - protected $groupManager; | |
| 48 | - /** @var IUserSession */ | |
| 49 | - protected $userSession; | |
| 50 | - /** @var AccountManager */ | |
| 51 | - protected $accountManager; | |
| 52 | - | |
| 53 | - /** | |
| 54 | - * @param string $appName | |
| 55 | - * @param IRequest $request | |
| 56 | - * @param IUserManager $userManager | |
| 57 | - * @param IConfig $config | |
| 58 | - * @param IGroupManager $groupManager | |
| 59 | - * @param IUserSession $userSession | |
| 60 | - * @param AccountManager $accountManager | |
| 61 | - */ | |
| 62 | - public function __construct(string $appName, | |
| 63 | - IRequest $request, | |
| 64 | - IUserManager $userManager, | |
| 65 | - IConfig $config, | |
| 66 | - IGroupManager $groupManager, | |
| 67 | - IUserSession $userSession, | |
| 68 | -								AccountManager $accountManager) { | |
| 69 | - parent::__construct($appName, $request); | |
| 70 | - | |
| 71 | - $this->userManager = $userManager; | |
| 72 | - $this->config = $config; | |
| 73 | - $this->groupManager = $groupManager; | |
| 74 | - $this->userSession = $userSession; | |
| 75 | - $this->accountManager = $accountManager; | |
| 76 | - } | |
| 77 | - | |
| 78 | - /** | |
| 79 | - * creates a array with all user data | |
| 80 | - * | |
| 81 | - * @param string $userId | |
| 82 | - * @return array | |
| 83 | - * @throws NotFoundException | |
| 84 | - * @throws OCSException | |
| 85 | - * @throws OCSNotFoundException | |
| 86 | - */ | |
| 87 | -	protected function getUserData(string $userId): array { | |
| 88 | - $currentLoggedInUser = $this->userSession->getUser(); | |
| 89 | - | |
| 90 | - $data = []; | |
| 91 | - | |
| 92 | - // Check if the target user exists | |
| 93 | - $targetUserObject = $this->userManager->get($userId); | |
| 94 | -		if($targetUserObject === null) { | |
| 95 | -			throw new OCSNotFoundException('User does not exist'); | |
| 96 | - } | |
| 97 | - | |
| 98 | - // Should be at least Admin Or SubAdmin! | |
| 99 | - if ($this->groupManager->isAdmin($currentLoggedInUser->getUID()) | |
| 100 | -			|| $this->groupManager->getSubAdmin()->isUserAccessible($currentLoggedInUser, $targetUserObject)) { | |
| 101 | - $data['enabled'] = $this->config->getUserValue($targetUserObject->getUID(), 'core', 'enabled', 'true') === 'true'; | |
| 102 | -		} else { | |
| 103 | - // Check they are looking up themselves | |
| 104 | -			if ($currentLoggedInUser->getUID() !== $targetUserObject->getUID()) { | |
| 105 | - return $data; | |
| 106 | - } | |
| 107 | - } | |
| 108 | - | |
| 109 | - // Get groups data | |
| 110 | - $userAccount = $this->accountManager->getUser($targetUserObject); | |
| 111 | - $groups = $this->groupManager->getUserGroups($targetUserObject); | |
| 112 | - $gids = []; | |
| 113 | -		foreach ($groups as $group) { | |
| 114 | - $gids[] = $group->getGID(); | |
| 115 | - } | |
| 116 | - | |
| 117 | -		try { | |
| 118 | - # might be thrown by LDAP due to handling of users disappears | |
| 119 | - # from the external source (reasons unknown to us) | |
| 120 | - # cf. https://github.com/nextcloud/server/issues/12991 | |
| 121 | - $data['storageLocation'] = $targetUserObject->getHome(); | |
| 122 | -		} catch (NoUserException $e) { | |
| 123 | - throw new OCSNotFoundException($e->getMessage(), $e); | |
| 124 | - } | |
| 125 | - | |
| 126 | - // Find the data | |
| 127 | - $data['id'] = $targetUserObject->getUID(); | |
| 128 | - $data['lastLogin'] = $targetUserObject->getLastLogin() * 1000; | |
| 129 | - $data['backend'] = $targetUserObject->getBackendClassName(); | |
| 130 | - $data['subadmin'] = $this->getUserSubAdminGroupsData($targetUserObject->getUID()); | |
| 131 | - $data['quota'] = $this->fillStorageInfo($targetUserObject->getUID()); | |
| 132 | - $data[AccountManager::PROPERTY_EMAIL] = $targetUserObject->getEMailAddress(); | |
| 133 | - $data[AccountManager::PROPERTY_DISPLAYNAME] = $targetUserObject->getDisplayName(); | |
| 134 | - $data[AccountManager::PROPERTY_PHONE] = $userAccount[AccountManager::PROPERTY_PHONE]['value']; | |
| 135 | - $data[AccountManager::PROPERTY_ADDRESS] = $userAccount[AccountManager::PROPERTY_ADDRESS]['value']; | |
| 136 | - $data[AccountManager::PROPERTY_WEBSITE] = $userAccount[AccountManager::PROPERTY_WEBSITE]['value']; | |
| 137 | - $data[AccountManager::PROPERTY_TWITTER] = $userAccount[AccountManager::PROPERTY_TWITTER]['value']; | |
| 138 | - $data['groups'] = $gids; | |
| 139 | - $data['language'] = $this->config->getUserValue($targetUserObject->getUID(), 'core', 'lang'); | |
| 140 | - $data['locale'] = $this->config->getUserValue($targetUserObject->getUID(), 'core', 'locale'); | |
| 141 | - | |
| 142 | - $backend = $targetUserObject->getBackend(); | |
| 143 | - $data['backendCapabilities'] = [ | |
| 144 | - 'setDisplayName' => $backend instanceof ISetDisplayNameBackend || $backend->implementsActions(Backend::SET_DISPLAYNAME), | |
| 145 | - 'setPassword' => $backend instanceof ISetPasswordBackend || $backend->implementsActions(Backend::SET_PASSWORD), | |
| 146 | - ]; | |
| 147 | - | |
| 148 | - return $data; | |
| 42 | + /** @var IUserManager */ | |
| 43 | + protected $userManager; | |
| 44 | + /** @var IConfig */ | |
| 45 | + protected $config; | |
| 46 | + /** @var IGroupManager|\OC\Group\Manager */ // FIXME Requires a method that is not on the interface | |
| 47 | + protected $groupManager; | |
| 48 | + /** @var IUserSession */ | |
| 49 | + protected $userSession; | |
| 50 | + /** @var AccountManager */ | |
| 51 | + protected $accountManager; | |
| 52 | + | |
| 53 | + /** | |
| 54 | + * @param string $appName | |
| 55 | + * @param IRequest $request | |
| 56 | + * @param IUserManager $userManager | |
| 57 | + * @param IConfig $config | |
| 58 | + * @param IGroupManager $groupManager | |
| 59 | + * @param IUserSession $userSession | |
| 60 | + * @param AccountManager $accountManager | |
| 61 | + */ | |
| 62 | + public function __construct(string $appName, | |
| 63 | + IRequest $request, | |
| 64 | + IUserManager $userManager, | |
| 65 | + IConfig $config, | |
| 66 | + IGroupManager $groupManager, | |
| 67 | + IUserSession $userSession, | |
| 68 | +                                AccountManager $accountManager) { | |
| 69 | + parent::__construct($appName, $request); | |
| 70 | + | |
| 71 | + $this->userManager = $userManager; | |
| 72 | + $this->config = $config; | |
| 73 | + $this->groupManager = $groupManager; | |
| 74 | + $this->userSession = $userSession; | |
| 75 | + $this->accountManager = $accountManager; | |
| 149 | 76 | } | 
| 150 | 77 | |
| 151 | - /** | |
| 152 | - * Get the groups a user is a subadmin of | |
| 153 | - * | |
| 154 | - * @param string $userId | |
| 155 | - * @return array | |
| 156 | - * @throws OCSException | |
| 157 | - */ | |
| 158 | -	protected function getUserSubAdminGroupsData(string $userId): array { | |
| 159 | - $user = $this->userManager->get($userId); | |
| 160 | - // Check if the user exists | |
| 161 | -		if($user === null) { | |
| 162 | -			throw new OCSNotFoundException('User does not exist'); | |
| 163 | - } | |
| 164 | - | |
| 165 | - // Get the subadmin groups | |
| 166 | - $subAdminGroups = $this->groupManager->getSubAdmin()->getSubAdminsGroups($user); | |
| 167 | - $groups = []; | |
| 168 | -		foreach ($subAdminGroups as $key => $group) { | |
| 169 | - $groups[] = $group->getGID(); | |
| 170 | - } | |
| 171 | - | |
| 172 | - return $groups; | |
| 173 | - } | |
| 174 | - | |
| 175 | - /** | |
| 176 | - * @param string $userId | |
| 177 | - * @return array | |
| 178 | - * @throws \OCP\Files\NotFoundException | |
| 179 | - */ | |
| 180 | -	protected function fillStorageInfo(string $userId): array { | |
| 181 | -		try { | |
| 182 | - \OC_Util::tearDownFS(); | |
| 183 | - \OC_Util::setupFS($userId); | |
| 184 | -			$storage = OC_Helper::getStorageInfo('/'); | |
| 185 | - $data = [ | |
| 186 | - 'free' => $storage['free'], | |
| 187 | - 'used' => $storage['used'], | |
| 188 | - 'total' => $storage['total'], | |
| 189 | - 'relative' => $storage['relative'], | |
| 190 | - 'quota' => $storage['quota'], | |
| 191 | - ]; | |
| 192 | -		} catch (NotFoundException $ex) { | |
| 193 | - // User fs is not setup yet | |
| 194 | - $user = $this->userManager->get($userId); | |
| 195 | -			if ($user === null) { | |
| 196 | -				throw new OCSException('User does not exist', 101); | |
| 197 | - } | |
| 198 | - $quota = $user->getQuota(); | |
| 199 | -			if ($quota !== 'none') { | |
| 200 | - $quota = OC_Helper::computerFileSize($quota); | |
| 201 | - } | |
| 202 | - $data = [ | |
| 203 | - 'quota' => $quota !== false ? $quota : 'none', | |
| 204 | - 'used' => 0 | |
| 205 | - ]; | |
| 206 | - } | |
| 207 | - return $data; | |
| 208 | - } | |
| 78 | + /** | |
| 79 | + * creates a array with all user data | |
| 80 | + * | |
| 81 | + * @param string $userId | |
| 82 | + * @return array | |
| 83 | + * @throws NotFoundException | |
| 84 | + * @throws OCSException | |
| 85 | + * @throws OCSNotFoundException | |
| 86 | + */ | |
| 87 | +    protected function getUserData(string $userId): array { | |
| 88 | + $currentLoggedInUser = $this->userSession->getUser(); | |
| 89 | + | |
| 90 | + $data = []; | |
| 91 | + | |
| 92 | + // Check if the target user exists | |
| 93 | + $targetUserObject = $this->userManager->get($userId); | |
| 94 | +        if($targetUserObject === null) { | |
| 95 | +            throw new OCSNotFoundException('User does not exist'); | |
| 96 | + } | |
| 97 | + | |
| 98 | + // Should be at least Admin Or SubAdmin! | |
| 99 | + if ($this->groupManager->isAdmin($currentLoggedInUser->getUID()) | |
| 100 | +            || $this->groupManager->getSubAdmin()->isUserAccessible($currentLoggedInUser, $targetUserObject)) { | |
| 101 | + $data['enabled'] = $this->config->getUserValue($targetUserObject->getUID(), 'core', 'enabled', 'true') === 'true'; | |
| 102 | +        } else { | |
| 103 | + // Check they are looking up themselves | |
| 104 | +            if ($currentLoggedInUser->getUID() !== $targetUserObject->getUID()) { | |
| 105 | + return $data; | |
| 106 | + } | |
| 107 | + } | |
| 108 | + | |
| 109 | + // Get groups data | |
| 110 | + $userAccount = $this->accountManager->getUser($targetUserObject); | |
| 111 | + $groups = $this->groupManager->getUserGroups($targetUserObject); | |
| 112 | + $gids = []; | |
| 113 | +        foreach ($groups as $group) { | |
| 114 | + $gids[] = $group->getGID(); | |
| 115 | + } | |
| 116 | + | |
| 117 | +        try { | |
| 118 | + # might be thrown by LDAP due to handling of users disappears | |
| 119 | + # from the external source (reasons unknown to us) | |
| 120 | + # cf. https://github.com/nextcloud/server/issues/12991 | |
| 121 | + $data['storageLocation'] = $targetUserObject->getHome(); | |
| 122 | +        } catch (NoUserException $e) { | |
| 123 | + throw new OCSNotFoundException($e->getMessage(), $e); | |
| 124 | + } | |
| 125 | + | |
| 126 | + // Find the data | |
| 127 | + $data['id'] = $targetUserObject->getUID(); | |
| 128 | + $data['lastLogin'] = $targetUserObject->getLastLogin() * 1000; | |
| 129 | + $data['backend'] = $targetUserObject->getBackendClassName(); | |
| 130 | + $data['subadmin'] = $this->getUserSubAdminGroupsData($targetUserObject->getUID()); | |
| 131 | + $data['quota'] = $this->fillStorageInfo($targetUserObject->getUID()); | |
| 132 | + $data[AccountManager::PROPERTY_EMAIL] = $targetUserObject->getEMailAddress(); | |
| 133 | + $data[AccountManager::PROPERTY_DISPLAYNAME] = $targetUserObject->getDisplayName(); | |
| 134 | + $data[AccountManager::PROPERTY_PHONE] = $userAccount[AccountManager::PROPERTY_PHONE]['value']; | |
| 135 | + $data[AccountManager::PROPERTY_ADDRESS] = $userAccount[AccountManager::PROPERTY_ADDRESS]['value']; | |
| 136 | + $data[AccountManager::PROPERTY_WEBSITE] = $userAccount[AccountManager::PROPERTY_WEBSITE]['value']; | |
| 137 | + $data[AccountManager::PROPERTY_TWITTER] = $userAccount[AccountManager::PROPERTY_TWITTER]['value']; | |
| 138 | + $data['groups'] = $gids; | |
| 139 | + $data['language'] = $this->config->getUserValue($targetUserObject->getUID(), 'core', 'lang'); | |
| 140 | + $data['locale'] = $this->config->getUserValue($targetUserObject->getUID(), 'core', 'locale'); | |
| 141 | + | |
| 142 | + $backend = $targetUserObject->getBackend(); | |
| 143 | + $data['backendCapabilities'] = [ | |
| 144 | + 'setDisplayName' => $backend instanceof ISetDisplayNameBackend || $backend->implementsActions(Backend::SET_DISPLAYNAME), | |
| 145 | + 'setPassword' => $backend instanceof ISetPasswordBackend || $backend->implementsActions(Backend::SET_PASSWORD), | |
| 146 | + ]; | |
| 147 | + | |
| 148 | + return $data; | |
| 149 | + } | |
| 150 | + | |
| 151 | + /** | |
| 152 | + * Get the groups a user is a subadmin of | |
| 153 | + * | |
| 154 | + * @param string $userId | |
| 155 | + * @return array | |
| 156 | + * @throws OCSException | |
| 157 | + */ | |
| 158 | +    protected function getUserSubAdminGroupsData(string $userId): array { | |
| 159 | + $user = $this->userManager->get($userId); | |
| 160 | + // Check if the user exists | |
| 161 | +        if($user === null) { | |
| 162 | +            throw new OCSNotFoundException('User does not exist'); | |
| 163 | + } | |
| 164 | + | |
| 165 | + // Get the subadmin groups | |
| 166 | + $subAdminGroups = $this->groupManager->getSubAdmin()->getSubAdminsGroups($user); | |
| 167 | + $groups = []; | |
| 168 | +        foreach ($subAdminGroups as $key => $group) { | |
| 169 | + $groups[] = $group->getGID(); | |
| 170 | + } | |
| 171 | + | |
| 172 | + return $groups; | |
| 173 | + } | |
| 174 | + | |
| 175 | + /** | |
| 176 | + * @param string $userId | |
| 177 | + * @return array | |
| 178 | + * @throws \OCP\Files\NotFoundException | |
| 179 | + */ | |
| 180 | +    protected function fillStorageInfo(string $userId): array { | |
| 181 | +        try { | |
| 182 | + \OC_Util::tearDownFS(); | |
| 183 | + \OC_Util::setupFS($userId); | |
| 184 | +            $storage = OC_Helper::getStorageInfo('/'); | |
| 185 | + $data = [ | |
| 186 | + 'free' => $storage['free'], | |
| 187 | + 'used' => $storage['used'], | |
| 188 | + 'total' => $storage['total'], | |
| 189 | + 'relative' => $storage['relative'], | |
| 190 | + 'quota' => $storage['quota'], | |
| 191 | + ]; | |
| 192 | +        } catch (NotFoundException $ex) { | |
| 193 | + // User fs is not setup yet | |
| 194 | + $user = $this->userManager->get($userId); | |
| 195 | +            if ($user === null) { | |
| 196 | +                throw new OCSException('User does not exist', 101); | |
| 197 | + } | |
| 198 | + $quota = $user->getQuota(); | |
| 199 | +            if ($quota !== 'none') { | |
| 200 | + $quota = OC_Helper::computerFileSize($quota); | |
| 201 | + } | |
| 202 | + $data = [ | |
| 203 | + 'quota' => $quota !== false ? $quota : 'none', | |
| 204 | + 'used' => 0 | |
| 205 | + ]; | |
| 206 | + } | |
| 207 | + return $data; | |
| 208 | + } | |
| 209 | 209 | |
| 210 | 210 | } | 
| @@ -44,250 +44,250 @@ | ||
| 44 | 44 | |
| 45 | 45 |  class GroupsController extends AUserData { | 
| 46 | 46 | |
| 47 | - /** @var ILogger */ | |
| 48 | - private $logger; | |
| 47 | + /** @var ILogger */ | |
| 48 | + private $logger; | |
| 49 | 49 | |
| 50 | - /** | |
| 51 | - * @param string $appName | |
| 52 | - * @param IRequest $request | |
| 53 | - * @param IUserManager $userManager | |
| 54 | - * @param IConfig $config | |
| 55 | - * @param IGroupManager $groupManager | |
| 56 | - * @param IUserSession $userSession | |
| 57 | - * @param AccountManager $accountManager | |
| 58 | - * @param ILogger $logger | |
| 59 | - * @param UsersController $userController | |
| 60 | - */ | |
| 61 | - public function __construct(string $appName, | |
| 62 | - IRequest $request, | |
| 63 | - IUserManager $userManager, | |
| 64 | - IConfig $config, | |
| 65 | - IGroupManager $groupManager, | |
| 66 | - IUserSession $userSession, | |
| 67 | - AccountManager $accountManager, | |
| 68 | -								ILogger $logger) { | |
| 69 | - parent::__construct($appName, | |
| 70 | - $request, | |
| 71 | - $userManager, | |
| 72 | - $config, | |
| 73 | - $groupManager, | |
| 74 | - $userSession, | |
| 75 | - $accountManager); | |
| 50 | + /** | |
| 51 | + * @param string $appName | |
| 52 | + * @param IRequest $request | |
| 53 | + * @param IUserManager $userManager | |
| 54 | + * @param IConfig $config | |
| 55 | + * @param IGroupManager $groupManager | |
| 56 | + * @param IUserSession $userSession | |
| 57 | + * @param AccountManager $accountManager | |
| 58 | + * @param ILogger $logger | |
| 59 | + * @param UsersController $userController | |
| 60 | + */ | |
| 61 | + public function __construct(string $appName, | |
| 62 | + IRequest $request, | |
| 63 | + IUserManager $userManager, | |
| 64 | + IConfig $config, | |
| 65 | + IGroupManager $groupManager, | |
| 66 | + IUserSession $userSession, | |
| 67 | + AccountManager $accountManager, | |
| 68 | +                                ILogger $logger) { | |
| 69 | + parent::__construct($appName, | |
| 70 | + $request, | |
| 71 | + $userManager, | |
| 72 | + $config, | |
| 73 | + $groupManager, | |
| 74 | + $userSession, | |
| 75 | + $accountManager); | |
| 76 | 76 | |
| 77 | - $this->logger = $logger; | |
| 78 | - } | |
| 77 | + $this->logger = $logger; | |
| 78 | + } | |
| 79 | 79 | |
| 80 | - /** | |
| 81 | - * returns a list of groups | |
| 82 | - * | |
| 83 | - * @NoAdminRequired | |
| 84 | - * | |
| 85 | - * @param string $search | |
| 86 | - * @param int $limit | |
| 87 | - * @param int $offset | |
| 88 | - * @return DataResponse | |
| 89 | - */ | |
| 90 | -	public function getGroups(string $search = '', int $limit = null, int $offset = 0): DataResponse { | |
| 91 | - $groups = $this->groupManager->search($search, $limit, $offset); | |
| 92 | -		$groups = array_map(function($group) { | |
| 93 | - /** @var IGroup $group */ | |
| 94 | - return $group->getGID(); | |
| 95 | - }, $groups); | |
| 80 | + /** | |
| 81 | + * returns a list of groups | |
| 82 | + * | |
| 83 | + * @NoAdminRequired | |
| 84 | + * | |
| 85 | + * @param string $search | |
| 86 | + * @param int $limit | |
| 87 | + * @param int $offset | |
| 88 | + * @return DataResponse | |
| 89 | + */ | |
| 90 | +    public function getGroups(string $search = '', int $limit = null, int $offset = 0): DataResponse { | |
| 91 | + $groups = $this->groupManager->search($search, $limit, $offset); | |
| 92 | +        $groups = array_map(function($group) { | |
| 93 | + /** @var IGroup $group */ | |
| 94 | + return $group->getGID(); | |
| 95 | + }, $groups); | |
| 96 | 96 | |
| 97 | - return new DataResponse(['groups' => $groups]); | |
| 98 | - } | |
| 97 | + return new DataResponse(['groups' => $groups]); | |
| 98 | + } | |
| 99 | 99 | |
| 100 | - /** | |
| 101 | - * returns a list of groups details with ids and displaynames | |
| 102 | - * | |
| 103 | - * @NoAdminRequired | |
| 104 | - * | |
| 105 | - * @param string $search | |
| 106 | - * @param int $limit | |
| 107 | - * @param int $offset | |
| 108 | - * @return DataResponse | |
| 109 | - */ | |
| 110 | -	public function getGroupsDetails(string $search = '', int $limit = null, int $offset = 0): DataResponse { | |
| 111 | - $groups = $this->groupManager->search($search, $limit, $offset); | |
| 112 | -		$groups = array_map(function($group) { | |
| 113 | - /** @var IGroup $group */ | |
| 114 | - return [ | |
| 115 | - 'id' => $group->getGID(), | |
| 116 | - 'displayname' => $group->getDisplayName(), | |
| 117 | - 'usercount' => $group->count(), | |
| 118 | - 'disabled' => $group->countDisabled(), | |
| 119 | - 'canAdd' => $group->canAddUser(), | |
| 120 | - 'canRemove' => $group->canRemoveUser(), | |
| 121 | - ]; | |
| 122 | - }, $groups); | |
| 100 | + /** | |
| 101 | + * returns a list of groups details with ids and displaynames | |
| 102 | + * | |
| 103 | + * @NoAdminRequired | |
| 104 | + * | |
| 105 | + * @param string $search | |
| 106 | + * @param int $limit | |
| 107 | + * @param int $offset | |
| 108 | + * @return DataResponse | |
| 109 | + */ | |
| 110 | +    public function getGroupsDetails(string $search = '', int $limit = null, int $offset = 0): DataResponse { | |
| 111 | + $groups = $this->groupManager->search($search, $limit, $offset); | |
| 112 | +        $groups = array_map(function($group) { | |
| 113 | + /** @var IGroup $group */ | |
| 114 | + return [ | |
| 115 | + 'id' => $group->getGID(), | |
| 116 | + 'displayname' => $group->getDisplayName(), | |
| 117 | + 'usercount' => $group->count(), | |
| 118 | + 'disabled' => $group->countDisabled(), | |
| 119 | + 'canAdd' => $group->canAddUser(), | |
| 120 | + 'canRemove' => $group->canRemoveUser(), | |
| 121 | + ]; | |
| 122 | + }, $groups); | |
| 123 | 123 | |
| 124 | - return new DataResponse(['groups' => $groups]); | |
| 125 | - } | |
| 124 | + return new DataResponse(['groups' => $groups]); | |
| 125 | + } | |
| 126 | 126 | |
| 127 | - /** | |
| 128 | - * @NoAdminRequired | |
| 129 | - * | |
| 130 | - * @param string $groupId | |
| 131 | - * @return DataResponse | |
| 132 | - * @throws OCSException | |
| 133 | - * | |
| 134 | - * @deprecated 14 Use getGroupUsers | |
| 135 | - */ | |
| 136 | -	public function getGroup(string $groupId): DataResponse { | |
| 137 | - return $this->getGroupUsers($groupId); | |
| 138 | - } | |
| 127 | + /** | |
| 128 | + * @NoAdminRequired | |
| 129 | + * | |
| 130 | + * @param string $groupId | |
| 131 | + * @return DataResponse | |
| 132 | + * @throws OCSException | |
| 133 | + * | |
| 134 | + * @deprecated 14 Use getGroupUsers | |
| 135 | + */ | |
| 136 | +    public function getGroup(string $groupId): DataResponse { | |
| 137 | + return $this->getGroupUsers($groupId); | |
| 138 | + } | |
| 139 | 139 | |
| 140 | - /** | |
| 141 | - * returns an array of users in the specified group | |
| 142 | - * | |
| 143 | - * @NoAdminRequired | |
| 144 | - * | |
| 145 | - * @param string $groupId | |
| 146 | - * @return DataResponse | |
| 147 | - * @throws OCSException | |
| 148 | - */ | |
| 149 | -	public function getGroupUsers(string $groupId): DataResponse { | |
| 150 | - $user = $this->userSession->getUser(); | |
| 151 | - $isSubadminOfGroup = false; | |
| 140 | + /** | |
| 141 | + * returns an array of users in the specified group | |
| 142 | + * | |
| 143 | + * @NoAdminRequired | |
| 144 | + * | |
| 145 | + * @param string $groupId | |
| 146 | + * @return DataResponse | |
| 147 | + * @throws OCSException | |
| 148 | + */ | |
| 149 | +    public function getGroupUsers(string $groupId): DataResponse { | |
| 150 | + $user = $this->userSession->getUser(); | |
| 151 | + $isSubadminOfGroup = false; | |
| 152 | 152 | |
| 153 | - // Check the group exists | |
| 154 | - $group = $this->groupManager->get($groupId); | |
| 155 | -		if ($group !== null) { | |
| 156 | - $isSubadminOfGroup =$this->groupManager->getSubAdmin()->isSubAdminOfGroup($user, $group); | |
| 157 | -		} else { | |
| 158 | -			throw new OCSNotFoundException('The requested group could not be found'); | |
| 159 | - } | |
| 153 | + // Check the group exists | |
| 154 | + $group = $this->groupManager->get($groupId); | |
| 155 | +        if ($group !== null) { | |
| 156 | + $isSubadminOfGroup =$this->groupManager->getSubAdmin()->isSubAdminOfGroup($user, $group); | |
| 157 | +        } else { | |
| 158 | +            throw new OCSNotFoundException('The requested group could not be found'); | |
| 159 | + } | |
| 160 | 160 | |
| 161 | - // Check subadmin has access to this group | |
| 162 | - if($this->groupManager->isAdmin($user->getUID()) | |
| 163 | -		   || $isSubadminOfGroup) { | |
| 164 | - $users = $this->groupManager->get($groupId)->getUsers(); | |
| 165 | -			$users =  array_map(function($user) { | |
| 166 | - /** @var IUser $user */ | |
| 167 | - return $user->getUID(); | |
| 168 | - }, $users); | |
| 169 | - $users = array_values($users); | |
| 170 | - return new DataResponse(['users' => $users]); | |
| 171 | - } | |
| 161 | + // Check subadmin has access to this group | |
| 162 | + if($this->groupManager->isAdmin($user->getUID()) | |
| 163 | +           || $isSubadminOfGroup) { | |
| 164 | + $users = $this->groupManager->get($groupId)->getUsers(); | |
| 165 | +            $users =  array_map(function($user) { | |
| 166 | + /** @var IUser $user */ | |
| 167 | + return $user->getUID(); | |
| 168 | + }, $users); | |
| 169 | + $users = array_values($users); | |
| 170 | + return new DataResponse(['users' => $users]); | |
| 171 | + } | |
| 172 | 172 | |
| 173 | - throw new OCSForbiddenException(); | |
| 174 | - } | |
| 173 | + throw new OCSForbiddenException(); | |
| 174 | + } | |
| 175 | 175 | |
| 176 | - /** | |
| 177 | - * returns an array of users details in the specified group | |
| 178 | - * | |
| 179 | - * @NoAdminRequired | |
| 180 | - * | |
| 181 | - * @param string $groupId | |
| 182 | - * @param string $search | |
| 183 | - * @param int $limit | |
| 184 | - * @param int $offset | |
| 185 | - * @return DataResponse | |
| 186 | - * @throws OCSException | |
| 187 | - */ | |
| 188 | -	public function getGroupUsersDetails(string $groupId, string $search = '', int $limit = null, int $offset = 0): DataResponse { | |
| 189 | - $currentUser = $this->userSession->getUser(); | |
| 176 | + /** | |
| 177 | + * returns an array of users details in the specified group | |
| 178 | + * | |
| 179 | + * @NoAdminRequired | |
| 180 | + * | |
| 181 | + * @param string $groupId | |
| 182 | + * @param string $search | |
| 183 | + * @param int $limit | |
| 184 | + * @param int $offset | |
| 185 | + * @return DataResponse | |
| 186 | + * @throws OCSException | |
| 187 | + */ | |
| 188 | +    public function getGroupUsersDetails(string $groupId, string $search = '', int $limit = null, int $offset = 0): DataResponse { | |
| 189 | + $currentUser = $this->userSession->getUser(); | |
| 190 | 190 | |
| 191 | - // Check the group exists | |
| 192 | - $group = $this->groupManager->get($groupId); | |
| 193 | -		if ($group !== null) { | |
| 194 | - $isSubadminOfGroup = $this->groupManager->getSubAdmin()->isSubAdminOfGroup($currentUser, $group); | |
| 195 | -		} else { | |
| 196 | -			throw new OCSException('The requested group could not be found', \OCP\API::RESPOND_NOT_FOUND); | |
| 197 | - } | |
| 191 | + // Check the group exists | |
| 192 | + $group = $this->groupManager->get($groupId); | |
| 193 | +        if ($group !== null) { | |
| 194 | + $isSubadminOfGroup = $this->groupManager->getSubAdmin()->isSubAdminOfGroup($currentUser, $group); | |
| 195 | +        } else { | |
| 196 | +            throw new OCSException('The requested group could not be found', \OCP\API::RESPOND_NOT_FOUND); | |
| 197 | + } | |
| 198 | 198 | |
| 199 | - // Check subadmin has access to this group | |
| 200 | -		if($this->groupManager->isAdmin($currentUser->getUID()) || $isSubadminOfGroup) { | |
| 201 | - $users = $group->searchUsers($search, $limit, $offset); | |
| 199 | + // Check subadmin has access to this group | |
| 200 | +        if($this->groupManager->isAdmin($currentUser->getUID()) || $isSubadminOfGroup) { | |
| 201 | + $users = $group->searchUsers($search, $limit, $offset); | |
| 202 | 202 | |
| 203 | - // Extract required number | |
| 204 | - $usersDetails = []; | |
| 205 | -			foreach ($users as $user) { | |
| 206 | -				try { | |
| 207 | - /** @var IUser $user */ | |
| 208 | - $userId = (string)$user->getUID(); | |
| 209 | - $userData = $this->getUserData($userId); | |
| 210 | - // Do not insert empty entry | |
| 211 | -					if (!empty($userData)) { | |
| 212 | - $usersDetails[$userId] = $userData; | |
| 213 | -					} else { | |
| 214 | - // Logged user does not have permissions to see this user | |
| 215 | - // only showing its id | |
| 216 | - $usersDetails[$userId] = ['id' => $userId]; | |
| 217 | - } | |
| 218 | -				} catch(OCSNotFoundException $e) { | |
| 219 | - // continue if a users ceased to exist. | |
| 220 | - } | |
| 221 | - } | |
| 222 | - return new DataResponse(['users' => $usersDetails]); | |
| 223 | - } | |
| 203 | + // Extract required number | |
| 204 | + $usersDetails = []; | |
| 205 | +            foreach ($users as $user) { | |
| 206 | +                try { | |
| 207 | + /** @var IUser $user */ | |
| 208 | + $userId = (string)$user->getUID(); | |
| 209 | + $userData = $this->getUserData($userId); | |
| 210 | + // Do not insert empty entry | |
| 211 | +                    if (!empty($userData)) { | |
| 212 | + $usersDetails[$userId] = $userData; | |
| 213 | +                    } else { | |
| 214 | + // Logged user does not have permissions to see this user | |
| 215 | + // only showing its id | |
| 216 | + $usersDetails[$userId] = ['id' => $userId]; | |
| 217 | + } | |
| 218 | +                } catch(OCSNotFoundException $e) { | |
| 219 | + // continue if a users ceased to exist. | |
| 220 | + } | |
| 221 | + } | |
| 222 | + return new DataResponse(['users' => $usersDetails]); | |
| 223 | + } | |
| 224 | 224 | |
| 225 | -		throw new OCSException('User does not have access to specified group', \OCP\API::RESPOND_UNAUTHORISED); | |
| 226 | - } | |
| 225 | +        throw new OCSException('User does not have access to specified group', \OCP\API::RESPOND_UNAUTHORISED); | |
| 226 | + } | |
| 227 | 227 | |
| 228 | - /** | |
| 229 | - * creates a new group | |
| 230 | - * | |
| 231 | - * @PasswordConfirmationRequired | |
| 232 | - * | |
| 233 | - * @param string $groupid | |
| 234 | - * @return DataResponse | |
| 235 | - * @throws OCSException | |
| 236 | - */ | |
| 237 | -	public function addGroup(string $groupid): DataResponse { | |
| 238 | - // Validate name | |
| 239 | -		if(empty($groupid)) { | |
| 240 | -			$this->logger->error('Group name not supplied', ['app' => 'provisioning_api']); | |
| 241 | -			throw new OCSException('Invalid group name', 101); | |
| 242 | - } | |
| 243 | - // Check if it exists | |
| 244 | -		if($this->groupManager->groupExists($groupid)){ | |
| 245 | -			throw new OCSException('group exists', 102); | |
| 246 | - } | |
| 247 | - $this->groupManager->createGroup($groupid); | |
| 248 | - return new DataResponse(); | |
| 249 | - } | |
| 228 | + /** | |
| 229 | + * creates a new group | |
| 230 | + * | |
| 231 | + * @PasswordConfirmationRequired | |
| 232 | + * | |
| 233 | + * @param string $groupid | |
| 234 | + * @return DataResponse | |
| 235 | + * @throws OCSException | |
| 236 | + */ | |
| 237 | +    public function addGroup(string $groupid): DataResponse { | |
| 238 | + // Validate name | |
| 239 | +        if(empty($groupid)) { | |
| 240 | +            $this->logger->error('Group name not supplied', ['app' => 'provisioning_api']); | |
| 241 | +            throw new OCSException('Invalid group name', 101); | |
| 242 | + } | |
| 243 | + // Check if it exists | |
| 244 | +        if($this->groupManager->groupExists($groupid)){ | |
| 245 | +            throw new OCSException('group exists', 102); | |
| 246 | + } | |
| 247 | + $this->groupManager->createGroup($groupid); | |
| 248 | + return new DataResponse(); | |
| 249 | + } | |
| 250 | 250 | |
| 251 | - /** | |
| 252 | - * @PasswordConfirmationRequired | |
| 253 | - * | |
| 254 | - * @param string $groupId | |
| 255 | - * @return DataResponse | |
| 256 | - * @throws OCSException | |
| 257 | - */ | |
| 258 | -	public function deleteGroup(string $groupId): DataResponse { | |
| 259 | - // Check it exists | |
| 260 | -		if(!$this->groupManager->groupExists($groupId)){ | |
| 261 | -			throw new OCSException('', 101); | |
| 262 | -		} else if($groupId === 'admin' || !$this->groupManager->get($groupId)->delete()){ | |
| 263 | - // Cannot delete admin group | |
| 264 | -			throw new OCSException('', 102); | |
| 265 | - } | |
| 251 | + /** | |
| 252 | + * @PasswordConfirmationRequired | |
| 253 | + * | |
| 254 | + * @param string $groupId | |
| 255 | + * @return DataResponse | |
| 256 | + * @throws OCSException | |
| 257 | + */ | |
| 258 | +    public function deleteGroup(string $groupId): DataResponse { | |
| 259 | + // Check it exists | |
| 260 | +        if(!$this->groupManager->groupExists($groupId)){ | |
| 261 | +            throw new OCSException('', 101); | |
| 262 | +        } else if($groupId === 'admin' || !$this->groupManager->get($groupId)->delete()){ | |
| 263 | + // Cannot delete admin group | |
| 264 | +            throw new OCSException('', 102); | |
| 265 | + } | |
| 266 | 266 | |
| 267 | - return new DataResponse(); | |
| 268 | - } | |
| 267 | + return new DataResponse(); | |
| 268 | + } | |
| 269 | 269 | |
| 270 | - /** | |
| 271 | - * @param string $groupId | |
| 272 | - * @return DataResponse | |
| 273 | - * @throws OCSException | |
| 274 | - */ | |
| 275 | -	public function getSubAdminsOfGroup(string $groupId): DataResponse { | |
| 276 | - // Check group exists | |
| 277 | - $targetGroup = $this->groupManager->get($groupId); | |
| 278 | -		if($targetGroup === null) { | |
| 279 | -			throw new OCSException('Group does not exist', 101); | |
| 280 | - } | |
| 270 | + /** | |
| 271 | + * @param string $groupId | |
| 272 | + * @return DataResponse | |
| 273 | + * @throws OCSException | |
| 274 | + */ | |
| 275 | +    public function getSubAdminsOfGroup(string $groupId): DataResponse { | |
| 276 | + // Check group exists | |
| 277 | + $targetGroup = $this->groupManager->get($groupId); | |
| 278 | +        if($targetGroup === null) { | |
| 279 | +            throw new OCSException('Group does not exist', 101); | |
| 280 | + } | |
| 281 | 281 | |
| 282 | - /** @var IUser[] $subadmins */ | |
| 283 | - $subadmins = $this->groupManager->getSubAdmin()->getGroupsSubAdmins($targetGroup); | |
| 284 | - // New class returns IUser[] so convert back | |
| 285 | - $uids = []; | |
| 286 | -		foreach ($subadmins as $user) { | |
| 287 | - $uids[] = $user->getUID(); | |
| 288 | - } | |
| 282 | + /** @var IUser[] $subadmins */ | |
| 283 | + $subadmins = $this->groupManager->getSubAdmin()->getGroupsSubAdmins($targetGroup); | |
| 284 | + // New class returns IUser[] so convert back | |
| 285 | + $uids = []; | |
| 286 | +        foreach ($subadmins as $user) { | |
| 287 | + $uids[] = $user->getUID(); | |
| 288 | + } | |
| 289 | 289 | |
| 290 | - return new DataResponse($uids); | |
| 291 | - } | |
| 290 | + return new DataResponse($uids); | |
| 291 | + } | |
| 292 | 292 | |
| 293 | 293 | } | 
| @@ -153,16 +153,16 @@ discard block | ||
| 153 | 153 | // Check the group exists | 
| 154 | 154 | $group = $this->groupManager->get($groupId); | 
| 155 | 155 |  		if ($group !== null) { | 
| 156 | - $isSubadminOfGroup =$this->groupManager->getSubAdmin()->isSubAdminOfGroup($user, $group); | |
| 156 | + $isSubadminOfGroup = $this->groupManager->getSubAdmin()->isSubAdminOfGroup($user, $group); | |
| 157 | 157 |  		} else { | 
| 158 | 158 |  			throw new OCSNotFoundException('The requested group could not be found'); | 
| 159 | 159 | } | 
| 160 | 160 | |
| 161 | 161 | // Check subadmin has access to this group | 
| 162 | - if($this->groupManager->isAdmin($user->getUID()) | |
| 162 | + if ($this->groupManager->isAdmin($user->getUID()) | |
| 163 | 163 |  		   || $isSubadminOfGroup) { | 
| 164 | 164 | $users = $this->groupManager->get($groupId)->getUsers(); | 
| 165 | -			$users =  array_map(function($user) { | |
| 165 | +			$users = array_map(function($user) { | |
| 166 | 166 | /** @var IUser $user */ | 
| 167 | 167 | return $user->getUID(); | 
| 168 | 168 | }, $users); | 
| @@ -197,7 +197,7 @@ discard block | ||
| 197 | 197 | } | 
| 198 | 198 | |
| 199 | 199 | // Check subadmin has access to this group | 
| 200 | -		if($this->groupManager->isAdmin($currentUser->getUID()) || $isSubadminOfGroup) { | |
| 200 | +		if ($this->groupManager->isAdmin($currentUser->getUID()) || $isSubadminOfGroup) { | |
| 201 | 201 | $users = $group->searchUsers($search, $limit, $offset); | 
| 202 | 202 | |
| 203 | 203 | // Extract required number | 
| @@ -205,7 +205,7 @@ discard block | ||
| 205 | 205 |  			foreach ($users as $user) { | 
| 206 | 206 |  				try { | 
| 207 | 207 | /** @var IUser $user */ | 
| 208 | - $userId = (string)$user->getUID(); | |
| 208 | + $userId = (string) $user->getUID(); | |
| 209 | 209 | $userData = $this->getUserData($userId); | 
| 210 | 210 | // Do not insert empty entry | 
| 211 | 211 |  					if (!empty($userData)) { | 
| @@ -215,7 +215,7 @@ discard block | ||
| 215 | 215 | // only showing its id | 
| 216 | 216 | $usersDetails[$userId] = ['id' => $userId]; | 
| 217 | 217 | } | 
| 218 | -				} catch(OCSNotFoundException $e) { | |
| 218 | +				} catch (OCSNotFoundException $e) { | |
| 219 | 219 | // continue if a users ceased to exist. | 
| 220 | 220 | } | 
| 221 | 221 | } | 
| @@ -236,12 +236,12 @@ discard block | ||
| 236 | 236 | */ | 
| 237 | 237 |  	public function addGroup(string $groupid): DataResponse { | 
| 238 | 238 | // Validate name | 
| 239 | -		if(empty($groupid)) { | |
| 239 | +		if (empty($groupid)) { | |
| 240 | 240 |  			$this->logger->error('Group name not supplied', ['app' => 'provisioning_api']); | 
| 241 | 241 |  			throw new OCSException('Invalid group name', 101); | 
| 242 | 242 | } | 
| 243 | 243 | // Check if it exists | 
| 244 | -		if($this->groupManager->groupExists($groupid)){ | |
| 244 | +		if ($this->groupManager->groupExists($groupid)) { | |
| 245 | 245 |  			throw new OCSException('group exists', 102); | 
| 246 | 246 | } | 
| 247 | 247 | $this->groupManager->createGroup($groupid); | 
| @@ -257,9 +257,9 @@ discard block | ||
| 257 | 257 | */ | 
| 258 | 258 |  	public function deleteGroup(string $groupId): DataResponse { | 
| 259 | 259 | // Check it exists | 
| 260 | -		if(!$this->groupManager->groupExists($groupId)){ | |
| 260 | +		if (!$this->groupManager->groupExists($groupId)) { | |
| 261 | 261 |  			throw new OCSException('', 101); | 
| 262 | -		} else if($groupId === 'admin' || !$this->groupManager->get($groupId)->delete()){ | |
| 262 | +		} else if ($groupId === 'admin' || !$this->groupManager->get($groupId)->delete()) { | |
| 263 | 263 | // Cannot delete admin group | 
| 264 | 264 |  			throw new OCSException('', 102); | 
| 265 | 265 | } | 
| @@ -275,7 +275,7 @@ discard block | ||
| 275 | 275 |  	public function getSubAdminsOfGroup(string $groupId): DataResponse { | 
| 276 | 276 | // Check group exists | 
| 277 | 277 | $targetGroup = $this->groupManager->get($groupId); | 
| 278 | -		if($targetGroup === null) { | |
| 278 | +		if ($targetGroup === null) { | |
| 279 | 279 |  			throw new OCSException('Group does not exist', 101); | 
| 280 | 280 | } | 
| 281 | 281 | |