@@ -52,238 +52,238 @@ |
||
| 52 | 52 | use OCP\User\Backend\ISetPasswordBackend; |
| 53 | 53 | |
| 54 | 54 | abstract class AUserData extends OCSController { |
| 55 | - public const SCOPE_SUFFIX = 'Scope'; |
|
| 55 | + public const SCOPE_SUFFIX = 'Scope'; |
|
| 56 | 56 | |
| 57 | - public const USER_FIELD_DISPLAYNAME = 'display'; |
|
| 58 | - public const USER_FIELD_LANGUAGE = 'language'; |
|
| 59 | - public const USER_FIELD_LOCALE = 'locale'; |
|
| 60 | - public const USER_FIELD_PASSWORD = 'password'; |
|
| 61 | - public const USER_FIELD_QUOTA = 'quota'; |
|
| 62 | - public const USER_FIELD_NOTIFICATION_EMAIL = 'notify_email'; |
|
| 57 | + public const USER_FIELD_DISPLAYNAME = 'display'; |
|
| 58 | + public const USER_FIELD_LANGUAGE = 'language'; |
|
| 59 | + public const USER_FIELD_LOCALE = 'locale'; |
|
| 60 | + public const USER_FIELD_PASSWORD = 'password'; |
|
| 61 | + public const USER_FIELD_QUOTA = 'quota'; |
|
| 62 | + public const USER_FIELD_NOTIFICATION_EMAIL = 'notify_email'; |
|
| 63 | 63 | |
| 64 | - /** @var IUserManager */ |
|
| 65 | - protected $userManager; |
|
| 66 | - /** @var IConfig */ |
|
| 67 | - protected $config; |
|
| 68 | - /** @var IGroupManager|Manager */ // FIXME Requires a method that is not on the interface |
|
| 69 | - protected $groupManager; |
|
| 70 | - /** @var IUserSession */ |
|
| 71 | - protected $userSession; |
|
| 72 | - /** @var IAccountManager */ |
|
| 73 | - protected $accountManager; |
|
| 74 | - /** @var IFactory */ |
|
| 75 | - protected $l10nFactory; |
|
| 64 | + /** @var IUserManager */ |
|
| 65 | + protected $userManager; |
|
| 66 | + /** @var IConfig */ |
|
| 67 | + protected $config; |
|
| 68 | + /** @var IGroupManager|Manager */ // FIXME Requires a method that is not on the interface |
|
| 69 | + protected $groupManager; |
|
| 70 | + /** @var IUserSession */ |
|
| 71 | + protected $userSession; |
|
| 72 | + /** @var IAccountManager */ |
|
| 73 | + protected $accountManager; |
|
| 74 | + /** @var IFactory */ |
|
| 75 | + protected $l10nFactory; |
|
| 76 | 76 | |
| 77 | - public function __construct(string $appName, |
|
| 78 | - IRequest $request, |
|
| 79 | - IUserManager $userManager, |
|
| 80 | - IConfig $config, |
|
| 81 | - IGroupManager $groupManager, |
|
| 82 | - IUserSession $userSession, |
|
| 83 | - IAccountManager $accountManager, |
|
| 84 | - IFactory $l10nFactory) { |
|
| 85 | - parent::__construct($appName, $request); |
|
| 77 | + public function __construct(string $appName, |
|
| 78 | + IRequest $request, |
|
| 79 | + IUserManager $userManager, |
|
| 80 | + IConfig $config, |
|
| 81 | + IGroupManager $groupManager, |
|
| 82 | + IUserSession $userSession, |
|
| 83 | + IAccountManager $accountManager, |
|
| 84 | + IFactory $l10nFactory) { |
|
| 85 | + parent::__construct($appName, $request); |
|
| 86 | 86 | |
| 87 | - $this->userManager = $userManager; |
|
| 88 | - $this->config = $config; |
|
| 89 | - $this->groupManager = $groupManager; |
|
| 90 | - $this->userSession = $userSession; |
|
| 91 | - $this->accountManager = $accountManager; |
|
| 92 | - $this->l10nFactory = $l10nFactory; |
|
| 93 | - } |
|
| 87 | + $this->userManager = $userManager; |
|
| 88 | + $this->config = $config; |
|
| 89 | + $this->groupManager = $groupManager; |
|
| 90 | + $this->userSession = $userSession; |
|
| 91 | + $this->accountManager = $accountManager; |
|
| 92 | + $this->l10nFactory = $l10nFactory; |
|
| 93 | + } |
|
| 94 | 94 | |
| 95 | - /** |
|
| 96 | - * creates a array with all user data |
|
| 97 | - * |
|
| 98 | - * @param string $userId |
|
| 99 | - * @param bool $includeScopes |
|
| 100 | - * @return array |
|
| 101 | - * @throws NotFoundException |
|
| 102 | - * @throws OCSException |
|
| 103 | - * @throws OCSNotFoundException |
|
| 104 | - */ |
|
| 105 | - protected function getUserData(string $userId, bool $includeScopes = false): array { |
|
| 106 | - $currentLoggedInUser = $this->userSession->getUser(); |
|
| 107 | - assert($currentLoggedInUser !== null, 'No user logged in'); |
|
| 95 | + /** |
|
| 96 | + * creates a array with all user data |
|
| 97 | + * |
|
| 98 | + * @param string $userId |
|
| 99 | + * @param bool $includeScopes |
|
| 100 | + * @return array |
|
| 101 | + * @throws NotFoundException |
|
| 102 | + * @throws OCSException |
|
| 103 | + * @throws OCSNotFoundException |
|
| 104 | + */ |
|
| 105 | + protected function getUserData(string $userId, bool $includeScopes = false): array { |
|
| 106 | + $currentLoggedInUser = $this->userSession->getUser(); |
|
| 107 | + assert($currentLoggedInUser !== null, 'No user logged in'); |
|
| 108 | 108 | |
| 109 | - $data = []; |
|
| 109 | + $data = []; |
|
| 110 | 110 | |
| 111 | - // Check if the target user exists |
|
| 112 | - $targetUserObject = $this->userManager->get($userId); |
|
| 113 | - if ($targetUserObject === null) { |
|
| 114 | - throw new OCSNotFoundException('User does not exist'); |
|
| 115 | - } |
|
| 111 | + // Check if the target user exists |
|
| 112 | + $targetUserObject = $this->userManager->get($userId); |
|
| 113 | + if ($targetUserObject === null) { |
|
| 114 | + throw new OCSNotFoundException('User does not exist'); |
|
| 115 | + } |
|
| 116 | 116 | |
| 117 | - $isAdmin = $this->groupManager->isAdmin($currentLoggedInUser->getUID()); |
|
| 118 | - if ($isAdmin |
|
| 119 | - || $this->groupManager->getSubAdmin()->isUserAccessible($currentLoggedInUser, $targetUserObject)) { |
|
| 120 | - $data['enabled'] = $this->config->getUserValue($targetUserObject->getUID(), 'core', 'enabled', 'true') === 'true'; |
|
| 121 | - } else { |
|
| 122 | - // Check they are looking up themselves |
|
| 123 | - if ($currentLoggedInUser->getUID() !== $targetUserObject->getUID()) { |
|
| 124 | - return $data; |
|
| 125 | - } |
|
| 126 | - } |
|
| 117 | + $isAdmin = $this->groupManager->isAdmin($currentLoggedInUser->getUID()); |
|
| 118 | + if ($isAdmin |
|
| 119 | + || $this->groupManager->getSubAdmin()->isUserAccessible($currentLoggedInUser, $targetUserObject)) { |
|
| 120 | + $data['enabled'] = $this->config->getUserValue($targetUserObject->getUID(), 'core', 'enabled', 'true') === 'true'; |
|
| 121 | + } else { |
|
| 122 | + // Check they are looking up themselves |
|
| 123 | + if ($currentLoggedInUser->getUID() !== $targetUserObject->getUID()) { |
|
| 124 | + return $data; |
|
| 125 | + } |
|
| 126 | + } |
|
| 127 | 127 | |
| 128 | - // Get groups data |
|
| 129 | - $userAccount = $this->accountManager->getAccount($targetUserObject); |
|
| 130 | - $groups = $this->groupManager->getUserGroups($targetUserObject); |
|
| 131 | - $gids = []; |
|
| 132 | - foreach ($groups as $group) { |
|
| 133 | - $gids[] = $group->getGID(); |
|
| 134 | - } |
|
| 128 | + // Get groups data |
|
| 129 | + $userAccount = $this->accountManager->getAccount($targetUserObject); |
|
| 130 | + $groups = $this->groupManager->getUserGroups($targetUserObject); |
|
| 131 | + $gids = []; |
|
| 132 | + foreach ($groups as $group) { |
|
| 133 | + $gids[] = $group->getGID(); |
|
| 134 | + } |
|
| 135 | 135 | |
| 136 | - if ($isAdmin) { |
|
| 137 | - try { |
|
| 138 | - # might be thrown by LDAP due to handling of users disappears |
|
| 139 | - # from the external source (reasons unknown to us) |
|
| 140 | - # cf. https://github.com/nextcloud/server/issues/12991 |
|
| 141 | - $data['storageLocation'] = $targetUserObject->getHome(); |
|
| 142 | - } catch (NoUserException $e) { |
|
| 143 | - throw new OCSNotFoundException($e->getMessage(), $e); |
|
| 144 | - } |
|
| 145 | - } |
|
| 136 | + if ($isAdmin) { |
|
| 137 | + try { |
|
| 138 | + # might be thrown by LDAP due to handling of users disappears |
|
| 139 | + # from the external source (reasons unknown to us) |
|
| 140 | + # cf. https://github.com/nextcloud/server/issues/12991 |
|
| 141 | + $data['storageLocation'] = $targetUserObject->getHome(); |
|
| 142 | + } catch (NoUserException $e) { |
|
| 143 | + throw new OCSNotFoundException($e->getMessage(), $e); |
|
| 144 | + } |
|
| 145 | + } |
|
| 146 | 146 | |
| 147 | - // Find the data |
|
| 148 | - $data['id'] = $targetUserObject->getUID(); |
|
| 149 | - $data['lastLogin'] = $targetUserObject->getLastLogin() * 1000; |
|
| 150 | - $data['backend'] = $targetUserObject->getBackendClassName(); |
|
| 151 | - $data['subadmin'] = $this->getUserSubAdminGroupsData($targetUserObject->getUID()); |
|
| 152 | - $data[self::USER_FIELD_QUOTA] = $this->fillStorageInfo($targetUserObject->getUID()); |
|
| 147 | + // Find the data |
|
| 148 | + $data['id'] = $targetUserObject->getUID(); |
|
| 149 | + $data['lastLogin'] = $targetUserObject->getLastLogin() * 1000; |
|
| 150 | + $data['backend'] = $targetUserObject->getBackendClassName(); |
|
| 151 | + $data['subadmin'] = $this->getUserSubAdminGroupsData($targetUserObject->getUID()); |
|
| 152 | + $data[self::USER_FIELD_QUOTA] = $this->fillStorageInfo($targetUserObject->getUID()); |
|
| 153 | 153 | |
| 154 | - try { |
|
| 155 | - if ($includeScopes) { |
|
| 156 | - $data[IAccountManager::PROPERTY_AVATAR . self::SCOPE_SUFFIX] = $userAccount->getProperty(IAccountManager::PROPERTY_AVATAR)->getScope(); |
|
| 157 | - } |
|
| 154 | + try { |
|
| 155 | + if ($includeScopes) { |
|
| 156 | + $data[IAccountManager::PROPERTY_AVATAR . self::SCOPE_SUFFIX] = $userAccount->getProperty(IAccountManager::PROPERTY_AVATAR)->getScope(); |
|
| 157 | + } |
|
| 158 | 158 | |
| 159 | - $data[IAccountManager::PROPERTY_EMAIL] = $targetUserObject->getSystemEMailAddress(); |
|
| 160 | - if ($includeScopes) { |
|
| 161 | - $data[IAccountManager::PROPERTY_EMAIL . self::SCOPE_SUFFIX] = $userAccount->getProperty(IAccountManager::PROPERTY_EMAIL)->getScope(); |
|
| 162 | - } |
|
| 159 | + $data[IAccountManager::PROPERTY_EMAIL] = $targetUserObject->getSystemEMailAddress(); |
|
| 160 | + if ($includeScopes) { |
|
| 161 | + $data[IAccountManager::PROPERTY_EMAIL . self::SCOPE_SUFFIX] = $userAccount->getProperty(IAccountManager::PROPERTY_EMAIL)->getScope(); |
|
| 162 | + } |
|
| 163 | 163 | |
| 164 | - $additionalEmails = $additionalEmailScopes = []; |
|
| 165 | - $emailCollection = $userAccount->getPropertyCollection(IAccountManager::COLLECTION_EMAIL); |
|
| 166 | - foreach ($emailCollection->getProperties() as $property) { |
|
| 167 | - $additionalEmails[] = $property->getValue(); |
|
| 168 | - if ($includeScopes) { |
|
| 169 | - $additionalEmailScopes[] = $property->getScope(); |
|
| 170 | - } |
|
| 171 | - } |
|
| 172 | - $data[IAccountManager::COLLECTION_EMAIL] = $additionalEmails; |
|
| 173 | - if ($includeScopes) { |
|
| 174 | - $data[IAccountManager::COLLECTION_EMAIL . self::SCOPE_SUFFIX] = $additionalEmailScopes; |
|
| 175 | - } |
|
| 164 | + $additionalEmails = $additionalEmailScopes = []; |
|
| 165 | + $emailCollection = $userAccount->getPropertyCollection(IAccountManager::COLLECTION_EMAIL); |
|
| 166 | + foreach ($emailCollection->getProperties() as $property) { |
|
| 167 | + $additionalEmails[] = $property->getValue(); |
|
| 168 | + if ($includeScopes) { |
|
| 169 | + $additionalEmailScopes[] = $property->getScope(); |
|
| 170 | + } |
|
| 171 | + } |
|
| 172 | + $data[IAccountManager::COLLECTION_EMAIL] = $additionalEmails; |
|
| 173 | + if ($includeScopes) { |
|
| 174 | + $data[IAccountManager::COLLECTION_EMAIL . self::SCOPE_SUFFIX] = $additionalEmailScopes; |
|
| 175 | + } |
|
| 176 | 176 | |
| 177 | - $data[IAccountManager::PROPERTY_DISPLAYNAME] = $targetUserObject->getDisplayName(); |
|
| 178 | - if ($includeScopes) { |
|
| 179 | - $data[IAccountManager::PROPERTY_DISPLAYNAME . self::SCOPE_SUFFIX] = $userAccount->getProperty(IAccountManager::PROPERTY_DISPLAYNAME)->getScope(); |
|
| 180 | - } |
|
| 177 | + $data[IAccountManager::PROPERTY_DISPLAYNAME] = $targetUserObject->getDisplayName(); |
|
| 178 | + if ($includeScopes) { |
|
| 179 | + $data[IAccountManager::PROPERTY_DISPLAYNAME . self::SCOPE_SUFFIX] = $userAccount->getProperty(IAccountManager::PROPERTY_DISPLAYNAME)->getScope(); |
|
| 180 | + } |
|
| 181 | 181 | |
| 182 | - foreach ([ |
|
| 183 | - IAccountManager::PROPERTY_PHONE, |
|
| 184 | - IAccountManager::PROPERTY_ADDRESS, |
|
| 185 | - IAccountManager::PROPERTY_WEBSITE, |
|
| 186 | - IAccountManager::PROPERTY_TWITTER, |
|
| 187 | - IAccountManager::PROPERTY_FEDIVERSE, |
|
| 188 | - IAccountManager::PROPERTY_ORGANISATION, |
|
| 189 | - IAccountManager::PROPERTY_ROLE, |
|
| 190 | - IAccountManager::PROPERTY_HEADLINE, |
|
| 191 | - IAccountManager::PROPERTY_BIOGRAPHY, |
|
| 192 | - IAccountManager::PROPERTY_PROFILE_ENABLED, |
|
| 193 | - ] as $propertyName) { |
|
| 194 | - $property = $userAccount->getProperty($propertyName); |
|
| 195 | - $data[$propertyName] = $property->getValue(); |
|
| 196 | - if ($includeScopes) { |
|
| 197 | - $data[$propertyName . self::SCOPE_SUFFIX] = $property->getScope(); |
|
| 198 | - } |
|
| 199 | - } |
|
| 200 | - } catch (PropertyDoesNotExistException $e) { |
|
| 201 | - // hard coded properties should exist |
|
| 202 | - throw new OCSException($e->getMessage(), Http::STATUS_INTERNAL_SERVER_ERROR, $e); |
|
| 203 | - } |
|
| 182 | + foreach ([ |
|
| 183 | + IAccountManager::PROPERTY_PHONE, |
|
| 184 | + IAccountManager::PROPERTY_ADDRESS, |
|
| 185 | + IAccountManager::PROPERTY_WEBSITE, |
|
| 186 | + IAccountManager::PROPERTY_TWITTER, |
|
| 187 | + IAccountManager::PROPERTY_FEDIVERSE, |
|
| 188 | + IAccountManager::PROPERTY_ORGANISATION, |
|
| 189 | + IAccountManager::PROPERTY_ROLE, |
|
| 190 | + IAccountManager::PROPERTY_HEADLINE, |
|
| 191 | + IAccountManager::PROPERTY_BIOGRAPHY, |
|
| 192 | + IAccountManager::PROPERTY_PROFILE_ENABLED, |
|
| 193 | + ] as $propertyName) { |
|
| 194 | + $property = $userAccount->getProperty($propertyName); |
|
| 195 | + $data[$propertyName] = $property->getValue(); |
|
| 196 | + if ($includeScopes) { |
|
| 197 | + $data[$propertyName . self::SCOPE_SUFFIX] = $property->getScope(); |
|
| 198 | + } |
|
| 199 | + } |
|
| 200 | + } catch (PropertyDoesNotExistException $e) { |
|
| 201 | + // hard coded properties should exist |
|
| 202 | + throw new OCSException($e->getMessage(), Http::STATUS_INTERNAL_SERVER_ERROR, $e); |
|
| 203 | + } |
|
| 204 | 204 | |
| 205 | - $data['groups'] = $gids; |
|
| 206 | - $data[self::USER_FIELD_LANGUAGE] = $this->l10nFactory->getUserLanguage($targetUserObject); |
|
| 207 | - $data[self::USER_FIELD_LOCALE] = $this->config->getUserValue($targetUserObject->getUID(), 'core', 'locale'); |
|
| 208 | - $data[self::USER_FIELD_NOTIFICATION_EMAIL] = $targetUserObject->getPrimaryEMailAddress(); |
|
| 205 | + $data['groups'] = $gids; |
|
| 206 | + $data[self::USER_FIELD_LANGUAGE] = $this->l10nFactory->getUserLanguage($targetUserObject); |
|
| 207 | + $data[self::USER_FIELD_LOCALE] = $this->config->getUserValue($targetUserObject->getUID(), 'core', 'locale'); |
|
| 208 | + $data[self::USER_FIELD_NOTIFICATION_EMAIL] = $targetUserObject->getPrimaryEMailAddress(); |
|
| 209 | 209 | |
| 210 | - $backend = $targetUserObject->getBackend(); |
|
| 211 | - $data['backendCapabilities'] = [ |
|
| 212 | - 'setDisplayName' => $backend instanceof ISetDisplayNameBackend || $backend->implementsActions(Backend::SET_DISPLAYNAME), |
|
| 213 | - 'setPassword' => $backend instanceof ISetPasswordBackend || $backend->implementsActions(Backend::SET_PASSWORD), |
|
| 214 | - ]; |
|
| 210 | + $backend = $targetUserObject->getBackend(); |
|
| 211 | + $data['backendCapabilities'] = [ |
|
| 212 | + 'setDisplayName' => $backend instanceof ISetDisplayNameBackend || $backend->implementsActions(Backend::SET_DISPLAYNAME), |
|
| 213 | + 'setPassword' => $backend instanceof ISetPasswordBackend || $backend->implementsActions(Backend::SET_PASSWORD), |
|
| 214 | + ]; |
|
| 215 | 215 | |
| 216 | - return $data; |
|
| 217 | - } |
|
| 216 | + return $data; |
|
| 217 | + } |
|
| 218 | 218 | |
| 219 | - /** |
|
| 220 | - * Get the groups a user is a subadmin of |
|
| 221 | - * |
|
| 222 | - * @param string $userId |
|
| 223 | - * @return array |
|
| 224 | - * @throws OCSException |
|
| 225 | - */ |
|
| 226 | - protected function getUserSubAdminGroupsData(string $userId): array { |
|
| 227 | - $user = $this->userManager->get($userId); |
|
| 228 | - // Check if the user exists |
|
| 229 | - if ($user === null) { |
|
| 230 | - throw new OCSNotFoundException('User does not exist'); |
|
| 231 | - } |
|
| 219 | + /** |
|
| 220 | + * Get the groups a user is a subadmin of |
|
| 221 | + * |
|
| 222 | + * @param string $userId |
|
| 223 | + * @return array |
|
| 224 | + * @throws OCSException |
|
| 225 | + */ |
|
| 226 | + protected function getUserSubAdminGroupsData(string $userId): array { |
|
| 227 | + $user = $this->userManager->get($userId); |
|
| 228 | + // Check if the user exists |
|
| 229 | + if ($user === null) { |
|
| 230 | + throw new OCSNotFoundException('User does not exist'); |
|
| 231 | + } |
|
| 232 | 232 | |
| 233 | - // Get the subadmin groups |
|
| 234 | - $subAdminGroups = $this->groupManager->getSubAdmin()->getSubAdminsGroups($user); |
|
| 235 | - $groups = []; |
|
| 236 | - foreach ($subAdminGroups as $key => $group) { |
|
| 237 | - $groups[] = $group->getGID(); |
|
| 238 | - } |
|
| 233 | + // Get the subadmin groups |
|
| 234 | + $subAdminGroups = $this->groupManager->getSubAdmin()->getSubAdminsGroups($user); |
|
| 235 | + $groups = []; |
|
| 236 | + foreach ($subAdminGroups as $key => $group) { |
|
| 237 | + $groups[] = $group->getGID(); |
|
| 238 | + } |
|
| 239 | 239 | |
| 240 | - return $groups; |
|
| 241 | - } |
|
| 240 | + return $groups; |
|
| 241 | + } |
|
| 242 | 242 | |
| 243 | - /** |
|
| 244 | - * @param string $userId |
|
| 245 | - * @return array |
|
| 246 | - * @throws OCSException |
|
| 247 | - */ |
|
| 248 | - protected function fillStorageInfo(string $userId): array { |
|
| 249 | - try { |
|
| 250 | - \OC_Util::tearDownFS(); |
|
| 251 | - \OC_Util::setupFS($userId); |
|
| 252 | - $storage = OC_Helper::getStorageInfo('/', null, true, false); |
|
| 253 | - $data = [ |
|
| 254 | - 'free' => $storage['free'], |
|
| 255 | - 'used' => $storage['used'], |
|
| 256 | - 'total' => $storage['total'], |
|
| 257 | - 'relative' => $storage['relative'], |
|
| 258 | - self::USER_FIELD_QUOTA => $storage['quota'], |
|
| 259 | - ]; |
|
| 260 | - } catch (NotFoundException $ex) { |
|
| 261 | - // User fs is not setup yet |
|
| 262 | - $user = $this->userManager->get($userId); |
|
| 263 | - if ($user === null) { |
|
| 264 | - throw new OCSException('User does not exist', 101); |
|
| 265 | - } |
|
| 266 | - $quota = $user->getQuota(); |
|
| 267 | - if ($quota !== 'none') { |
|
| 268 | - $quota = OC_Helper::computerFileSize($quota); |
|
| 269 | - } |
|
| 270 | - $data = [ |
|
| 271 | - self::USER_FIELD_QUOTA => $quota !== false ? $quota : 'none', |
|
| 272 | - 'used' => 0 |
|
| 273 | - ]; |
|
| 274 | - } catch (\Exception $e) { |
|
| 275 | - \OC::$server->get(\Psr\Log\LoggerInterface::class)->error( |
|
| 276 | - "Could not load storage info for {user}", |
|
| 277 | - [ |
|
| 278 | - 'app' => 'provisioning_api', |
|
| 279 | - 'user' => $userId, |
|
| 280 | - 'exception' => $e, |
|
| 281 | - ] |
|
| 282 | - ); |
|
| 283 | - /* In case the Exception left things in a bad state */ |
|
| 284 | - \OC_Util::tearDownFS(); |
|
| 285 | - return []; |
|
| 286 | - } |
|
| 287 | - return $data; |
|
| 288 | - } |
|
| 243 | + /** |
|
| 244 | + * @param string $userId |
|
| 245 | + * @return array |
|
| 246 | + * @throws OCSException |
|
| 247 | + */ |
|
| 248 | + protected function fillStorageInfo(string $userId): array { |
|
| 249 | + try { |
|
| 250 | + \OC_Util::tearDownFS(); |
|
| 251 | + \OC_Util::setupFS($userId); |
|
| 252 | + $storage = OC_Helper::getStorageInfo('/', null, true, false); |
|
| 253 | + $data = [ |
|
| 254 | + 'free' => $storage['free'], |
|
| 255 | + 'used' => $storage['used'], |
|
| 256 | + 'total' => $storage['total'], |
|
| 257 | + 'relative' => $storage['relative'], |
|
| 258 | + self::USER_FIELD_QUOTA => $storage['quota'], |
|
| 259 | + ]; |
|
| 260 | + } catch (NotFoundException $ex) { |
|
| 261 | + // User fs is not setup yet |
|
| 262 | + $user = $this->userManager->get($userId); |
|
| 263 | + if ($user === null) { |
|
| 264 | + throw new OCSException('User does not exist', 101); |
|
| 265 | + } |
|
| 266 | + $quota = $user->getQuota(); |
|
| 267 | + if ($quota !== 'none') { |
|
| 268 | + $quota = OC_Helper::computerFileSize($quota); |
|
| 269 | + } |
|
| 270 | + $data = [ |
|
| 271 | + self::USER_FIELD_QUOTA => $quota !== false ? $quota : 'none', |
|
| 272 | + 'used' => 0 |
|
| 273 | + ]; |
|
| 274 | + } catch (\Exception $e) { |
|
| 275 | + \OC::$server->get(\Psr\Log\LoggerInterface::class)->error( |
|
| 276 | + "Could not load storage info for {user}", |
|
| 277 | + [ |
|
| 278 | + 'app' => 'provisioning_api', |
|
| 279 | + 'user' => $userId, |
|
| 280 | + 'exception' => $e, |
|
| 281 | + ] |
|
| 282 | + ); |
|
| 283 | + /* In case the Exception left things in a bad state */ |
|
| 284 | + \OC_Util::tearDownFS(); |
|
| 285 | + return []; |
|
| 286 | + } |
|
| 287 | + return $data; |
|
| 288 | + } |
|
| 289 | 289 | } |