@@ -36,178 +36,178 @@ |
||
| 36 | 36 | */ |
| 37 | 37 | interface IUser { |
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * get the user id |
|
| 41 | - * |
|
| 42 | - * @return string |
|
| 43 | - * @since 8.0.0 |
|
| 44 | - */ |
|
| 45 | - public function getUID(); |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * get the display name for the user, if no specific display name is set it will fallback to the user id |
|
| 49 | - * |
|
| 50 | - * @return string |
|
| 51 | - * @since 8.0.0 |
|
| 52 | - */ |
|
| 53 | - public function getDisplayName(); |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * set the display name for the user |
|
| 57 | - * |
|
| 58 | - * @param string $displayName |
|
| 59 | - * @return bool |
|
| 60 | - * @since 8.0.0 |
|
| 61 | - */ |
|
| 62 | - public function setDisplayName($displayName); |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * returns the timestamp of the user's last login or 0 if the user did never |
|
| 66 | - * login |
|
| 67 | - * |
|
| 68 | - * @return int |
|
| 69 | - * @since 8.0.0 |
|
| 70 | - */ |
|
| 71 | - public function getLastLogin(); |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * updates the timestamp of the most recent login of this user |
|
| 75 | - * @since 8.0.0 |
|
| 76 | - */ |
|
| 77 | - public function updateLastLoginTimestamp(); |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * Delete the user |
|
| 81 | - * |
|
| 82 | - * @return bool |
|
| 83 | - * @since 8.0.0 |
|
| 84 | - */ |
|
| 85 | - public function delete(); |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * Set the password of the user |
|
| 89 | - * |
|
| 90 | - * @param string $password |
|
| 91 | - * @param string $recoveryPassword for the encryption app to reset encryption keys |
|
| 92 | - * @return bool |
|
| 93 | - * @since 8.0.0 |
|
| 94 | - */ |
|
| 95 | - public function setPassword($password, $recoveryPassword = null); |
|
| 96 | - |
|
| 97 | - /** |
|
| 98 | - * get the users home folder to mount |
|
| 99 | - * |
|
| 100 | - * @return string |
|
| 101 | - * @since 8.0.0 |
|
| 102 | - */ |
|
| 103 | - public function getHome(); |
|
| 104 | - |
|
| 105 | - /** |
|
| 106 | - * Get the name of the backend class the user is connected with |
|
| 107 | - * |
|
| 108 | - * @return string |
|
| 109 | - * @since 8.0.0 |
|
| 110 | - */ |
|
| 111 | - public function getBackendClassName(); |
|
| 112 | - |
|
| 113 | - /** |
|
| 114 | - * Get the backend for the current user object |
|
| 115 | - * |
|
| 116 | - * @return UserInterface |
|
| 117 | - * @since 15.0.0 |
|
| 118 | - */ |
|
| 119 | - public function getBackend(); |
|
| 120 | - |
|
| 121 | - /** |
|
| 122 | - * check if the backend allows the user to change his avatar on Personal page |
|
| 123 | - * |
|
| 124 | - * @return bool |
|
| 125 | - * @since 8.0.0 |
|
| 126 | - */ |
|
| 127 | - public function canChangeAvatar(); |
|
| 128 | - |
|
| 129 | - /** |
|
| 130 | - * check if the backend supports changing passwords |
|
| 131 | - * |
|
| 132 | - * @return bool |
|
| 133 | - * @since 8.0.0 |
|
| 134 | - */ |
|
| 135 | - public function canChangePassword(); |
|
| 136 | - |
|
| 137 | - /** |
|
| 138 | - * check if the backend supports changing display names |
|
| 139 | - * |
|
| 140 | - * @return bool |
|
| 141 | - * @since 8.0.0 |
|
| 142 | - */ |
|
| 143 | - public function canChangeDisplayName(); |
|
| 144 | - |
|
| 145 | - /** |
|
| 146 | - * check if the user is enabled |
|
| 147 | - * |
|
| 148 | - * @return bool |
|
| 149 | - * @since 8.0.0 |
|
| 150 | - */ |
|
| 151 | - public function isEnabled(); |
|
| 152 | - |
|
| 153 | - /** |
|
| 154 | - * set the enabled status for the user |
|
| 155 | - * |
|
| 156 | - * @param bool $enabled |
|
| 157 | - * @since 8.0.0 |
|
| 158 | - */ |
|
| 159 | - public function setEnabled(bool $enabled = true); |
|
| 160 | - |
|
| 161 | - /** |
|
| 162 | - * get the users email address |
|
| 163 | - * |
|
| 164 | - * @return string|null |
|
| 165 | - * @since 9.0.0 |
|
| 166 | - */ |
|
| 167 | - public function getEMailAddress(); |
|
| 168 | - |
|
| 169 | - /** |
|
| 170 | - * get the avatar image if it exists |
|
| 171 | - * |
|
| 172 | - * @param int $size |
|
| 173 | - * @return IImage|null |
|
| 174 | - * @since 9.0.0 |
|
| 175 | - */ |
|
| 176 | - public function getAvatarImage($size); |
|
| 177 | - |
|
| 178 | - /** |
|
| 179 | - * get the federation cloud id |
|
| 180 | - * |
|
| 181 | - * @return string |
|
| 182 | - * @since 9.0.0 |
|
| 183 | - */ |
|
| 184 | - public function getCloudId(); |
|
| 185 | - |
|
| 186 | - /** |
|
| 187 | - * set the email address of the user |
|
| 188 | - * |
|
| 189 | - * @param string|null $mailAddress |
|
| 190 | - * @return void |
|
| 191 | - * @since 9.0.0 |
|
| 192 | - */ |
|
| 193 | - public function setEMailAddress($mailAddress); |
|
| 194 | - |
|
| 195 | - /** |
|
| 196 | - * get the users' quota in human readable form. If a specific quota is not |
|
| 197 | - * set for the user, the default value is returned. If a default setting |
|
| 198 | - * was not set otherwise, it is return as 'none', i.e. quota is not limited. |
|
| 199 | - * |
|
| 200 | - * @return string |
|
| 201 | - * @since 9.0.0 |
|
| 202 | - */ |
|
| 203 | - public function getQuota(); |
|
| 204 | - |
|
| 205 | - /** |
|
| 206 | - * set the users' quota |
|
| 207 | - * |
|
| 208 | - * @param string $quota |
|
| 209 | - * @return void |
|
| 210 | - * @since 9.0.0 |
|
| 211 | - */ |
|
| 212 | - public function setQuota($quota); |
|
| 39 | + /** |
|
| 40 | + * get the user id |
|
| 41 | + * |
|
| 42 | + * @return string |
|
| 43 | + * @since 8.0.0 |
|
| 44 | + */ |
|
| 45 | + public function getUID(); |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * get the display name for the user, if no specific display name is set it will fallback to the user id |
|
| 49 | + * |
|
| 50 | + * @return string |
|
| 51 | + * @since 8.0.0 |
|
| 52 | + */ |
|
| 53 | + public function getDisplayName(); |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * set the display name for the user |
|
| 57 | + * |
|
| 58 | + * @param string $displayName |
|
| 59 | + * @return bool |
|
| 60 | + * @since 8.0.0 |
|
| 61 | + */ |
|
| 62 | + public function setDisplayName($displayName); |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * returns the timestamp of the user's last login or 0 if the user did never |
|
| 66 | + * login |
|
| 67 | + * |
|
| 68 | + * @return int |
|
| 69 | + * @since 8.0.0 |
|
| 70 | + */ |
|
| 71 | + public function getLastLogin(); |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * updates the timestamp of the most recent login of this user |
|
| 75 | + * @since 8.0.0 |
|
| 76 | + */ |
|
| 77 | + public function updateLastLoginTimestamp(); |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * Delete the user |
|
| 81 | + * |
|
| 82 | + * @return bool |
|
| 83 | + * @since 8.0.0 |
|
| 84 | + */ |
|
| 85 | + public function delete(); |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * Set the password of the user |
|
| 89 | + * |
|
| 90 | + * @param string $password |
|
| 91 | + * @param string $recoveryPassword for the encryption app to reset encryption keys |
|
| 92 | + * @return bool |
|
| 93 | + * @since 8.0.0 |
|
| 94 | + */ |
|
| 95 | + public function setPassword($password, $recoveryPassword = null); |
|
| 96 | + |
|
| 97 | + /** |
|
| 98 | + * get the users home folder to mount |
|
| 99 | + * |
|
| 100 | + * @return string |
|
| 101 | + * @since 8.0.0 |
|
| 102 | + */ |
|
| 103 | + public function getHome(); |
|
| 104 | + |
|
| 105 | + /** |
|
| 106 | + * Get the name of the backend class the user is connected with |
|
| 107 | + * |
|
| 108 | + * @return string |
|
| 109 | + * @since 8.0.0 |
|
| 110 | + */ |
|
| 111 | + public function getBackendClassName(); |
|
| 112 | + |
|
| 113 | + /** |
|
| 114 | + * Get the backend for the current user object |
|
| 115 | + * |
|
| 116 | + * @return UserInterface |
|
| 117 | + * @since 15.0.0 |
|
| 118 | + */ |
|
| 119 | + public function getBackend(); |
|
| 120 | + |
|
| 121 | + /** |
|
| 122 | + * check if the backend allows the user to change his avatar on Personal page |
|
| 123 | + * |
|
| 124 | + * @return bool |
|
| 125 | + * @since 8.0.0 |
|
| 126 | + */ |
|
| 127 | + public function canChangeAvatar(); |
|
| 128 | + |
|
| 129 | + /** |
|
| 130 | + * check if the backend supports changing passwords |
|
| 131 | + * |
|
| 132 | + * @return bool |
|
| 133 | + * @since 8.0.0 |
|
| 134 | + */ |
|
| 135 | + public function canChangePassword(); |
|
| 136 | + |
|
| 137 | + /** |
|
| 138 | + * check if the backend supports changing display names |
|
| 139 | + * |
|
| 140 | + * @return bool |
|
| 141 | + * @since 8.0.0 |
|
| 142 | + */ |
|
| 143 | + public function canChangeDisplayName(); |
|
| 144 | + |
|
| 145 | + /** |
|
| 146 | + * check if the user is enabled |
|
| 147 | + * |
|
| 148 | + * @return bool |
|
| 149 | + * @since 8.0.0 |
|
| 150 | + */ |
|
| 151 | + public function isEnabled(); |
|
| 152 | + |
|
| 153 | + /** |
|
| 154 | + * set the enabled status for the user |
|
| 155 | + * |
|
| 156 | + * @param bool $enabled |
|
| 157 | + * @since 8.0.0 |
|
| 158 | + */ |
|
| 159 | + public function setEnabled(bool $enabled = true); |
|
| 160 | + |
|
| 161 | + /** |
|
| 162 | + * get the users email address |
|
| 163 | + * |
|
| 164 | + * @return string|null |
|
| 165 | + * @since 9.0.0 |
|
| 166 | + */ |
|
| 167 | + public function getEMailAddress(); |
|
| 168 | + |
|
| 169 | + /** |
|
| 170 | + * get the avatar image if it exists |
|
| 171 | + * |
|
| 172 | + * @param int $size |
|
| 173 | + * @return IImage|null |
|
| 174 | + * @since 9.0.0 |
|
| 175 | + */ |
|
| 176 | + public function getAvatarImage($size); |
|
| 177 | + |
|
| 178 | + /** |
|
| 179 | + * get the federation cloud id |
|
| 180 | + * |
|
| 181 | + * @return string |
|
| 182 | + * @since 9.0.0 |
|
| 183 | + */ |
|
| 184 | + public function getCloudId(); |
|
| 185 | + |
|
| 186 | + /** |
|
| 187 | + * set the email address of the user |
|
| 188 | + * |
|
| 189 | + * @param string|null $mailAddress |
|
| 190 | + * @return void |
|
| 191 | + * @since 9.0.0 |
|
| 192 | + */ |
|
| 193 | + public function setEMailAddress($mailAddress); |
|
| 194 | + |
|
| 195 | + /** |
|
| 196 | + * get the users' quota in human readable form. If a specific quota is not |
|
| 197 | + * set for the user, the default value is returned. If a default setting |
|
| 198 | + * was not set otherwise, it is return as 'none', i.e. quota is not limited. |
|
| 199 | + * |
|
| 200 | + * @return string |
|
| 201 | + * @since 9.0.0 |
|
| 202 | + */ |
|
| 203 | + public function getQuota(); |
|
| 204 | + |
|
| 205 | + /** |
|
| 206 | + * set the users' quota |
|
| 207 | + * |
|
| 208 | + * @param string $quota |
|
| 209 | + * @return void |
|
| 210 | + * @since 9.0.0 |
|
| 211 | + */ |
|
| 212 | + public function setQuota($quota); |
|
| 213 | 213 | } |
@@ -38,162 +38,162 @@ |
||
| 38 | 38 | |
| 39 | 39 | abstract class AUserData extends OCSController { |
| 40 | 40 | |
| 41 | - /** @var IUserManager */ |
|
| 42 | - protected $userManager; |
|
| 43 | - /** @var IConfig */ |
|
| 44 | - protected $config; |
|
| 45 | - /** @var IGroupManager|\OC\Group\Manager */ // FIXME Requires a method that is not on the interface |
|
| 46 | - protected $groupManager; |
|
| 47 | - /** @var IUserSession */ |
|
| 48 | - protected $userSession; |
|
| 49 | - /** @var AccountManager */ |
|
| 50 | - protected $accountManager; |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * @param string $appName |
|
| 54 | - * @param IRequest $request |
|
| 55 | - * @param IUserManager $userManager |
|
| 56 | - * @param IConfig $config |
|
| 57 | - * @param IGroupManager $groupManager |
|
| 58 | - * @param IUserSession $userSession |
|
| 59 | - * @param AccountManager $accountManager |
|
| 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 | - parent::__construct($appName, $request); |
|
| 69 | - |
|
| 70 | - $this->userManager = $userManager; |
|
| 71 | - $this->config = $config; |
|
| 72 | - $this->groupManager = $groupManager; |
|
| 73 | - $this->userSession = $userSession; |
|
| 74 | - $this->accountManager = $accountManager; |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * creates a array with all user data |
|
| 79 | - * |
|
| 80 | - * @param string $userId |
|
| 81 | - * @return array |
|
| 82 | - * @throws OCSException |
|
| 83 | - */ |
|
| 84 | - protected function getUserData(string $userId): array { |
|
| 85 | - $currentLoggedInUser = $this->userSession->getUser(); |
|
| 86 | - |
|
| 87 | - $data = []; |
|
| 88 | - |
|
| 89 | - // Check if the target user exists |
|
| 90 | - $targetUserObject = $this->userManager->get($userId); |
|
| 91 | - if($targetUserObject === null) { |
|
| 92 | - throw new OCSNotFoundException('User does not exist'); |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - // Should be at least Admin Or SubAdmin! |
|
| 96 | - if ($this->groupManager->isAdmin($currentLoggedInUser->getUID()) |
|
| 97 | - || $this->groupManager->getSubAdmin()->isUserAccessible($currentLoggedInUser, $targetUserObject)) { |
|
| 98 | - $data['enabled'] = $this->config->getUserValue($targetUserObject->getUID(), 'core', 'enabled', 'true') === 'true'; |
|
| 99 | - } else { |
|
| 100 | - // Check they are looking up themselves |
|
| 101 | - if ($currentLoggedInUser->getUID() !== $targetUserObject->getUID()) { |
|
| 102 | - return $data; |
|
| 103 | - } |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - // Get groups data |
|
| 107 | - $userAccount = $this->accountManager->getUser($targetUserObject); |
|
| 108 | - $groups = $this->groupManager->getUserGroups($targetUserObject); |
|
| 109 | - $gids = []; |
|
| 110 | - foreach ($groups as $group) { |
|
| 111 | - $gids[] = $group->getGID(); |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - // Find the data |
|
| 115 | - $data['id'] = $targetUserObject->getUID(); |
|
| 116 | - $data['storageLocation'] = $targetUserObject->getHome(); |
|
| 117 | - $data['lastLogin'] = $targetUserObject->getLastLogin() * 1000; |
|
| 118 | - $data['backend'] = $targetUserObject->getBackendClassName(); |
|
| 119 | - $data['subadmin'] = $this->getUserSubAdminGroupsData($targetUserObject->getUID()); |
|
| 120 | - $data['quota'] = $this->fillStorageInfo($targetUserObject->getUID()); |
|
| 121 | - $data[AccountManager::PROPERTY_EMAIL] = $targetUserObject->getEMailAddress(); |
|
| 122 | - $data[AccountManager::PROPERTY_DISPLAYNAME] = $targetUserObject->getDisplayName(); |
|
| 123 | - $data[AccountManager::PROPERTY_PHONE] = $userAccount[AccountManager::PROPERTY_PHONE]['value']; |
|
| 124 | - $data[AccountManager::PROPERTY_ADDRESS] = $userAccount[AccountManager::PROPERTY_ADDRESS]['value']; |
|
| 125 | - $data[AccountManager::PROPERTY_WEBSITE] = $userAccount[AccountManager::PROPERTY_WEBSITE]['value']; |
|
| 126 | - $data[AccountManager::PROPERTY_TWITTER] = $userAccount[AccountManager::PROPERTY_TWITTER]['value']; |
|
| 127 | - $data['groups'] = $gids; |
|
| 128 | - $data['language'] = $this->config->getUserValue($targetUserObject->getUID(), 'core', 'lang'); |
|
| 129 | - $data['locale'] = $this->config->getUserValue($targetUserObject->getUID(), 'core', 'locale'); |
|
| 130 | - |
|
| 131 | - $backend = $targetUserObject->getBackend(); |
|
| 132 | - $data['backendCapabilities'] = [ |
|
| 133 | - 'setDisplayName' => $backend instanceof ISetDisplayNameBackend || $backend->implementsActions(Backend::SET_DISPLAYNAME), |
|
| 134 | - 'setPassword' => $backend instanceof ISetPasswordBackend || $backend->implementsActions(Backend::SET_PASSWORD), |
|
| 135 | - ]; |
|
| 136 | - |
|
| 137 | - return $data; |
|
| 41 | + /** @var IUserManager */ |
|
| 42 | + protected $userManager; |
|
| 43 | + /** @var IConfig */ |
|
| 44 | + protected $config; |
|
| 45 | + /** @var IGroupManager|\OC\Group\Manager */ // FIXME Requires a method that is not on the interface |
|
| 46 | + protected $groupManager; |
|
| 47 | + /** @var IUserSession */ |
|
| 48 | + protected $userSession; |
|
| 49 | + /** @var AccountManager */ |
|
| 50 | + protected $accountManager; |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * @param string $appName |
|
| 54 | + * @param IRequest $request |
|
| 55 | + * @param IUserManager $userManager |
|
| 56 | + * @param IConfig $config |
|
| 57 | + * @param IGroupManager $groupManager |
|
| 58 | + * @param IUserSession $userSession |
|
| 59 | + * @param AccountManager $accountManager |
|
| 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 | + parent::__construct($appName, $request); |
|
| 69 | + |
|
| 70 | + $this->userManager = $userManager; |
|
| 71 | + $this->config = $config; |
|
| 72 | + $this->groupManager = $groupManager; |
|
| 73 | + $this->userSession = $userSession; |
|
| 74 | + $this->accountManager = $accountManager; |
|
| 138 | 75 | } |
| 139 | 76 | |
| 140 | - /** |
|
| 141 | - * Get the groups a user is a subadmin of |
|
| 142 | - * |
|
| 143 | - * @param string $userId |
|
| 144 | - * @return array |
|
| 145 | - * @throws OCSException |
|
| 146 | - */ |
|
| 147 | - protected function getUserSubAdminGroupsData(string $userId): array { |
|
| 148 | - $user = $this->userManager->get($userId); |
|
| 149 | - // Check if the user exists |
|
| 150 | - if($user === null) { |
|
| 151 | - throw new OCSNotFoundException('User does not exist'); |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - // Get the subadmin groups |
|
| 155 | - $subAdminGroups = $this->groupManager->getSubAdmin()->getSubAdminsGroups($user); |
|
| 156 | - $groups = []; |
|
| 157 | - foreach ($subAdminGroups as $key => $group) { |
|
| 158 | - $groups[] = $group->getGID(); |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - return $groups; |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - /** |
|
| 165 | - * @param string $userId |
|
| 166 | - * @return array |
|
| 167 | - * @throws \OCP\Files\NotFoundException |
|
| 168 | - */ |
|
| 169 | - protected function fillStorageInfo(string $userId): array { |
|
| 170 | - try { |
|
| 171 | - \OC_Util::tearDownFS(); |
|
| 172 | - \OC_Util::setupFS($userId); |
|
| 173 | - $storage = OC_Helper::getStorageInfo('/'); |
|
| 174 | - $data = [ |
|
| 175 | - 'free' => $storage['free'], |
|
| 176 | - 'used' => $storage['used'], |
|
| 177 | - 'total' => $storage['total'], |
|
| 178 | - 'relative' => $storage['relative'], |
|
| 179 | - 'quota' => $storage['quota'], |
|
| 180 | - ]; |
|
| 181 | - } catch (NotFoundException $ex) { |
|
| 182 | - // User fs is not setup yet |
|
| 183 | - $user = $this->userManager->get($userId); |
|
| 184 | - if ($user === null) { |
|
| 185 | - throw new OCSException('User does not exist', 101); |
|
| 186 | - } |
|
| 187 | - $quota = $user->getQuota(); |
|
| 188 | - if ($quota !== 'none') { |
|
| 189 | - $quota = OC_Helper::computerFileSize($quota); |
|
| 190 | - } |
|
| 191 | - $data = [ |
|
| 192 | - 'quota' => $quota !== false ? $quota : 'none', |
|
| 193 | - 'used' => 0 |
|
| 194 | - ]; |
|
| 195 | - } |
|
| 196 | - return $data; |
|
| 197 | - } |
|
| 77 | + /** |
|
| 78 | + * creates a array with all user data |
|
| 79 | + * |
|
| 80 | + * @param string $userId |
|
| 81 | + * @return array |
|
| 82 | + * @throws OCSException |
|
| 83 | + */ |
|
| 84 | + protected function getUserData(string $userId): array { |
|
| 85 | + $currentLoggedInUser = $this->userSession->getUser(); |
|
| 86 | + |
|
| 87 | + $data = []; |
|
| 88 | + |
|
| 89 | + // Check if the target user exists |
|
| 90 | + $targetUserObject = $this->userManager->get($userId); |
|
| 91 | + if($targetUserObject === null) { |
|
| 92 | + throw new OCSNotFoundException('User does not exist'); |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + // Should be at least Admin Or SubAdmin! |
|
| 96 | + if ($this->groupManager->isAdmin($currentLoggedInUser->getUID()) |
|
| 97 | + || $this->groupManager->getSubAdmin()->isUserAccessible($currentLoggedInUser, $targetUserObject)) { |
|
| 98 | + $data['enabled'] = $this->config->getUserValue($targetUserObject->getUID(), 'core', 'enabled', 'true') === 'true'; |
|
| 99 | + } else { |
|
| 100 | + // Check they are looking up themselves |
|
| 101 | + if ($currentLoggedInUser->getUID() !== $targetUserObject->getUID()) { |
|
| 102 | + return $data; |
|
| 103 | + } |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + // Get groups data |
|
| 107 | + $userAccount = $this->accountManager->getUser($targetUserObject); |
|
| 108 | + $groups = $this->groupManager->getUserGroups($targetUserObject); |
|
| 109 | + $gids = []; |
|
| 110 | + foreach ($groups as $group) { |
|
| 111 | + $gids[] = $group->getGID(); |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + // Find the data |
|
| 115 | + $data['id'] = $targetUserObject->getUID(); |
|
| 116 | + $data['storageLocation'] = $targetUserObject->getHome(); |
|
| 117 | + $data['lastLogin'] = $targetUserObject->getLastLogin() * 1000; |
|
| 118 | + $data['backend'] = $targetUserObject->getBackendClassName(); |
|
| 119 | + $data['subadmin'] = $this->getUserSubAdminGroupsData($targetUserObject->getUID()); |
|
| 120 | + $data['quota'] = $this->fillStorageInfo($targetUserObject->getUID()); |
|
| 121 | + $data[AccountManager::PROPERTY_EMAIL] = $targetUserObject->getEMailAddress(); |
|
| 122 | + $data[AccountManager::PROPERTY_DISPLAYNAME] = $targetUserObject->getDisplayName(); |
|
| 123 | + $data[AccountManager::PROPERTY_PHONE] = $userAccount[AccountManager::PROPERTY_PHONE]['value']; |
|
| 124 | + $data[AccountManager::PROPERTY_ADDRESS] = $userAccount[AccountManager::PROPERTY_ADDRESS]['value']; |
|
| 125 | + $data[AccountManager::PROPERTY_WEBSITE] = $userAccount[AccountManager::PROPERTY_WEBSITE]['value']; |
|
| 126 | + $data[AccountManager::PROPERTY_TWITTER] = $userAccount[AccountManager::PROPERTY_TWITTER]['value']; |
|
| 127 | + $data['groups'] = $gids; |
|
| 128 | + $data['language'] = $this->config->getUserValue($targetUserObject->getUID(), 'core', 'lang'); |
|
| 129 | + $data['locale'] = $this->config->getUserValue($targetUserObject->getUID(), 'core', 'locale'); |
|
| 130 | + |
|
| 131 | + $backend = $targetUserObject->getBackend(); |
|
| 132 | + $data['backendCapabilities'] = [ |
|
| 133 | + 'setDisplayName' => $backend instanceof ISetDisplayNameBackend || $backend->implementsActions(Backend::SET_DISPLAYNAME), |
|
| 134 | + 'setPassword' => $backend instanceof ISetPasswordBackend || $backend->implementsActions(Backend::SET_PASSWORD), |
|
| 135 | + ]; |
|
| 136 | + |
|
| 137 | + return $data; |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * Get the groups a user is a subadmin of |
|
| 142 | + * |
|
| 143 | + * @param string $userId |
|
| 144 | + * @return array |
|
| 145 | + * @throws OCSException |
|
| 146 | + */ |
|
| 147 | + protected function getUserSubAdminGroupsData(string $userId): array { |
|
| 148 | + $user = $this->userManager->get($userId); |
|
| 149 | + // Check if the user exists |
|
| 150 | + if($user === null) { |
|
| 151 | + throw new OCSNotFoundException('User does not exist'); |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + // Get the subadmin groups |
|
| 155 | + $subAdminGroups = $this->groupManager->getSubAdmin()->getSubAdminsGroups($user); |
|
| 156 | + $groups = []; |
|
| 157 | + foreach ($subAdminGroups as $key => $group) { |
|
| 158 | + $groups[] = $group->getGID(); |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + return $groups; |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + /** |
|
| 165 | + * @param string $userId |
|
| 166 | + * @return array |
|
| 167 | + * @throws \OCP\Files\NotFoundException |
|
| 168 | + */ |
|
| 169 | + protected function fillStorageInfo(string $userId): array { |
|
| 170 | + try { |
|
| 171 | + \OC_Util::tearDownFS(); |
|
| 172 | + \OC_Util::setupFS($userId); |
|
| 173 | + $storage = OC_Helper::getStorageInfo('/'); |
|
| 174 | + $data = [ |
|
| 175 | + 'free' => $storage['free'], |
|
| 176 | + 'used' => $storage['used'], |
|
| 177 | + 'total' => $storage['total'], |
|
| 178 | + 'relative' => $storage['relative'], |
|
| 179 | + 'quota' => $storage['quota'], |
|
| 180 | + ]; |
|
| 181 | + } catch (NotFoundException $ex) { |
|
| 182 | + // User fs is not setup yet |
|
| 183 | + $user = $this->userManager->get($userId); |
|
| 184 | + if ($user === null) { |
|
| 185 | + throw new OCSException('User does not exist', 101); |
|
| 186 | + } |
|
| 187 | + $quota = $user->getQuota(); |
|
| 188 | + if ($quota !== 'none') { |
|
| 189 | + $quota = OC_Helper::computerFileSize($quota); |
|
| 190 | + } |
|
| 191 | + $data = [ |
|
| 192 | + 'quota' => $quota !== false ? $quota : 'none', |
|
| 193 | + 'used' => 0 |
|
| 194 | + ]; |
|
| 195 | + } |
|
| 196 | + return $data; |
|
| 197 | + } |
|
| 198 | 198 | |
| 199 | 199 | } |