@@ -25,43 +25,43 @@ |
||
| 25 | 25 | */ |
| 26 | 26 | |
| 27 | 27 | return [ |
| 28 | - 'ocs' => [ |
|
| 29 | - // Apps |
|
| 30 | - ['root' => '/cloud', 'name' => 'Apps#getApps', 'url' => '/apps', 'verb' => 'GET'], |
|
| 31 | - ['root' => '/cloud', 'name' => 'Apps#getAppInfo', 'url' => '/apps/{app}', 'verb' => 'GET'], |
|
| 32 | - ['root' => '/cloud', 'name' => 'Apps#enable', 'url' => '/apps/{app}', 'verb' => 'POST'], |
|
| 33 | - ['root' => '/cloud', 'name' => 'Apps#disable', 'url' => '/apps/{app}', 'verb' => 'DELETE'], |
|
| 28 | + 'ocs' => [ |
|
| 29 | + // Apps |
|
| 30 | + ['root' => '/cloud', 'name' => 'Apps#getApps', 'url' => '/apps', 'verb' => 'GET'], |
|
| 31 | + ['root' => '/cloud', 'name' => 'Apps#getAppInfo', 'url' => '/apps/{app}', 'verb' => 'GET'], |
|
| 32 | + ['root' => '/cloud', 'name' => 'Apps#enable', 'url' => '/apps/{app}', 'verb' => 'POST'], |
|
| 33 | + ['root' => '/cloud', 'name' => 'Apps#disable', 'url' => '/apps/{app}', 'verb' => 'DELETE'], |
|
| 34 | 34 | |
| 35 | - // Groups |
|
| 36 | - ['root' => '/cloud', 'name' => 'Groups#getGroups', 'url' => '/groups', 'verb' => 'GET'], |
|
| 37 | - ['root' => '/cloud', 'name' => 'Groups#getGroup', 'url' => '/groups/{groupId}', 'verb' => 'GET'], |
|
| 38 | - ['root' => '/cloud', 'name' => 'Groups#addGroup', 'url' => '/groups', 'verb' => 'POST'], |
|
| 39 | - ['root' => '/cloud', 'name' => 'Groups#deleteGroup', 'url' => '/groups/{groupId}', 'verb' => 'DELETE'], |
|
| 40 | - ['root' => '/cloud', 'name' => 'Groups#getSubAdminsOfGroup', 'url' => '/groups/{groupId}/subadmins', 'verb' => 'GET'], |
|
| 35 | + // Groups |
|
| 36 | + ['root' => '/cloud', 'name' => 'Groups#getGroups', 'url' => '/groups', 'verb' => 'GET'], |
|
| 37 | + ['root' => '/cloud', 'name' => 'Groups#getGroup', 'url' => '/groups/{groupId}', 'verb' => 'GET'], |
|
| 38 | + ['root' => '/cloud', 'name' => 'Groups#addGroup', 'url' => '/groups', 'verb' => 'POST'], |
|
| 39 | + ['root' => '/cloud', 'name' => 'Groups#deleteGroup', 'url' => '/groups/{groupId}', 'verb' => 'DELETE'], |
|
| 40 | + ['root' => '/cloud', 'name' => 'Groups#getSubAdminsOfGroup', 'url' => '/groups/{groupId}/subadmins', 'verb' => 'GET'], |
|
| 41 | 41 | |
| 42 | - // Users |
|
| 43 | - ['root' => '/cloud', 'name' => 'Users#getUsers', 'url' => '/users', 'verb' => 'GET'], |
|
| 44 | - ['root' => '/cloud', 'name' => 'Users#addUser', 'url' => '/users', 'verb' => 'POST'], |
|
| 45 | - ['root' => '/cloud', 'name' => 'Users#getUser', 'url' => '/users/{userId}', 'verb' => 'GET'], |
|
| 46 | - ['root' => '/cloud', 'name' => 'Users#getCurrentUser', 'url' => '/user', 'verb' => 'GET'], |
|
| 47 | - ['root' => '/cloud', 'name' => 'Users#getEditableFields', 'url' => '/user/fields', 'verb' => 'GET'], |
|
| 48 | - ['root' => '/cloud', 'name' => 'Users#editUser', 'url' => '/users/{userId}', 'verb' => 'PUT'], |
|
| 49 | - ['root' => '/cloud', 'name' => 'Users#deleteUser', 'url' => '/users/{userId}', 'verb' => 'DELETE'], |
|
| 50 | - ['root' => '/cloud', 'name' => 'Users#enableUser', 'url' => '/users/{userId}/enable', 'verb' => 'PUT'], |
|
| 51 | - ['root' => '/cloud', 'name' => 'Users#disableUser', 'url' => '/users/{userId}/disable', 'verb' => 'PUT'], |
|
| 52 | - ['root' => '/cloud', 'name' => 'Users#getUsersGroups', 'url' => '/users/{userId}/groups', 'verb' => 'GET'], |
|
| 53 | - ['root' => '/cloud', 'name' => 'Users#addToGroup', 'url' => '/users/{userId}/groups', 'verb' => 'POST'], |
|
| 54 | - ['root' => '/cloud', 'name' => 'Users#removeFromGroup', 'url' => '/users/{userId}/groups', 'verb' => 'DELETE'], |
|
| 55 | - ['root' => '/cloud', 'name' => 'Users#getUserSubAdminGroups', 'url' => '/users/{userId}/subadmins', 'verb' => 'GET'], |
|
| 56 | - ['root' => '/cloud', 'name' => 'Users#addSubAdmin', 'url' => '/users/{userId}/subadmins', 'verb' => 'POST'], |
|
| 57 | - ['root' => '/cloud', 'name' => 'Users#removeSubAdmin', 'url' => '/users/{userId}/subadmins', 'verb' => 'DELETE'], |
|
| 58 | - ['root' => '/cloud', 'name' => 'Users#resendWelcomeMessage', 'url' => '/users/{userId}/welcome', 'verb' => 'POST'], |
|
| 42 | + // Users |
|
| 43 | + ['root' => '/cloud', 'name' => 'Users#getUsers', 'url' => '/users', 'verb' => 'GET'], |
|
| 44 | + ['root' => '/cloud', 'name' => 'Users#addUser', 'url' => '/users', 'verb' => 'POST'], |
|
| 45 | + ['root' => '/cloud', 'name' => 'Users#getUser', 'url' => '/users/{userId}', 'verb' => 'GET'], |
|
| 46 | + ['root' => '/cloud', 'name' => 'Users#getCurrentUser', 'url' => '/user', 'verb' => 'GET'], |
|
| 47 | + ['root' => '/cloud', 'name' => 'Users#getEditableFields', 'url' => '/user/fields', 'verb' => 'GET'], |
|
| 48 | + ['root' => '/cloud', 'name' => 'Users#editUser', 'url' => '/users/{userId}', 'verb' => 'PUT'], |
|
| 49 | + ['root' => '/cloud', 'name' => 'Users#deleteUser', 'url' => '/users/{userId}', 'verb' => 'DELETE'], |
|
| 50 | + ['root' => '/cloud', 'name' => 'Users#enableUser', 'url' => '/users/{userId}/enable', 'verb' => 'PUT'], |
|
| 51 | + ['root' => '/cloud', 'name' => 'Users#disableUser', 'url' => '/users/{userId}/disable', 'verb' => 'PUT'], |
|
| 52 | + ['root' => '/cloud', 'name' => 'Users#getUsersGroups', 'url' => '/users/{userId}/groups', 'verb' => 'GET'], |
|
| 53 | + ['root' => '/cloud', 'name' => 'Users#addToGroup', 'url' => '/users/{userId}/groups', 'verb' => 'POST'], |
|
| 54 | + ['root' => '/cloud', 'name' => 'Users#removeFromGroup', 'url' => '/users/{userId}/groups', 'verb' => 'DELETE'], |
|
| 55 | + ['root' => '/cloud', 'name' => 'Users#getUserSubAdminGroups', 'url' => '/users/{userId}/subadmins', 'verb' => 'GET'], |
|
| 56 | + ['root' => '/cloud', 'name' => 'Users#addSubAdmin', 'url' => '/users/{userId}/subadmins', 'verb' => 'POST'], |
|
| 57 | + ['root' => '/cloud', 'name' => 'Users#removeSubAdmin', 'url' => '/users/{userId}/subadmins', 'verb' => 'DELETE'], |
|
| 58 | + ['root' => '/cloud', 'name' => 'Users#resendWelcomeMessage', 'url' => '/users/{userId}/welcome', 'verb' => 'POST'], |
|
| 59 | 59 | |
| 60 | - // Config |
|
| 61 | - ['name' => 'AppConfig#getApps', 'url' => '/api/v1/config/apps', 'verb' => 'GET'], |
|
| 62 | - ['name' => 'AppConfig#getKeys', 'url' => '/api/v1/config/apps/{app}', 'verb' => 'GET'], |
|
| 63 | - ['name' => 'AppConfig#getValue', 'url' => '/api/v1/config/apps/{app}/{key}', 'verb' => 'GET'], |
|
| 64 | - ['name' => 'AppConfig#setValue', 'url' => '/api/v1/config/apps/{app}/{key}', 'verb' => 'POST'], |
|
| 65 | - ['name' => 'AppConfig#deleteKey', 'url' => '/api/v1/config/apps/{app}/{key}', 'verb' => 'DELETE'], |
|
| 66 | - ], |
|
| 60 | + // Config |
|
| 61 | + ['name' => 'AppConfig#getApps', 'url' => '/api/v1/config/apps', 'verb' => 'GET'], |
|
| 62 | + ['name' => 'AppConfig#getKeys', 'url' => '/api/v1/config/apps/{app}', 'verb' => 'GET'], |
|
| 63 | + ['name' => 'AppConfig#getValue', 'url' => '/api/v1/config/apps/{app}/{key}', 'verb' => 'GET'], |
|
| 64 | + ['name' => 'AppConfig#setValue', 'url' => '/api/v1/config/apps/{app}/{key}', 'verb' => 'POST'], |
|
| 65 | + ['name' => 'AppConfig#deleteKey', 'url' => '/api/v1/config/apps/{app}/{key}', 'verb' => 'DELETE'], |
|
| 66 | + ], |
|
| 67 | 67 | ]; |
@@ -6,12 +6,12 @@ |
||
| 6 | 6 | $baseDir = $vendorDir; |
| 7 | 7 | |
| 8 | 8 | return array( |
| 9 | - 'OCA\\Provisioning_API\\AppInfo\\Application' => $baseDir . '/../lib/AppInfo/Application.php', |
|
| 10 | - 'OCA\\Provisioning_API\\Controller\\AppConfigController' => $baseDir . '/../lib/Controller/AppConfigController.php', |
|
| 11 | - 'OCA\\Provisioning_API\\Controller\\AppsController' => $baseDir . '/../lib/Controller/AppsController.php', |
|
| 12 | - 'OCA\\Provisioning_API\\Controller\\GroupsController' => $baseDir . '/../lib/Controller/GroupsController.php', |
|
| 13 | - 'OCA\\Provisioning_API\\Controller\\UsersController' => $baseDir . '/../lib/Controller/UsersController.php', |
|
| 14 | - 'OCA\\Provisioning_API\\FederatedFileSharingFactory' => $baseDir . '/../lib/FederatedFileSharingFactory.php', |
|
| 15 | - 'OCA\\Provisioning_API\\Middleware\\Exceptions\\NotSubAdminException' => $baseDir . '/../lib/Middleware/Exceptions/NotSubAdminException.php', |
|
| 16 | - 'OCA\\Provisioning_API\\Middleware\\ProvisioningApiMiddleware' => $baseDir . '/../lib/Middleware/ProvisioningApiMiddleware.php', |
|
| 9 | + 'OCA\\Provisioning_API\\AppInfo\\Application' => $baseDir.'/../lib/AppInfo/Application.php', |
|
| 10 | + 'OCA\\Provisioning_API\\Controller\\AppConfigController' => $baseDir.'/../lib/Controller/AppConfigController.php', |
|
| 11 | + 'OCA\\Provisioning_API\\Controller\\AppsController' => $baseDir.'/../lib/Controller/AppsController.php', |
|
| 12 | + 'OCA\\Provisioning_API\\Controller\\GroupsController' => $baseDir.'/../lib/Controller/GroupsController.php', |
|
| 13 | + 'OCA\\Provisioning_API\\Controller\\UsersController' => $baseDir.'/../lib/Controller/UsersController.php', |
|
| 14 | + 'OCA\\Provisioning_API\\FederatedFileSharingFactory' => $baseDir.'/../lib/FederatedFileSharingFactory.php', |
|
| 15 | + 'OCA\\Provisioning_API\\Middleware\\Exceptions\\NotSubAdminException' => $baseDir.'/../lib/Middleware/Exceptions/NotSubAdminException.php', |
|
| 16 | + 'OCA\\Provisioning_API\\Middleware\\ProvisioningApiMiddleware' => $baseDir.'/../lib/Middleware/ProvisioningApiMiddleware.php', |
|
| 17 | 17 | ); |
@@ -6,34 +6,34 @@ |
||
| 6 | 6 | |
| 7 | 7 | class ComposerStaticInitProvisioning_API |
| 8 | 8 | { |
| 9 | - public static $prefixLengthsPsr4 = array ( |
|
| 9 | + public static $prefixLengthsPsr4 = array( |
|
| 10 | 10 | 'O' => |
| 11 | - array ( |
|
| 11 | + array( |
|
| 12 | 12 | 'OCA\\Provisioning_API\\' => 21, |
| 13 | 13 | ), |
| 14 | 14 | ); |
| 15 | 15 | |
| 16 | - public static $prefixDirsPsr4 = array ( |
|
| 16 | + public static $prefixDirsPsr4 = array( |
|
| 17 | 17 | 'OCA\\Provisioning_API\\' => |
| 18 | - array ( |
|
| 19 | - 0 => __DIR__ . '/..' . '/../lib', |
|
| 18 | + array( |
|
| 19 | + 0 => __DIR__.'/..'.'/../lib', |
|
| 20 | 20 | ), |
| 21 | 21 | ); |
| 22 | 22 | |
| 23 | - public static $classMap = array ( |
|
| 24 | - 'OCA\\Provisioning_API\\AppInfo\\Application' => __DIR__ . '/..' . '/../lib/AppInfo/Application.php', |
|
| 25 | - 'OCA\\Provisioning_API\\Controller\\AppConfigController' => __DIR__ . '/..' . '/../lib/Controller/AppConfigController.php', |
|
| 26 | - 'OCA\\Provisioning_API\\Controller\\AppsController' => __DIR__ . '/..' . '/../lib/Controller/AppsController.php', |
|
| 27 | - 'OCA\\Provisioning_API\\Controller\\GroupsController' => __DIR__ . '/..' . '/../lib/Controller/GroupsController.php', |
|
| 28 | - 'OCA\\Provisioning_API\\Controller\\UsersController' => __DIR__ . '/..' . '/../lib/Controller/UsersController.php', |
|
| 29 | - 'OCA\\Provisioning_API\\FederatedFileSharingFactory' => __DIR__ . '/..' . '/../lib/FederatedFileSharingFactory.php', |
|
| 30 | - 'OCA\\Provisioning_API\\Middleware\\Exceptions\\NotSubAdminException' => __DIR__ . '/..' . '/../lib/Middleware/Exceptions/NotSubAdminException.php', |
|
| 31 | - 'OCA\\Provisioning_API\\Middleware\\ProvisioningApiMiddleware' => __DIR__ . '/..' . '/../lib/Middleware/ProvisioningApiMiddleware.php', |
|
| 23 | + public static $classMap = array( |
|
| 24 | + 'OCA\\Provisioning_API\\AppInfo\\Application' => __DIR__.'/..'.'/../lib/AppInfo/Application.php', |
|
| 25 | + 'OCA\\Provisioning_API\\Controller\\AppConfigController' => __DIR__.'/..'.'/../lib/Controller/AppConfigController.php', |
|
| 26 | + 'OCA\\Provisioning_API\\Controller\\AppsController' => __DIR__.'/..'.'/../lib/Controller/AppsController.php', |
|
| 27 | + 'OCA\\Provisioning_API\\Controller\\GroupsController' => __DIR__.'/..'.'/../lib/Controller/GroupsController.php', |
|
| 28 | + 'OCA\\Provisioning_API\\Controller\\UsersController' => __DIR__.'/..'.'/../lib/Controller/UsersController.php', |
|
| 29 | + 'OCA\\Provisioning_API\\FederatedFileSharingFactory' => __DIR__.'/..'.'/../lib/FederatedFileSharingFactory.php', |
|
| 30 | + 'OCA\\Provisioning_API\\Middleware\\Exceptions\\NotSubAdminException' => __DIR__.'/..'.'/../lib/Middleware/Exceptions/NotSubAdminException.php', |
|
| 31 | + 'OCA\\Provisioning_API\\Middleware\\ProvisioningApiMiddleware' => __DIR__.'/..'.'/../lib/Middleware/ProvisioningApiMiddleware.php', |
|
| 32 | 32 | ); |
| 33 | 33 | |
| 34 | 34 | public static function getInitializer(ClassLoader $loader) |
| 35 | 35 | { |
| 36 | - return \Closure::bind(function () use ($loader) { |
|
| 36 | + return \Closure::bind(function() use ($loader) { |
|
| 37 | 37 | $loader->prefixLengthsPsr4 = ComposerStaticInitProvisioning_API::$prefixLengthsPsr4; |
| 38 | 38 | $loader->prefixDirsPsr4 = ComposerStaticInitProvisioning_API::$prefixDirsPsr4; |
| 39 | 39 | $loader->classMap = ComposerStaticInitProvisioning_API::$classMap; |
@@ -27,7 +27,7 @@ |
||
| 27 | 27 | use OCA\FederatedFileSharing\AppInfo\Application; |
| 28 | 28 | |
| 29 | 29 | class FederatedFileSharingFactory { |
| 30 | - public function get(): Application { |
|
| 31 | - return new Application(); |
|
| 32 | - } |
|
| 30 | + public function get(): Application { |
|
| 31 | + return new Application(); |
|
| 32 | + } |
|
| 33 | 33 | } |
@@ -20,7 +20,7 @@ |
||
| 20 | 20 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 21 | 21 | * |
| 22 | 22 | */ |
| 23 | -declare(strict_types=1); |
|
| 23 | +declare(strict_types = 1); |
|
| 24 | 24 | |
| 25 | 25 | namespace OCA\Provisioning_API; |
| 26 | 26 | |
@@ -51,826 +51,826 @@ |
||
| 51 | 51 | |
| 52 | 52 | class UsersController extends OCSController { |
| 53 | 53 | |
| 54 | - /** @var IUserManager */ |
|
| 55 | - private $userManager; |
|
| 56 | - /** @var IConfig */ |
|
| 57 | - private $config; |
|
| 58 | - /** @var IAppManager */ |
|
| 59 | - private $appManager; |
|
| 60 | - /** @var IGroupManager|\OC\Group\Manager */ // FIXME Requires a method that is not on the interface |
|
| 61 | - private $groupManager; |
|
| 62 | - /** @var IUserSession */ |
|
| 63 | - private $userSession; |
|
| 64 | - /** @var AccountManager */ |
|
| 65 | - private $accountManager; |
|
| 66 | - /** @var ILogger */ |
|
| 67 | - private $logger; |
|
| 68 | - /** @var IFactory */ |
|
| 69 | - private $l10nFactory; |
|
| 70 | - /** @var NewUserMailHelper */ |
|
| 71 | - private $newUserMailHelper; |
|
| 72 | - /** @var FederatedFileSharingFactory */ |
|
| 73 | - private $federatedFileSharingFactory; |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * @param string $appName |
|
| 77 | - * @param IRequest $request |
|
| 78 | - * @param IUserManager $userManager |
|
| 79 | - * @param IConfig $config |
|
| 80 | - * @param IAppManager $appManager |
|
| 81 | - * @param IGroupManager $groupManager |
|
| 82 | - * @param IUserSession $userSession |
|
| 83 | - * @param AccountManager $accountManager |
|
| 84 | - * @param ILogger $logger |
|
| 85 | - * @param IFactory $l10nFactory |
|
| 86 | - * @param NewUserMailHelper $newUserMailHelper |
|
| 87 | - * @param FederatedFileSharingFactory $federatedFileSharingFactory |
|
| 88 | - */ |
|
| 89 | - public function __construct($appName, |
|
| 90 | - IRequest $request, |
|
| 91 | - IUserManager $userManager, |
|
| 92 | - IConfig $config, |
|
| 93 | - IAppManager $appManager, |
|
| 94 | - IGroupManager $groupManager, |
|
| 95 | - IUserSession $userSession, |
|
| 96 | - AccountManager $accountManager, |
|
| 97 | - ILogger $logger, |
|
| 98 | - IFactory $l10nFactory, |
|
| 99 | - NewUserMailHelper $newUserMailHelper, |
|
| 100 | - FederatedFileSharingFactory $federatedFileSharingFactory) { |
|
| 101 | - parent::__construct($appName, $request); |
|
| 102 | - |
|
| 103 | - $this->userManager = $userManager; |
|
| 104 | - $this->config = $config; |
|
| 105 | - $this->appManager = $appManager; |
|
| 106 | - $this->groupManager = $groupManager; |
|
| 107 | - $this->userSession = $userSession; |
|
| 108 | - $this->accountManager = $accountManager; |
|
| 109 | - $this->logger = $logger; |
|
| 110 | - $this->l10nFactory = $l10nFactory; |
|
| 111 | - $this->newUserMailHelper = $newUserMailHelper; |
|
| 112 | - $this->federatedFileSharingFactory = $federatedFileSharingFactory; |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * @NoAdminRequired |
|
| 117 | - * |
|
| 118 | - * returns a list of users |
|
| 119 | - * |
|
| 120 | - * @param string $search |
|
| 121 | - * @param int $limit |
|
| 122 | - * @param int $offset |
|
| 123 | - * @return DataResponse |
|
| 124 | - */ |
|
| 125 | - public function getUsers($search = '', $limit = null, $offset = null) { |
|
| 126 | - $user = $this->userSession->getUser(); |
|
| 127 | - $users = []; |
|
| 128 | - |
|
| 129 | - // Admin? Or SubAdmin? |
|
| 130 | - $uid = $user->getUID(); |
|
| 131 | - $subAdminManager = $this->groupManager->getSubAdmin(); |
|
| 132 | - if($this->groupManager->isAdmin($uid)){ |
|
| 133 | - $users = $this->userManager->search($search, $limit, $offset); |
|
| 134 | - } else if ($subAdminManager->isSubAdmin($user)) { |
|
| 135 | - $subAdminOfGroups = $subAdminManager->getSubAdminsGroups($user); |
|
| 136 | - foreach ($subAdminOfGroups as $key => $group) { |
|
| 137 | - $subAdminOfGroups[$key] = $group->getGID(); |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - if($offset === null) { |
|
| 141 | - $offset = 0; |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - $users = []; |
|
| 145 | - foreach ($subAdminOfGroups as $group) { |
|
| 146 | - $users = array_merge($users, $this->groupManager->displayNamesInGroup($group, $search)); |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - $users = array_slice($users, $offset, $limit); |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - $users = array_keys($users); |
|
| 153 | - |
|
| 154 | - return new DataResponse([ |
|
| 155 | - 'users' => $users |
|
| 156 | - ]); |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - /** |
|
| 160 | - * @PasswordConfirmationRequired |
|
| 161 | - * @NoAdminRequired |
|
| 162 | - * |
|
| 163 | - * @param string $userid |
|
| 164 | - * @param string $password |
|
| 165 | - * @param array $groups |
|
| 166 | - * @return DataResponse |
|
| 167 | - * @throws OCSException |
|
| 168 | - */ |
|
| 169 | - public function addUser($userid, $password, $groups = null) { |
|
| 170 | - $user = $this->userSession->getUser(); |
|
| 171 | - $isAdmin = $this->groupManager->isAdmin($user->getUID()); |
|
| 172 | - $subAdminManager = $this->groupManager->getSubAdmin(); |
|
| 173 | - |
|
| 174 | - if($this->userManager->userExists($userid)) { |
|
| 175 | - $this->logger->error('Failed addUser attempt: User already exists.', ['app' => 'ocs_api']); |
|
| 176 | - throw new OCSException('User already exists', 102); |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - if(is_array($groups)) { |
|
| 180 | - foreach ($groups as $group) { |
|
| 181 | - if(!$this->groupManager->groupExists($group)) { |
|
| 182 | - throw new OCSException('group '.$group.' does not exist', 104); |
|
| 183 | - } |
|
| 184 | - if(!$isAdmin && !$subAdminManager->isSubAdminofGroup($user, $this->groupManager->get($group))) { |
|
| 185 | - throw new OCSException('insufficient privileges for group '. $group, 105); |
|
| 186 | - } |
|
| 187 | - } |
|
| 188 | - } else { |
|
| 189 | - if(!$isAdmin) { |
|
| 190 | - throw new OCSException('no group specified (required for subadmins)', 106); |
|
| 191 | - } |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - try { |
|
| 195 | - $newUser = $this->userManager->createUser($userid, $password); |
|
| 196 | - $this->logger->info('Successful addUser call with userid: '.$userid, ['app' => 'ocs_api']); |
|
| 197 | - |
|
| 198 | - if (is_array($groups)) { |
|
| 199 | - foreach ($groups as $group) { |
|
| 200 | - $this->groupManager->get($group)->addUser($newUser); |
|
| 201 | - $this->logger->info('Added userid '.$userid.' to group '.$group, ['app' => 'ocs_api']); |
|
| 202 | - } |
|
| 203 | - } |
|
| 204 | - return new DataResponse(); |
|
| 205 | - } catch (\Exception $e) { |
|
| 206 | - $this->logger->logException($e, [ |
|
| 207 | - 'message' => 'Failed addUser attempt with exception.', |
|
| 208 | - 'level' => \OCP\Util::ERROR, |
|
| 209 | - 'app' => 'ocs_api', |
|
| 210 | - ]); |
|
| 211 | - throw new OCSException('Bad request', 101); |
|
| 212 | - } |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - /** |
|
| 216 | - * @NoAdminRequired |
|
| 217 | - * @NoSubAdminRequired |
|
| 218 | - * |
|
| 219 | - * gets user info |
|
| 220 | - * |
|
| 221 | - * @param string $userId |
|
| 222 | - * @return DataResponse |
|
| 223 | - * @throws OCSException |
|
| 224 | - */ |
|
| 225 | - public function getUser($userId) { |
|
| 226 | - $data = $this->getUserData($userId); |
|
| 227 | - return new DataResponse($data); |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - /** |
|
| 231 | - * @NoAdminRequired |
|
| 232 | - * @NoSubAdminRequired |
|
| 233 | - * |
|
| 234 | - * gets user info from the currently logged in user |
|
| 235 | - * |
|
| 236 | - * @return DataResponse |
|
| 237 | - * @throws OCSException |
|
| 238 | - */ |
|
| 239 | - public function getCurrentUser() { |
|
| 240 | - $user = $this->userSession->getUser(); |
|
| 241 | - if ($user) { |
|
| 242 | - $data = $this->getUserData($user->getUID()); |
|
| 243 | - // rename "displayname" to "display-name" only for this call to keep |
|
| 244 | - // the API stable. |
|
| 245 | - $data['display-name'] = $data['displayname']; |
|
| 246 | - unset($data['displayname']); |
|
| 247 | - return new DataResponse($data); |
|
| 248 | - |
|
| 249 | - } |
|
| 250 | - |
|
| 251 | - throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - /** |
|
| 255 | - * creates a array with all user data |
|
| 256 | - * |
|
| 257 | - * @param $userId |
|
| 258 | - * @return array |
|
| 259 | - * @throws OCSException |
|
| 260 | - */ |
|
| 261 | - protected function getUserData($userId) { |
|
| 262 | - $currentLoggedInUser = $this->userSession->getUser(); |
|
| 263 | - |
|
| 264 | - $data = []; |
|
| 265 | - |
|
| 266 | - // Check if the target user exists |
|
| 267 | - $targetUserObject = $this->userManager->get($userId); |
|
| 268 | - if($targetUserObject === null) { |
|
| 269 | - throw new OCSException('The requested user could not be found', \OCP\API::RESPOND_NOT_FOUND); |
|
| 270 | - } |
|
| 271 | - |
|
| 272 | - // Admin? Or SubAdmin? |
|
| 273 | - if($this->groupManager->isAdmin($currentLoggedInUser->getUID()) |
|
| 274 | - || $this->groupManager->getSubAdmin()->isUserAccessible($currentLoggedInUser, $targetUserObject)) { |
|
| 275 | - $data['enabled'] = $this->config->getUserValue($targetUserObject->getUID(), 'core', 'enabled', 'true'); |
|
| 276 | - } else { |
|
| 277 | - // Check they are looking up themselves |
|
| 278 | - if($currentLoggedInUser->getUID() !== $targetUserObject->getUID()) { |
|
| 279 | - throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
| 280 | - } |
|
| 281 | - } |
|
| 282 | - |
|
| 283 | - $userAccount = $this->accountManager->getUser($targetUserObject); |
|
| 284 | - $groups = $this->groupManager->getUserGroups($targetUserObject); |
|
| 285 | - $gids = []; |
|
| 286 | - foreach ($groups as $group) { |
|
| 287 | - $gids[] = $group->getDisplayName(); |
|
| 288 | - } |
|
| 289 | - |
|
| 290 | - // Find the data |
|
| 291 | - $data['id'] = $targetUserObject->getUID(); |
|
| 292 | - $data['quota'] = $this->fillStorageInfo($targetUserObject->getUID()); |
|
| 293 | - $data[AccountManager::PROPERTY_EMAIL] = $targetUserObject->getEMailAddress(); |
|
| 294 | - $data[AccountManager::PROPERTY_DISPLAYNAME] = $targetUserObject->getDisplayName(); |
|
| 295 | - $data[AccountManager::PROPERTY_PHONE] = $userAccount[AccountManager::PROPERTY_PHONE]['value']; |
|
| 296 | - $data[AccountManager::PROPERTY_ADDRESS] = $userAccount[AccountManager::PROPERTY_ADDRESS]['value']; |
|
| 297 | - $data[AccountManager::PROPERTY_WEBSITE] = $userAccount[AccountManager::PROPERTY_WEBSITE]['value']; |
|
| 298 | - $data[AccountManager::PROPERTY_TWITTER] = $userAccount[AccountManager::PROPERTY_TWITTER]['value']; |
|
| 299 | - $data['groups'] = $gids; |
|
| 300 | - $data['language'] = $this->config->getUserValue($targetUserObject->getUID(), 'core', 'lang'); |
|
| 301 | - |
|
| 302 | - return $data; |
|
| 303 | - } |
|
| 304 | - |
|
| 305 | - /** |
|
| 306 | - * @NoAdminRequired |
|
| 307 | - * @NoSubAdminRequired |
|
| 308 | - */ |
|
| 309 | - public function getEditableFields() { |
|
| 310 | - $permittedFields = []; |
|
| 311 | - |
|
| 312 | - // Editing self (display, email) |
|
| 313 | - if ($this->config->getSystemValue('allow_user_to_change_display_name', true) !== false) { |
|
| 314 | - $permittedFields[] = AccountManager::PROPERTY_DISPLAYNAME; |
|
| 315 | - $permittedFields[] = AccountManager::PROPERTY_EMAIL; |
|
| 316 | - } |
|
| 317 | - |
|
| 318 | - if ($this->appManager->isEnabledForUser('federatedfilesharing')) { |
|
| 319 | - $federatedFileSharing = $this->federatedFileSharingFactory->get(); |
|
| 320 | - $shareProvider = $federatedFileSharing->getFederatedShareProvider(); |
|
| 321 | - if ($shareProvider->isLookupServerUploadEnabled()) { |
|
| 322 | - $permittedFields[] = AccountManager::PROPERTY_PHONE; |
|
| 323 | - $permittedFields[] = AccountManager::PROPERTY_ADDRESS; |
|
| 324 | - $permittedFields[] = AccountManager::PROPERTY_WEBSITE; |
|
| 325 | - $permittedFields[] = AccountManager::PROPERTY_TWITTER; |
|
| 326 | - } |
|
| 327 | - } |
|
| 328 | - |
|
| 329 | - return new DataResponse($permittedFields); |
|
| 330 | - } |
|
| 331 | - |
|
| 332 | - /** |
|
| 333 | - * @NoAdminRequired |
|
| 334 | - * @NoSubAdminRequired |
|
| 335 | - * @PasswordConfirmationRequired |
|
| 336 | - * |
|
| 337 | - * edit users |
|
| 338 | - * |
|
| 339 | - * @param string $userId |
|
| 340 | - * @param string $key |
|
| 341 | - * @param string $value |
|
| 342 | - * @return DataResponse |
|
| 343 | - * @throws OCSException |
|
| 344 | - * @throws OCSForbiddenException |
|
| 345 | - */ |
|
| 346 | - public function editUser($userId, $key, $value) { |
|
| 347 | - $currentLoggedInUser = $this->userSession->getUser(); |
|
| 348 | - |
|
| 349 | - $targetUser = $this->userManager->get($userId); |
|
| 350 | - if($targetUser === null) { |
|
| 351 | - throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
| 352 | - } |
|
| 353 | - |
|
| 354 | - $permittedFields = []; |
|
| 355 | - if($targetUser->getUID() === $currentLoggedInUser->getUID()) { |
|
| 356 | - // Editing self (display, email) |
|
| 357 | - if ($this->config->getSystemValue('allow_user_to_change_display_name', true) !== false) { |
|
| 358 | - $permittedFields[] = 'display'; |
|
| 359 | - $permittedFields[] = AccountManager::PROPERTY_DISPLAYNAME; |
|
| 360 | - $permittedFields[] = AccountManager::PROPERTY_EMAIL; |
|
| 361 | - } |
|
| 362 | - |
|
| 363 | - $permittedFields[] = 'password'; |
|
| 364 | - if ($this->config->getSystemValue('force_language', false) === false || |
|
| 365 | - $this->groupManager->isAdmin($currentLoggedInUser->getUID())) { |
|
| 366 | - $permittedFields[] = 'language'; |
|
| 367 | - } |
|
| 368 | - |
|
| 369 | - if ($this->appManager->isEnabledForUser('federatedfilesharing')) { |
|
| 370 | - $federatedFileSharing = new \OCA\FederatedFileSharing\AppInfo\Application(); |
|
| 371 | - $shareProvider = $federatedFileSharing->getFederatedShareProvider(); |
|
| 372 | - if ($shareProvider->isLookupServerUploadEnabled()) { |
|
| 373 | - $permittedFields[] = AccountManager::PROPERTY_PHONE; |
|
| 374 | - $permittedFields[] = AccountManager::PROPERTY_ADDRESS; |
|
| 375 | - $permittedFields[] = AccountManager::PROPERTY_WEBSITE; |
|
| 376 | - $permittedFields[] = AccountManager::PROPERTY_TWITTER; |
|
| 377 | - } |
|
| 378 | - } |
|
| 379 | - |
|
| 380 | - // If admin they can edit their own quota |
|
| 381 | - if($this->groupManager->isAdmin($currentLoggedInUser->getUID())) { |
|
| 382 | - $permittedFields[] = 'quota'; |
|
| 383 | - } |
|
| 384 | - } else { |
|
| 385 | - // Check if admin / subadmin |
|
| 386 | - $subAdminManager = $this->groupManager->getSubAdmin(); |
|
| 387 | - if($subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser) |
|
| 388 | - || $this->groupManager->isAdmin($currentLoggedInUser->getUID())) { |
|
| 389 | - // They have permissions over the user |
|
| 390 | - $permittedFields[] = 'display'; |
|
| 391 | - $permittedFields[] = AccountManager::PROPERTY_DISPLAYNAME; |
|
| 392 | - $permittedFields[] = AccountManager::PROPERTY_EMAIL; |
|
| 393 | - $permittedFields[] = 'password'; |
|
| 394 | - $permittedFields[] = 'language'; |
|
| 395 | - $permittedFields[] = AccountManager::PROPERTY_PHONE; |
|
| 396 | - $permittedFields[] = AccountManager::PROPERTY_ADDRESS; |
|
| 397 | - $permittedFields[] = AccountManager::PROPERTY_WEBSITE; |
|
| 398 | - $permittedFields[] = AccountManager::PROPERTY_TWITTER; |
|
| 399 | - $permittedFields[] = 'quota'; |
|
| 400 | - } else { |
|
| 401 | - // No rights |
|
| 402 | - throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
| 403 | - } |
|
| 404 | - } |
|
| 405 | - // Check if permitted to edit this field |
|
| 406 | - if(!in_array($key, $permittedFields)) { |
|
| 407 | - throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
| 408 | - } |
|
| 409 | - // Process the edit |
|
| 410 | - switch($key) { |
|
| 411 | - case 'display': |
|
| 412 | - case AccountManager::PROPERTY_DISPLAYNAME: |
|
| 413 | - $targetUser->setDisplayName($value); |
|
| 414 | - break; |
|
| 415 | - case 'quota': |
|
| 416 | - $quota = $value; |
|
| 417 | - if($quota !== 'none' && $quota !== 'default') { |
|
| 418 | - if (is_numeric($quota)) { |
|
| 419 | - $quota = (float) $quota; |
|
| 420 | - } else { |
|
| 421 | - $quota = \OCP\Util::computerFileSize($quota); |
|
| 422 | - } |
|
| 423 | - if ($quota === false) { |
|
| 424 | - throw new OCSException('Invalid quota value '.$value, 103); |
|
| 425 | - } |
|
| 426 | - if($quota === 0) { |
|
| 427 | - $quota = 'default'; |
|
| 428 | - }else if($quota === -1) { |
|
| 429 | - $quota = 'none'; |
|
| 430 | - } else { |
|
| 431 | - $quota = \OCP\Util::humanFileSize($quota); |
|
| 432 | - } |
|
| 433 | - } |
|
| 434 | - $targetUser->setQuota($quota); |
|
| 435 | - break; |
|
| 436 | - case 'password': |
|
| 437 | - $targetUser->setPassword($value); |
|
| 438 | - break; |
|
| 439 | - case 'language': |
|
| 440 | - $languagesCodes = $this->l10nFactory->findAvailableLanguages(); |
|
| 441 | - if (!in_array($value, $languagesCodes, true) && $value !== 'en') { |
|
| 442 | - throw new OCSException('Invalid language', 102); |
|
| 443 | - } |
|
| 444 | - $this->config->setUserValue($targetUser->getUID(), 'core', 'lang', $value); |
|
| 445 | - break; |
|
| 446 | - case AccountManager::PROPERTY_EMAIL: |
|
| 447 | - if(filter_var($value, FILTER_VALIDATE_EMAIL)) { |
|
| 448 | - $targetUser->setEMailAddress($value); |
|
| 449 | - } else { |
|
| 450 | - throw new OCSException('', 102); |
|
| 451 | - } |
|
| 452 | - break; |
|
| 453 | - case AccountManager::PROPERTY_PHONE: |
|
| 454 | - case AccountManager::PROPERTY_ADDRESS: |
|
| 455 | - case AccountManager::PROPERTY_WEBSITE: |
|
| 456 | - case AccountManager::PROPERTY_TWITTER: |
|
| 457 | - $userAccount = $this->accountManager->getUser($targetUser); |
|
| 458 | - if ($userAccount[$key]['value'] !== $value) { |
|
| 459 | - $userAccount[$key]['value'] = $value; |
|
| 460 | - $this->accountManager->updateUser($targetUser, $userAccount); |
|
| 461 | - } |
|
| 462 | - break; |
|
| 463 | - default: |
|
| 464 | - throw new OCSException('', 103); |
|
| 465 | - } |
|
| 466 | - return new DataResponse(); |
|
| 467 | - } |
|
| 468 | - |
|
| 469 | - /** |
|
| 470 | - * @PasswordConfirmationRequired |
|
| 471 | - * @NoAdminRequired |
|
| 472 | - * |
|
| 473 | - * @param string $userId |
|
| 474 | - * @return DataResponse |
|
| 475 | - * @throws OCSException |
|
| 476 | - * @throws OCSForbiddenException |
|
| 477 | - */ |
|
| 478 | - public function deleteUser($userId) { |
|
| 479 | - $currentLoggedInUser = $this->userSession->getUser(); |
|
| 480 | - |
|
| 481 | - $targetUser = $this->userManager->get($userId); |
|
| 482 | - |
|
| 483 | - if($targetUser === null || $targetUser->getUID() === $currentLoggedInUser->getUID()) { |
|
| 484 | - throw new OCSException('', 101); |
|
| 485 | - } |
|
| 486 | - |
|
| 487 | - // If not permitted |
|
| 488 | - $subAdminManager = $this->groupManager->getSubAdmin(); |
|
| 489 | - if(!$this->groupManager->isAdmin($currentLoggedInUser->getUID()) && !$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)) { |
|
| 490 | - throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
| 491 | - } |
|
| 492 | - |
|
| 493 | - // Go ahead with the delete |
|
| 494 | - if($targetUser->delete()) { |
|
| 495 | - return new DataResponse(); |
|
| 496 | - } else { |
|
| 497 | - throw new OCSException('', 101); |
|
| 498 | - } |
|
| 499 | - } |
|
| 500 | - |
|
| 501 | - /** |
|
| 502 | - * @PasswordConfirmationRequired |
|
| 503 | - * @NoAdminRequired |
|
| 504 | - * |
|
| 505 | - * @param string $userId |
|
| 506 | - * @return DataResponse |
|
| 507 | - * @throws OCSException |
|
| 508 | - * @throws OCSForbiddenException |
|
| 509 | - */ |
|
| 510 | - public function disableUser($userId) { |
|
| 511 | - return $this->setEnabled($userId, false); |
|
| 512 | - } |
|
| 513 | - |
|
| 514 | - /** |
|
| 515 | - * @PasswordConfirmationRequired |
|
| 516 | - * @NoAdminRequired |
|
| 517 | - * |
|
| 518 | - * @param string $userId |
|
| 519 | - * @return DataResponse |
|
| 520 | - * @throws OCSException |
|
| 521 | - * @throws OCSForbiddenException |
|
| 522 | - */ |
|
| 523 | - public function enableUser($userId) { |
|
| 524 | - return $this->setEnabled($userId, true); |
|
| 525 | - } |
|
| 526 | - |
|
| 527 | - /** |
|
| 528 | - * @param string $userId |
|
| 529 | - * @param bool $value |
|
| 530 | - * @return DataResponse |
|
| 531 | - * @throws OCSException |
|
| 532 | - * @throws OCSForbiddenException |
|
| 533 | - */ |
|
| 534 | - private function setEnabled($userId, $value) { |
|
| 535 | - $currentLoggedInUser = $this->userSession->getUser(); |
|
| 536 | - |
|
| 537 | - $targetUser = $this->userManager->get($userId); |
|
| 538 | - if($targetUser === null || $targetUser->getUID() === $currentLoggedInUser->getUID()) { |
|
| 539 | - throw new OCSException('', 101); |
|
| 540 | - } |
|
| 541 | - |
|
| 542 | - // If not permitted |
|
| 543 | - $subAdminManager = $this->groupManager->getSubAdmin(); |
|
| 544 | - if(!$this->groupManager->isAdmin($currentLoggedInUser->getUID()) && !$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)) { |
|
| 545 | - throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
| 546 | - } |
|
| 547 | - |
|
| 548 | - // enable/disable the user now |
|
| 549 | - $targetUser->setEnabled($value); |
|
| 550 | - return new DataResponse(); |
|
| 551 | - } |
|
| 552 | - |
|
| 553 | - /** |
|
| 554 | - * @NoAdminRequired |
|
| 555 | - * @NoSubAdminRequired |
|
| 556 | - * |
|
| 557 | - * @param string $userId |
|
| 558 | - * @return DataResponse |
|
| 559 | - * @throws OCSException |
|
| 560 | - */ |
|
| 561 | - public function getUsersGroups($userId) { |
|
| 562 | - $loggedInUser = $this->userSession->getUser(); |
|
| 563 | - |
|
| 564 | - $targetUser = $this->userManager->get($userId); |
|
| 565 | - if($targetUser === null) { |
|
| 566 | - throw new OCSException('', \OCP\API::RESPOND_NOT_FOUND); |
|
| 567 | - } |
|
| 568 | - |
|
| 569 | - if($targetUser->getUID() === $loggedInUser->getUID() || $this->groupManager->isAdmin($loggedInUser->getUID())) { |
|
| 570 | - // Self lookup or admin lookup |
|
| 571 | - return new DataResponse([ |
|
| 572 | - 'groups' => $this->groupManager->getUserGroupIds($targetUser) |
|
| 573 | - ]); |
|
| 574 | - } else { |
|
| 575 | - $subAdminManager = $this->groupManager->getSubAdmin(); |
|
| 576 | - |
|
| 577 | - // Looking up someone else |
|
| 578 | - if($subAdminManager->isUserAccessible($loggedInUser, $targetUser)) { |
|
| 579 | - // Return the group that the method caller is subadmin of for the user in question |
|
| 580 | - /** @var IGroup[] $getSubAdminsGroups */ |
|
| 581 | - $getSubAdminsGroups = $subAdminManager->getSubAdminsGroups($loggedInUser); |
|
| 582 | - foreach ($getSubAdminsGroups as $key => $group) { |
|
| 583 | - $getSubAdminsGroups[$key] = $group->getGID(); |
|
| 584 | - } |
|
| 585 | - $groups = array_intersect( |
|
| 586 | - $getSubAdminsGroups, |
|
| 587 | - $this->groupManager->getUserGroupIds($targetUser) |
|
| 588 | - ); |
|
| 589 | - return new DataResponse(['groups' => $groups]); |
|
| 590 | - } else { |
|
| 591 | - // Not permitted |
|
| 592 | - throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
| 593 | - } |
|
| 594 | - } |
|
| 595 | - |
|
| 596 | - } |
|
| 597 | - |
|
| 598 | - /** |
|
| 599 | - * @PasswordConfirmationRequired |
|
| 600 | - * @NoAdminRequired |
|
| 601 | - * |
|
| 602 | - * @param string $userId |
|
| 603 | - * @param string $groupid |
|
| 604 | - * @return DataResponse |
|
| 605 | - * @throws OCSException |
|
| 606 | - */ |
|
| 607 | - public function addToGroup($userId, $groupid = '') { |
|
| 608 | - if($groupid === '') { |
|
| 609 | - throw new OCSException('', 101); |
|
| 610 | - } |
|
| 611 | - |
|
| 612 | - $group = $this->groupManager->get($groupid); |
|
| 613 | - $targetUser = $this->userManager->get($userId); |
|
| 614 | - if($group === null) { |
|
| 615 | - throw new OCSException('', 102); |
|
| 616 | - } |
|
| 617 | - if($targetUser === null) { |
|
| 618 | - throw new OCSException('', 103); |
|
| 619 | - } |
|
| 620 | - |
|
| 621 | - // If they're not an admin, check they are a subadmin of the group in question |
|
| 622 | - $loggedInUser = $this->userSession->getUser(); |
|
| 623 | - $subAdminManager = $this->groupManager->getSubAdmin(); |
|
| 624 | - if (!$this->groupManager->isAdmin($loggedInUser->getUID()) && !$subAdminManager->isSubAdminOfGroup($loggedInUser, $group)) { |
|
| 625 | - throw new OCSException('', 104); |
|
| 626 | - } |
|
| 627 | - |
|
| 628 | - // Add user to group |
|
| 629 | - $group->addUser($targetUser); |
|
| 630 | - return new DataResponse(); |
|
| 631 | - } |
|
| 632 | - |
|
| 633 | - /** |
|
| 634 | - * @PasswordConfirmationRequired |
|
| 635 | - * @NoAdminRequired |
|
| 636 | - * |
|
| 637 | - * @param string $userId |
|
| 638 | - * @param string $groupid |
|
| 639 | - * @return DataResponse |
|
| 640 | - * @throws OCSException |
|
| 641 | - */ |
|
| 642 | - public function removeFromGroup($userId, $groupid) { |
|
| 643 | - $loggedInUser = $this->userSession->getUser(); |
|
| 644 | - |
|
| 645 | - if($groupid === null || trim($groupid) === '') { |
|
| 646 | - throw new OCSException('', 101); |
|
| 647 | - } |
|
| 648 | - |
|
| 649 | - $group = $this->groupManager->get($groupid); |
|
| 650 | - if($group === null) { |
|
| 651 | - throw new OCSException('', 102); |
|
| 652 | - } |
|
| 653 | - |
|
| 654 | - $targetUser = $this->userManager->get($userId); |
|
| 655 | - if($targetUser === null) { |
|
| 656 | - throw new OCSException('', 103); |
|
| 657 | - } |
|
| 658 | - |
|
| 659 | - // If they're not an admin, check they are a subadmin of the group in question |
|
| 660 | - $subAdminManager = $this->groupManager->getSubAdmin(); |
|
| 661 | - if (!$this->groupManager->isAdmin($loggedInUser->getUID()) && !$subAdminManager->isSubAdminOfGroup($loggedInUser, $group)) { |
|
| 662 | - throw new OCSException('', 104); |
|
| 663 | - } |
|
| 664 | - |
|
| 665 | - // Check they aren't removing themselves from 'admin' or their 'subadmin; group |
|
| 666 | - if ($targetUser->getUID() === $loggedInUser->getUID()) { |
|
| 667 | - if ($this->groupManager->isAdmin($loggedInUser->getUID())) { |
|
| 668 | - if ($group->getGID() === 'admin') { |
|
| 669 | - throw new OCSException('Cannot remove yourself from the admin group', 105); |
|
| 670 | - } |
|
| 671 | - } else { |
|
| 672 | - // Not an admin, so the user must be a subadmin of this group, but that is not allowed. |
|
| 673 | - throw new OCSException('Cannot remove yourself from this group as you are a SubAdmin', 105); |
|
| 674 | - } |
|
| 675 | - |
|
| 676 | - } else if (!$this->groupManager->isAdmin($loggedInUser->getUID())) { |
|
| 677 | - /** @var IGroup[] $subAdminGroups */ |
|
| 678 | - $subAdminGroups = $subAdminManager->getSubAdminsGroups($loggedInUser); |
|
| 679 | - $subAdminGroups = array_map(function (IGroup $subAdminGroup) { |
|
| 680 | - return $subAdminGroup->getGID(); |
|
| 681 | - }, $subAdminGroups); |
|
| 682 | - $userGroups = $this->groupManager->getUserGroupIds($targetUser); |
|
| 683 | - $userSubAdminGroups = array_intersect($subAdminGroups, $userGroups); |
|
| 684 | - |
|
| 685 | - if (count($userSubAdminGroups) <= 1) { |
|
| 686 | - // Subadmin must not be able to remove a user from all their subadmin groups. |
|
| 687 | - throw new OCSException('Cannot remove user from this group as this is the only remaining group you are a SubAdmin of', 105); |
|
| 688 | - } |
|
| 689 | - } |
|
| 690 | - |
|
| 691 | - // Remove user from group |
|
| 692 | - $group->removeUser($targetUser); |
|
| 693 | - return new DataResponse(); |
|
| 694 | - } |
|
| 695 | - |
|
| 696 | - /** |
|
| 697 | - * Creates a subadmin |
|
| 698 | - * |
|
| 699 | - * @PasswordConfirmationRequired |
|
| 700 | - * |
|
| 701 | - * @param string $userId |
|
| 702 | - * @param string $groupid |
|
| 703 | - * @return DataResponse |
|
| 704 | - * @throws OCSException |
|
| 705 | - */ |
|
| 706 | - public function addSubAdmin($userId, $groupid) { |
|
| 707 | - $group = $this->groupManager->get($groupid); |
|
| 708 | - $user = $this->userManager->get($userId); |
|
| 709 | - |
|
| 710 | - // Check if the user exists |
|
| 711 | - if($user === null) { |
|
| 712 | - throw new OCSException('User does not exist', 101); |
|
| 713 | - } |
|
| 714 | - // Check if group exists |
|
| 715 | - if($group === null) { |
|
| 716 | - throw new OCSException('Group does not exist', 102); |
|
| 717 | - } |
|
| 718 | - // Check if trying to make subadmin of admin group |
|
| 719 | - if($group->getGID() === 'admin') { |
|
| 720 | - throw new OCSException('Cannot create subadmins for admin group', 103); |
|
| 721 | - } |
|
| 722 | - |
|
| 723 | - $subAdminManager = $this->groupManager->getSubAdmin(); |
|
| 724 | - |
|
| 725 | - // We cannot be subadmin twice |
|
| 726 | - if ($subAdminManager->isSubAdminofGroup($user, $group)) { |
|
| 727 | - return new DataResponse(); |
|
| 728 | - } |
|
| 729 | - // Go |
|
| 730 | - if($subAdminManager->createSubAdmin($user, $group)) { |
|
| 731 | - return new DataResponse(); |
|
| 732 | - } else { |
|
| 733 | - throw new OCSException('Unknown error occurred', 103); |
|
| 734 | - } |
|
| 735 | - } |
|
| 736 | - |
|
| 737 | - /** |
|
| 738 | - * Removes a subadmin from a group |
|
| 739 | - * |
|
| 740 | - * @PasswordConfirmationRequired |
|
| 741 | - * |
|
| 742 | - * @param string $userId |
|
| 743 | - * @param string $groupid |
|
| 744 | - * @return DataResponse |
|
| 745 | - * @throws OCSException |
|
| 746 | - */ |
|
| 747 | - public function removeSubAdmin($userId, $groupid) { |
|
| 748 | - $group = $this->groupManager->get($groupid); |
|
| 749 | - $user = $this->userManager->get($userId); |
|
| 750 | - $subAdminManager = $this->groupManager->getSubAdmin(); |
|
| 751 | - |
|
| 752 | - // Check if the user exists |
|
| 753 | - if($user === null) { |
|
| 754 | - throw new OCSException('User does not exist', 101); |
|
| 755 | - } |
|
| 756 | - // Check if the group exists |
|
| 757 | - if($group === null) { |
|
| 758 | - throw new OCSException('Group does not exist', 101); |
|
| 759 | - } |
|
| 760 | - // Check if they are a subadmin of this said group |
|
| 761 | - if(!$subAdminManager->isSubAdminOfGroup($user, $group)) { |
|
| 762 | - throw new OCSException('User is not a subadmin of this group', 102); |
|
| 763 | - } |
|
| 764 | - |
|
| 765 | - // Go |
|
| 766 | - if($subAdminManager->deleteSubAdmin($user, $group)) { |
|
| 767 | - return new DataResponse(); |
|
| 768 | - } else { |
|
| 769 | - throw new OCSException('Unknown error occurred', 103); |
|
| 770 | - } |
|
| 771 | - } |
|
| 772 | - |
|
| 773 | - /** |
|
| 774 | - * Get the groups a user is a subadmin of |
|
| 775 | - * |
|
| 776 | - * @param string $userId |
|
| 777 | - * @return DataResponse |
|
| 778 | - * @throws OCSException |
|
| 779 | - */ |
|
| 780 | - public function getUserSubAdminGroups($userId) { |
|
| 781 | - $user = $this->userManager->get($userId); |
|
| 782 | - // Check if the user exists |
|
| 783 | - if($user === null) { |
|
| 784 | - throw new OCSException('User does not exist', 101); |
|
| 785 | - } |
|
| 786 | - |
|
| 787 | - // Get the subadmin groups |
|
| 788 | - $groups = $this->groupManager->getSubAdmin()->getSubAdminsGroups($user); |
|
| 789 | - foreach ($groups as $key => $group) { |
|
| 790 | - $groups[$key] = $group->getGID(); |
|
| 791 | - } |
|
| 792 | - |
|
| 793 | - if(!$groups) { |
|
| 794 | - throw new OCSException('Unknown error occurred', 102); |
|
| 795 | - } else { |
|
| 796 | - return new DataResponse($groups); |
|
| 797 | - } |
|
| 798 | - } |
|
| 799 | - |
|
| 800 | - /** |
|
| 801 | - * @param string $userId |
|
| 802 | - * @return array |
|
| 803 | - * @throws \OCP\Files\NotFoundException |
|
| 804 | - */ |
|
| 805 | - protected function fillStorageInfo($userId) { |
|
| 806 | - try { |
|
| 807 | - \OC_Util::tearDownFS(); |
|
| 808 | - \OC_Util::setupFS($userId); |
|
| 809 | - $storage = OC_Helper::getStorageInfo('/'); |
|
| 810 | - $data = [ |
|
| 811 | - 'free' => $storage['free'], |
|
| 812 | - 'used' => $storage['used'], |
|
| 813 | - 'total' => $storage['total'], |
|
| 814 | - 'relative' => $storage['relative'], |
|
| 815 | - 'quota' => $storage['quota'], |
|
| 816 | - ]; |
|
| 817 | - } catch (NotFoundException $ex) { |
|
| 818 | - $data = []; |
|
| 819 | - } |
|
| 820 | - return $data; |
|
| 821 | - } |
|
| 822 | - |
|
| 823 | - /** |
|
| 824 | - * @NoAdminRequired |
|
| 825 | - * @PasswordConfirmationRequired |
|
| 826 | - * |
|
| 827 | - * resend welcome message |
|
| 828 | - * |
|
| 829 | - * @param string $userId |
|
| 830 | - * @return DataResponse |
|
| 831 | - * @throws OCSException |
|
| 832 | - */ |
|
| 833 | - public function resendWelcomeMessage($userId) { |
|
| 834 | - $currentLoggedInUser = $this->userSession->getUser(); |
|
| 835 | - |
|
| 836 | - $targetUser = $this->userManager->get($userId); |
|
| 837 | - if($targetUser === null) { |
|
| 838 | - throw new OCSException('', \OCP\API::RESPOND_NOT_FOUND); |
|
| 839 | - } |
|
| 840 | - |
|
| 841 | - // Check if admin / subadmin |
|
| 842 | - $subAdminManager = $this->groupManager->getSubAdmin(); |
|
| 843 | - if(!$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser) |
|
| 844 | - && !$this->groupManager->isAdmin($currentLoggedInUser->getUID())) { |
|
| 845 | - // No rights |
|
| 846 | - throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
| 847 | - } |
|
| 848 | - |
|
| 849 | - $email = $targetUser->getEMailAddress(); |
|
| 850 | - if ($email === '' || $email === null) { |
|
| 851 | - throw new OCSException('Email address not available', 101); |
|
| 852 | - } |
|
| 853 | - $username = $targetUser->getUID(); |
|
| 854 | - $lang = $this->config->getUserValue($username, 'core', 'lang', 'en'); |
|
| 855 | - if (!$this->l10nFactory->languageExists('settings', $lang)) { |
|
| 856 | - $lang = 'en'; |
|
| 857 | - } |
|
| 858 | - |
|
| 859 | - $l10n = $this->l10nFactory->get('settings', $lang); |
|
| 860 | - |
|
| 861 | - try { |
|
| 862 | - $this->newUserMailHelper->setL10N($l10n); |
|
| 863 | - $emailTemplate = $this->newUserMailHelper->generateTemplate($targetUser, false); |
|
| 864 | - $this->newUserMailHelper->sendMail($targetUser, $emailTemplate); |
|
| 865 | - } catch(\Exception $e) { |
|
| 866 | - $this->logger->logException($e, [ |
|
| 867 | - 'message' => "Can't send new user mail to $email", |
|
| 868 | - 'level' => \OCP\Util::ERROR, |
|
| 869 | - 'app' => 'settings', |
|
| 870 | - ]); |
|
| 871 | - throw new OCSException('Sending email failed', 102); |
|
| 872 | - } |
|
| 873 | - |
|
| 874 | - return new DataResponse(); |
|
| 875 | - } |
|
| 54 | + /** @var IUserManager */ |
|
| 55 | + private $userManager; |
|
| 56 | + /** @var IConfig */ |
|
| 57 | + private $config; |
|
| 58 | + /** @var IAppManager */ |
|
| 59 | + private $appManager; |
|
| 60 | + /** @var IGroupManager|\OC\Group\Manager */ // FIXME Requires a method that is not on the interface |
|
| 61 | + private $groupManager; |
|
| 62 | + /** @var IUserSession */ |
|
| 63 | + private $userSession; |
|
| 64 | + /** @var AccountManager */ |
|
| 65 | + private $accountManager; |
|
| 66 | + /** @var ILogger */ |
|
| 67 | + private $logger; |
|
| 68 | + /** @var IFactory */ |
|
| 69 | + private $l10nFactory; |
|
| 70 | + /** @var NewUserMailHelper */ |
|
| 71 | + private $newUserMailHelper; |
|
| 72 | + /** @var FederatedFileSharingFactory */ |
|
| 73 | + private $federatedFileSharingFactory; |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * @param string $appName |
|
| 77 | + * @param IRequest $request |
|
| 78 | + * @param IUserManager $userManager |
|
| 79 | + * @param IConfig $config |
|
| 80 | + * @param IAppManager $appManager |
|
| 81 | + * @param IGroupManager $groupManager |
|
| 82 | + * @param IUserSession $userSession |
|
| 83 | + * @param AccountManager $accountManager |
|
| 84 | + * @param ILogger $logger |
|
| 85 | + * @param IFactory $l10nFactory |
|
| 86 | + * @param NewUserMailHelper $newUserMailHelper |
|
| 87 | + * @param FederatedFileSharingFactory $federatedFileSharingFactory |
|
| 88 | + */ |
|
| 89 | + public function __construct($appName, |
|
| 90 | + IRequest $request, |
|
| 91 | + IUserManager $userManager, |
|
| 92 | + IConfig $config, |
|
| 93 | + IAppManager $appManager, |
|
| 94 | + IGroupManager $groupManager, |
|
| 95 | + IUserSession $userSession, |
|
| 96 | + AccountManager $accountManager, |
|
| 97 | + ILogger $logger, |
|
| 98 | + IFactory $l10nFactory, |
|
| 99 | + NewUserMailHelper $newUserMailHelper, |
|
| 100 | + FederatedFileSharingFactory $federatedFileSharingFactory) { |
|
| 101 | + parent::__construct($appName, $request); |
|
| 102 | + |
|
| 103 | + $this->userManager = $userManager; |
|
| 104 | + $this->config = $config; |
|
| 105 | + $this->appManager = $appManager; |
|
| 106 | + $this->groupManager = $groupManager; |
|
| 107 | + $this->userSession = $userSession; |
|
| 108 | + $this->accountManager = $accountManager; |
|
| 109 | + $this->logger = $logger; |
|
| 110 | + $this->l10nFactory = $l10nFactory; |
|
| 111 | + $this->newUserMailHelper = $newUserMailHelper; |
|
| 112 | + $this->federatedFileSharingFactory = $federatedFileSharingFactory; |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * @NoAdminRequired |
|
| 117 | + * |
|
| 118 | + * returns a list of users |
|
| 119 | + * |
|
| 120 | + * @param string $search |
|
| 121 | + * @param int $limit |
|
| 122 | + * @param int $offset |
|
| 123 | + * @return DataResponse |
|
| 124 | + */ |
|
| 125 | + public function getUsers($search = '', $limit = null, $offset = null) { |
|
| 126 | + $user = $this->userSession->getUser(); |
|
| 127 | + $users = []; |
|
| 128 | + |
|
| 129 | + // Admin? Or SubAdmin? |
|
| 130 | + $uid = $user->getUID(); |
|
| 131 | + $subAdminManager = $this->groupManager->getSubAdmin(); |
|
| 132 | + if($this->groupManager->isAdmin($uid)){ |
|
| 133 | + $users = $this->userManager->search($search, $limit, $offset); |
|
| 134 | + } else if ($subAdminManager->isSubAdmin($user)) { |
|
| 135 | + $subAdminOfGroups = $subAdminManager->getSubAdminsGroups($user); |
|
| 136 | + foreach ($subAdminOfGroups as $key => $group) { |
|
| 137 | + $subAdminOfGroups[$key] = $group->getGID(); |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + if($offset === null) { |
|
| 141 | + $offset = 0; |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + $users = []; |
|
| 145 | + foreach ($subAdminOfGroups as $group) { |
|
| 146 | + $users = array_merge($users, $this->groupManager->displayNamesInGroup($group, $search)); |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + $users = array_slice($users, $offset, $limit); |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + $users = array_keys($users); |
|
| 153 | + |
|
| 154 | + return new DataResponse([ |
|
| 155 | + 'users' => $users |
|
| 156 | + ]); |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + /** |
|
| 160 | + * @PasswordConfirmationRequired |
|
| 161 | + * @NoAdminRequired |
|
| 162 | + * |
|
| 163 | + * @param string $userid |
|
| 164 | + * @param string $password |
|
| 165 | + * @param array $groups |
|
| 166 | + * @return DataResponse |
|
| 167 | + * @throws OCSException |
|
| 168 | + */ |
|
| 169 | + public function addUser($userid, $password, $groups = null) { |
|
| 170 | + $user = $this->userSession->getUser(); |
|
| 171 | + $isAdmin = $this->groupManager->isAdmin($user->getUID()); |
|
| 172 | + $subAdminManager = $this->groupManager->getSubAdmin(); |
|
| 173 | + |
|
| 174 | + if($this->userManager->userExists($userid)) { |
|
| 175 | + $this->logger->error('Failed addUser attempt: User already exists.', ['app' => 'ocs_api']); |
|
| 176 | + throw new OCSException('User already exists', 102); |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + if(is_array($groups)) { |
|
| 180 | + foreach ($groups as $group) { |
|
| 181 | + if(!$this->groupManager->groupExists($group)) { |
|
| 182 | + throw new OCSException('group '.$group.' does not exist', 104); |
|
| 183 | + } |
|
| 184 | + if(!$isAdmin && !$subAdminManager->isSubAdminofGroup($user, $this->groupManager->get($group))) { |
|
| 185 | + throw new OCSException('insufficient privileges for group '. $group, 105); |
|
| 186 | + } |
|
| 187 | + } |
|
| 188 | + } else { |
|
| 189 | + if(!$isAdmin) { |
|
| 190 | + throw new OCSException('no group specified (required for subadmins)', 106); |
|
| 191 | + } |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + try { |
|
| 195 | + $newUser = $this->userManager->createUser($userid, $password); |
|
| 196 | + $this->logger->info('Successful addUser call with userid: '.$userid, ['app' => 'ocs_api']); |
|
| 197 | + |
|
| 198 | + if (is_array($groups)) { |
|
| 199 | + foreach ($groups as $group) { |
|
| 200 | + $this->groupManager->get($group)->addUser($newUser); |
|
| 201 | + $this->logger->info('Added userid '.$userid.' to group '.$group, ['app' => 'ocs_api']); |
|
| 202 | + } |
|
| 203 | + } |
|
| 204 | + return new DataResponse(); |
|
| 205 | + } catch (\Exception $e) { |
|
| 206 | + $this->logger->logException($e, [ |
|
| 207 | + 'message' => 'Failed addUser attempt with exception.', |
|
| 208 | + 'level' => \OCP\Util::ERROR, |
|
| 209 | + 'app' => 'ocs_api', |
|
| 210 | + ]); |
|
| 211 | + throw new OCSException('Bad request', 101); |
|
| 212 | + } |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + /** |
|
| 216 | + * @NoAdminRequired |
|
| 217 | + * @NoSubAdminRequired |
|
| 218 | + * |
|
| 219 | + * gets user info |
|
| 220 | + * |
|
| 221 | + * @param string $userId |
|
| 222 | + * @return DataResponse |
|
| 223 | + * @throws OCSException |
|
| 224 | + */ |
|
| 225 | + public function getUser($userId) { |
|
| 226 | + $data = $this->getUserData($userId); |
|
| 227 | + return new DataResponse($data); |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + /** |
|
| 231 | + * @NoAdminRequired |
|
| 232 | + * @NoSubAdminRequired |
|
| 233 | + * |
|
| 234 | + * gets user info from the currently logged in user |
|
| 235 | + * |
|
| 236 | + * @return DataResponse |
|
| 237 | + * @throws OCSException |
|
| 238 | + */ |
|
| 239 | + public function getCurrentUser() { |
|
| 240 | + $user = $this->userSession->getUser(); |
|
| 241 | + if ($user) { |
|
| 242 | + $data = $this->getUserData($user->getUID()); |
|
| 243 | + // rename "displayname" to "display-name" only for this call to keep |
|
| 244 | + // the API stable. |
|
| 245 | + $data['display-name'] = $data['displayname']; |
|
| 246 | + unset($data['displayname']); |
|
| 247 | + return new DataResponse($data); |
|
| 248 | + |
|
| 249 | + } |
|
| 250 | + |
|
| 251 | + throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + /** |
|
| 255 | + * creates a array with all user data |
|
| 256 | + * |
|
| 257 | + * @param $userId |
|
| 258 | + * @return array |
|
| 259 | + * @throws OCSException |
|
| 260 | + */ |
|
| 261 | + protected function getUserData($userId) { |
|
| 262 | + $currentLoggedInUser = $this->userSession->getUser(); |
|
| 263 | + |
|
| 264 | + $data = []; |
|
| 265 | + |
|
| 266 | + // Check if the target user exists |
|
| 267 | + $targetUserObject = $this->userManager->get($userId); |
|
| 268 | + if($targetUserObject === null) { |
|
| 269 | + throw new OCSException('The requested user could not be found', \OCP\API::RESPOND_NOT_FOUND); |
|
| 270 | + } |
|
| 271 | + |
|
| 272 | + // Admin? Or SubAdmin? |
|
| 273 | + if($this->groupManager->isAdmin($currentLoggedInUser->getUID()) |
|
| 274 | + || $this->groupManager->getSubAdmin()->isUserAccessible($currentLoggedInUser, $targetUserObject)) { |
|
| 275 | + $data['enabled'] = $this->config->getUserValue($targetUserObject->getUID(), 'core', 'enabled', 'true'); |
|
| 276 | + } else { |
|
| 277 | + // Check they are looking up themselves |
|
| 278 | + if($currentLoggedInUser->getUID() !== $targetUserObject->getUID()) { |
|
| 279 | + throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
| 280 | + } |
|
| 281 | + } |
|
| 282 | + |
|
| 283 | + $userAccount = $this->accountManager->getUser($targetUserObject); |
|
| 284 | + $groups = $this->groupManager->getUserGroups($targetUserObject); |
|
| 285 | + $gids = []; |
|
| 286 | + foreach ($groups as $group) { |
|
| 287 | + $gids[] = $group->getDisplayName(); |
|
| 288 | + } |
|
| 289 | + |
|
| 290 | + // Find the data |
|
| 291 | + $data['id'] = $targetUserObject->getUID(); |
|
| 292 | + $data['quota'] = $this->fillStorageInfo($targetUserObject->getUID()); |
|
| 293 | + $data[AccountManager::PROPERTY_EMAIL] = $targetUserObject->getEMailAddress(); |
|
| 294 | + $data[AccountManager::PROPERTY_DISPLAYNAME] = $targetUserObject->getDisplayName(); |
|
| 295 | + $data[AccountManager::PROPERTY_PHONE] = $userAccount[AccountManager::PROPERTY_PHONE]['value']; |
|
| 296 | + $data[AccountManager::PROPERTY_ADDRESS] = $userAccount[AccountManager::PROPERTY_ADDRESS]['value']; |
|
| 297 | + $data[AccountManager::PROPERTY_WEBSITE] = $userAccount[AccountManager::PROPERTY_WEBSITE]['value']; |
|
| 298 | + $data[AccountManager::PROPERTY_TWITTER] = $userAccount[AccountManager::PROPERTY_TWITTER]['value']; |
|
| 299 | + $data['groups'] = $gids; |
|
| 300 | + $data['language'] = $this->config->getUserValue($targetUserObject->getUID(), 'core', 'lang'); |
|
| 301 | + |
|
| 302 | + return $data; |
|
| 303 | + } |
|
| 304 | + |
|
| 305 | + /** |
|
| 306 | + * @NoAdminRequired |
|
| 307 | + * @NoSubAdminRequired |
|
| 308 | + */ |
|
| 309 | + public function getEditableFields() { |
|
| 310 | + $permittedFields = []; |
|
| 311 | + |
|
| 312 | + // Editing self (display, email) |
|
| 313 | + if ($this->config->getSystemValue('allow_user_to_change_display_name', true) !== false) { |
|
| 314 | + $permittedFields[] = AccountManager::PROPERTY_DISPLAYNAME; |
|
| 315 | + $permittedFields[] = AccountManager::PROPERTY_EMAIL; |
|
| 316 | + } |
|
| 317 | + |
|
| 318 | + if ($this->appManager->isEnabledForUser('federatedfilesharing')) { |
|
| 319 | + $federatedFileSharing = $this->federatedFileSharingFactory->get(); |
|
| 320 | + $shareProvider = $federatedFileSharing->getFederatedShareProvider(); |
|
| 321 | + if ($shareProvider->isLookupServerUploadEnabled()) { |
|
| 322 | + $permittedFields[] = AccountManager::PROPERTY_PHONE; |
|
| 323 | + $permittedFields[] = AccountManager::PROPERTY_ADDRESS; |
|
| 324 | + $permittedFields[] = AccountManager::PROPERTY_WEBSITE; |
|
| 325 | + $permittedFields[] = AccountManager::PROPERTY_TWITTER; |
|
| 326 | + } |
|
| 327 | + } |
|
| 328 | + |
|
| 329 | + return new DataResponse($permittedFields); |
|
| 330 | + } |
|
| 331 | + |
|
| 332 | + /** |
|
| 333 | + * @NoAdminRequired |
|
| 334 | + * @NoSubAdminRequired |
|
| 335 | + * @PasswordConfirmationRequired |
|
| 336 | + * |
|
| 337 | + * edit users |
|
| 338 | + * |
|
| 339 | + * @param string $userId |
|
| 340 | + * @param string $key |
|
| 341 | + * @param string $value |
|
| 342 | + * @return DataResponse |
|
| 343 | + * @throws OCSException |
|
| 344 | + * @throws OCSForbiddenException |
|
| 345 | + */ |
|
| 346 | + public function editUser($userId, $key, $value) { |
|
| 347 | + $currentLoggedInUser = $this->userSession->getUser(); |
|
| 348 | + |
|
| 349 | + $targetUser = $this->userManager->get($userId); |
|
| 350 | + if($targetUser === null) { |
|
| 351 | + throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
| 352 | + } |
|
| 353 | + |
|
| 354 | + $permittedFields = []; |
|
| 355 | + if($targetUser->getUID() === $currentLoggedInUser->getUID()) { |
|
| 356 | + // Editing self (display, email) |
|
| 357 | + if ($this->config->getSystemValue('allow_user_to_change_display_name', true) !== false) { |
|
| 358 | + $permittedFields[] = 'display'; |
|
| 359 | + $permittedFields[] = AccountManager::PROPERTY_DISPLAYNAME; |
|
| 360 | + $permittedFields[] = AccountManager::PROPERTY_EMAIL; |
|
| 361 | + } |
|
| 362 | + |
|
| 363 | + $permittedFields[] = 'password'; |
|
| 364 | + if ($this->config->getSystemValue('force_language', false) === false || |
|
| 365 | + $this->groupManager->isAdmin($currentLoggedInUser->getUID())) { |
|
| 366 | + $permittedFields[] = 'language'; |
|
| 367 | + } |
|
| 368 | + |
|
| 369 | + if ($this->appManager->isEnabledForUser('federatedfilesharing')) { |
|
| 370 | + $federatedFileSharing = new \OCA\FederatedFileSharing\AppInfo\Application(); |
|
| 371 | + $shareProvider = $federatedFileSharing->getFederatedShareProvider(); |
|
| 372 | + if ($shareProvider->isLookupServerUploadEnabled()) { |
|
| 373 | + $permittedFields[] = AccountManager::PROPERTY_PHONE; |
|
| 374 | + $permittedFields[] = AccountManager::PROPERTY_ADDRESS; |
|
| 375 | + $permittedFields[] = AccountManager::PROPERTY_WEBSITE; |
|
| 376 | + $permittedFields[] = AccountManager::PROPERTY_TWITTER; |
|
| 377 | + } |
|
| 378 | + } |
|
| 379 | + |
|
| 380 | + // If admin they can edit their own quota |
|
| 381 | + if($this->groupManager->isAdmin($currentLoggedInUser->getUID())) { |
|
| 382 | + $permittedFields[] = 'quota'; |
|
| 383 | + } |
|
| 384 | + } else { |
|
| 385 | + // Check if admin / subadmin |
|
| 386 | + $subAdminManager = $this->groupManager->getSubAdmin(); |
|
| 387 | + if($subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser) |
|
| 388 | + || $this->groupManager->isAdmin($currentLoggedInUser->getUID())) { |
|
| 389 | + // They have permissions over the user |
|
| 390 | + $permittedFields[] = 'display'; |
|
| 391 | + $permittedFields[] = AccountManager::PROPERTY_DISPLAYNAME; |
|
| 392 | + $permittedFields[] = AccountManager::PROPERTY_EMAIL; |
|
| 393 | + $permittedFields[] = 'password'; |
|
| 394 | + $permittedFields[] = 'language'; |
|
| 395 | + $permittedFields[] = AccountManager::PROPERTY_PHONE; |
|
| 396 | + $permittedFields[] = AccountManager::PROPERTY_ADDRESS; |
|
| 397 | + $permittedFields[] = AccountManager::PROPERTY_WEBSITE; |
|
| 398 | + $permittedFields[] = AccountManager::PROPERTY_TWITTER; |
|
| 399 | + $permittedFields[] = 'quota'; |
|
| 400 | + } else { |
|
| 401 | + // No rights |
|
| 402 | + throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
| 403 | + } |
|
| 404 | + } |
|
| 405 | + // Check if permitted to edit this field |
|
| 406 | + if(!in_array($key, $permittedFields)) { |
|
| 407 | + throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
| 408 | + } |
|
| 409 | + // Process the edit |
|
| 410 | + switch($key) { |
|
| 411 | + case 'display': |
|
| 412 | + case AccountManager::PROPERTY_DISPLAYNAME: |
|
| 413 | + $targetUser->setDisplayName($value); |
|
| 414 | + break; |
|
| 415 | + case 'quota': |
|
| 416 | + $quota = $value; |
|
| 417 | + if($quota !== 'none' && $quota !== 'default') { |
|
| 418 | + if (is_numeric($quota)) { |
|
| 419 | + $quota = (float) $quota; |
|
| 420 | + } else { |
|
| 421 | + $quota = \OCP\Util::computerFileSize($quota); |
|
| 422 | + } |
|
| 423 | + if ($quota === false) { |
|
| 424 | + throw new OCSException('Invalid quota value '.$value, 103); |
|
| 425 | + } |
|
| 426 | + if($quota === 0) { |
|
| 427 | + $quota = 'default'; |
|
| 428 | + }else if($quota === -1) { |
|
| 429 | + $quota = 'none'; |
|
| 430 | + } else { |
|
| 431 | + $quota = \OCP\Util::humanFileSize($quota); |
|
| 432 | + } |
|
| 433 | + } |
|
| 434 | + $targetUser->setQuota($quota); |
|
| 435 | + break; |
|
| 436 | + case 'password': |
|
| 437 | + $targetUser->setPassword($value); |
|
| 438 | + break; |
|
| 439 | + case 'language': |
|
| 440 | + $languagesCodes = $this->l10nFactory->findAvailableLanguages(); |
|
| 441 | + if (!in_array($value, $languagesCodes, true) && $value !== 'en') { |
|
| 442 | + throw new OCSException('Invalid language', 102); |
|
| 443 | + } |
|
| 444 | + $this->config->setUserValue($targetUser->getUID(), 'core', 'lang', $value); |
|
| 445 | + break; |
|
| 446 | + case AccountManager::PROPERTY_EMAIL: |
|
| 447 | + if(filter_var($value, FILTER_VALIDATE_EMAIL)) { |
|
| 448 | + $targetUser->setEMailAddress($value); |
|
| 449 | + } else { |
|
| 450 | + throw new OCSException('', 102); |
|
| 451 | + } |
|
| 452 | + break; |
|
| 453 | + case AccountManager::PROPERTY_PHONE: |
|
| 454 | + case AccountManager::PROPERTY_ADDRESS: |
|
| 455 | + case AccountManager::PROPERTY_WEBSITE: |
|
| 456 | + case AccountManager::PROPERTY_TWITTER: |
|
| 457 | + $userAccount = $this->accountManager->getUser($targetUser); |
|
| 458 | + if ($userAccount[$key]['value'] !== $value) { |
|
| 459 | + $userAccount[$key]['value'] = $value; |
|
| 460 | + $this->accountManager->updateUser($targetUser, $userAccount); |
|
| 461 | + } |
|
| 462 | + break; |
|
| 463 | + default: |
|
| 464 | + throw new OCSException('', 103); |
|
| 465 | + } |
|
| 466 | + return new DataResponse(); |
|
| 467 | + } |
|
| 468 | + |
|
| 469 | + /** |
|
| 470 | + * @PasswordConfirmationRequired |
|
| 471 | + * @NoAdminRequired |
|
| 472 | + * |
|
| 473 | + * @param string $userId |
|
| 474 | + * @return DataResponse |
|
| 475 | + * @throws OCSException |
|
| 476 | + * @throws OCSForbiddenException |
|
| 477 | + */ |
|
| 478 | + public function deleteUser($userId) { |
|
| 479 | + $currentLoggedInUser = $this->userSession->getUser(); |
|
| 480 | + |
|
| 481 | + $targetUser = $this->userManager->get($userId); |
|
| 482 | + |
|
| 483 | + if($targetUser === null || $targetUser->getUID() === $currentLoggedInUser->getUID()) { |
|
| 484 | + throw new OCSException('', 101); |
|
| 485 | + } |
|
| 486 | + |
|
| 487 | + // If not permitted |
|
| 488 | + $subAdminManager = $this->groupManager->getSubAdmin(); |
|
| 489 | + if(!$this->groupManager->isAdmin($currentLoggedInUser->getUID()) && !$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)) { |
|
| 490 | + throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
| 491 | + } |
|
| 492 | + |
|
| 493 | + // Go ahead with the delete |
|
| 494 | + if($targetUser->delete()) { |
|
| 495 | + return new DataResponse(); |
|
| 496 | + } else { |
|
| 497 | + throw new OCSException('', 101); |
|
| 498 | + } |
|
| 499 | + } |
|
| 500 | + |
|
| 501 | + /** |
|
| 502 | + * @PasswordConfirmationRequired |
|
| 503 | + * @NoAdminRequired |
|
| 504 | + * |
|
| 505 | + * @param string $userId |
|
| 506 | + * @return DataResponse |
|
| 507 | + * @throws OCSException |
|
| 508 | + * @throws OCSForbiddenException |
|
| 509 | + */ |
|
| 510 | + public function disableUser($userId) { |
|
| 511 | + return $this->setEnabled($userId, false); |
|
| 512 | + } |
|
| 513 | + |
|
| 514 | + /** |
|
| 515 | + * @PasswordConfirmationRequired |
|
| 516 | + * @NoAdminRequired |
|
| 517 | + * |
|
| 518 | + * @param string $userId |
|
| 519 | + * @return DataResponse |
|
| 520 | + * @throws OCSException |
|
| 521 | + * @throws OCSForbiddenException |
|
| 522 | + */ |
|
| 523 | + public function enableUser($userId) { |
|
| 524 | + return $this->setEnabled($userId, true); |
|
| 525 | + } |
|
| 526 | + |
|
| 527 | + /** |
|
| 528 | + * @param string $userId |
|
| 529 | + * @param bool $value |
|
| 530 | + * @return DataResponse |
|
| 531 | + * @throws OCSException |
|
| 532 | + * @throws OCSForbiddenException |
|
| 533 | + */ |
|
| 534 | + private function setEnabled($userId, $value) { |
|
| 535 | + $currentLoggedInUser = $this->userSession->getUser(); |
|
| 536 | + |
|
| 537 | + $targetUser = $this->userManager->get($userId); |
|
| 538 | + if($targetUser === null || $targetUser->getUID() === $currentLoggedInUser->getUID()) { |
|
| 539 | + throw new OCSException('', 101); |
|
| 540 | + } |
|
| 541 | + |
|
| 542 | + // If not permitted |
|
| 543 | + $subAdminManager = $this->groupManager->getSubAdmin(); |
|
| 544 | + if(!$this->groupManager->isAdmin($currentLoggedInUser->getUID()) && !$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)) { |
|
| 545 | + throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
| 546 | + } |
|
| 547 | + |
|
| 548 | + // enable/disable the user now |
|
| 549 | + $targetUser->setEnabled($value); |
|
| 550 | + return new DataResponse(); |
|
| 551 | + } |
|
| 552 | + |
|
| 553 | + /** |
|
| 554 | + * @NoAdminRequired |
|
| 555 | + * @NoSubAdminRequired |
|
| 556 | + * |
|
| 557 | + * @param string $userId |
|
| 558 | + * @return DataResponse |
|
| 559 | + * @throws OCSException |
|
| 560 | + */ |
|
| 561 | + public function getUsersGroups($userId) { |
|
| 562 | + $loggedInUser = $this->userSession->getUser(); |
|
| 563 | + |
|
| 564 | + $targetUser = $this->userManager->get($userId); |
|
| 565 | + if($targetUser === null) { |
|
| 566 | + throw new OCSException('', \OCP\API::RESPOND_NOT_FOUND); |
|
| 567 | + } |
|
| 568 | + |
|
| 569 | + if($targetUser->getUID() === $loggedInUser->getUID() || $this->groupManager->isAdmin($loggedInUser->getUID())) { |
|
| 570 | + // Self lookup or admin lookup |
|
| 571 | + return new DataResponse([ |
|
| 572 | + 'groups' => $this->groupManager->getUserGroupIds($targetUser) |
|
| 573 | + ]); |
|
| 574 | + } else { |
|
| 575 | + $subAdminManager = $this->groupManager->getSubAdmin(); |
|
| 576 | + |
|
| 577 | + // Looking up someone else |
|
| 578 | + if($subAdminManager->isUserAccessible($loggedInUser, $targetUser)) { |
|
| 579 | + // Return the group that the method caller is subadmin of for the user in question |
|
| 580 | + /** @var IGroup[] $getSubAdminsGroups */ |
|
| 581 | + $getSubAdminsGroups = $subAdminManager->getSubAdminsGroups($loggedInUser); |
|
| 582 | + foreach ($getSubAdminsGroups as $key => $group) { |
|
| 583 | + $getSubAdminsGroups[$key] = $group->getGID(); |
|
| 584 | + } |
|
| 585 | + $groups = array_intersect( |
|
| 586 | + $getSubAdminsGroups, |
|
| 587 | + $this->groupManager->getUserGroupIds($targetUser) |
|
| 588 | + ); |
|
| 589 | + return new DataResponse(['groups' => $groups]); |
|
| 590 | + } else { |
|
| 591 | + // Not permitted |
|
| 592 | + throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
| 593 | + } |
|
| 594 | + } |
|
| 595 | + |
|
| 596 | + } |
|
| 597 | + |
|
| 598 | + /** |
|
| 599 | + * @PasswordConfirmationRequired |
|
| 600 | + * @NoAdminRequired |
|
| 601 | + * |
|
| 602 | + * @param string $userId |
|
| 603 | + * @param string $groupid |
|
| 604 | + * @return DataResponse |
|
| 605 | + * @throws OCSException |
|
| 606 | + */ |
|
| 607 | + public function addToGroup($userId, $groupid = '') { |
|
| 608 | + if($groupid === '') { |
|
| 609 | + throw new OCSException('', 101); |
|
| 610 | + } |
|
| 611 | + |
|
| 612 | + $group = $this->groupManager->get($groupid); |
|
| 613 | + $targetUser = $this->userManager->get($userId); |
|
| 614 | + if($group === null) { |
|
| 615 | + throw new OCSException('', 102); |
|
| 616 | + } |
|
| 617 | + if($targetUser === null) { |
|
| 618 | + throw new OCSException('', 103); |
|
| 619 | + } |
|
| 620 | + |
|
| 621 | + // If they're not an admin, check they are a subadmin of the group in question |
|
| 622 | + $loggedInUser = $this->userSession->getUser(); |
|
| 623 | + $subAdminManager = $this->groupManager->getSubAdmin(); |
|
| 624 | + if (!$this->groupManager->isAdmin($loggedInUser->getUID()) && !$subAdminManager->isSubAdminOfGroup($loggedInUser, $group)) { |
|
| 625 | + throw new OCSException('', 104); |
|
| 626 | + } |
|
| 627 | + |
|
| 628 | + // Add user to group |
|
| 629 | + $group->addUser($targetUser); |
|
| 630 | + return new DataResponse(); |
|
| 631 | + } |
|
| 632 | + |
|
| 633 | + /** |
|
| 634 | + * @PasswordConfirmationRequired |
|
| 635 | + * @NoAdminRequired |
|
| 636 | + * |
|
| 637 | + * @param string $userId |
|
| 638 | + * @param string $groupid |
|
| 639 | + * @return DataResponse |
|
| 640 | + * @throws OCSException |
|
| 641 | + */ |
|
| 642 | + public function removeFromGroup($userId, $groupid) { |
|
| 643 | + $loggedInUser = $this->userSession->getUser(); |
|
| 644 | + |
|
| 645 | + if($groupid === null || trim($groupid) === '') { |
|
| 646 | + throw new OCSException('', 101); |
|
| 647 | + } |
|
| 648 | + |
|
| 649 | + $group = $this->groupManager->get($groupid); |
|
| 650 | + if($group === null) { |
|
| 651 | + throw new OCSException('', 102); |
|
| 652 | + } |
|
| 653 | + |
|
| 654 | + $targetUser = $this->userManager->get($userId); |
|
| 655 | + if($targetUser === null) { |
|
| 656 | + throw new OCSException('', 103); |
|
| 657 | + } |
|
| 658 | + |
|
| 659 | + // If they're not an admin, check they are a subadmin of the group in question |
|
| 660 | + $subAdminManager = $this->groupManager->getSubAdmin(); |
|
| 661 | + if (!$this->groupManager->isAdmin($loggedInUser->getUID()) && !$subAdminManager->isSubAdminOfGroup($loggedInUser, $group)) { |
|
| 662 | + throw new OCSException('', 104); |
|
| 663 | + } |
|
| 664 | + |
|
| 665 | + // Check they aren't removing themselves from 'admin' or their 'subadmin; group |
|
| 666 | + if ($targetUser->getUID() === $loggedInUser->getUID()) { |
|
| 667 | + if ($this->groupManager->isAdmin($loggedInUser->getUID())) { |
|
| 668 | + if ($group->getGID() === 'admin') { |
|
| 669 | + throw new OCSException('Cannot remove yourself from the admin group', 105); |
|
| 670 | + } |
|
| 671 | + } else { |
|
| 672 | + // Not an admin, so the user must be a subadmin of this group, but that is not allowed. |
|
| 673 | + throw new OCSException('Cannot remove yourself from this group as you are a SubAdmin', 105); |
|
| 674 | + } |
|
| 675 | + |
|
| 676 | + } else if (!$this->groupManager->isAdmin($loggedInUser->getUID())) { |
|
| 677 | + /** @var IGroup[] $subAdminGroups */ |
|
| 678 | + $subAdminGroups = $subAdminManager->getSubAdminsGroups($loggedInUser); |
|
| 679 | + $subAdminGroups = array_map(function (IGroup $subAdminGroup) { |
|
| 680 | + return $subAdminGroup->getGID(); |
|
| 681 | + }, $subAdminGroups); |
|
| 682 | + $userGroups = $this->groupManager->getUserGroupIds($targetUser); |
|
| 683 | + $userSubAdminGroups = array_intersect($subAdminGroups, $userGroups); |
|
| 684 | + |
|
| 685 | + if (count($userSubAdminGroups) <= 1) { |
|
| 686 | + // Subadmin must not be able to remove a user from all their subadmin groups. |
|
| 687 | + throw new OCSException('Cannot remove user from this group as this is the only remaining group you are a SubAdmin of', 105); |
|
| 688 | + } |
|
| 689 | + } |
|
| 690 | + |
|
| 691 | + // Remove user from group |
|
| 692 | + $group->removeUser($targetUser); |
|
| 693 | + return new DataResponse(); |
|
| 694 | + } |
|
| 695 | + |
|
| 696 | + /** |
|
| 697 | + * Creates a subadmin |
|
| 698 | + * |
|
| 699 | + * @PasswordConfirmationRequired |
|
| 700 | + * |
|
| 701 | + * @param string $userId |
|
| 702 | + * @param string $groupid |
|
| 703 | + * @return DataResponse |
|
| 704 | + * @throws OCSException |
|
| 705 | + */ |
|
| 706 | + public function addSubAdmin($userId, $groupid) { |
|
| 707 | + $group = $this->groupManager->get($groupid); |
|
| 708 | + $user = $this->userManager->get($userId); |
|
| 709 | + |
|
| 710 | + // Check if the user exists |
|
| 711 | + if($user === null) { |
|
| 712 | + throw new OCSException('User does not exist', 101); |
|
| 713 | + } |
|
| 714 | + // Check if group exists |
|
| 715 | + if($group === null) { |
|
| 716 | + throw new OCSException('Group does not exist', 102); |
|
| 717 | + } |
|
| 718 | + // Check if trying to make subadmin of admin group |
|
| 719 | + if($group->getGID() === 'admin') { |
|
| 720 | + throw new OCSException('Cannot create subadmins for admin group', 103); |
|
| 721 | + } |
|
| 722 | + |
|
| 723 | + $subAdminManager = $this->groupManager->getSubAdmin(); |
|
| 724 | + |
|
| 725 | + // We cannot be subadmin twice |
|
| 726 | + if ($subAdminManager->isSubAdminofGroup($user, $group)) { |
|
| 727 | + return new DataResponse(); |
|
| 728 | + } |
|
| 729 | + // Go |
|
| 730 | + if($subAdminManager->createSubAdmin($user, $group)) { |
|
| 731 | + return new DataResponse(); |
|
| 732 | + } else { |
|
| 733 | + throw new OCSException('Unknown error occurred', 103); |
|
| 734 | + } |
|
| 735 | + } |
|
| 736 | + |
|
| 737 | + /** |
|
| 738 | + * Removes a subadmin from a group |
|
| 739 | + * |
|
| 740 | + * @PasswordConfirmationRequired |
|
| 741 | + * |
|
| 742 | + * @param string $userId |
|
| 743 | + * @param string $groupid |
|
| 744 | + * @return DataResponse |
|
| 745 | + * @throws OCSException |
|
| 746 | + */ |
|
| 747 | + public function removeSubAdmin($userId, $groupid) { |
|
| 748 | + $group = $this->groupManager->get($groupid); |
|
| 749 | + $user = $this->userManager->get($userId); |
|
| 750 | + $subAdminManager = $this->groupManager->getSubAdmin(); |
|
| 751 | + |
|
| 752 | + // Check if the user exists |
|
| 753 | + if($user === null) { |
|
| 754 | + throw new OCSException('User does not exist', 101); |
|
| 755 | + } |
|
| 756 | + // Check if the group exists |
|
| 757 | + if($group === null) { |
|
| 758 | + throw new OCSException('Group does not exist', 101); |
|
| 759 | + } |
|
| 760 | + // Check if they are a subadmin of this said group |
|
| 761 | + if(!$subAdminManager->isSubAdminOfGroup($user, $group)) { |
|
| 762 | + throw new OCSException('User is not a subadmin of this group', 102); |
|
| 763 | + } |
|
| 764 | + |
|
| 765 | + // Go |
|
| 766 | + if($subAdminManager->deleteSubAdmin($user, $group)) { |
|
| 767 | + return new DataResponse(); |
|
| 768 | + } else { |
|
| 769 | + throw new OCSException('Unknown error occurred', 103); |
|
| 770 | + } |
|
| 771 | + } |
|
| 772 | + |
|
| 773 | + /** |
|
| 774 | + * Get the groups a user is a subadmin of |
|
| 775 | + * |
|
| 776 | + * @param string $userId |
|
| 777 | + * @return DataResponse |
|
| 778 | + * @throws OCSException |
|
| 779 | + */ |
|
| 780 | + public function getUserSubAdminGroups($userId) { |
|
| 781 | + $user = $this->userManager->get($userId); |
|
| 782 | + // Check if the user exists |
|
| 783 | + if($user === null) { |
|
| 784 | + throw new OCSException('User does not exist', 101); |
|
| 785 | + } |
|
| 786 | + |
|
| 787 | + // Get the subadmin groups |
|
| 788 | + $groups = $this->groupManager->getSubAdmin()->getSubAdminsGroups($user); |
|
| 789 | + foreach ($groups as $key => $group) { |
|
| 790 | + $groups[$key] = $group->getGID(); |
|
| 791 | + } |
|
| 792 | + |
|
| 793 | + if(!$groups) { |
|
| 794 | + throw new OCSException('Unknown error occurred', 102); |
|
| 795 | + } else { |
|
| 796 | + return new DataResponse($groups); |
|
| 797 | + } |
|
| 798 | + } |
|
| 799 | + |
|
| 800 | + /** |
|
| 801 | + * @param string $userId |
|
| 802 | + * @return array |
|
| 803 | + * @throws \OCP\Files\NotFoundException |
|
| 804 | + */ |
|
| 805 | + protected function fillStorageInfo($userId) { |
|
| 806 | + try { |
|
| 807 | + \OC_Util::tearDownFS(); |
|
| 808 | + \OC_Util::setupFS($userId); |
|
| 809 | + $storage = OC_Helper::getStorageInfo('/'); |
|
| 810 | + $data = [ |
|
| 811 | + 'free' => $storage['free'], |
|
| 812 | + 'used' => $storage['used'], |
|
| 813 | + 'total' => $storage['total'], |
|
| 814 | + 'relative' => $storage['relative'], |
|
| 815 | + 'quota' => $storage['quota'], |
|
| 816 | + ]; |
|
| 817 | + } catch (NotFoundException $ex) { |
|
| 818 | + $data = []; |
|
| 819 | + } |
|
| 820 | + return $data; |
|
| 821 | + } |
|
| 822 | + |
|
| 823 | + /** |
|
| 824 | + * @NoAdminRequired |
|
| 825 | + * @PasswordConfirmationRequired |
|
| 826 | + * |
|
| 827 | + * resend welcome message |
|
| 828 | + * |
|
| 829 | + * @param string $userId |
|
| 830 | + * @return DataResponse |
|
| 831 | + * @throws OCSException |
|
| 832 | + */ |
|
| 833 | + public function resendWelcomeMessage($userId) { |
|
| 834 | + $currentLoggedInUser = $this->userSession->getUser(); |
|
| 835 | + |
|
| 836 | + $targetUser = $this->userManager->get($userId); |
|
| 837 | + if($targetUser === null) { |
|
| 838 | + throw new OCSException('', \OCP\API::RESPOND_NOT_FOUND); |
|
| 839 | + } |
|
| 840 | + |
|
| 841 | + // Check if admin / subadmin |
|
| 842 | + $subAdminManager = $this->groupManager->getSubAdmin(); |
|
| 843 | + if(!$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser) |
|
| 844 | + && !$this->groupManager->isAdmin($currentLoggedInUser->getUID())) { |
|
| 845 | + // No rights |
|
| 846 | + throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
| 847 | + } |
|
| 848 | + |
|
| 849 | + $email = $targetUser->getEMailAddress(); |
|
| 850 | + if ($email === '' || $email === null) { |
|
| 851 | + throw new OCSException('Email address not available', 101); |
|
| 852 | + } |
|
| 853 | + $username = $targetUser->getUID(); |
|
| 854 | + $lang = $this->config->getUserValue($username, 'core', 'lang', 'en'); |
|
| 855 | + if (!$this->l10nFactory->languageExists('settings', $lang)) { |
|
| 856 | + $lang = 'en'; |
|
| 857 | + } |
|
| 858 | + |
|
| 859 | + $l10n = $this->l10nFactory->get('settings', $lang); |
|
| 860 | + |
|
| 861 | + try { |
|
| 862 | + $this->newUserMailHelper->setL10N($l10n); |
|
| 863 | + $emailTemplate = $this->newUserMailHelper->generateTemplate($targetUser, false); |
|
| 864 | + $this->newUserMailHelper->sendMail($targetUser, $emailTemplate); |
|
| 865 | + } catch(\Exception $e) { |
|
| 866 | + $this->logger->logException($e, [ |
|
| 867 | + 'message' => "Can't send new user mail to $email", |
|
| 868 | + 'level' => \OCP\Util::ERROR, |
|
| 869 | + 'app' => 'settings', |
|
| 870 | + ]); |
|
| 871 | + throw new OCSException('Sending email failed', 102); |
|
| 872 | + } |
|
| 873 | + |
|
| 874 | + return new DataResponse(); |
|
| 875 | + } |
|
| 876 | 876 | } |