@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -declare(strict_types=1); |
|
| 2 | +declare(strict_types = 1); |
|
| 3 | 3 | /** |
| 4 | 4 | * @copyright Copyright (c) 2018 John Molakvoæ (skjnldsv) <[email protected]> |
| 5 | 5 | * |
@@ -45,17 +45,17 @@ discard block |
||
| 45 | 45 | |
| 46 | 46 | // Check if the target user exists |
| 47 | 47 | $targetUserObject = $this->userManager->get($userId); |
| 48 | - if($targetUserObject === null) { |
|
| 48 | + if ($targetUserObject === null) { |
|
| 49 | 49 | throw new OCSNotFoundException('User does not exist'); |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | // Should be at least Admin Or SubAdmin! |
| 53 | - if( $this->groupManager->isAdmin($currentLoggedInUser->getUID()) |
|
| 53 | + if ($this->groupManager->isAdmin($currentLoggedInUser->getUID()) |
|
| 54 | 54 | || $this->groupManager->getSubAdmin()->isUserAccessible($currentLoggedInUser, $targetUserObject)) { |
| 55 | 55 | $data['enabled'] = $this->config->getUserValue($targetUserObject->getUID(), 'core', 'enabled', 'true'); |
| 56 | 56 | } else { |
| 57 | 57 | // Check they are looking up themselves |
| 58 | - if($currentLoggedInUser->getUID() !== $targetUserObject->getUID()) { |
|
| 58 | + if ($currentLoggedInUser->getUID() !== $targetUserObject->getUID()) { |
|
| 59 | 59 | return $data; |
| 60 | 60 | } |
| 61 | 61 | } |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | protected function getUserSubAdminGroupsData(string $userId): array { |
| 98 | 98 | $user = $this->userManager->get($userId); |
| 99 | 99 | // Check if the user exists |
| 100 | - if($user === null) { |
|
| 100 | + if ($user === null) { |
|
| 101 | 101 | throw new OCSNotFoundException('User does not exist'); |
| 102 | 102 | } |
| 103 | 103 | |
@@ -35,152 +35,152 @@ |
||
| 35 | 35 | |
| 36 | 36 | abstract class AUserData extends OCSController { |
| 37 | 37 | |
| 38 | - /** @var IUserManager */ |
|
| 39 | - protected $userManager; |
|
| 40 | - /** @var IConfig */ |
|
| 41 | - protected $config; |
|
| 42 | - /** @var IGroupManager|\OC\Group\Manager */ // FIXME Requires a method that is not on the interface |
|
| 43 | - protected $groupManager; |
|
| 44 | - /** @var IUserSession */ |
|
| 45 | - protected $userSession; |
|
| 46 | - /** @var AccountManager */ |
|
| 47 | - protected $accountManager; |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * @param string $appName |
|
| 51 | - * @param IRequest $request |
|
| 52 | - * @param IUserManager $userManager |
|
| 53 | - * @param IConfig $config |
|
| 54 | - * @param IGroupManager $groupManager |
|
| 55 | - * @param IUserSession $userSession |
|
| 56 | - * @param AccountManager $accountManager |
|
| 57 | - */ |
|
| 58 | - public function __construct(string $appName, |
|
| 59 | - IRequest $request, |
|
| 60 | - IUserManager $userManager, |
|
| 61 | - IConfig $config, |
|
| 62 | - IGroupManager $groupManager, |
|
| 63 | - IUserSession $userSession, |
|
| 64 | - AccountManager $accountManager) { |
|
| 65 | - parent::__construct($appName, $request); |
|
| 66 | - |
|
| 67 | - $this->userManager = $userManager; |
|
| 68 | - $this->config = $config; |
|
| 69 | - $this->groupManager = $groupManager; |
|
| 70 | - $this->userSession = $userSession; |
|
| 71 | - $this->accountManager = $accountManager; |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * creates a array with all user data |
|
| 76 | - * |
|
| 77 | - * @param $userId |
|
| 78 | - * @return array |
|
| 79 | - * @throws OCSException |
|
| 80 | - */ |
|
| 81 | - protected function getUserData(string $userId): array { |
|
| 82 | - $currentLoggedInUser = $this->userSession->getUser(); |
|
| 83 | - |
|
| 84 | - $data = []; |
|
| 85 | - |
|
| 86 | - // Check if the target user exists |
|
| 87 | - $targetUserObject = $this->userManager->get($userId); |
|
| 88 | - if($targetUserObject === null) { |
|
| 89 | - throw new OCSNotFoundException('User does not exist'); |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - // Should be at least Admin Or SubAdmin! |
|
| 93 | - if( $this->groupManager->isAdmin($currentLoggedInUser->getUID()) |
|
| 94 | - || $this->groupManager->getSubAdmin()->isUserAccessible($currentLoggedInUser, $targetUserObject)) { |
|
| 95 | - $data['enabled'] = $this->config->getUserValue($targetUserObject->getUID(), 'core', 'enabled', 'true'); |
|
| 96 | - } else { |
|
| 97 | - // Check they are looking up themselves |
|
| 98 | - if($currentLoggedInUser->getUID() !== $targetUserObject->getUID()) { |
|
| 99 | - return $data; |
|
| 100 | - } |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - // Get groups data |
|
| 104 | - $userAccount = $this->accountManager->getUser($targetUserObject); |
|
| 105 | - $groups = $this->groupManager->getUserGroups($targetUserObject); |
|
| 106 | - $gids = []; |
|
| 107 | - foreach ($groups as $group) { |
|
| 108 | - $gids[] = $group->getDisplayName(); |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - // Find the data |
|
| 112 | - $data['id'] = $targetUserObject->getUID(); |
|
| 113 | - $data['storageLocation'] = $targetUserObject->getHome(); |
|
| 114 | - $data['lastLogin'] = $targetUserObject->getLastLogin() * 1000; |
|
| 115 | - $data['backend'] = $targetUserObject->getBackendClassName(); |
|
| 116 | - $data['subadmin'] = $this->getUserSubAdminGroupsData($targetUserObject->getUID()); |
|
| 117 | - $data['quota'] = $this->fillStorageInfo($targetUserObject->getUID()); |
|
| 118 | - $data[AccountManager::PROPERTY_EMAIL] = $targetUserObject->getEMailAddress(); |
|
| 119 | - $data[AccountManager::PROPERTY_DISPLAYNAME] = $targetUserObject->getDisplayName(); |
|
| 120 | - $data[AccountManager::PROPERTY_PHONE] = $userAccount[AccountManager::PROPERTY_PHONE]['value']; |
|
| 121 | - $data[AccountManager::PROPERTY_ADDRESS] = $userAccount[AccountManager::PROPERTY_ADDRESS]['value']; |
|
| 122 | - $data[AccountManager::PROPERTY_WEBSITE] = $userAccount[AccountManager::PROPERTY_WEBSITE]['value']; |
|
| 123 | - $data[AccountManager::PROPERTY_TWITTER] = $userAccount[AccountManager::PROPERTY_TWITTER]['value']; |
|
| 124 | - $data['groups'] = $gids; |
|
| 125 | - $data['language'] = $this->config->getUserValue($targetUserObject->getUID(), 'core', 'lang'); |
|
| 126 | - |
|
| 127 | - return $data; |
|
| 38 | + /** @var IUserManager */ |
|
| 39 | + protected $userManager; |
|
| 40 | + /** @var IConfig */ |
|
| 41 | + protected $config; |
|
| 42 | + /** @var IGroupManager|\OC\Group\Manager */ // FIXME Requires a method that is not on the interface |
|
| 43 | + protected $groupManager; |
|
| 44 | + /** @var IUserSession */ |
|
| 45 | + protected $userSession; |
|
| 46 | + /** @var AccountManager */ |
|
| 47 | + protected $accountManager; |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * @param string $appName |
|
| 51 | + * @param IRequest $request |
|
| 52 | + * @param IUserManager $userManager |
|
| 53 | + * @param IConfig $config |
|
| 54 | + * @param IGroupManager $groupManager |
|
| 55 | + * @param IUserSession $userSession |
|
| 56 | + * @param AccountManager $accountManager |
|
| 57 | + */ |
|
| 58 | + public function __construct(string $appName, |
|
| 59 | + IRequest $request, |
|
| 60 | + IUserManager $userManager, |
|
| 61 | + IConfig $config, |
|
| 62 | + IGroupManager $groupManager, |
|
| 63 | + IUserSession $userSession, |
|
| 64 | + AccountManager $accountManager) { |
|
| 65 | + parent::__construct($appName, $request); |
|
| 66 | + |
|
| 67 | + $this->userManager = $userManager; |
|
| 68 | + $this->config = $config; |
|
| 69 | + $this->groupManager = $groupManager; |
|
| 70 | + $this->userSession = $userSession; |
|
| 71 | + $this->accountManager = $accountManager; |
|
| 128 | 72 | } |
| 129 | 73 | |
| 130 | - /** |
|
| 131 | - * Get the groups a user is a subadmin of |
|
| 132 | - * |
|
| 133 | - * @param string $userId |
|
| 134 | - * @return array |
|
| 135 | - * @throws OCSException |
|
| 136 | - */ |
|
| 137 | - protected function getUserSubAdminGroupsData(string $userId): array { |
|
| 138 | - $user = $this->userManager->get($userId); |
|
| 139 | - // Check if the user exists |
|
| 140 | - if($user === null) { |
|
| 141 | - throw new OCSNotFoundException('User does not exist'); |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - // Get the subadmin groups |
|
| 145 | - $subAdminGroups = $this->groupManager->getSubAdmin()->getSubAdminsGroups($user); |
|
| 146 | - $groups = []; |
|
| 147 | - foreach ($subAdminGroups as $key => $group) { |
|
| 148 | - $groups[] = $group->getGID(); |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - return $groups; |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - /** |
|
| 155 | - * @param string $userId |
|
| 156 | - * @return array |
|
| 157 | - * @throws \OCP\Files\NotFoundException |
|
| 158 | - */ |
|
| 159 | - protected function fillStorageInfo(string $userId): array { |
|
| 160 | - try { |
|
| 161 | - \OC_Util::tearDownFS(); |
|
| 162 | - \OC_Util::setupFS($userId); |
|
| 163 | - $storage = OC_Helper::getStorageInfo('/'); |
|
| 164 | - $data = [ |
|
| 165 | - 'free' => $storage['free'], |
|
| 166 | - 'used' => $storage['used'], |
|
| 167 | - 'total' => $storage['total'], |
|
| 168 | - 'relative' => $storage['relative'], |
|
| 169 | - 'quota' => $storage['quota'], |
|
| 170 | - ]; |
|
| 171 | - } catch (NotFoundException $ex) { |
|
| 172 | - // User fs is not setup yet |
|
| 173 | - $user = $this->userManager->get($userId); |
|
| 174 | - if ($user === null) { |
|
| 175 | - throw new OCSException('User does not exist', 101); |
|
| 176 | - } |
|
| 177 | - $quota = OC_Helper::computerFileSize($user->getQuota()); |
|
| 178 | - $data = [ |
|
| 179 | - 'quota' => $quota ? $quota : 'none', |
|
| 180 | - 'used' => 0 |
|
| 181 | - ]; |
|
| 182 | - } |
|
| 183 | - return $data; |
|
| 184 | - } |
|
| 74 | + /** |
|
| 75 | + * creates a array with all user data |
|
| 76 | + * |
|
| 77 | + * @param $userId |
|
| 78 | + * @return array |
|
| 79 | + * @throws OCSException |
|
| 80 | + */ |
|
| 81 | + protected function getUserData(string $userId): array { |
|
| 82 | + $currentLoggedInUser = $this->userSession->getUser(); |
|
| 83 | + |
|
| 84 | + $data = []; |
|
| 85 | + |
|
| 86 | + // Check if the target user exists |
|
| 87 | + $targetUserObject = $this->userManager->get($userId); |
|
| 88 | + if($targetUserObject === null) { |
|
| 89 | + throw new OCSNotFoundException('User does not exist'); |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + // Should be at least Admin Or SubAdmin! |
|
| 93 | + if( $this->groupManager->isAdmin($currentLoggedInUser->getUID()) |
|
| 94 | + || $this->groupManager->getSubAdmin()->isUserAccessible($currentLoggedInUser, $targetUserObject)) { |
|
| 95 | + $data['enabled'] = $this->config->getUserValue($targetUserObject->getUID(), 'core', 'enabled', 'true'); |
|
| 96 | + } else { |
|
| 97 | + // Check they are looking up themselves |
|
| 98 | + if($currentLoggedInUser->getUID() !== $targetUserObject->getUID()) { |
|
| 99 | + return $data; |
|
| 100 | + } |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + // Get groups data |
|
| 104 | + $userAccount = $this->accountManager->getUser($targetUserObject); |
|
| 105 | + $groups = $this->groupManager->getUserGroups($targetUserObject); |
|
| 106 | + $gids = []; |
|
| 107 | + foreach ($groups as $group) { |
|
| 108 | + $gids[] = $group->getDisplayName(); |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + // Find the data |
|
| 112 | + $data['id'] = $targetUserObject->getUID(); |
|
| 113 | + $data['storageLocation'] = $targetUserObject->getHome(); |
|
| 114 | + $data['lastLogin'] = $targetUserObject->getLastLogin() * 1000; |
|
| 115 | + $data['backend'] = $targetUserObject->getBackendClassName(); |
|
| 116 | + $data['subadmin'] = $this->getUserSubAdminGroupsData($targetUserObject->getUID()); |
|
| 117 | + $data['quota'] = $this->fillStorageInfo($targetUserObject->getUID()); |
|
| 118 | + $data[AccountManager::PROPERTY_EMAIL] = $targetUserObject->getEMailAddress(); |
|
| 119 | + $data[AccountManager::PROPERTY_DISPLAYNAME] = $targetUserObject->getDisplayName(); |
|
| 120 | + $data[AccountManager::PROPERTY_PHONE] = $userAccount[AccountManager::PROPERTY_PHONE]['value']; |
|
| 121 | + $data[AccountManager::PROPERTY_ADDRESS] = $userAccount[AccountManager::PROPERTY_ADDRESS]['value']; |
|
| 122 | + $data[AccountManager::PROPERTY_WEBSITE] = $userAccount[AccountManager::PROPERTY_WEBSITE]['value']; |
|
| 123 | + $data[AccountManager::PROPERTY_TWITTER] = $userAccount[AccountManager::PROPERTY_TWITTER]['value']; |
|
| 124 | + $data['groups'] = $gids; |
|
| 125 | + $data['language'] = $this->config->getUserValue($targetUserObject->getUID(), 'core', 'lang'); |
|
| 126 | + |
|
| 127 | + return $data; |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + /** |
|
| 131 | + * Get the groups a user is a subadmin of |
|
| 132 | + * |
|
| 133 | + * @param string $userId |
|
| 134 | + * @return array |
|
| 135 | + * @throws OCSException |
|
| 136 | + */ |
|
| 137 | + protected function getUserSubAdminGroupsData(string $userId): array { |
|
| 138 | + $user = $this->userManager->get($userId); |
|
| 139 | + // Check if the user exists |
|
| 140 | + if($user === null) { |
|
| 141 | + throw new OCSNotFoundException('User does not exist'); |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + // Get the subadmin groups |
|
| 145 | + $subAdminGroups = $this->groupManager->getSubAdmin()->getSubAdminsGroups($user); |
|
| 146 | + $groups = []; |
|
| 147 | + foreach ($subAdminGroups as $key => $group) { |
|
| 148 | + $groups[] = $group->getGID(); |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + return $groups; |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + /** |
|
| 155 | + * @param string $userId |
|
| 156 | + * @return array |
|
| 157 | + * @throws \OCP\Files\NotFoundException |
|
| 158 | + */ |
|
| 159 | + protected function fillStorageInfo(string $userId): array { |
|
| 160 | + try { |
|
| 161 | + \OC_Util::tearDownFS(); |
|
| 162 | + \OC_Util::setupFS($userId); |
|
| 163 | + $storage = OC_Helper::getStorageInfo('/'); |
|
| 164 | + $data = [ |
|
| 165 | + 'free' => $storage['free'], |
|
| 166 | + 'used' => $storage['used'], |
|
| 167 | + 'total' => $storage['total'], |
|
| 168 | + 'relative' => $storage['relative'], |
|
| 169 | + 'quota' => $storage['quota'], |
|
| 170 | + ]; |
|
| 171 | + } catch (NotFoundException $ex) { |
|
| 172 | + // User fs is not setup yet |
|
| 173 | + $user = $this->userManager->get($userId); |
|
| 174 | + if ($user === null) { |
|
| 175 | + throw new OCSException('User does not exist', 101); |
|
| 176 | + } |
|
| 177 | + $quota = OC_Helper::computerFileSize($user->getQuota()); |
|
| 178 | + $data = [ |
|
| 179 | + 'quota' => $quota ? $quota : 'none', |
|
| 180 | + 'used' => 0 |
|
| 181 | + ]; |
|
| 182 | + } |
|
| 183 | + return $data; |
|
| 184 | + } |
|
| 185 | 185 | |
| 186 | 186 | } |