@@ -32,97 +32,97 @@ |
||
| 32 | 32 | use OCP\Files\StorageNotAvailableException; |
| 33 | 33 | |
| 34 | 34 | class Scanner extends \OC\Files\Cache\Scanner { |
| 35 | - /** @var \OCA\Files_Sharing\External\Storage */ |
|
| 36 | - protected $storage; |
|
| 35 | + /** @var \OCA\Files_Sharing\External\Storage */ |
|
| 36 | + protected $storage; |
|
| 37 | 37 | |
| 38 | - /** {@inheritDoc} */ |
|
| 39 | - public function scan($path, $recursive = self::SCAN_RECURSIVE, $reuse = -1, $lock = true) { |
|
| 40 | - if(!$this->storage->remoteIsOwnCloud()) { |
|
| 41 | - return parent::scan($path, $recursive, $recursive, $lock); |
|
| 42 | - } |
|
| 38 | + /** {@inheritDoc} */ |
|
| 39 | + public function scan($path, $recursive = self::SCAN_RECURSIVE, $reuse = -1, $lock = true) { |
|
| 40 | + if(!$this->storage->remoteIsOwnCloud()) { |
|
| 41 | + return parent::scan($path, $recursive, $recursive, $lock); |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - $this->scanAll(); |
|
| 45 | - } |
|
| 44 | + $this->scanAll(); |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * Scan a single file and store it in the cache. |
|
| 49 | - * If an exception happened while accessing the external storage, |
|
| 50 | - * the storage will be checked for availability and removed |
|
| 51 | - * if it is not available any more. |
|
| 52 | - * |
|
| 53 | - * @param string $file file to scan |
|
| 54 | - * @param int $reuseExisting |
|
| 55 | - * @param int $parentId |
|
| 56 | - * @param array | null $cacheData existing data in the cache for the file to be scanned |
|
| 57 | - * @param bool $lock set to false to disable getting an additional read lock during scanning |
|
| 58 | - * @return array an array of metadata of the scanned file |
|
| 59 | - */ |
|
| 60 | - public function scanFile($file, $reuseExisting = 0, $parentId = -1, $cacheData = null, $lock = true) { |
|
| 61 | - try { |
|
| 62 | - return parent::scanFile($file, $reuseExisting); |
|
| 63 | - } catch (ForbiddenException $e) { |
|
| 64 | - $this->storage->checkStorageAvailability(); |
|
| 65 | - } catch (NotFoundException $e) { |
|
| 66 | - // if the storage isn't found, the call to |
|
| 67 | - // checkStorageAvailable() will verify it and remove it |
|
| 68 | - // if appropriate |
|
| 69 | - $this->storage->checkStorageAvailability(); |
|
| 70 | - } catch (StorageInvalidException $e) { |
|
| 71 | - $this->storage->checkStorageAvailability(); |
|
| 72 | - } catch (StorageNotAvailableException $e) { |
|
| 73 | - $this->storage->checkStorageAvailability(); |
|
| 74 | - } |
|
| 75 | - } |
|
| 47 | + /** |
|
| 48 | + * Scan a single file and store it in the cache. |
|
| 49 | + * If an exception happened while accessing the external storage, |
|
| 50 | + * the storage will be checked for availability and removed |
|
| 51 | + * if it is not available any more. |
|
| 52 | + * |
|
| 53 | + * @param string $file file to scan |
|
| 54 | + * @param int $reuseExisting |
|
| 55 | + * @param int $parentId |
|
| 56 | + * @param array | null $cacheData existing data in the cache for the file to be scanned |
|
| 57 | + * @param bool $lock set to false to disable getting an additional read lock during scanning |
|
| 58 | + * @return array an array of metadata of the scanned file |
|
| 59 | + */ |
|
| 60 | + public function scanFile($file, $reuseExisting = 0, $parentId = -1, $cacheData = null, $lock = true) { |
|
| 61 | + try { |
|
| 62 | + return parent::scanFile($file, $reuseExisting); |
|
| 63 | + } catch (ForbiddenException $e) { |
|
| 64 | + $this->storage->checkStorageAvailability(); |
|
| 65 | + } catch (NotFoundException $e) { |
|
| 66 | + // if the storage isn't found, the call to |
|
| 67 | + // checkStorageAvailable() will verify it and remove it |
|
| 68 | + // if appropriate |
|
| 69 | + $this->storage->checkStorageAvailability(); |
|
| 70 | + } catch (StorageInvalidException $e) { |
|
| 71 | + $this->storage->checkStorageAvailability(); |
|
| 72 | + } catch (StorageNotAvailableException $e) { |
|
| 73 | + $this->storage->checkStorageAvailability(); |
|
| 74 | + } |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | - /** |
|
| 78 | - * Checks the remote share for changes. |
|
| 79 | - * If changes are available, scan them and update |
|
| 80 | - * the cache. |
|
| 81 | - * @throws NotFoundException |
|
| 82 | - * @throws StorageInvalidException |
|
| 83 | - * @throws \Exception |
|
| 84 | - */ |
|
| 85 | - public function scanAll() { |
|
| 86 | - try { |
|
| 87 | - $data = $this->storage->getShareInfo(); |
|
| 88 | - } catch (\Exception $e) { |
|
| 89 | - $this->storage->checkStorageAvailability(); |
|
| 90 | - throw new \Exception( |
|
| 91 | - 'Error while scanning remote share: "' . |
|
| 92 | - $this->storage->getRemote() . '" ' . |
|
| 93 | - $e->getMessage() |
|
| 94 | - ); |
|
| 95 | - } |
|
| 96 | - if ($data['status'] === 'success') { |
|
| 97 | - $this->addResult($data['data'], ''); |
|
| 98 | - } else { |
|
| 99 | - throw new \Exception( |
|
| 100 | - 'Error while scanning remote share: "' . |
|
| 101 | - $this->storage->getRemote() . '"' |
|
| 102 | - ); |
|
| 103 | - } |
|
| 104 | - } |
|
| 77 | + /** |
|
| 78 | + * Checks the remote share for changes. |
|
| 79 | + * If changes are available, scan them and update |
|
| 80 | + * the cache. |
|
| 81 | + * @throws NotFoundException |
|
| 82 | + * @throws StorageInvalidException |
|
| 83 | + * @throws \Exception |
|
| 84 | + */ |
|
| 85 | + public function scanAll() { |
|
| 86 | + try { |
|
| 87 | + $data = $this->storage->getShareInfo(); |
|
| 88 | + } catch (\Exception $e) { |
|
| 89 | + $this->storage->checkStorageAvailability(); |
|
| 90 | + throw new \Exception( |
|
| 91 | + 'Error while scanning remote share: "' . |
|
| 92 | + $this->storage->getRemote() . '" ' . |
|
| 93 | + $e->getMessage() |
|
| 94 | + ); |
|
| 95 | + } |
|
| 96 | + if ($data['status'] === 'success') { |
|
| 97 | + $this->addResult($data['data'], ''); |
|
| 98 | + } else { |
|
| 99 | + throw new \Exception( |
|
| 100 | + 'Error while scanning remote share: "' . |
|
| 101 | + $this->storage->getRemote() . '"' |
|
| 102 | + ); |
|
| 103 | + } |
|
| 104 | + } |
|
| 105 | 105 | |
| 106 | - /** |
|
| 107 | - * @param array $data |
|
| 108 | - * @param string $path |
|
| 109 | - */ |
|
| 110 | - private function addResult($data, $path) { |
|
| 111 | - $id = $this->cache->put($path, $data); |
|
| 112 | - if (isset($data['children'])) { |
|
| 113 | - $children = []; |
|
| 114 | - foreach ($data['children'] as $child) { |
|
| 115 | - $children[$child['name']] = true; |
|
| 116 | - $this->addResult($child, ltrim($path . '/' . $child['name'], '/')); |
|
| 117 | - } |
|
| 106 | + /** |
|
| 107 | + * @param array $data |
|
| 108 | + * @param string $path |
|
| 109 | + */ |
|
| 110 | + private function addResult($data, $path) { |
|
| 111 | + $id = $this->cache->put($path, $data); |
|
| 112 | + if (isset($data['children'])) { |
|
| 113 | + $children = []; |
|
| 114 | + foreach ($data['children'] as $child) { |
|
| 115 | + $children[$child['name']] = true; |
|
| 116 | + $this->addResult($child, ltrim($path . '/' . $child['name'], '/')); |
|
| 117 | + } |
|
| 118 | 118 | |
| 119 | - $existingCache = $this->cache->getFolderContentsById($id); |
|
| 120 | - foreach ($existingCache as $existingChild) { |
|
| 121 | - // if an existing child is not in the new data, remove it |
|
| 122 | - if (!isset($children[$existingChild['name']])) { |
|
| 123 | - $this->cache->remove(ltrim($path . '/' . $existingChild['name'], '/')); |
|
| 124 | - } |
|
| 125 | - } |
|
| 126 | - } |
|
| 127 | - } |
|
| 119 | + $existingCache = $this->cache->getFolderContentsById($id); |
|
| 120 | + foreach ($existingCache as $existingChild) { |
|
| 121 | + // if an existing child is not in the new data, remove it |
|
| 122 | + if (!isset($children[$existingChild['name']])) { |
|
| 123 | + $this->cache->remove(ltrim($path . '/' . $existingChild['name'], '/')); |
|
| 124 | + } |
|
| 125 | + } |
|
| 126 | + } |
|
| 127 | + } |
|
| 128 | 128 | } |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | |
| 38 | 38 | /** {@inheritDoc} */ |
| 39 | 39 | public function scan($path, $recursive = self::SCAN_RECURSIVE, $reuse = -1, $lock = true) { |
| 40 | - if(!$this->storage->remoteIsOwnCloud()) { |
|
| 40 | + if (!$this->storage->remoteIsOwnCloud()) { |
|
| 41 | 41 | return parent::scan($path, $recursive, $recursive, $lock); |
| 42 | 42 | } |
| 43 | 43 | |
@@ -88,8 +88,8 @@ discard block |
||
| 88 | 88 | } catch (\Exception $e) { |
| 89 | 89 | $this->storage->checkStorageAvailability(); |
| 90 | 90 | throw new \Exception( |
| 91 | - 'Error while scanning remote share: "' . |
|
| 92 | - $this->storage->getRemote() . '" ' . |
|
| 91 | + 'Error while scanning remote share: "'. |
|
| 92 | + $this->storage->getRemote().'" '. |
|
| 93 | 93 | $e->getMessage() |
| 94 | 94 | ); |
| 95 | 95 | } |
@@ -97,8 +97,8 @@ discard block |
||
| 97 | 97 | $this->addResult($data['data'], ''); |
| 98 | 98 | } else { |
| 99 | 99 | throw new \Exception( |
| 100 | - 'Error while scanning remote share: "' . |
|
| 101 | - $this->storage->getRemote() . '"' |
|
| 100 | + 'Error while scanning remote share: "'. |
|
| 101 | + $this->storage->getRemote().'"' |
|
| 102 | 102 | ); |
| 103 | 103 | } |
| 104 | 104 | } |
@@ -113,14 +113,14 @@ discard block |
||
| 113 | 113 | $children = []; |
| 114 | 114 | foreach ($data['children'] as $child) { |
| 115 | 115 | $children[$child['name']] = true; |
| 116 | - $this->addResult($child, ltrim($path . '/' . $child['name'], '/')); |
|
| 116 | + $this->addResult($child, ltrim($path.'/'.$child['name'], '/')); |
|
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | $existingCache = $this->cache->getFolderContentsById($id); |
| 120 | 120 | foreach ($existingCache as $existingChild) { |
| 121 | 121 | // if an existing child is not in the new data, remove it |
| 122 | 122 | if (!isset($children[$existingChild['name']])) { |
| 123 | - $this->cache->remove(ltrim($path . '/' . $existingChild['name'], '/')); |
|
| 123 | + $this->cache->remove(ltrim($path.'/'.$existingChild['name'], '/')); |
|
| 124 | 124 | } |
| 125 | 125 | } |
| 126 | 126 | } |
@@ -27,44 +27,44 @@ |
||
| 27 | 27 | use OCP\Federation\ICloudId; |
| 28 | 28 | |
| 29 | 29 | class Cache extends \OC\Files\Cache\Cache { |
| 30 | - /** @var ICloudId */ |
|
| 31 | - private $cloudId; |
|
| 32 | - private $remote; |
|
| 33 | - private $remoteUser; |
|
| 34 | - private $storage; |
|
| 30 | + /** @var ICloudId */ |
|
| 31 | + private $cloudId; |
|
| 32 | + private $remote; |
|
| 33 | + private $remoteUser; |
|
| 34 | + private $storage; |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * @param \OCA\Files_Sharing\External\Storage $storage |
|
| 38 | - * @param ICloudId $cloudId |
|
| 39 | - */ |
|
| 40 | - public function __construct($storage, ICloudId $cloudId) { |
|
| 41 | - $this->cloudId = $cloudId; |
|
| 42 | - $this->storage = $storage; |
|
| 43 | - list(, $remote) = explode('://', $cloudId->getRemote(), 2); |
|
| 44 | - $this->remote = $remote; |
|
| 45 | - $this->remoteUser = $cloudId->getUser(); |
|
| 46 | - parent::__construct($storage); |
|
| 47 | - } |
|
| 36 | + /** |
|
| 37 | + * @param \OCA\Files_Sharing\External\Storage $storage |
|
| 38 | + * @param ICloudId $cloudId |
|
| 39 | + */ |
|
| 40 | + public function __construct($storage, ICloudId $cloudId) { |
|
| 41 | + $this->cloudId = $cloudId; |
|
| 42 | + $this->storage = $storage; |
|
| 43 | + list(, $remote) = explode('://', $cloudId->getRemote(), 2); |
|
| 44 | + $this->remote = $remote; |
|
| 45 | + $this->remoteUser = $cloudId->getUser(); |
|
| 46 | + parent::__construct($storage); |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - public function get($file) { |
|
| 50 | - $result = parent::get($file); |
|
| 51 | - if (!$result) { |
|
| 52 | - return false; |
|
| 53 | - } |
|
| 54 | - $result['displayname_owner'] = $this->cloudId->getDisplayId(); |
|
| 55 | - if (!$file || $file === '') { |
|
| 56 | - $result['is_share_mount_point'] = true; |
|
| 57 | - $mountPoint = rtrim($this->storage->getMountPoint()); |
|
| 58 | - $result['name'] = basename($mountPoint); |
|
| 59 | - } |
|
| 60 | - return $result; |
|
| 61 | - } |
|
| 49 | + public function get($file) { |
|
| 50 | + $result = parent::get($file); |
|
| 51 | + if (!$result) { |
|
| 52 | + return false; |
|
| 53 | + } |
|
| 54 | + $result['displayname_owner'] = $this->cloudId->getDisplayId(); |
|
| 55 | + if (!$file || $file === '') { |
|
| 56 | + $result['is_share_mount_point'] = true; |
|
| 57 | + $mountPoint = rtrim($this->storage->getMountPoint()); |
|
| 58 | + $result['name'] = basename($mountPoint); |
|
| 59 | + } |
|
| 60 | + return $result; |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - public function getFolderContentsById($id) { |
|
| 64 | - $results = parent::getFolderContentsById($id); |
|
| 65 | - foreach ($results as &$file) { |
|
| 66 | - $file['displayname_owner'] = $this->cloudId->getDisplayId(); |
|
| 67 | - } |
|
| 68 | - return $results; |
|
| 69 | - } |
|
| 63 | + public function getFolderContentsById($id) { |
|
| 64 | + $results = parent::getFolderContentsById($id); |
|
| 65 | + foreach ($results as &$file) { |
|
| 66 | + $file['displayname_owner'] = $this->cloudId->getDisplayId(); |
|
| 67 | + } |
|
| 68 | + return $results; |
|
| 69 | + } |
|
| 70 | 70 | } |
@@ -29,59 +29,59 @@ |
||
| 29 | 29 | use OCP\IUser; |
| 30 | 30 | |
| 31 | 31 | class MountProvider implements IMountProvider { |
| 32 | - const STORAGE = '\OCA\Files_Sharing\External\Storage'; |
|
| 32 | + const STORAGE = '\OCA\Files_Sharing\External\Storage'; |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * @var \OCP\IDBConnection |
|
| 36 | - */ |
|
| 37 | - private $connection; |
|
| 34 | + /** |
|
| 35 | + * @var \OCP\IDBConnection |
|
| 36 | + */ |
|
| 37 | + private $connection; |
|
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * @var callable |
|
| 41 | - */ |
|
| 42 | - private $managerProvider; |
|
| 39 | + /** |
|
| 40 | + * @var callable |
|
| 41 | + */ |
|
| 42 | + private $managerProvider; |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * @var ICloudIdManager |
|
| 46 | - */ |
|
| 47 | - private $cloudIdManager; |
|
| 44 | + /** |
|
| 45 | + * @var ICloudIdManager |
|
| 46 | + */ |
|
| 47 | + private $cloudIdManager; |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * @param \OCP\IDBConnection $connection |
|
| 51 | - * @param callable $managerProvider due to setup order we need a callable that return the manager instead of the manager itself |
|
| 52 | - * @param ICloudIdManager $cloudIdManager |
|
| 53 | - */ |
|
| 54 | - public function __construct(IDBConnection $connection, callable $managerProvider, ICloudIdManager $cloudIdManager) { |
|
| 55 | - $this->connection = $connection; |
|
| 56 | - $this->managerProvider = $managerProvider; |
|
| 57 | - $this->cloudIdManager = $cloudIdManager; |
|
| 58 | - } |
|
| 49 | + /** |
|
| 50 | + * @param \OCP\IDBConnection $connection |
|
| 51 | + * @param callable $managerProvider due to setup order we need a callable that return the manager instead of the manager itself |
|
| 52 | + * @param ICloudIdManager $cloudIdManager |
|
| 53 | + */ |
|
| 54 | + public function __construct(IDBConnection $connection, callable $managerProvider, ICloudIdManager $cloudIdManager) { |
|
| 55 | + $this->connection = $connection; |
|
| 56 | + $this->managerProvider = $managerProvider; |
|
| 57 | + $this->cloudIdManager = $cloudIdManager; |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - public function getMount(IUser $user, $data, IStorageFactory $storageFactory) { |
|
| 61 | - $managerProvider = $this->managerProvider; |
|
| 62 | - $manager = $managerProvider(); |
|
| 63 | - $data['manager'] = $manager; |
|
| 64 | - $mountPoint = '/' . $user->getUID() . '/files/' . ltrim($data['mountpoint'], '/'); |
|
| 65 | - $data['mountpoint'] = $mountPoint; |
|
| 66 | - $data['cloudId'] = $this->cloudIdManager->getCloudId($data['owner'], $data['remote']); |
|
| 67 | - $data['certificateManager'] = \OC::$server->getCertificateManager($user->getUID()); |
|
| 68 | - $data['HttpClientService'] = \OC::$server->getHTTPClientService(); |
|
| 69 | - return new Mount(self::STORAGE, $mountPoint, $data, $manager, $storageFactory); |
|
| 70 | - } |
|
| 60 | + public function getMount(IUser $user, $data, IStorageFactory $storageFactory) { |
|
| 61 | + $managerProvider = $this->managerProvider; |
|
| 62 | + $manager = $managerProvider(); |
|
| 63 | + $data['manager'] = $manager; |
|
| 64 | + $mountPoint = '/' . $user->getUID() . '/files/' . ltrim($data['mountpoint'], '/'); |
|
| 65 | + $data['mountpoint'] = $mountPoint; |
|
| 66 | + $data['cloudId'] = $this->cloudIdManager->getCloudId($data['owner'], $data['remote']); |
|
| 67 | + $data['certificateManager'] = \OC::$server->getCertificateManager($user->getUID()); |
|
| 68 | + $data['HttpClientService'] = \OC::$server->getHTTPClientService(); |
|
| 69 | + return new Mount(self::STORAGE, $mountPoint, $data, $manager, $storageFactory); |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - public function getMountsForUser(IUser $user, IStorageFactory $loader) { |
|
| 73 | - $query = $this->connection->prepare(' |
|
| 72 | + public function getMountsForUser(IUser $user, IStorageFactory $loader) { |
|
| 73 | + $query = $this->connection->prepare(' |
|
| 74 | 74 | SELECT `remote`, `share_token`, `password`, `mountpoint`, `owner` |
| 75 | 75 | FROM `*PREFIX*share_external` |
| 76 | 76 | WHERE `user` = ? AND `accepted` = ? |
| 77 | 77 | '); |
| 78 | - $query->execute([$user->getUID(), 1]); |
|
| 79 | - $mounts = []; |
|
| 80 | - while ($row = $query->fetch()) { |
|
| 81 | - $row['manager'] = $this; |
|
| 82 | - $row['token'] = $row['share_token']; |
|
| 83 | - $mounts[] = $this->getMount($user, $row, $loader); |
|
| 84 | - } |
|
| 85 | - return $mounts; |
|
| 86 | - } |
|
| 78 | + $query->execute([$user->getUID(), 1]); |
|
| 79 | + $mounts = []; |
|
| 80 | + while ($row = $query->fetch()) { |
|
| 81 | + $row['manager'] = $this; |
|
| 82 | + $row['token'] = $row['share_token']; |
|
| 83 | + $mounts[] = $this->getMount($user, $row, $loader); |
|
| 84 | + } |
|
| 85 | + return $mounts; |
|
| 86 | + } |
|
| 87 | 87 | } |
@@ -61,7 +61,7 @@ |
||
| 61 | 61 | $managerProvider = $this->managerProvider; |
| 62 | 62 | $manager = $managerProvider(); |
| 63 | 63 | $data['manager'] = $manager; |
| 64 | - $mountPoint = '/' . $user->getUID() . '/files/' . ltrim($data['mountpoint'], '/'); |
|
| 64 | + $mountPoint = '/'.$user->getUID().'/files/'.ltrim($data['mountpoint'], '/'); |
|
| 65 | 65 | $data['mountpoint'] = $mountPoint; |
| 66 | 66 | $data['cloudId'] = $this->cloudIdManager->getCloudId($data['owner'], $data['remote']); |
| 67 | 67 | $data['certificateManager'] = \OC::$server->getCertificateManager($user->getUID()); |
@@ -23,12 +23,12 @@ |
||
| 23 | 23 | namespace OCA\Files_Sharing\External; |
| 24 | 24 | |
| 25 | 25 | class Watcher extends \OC\Files\Cache\Watcher { |
| 26 | - /** |
|
| 27 | - * remove deleted files in $path from the cache |
|
| 28 | - * |
|
| 29 | - * @param string $path |
|
| 30 | - */ |
|
| 31 | - public function cleanFolder($path) { |
|
| 32 | - // not needed, the scanner takes care of this |
|
| 33 | - } |
|
| 26 | + /** |
|
| 27 | + * remove deleted files in $path from the cache |
|
| 28 | + * |
|
| 29 | + * @param string $path |
|
| 30 | + */ |
|
| 31 | + public function cleanFolder($path) { |
|
| 32 | + // not needed, the scanner takes care of this |
|
| 33 | + } |
|
| 34 | 34 | } |
@@ -31,36 +31,36 @@ |
||
| 31 | 31 | */ |
| 32 | 32 | class DeleteOrphanedSharesJob extends TimedJob { |
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * Default interval in minutes |
|
| 36 | - * |
|
| 37 | - * @var int $defaultIntervalMin |
|
| 38 | - **/ |
|
| 39 | - protected $defaultIntervalMin = 15; |
|
| 34 | + /** |
|
| 35 | + * Default interval in minutes |
|
| 36 | + * |
|
| 37 | + * @var int $defaultIntervalMin |
|
| 38 | + **/ |
|
| 39 | + protected $defaultIntervalMin = 15; |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * sets the correct interval for this timed job |
|
| 43 | - */ |
|
| 44 | - public function __construct(){ |
|
| 45 | - $this->interval = $this->defaultIntervalMin * 60; |
|
| 46 | - } |
|
| 41 | + /** |
|
| 42 | + * sets the correct interval for this timed job |
|
| 43 | + */ |
|
| 44 | + public function __construct(){ |
|
| 45 | + $this->interval = $this->defaultIntervalMin * 60; |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * Makes the background job do its work |
|
| 50 | - * |
|
| 51 | - * @param array $argument unused argument |
|
| 52 | - */ |
|
| 53 | - public function run($argument) { |
|
| 54 | - $connection = \OC::$server->getDatabaseConnection(); |
|
| 55 | - $logger = \OC::$server->getLogger(); |
|
| 48 | + /** |
|
| 49 | + * Makes the background job do its work |
|
| 50 | + * |
|
| 51 | + * @param array $argument unused argument |
|
| 52 | + */ |
|
| 53 | + public function run($argument) { |
|
| 54 | + $connection = \OC::$server->getDatabaseConnection(); |
|
| 55 | + $logger = \OC::$server->getLogger(); |
|
| 56 | 56 | |
| 57 | - $sql = |
|
| 58 | - 'DELETE FROM `*PREFIX*share` ' . |
|
| 59 | - 'WHERE `item_type` in (\'file\', \'folder\') ' . |
|
| 60 | - 'AND NOT EXISTS (SELECT `fileid` FROM `*PREFIX*filecache` WHERE `file_source` = `fileid`)'; |
|
| 57 | + $sql = |
|
| 58 | + 'DELETE FROM `*PREFIX*share` ' . |
|
| 59 | + 'WHERE `item_type` in (\'file\', \'folder\') ' . |
|
| 60 | + 'AND NOT EXISTS (SELECT `fileid` FROM `*PREFIX*filecache` WHERE `file_source` = `fileid`)'; |
|
| 61 | 61 | |
| 62 | - $deletedEntries = $connection->executeUpdate($sql); |
|
| 63 | - $logger->debug("$deletedEntries orphaned share(s) deleted", ['app' => 'DeleteOrphanedSharesJob']); |
|
| 64 | - } |
|
| 62 | + $deletedEntries = $connection->executeUpdate($sql); |
|
| 63 | + $logger->debug("$deletedEntries orphaned share(s) deleted", ['app' => 'DeleteOrphanedSharesJob']); |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | 66 | } |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | /** |
| 42 | 42 | * sets the correct interval for this timed job |
| 43 | 43 | */ |
| 44 | - public function __construct(){ |
|
| 44 | + public function __construct() { |
|
| 45 | 45 | $this->interval = $this->defaultIntervalMin * 60; |
| 46 | 46 | } |
| 47 | 47 | |
@@ -55,8 +55,8 @@ discard block |
||
| 55 | 55 | $logger = \OC::$server->getLogger(); |
| 56 | 56 | |
| 57 | 57 | $sql = |
| 58 | - 'DELETE FROM `*PREFIX*share` ' . |
|
| 59 | - 'WHERE `item_type` in (\'file\', \'folder\') ' . |
|
| 58 | + 'DELETE FROM `*PREFIX*share` '. |
|
| 59 | + 'WHERE `item_type` in (\'file\', \'folder\') '. |
|
| 60 | 60 | 'AND NOT EXISTS (SELECT `fileid` FROM `*PREFIX*filecache` WHERE `file_source` = `fileid`)'; |
| 61 | 61 | |
| 62 | 62 | $deletedEntries = $connection->executeUpdate($sql); |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | */ |
| 97 | 97 | public function generateTarget($filePath, $shareWith, $exclude = null) { |
| 98 | 98 | $shareFolder = \OCA\Files_Sharing\Helper::getShareFolder(); |
| 99 | - $target = \OC\Files\Filesystem::normalizePath($shareFolder . '/' . basename($filePath)); |
|
| 99 | + $target = \OC\Files\Filesystem::normalizePath($shareFolder.'/'.basename($filePath)); |
|
| 100 | 100 | |
| 101 | 101 | // for group shares we return the target right away |
| 102 | 102 | if ($shareWith === false) { |
@@ -104,13 +104,13 @@ discard block |
||
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | \OC\Files\Filesystem::initMountPoints($shareWith); |
| 107 | - $view = new \OC\Files\View('/' . $shareWith . '/files'); |
|
| 107 | + $view = new \OC\Files\View('/'.$shareWith.'/files'); |
|
| 108 | 108 | |
| 109 | 109 | if (!$view->is_dir($shareFolder)) { |
| 110 | 110 | $dir = ''; |
| 111 | 111 | $subdirs = explode('/', $shareFolder); |
| 112 | 112 | foreach ($subdirs as $subdir) { |
| 113 | - $dir = $dir . '/' . $subdir; |
|
| 113 | + $dir = $dir.'/'.$subdir; |
|
| 114 | 114 | if (!$view->is_dir($dir)) { |
| 115 | 115 | $view->mkdir($dir); |
| 116 | 116 | } |
@@ -237,7 +237,7 @@ discard block |
||
| 237 | 237 | if ($share['item_type'] === 'folder' && $target !== '') { |
| 238 | 238 | // note: in case of ext storage mount points the path might be empty |
| 239 | 239 | // which would cause a leading slash to appear |
| 240 | - $share['path'] = ltrim($share['path'] . '/' . $target, '/'); |
|
| 240 | + $share['path'] = ltrim($share['path'].'/'.$target, '/'); |
|
| 241 | 241 | } |
| 242 | 242 | return self::resolveReshares($share); |
| 243 | 243 | } |
@@ -37,208 +37,208 @@ |
||
| 37 | 37 | |
| 38 | 38 | class File implements \OCP\Share_Backend_File_Dependent { |
| 39 | 39 | |
| 40 | - const FORMAT_SHARED_STORAGE = 0; |
|
| 41 | - const FORMAT_GET_FOLDER_CONTENTS = 1; |
|
| 42 | - const FORMAT_FILE_APP_ROOT = 2; |
|
| 43 | - const FORMAT_OPENDIR = 3; |
|
| 44 | - const FORMAT_GET_ALL = 4; |
|
| 45 | - const FORMAT_PERMISSIONS = 5; |
|
| 46 | - const FORMAT_TARGET_NAMES = 6; |
|
| 47 | - |
|
| 48 | - private $path; |
|
| 49 | - |
|
| 50 | - /** @var FederatedShareProvider */ |
|
| 51 | - private $federatedShareProvider; |
|
| 52 | - |
|
| 53 | - public function __construct(FederatedShareProvider $federatedShareProvider = null) { |
|
| 54 | - if ($federatedShareProvider) { |
|
| 55 | - $this->federatedShareProvider = $federatedShareProvider; |
|
| 56 | - } else { |
|
| 57 | - $federatedSharingApp = new \OCA\FederatedFileSharing\AppInfo\Application(); |
|
| 58 | - $this->federatedShareProvider = $federatedSharingApp->getFederatedShareProvider(); |
|
| 59 | - } |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - public function isValidSource($itemSource, $uidOwner) { |
|
| 63 | - try { |
|
| 64 | - $path = \OC\Files\Filesystem::getPath($itemSource); |
|
| 65 | - // FIXME: attributes should not be set here, |
|
| 66 | - // keeping this pattern for now to avoid unexpected |
|
| 67 | - // regressions |
|
| 68 | - $this->path = \OC\Files\Filesystem::normalizePath(basename($path)); |
|
| 69 | - return true; |
|
| 70 | - } catch (\OCP\Files\NotFoundException $e) { |
|
| 71 | - return false; |
|
| 72 | - } |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - public function getFilePath($itemSource, $uidOwner) { |
|
| 76 | - if (isset($this->path)) { |
|
| 77 | - $path = $this->path; |
|
| 78 | - $this->path = null; |
|
| 79 | - return $path; |
|
| 80 | - } else { |
|
| 81 | - try { |
|
| 82 | - $path = \OC\Files\Filesystem::getPath($itemSource); |
|
| 83 | - return $path; |
|
| 84 | - } catch (\OCP\Files\NotFoundException $e) { |
|
| 85 | - return false; |
|
| 86 | - } |
|
| 87 | - } |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * create unique target |
|
| 92 | - * @param string $filePath |
|
| 93 | - * @param string $shareWith |
|
| 94 | - * @param array $exclude (optional) |
|
| 95 | - * @return string |
|
| 96 | - */ |
|
| 97 | - public function generateTarget($filePath, $shareWith, $exclude = null) { |
|
| 98 | - $shareFolder = \OCA\Files_Sharing\Helper::getShareFolder(); |
|
| 99 | - $target = \OC\Files\Filesystem::normalizePath($shareFolder . '/' . basename($filePath)); |
|
| 100 | - |
|
| 101 | - // for group shares we return the target right away |
|
| 102 | - if ($shareWith === false) { |
|
| 103 | - return $target; |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - \OC\Files\Filesystem::initMountPoints($shareWith); |
|
| 107 | - $view = new \OC\Files\View('/' . $shareWith . '/files'); |
|
| 108 | - |
|
| 109 | - if (!$view->is_dir($shareFolder)) { |
|
| 110 | - $dir = ''; |
|
| 111 | - $subdirs = explode('/', $shareFolder); |
|
| 112 | - foreach ($subdirs as $subdir) { |
|
| 113 | - $dir = $dir . '/' . $subdir; |
|
| 114 | - if (!$view->is_dir($dir)) { |
|
| 115 | - $view->mkdir($dir); |
|
| 116 | - } |
|
| 117 | - } |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - $excludeList = is_array($exclude) ? $exclude : array(); |
|
| 121 | - |
|
| 122 | - return \OCA\Files_Sharing\Helper::generateUniqueTarget($target, $excludeList, $view); |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - public function formatItems($items, $format, $parameters = null) { |
|
| 126 | - if ($format === self::FORMAT_SHARED_STORAGE) { |
|
| 127 | - // Only 1 item should come through for this format call |
|
| 128 | - $item = array_shift($items); |
|
| 129 | - return array( |
|
| 130 | - 'parent' => $item['parent'], |
|
| 131 | - 'path' => $item['path'], |
|
| 132 | - 'storage' => $item['storage'], |
|
| 133 | - 'permissions' => $item['permissions'], |
|
| 134 | - 'uid_owner' => $item['uid_owner'], |
|
| 135 | - ); |
|
| 136 | - } else if ($format === self::FORMAT_GET_FOLDER_CONTENTS) { |
|
| 137 | - $files = array(); |
|
| 138 | - foreach ($items as $item) { |
|
| 139 | - $file = array(); |
|
| 140 | - $file['fileid'] = $item['file_source']; |
|
| 141 | - $file['storage'] = $item['storage']; |
|
| 142 | - $file['path'] = $item['file_target']; |
|
| 143 | - $file['parent'] = $item['file_parent']; |
|
| 144 | - $file['name'] = basename($item['file_target']); |
|
| 145 | - $file['mimetype'] = $item['mimetype']; |
|
| 146 | - $file['mimepart'] = $item['mimepart']; |
|
| 147 | - $file['mtime'] = $item['mtime']; |
|
| 148 | - $file['encrypted'] = $item['encrypted']; |
|
| 149 | - $file['etag'] = $item['etag']; |
|
| 150 | - $file['uid_owner'] = $item['uid_owner']; |
|
| 151 | - $file['displayname_owner'] = $item['displayname_owner']; |
|
| 152 | - |
|
| 153 | - $storage = \OC\Files\Filesystem::getStorage('/'); |
|
| 154 | - $cache = $storage->getCache(); |
|
| 155 | - $file['size'] = $item['size']; |
|
| 156 | - $files[] = $file; |
|
| 157 | - } |
|
| 158 | - return $files; |
|
| 159 | - } else if ($format === self::FORMAT_OPENDIR) { |
|
| 160 | - $files = array(); |
|
| 161 | - foreach ($items as $item) { |
|
| 162 | - $files[] = basename($item['file_target']); |
|
| 163 | - } |
|
| 164 | - return $files; |
|
| 165 | - } else if ($format === self::FORMAT_GET_ALL) { |
|
| 166 | - $ids = array(); |
|
| 167 | - foreach ($items as $item) { |
|
| 168 | - $ids[] = $item['file_source']; |
|
| 169 | - } |
|
| 170 | - return $ids; |
|
| 171 | - } else if ($format === self::FORMAT_PERMISSIONS) { |
|
| 172 | - $filePermissions = array(); |
|
| 173 | - foreach ($items as $item) { |
|
| 174 | - $filePermissions[$item['file_source']] = $item['permissions']; |
|
| 175 | - } |
|
| 176 | - return $filePermissions; |
|
| 177 | - } else if ($format === self::FORMAT_TARGET_NAMES) { |
|
| 178 | - $targets = array(); |
|
| 179 | - foreach ($items as $item) { |
|
| 180 | - $targets[] = $item['file_target']; |
|
| 181 | - } |
|
| 182 | - return $targets; |
|
| 183 | - } |
|
| 184 | - return array(); |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - /** |
|
| 188 | - * check if server2server share is enabled |
|
| 189 | - * |
|
| 190 | - * @param int $shareType |
|
| 191 | - * @return boolean |
|
| 192 | - */ |
|
| 193 | - public function isShareTypeAllowed($shareType) { |
|
| 194 | - if ($shareType === \OCP\Share::SHARE_TYPE_REMOTE) { |
|
| 195 | - return $this->federatedShareProvider->isOutgoingServer2serverShareEnabled(); |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - return true; |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - /** |
|
| 202 | - * resolve reshares to return the correct source item |
|
| 203 | - * @param array $source |
|
| 204 | - * @return array source item |
|
| 205 | - */ |
|
| 206 | - protected static function resolveReshares($source) { |
|
| 207 | - if (isset($source['parent'])) { |
|
| 208 | - $parent = $source['parent']; |
|
| 209 | - while (isset($parent)) { |
|
| 210 | - $query = \OCP\DB::prepare('SELECT `parent`, `uid_owner` FROM `*PREFIX*share` WHERE `id` = ?', 1); |
|
| 211 | - $item = $query->execute(array($parent))->fetchRow(); |
|
| 212 | - if (isset($item['parent'])) { |
|
| 213 | - $parent = $item['parent']; |
|
| 214 | - } else { |
|
| 215 | - $fileOwner = $item['uid_owner']; |
|
| 216 | - break; |
|
| 217 | - } |
|
| 218 | - } |
|
| 219 | - } else { |
|
| 220 | - $fileOwner = $source['uid_owner']; |
|
| 221 | - } |
|
| 222 | - if (isset($fileOwner)) { |
|
| 223 | - $source['fileOwner'] = $fileOwner; |
|
| 224 | - } else { |
|
| 225 | - \OCP\Util::writeLog('files_sharing', "No owner found for reshare", \OCP\Util::ERROR); |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - return $source; |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - /** |
|
| 232 | - * @param string $target |
|
| 233 | - * @param array $share |
|
| 234 | - * @return array|false source item |
|
| 235 | - */ |
|
| 236 | - public static function getSource($target, $share) { |
|
| 237 | - if ($share['item_type'] === 'folder' && $target !== '') { |
|
| 238 | - // note: in case of ext storage mount points the path might be empty |
|
| 239 | - // which would cause a leading slash to appear |
|
| 240 | - $share['path'] = ltrim($share['path'] . '/' . $target, '/'); |
|
| 241 | - } |
|
| 242 | - return self::resolveReshares($share); |
|
| 243 | - } |
|
| 40 | + const FORMAT_SHARED_STORAGE = 0; |
|
| 41 | + const FORMAT_GET_FOLDER_CONTENTS = 1; |
|
| 42 | + const FORMAT_FILE_APP_ROOT = 2; |
|
| 43 | + const FORMAT_OPENDIR = 3; |
|
| 44 | + const FORMAT_GET_ALL = 4; |
|
| 45 | + const FORMAT_PERMISSIONS = 5; |
|
| 46 | + const FORMAT_TARGET_NAMES = 6; |
|
| 47 | + |
|
| 48 | + private $path; |
|
| 49 | + |
|
| 50 | + /** @var FederatedShareProvider */ |
|
| 51 | + private $federatedShareProvider; |
|
| 52 | + |
|
| 53 | + public function __construct(FederatedShareProvider $federatedShareProvider = null) { |
|
| 54 | + if ($federatedShareProvider) { |
|
| 55 | + $this->federatedShareProvider = $federatedShareProvider; |
|
| 56 | + } else { |
|
| 57 | + $federatedSharingApp = new \OCA\FederatedFileSharing\AppInfo\Application(); |
|
| 58 | + $this->federatedShareProvider = $federatedSharingApp->getFederatedShareProvider(); |
|
| 59 | + } |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + public function isValidSource($itemSource, $uidOwner) { |
|
| 63 | + try { |
|
| 64 | + $path = \OC\Files\Filesystem::getPath($itemSource); |
|
| 65 | + // FIXME: attributes should not be set here, |
|
| 66 | + // keeping this pattern for now to avoid unexpected |
|
| 67 | + // regressions |
|
| 68 | + $this->path = \OC\Files\Filesystem::normalizePath(basename($path)); |
|
| 69 | + return true; |
|
| 70 | + } catch (\OCP\Files\NotFoundException $e) { |
|
| 71 | + return false; |
|
| 72 | + } |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + public function getFilePath($itemSource, $uidOwner) { |
|
| 76 | + if (isset($this->path)) { |
|
| 77 | + $path = $this->path; |
|
| 78 | + $this->path = null; |
|
| 79 | + return $path; |
|
| 80 | + } else { |
|
| 81 | + try { |
|
| 82 | + $path = \OC\Files\Filesystem::getPath($itemSource); |
|
| 83 | + return $path; |
|
| 84 | + } catch (\OCP\Files\NotFoundException $e) { |
|
| 85 | + return false; |
|
| 86 | + } |
|
| 87 | + } |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * create unique target |
|
| 92 | + * @param string $filePath |
|
| 93 | + * @param string $shareWith |
|
| 94 | + * @param array $exclude (optional) |
|
| 95 | + * @return string |
|
| 96 | + */ |
|
| 97 | + public function generateTarget($filePath, $shareWith, $exclude = null) { |
|
| 98 | + $shareFolder = \OCA\Files_Sharing\Helper::getShareFolder(); |
|
| 99 | + $target = \OC\Files\Filesystem::normalizePath($shareFolder . '/' . basename($filePath)); |
|
| 100 | + |
|
| 101 | + // for group shares we return the target right away |
|
| 102 | + if ($shareWith === false) { |
|
| 103 | + return $target; |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + \OC\Files\Filesystem::initMountPoints($shareWith); |
|
| 107 | + $view = new \OC\Files\View('/' . $shareWith . '/files'); |
|
| 108 | + |
|
| 109 | + if (!$view->is_dir($shareFolder)) { |
|
| 110 | + $dir = ''; |
|
| 111 | + $subdirs = explode('/', $shareFolder); |
|
| 112 | + foreach ($subdirs as $subdir) { |
|
| 113 | + $dir = $dir . '/' . $subdir; |
|
| 114 | + if (!$view->is_dir($dir)) { |
|
| 115 | + $view->mkdir($dir); |
|
| 116 | + } |
|
| 117 | + } |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + $excludeList = is_array($exclude) ? $exclude : array(); |
|
| 121 | + |
|
| 122 | + return \OCA\Files_Sharing\Helper::generateUniqueTarget($target, $excludeList, $view); |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + public function formatItems($items, $format, $parameters = null) { |
|
| 126 | + if ($format === self::FORMAT_SHARED_STORAGE) { |
|
| 127 | + // Only 1 item should come through for this format call |
|
| 128 | + $item = array_shift($items); |
|
| 129 | + return array( |
|
| 130 | + 'parent' => $item['parent'], |
|
| 131 | + 'path' => $item['path'], |
|
| 132 | + 'storage' => $item['storage'], |
|
| 133 | + 'permissions' => $item['permissions'], |
|
| 134 | + 'uid_owner' => $item['uid_owner'], |
|
| 135 | + ); |
|
| 136 | + } else if ($format === self::FORMAT_GET_FOLDER_CONTENTS) { |
|
| 137 | + $files = array(); |
|
| 138 | + foreach ($items as $item) { |
|
| 139 | + $file = array(); |
|
| 140 | + $file['fileid'] = $item['file_source']; |
|
| 141 | + $file['storage'] = $item['storage']; |
|
| 142 | + $file['path'] = $item['file_target']; |
|
| 143 | + $file['parent'] = $item['file_parent']; |
|
| 144 | + $file['name'] = basename($item['file_target']); |
|
| 145 | + $file['mimetype'] = $item['mimetype']; |
|
| 146 | + $file['mimepart'] = $item['mimepart']; |
|
| 147 | + $file['mtime'] = $item['mtime']; |
|
| 148 | + $file['encrypted'] = $item['encrypted']; |
|
| 149 | + $file['etag'] = $item['etag']; |
|
| 150 | + $file['uid_owner'] = $item['uid_owner']; |
|
| 151 | + $file['displayname_owner'] = $item['displayname_owner']; |
|
| 152 | + |
|
| 153 | + $storage = \OC\Files\Filesystem::getStorage('/'); |
|
| 154 | + $cache = $storage->getCache(); |
|
| 155 | + $file['size'] = $item['size']; |
|
| 156 | + $files[] = $file; |
|
| 157 | + } |
|
| 158 | + return $files; |
|
| 159 | + } else if ($format === self::FORMAT_OPENDIR) { |
|
| 160 | + $files = array(); |
|
| 161 | + foreach ($items as $item) { |
|
| 162 | + $files[] = basename($item['file_target']); |
|
| 163 | + } |
|
| 164 | + return $files; |
|
| 165 | + } else if ($format === self::FORMAT_GET_ALL) { |
|
| 166 | + $ids = array(); |
|
| 167 | + foreach ($items as $item) { |
|
| 168 | + $ids[] = $item['file_source']; |
|
| 169 | + } |
|
| 170 | + return $ids; |
|
| 171 | + } else if ($format === self::FORMAT_PERMISSIONS) { |
|
| 172 | + $filePermissions = array(); |
|
| 173 | + foreach ($items as $item) { |
|
| 174 | + $filePermissions[$item['file_source']] = $item['permissions']; |
|
| 175 | + } |
|
| 176 | + return $filePermissions; |
|
| 177 | + } else if ($format === self::FORMAT_TARGET_NAMES) { |
|
| 178 | + $targets = array(); |
|
| 179 | + foreach ($items as $item) { |
|
| 180 | + $targets[] = $item['file_target']; |
|
| 181 | + } |
|
| 182 | + return $targets; |
|
| 183 | + } |
|
| 184 | + return array(); |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + /** |
|
| 188 | + * check if server2server share is enabled |
|
| 189 | + * |
|
| 190 | + * @param int $shareType |
|
| 191 | + * @return boolean |
|
| 192 | + */ |
|
| 193 | + public function isShareTypeAllowed($shareType) { |
|
| 194 | + if ($shareType === \OCP\Share::SHARE_TYPE_REMOTE) { |
|
| 195 | + return $this->federatedShareProvider->isOutgoingServer2serverShareEnabled(); |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + return true; |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + /** |
|
| 202 | + * resolve reshares to return the correct source item |
|
| 203 | + * @param array $source |
|
| 204 | + * @return array source item |
|
| 205 | + */ |
|
| 206 | + protected static function resolveReshares($source) { |
|
| 207 | + if (isset($source['parent'])) { |
|
| 208 | + $parent = $source['parent']; |
|
| 209 | + while (isset($parent)) { |
|
| 210 | + $query = \OCP\DB::prepare('SELECT `parent`, `uid_owner` FROM `*PREFIX*share` WHERE `id` = ?', 1); |
|
| 211 | + $item = $query->execute(array($parent))->fetchRow(); |
|
| 212 | + if (isset($item['parent'])) { |
|
| 213 | + $parent = $item['parent']; |
|
| 214 | + } else { |
|
| 215 | + $fileOwner = $item['uid_owner']; |
|
| 216 | + break; |
|
| 217 | + } |
|
| 218 | + } |
|
| 219 | + } else { |
|
| 220 | + $fileOwner = $source['uid_owner']; |
|
| 221 | + } |
|
| 222 | + if (isset($fileOwner)) { |
|
| 223 | + $source['fileOwner'] = $fileOwner; |
|
| 224 | + } else { |
|
| 225 | + \OCP\Util::writeLog('files_sharing', "No owner found for reshare", \OCP\Util::ERROR); |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + return $source; |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + /** |
|
| 232 | + * @param string $target |
|
| 233 | + * @param array $share |
|
| 234 | + * @return array|false source item |
|
| 235 | + */ |
|
| 236 | + public static function getSource($target, $share) { |
|
| 237 | + if ($share['item_type'] === 'folder' && $target !== '') { |
|
| 238 | + // note: in case of ext storage mount points the path might be empty |
|
| 239 | + // which would cause a leading slash to appear |
|
| 240 | + $share['path'] = ltrim($share['path'] . '/' . $target, '/'); |
|
| 241 | + } |
|
| 242 | + return self::resolveReshares($share); |
|
| 243 | + } |
|
| 244 | 244 | } |
@@ -335,7 +335,7 @@ |
||
| 335 | 335 | } |
| 336 | 336 | if($quota === 0) { |
| 337 | 337 | $quota = 'default'; |
| 338 | - }else if($quota === -1) { |
|
| 338 | + } else if($quota === -1) { |
|
| 339 | 339 | $quota = 'none'; |
| 340 | 340 | } else { |
| 341 | 341 | $quota = \OCP\Util::humanFileSize($quota); |
@@ -54,917 +54,917 @@ |
||
| 54 | 54 | |
| 55 | 55 | class UsersController extends OCSController { |
| 56 | 56 | |
| 57 | - /** @var IUserManager */ |
|
| 58 | - private $userManager; |
|
| 59 | - /** @var IConfig */ |
|
| 60 | - private $config; |
|
| 61 | - /** @var IAppManager */ |
|
| 62 | - private $appManager; |
|
| 63 | - /** @var IGroupManager|\OC\Group\Manager */ // FIXME Requires a method that is not on the interface |
|
| 64 | - private $groupManager; |
|
| 65 | - /** @var IUserSession */ |
|
| 66 | - private $userSession; |
|
| 67 | - /** @var AccountManager */ |
|
| 68 | - private $accountManager; |
|
| 69 | - /** @var ILogger */ |
|
| 70 | - private $logger; |
|
| 71 | - /** @var IFactory */ |
|
| 72 | - private $l10nFactory; |
|
| 73 | - /** @var NewUserMailHelper */ |
|
| 74 | - private $newUserMailHelper; |
|
| 75 | - /** @var FederatedFileSharingFactory */ |
|
| 76 | - private $federatedFileSharingFactory; |
|
| 77 | - /** @var ISecureRandom */ |
|
| 78 | - private $secureRandom; |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * @param string $appName |
|
| 82 | - * @param IRequest $request |
|
| 83 | - * @param IUserManager $userManager |
|
| 84 | - * @param IConfig $config |
|
| 85 | - * @param IAppManager $appManager |
|
| 86 | - * @param IGroupManager $groupManager |
|
| 87 | - * @param IUserSession $userSession |
|
| 88 | - * @param AccountManager $accountManager |
|
| 89 | - * @param ILogger $logger |
|
| 90 | - * @param IFactory $l10nFactory |
|
| 91 | - * @param NewUserMailHelper $newUserMailHelper |
|
| 92 | - * @param FederatedFileSharingFactory $federatedFileSharingFactory |
|
| 93 | - * @param ISecureRandom $secureRandom |
|
| 94 | - */ |
|
| 95 | - public function __construct(string $appName, |
|
| 96 | - IRequest $request, |
|
| 97 | - IUserManager $userManager, |
|
| 98 | - IConfig $config, |
|
| 99 | - IAppManager $appManager, |
|
| 100 | - IGroupManager $groupManager, |
|
| 101 | - IUserSession $userSession, |
|
| 102 | - AccountManager $accountManager, |
|
| 103 | - ILogger $logger, |
|
| 104 | - IFactory $l10nFactory, |
|
| 105 | - NewUserMailHelper $newUserMailHelper, |
|
| 106 | - FederatedFileSharingFactory $federatedFileSharingFactory, |
|
| 107 | - ISecureRandom $secureRandom) { |
|
| 108 | - parent::__construct($appName, $request); |
|
| 109 | - |
|
| 110 | - $this->userManager = $userManager; |
|
| 111 | - $this->config = $config; |
|
| 112 | - $this->appManager = $appManager; |
|
| 113 | - $this->groupManager = $groupManager; |
|
| 114 | - $this->userSession = $userSession; |
|
| 115 | - $this->accountManager = $accountManager; |
|
| 116 | - $this->logger = $logger; |
|
| 117 | - $this->l10nFactory = $l10nFactory; |
|
| 118 | - $this->newUserMailHelper = $newUserMailHelper; |
|
| 119 | - $this->federatedFileSharingFactory = $federatedFileSharingFactory; |
|
| 120 | - $this->secureRandom = $secureRandom; |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * @NoAdminRequired |
|
| 125 | - * |
|
| 126 | - * returns a list of users |
|
| 127 | - * |
|
| 128 | - * @param string $search |
|
| 129 | - * @param int $limit |
|
| 130 | - * @param int $offset |
|
| 131 | - * @return DataResponse |
|
| 132 | - */ |
|
| 133 | - public function getUsers(string $search = '', $limit = null, $offset = 0): DataResponse { |
|
| 134 | - $user = $this->userSession->getUser(); |
|
| 135 | - $users = []; |
|
| 136 | - |
|
| 137 | - // Admin? Or SubAdmin? |
|
| 138 | - $uid = $user->getUID(); |
|
| 139 | - $subAdminManager = $this->groupManager->getSubAdmin(); |
|
| 140 | - if($this->groupManager->isAdmin($uid)){ |
|
| 141 | - $users = $this->userManager->search($search, $limit, $offset); |
|
| 142 | - } else if ($subAdminManager->isSubAdmin($user)) { |
|
| 143 | - $subAdminOfGroups = $subAdminManager->getSubAdminsGroups($user); |
|
| 144 | - foreach ($subAdminOfGroups as $key => $group) { |
|
| 145 | - $subAdminOfGroups[$key] = $group->getGID(); |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - $users = []; |
|
| 149 | - foreach ($subAdminOfGroups as $group) { |
|
| 150 | - $users = array_merge($users, $this->groupManager->displayNamesInGroup($group, $search, $limit, $offset)); |
|
| 151 | - } |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - $users = array_keys($users); |
|
| 155 | - |
|
| 156 | - return new DataResponse([ |
|
| 157 | - 'users' => $users |
|
| 158 | - ]); |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - /** |
|
| 162 | - * @NoAdminRequired |
|
| 163 | - * |
|
| 164 | - * returns a list of users and their data |
|
| 165 | - */ |
|
| 166 | - public function getUsersDetails(string $search = '', $limit = null, $offset = 0): DataResponse { |
|
| 167 | - $user = $this->userSession->getUser(); |
|
| 168 | - $users = []; |
|
| 169 | - |
|
| 170 | - // Admin? Or SubAdmin? |
|
| 171 | - $uid = $user->getUID(); |
|
| 172 | - $subAdminManager = $this->groupManager->getSubAdmin(); |
|
| 173 | - if($this->groupManager->isAdmin($uid)){ |
|
| 174 | - $users = $this->userManager->search($search, $limit, $offset); |
|
| 175 | - } else if ($subAdminManager->isSubAdmin($user)) { |
|
| 176 | - $subAdminOfGroups = $subAdminManager->getSubAdminsGroups($user); |
|
| 177 | - foreach ($subAdminOfGroups as $key => $group) { |
|
| 178 | - $subAdminOfGroups[$key] = $group->getGID(); |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - $users = []; |
|
| 182 | - foreach ($subAdminOfGroups as $group) { |
|
| 183 | - $users = array_merge($users, $this->groupManager->displayNamesInGroup($group, $search, $limit, $offset)); |
|
| 184 | - } |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - $users = array_keys($users); |
|
| 188 | - $usersDetails = []; |
|
| 189 | - foreach ($users as $key => $userId) { |
|
| 190 | - $userData = $this->getUserData($userId); |
|
| 191 | - // Do not insert empty entry |
|
| 192 | - if(!empty($userData)) { |
|
| 193 | - $usersDetails[$userId] = $userData; |
|
| 194 | - } |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - return new DataResponse([ |
|
| 198 | - 'users' => $usersDetails |
|
| 199 | - ]); |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - /** |
|
| 203 | - * @PasswordConfirmationRequired |
|
| 204 | - * @NoAdminRequired |
|
| 205 | - * |
|
| 206 | - * @param string $userid |
|
| 207 | - * @param string $password |
|
| 208 | - * @param string $email |
|
| 209 | - * @param array $groups |
|
| 210 | - * @return DataResponse |
|
| 211 | - * @throws OCSException |
|
| 212 | - */ |
|
| 213 | - public function addUser(string $userid, string $password = '', string $email='', array $groups = []): DataResponse { |
|
| 214 | - $user = $this->userSession->getUser(); |
|
| 215 | - $isAdmin = $this->groupManager->isAdmin($user->getUID()); |
|
| 216 | - $subAdminManager = $this->groupManager->getSubAdmin(); |
|
| 217 | - |
|
| 218 | - if($this->userManager->userExists($userid)) { |
|
| 219 | - $this->logger->error('Failed addUser attempt: User already exists.', ['app' => 'ocs_api']); |
|
| 220 | - throw new OCSException('User already exists', 102); |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - if($groups !== []) { |
|
| 224 | - foreach ($groups as $group) { |
|
| 225 | - if(!$this->groupManager->groupExists($group)) { |
|
| 226 | - throw new OCSException('group '.$group.' does not exist', 104); |
|
| 227 | - } |
|
| 228 | - if(!$isAdmin && !$subAdminManager->isSubAdminofGroup($user, $this->groupManager->get($group))) { |
|
| 229 | - throw new OCSException('insufficient privileges for group '. $group, 105); |
|
| 230 | - } |
|
| 231 | - } |
|
| 232 | - } else { |
|
| 233 | - if(!$isAdmin) { |
|
| 234 | - throw new OCSException('no group specified (required for subadmins)', 106); |
|
| 235 | - } |
|
| 236 | - } |
|
| 237 | - |
|
| 238 | - $generatePasswordResetToken = false; |
|
| 239 | - if ($password === '') { |
|
| 240 | - if ($email === '') { |
|
| 241 | - throw new OCSException('To send a password link to the user an email address is required.', 108); |
|
| 242 | - } |
|
| 243 | - |
|
| 244 | - $password = $this->secureRandom->generate(10); |
|
| 245 | - // Make sure we pass the password_policy |
|
| 246 | - $password .= $this->secureRandom->generate(2, '$!.,;:-~+*[]{}()'); |
|
| 247 | - $generatePasswordResetToken = true; |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - try { |
|
| 251 | - $newUser = $this->userManager->createUser($userid, $password); |
|
| 252 | - $this->logger->info('Successful addUser call with userid: ' . $userid, ['app' => 'ocs_api']); |
|
| 253 | - |
|
| 254 | - foreach ($groups as $group) { |
|
| 255 | - $this->groupManager->get($group)->addUser($newUser); |
|
| 256 | - $this->logger->info('Added userid ' . $userid . ' to group ' . $group, ['app' => 'ocs_api']); |
|
| 257 | - } |
|
| 258 | - |
|
| 259 | - // Send new user mail only if a mail is set |
|
| 260 | - if ($email !== '') { |
|
| 261 | - $newUser->setEMailAddress($email); |
|
| 262 | - try { |
|
| 263 | - $emailTemplate = $this->newUserMailHelper->generateTemplate($newUser, $generatePasswordResetToken); |
|
| 264 | - $this->newUserMailHelper->sendMail($newUser, $emailTemplate); |
|
| 265 | - } catch (\Exception $e) { |
|
| 266 | - $this->logger->logException($e, [ |
|
| 267 | - 'message' => "Can't send new user mail to $email", |
|
| 268 | - 'level' => \OCP\Util::ERROR, |
|
| 269 | - 'app' => 'ocs_api', |
|
| 270 | - ]); |
|
| 271 | - throw new OCSException('Unable to send the invitation mail', 109); |
|
| 272 | - } |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - return new DataResponse(); |
|
| 276 | - |
|
| 277 | - } catch (HintException $e ) { |
|
| 278 | - $this->logger->logException($e, [ |
|
| 279 | - 'message' => 'Failed addUser attempt with hint exception.', |
|
| 280 | - 'level' => \OCP\Util::WARN, |
|
| 281 | - 'app' => 'ocs_api', |
|
| 282 | - ]); |
|
| 283 | - throw new OCSException($e->getHint(), 107); |
|
| 284 | - } catch (\Exception $e) { |
|
| 285 | - $this->logger->logException($e, [ |
|
| 286 | - 'message' => 'Failed addUser attempt with exception.', |
|
| 287 | - 'level' => \OCP\Util::ERROR, |
|
| 288 | - 'app' => 'ocs_api', |
|
| 289 | - ]); |
|
| 290 | - throw new OCSException('Bad request', 101); |
|
| 291 | - } |
|
| 292 | - } |
|
| 293 | - |
|
| 294 | - /** |
|
| 295 | - * @NoAdminRequired |
|
| 296 | - * @NoSubAdminRequired |
|
| 297 | - * |
|
| 298 | - * gets user info |
|
| 299 | - * |
|
| 300 | - * @param string $userId |
|
| 301 | - * @return DataResponse |
|
| 302 | - * @throws OCSException |
|
| 303 | - */ |
|
| 304 | - public function getUser(string $userId): DataResponse { |
|
| 305 | - $data = $this->getUserData($userId); |
|
| 306 | - // getUserData returns empty array if not enough permissions |
|
| 307 | - if(empty($data)) { |
|
| 308 | - throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
| 309 | - } |
|
| 310 | - return new DataResponse($data); |
|
| 311 | - } |
|
| 312 | - |
|
| 313 | - /** |
|
| 314 | - * @NoAdminRequired |
|
| 315 | - * @NoSubAdminRequired |
|
| 316 | - * |
|
| 317 | - * gets user info from the currently logged in user |
|
| 318 | - * |
|
| 319 | - * @return DataResponse |
|
| 320 | - * @throws OCSException |
|
| 321 | - */ |
|
| 322 | - public function getCurrentUser(): DataResponse { |
|
| 323 | - $user = $this->userSession->getUser(); |
|
| 324 | - if ($user) { |
|
| 325 | - $data = $this->getUserData($user->getUID()); |
|
| 326 | - // rename "displayname" to "display-name" only for this call to keep |
|
| 327 | - // the API stable. |
|
| 328 | - $data['display-name'] = $data['displayname']; |
|
| 329 | - unset($data['displayname']); |
|
| 330 | - return new DataResponse($data); |
|
| 331 | - |
|
| 332 | - } |
|
| 333 | - |
|
| 334 | - throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
| 335 | - } |
|
| 336 | - |
|
| 337 | - /** |
|
| 338 | - * creates a array with all user data |
|
| 339 | - * |
|
| 340 | - * @param $userId |
|
| 341 | - * @return array |
|
| 342 | - * @throws OCSException |
|
| 343 | - */ |
|
| 344 | - protected function getUserData(string $userId): array { |
|
| 345 | - $currentLoggedInUser = $this->userSession->getUser(); |
|
| 346 | - |
|
| 347 | - $data = []; |
|
| 348 | - |
|
| 349 | - // Check if the target user exists |
|
| 350 | - $targetUserObject = $this->userManager->get($userId); |
|
| 351 | - if($targetUserObject === null) { |
|
| 352 | - throw new OCSException('The requested user could not be found', \OCP\API::RESPOND_NOT_FOUND); |
|
| 353 | - } |
|
| 354 | - |
|
| 355 | - // Should be at least Admin Or SubAdmin! |
|
| 356 | - if( $this->groupManager->isAdmin($currentLoggedInUser->getUID()) |
|
| 357 | - || $this->groupManager->getSubAdmin()->isUserAccessible($currentLoggedInUser, $targetUserObject)) { |
|
| 358 | - $data['enabled'] = $this->config->getUserValue($targetUserObject->getUID(), 'core', 'enabled', 'true'); |
|
| 359 | - } else { |
|
| 360 | - // Check they are looking up themselves |
|
| 361 | - if($currentLoggedInUser->getUID() !== $targetUserObject->getUID()) { |
|
| 362 | - return $data; |
|
| 363 | - } |
|
| 364 | - } |
|
| 365 | - |
|
| 366 | - // Get groups data |
|
| 367 | - $userAccount = $this->accountManager->getUser($targetUserObject); |
|
| 368 | - $groups = $this->groupManager->getUserGroups($targetUserObject); |
|
| 369 | - $gids = []; |
|
| 370 | - foreach ($groups as $group) { |
|
| 371 | - $gids[] = $group->getDisplayName(); |
|
| 372 | - } |
|
| 373 | - |
|
| 374 | - // Find the data |
|
| 375 | - $data['id'] = $targetUserObject->getUID(); |
|
| 376 | - $data['storageLocation'] = $targetUserObject->getHome(); |
|
| 377 | - $data['lastLogin'] = $targetUserObject->getLastLogin() * 1000; |
|
| 378 | - $data['backend'] = $targetUserObject->getBackendClassName(); |
|
| 379 | - $data['subadmin'] = $this->getUserSubAdminGroupsData($targetUserObject->getUID()); |
|
| 380 | - $data['quota'] = $this->fillStorageInfo($targetUserObject->getUID()); |
|
| 381 | - $data[AccountManager::PROPERTY_EMAIL] = $targetUserObject->getEMailAddress(); |
|
| 382 | - $data[AccountManager::PROPERTY_DISPLAYNAME] = $targetUserObject->getDisplayName(); |
|
| 383 | - $data[AccountManager::PROPERTY_PHONE] = $userAccount[AccountManager::PROPERTY_PHONE]['value']; |
|
| 384 | - $data[AccountManager::PROPERTY_ADDRESS] = $userAccount[AccountManager::PROPERTY_ADDRESS]['value']; |
|
| 385 | - $data[AccountManager::PROPERTY_WEBSITE] = $userAccount[AccountManager::PROPERTY_WEBSITE]['value']; |
|
| 386 | - $data[AccountManager::PROPERTY_TWITTER] = $userAccount[AccountManager::PROPERTY_TWITTER]['value']; |
|
| 387 | - $data['groups'] = $gids; |
|
| 388 | - $data['language'] = $this->config->getUserValue($targetUserObject->getUID(), 'core', 'lang'); |
|
| 389 | - |
|
| 390 | - return $data; |
|
| 391 | - } |
|
| 392 | - |
|
| 393 | - /** |
|
| 394 | - * @NoAdminRequired |
|
| 395 | - * @NoSubAdminRequired |
|
| 396 | - */ |
|
| 397 | - public function getEditableFields(): DataResponse { |
|
| 398 | - $permittedFields = []; |
|
| 399 | - |
|
| 400 | - // Editing self (display, email) |
|
| 401 | - if ($this->config->getSystemValue('allow_user_to_change_display_name', true) !== false) { |
|
| 402 | - $permittedFields[] = AccountManager::PROPERTY_DISPLAYNAME; |
|
| 403 | - $permittedFields[] = AccountManager::PROPERTY_EMAIL; |
|
| 404 | - } |
|
| 405 | - |
|
| 406 | - if ($this->appManager->isEnabledForUser('federatedfilesharing')) { |
|
| 407 | - $federatedFileSharing = $this->federatedFileSharingFactory->get(); |
|
| 408 | - $shareProvider = $federatedFileSharing->getFederatedShareProvider(); |
|
| 409 | - if ($shareProvider->isLookupServerUploadEnabled()) { |
|
| 410 | - $permittedFields[] = AccountManager::PROPERTY_PHONE; |
|
| 411 | - $permittedFields[] = AccountManager::PROPERTY_ADDRESS; |
|
| 412 | - $permittedFields[] = AccountManager::PROPERTY_WEBSITE; |
|
| 413 | - $permittedFields[] = AccountManager::PROPERTY_TWITTER; |
|
| 414 | - } |
|
| 415 | - } |
|
| 416 | - |
|
| 417 | - return new DataResponse($permittedFields); |
|
| 418 | - } |
|
| 419 | - |
|
| 420 | - /** |
|
| 421 | - * @NoAdminRequired |
|
| 422 | - * @NoSubAdminRequired |
|
| 423 | - * @PasswordConfirmationRequired |
|
| 424 | - * |
|
| 425 | - * edit users |
|
| 426 | - * |
|
| 427 | - * @param string $userId |
|
| 428 | - * @param string $key |
|
| 429 | - * @param string $value |
|
| 430 | - * @return DataResponse |
|
| 431 | - * @throws OCSException |
|
| 432 | - */ |
|
| 433 | - public function editUser(string $userId, string $key, string $value): DataResponse { |
|
| 434 | - $currentLoggedInUser = $this->userSession->getUser(); |
|
| 435 | - |
|
| 436 | - $targetUser = $this->userManager->get($userId); |
|
| 437 | - if($targetUser === null) { |
|
| 438 | - throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
| 439 | - } |
|
| 440 | - |
|
| 441 | - $permittedFields = []; |
|
| 442 | - if($targetUser->getUID() === $currentLoggedInUser->getUID()) { |
|
| 443 | - // Editing self (display, email) |
|
| 444 | - if ($this->config->getSystemValue('allow_user_to_change_display_name', true) !== false) { |
|
| 445 | - $permittedFields[] = 'display'; |
|
| 446 | - $permittedFields[] = AccountManager::PROPERTY_DISPLAYNAME; |
|
| 447 | - $permittedFields[] = AccountManager::PROPERTY_EMAIL; |
|
| 448 | - } |
|
| 449 | - |
|
| 450 | - $permittedFields[] = 'password'; |
|
| 451 | - if ($this->config->getSystemValue('force_language', false) === false || |
|
| 452 | - $this->groupManager->isAdmin($currentLoggedInUser->getUID())) { |
|
| 453 | - $permittedFields[] = 'language'; |
|
| 454 | - } |
|
| 455 | - |
|
| 456 | - if ($this->appManager->isEnabledForUser('federatedfilesharing')) { |
|
| 457 | - $federatedFileSharing = new \OCA\FederatedFileSharing\AppInfo\Application(); |
|
| 458 | - $shareProvider = $federatedFileSharing->getFederatedShareProvider(); |
|
| 459 | - if ($shareProvider->isLookupServerUploadEnabled()) { |
|
| 460 | - $permittedFields[] = AccountManager::PROPERTY_PHONE; |
|
| 461 | - $permittedFields[] = AccountManager::PROPERTY_ADDRESS; |
|
| 462 | - $permittedFields[] = AccountManager::PROPERTY_WEBSITE; |
|
| 463 | - $permittedFields[] = AccountManager::PROPERTY_TWITTER; |
|
| 464 | - } |
|
| 465 | - } |
|
| 466 | - |
|
| 467 | - // If admin they can edit their own quota |
|
| 468 | - if($this->groupManager->isAdmin($currentLoggedInUser->getUID())) { |
|
| 469 | - $permittedFields[] = 'quota'; |
|
| 470 | - } |
|
| 471 | - } else { |
|
| 472 | - // Check if admin / subadmin |
|
| 473 | - $subAdminManager = $this->groupManager->getSubAdmin(); |
|
| 474 | - if($subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser) |
|
| 475 | - || $this->groupManager->isAdmin($currentLoggedInUser->getUID())) { |
|
| 476 | - // They have permissions over the user |
|
| 477 | - $permittedFields[] = 'display'; |
|
| 478 | - $permittedFields[] = AccountManager::PROPERTY_DISPLAYNAME; |
|
| 479 | - $permittedFields[] = AccountManager::PROPERTY_EMAIL; |
|
| 480 | - $permittedFields[] = 'password'; |
|
| 481 | - $permittedFields[] = 'language'; |
|
| 482 | - $permittedFields[] = AccountManager::PROPERTY_PHONE; |
|
| 483 | - $permittedFields[] = AccountManager::PROPERTY_ADDRESS; |
|
| 484 | - $permittedFields[] = AccountManager::PROPERTY_WEBSITE; |
|
| 485 | - $permittedFields[] = AccountManager::PROPERTY_TWITTER; |
|
| 486 | - $permittedFields[] = 'quota'; |
|
| 487 | - } else { |
|
| 488 | - // No rights |
|
| 489 | - throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
| 490 | - } |
|
| 491 | - } |
|
| 492 | - // Check if permitted to edit this field |
|
| 493 | - if(!in_array($key, $permittedFields)) { |
|
| 494 | - throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
| 495 | - } |
|
| 496 | - // Process the edit |
|
| 497 | - switch($key) { |
|
| 498 | - case 'display': |
|
| 499 | - case AccountManager::PROPERTY_DISPLAYNAME: |
|
| 500 | - $targetUser->setDisplayName($value); |
|
| 501 | - break; |
|
| 502 | - case 'quota': |
|
| 503 | - $quota = $value; |
|
| 504 | - if($quota !== 'none' && $quota !== 'default') { |
|
| 505 | - if (is_numeric($quota)) { |
|
| 506 | - $quota = (float) $quota; |
|
| 507 | - } else { |
|
| 508 | - $quota = \OCP\Util::computerFileSize($quota); |
|
| 509 | - } |
|
| 510 | - if ($quota === false) { |
|
| 511 | - throw new OCSException('Invalid quota value '.$value, 103); |
|
| 512 | - } |
|
| 513 | - if($quota === 0) { |
|
| 514 | - $quota = 'default'; |
|
| 515 | - }else if($quota === -1) { |
|
| 516 | - $quota = 'none'; |
|
| 517 | - } else { |
|
| 518 | - $quota = \OCP\Util::humanFileSize($quota); |
|
| 519 | - } |
|
| 520 | - } |
|
| 521 | - $targetUser->setQuota($quota); |
|
| 522 | - break; |
|
| 523 | - case 'password': |
|
| 524 | - $targetUser->setPassword($value); |
|
| 525 | - break; |
|
| 526 | - case 'language': |
|
| 527 | - $languagesCodes = $this->l10nFactory->findAvailableLanguages(); |
|
| 528 | - if (!in_array($value, $languagesCodes, true) && $value !== 'en') { |
|
| 529 | - throw new OCSException('Invalid language', 102); |
|
| 530 | - } |
|
| 531 | - $this->config->setUserValue($targetUser->getUID(), 'core', 'lang', $value); |
|
| 532 | - break; |
|
| 533 | - case AccountManager::PROPERTY_EMAIL: |
|
| 534 | - if(filter_var($value, FILTER_VALIDATE_EMAIL) || $value === '') { |
|
| 535 | - $targetUser->setEMailAddress($value); |
|
| 536 | - } else { |
|
| 537 | - throw new OCSException('', 102); |
|
| 538 | - } |
|
| 539 | - break; |
|
| 540 | - case AccountManager::PROPERTY_PHONE: |
|
| 541 | - case AccountManager::PROPERTY_ADDRESS: |
|
| 542 | - case AccountManager::PROPERTY_WEBSITE: |
|
| 543 | - case AccountManager::PROPERTY_TWITTER: |
|
| 544 | - $userAccount = $this->accountManager->getUser($targetUser); |
|
| 545 | - if ($userAccount[$key]['value'] !== $value) { |
|
| 546 | - $userAccount[$key]['value'] = $value; |
|
| 547 | - $this->accountManager->updateUser($targetUser, $userAccount); |
|
| 548 | - } |
|
| 549 | - break; |
|
| 550 | - default: |
|
| 551 | - throw new OCSException('', 103); |
|
| 552 | - } |
|
| 553 | - return new DataResponse(); |
|
| 554 | - } |
|
| 555 | - |
|
| 556 | - /** |
|
| 557 | - * @PasswordConfirmationRequired |
|
| 558 | - * @NoAdminRequired |
|
| 559 | - * |
|
| 560 | - * @param string $userId |
|
| 561 | - * @return DataResponse |
|
| 562 | - * @throws OCSException |
|
| 563 | - */ |
|
| 564 | - public function deleteUser(string $userId): DataResponse { |
|
| 565 | - $currentLoggedInUser = $this->userSession->getUser(); |
|
| 566 | - |
|
| 567 | - $targetUser = $this->userManager->get($userId); |
|
| 568 | - |
|
| 569 | - if($targetUser === null || $targetUser->getUID() === $currentLoggedInUser->getUID()) { |
|
| 570 | - throw new OCSException('', 101); |
|
| 571 | - } |
|
| 572 | - |
|
| 573 | - // If not permitted |
|
| 574 | - $subAdminManager = $this->groupManager->getSubAdmin(); |
|
| 575 | - if(!$this->groupManager->isAdmin($currentLoggedInUser->getUID()) && !$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)) { |
|
| 576 | - throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
| 577 | - } |
|
| 578 | - |
|
| 579 | - // Go ahead with the delete |
|
| 580 | - if($targetUser->delete()) { |
|
| 581 | - return new DataResponse(); |
|
| 582 | - } else { |
|
| 583 | - throw new OCSException('', 101); |
|
| 584 | - } |
|
| 585 | - } |
|
| 586 | - |
|
| 587 | - /** |
|
| 588 | - * @PasswordConfirmationRequired |
|
| 589 | - * @NoAdminRequired |
|
| 590 | - * |
|
| 591 | - * @param string $userId |
|
| 592 | - * @return DataResponse |
|
| 593 | - * @throws OCSException |
|
| 594 | - * @throws OCSForbiddenException |
|
| 595 | - */ |
|
| 596 | - public function disableUser(string $userId): DataResponse { |
|
| 597 | - return $this->setEnabled($userId, false); |
|
| 598 | - } |
|
| 599 | - |
|
| 600 | - /** |
|
| 601 | - * @PasswordConfirmationRequired |
|
| 602 | - * @NoAdminRequired |
|
| 603 | - * |
|
| 604 | - * @param string $userId |
|
| 605 | - * @return DataResponse |
|
| 606 | - * @throws OCSException |
|
| 607 | - * @throws OCSForbiddenException |
|
| 608 | - */ |
|
| 609 | - public function enableUser(string $userId): DataResponse { |
|
| 610 | - return $this->setEnabled($userId, true); |
|
| 611 | - } |
|
| 612 | - |
|
| 613 | - /** |
|
| 614 | - * @param string $userId |
|
| 615 | - * @param bool $value |
|
| 616 | - * @return DataResponse |
|
| 617 | - * @throws OCSException |
|
| 618 | - */ |
|
| 619 | - private function setEnabled(string $userId, bool $value): DataResponse { |
|
| 620 | - $currentLoggedInUser = $this->userSession->getUser(); |
|
| 621 | - |
|
| 622 | - $targetUser = $this->userManager->get($userId); |
|
| 623 | - if($targetUser === null || $targetUser->getUID() === $currentLoggedInUser->getUID()) { |
|
| 624 | - throw new OCSException('', 101); |
|
| 625 | - } |
|
| 626 | - |
|
| 627 | - // If not permitted |
|
| 628 | - $subAdminManager = $this->groupManager->getSubAdmin(); |
|
| 629 | - if(!$this->groupManager->isAdmin($currentLoggedInUser->getUID()) && !$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)) { |
|
| 630 | - throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
| 631 | - } |
|
| 632 | - |
|
| 633 | - // enable/disable the user now |
|
| 634 | - $targetUser->setEnabled($value); |
|
| 635 | - return new DataResponse(); |
|
| 636 | - } |
|
| 637 | - |
|
| 638 | - /** |
|
| 639 | - * @NoAdminRequired |
|
| 640 | - * @NoSubAdminRequired |
|
| 641 | - * |
|
| 642 | - * @param string $userId |
|
| 643 | - * @return DataResponse |
|
| 644 | - * @throws OCSException |
|
| 645 | - */ |
|
| 646 | - public function getUsersGroups(string $userId): DataResponse { |
|
| 647 | - $loggedInUser = $this->userSession->getUser(); |
|
| 648 | - |
|
| 649 | - $targetUser = $this->userManager->get($userId); |
|
| 650 | - if($targetUser === null) { |
|
| 651 | - throw new OCSException('', \OCP\API::RESPOND_NOT_FOUND); |
|
| 652 | - } |
|
| 653 | - |
|
| 654 | - if($targetUser->getUID() === $loggedInUser->getUID() || $this->groupManager->isAdmin($loggedInUser->getUID())) { |
|
| 655 | - // Self lookup or admin lookup |
|
| 656 | - return new DataResponse([ |
|
| 657 | - 'groups' => $this->groupManager->getUserGroupIds($targetUser) |
|
| 658 | - ]); |
|
| 659 | - } else { |
|
| 660 | - $subAdminManager = $this->groupManager->getSubAdmin(); |
|
| 661 | - |
|
| 662 | - // Looking up someone else |
|
| 663 | - if($subAdminManager->isUserAccessible($loggedInUser, $targetUser)) { |
|
| 664 | - // Return the group that the method caller is subadmin of for the user in question |
|
| 665 | - /** @var IGroup[] $getSubAdminsGroups */ |
|
| 666 | - $getSubAdminsGroups = $subAdminManager->getSubAdminsGroups($loggedInUser); |
|
| 667 | - foreach ($getSubAdminsGroups as $key => $group) { |
|
| 668 | - $getSubAdminsGroups[$key] = $group->getGID(); |
|
| 669 | - } |
|
| 670 | - $groups = array_intersect( |
|
| 671 | - $getSubAdminsGroups, |
|
| 672 | - $this->groupManager->getUserGroupIds($targetUser) |
|
| 673 | - ); |
|
| 674 | - return new DataResponse(['groups' => $groups]); |
|
| 675 | - } else { |
|
| 676 | - // Not permitted |
|
| 677 | - throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
| 678 | - } |
|
| 679 | - } |
|
| 680 | - |
|
| 681 | - } |
|
| 682 | - |
|
| 683 | - /** |
|
| 684 | - * @PasswordConfirmationRequired |
|
| 685 | - * @NoAdminRequired |
|
| 686 | - * |
|
| 687 | - * @param string $userId |
|
| 688 | - * @param string $groupid |
|
| 689 | - * @return DataResponse |
|
| 690 | - * @throws OCSException |
|
| 691 | - */ |
|
| 692 | - public function addToGroup(string $userId, string $groupid = ''): DataResponse { |
|
| 693 | - if($groupid === '') { |
|
| 694 | - throw new OCSException('', 101); |
|
| 695 | - } |
|
| 696 | - |
|
| 697 | - $group = $this->groupManager->get($groupid); |
|
| 698 | - $targetUser = $this->userManager->get($userId); |
|
| 699 | - if($group === null) { |
|
| 700 | - throw new OCSException('', 102); |
|
| 701 | - } |
|
| 702 | - if($targetUser === null) { |
|
| 703 | - throw new OCSException('', 103); |
|
| 704 | - } |
|
| 705 | - |
|
| 706 | - // If they're not an admin, check they are a subadmin of the group in question |
|
| 707 | - $loggedInUser = $this->userSession->getUser(); |
|
| 708 | - $subAdminManager = $this->groupManager->getSubAdmin(); |
|
| 709 | - if (!$this->groupManager->isAdmin($loggedInUser->getUID()) && !$subAdminManager->isSubAdminOfGroup($loggedInUser, $group)) { |
|
| 710 | - throw new OCSException('', 104); |
|
| 711 | - } |
|
| 712 | - |
|
| 713 | - // Add user to group |
|
| 714 | - $group->addUser($targetUser); |
|
| 715 | - return new DataResponse(); |
|
| 716 | - } |
|
| 717 | - |
|
| 718 | - /** |
|
| 719 | - * @PasswordConfirmationRequired |
|
| 720 | - * @NoAdminRequired |
|
| 721 | - * |
|
| 722 | - * @param string $userId |
|
| 723 | - * @param string $groupid |
|
| 724 | - * @return DataResponse |
|
| 725 | - * @throws OCSException |
|
| 726 | - */ |
|
| 727 | - public function removeFromGroup(string $userId, string $groupid): DataResponse { |
|
| 728 | - $loggedInUser = $this->userSession->getUser(); |
|
| 729 | - |
|
| 730 | - if($groupid === null || trim($groupid) === '') { |
|
| 731 | - throw new OCSException('', 101); |
|
| 732 | - } |
|
| 733 | - |
|
| 734 | - $group = $this->groupManager->get($groupid); |
|
| 735 | - if($group === null) { |
|
| 736 | - throw new OCSException('', 102); |
|
| 737 | - } |
|
| 738 | - |
|
| 739 | - $targetUser = $this->userManager->get($userId); |
|
| 740 | - if($targetUser === null) { |
|
| 741 | - throw new OCSException('', 103); |
|
| 742 | - } |
|
| 743 | - |
|
| 744 | - // If they're not an admin, check they are a subadmin of the group in question |
|
| 745 | - $subAdminManager = $this->groupManager->getSubAdmin(); |
|
| 746 | - if (!$this->groupManager->isAdmin($loggedInUser->getUID()) && !$subAdminManager->isSubAdminOfGroup($loggedInUser, $group)) { |
|
| 747 | - throw new OCSException('', 104); |
|
| 748 | - } |
|
| 749 | - |
|
| 750 | - // Check they aren't removing themselves from 'admin' or their 'subadmin; group |
|
| 751 | - if ($targetUser->getUID() === $loggedInUser->getUID()) { |
|
| 752 | - if ($this->groupManager->isAdmin($loggedInUser->getUID())) { |
|
| 753 | - if ($group->getGID() === 'admin') { |
|
| 754 | - throw new OCSException('Cannot remove yourself from the admin group', 105); |
|
| 755 | - } |
|
| 756 | - } else { |
|
| 757 | - // Not an admin, so the user must be a subadmin of this group, but that is not allowed. |
|
| 758 | - throw new OCSException('Cannot remove yourself from this group as you are a SubAdmin', 105); |
|
| 759 | - } |
|
| 760 | - |
|
| 761 | - } else if (!$this->groupManager->isAdmin($loggedInUser->getUID())) { |
|
| 762 | - /** @var IGroup[] $subAdminGroups */ |
|
| 763 | - $subAdminGroups = $subAdminManager->getSubAdminsGroups($loggedInUser); |
|
| 764 | - $subAdminGroups = array_map(function (IGroup $subAdminGroup) { |
|
| 765 | - return $subAdminGroup->getGID(); |
|
| 766 | - }, $subAdminGroups); |
|
| 767 | - $userGroups = $this->groupManager->getUserGroupIds($targetUser); |
|
| 768 | - $userSubAdminGroups = array_intersect($subAdminGroups, $userGroups); |
|
| 769 | - |
|
| 770 | - if (count($userSubAdminGroups) <= 1) { |
|
| 771 | - // Subadmin must not be able to remove a user from all their subadmin groups. |
|
| 772 | - throw new OCSException('Cannot remove user from this group as this is the only remaining group you are a SubAdmin of', 105); |
|
| 773 | - } |
|
| 774 | - } |
|
| 775 | - |
|
| 776 | - // Remove user from group |
|
| 777 | - $group->removeUser($targetUser); |
|
| 778 | - return new DataResponse(); |
|
| 779 | - } |
|
| 780 | - |
|
| 781 | - /** |
|
| 782 | - * Creates a subadmin |
|
| 783 | - * |
|
| 784 | - * @PasswordConfirmationRequired |
|
| 785 | - * |
|
| 786 | - * @param string $userId |
|
| 787 | - * @param string $groupid |
|
| 788 | - * @return DataResponse |
|
| 789 | - * @throws OCSException |
|
| 790 | - */ |
|
| 791 | - public function addSubAdmin(string $userId, string $groupid): DataResponse { |
|
| 792 | - $group = $this->groupManager->get($groupid); |
|
| 793 | - $user = $this->userManager->get($userId); |
|
| 794 | - |
|
| 795 | - // Check if the user exists |
|
| 796 | - if($user === null) { |
|
| 797 | - throw new OCSException('User does not exist', 101); |
|
| 798 | - } |
|
| 799 | - // Check if group exists |
|
| 800 | - if($group === null) { |
|
| 801 | - throw new OCSException('Group does not exist', 102); |
|
| 802 | - } |
|
| 803 | - // Check if trying to make subadmin of admin group |
|
| 804 | - if($group->getGID() === 'admin') { |
|
| 805 | - throw new OCSException('Cannot create subadmins for admin group', 103); |
|
| 806 | - } |
|
| 807 | - |
|
| 808 | - $subAdminManager = $this->groupManager->getSubAdmin(); |
|
| 809 | - |
|
| 810 | - // We cannot be subadmin twice |
|
| 811 | - if ($subAdminManager->isSubAdminofGroup($user, $group)) { |
|
| 812 | - return new DataResponse(); |
|
| 813 | - } |
|
| 814 | - // Go |
|
| 815 | - if($subAdminManager->createSubAdmin($user, $group)) { |
|
| 816 | - return new DataResponse(); |
|
| 817 | - } else { |
|
| 818 | - throw new OCSException('Unknown error occurred', 103); |
|
| 819 | - } |
|
| 820 | - } |
|
| 821 | - |
|
| 822 | - /** |
|
| 823 | - * Removes a subadmin from a group |
|
| 824 | - * |
|
| 825 | - * @PasswordConfirmationRequired |
|
| 826 | - * |
|
| 827 | - * @param string $userId |
|
| 828 | - * @param string $groupid |
|
| 829 | - * @return DataResponse |
|
| 830 | - * @throws OCSException |
|
| 831 | - */ |
|
| 832 | - public function removeSubAdmin(string $userId, string $groupid): DataResponse { |
|
| 833 | - $group = $this->groupManager->get($groupid); |
|
| 834 | - $user = $this->userManager->get($userId); |
|
| 835 | - $subAdminManager = $this->groupManager->getSubAdmin(); |
|
| 836 | - |
|
| 837 | - // Check if the user exists |
|
| 838 | - if($user === null) { |
|
| 839 | - throw new OCSException('User does not exist', 101); |
|
| 840 | - } |
|
| 841 | - // Check if the group exists |
|
| 842 | - if($group === null) { |
|
| 843 | - throw new OCSException('Group does not exist', 101); |
|
| 844 | - } |
|
| 845 | - // Check if they are a subadmin of this said group |
|
| 846 | - if(!$subAdminManager->isSubAdminOfGroup($user, $group)) { |
|
| 847 | - throw new OCSException('User is not a subadmin of this group', 102); |
|
| 848 | - } |
|
| 849 | - |
|
| 850 | - // Go |
|
| 851 | - if($subAdminManager->deleteSubAdmin($user, $group)) { |
|
| 852 | - return new DataResponse(); |
|
| 853 | - } else { |
|
| 854 | - throw new OCSException('Unknown error occurred', 103); |
|
| 855 | - } |
|
| 856 | - } |
|
| 857 | - |
|
| 858 | - /** |
|
| 859 | - * Get the groups a user is a subadmin of |
|
| 860 | - * |
|
| 861 | - * @param string $userId |
|
| 862 | - * @return array |
|
| 863 | - * @throws OCSException |
|
| 864 | - */ |
|
| 865 | - protected function getUserSubAdminGroupsData(string $userId): array { |
|
| 866 | - $user = $this->userManager->get($userId); |
|
| 867 | - // Check if the user exists |
|
| 868 | - if($user === null) { |
|
| 869 | - throw new OCSException('User does not exist', 101); |
|
| 870 | - } |
|
| 871 | - |
|
| 872 | - // Get the subadmin groups |
|
| 873 | - $subAdminGroups = $this->groupManager->getSubAdmin()->getSubAdminsGroups($user); |
|
| 874 | - $groups = []; |
|
| 875 | - foreach ($subAdminGroups as $key => $group) { |
|
| 876 | - $groups[] = $group->getGID(); |
|
| 877 | - } |
|
| 878 | - |
|
| 879 | - return $groups; |
|
| 880 | - } |
|
| 881 | - |
|
| 882 | - /** |
|
| 883 | - * Get the groups a user is a subadmin of |
|
| 884 | - * |
|
| 885 | - * @param string $userId |
|
| 886 | - * @return DataResponse |
|
| 887 | - * @throws OCSException |
|
| 888 | - */ |
|
| 889 | - public function getUserSubAdminGroups(string $userId): DataResponse { |
|
| 890 | - $groups = $this->getUserSubAdminGroupsData($userId); |
|
| 891 | - return new DataResponse($groups); |
|
| 892 | - } |
|
| 893 | - |
|
| 894 | - /** |
|
| 895 | - * @param string $userId |
|
| 896 | - * @return array |
|
| 897 | - * @throws \OCP\Files\NotFoundException |
|
| 898 | - */ |
|
| 899 | - protected function fillStorageInfo(string $userId): array { |
|
| 900 | - try { |
|
| 901 | - \OC_Util::tearDownFS(); |
|
| 902 | - \OC_Util::setupFS($userId); |
|
| 903 | - $storage = OC_Helper::getStorageInfo('/'); |
|
| 904 | - $data = [ |
|
| 905 | - 'free' => $storage['free'], |
|
| 906 | - 'used' => $storage['used'], |
|
| 907 | - 'total' => $storage['total'], |
|
| 908 | - 'relative' => $storage['relative'], |
|
| 909 | - 'quota' => $storage['quota'], |
|
| 910 | - ]; |
|
| 911 | - } catch (NotFoundException $ex) { |
|
| 912 | - $data = []; |
|
| 913 | - } |
|
| 914 | - return $data; |
|
| 915 | - } |
|
| 916 | - |
|
| 917 | - /** |
|
| 918 | - * @NoAdminRequired |
|
| 919 | - * @PasswordConfirmationRequired |
|
| 920 | - * |
|
| 921 | - * resend welcome message |
|
| 922 | - * |
|
| 923 | - * @param string $userId |
|
| 924 | - * @return DataResponse |
|
| 925 | - * @throws OCSException |
|
| 926 | - */ |
|
| 927 | - public function resendWelcomeMessage(string $userId): DataResponse { |
|
| 928 | - $currentLoggedInUser = $this->userSession->getUser(); |
|
| 929 | - |
|
| 930 | - $targetUser = $this->userManager->get($userId); |
|
| 931 | - if($targetUser === null) { |
|
| 932 | - throw new OCSException('', \OCP\API::RESPOND_NOT_FOUND); |
|
| 933 | - } |
|
| 934 | - |
|
| 935 | - // Check if admin / subadmin |
|
| 936 | - $subAdminManager = $this->groupManager->getSubAdmin(); |
|
| 937 | - if(!$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser) |
|
| 938 | - && !$this->groupManager->isAdmin($currentLoggedInUser->getUID())) { |
|
| 939 | - // No rights |
|
| 940 | - throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
| 941 | - } |
|
| 942 | - |
|
| 943 | - $email = $targetUser->getEMailAddress(); |
|
| 944 | - if ($email === '' || $email === null) { |
|
| 945 | - throw new OCSException('Email address not available', 101); |
|
| 946 | - } |
|
| 947 | - $username = $targetUser->getUID(); |
|
| 948 | - $lang = $this->config->getUserValue($username, 'core', 'lang', 'en'); |
|
| 949 | - if (!$this->l10nFactory->languageExists('settings', $lang)) { |
|
| 950 | - $lang = 'en'; |
|
| 951 | - } |
|
| 952 | - |
|
| 953 | - $l10n = $this->l10nFactory->get('settings', $lang); |
|
| 954 | - |
|
| 955 | - try { |
|
| 956 | - $this->newUserMailHelper->setL10N($l10n); |
|
| 957 | - $emailTemplate = $this->newUserMailHelper->generateTemplate($targetUser, false); |
|
| 958 | - $this->newUserMailHelper->sendMail($targetUser, $emailTemplate); |
|
| 959 | - } catch(\Exception $e) { |
|
| 960 | - $this->logger->logException($e, [ |
|
| 961 | - 'message' => "Can't send new user mail to $email", |
|
| 962 | - 'level' => \OCP\Util::ERROR, |
|
| 963 | - 'app' => 'settings', |
|
| 964 | - ]); |
|
| 965 | - throw new OCSException('Sending email failed', 102); |
|
| 966 | - } |
|
| 967 | - |
|
| 968 | - return new DataResponse(); |
|
| 969 | - } |
|
| 57 | + /** @var IUserManager */ |
|
| 58 | + private $userManager; |
|
| 59 | + /** @var IConfig */ |
|
| 60 | + private $config; |
|
| 61 | + /** @var IAppManager */ |
|
| 62 | + private $appManager; |
|
| 63 | + /** @var IGroupManager|\OC\Group\Manager */ // FIXME Requires a method that is not on the interface |
|
| 64 | + private $groupManager; |
|
| 65 | + /** @var IUserSession */ |
|
| 66 | + private $userSession; |
|
| 67 | + /** @var AccountManager */ |
|
| 68 | + private $accountManager; |
|
| 69 | + /** @var ILogger */ |
|
| 70 | + private $logger; |
|
| 71 | + /** @var IFactory */ |
|
| 72 | + private $l10nFactory; |
|
| 73 | + /** @var NewUserMailHelper */ |
|
| 74 | + private $newUserMailHelper; |
|
| 75 | + /** @var FederatedFileSharingFactory */ |
|
| 76 | + private $federatedFileSharingFactory; |
|
| 77 | + /** @var ISecureRandom */ |
|
| 78 | + private $secureRandom; |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * @param string $appName |
|
| 82 | + * @param IRequest $request |
|
| 83 | + * @param IUserManager $userManager |
|
| 84 | + * @param IConfig $config |
|
| 85 | + * @param IAppManager $appManager |
|
| 86 | + * @param IGroupManager $groupManager |
|
| 87 | + * @param IUserSession $userSession |
|
| 88 | + * @param AccountManager $accountManager |
|
| 89 | + * @param ILogger $logger |
|
| 90 | + * @param IFactory $l10nFactory |
|
| 91 | + * @param NewUserMailHelper $newUserMailHelper |
|
| 92 | + * @param FederatedFileSharingFactory $federatedFileSharingFactory |
|
| 93 | + * @param ISecureRandom $secureRandom |
|
| 94 | + */ |
|
| 95 | + public function __construct(string $appName, |
|
| 96 | + IRequest $request, |
|
| 97 | + IUserManager $userManager, |
|
| 98 | + IConfig $config, |
|
| 99 | + IAppManager $appManager, |
|
| 100 | + IGroupManager $groupManager, |
|
| 101 | + IUserSession $userSession, |
|
| 102 | + AccountManager $accountManager, |
|
| 103 | + ILogger $logger, |
|
| 104 | + IFactory $l10nFactory, |
|
| 105 | + NewUserMailHelper $newUserMailHelper, |
|
| 106 | + FederatedFileSharingFactory $federatedFileSharingFactory, |
|
| 107 | + ISecureRandom $secureRandom) { |
|
| 108 | + parent::__construct($appName, $request); |
|
| 109 | + |
|
| 110 | + $this->userManager = $userManager; |
|
| 111 | + $this->config = $config; |
|
| 112 | + $this->appManager = $appManager; |
|
| 113 | + $this->groupManager = $groupManager; |
|
| 114 | + $this->userSession = $userSession; |
|
| 115 | + $this->accountManager = $accountManager; |
|
| 116 | + $this->logger = $logger; |
|
| 117 | + $this->l10nFactory = $l10nFactory; |
|
| 118 | + $this->newUserMailHelper = $newUserMailHelper; |
|
| 119 | + $this->federatedFileSharingFactory = $federatedFileSharingFactory; |
|
| 120 | + $this->secureRandom = $secureRandom; |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + /** |
|
| 124 | + * @NoAdminRequired |
|
| 125 | + * |
|
| 126 | + * returns a list of users |
|
| 127 | + * |
|
| 128 | + * @param string $search |
|
| 129 | + * @param int $limit |
|
| 130 | + * @param int $offset |
|
| 131 | + * @return DataResponse |
|
| 132 | + */ |
|
| 133 | + public function getUsers(string $search = '', $limit = null, $offset = 0): DataResponse { |
|
| 134 | + $user = $this->userSession->getUser(); |
|
| 135 | + $users = []; |
|
| 136 | + |
|
| 137 | + // Admin? Or SubAdmin? |
|
| 138 | + $uid = $user->getUID(); |
|
| 139 | + $subAdminManager = $this->groupManager->getSubAdmin(); |
|
| 140 | + if($this->groupManager->isAdmin($uid)){ |
|
| 141 | + $users = $this->userManager->search($search, $limit, $offset); |
|
| 142 | + } else if ($subAdminManager->isSubAdmin($user)) { |
|
| 143 | + $subAdminOfGroups = $subAdminManager->getSubAdminsGroups($user); |
|
| 144 | + foreach ($subAdminOfGroups as $key => $group) { |
|
| 145 | + $subAdminOfGroups[$key] = $group->getGID(); |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + $users = []; |
|
| 149 | + foreach ($subAdminOfGroups as $group) { |
|
| 150 | + $users = array_merge($users, $this->groupManager->displayNamesInGroup($group, $search, $limit, $offset)); |
|
| 151 | + } |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + $users = array_keys($users); |
|
| 155 | + |
|
| 156 | + return new DataResponse([ |
|
| 157 | + 'users' => $users |
|
| 158 | + ]); |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + /** |
|
| 162 | + * @NoAdminRequired |
|
| 163 | + * |
|
| 164 | + * returns a list of users and their data |
|
| 165 | + */ |
|
| 166 | + public function getUsersDetails(string $search = '', $limit = null, $offset = 0): DataResponse { |
|
| 167 | + $user = $this->userSession->getUser(); |
|
| 168 | + $users = []; |
|
| 169 | + |
|
| 170 | + // Admin? Or SubAdmin? |
|
| 171 | + $uid = $user->getUID(); |
|
| 172 | + $subAdminManager = $this->groupManager->getSubAdmin(); |
|
| 173 | + if($this->groupManager->isAdmin($uid)){ |
|
| 174 | + $users = $this->userManager->search($search, $limit, $offset); |
|
| 175 | + } else if ($subAdminManager->isSubAdmin($user)) { |
|
| 176 | + $subAdminOfGroups = $subAdminManager->getSubAdminsGroups($user); |
|
| 177 | + foreach ($subAdminOfGroups as $key => $group) { |
|
| 178 | + $subAdminOfGroups[$key] = $group->getGID(); |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + $users = []; |
|
| 182 | + foreach ($subAdminOfGroups as $group) { |
|
| 183 | + $users = array_merge($users, $this->groupManager->displayNamesInGroup($group, $search, $limit, $offset)); |
|
| 184 | + } |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + $users = array_keys($users); |
|
| 188 | + $usersDetails = []; |
|
| 189 | + foreach ($users as $key => $userId) { |
|
| 190 | + $userData = $this->getUserData($userId); |
|
| 191 | + // Do not insert empty entry |
|
| 192 | + if(!empty($userData)) { |
|
| 193 | + $usersDetails[$userId] = $userData; |
|
| 194 | + } |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + return new DataResponse([ |
|
| 198 | + 'users' => $usersDetails |
|
| 199 | + ]); |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + /** |
|
| 203 | + * @PasswordConfirmationRequired |
|
| 204 | + * @NoAdminRequired |
|
| 205 | + * |
|
| 206 | + * @param string $userid |
|
| 207 | + * @param string $password |
|
| 208 | + * @param string $email |
|
| 209 | + * @param array $groups |
|
| 210 | + * @return DataResponse |
|
| 211 | + * @throws OCSException |
|
| 212 | + */ |
|
| 213 | + public function addUser(string $userid, string $password = '', string $email='', array $groups = []): DataResponse { |
|
| 214 | + $user = $this->userSession->getUser(); |
|
| 215 | + $isAdmin = $this->groupManager->isAdmin($user->getUID()); |
|
| 216 | + $subAdminManager = $this->groupManager->getSubAdmin(); |
|
| 217 | + |
|
| 218 | + if($this->userManager->userExists($userid)) { |
|
| 219 | + $this->logger->error('Failed addUser attempt: User already exists.', ['app' => 'ocs_api']); |
|
| 220 | + throw new OCSException('User already exists', 102); |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + if($groups !== []) { |
|
| 224 | + foreach ($groups as $group) { |
|
| 225 | + if(!$this->groupManager->groupExists($group)) { |
|
| 226 | + throw new OCSException('group '.$group.' does not exist', 104); |
|
| 227 | + } |
|
| 228 | + if(!$isAdmin && !$subAdminManager->isSubAdminofGroup($user, $this->groupManager->get($group))) { |
|
| 229 | + throw new OCSException('insufficient privileges for group '. $group, 105); |
|
| 230 | + } |
|
| 231 | + } |
|
| 232 | + } else { |
|
| 233 | + if(!$isAdmin) { |
|
| 234 | + throw new OCSException('no group specified (required for subadmins)', 106); |
|
| 235 | + } |
|
| 236 | + } |
|
| 237 | + |
|
| 238 | + $generatePasswordResetToken = false; |
|
| 239 | + if ($password === '') { |
|
| 240 | + if ($email === '') { |
|
| 241 | + throw new OCSException('To send a password link to the user an email address is required.', 108); |
|
| 242 | + } |
|
| 243 | + |
|
| 244 | + $password = $this->secureRandom->generate(10); |
|
| 245 | + // Make sure we pass the password_policy |
|
| 246 | + $password .= $this->secureRandom->generate(2, '$!.,;:-~+*[]{}()'); |
|
| 247 | + $generatePasswordResetToken = true; |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + try { |
|
| 251 | + $newUser = $this->userManager->createUser($userid, $password); |
|
| 252 | + $this->logger->info('Successful addUser call with userid: ' . $userid, ['app' => 'ocs_api']); |
|
| 253 | + |
|
| 254 | + foreach ($groups as $group) { |
|
| 255 | + $this->groupManager->get($group)->addUser($newUser); |
|
| 256 | + $this->logger->info('Added userid ' . $userid . ' to group ' . $group, ['app' => 'ocs_api']); |
|
| 257 | + } |
|
| 258 | + |
|
| 259 | + // Send new user mail only if a mail is set |
|
| 260 | + if ($email !== '') { |
|
| 261 | + $newUser->setEMailAddress($email); |
|
| 262 | + try { |
|
| 263 | + $emailTemplate = $this->newUserMailHelper->generateTemplate($newUser, $generatePasswordResetToken); |
|
| 264 | + $this->newUserMailHelper->sendMail($newUser, $emailTemplate); |
|
| 265 | + } catch (\Exception $e) { |
|
| 266 | + $this->logger->logException($e, [ |
|
| 267 | + 'message' => "Can't send new user mail to $email", |
|
| 268 | + 'level' => \OCP\Util::ERROR, |
|
| 269 | + 'app' => 'ocs_api', |
|
| 270 | + ]); |
|
| 271 | + throw new OCSException('Unable to send the invitation mail', 109); |
|
| 272 | + } |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + return new DataResponse(); |
|
| 276 | + |
|
| 277 | + } catch (HintException $e ) { |
|
| 278 | + $this->logger->logException($e, [ |
|
| 279 | + 'message' => 'Failed addUser attempt with hint exception.', |
|
| 280 | + 'level' => \OCP\Util::WARN, |
|
| 281 | + 'app' => 'ocs_api', |
|
| 282 | + ]); |
|
| 283 | + throw new OCSException($e->getHint(), 107); |
|
| 284 | + } catch (\Exception $e) { |
|
| 285 | + $this->logger->logException($e, [ |
|
| 286 | + 'message' => 'Failed addUser attempt with exception.', |
|
| 287 | + 'level' => \OCP\Util::ERROR, |
|
| 288 | + 'app' => 'ocs_api', |
|
| 289 | + ]); |
|
| 290 | + throw new OCSException('Bad request', 101); |
|
| 291 | + } |
|
| 292 | + } |
|
| 293 | + |
|
| 294 | + /** |
|
| 295 | + * @NoAdminRequired |
|
| 296 | + * @NoSubAdminRequired |
|
| 297 | + * |
|
| 298 | + * gets user info |
|
| 299 | + * |
|
| 300 | + * @param string $userId |
|
| 301 | + * @return DataResponse |
|
| 302 | + * @throws OCSException |
|
| 303 | + */ |
|
| 304 | + public function getUser(string $userId): DataResponse { |
|
| 305 | + $data = $this->getUserData($userId); |
|
| 306 | + // getUserData returns empty array if not enough permissions |
|
| 307 | + if(empty($data)) { |
|
| 308 | + throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
| 309 | + } |
|
| 310 | + return new DataResponse($data); |
|
| 311 | + } |
|
| 312 | + |
|
| 313 | + /** |
|
| 314 | + * @NoAdminRequired |
|
| 315 | + * @NoSubAdminRequired |
|
| 316 | + * |
|
| 317 | + * gets user info from the currently logged in user |
|
| 318 | + * |
|
| 319 | + * @return DataResponse |
|
| 320 | + * @throws OCSException |
|
| 321 | + */ |
|
| 322 | + public function getCurrentUser(): DataResponse { |
|
| 323 | + $user = $this->userSession->getUser(); |
|
| 324 | + if ($user) { |
|
| 325 | + $data = $this->getUserData($user->getUID()); |
|
| 326 | + // rename "displayname" to "display-name" only for this call to keep |
|
| 327 | + // the API stable. |
|
| 328 | + $data['display-name'] = $data['displayname']; |
|
| 329 | + unset($data['displayname']); |
|
| 330 | + return new DataResponse($data); |
|
| 331 | + |
|
| 332 | + } |
|
| 333 | + |
|
| 334 | + throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
| 335 | + } |
|
| 336 | + |
|
| 337 | + /** |
|
| 338 | + * creates a array with all user data |
|
| 339 | + * |
|
| 340 | + * @param $userId |
|
| 341 | + * @return array |
|
| 342 | + * @throws OCSException |
|
| 343 | + */ |
|
| 344 | + protected function getUserData(string $userId): array { |
|
| 345 | + $currentLoggedInUser = $this->userSession->getUser(); |
|
| 346 | + |
|
| 347 | + $data = []; |
|
| 348 | + |
|
| 349 | + // Check if the target user exists |
|
| 350 | + $targetUserObject = $this->userManager->get($userId); |
|
| 351 | + if($targetUserObject === null) { |
|
| 352 | + throw new OCSException('The requested user could not be found', \OCP\API::RESPOND_NOT_FOUND); |
|
| 353 | + } |
|
| 354 | + |
|
| 355 | + // Should be at least Admin Or SubAdmin! |
|
| 356 | + if( $this->groupManager->isAdmin($currentLoggedInUser->getUID()) |
|
| 357 | + || $this->groupManager->getSubAdmin()->isUserAccessible($currentLoggedInUser, $targetUserObject)) { |
|
| 358 | + $data['enabled'] = $this->config->getUserValue($targetUserObject->getUID(), 'core', 'enabled', 'true'); |
|
| 359 | + } else { |
|
| 360 | + // Check they are looking up themselves |
|
| 361 | + if($currentLoggedInUser->getUID() !== $targetUserObject->getUID()) { |
|
| 362 | + return $data; |
|
| 363 | + } |
|
| 364 | + } |
|
| 365 | + |
|
| 366 | + // Get groups data |
|
| 367 | + $userAccount = $this->accountManager->getUser($targetUserObject); |
|
| 368 | + $groups = $this->groupManager->getUserGroups($targetUserObject); |
|
| 369 | + $gids = []; |
|
| 370 | + foreach ($groups as $group) { |
|
| 371 | + $gids[] = $group->getDisplayName(); |
|
| 372 | + } |
|
| 373 | + |
|
| 374 | + // Find the data |
|
| 375 | + $data['id'] = $targetUserObject->getUID(); |
|
| 376 | + $data['storageLocation'] = $targetUserObject->getHome(); |
|
| 377 | + $data['lastLogin'] = $targetUserObject->getLastLogin() * 1000; |
|
| 378 | + $data['backend'] = $targetUserObject->getBackendClassName(); |
|
| 379 | + $data['subadmin'] = $this->getUserSubAdminGroupsData($targetUserObject->getUID()); |
|
| 380 | + $data['quota'] = $this->fillStorageInfo($targetUserObject->getUID()); |
|
| 381 | + $data[AccountManager::PROPERTY_EMAIL] = $targetUserObject->getEMailAddress(); |
|
| 382 | + $data[AccountManager::PROPERTY_DISPLAYNAME] = $targetUserObject->getDisplayName(); |
|
| 383 | + $data[AccountManager::PROPERTY_PHONE] = $userAccount[AccountManager::PROPERTY_PHONE]['value']; |
|
| 384 | + $data[AccountManager::PROPERTY_ADDRESS] = $userAccount[AccountManager::PROPERTY_ADDRESS]['value']; |
|
| 385 | + $data[AccountManager::PROPERTY_WEBSITE] = $userAccount[AccountManager::PROPERTY_WEBSITE]['value']; |
|
| 386 | + $data[AccountManager::PROPERTY_TWITTER] = $userAccount[AccountManager::PROPERTY_TWITTER]['value']; |
|
| 387 | + $data['groups'] = $gids; |
|
| 388 | + $data['language'] = $this->config->getUserValue($targetUserObject->getUID(), 'core', 'lang'); |
|
| 389 | + |
|
| 390 | + return $data; |
|
| 391 | + } |
|
| 392 | + |
|
| 393 | + /** |
|
| 394 | + * @NoAdminRequired |
|
| 395 | + * @NoSubAdminRequired |
|
| 396 | + */ |
|
| 397 | + public function getEditableFields(): DataResponse { |
|
| 398 | + $permittedFields = []; |
|
| 399 | + |
|
| 400 | + // Editing self (display, email) |
|
| 401 | + if ($this->config->getSystemValue('allow_user_to_change_display_name', true) !== false) { |
|
| 402 | + $permittedFields[] = AccountManager::PROPERTY_DISPLAYNAME; |
|
| 403 | + $permittedFields[] = AccountManager::PROPERTY_EMAIL; |
|
| 404 | + } |
|
| 405 | + |
|
| 406 | + if ($this->appManager->isEnabledForUser('federatedfilesharing')) { |
|
| 407 | + $federatedFileSharing = $this->federatedFileSharingFactory->get(); |
|
| 408 | + $shareProvider = $federatedFileSharing->getFederatedShareProvider(); |
|
| 409 | + if ($shareProvider->isLookupServerUploadEnabled()) { |
|
| 410 | + $permittedFields[] = AccountManager::PROPERTY_PHONE; |
|
| 411 | + $permittedFields[] = AccountManager::PROPERTY_ADDRESS; |
|
| 412 | + $permittedFields[] = AccountManager::PROPERTY_WEBSITE; |
|
| 413 | + $permittedFields[] = AccountManager::PROPERTY_TWITTER; |
|
| 414 | + } |
|
| 415 | + } |
|
| 416 | + |
|
| 417 | + return new DataResponse($permittedFields); |
|
| 418 | + } |
|
| 419 | + |
|
| 420 | + /** |
|
| 421 | + * @NoAdminRequired |
|
| 422 | + * @NoSubAdminRequired |
|
| 423 | + * @PasswordConfirmationRequired |
|
| 424 | + * |
|
| 425 | + * edit users |
|
| 426 | + * |
|
| 427 | + * @param string $userId |
|
| 428 | + * @param string $key |
|
| 429 | + * @param string $value |
|
| 430 | + * @return DataResponse |
|
| 431 | + * @throws OCSException |
|
| 432 | + */ |
|
| 433 | + public function editUser(string $userId, string $key, string $value): DataResponse { |
|
| 434 | + $currentLoggedInUser = $this->userSession->getUser(); |
|
| 435 | + |
|
| 436 | + $targetUser = $this->userManager->get($userId); |
|
| 437 | + if($targetUser === null) { |
|
| 438 | + throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
| 439 | + } |
|
| 440 | + |
|
| 441 | + $permittedFields = []; |
|
| 442 | + if($targetUser->getUID() === $currentLoggedInUser->getUID()) { |
|
| 443 | + // Editing self (display, email) |
|
| 444 | + if ($this->config->getSystemValue('allow_user_to_change_display_name', true) !== false) { |
|
| 445 | + $permittedFields[] = 'display'; |
|
| 446 | + $permittedFields[] = AccountManager::PROPERTY_DISPLAYNAME; |
|
| 447 | + $permittedFields[] = AccountManager::PROPERTY_EMAIL; |
|
| 448 | + } |
|
| 449 | + |
|
| 450 | + $permittedFields[] = 'password'; |
|
| 451 | + if ($this->config->getSystemValue('force_language', false) === false || |
|
| 452 | + $this->groupManager->isAdmin($currentLoggedInUser->getUID())) { |
|
| 453 | + $permittedFields[] = 'language'; |
|
| 454 | + } |
|
| 455 | + |
|
| 456 | + if ($this->appManager->isEnabledForUser('federatedfilesharing')) { |
|
| 457 | + $federatedFileSharing = new \OCA\FederatedFileSharing\AppInfo\Application(); |
|
| 458 | + $shareProvider = $federatedFileSharing->getFederatedShareProvider(); |
|
| 459 | + if ($shareProvider->isLookupServerUploadEnabled()) { |
|
| 460 | + $permittedFields[] = AccountManager::PROPERTY_PHONE; |
|
| 461 | + $permittedFields[] = AccountManager::PROPERTY_ADDRESS; |
|
| 462 | + $permittedFields[] = AccountManager::PROPERTY_WEBSITE; |
|
| 463 | + $permittedFields[] = AccountManager::PROPERTY_TWITTER; |
|
| 464 | + } |
|
| 465 | + } |
|
| 466 | + |
|
| 467 | + // If admin they can edit their own quota |
|
| 468 | + if($this->groupManager->isAdmin($currentLoggedInUser->getUID())) { |
|
| 469 | + $permittedFields[] = 'quota'; |
|
| 470 | + } |
|
| 471 | + } else { |
|
| 472 | + // Check if admin / subadmin |
|
| 473 | + $subAdminManager = $this->groupManager->getSubAdmin(); |
|
| 474 | + if($subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser) |
|
| 475 | + || $this->groupManager->isAdmin($currentLoggedInUser->getUID())) { |
|
| 476 | + // They have permissions over the user |
|
| 477 | + $permittedFields[] = 'display'; |
|
| 478 | + $permittedFields[] = AccountManager::PROPERTY_DISPLAYNAME; |
|
| 479 | + $permittedFields[] = AccountManager::PROPERTY_EMAIL; |
|
| 480 | + $permittedFields[] = 'password'; |
|
| 481 | + $permittedFields[] = 'language'; |
|
| 482 | + $permittedFields[] = AccountManager::PROPERTY_PHONE; |
|
| 483 | + $permittedFields[] = AccountManager::PROPERTY_ADDRESS; |
|
| 484 | + $permittedFields[] = AccountManager::PROPERTY_WEBSITE; |
|
| 485 | + $permittedFields[] = AccountManager::PROPERTY_TWITTER; |
|
| 486 | + $permittedFields[] = 'quota'; |
|
| 487 | + } else { |
|
| 488 | + // No rights |
|
| 489 | + throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
| 490 | + } |
|
| 491 | + } |
|
| 492 | + // Check if permitted to edit this field |
|
| 493 | + if(!in_array($key, $permittedFields)) { |
|
| 494 | + throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
| 495 | + } |
|
| 496 | + // Process the edit |
|
| 497 | + switch($key) { |
|
| 498 | + case 'display': |
|
| 499 | + case AccountManager::PROPERTY_DISPLAYNAME: |
|
| 500 | + $targetUser->setDisplayName($value); |
|
| 501 | + break; |
|
| 502 | + case 'quota': |
|
| 503 | + $quota = $value; |
|
| 504 | + if($quota !== 'none' && $quota !== 'default') { |
|
| 505 | + if (is_numeric($quota)) { |
|
| 506 | + $quota = (float) $quota; |
|
| 507 | + } else { |
|
| 508 | + $quota = \OCP\Util::computerFileSize($quota); |
|
| 509 | + } |
|
| 510 | + if ($quota === false) { |
|
| 511 | + throw new OCSException('Invalid quota value '.$value, 103); |
|
| 512 | + } |
|
| 513 | + if($quota === 0) { |
|
| 514 | + $quota = 'default'; |
|
| 515 | + }else if($quota === -1) { |
|
| 516 | + $quota = 'none'; |
|
| 517 | + } else { |
|
| 518 | + $quota = \OCP\Util::humanFileSize($quota); |
|
| 519 | + } |
|
| 520 | + } |
|
| 521 | + $targetUser->setQuota($quota); |
|
| 522 | + break; |
|
| 523 | + case 'password': |
|
| 524 | + $targetUser->setPassword($value); |
|
| 525 | + break; |
|
| 526 | + case 'language': |
|
| 527 | + $languagesCodes = $this->l10nFactory->findAvailableLanguages(); |
|
| 528 | + if (!in_array($value, $languagesCodes, true) && $value !== 'en') { |
|
| 529 | + throw new OCSException('Invalid language', 102); |
|
| 530 | + } |
|
| 531 | + $this->config->setUserValue($targetUser->getUID(), 'core', 'lang', $value); |
|
| 532 | + break; |
|
| 533 | + case AccountManager::PROPERTY_EMAIL: |
|
| 534 | + if(filter_var($value, FILTER_VALIDATE_EMAIL) || $value === '') { |
|
| 535 | + $targetUser->setEMailAddress($value); |
|
| 536 | + } else { |
|
| 537 | + throw new OCSException('', 102); |
|
| 538 | + } |
|
| 539 | + break; |
|
| 540 | + case AccountManager::PROPERTY_PHONE: |
|
| 541 | + case AccountManager::PROPERTY_ADDRESS: |
|
| 542 | + case AccountManager::PROPERTY_WEBSITE: |
|
| 543 | + case AccountManager::PROPERTY_TWITTER: |
|
| 544 | + $userAccount = $this->accountManager->getUser($targetUser); |
|
| 545 | + if ($userAccount[$key]['value'] !== $value) { |
|
| 546 | + $userAccount[$key]['value'] = $value; |
|
| 547 | + $this->accountManager->updateUser($targetUser, $userAccount); |
|
| 548 | + } |
|
| 549 | + break; |
|
| 550 | + default: |
|
| 551 | + throw new OCSException('', 103); |
|
| 552 | + } |
|
| 553 | + return new DataResponse(); |
|
| 554 | + } |
|
| 555 | + |
|
| 556 | + /** |
|
| 557 | + * @PasswordConfirmationRequired |
|
| 558 | + * @NoAdminRequired |
|
| 559 | + * |
|
| 560 | + * @param string $userId |
|
| 561 | + * @return DataResponse |
|
| 562 | + * @throws OCSException |
|
| 563 | + */ |
|
| 564 | + public function deleteUser(string $userId): DataResponse { |
|
| 565 | + $currentLoggedInUser = $this->userSession->getUser(); |
|
| 566 | + |
|
| 567 | + $targetUser = $this->userManager->get($userId); |
|
| 568 | + |
|
| 569 | + if($targetUser === null || $targetUser->getUID() === $currentLoggedInUser->getUID()) { |
|
| 570 | + throw new OCSException('', 101); |
|
| 571 | + } |
|
| 572 | + |
|
| 573 | + // If not permitted |
|
| 574 | + $subAdminManager = $this->groupManager->getSubAdmin(); |
|
| 575 | + if(!$this->groupManager->isAdmin($currentLoggedInUser->getUID()) && !$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)) { |
|
| 576 | + throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
| 577 | + } |
|
| 578 | + |
|
| 579 | + // Go ahead with the delete |
|
| 580 | + if($targetUser->delete()) { |
|
| 581 | + return new DataResponse(); |
|
| 582 | + } else { |
|
| 583 | + throw new OCSException('', 101); |
|
| 584 | + } |
|
| 585 | + } |
|
| 586 | + |
|
| 587 | + /** |
|
| 588 | + * @PasswordConfirmationRequired |
|
| 589 | + * @NoAdminRequired |
|
| 590 | + * |
|
| 591 | + * @param string $userId |
|
| 592 | + * @return DataResponse |
|
| 593 | + * @throws OCSException |
|
| 594 | + * @throws OCSForbiddenException |
|
| 595 | + */ |
|
| 596 | + public function disableUser(string $userId): DataResponse { |
|
| 597 | + return $this->setEnabled($userId, false); |
|
| 598 | + } |
|
| 599 | + |
|
| 600 | + /** |
|
| 601 | + * @PasswordConfirmationRequired |
|
| 602 | + * @NoAdminRequired |
|
| 603 | + * |
|
| 604 | + * @param string $userId |
|
| 605 | + * @return DataResponse |
|
| 606 | + * @throws OCSException |
|
| 607 | + * @throws OCSForbiddenException |
|
| 608 | + */ |
|
| 609 | + public function enableUser(string $userId): DataResponse { |
|
| 610 | + return $this->setEnabled($userId, true); |
|
| 611 | + } |
|
| 612 | + |
|
| 613 | + /** |
|
| 614 | + * @param string $userId |
|
| 615 | + * @param bool $value |
|
| 616 | + * @return DataResponse |
|
| 617 | + * @throws OCSException |
|
| 618 | + */ |
|
| 619 | + private function setEnabled(string $userId, bool $value): DataResponse { |
|
| 620 | + $currentLoggedInUser = $this->userSession->getUser(); |
|
| 621 | + |
|
| 622 | + $targetUser = $this->userManager->get($userId); |
|
| 623 | + if($targetUser === null || $targetUser->getUID() === $currentLoggedInUser->getUID()) { |
|
| 624 | + throw new OCSException('', 101); |
|
| 625 | + } |
|
| 626 | + |
|
| 627 | + // If not permitted |
|
| 628 | + $subAdminManager = $this->groupManager->getSubAdmin(); |
|
| 629 | + if(!$this->groupManager->isAdmin($currentLoggedInUser->getUID()) && !$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)) { |
|
| 630 | + throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
| 631 | + } |
|
| 632 | + |
|
| 633 | + // enable/disable the user now |
|
| 634 | + $targetUser->setEnabled($value); |
|
| 635 | + return new DataResponse(); |
|
| 636 | + } |
|
| 637 | + |
|
| 638 | + /** |
|
| 639 | + * @NoAdminRequired |
|
| 640 | + * @NoSubAdminRequired |
|
| 641 | + * |
|
| 642 | + * @param string $userId |
|
| 643 | + * @return DataResponse |
|
| 644 | + * @throws OCSException |
|
| 645 | + */ |
|
| 646 | + public function getUsersGroups(string $userId): DataResponse { |
|
| 647 | + $loggedInUser = $this->userSession->getUser(); |
|
| 648 | + |
|
| 649 | + $targetUser = $this->userManager->get($userId); |
|
| 650 | + if($targetUser === null) { |
|
| 651 | + throw new OCSException('', \OCP\API::RESPOND_NOT_FOUND); |
|
| 652 | + } |
|
| 653 | + |
|
| 654 | + if($targetUser->getUID() === $loggedInUser->getUID() || $this->groupManager->isAdmin($loggedInUser->getUID())) { |
|
| 655 | + // Self lookup or admin lookup |
|
| 656 | + return new DataResponse([ |
|
| 657 | + 'groups' => $this->groupManager->getUserGroupIds($targetUser) |
|
| 658 | + ]); |
|
| 659 | + } else { |
|
| 660 | + $subAdminManager = $this->groupManager->getSubAdmin(); |
|
| 661 | + |
|
| 662 | + // Looking up someone else |
|
| 663 | + if($subAdminManager->isUserAccessible($loggedInUser, $targetUser)) { |
|
| 664 | + // Return the group that the method caller is subadmin of for the user in question |
|
| 665 | + /** @var IGroup[] $getSubAdminsGroups */ |
|
| 666 | + $getSubAdminsGroups = $subAdminManager->getSubAdminsGroups($loggedInUser); |
|
| 667 | + foreach ($getSubAdminsGroups as $key => $group) { |
|
| 668 | + $getSubAdminsGroups[$key] = $group->getGID(); |
|
| 669 | + } |
|
| 670 | + $groups = array_intersect( |
|
| 671 | + $getSubAdminsGroups, |
|
| 672 | + $this->groupManager->getUserGroupIds($targetUser) |
|
| 673 | + ); |
|
| 674 | + return new DataResponse(['groups' => $groups]); |
|
| 675 | + } else { |
|
| 676 | + // Not permitted |
|
| 677 | + throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
| 678 | + } |
|
| 679 | + } |
|
| 680 | + |
|
| 681 | + } |
|
| 682 | + |
|
| 683 | + /** |
|
| 684 | + * @PasswordConfirmationRequired |
|
| 685 | + * @NoAdminRequired |
|
| 686 | + * |
|
| 687 | + * @param string $userId |
|
| 688 | + * @param string $groupid |
|
| 689 | + * @return DataResponse |
|
| 690 | + * @throws OCSException |
|
| 691 | + */ |
|
| 692 | + public function addToGroup(string $userId, string $groupid = ''): DataResponse { |
|
| 693 | + if($groupid === '') { |
|
| 694 | + throw new OCSException('', 101); |
|
| 695 | + } |
|
| 696 | + |
|
| 697 | + $group = $this->groupManager->get($groupid); |
|
| 698 | + $targetUser = $this->userManager->get($userId); |
|
| 699 | + if($group === null) { |
|
| 700 | + throw new OCSException('', 102); |
|
| 701 | + } |
|
| 702 | + if($targetUser === null) { |
|
| 703 | + throw new OCSException('', 103); |
|
| 704 | + } |
|
| 705 | + |
|
| 706 | + // If they're not an admin, check they are a subadmin of the group in question |
|
| 707 | + $loggedInUser = $this->userSession->getUser(); |
|
| 708 | + $subAdminManager = $this->groupManager->getSubAdmin(); |
|
| 709 | + if (!$this->groupManager->isAdmin($loggedInUser->getUID()) && !$subAdminManager->isSubAdminOfGroup($loggedInUser, $group)) { |
|
| 710 | + throw new OCSException('', 104); |
|
| 711 | + } |
|
| 712 | + |
|
| 713 | + // Add user to group |
|
| 714 | + $group->addUser($targetUser); |
|
| 715 | + return new DataResponse(); |
|
| 716 | + } |
|
| 717 | + |
|
| 718 | + /** |
|
| 719 | + * @PasswordConfirmationRequired |
|
| 720 | + * @NoAdminRequired |
|
| 721 | + * |
|
| 722 | + * @param string $userId |
|
| 723 | + * @param string $groupid |
|
| 724 | + * @return DataResponse |
|
| 725 | + * @throws OCSException |
|
| 726 | + */ |
|
| 727 | + public function removeFromGroup(string $userId, string $groupid): DataResponse { |
|
| 728 | + $loggedInUser = $this->userSession->getUser(); |
|
| 729 | + |
|
| 730 | + if($groupid === null || trim($groupid) === '') { |
|
| 731 | + throw new OCSException('', 101); |
|
| 732 | + } |
|
| 733 | + |
|
| 734 | + $group = $this->groupManager->get($groupid); |
|
| 735 | + if($group === null) { |
|
| 736 | + throw new OCSException('', 102); |
|
| 737 | + } |
|
| 738 | + |
|
| 739 | + $targetUser = $this->userManager->get($userId); |
|
| 740 | + if($targetUser === null) { |
|
| 741 | + throw new OCSException('', 103); |
|
| 742 | + } |
|
| 743 | + |
|
| 744 | + // If they're not an admin, check they are a subadmin of the group in question |
|
| 745 | + $subAdminManager = $this->groupManager->getSubAdmin(); |
|
| 746 | + if (!$this->groupManager->isAdmin($loggedInUser->getUID()) && !$subAdminManager->isSubAdminOfGroup($loggedInUser, $group)) { |
|
| 747 | + throw new OCSException('', 104); |
|
| 748 | + } |
|
| 749 | + |
|
| 750 | + // Check they aren't removing themselves from 'admin' or their 'subadmin; group |
|
| 751 | + if ($targetUser->getUID() === $loggedInUser->getUID()) { |
|
| 752 | + if ($this->groupManager->isAdmin($loggedInUser->getUID())) { |
|
| 753 | + if ($group->getGID() === 'admin') { |
|
| 754 | + throw new OCSException('Cannot remove yourself from the admin group', 105); |
|
| 755 | + } |
|
| 756 | + } else { |
|
| 757 | + // Not an admin, so the user must be a subadmin of this group, but that is not allowed. |
|
| 758 | + throw new OCSException('Cannot remove yourself from this group as you are a SubAdmin', 105); |
|
| 759 | + } |
|
| 760 | + |
|
| 761 | + } else if (!$this->groupManager->isAdmin($loggedInUser->getUID())) { |
|
| 762 | + /** @var IGroup[] $subAdminGroups */ |
|
| 763 | + $subAdminGroups = $subAdminManager->getSubAdminsGroups($loggedInUser); |
|
| 764 | + $subAdminGroups = array_map(function (IGroup $subAdminGroup) { |
|
| 765 | + return $subAdminGroup->getGID(); |
|
| 766 | + }, $subAdminGroups); |
|
| 767 | + $userGroups = $this->groupManager->getUserGroupIds($targetUser); |
|
| 768 | + $userSubAdminGroups = array_intersect($subAdminGroups, $userGroups); |
|
| 769 | + |
|
| 770 | + if (count($userSubAdminGroups) <= 1) { |
|
| 771 | + // Subadmin must not be able to remove a user from all their subadmin groups. |
|
| 772 | + throw new OCSException('Cannot remove user from this group as this is the only remaining group you are a SubAdmin of', 105); |
|
| 773 | + } |
|
| 774 | + } |
|
| 775 | + |
|
| 776 | + // Remove user from group |
|
| 777 | + $group->removeUser($targetUser); |
|
| 778 | + return new DataResponse(); |
|
| 779 | + } |
|
| 780 | + |
|
| 781 | + /** |
|
| 782 | + * Creates a subadmin |
|
| 783 | + * |
|
| 784 | + * @PasswordConfirmationRequired |
|
| 785 | + * |
|
| 786 | + * @param string $userId |
|
| 787 | + * @param string $groupid |
|
| 788 | + * @return DataResponse |
|
| 789 | + * @throws OCSException |
|
| 790 | + */ |
|
| 791 | + public function addSubAdmin(string $userId, string $groupid): DataResponse { |
|
| 792 | + $group = $this->groupManager->get($groupid); |
|
| 793 | + $user = $this->userManager->get($userId); |
|
| 794 | + |
|
| 795 | + // Check if the user exists |
|
| 796 | + if($user === null) { |
|
| 797 | + throw new OCSException('User does not exist', 101); |
|
| 798 | + } |
|
| 799 | + // Check if group exists |
|
| 800 | + if($group === null) { |
|
| 801 | + throw new OCSException('Group does not exist', 102); |
|
| 802 | + } |
|
| 803 | + // Check if trying to make subadmin of admin group |
|
| 804 | + if($group->getGID() === 'admin') { |
|
| 805 | + throw new OCSException('Cannot create subadmins for admin group', 103); |
|
| 806 | + } |
|
| 807 | + |
|
| 808 | + $subAdminManager = $this->groupManager->getSubAdmin(); |
|
| 809 | + |
|
| 810 | + // We cannot be subadmin twice |
|
| 811 | + if ($subAdminManager->isSubAdminofGroup($user, $group)) { |
|
| 812 | + return new DataResponse(); |
|
| 813 | + } |
|
| 814 | + // Go |
|
| 815 | + if($subAdminManager->createSubAdmin($user, $group)) { |
|
| 816 | + return new DataResponse(); |
|
| 817 | + } else { |
|
| 818 | + throw new OCSException('Unknown error occurred', 103); |
|
| 819 | + } |
|
| 820 | + } |
|
| 821 | + |
|
| 822 | + /** |
|
| 823 | + * Removes a subadmin from a group |
|
| 824 | + * |
|
| 825 | + * @PasswordConfirmationRequired |
|
| 826 | + * |
|
| 827 | + * @param string $userId |
|
| 828 | + * @param string $groupid |
|
| 829 | + * @return DataResponse |
|
| 830 | + * @throws OCSException |
|
| 831 | + */ |
|
| 832 | + public function removeSubAdmin(string $userId, string $groupid): DataResponse { |
|
| 833 | + $group = $this->groupManager->get($groupid); |
|
| 834 | + $user = $this->userManager->get($userId); |
|
| 835 | + $subAdminManager = $this->groupManager->getSubAdmin(); |
|
| 836 | + |
|
| 837 | + // Check if the user exists |
|
| 838 | + if($user === null) { |
|
| 839 | + throw new OCSException('User does not exist', 101); |
|
| 840 | + } |
|
| 841 | + // Check if the group exists |
|
| 842 | + if($group === null) { |
|
| 843 | + throw new OCSException('Group does not exist', 101); |
|
| 844 | + } |
|
| 845 | + // Check if they are a subadmin of this said group |
|
| 846 | + if(!$subAdminManager->isSubAdminOfGroup($user, $group)) { |
|
| 847 | + throw new OCSException('User is not a subadmin of this group', 102); |
|
| 848 | + } |
|
| 849 | + |
|
| 850 | + // Go |
|
| 851 | + if($subAdminManager->deleteSubAdmin($user, $group)) { |
|
| 852 | + return new DataResponse(); |
|
| 853 | + } else { |
|
| 854 | + throw new OCSException('Unknown error occurred', 103); |
|
| 855 | + } |
|
| 856 | + } |
|
| 857 | + |
|
| 858 | + /** |
|
| 859 | + * Get the groups a user is a subadmin of |
|
| 860 | + * |
|
| 861 | + * @param string $userId |
|
| 862 | + * @return array |
|
| 863 | + * @throws OCSException |
|
| 864 | + */ |
|
| 865 | + protected function getUserSubAdminGroupsData(string $userId): array { |
|
| 866 | + $user = $this->userManager->get($userId); |
|
| 867 | + // Check if the user exists |
|
| 868 | + if($user === null) { |
|
| 869 | + throw new OCSException('User does not exist', 101); |
|
| 870 | + } |
|
| 871 | + |
|
| 872 | + // Get the subadmin groups |
|
| 873 | + $subAdminGroups = $this->groupManager->getSubAdmin()->getSubAdminsGroups($user); |
|
| 874 | + $groups = []; |
|
| 875 | + foreach ($subAdminGroups as $key => $group) { |
|
| 876 | + $groups[] = $group->getGID(); |
|
| 877 | + } |
|
| 878 | + |
|
| 879 | + return $groups; |
|
| 880 | + } |
|
| 881 | + |
|
| 882 | + /** |
|
| 883 | + * Get the groups a user is a subadmin of |
|
| 884 | + * |
|
| 885 | + * @param string $userId |
|
| 886 | + * @return DataResponse |
|
| 887 | + * @throws OCSException |
|
| 888 | + */ |
|
| 889 | + public function getUserSubAdminGroups(string $userId): DataResponse { |
|
| 890 | + $groups = $this->getUserSubAdminGroupsData($userId); |
|
| 891 | + return new DataResponse($groups); |
|
| 892 | + } |
|
| 893 | + |
|
| 894 | + /** |
|
| 895 | + * @param string $userId |
|
| 896 | + * @return array |
|
| 897 | + * @throws \OCP\Files\NotFoundException |
|
| 898 | + */ |
|
| 899 | + protected function fillStorageInfo(string $userId): array { |
|
| 900 | + try { |
|
| 901 | + \OC_Util::tearDownFS(); |
|
| 902 | + \OC_Util::setupFS($userId); |
|
| 903 | + $storage = OC_Helper::getStorageInfo('/'); |
|
| 904 | + $data = [ |
|
| 905 | + 'free' => $storage['free'], |
|
| 906 | + 'used' => $storage['used'], |
|
| 907 | + 'total' => $storage['total'], |
|
| 908 | + 'relative' => $storage['relative'], |
|
| 909 | + 'quota' => $storage['quota'], |
|
| 910 | + ]; |
|
| 911 | + } catch (NotFoundException $ex) { |
|
| 912 | + $data = []; |
|
| 913 | + } |
|
| 914 | + return $data; |
|
| 915 | + } |
|
| 916 | + |
|
| 917 | + /** |
|
| 918 | + * @NoAdminRequired |
|
| 919 | + * @PasswordConfirmationRequired |
|
| 920 | + * |
|
| 921 | + * resend welcome message |
|
| 922 | + * |
|
| 923 | + * @param string $userId |
|
| 924 | + * @return DataResponse |
|
| 925 | + * @throws OCSException |
|
| 926 | + */ |
|
| 927 | + public function resendWelcomeMessage(string $userId): DataResponse { |
|
| 928 | + $currentLoggedInUser = $this->userSession->getUser(); |
|
| 929 | + |
|
| 930 | + $targetUser = $this->userManager->get($userId); |
|
| 931 | + if($targetUser === null) { |
|
| 932 | + throw new OCSException('', \OCP\API::RESPOND_NOT_FOUND); |
|
| 933 | + } |
|
| 934 | + |
|
| 935 | + // Check if admin / subadmin |
|
| 936 | + $subAdminManager = $this->groupManager->getSubAdmin(); |
|
| 937 | + if(!$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser) |
|
| 938 | + && !$this->groupManager->isAdmin($currentLoggedInUser->getUID())) { |
|
| 939 | + // No rights |
|
| 940 | + throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
| 941 | + } |
|
| 942 | + |
|
| 943 | + $email = $targetUser->getEMailAddress(); |
|
| 944 | + if ($email === '' || $email === null) { |
|
| 945 | + throw new OCSException('Email address not available', 101); |
|
| 946 | + } |
|
| 947 | + $username = $targetUser->getUID(); |
|
| 948 | + $lang = $this->config->getUserValue($username, 'core', 'lang', 'en'); |
|
| 949 | + if (!$this->l10nFactory->languageExists('settings', $lang)) { |
|
| 950 | + $lang = 'en'; |
|
| 951 | + } |
|
| 952 | + |
|
| 953 | + $l10n = $this->l10nFactory->get('settings', $lang); |
|
| 954 | + |
|
| 955 | + try { |
|
| 956 | + $this->newUserMailHelper->setL10N($l10n); |
|
| 957 | + $emailTemplate = $this->newUserMailHelper->generateTemplate($targetUser, false); |
|
| 958 | + $this->newUserMailHelper->sendMail($targetUser, $emailTemplate); |
|
| 959 | + } catch(\Exception $e) { |
|
| 960 | + $this->logger->logException($e, [ |
|
| 961 | + 'message' => "Can't send new user mail to $email", |
|
| 962 | + 'level' => \OCP\Util::ERROR, |
|
| 963 | + 'app' => 'settings', |
|
| 964 | + ]); |
|
| 965 | + throw new OCSException('Sending email failed', 102); |
|
| 966 | + } |
|
| 967 | + |
|
| 968 | + return new DataResponse(); |
|
| 969 | + } |
|
| 970 | 970 | } |
@@ -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) 2016, ownCloud, Inc. |
| 5 | 5 | * |
@@ -137,7 +137,7 @@ discard block |
||
| 137 | 137 | // Admin? Or SubAdmin? |
| 138 | 138 | $uid = $user->getUID(); |
| 139 | 139 | $subAdminManager = $this->groupManager->getSubAdmin(); |
| 140 | - if($this->groupManager->isAdmin($uid)){ |
|
| 140 | + if ($this->groupManager->isAdmin($uid)) { |
|
| 141 | 141 | $users = $this->userManager->search($search, $limit, $offset); |
| 142 | 142 | } else if ($subAdminManager->isSubAdmin($user)) { |
| 143 | 143 | $subAdminOfGroups = $subAdminManager->getSubAdminsGroups($user); |
@@ -170,7 +170,7 @@ discard block |
||
| 170 | 170 | // Admin? Or SubAdmin? |
| 171 | 171 | $uid = $user->getUID(); |
| 172 | 172 | $subAdminManager = $this->groupManager->getSubAdmin(); |
| 173 | - if($this->groupManager->isAdmin($uid)){ |
|
| 173 | + if ($this->groupManager->isAdmin($uid)) { |
|
| 174 | 174 | $users = $this->userManager->search($search, $limit, $offset); |
| 175 | 175 | } else if ($subAdminManager->isSubAdmin($user)) { |
| 176 | 176 | $subAdminOfGroups = $subAdminManager->getSubAdminsGroups($user); |
@@ -189,7 +189,7 @@ discard block |
||
| 189 | 189 | foreach ($users as $key => $userId) { |
| 190 | 190 | $userData = $this->getUserData($userId); |
| 191 | 191 | // Do not insert empty entry |
| 192 | - if(!empty($userData)) { |
|
| 192 | + if (!empty($userData)) { |
|
| 193 | 193 | $usersDetails[$userId] = $userData; |
| 194 | 194 | } |
| 195 | 195 | } |
@@ -210,27 +210,27 @@ discard block |
||
| 210 | 210 | * @return DataResponse |
| 211 | 211 | * @throws OCSException |
| 212 | 212 | */ |
| 213 | - public function addUser(string $userid, string $password = '', string $email='', array $groups = []): DataResponse { |
|
| 213 | + public function addUser(string $userid, string $password = '', string $email = '', array $groups = []): DataResponse { |
|
| 214 | 214 | $user = $this->userSession->getUser(); |
| 215 | 215 | $isAdmin = $this->groupManager->isAdmin($user->getUID()); |
| 216 | 216 | $subAdminManager = $this->groupManager->getSubAdmin(); |
| 217 | 217 | |
| 218 | - if($this->userManager->userExists($userid)) { |
|
| 218 | + if ($this->userManager->userExists($userid)) { |
|
| 219 | 219 | $this->logger->error('Failed addUser attempt: User already exists.', ['app' => 'ocs_api']); |
| 220 | 220 | throw new OCSException('User already exists', 102); |
| 221 | 221 | } |
| 222 | 222 | |
| 223 | - if($groups !== []) { |
|
| 223 | + if ($groups !== []) { |
|
| 224 | 224 | foreach ($groups as $group) { |
| 225 | - if(!$this->groupManager->groupExists($group)) { |
|
| 225 | + if (!$this->groupManager->groupExists($group)) { |
|
| 226 | 226 | throw new OCSException('group '.$group.' does not exist', 104); |
| 227 | 227 | } |
| 228 | - if(!$isAdmin && !$subAdminManager->isSubAdminofGroup($user, $this->groupManager->get($group))) { |
|
| 229 | - throw new OCSException('insufficient privileges for group '. $group, 105); |
|
| 228 | + if (!$isAdmin && !$subAdminManager->isSubAdminofGroup($user, $this->groupManager->get($group))) { |
|
| 229 | + throw new OCSException('insufficient privileges for group '.$group, 105); |
|
| 230 | 230 | } |
| 231 | 231 | } |
| 232 | 232 | } else { |
| 233 | - if(!$isAdmin) { |
|
| 233 | + if (!$isAdmin) { |
|
| 234 | 234 | throw new OCSException('no group specified (required for subadmins)', 106); |
| 235 | 235 | } |
| 236 | 236 | } |
@@ -249,11 +249,11 @@ discard block |
||
| 249 | 249 | |
| 250 | 250 | try { |
| 251 | 251 | $newUser = $this->userManager->createUser($userid, $password); |
| 252 | - $this->logger->info('Successful addUser call with userid: ' . $userid, ['app' => 'ocs_api']); |
|
| 252 | + $this->logger->info('Successful addUser call with userid: '.$userid, ['app' => 'ocs_api']); |
|
| 253 | 253 | |
| 254 | 254 | foreach ($groups as $group) { |
| 255 | 255 | $this->groupManager->get($group)->addUser($newUser); |
| 256 | - $this->logger->info('Added userid ' . $userid . ' to group ' . $group, ['app' => 'ocs_api']); |
|
| 256 | + $this->logger->info('Added userid '.$userid.' to group '.$group, ['app' => 'ocs_api']); |
|
| 257 | 257 | } |
| 258 | 258 | |
| 259 | 259 | // Send new user mail only if a mail is set |
@@ -274,7 +274,7 @@ discard block |
||
| 274 | 274 | |
| 275 | 275 | return new DataResponse(); |
| 276 | 276 | |
| 277 | - } catch (HintException $e ) { |
|
| 277 | + } catch (HintException $e) { |
|
| 278 | 278 | $this->logger->logException($e, [ |
| 279 | 279 | 'message' => 'Failed addUser attempt with hint exception.', |
| 280 | 280 | 'level' => \OCP\Util::WARN, |
@@ -304,7 +304,7 @@ discard block |
||
| 304 | 304 | public function getUser(string $userId): DataResponse { |
| 305 | 305 | $data = $this->getUserData($userId); |
| 306 | 306 | // getUserData returns empty array if not enough permissions |
| 307 | - if(empty($data)) { |
|
| 307 | + if (empty($data)) { |
|
| 308 | 308 | throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
| 309 | 309 | } |
| 310 | 310 | return new DataResponse($data); |
@@ -322,7 +322,7 @@ discard block |
||
| 322 | 322 | public function getCurrentUser(): DataResponse { |
| 323 | 323 | $user = $this->userSession->getUser(); |
| 324 | 324 | if ($user) { |
| 325 | - $data = $this->getUserData($user->getUID()); |
|
| 325 | + $data = $this->getUserData($user->getUID()); |
|
| 326 | 326 | // rename "displayname" to "display-name" only for this call to keep |
| 327 | 327 | // the API stable. |
| 328 | 328 | $data['display-name'] = $data['displayname']; |
@@ -348,17 +348,17 @@ discard block |
||
| 348 | 348 | |
| 349 | 349 | // Check if the target user exists |
| 350 | 350 | $targetUserObject = $this->userManager->get($userId); |
| 351 | - if($targetUserObject === null) { |
|
| 351 | + if ($targetUserObject === null) { |
|
| 352 | 352 | throw new OCSException('The requested user could not be found', \OCP\API::RESPOND_NOT_FOUND); |
| 353 | 353 | } |
| 354 | 354 | |
| 355 | 355 | // Should be at least Admin Or SubAdmin! |
| 356 | - if( $this->groupManager->isAdmin($currentLoggedInUser->getUID()) |
|
| 356 | + if ($this->groupManager->isAdmin($currentLoggedInUser->getUID()) |
|
| 357 | 357 | || $this->groupManager->getSubAdmin()->isUserAccessible($currentLoggedInUser, $targetUserObject)) { |
| 358 | 358 | $data['enabled'] = $this->config->getUserValue($targetUserObject->getUID(), 'core', 'enabled', 'true'); |
| 359 | 359 | } else { |
| 360 | 360 | // Check they are looking up themselves |
| 361 | - if($currentLoggedInUser->getUID() !== $targetUserObject->getUID()) { |
|
| 361 | + if ($currentLoggedInUser->getUID() !== $targetUserObject->getUID()) { |
|
| 362 | 362 | return $data; |
| 363 | 363 | } |
| 364 | 364 | } |
@@ -434,12 +434,12 @@ discard block |
||
| 434 | 434 | $currentLoggedInUser = $this->userSession->getUser(); |
| 435 | 435 | |
| 436 | 436 | $targetUser = $this->userManager->get($userId); |
| 437 | - if($targetUser === null) { |
|
| 437 | + if ($targetUser === null) { |
|
| 438 | 438 | throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
| 439 | 439 | } |
| 440 | 440 | |
| 441 | 441 | $permittedFields = []; |
| 442 | - if($targetUser->getUID() === $currentLoggedInUser->getUID()) { |
|
| 442 | + if ($targetUser->getUID() === $currentLoggedInUser->getUID()) { |
|
| 443 | 443 | // Editing self (display, email) |
| 444 | 444 | if ($this->config->getSystemValue('allow_user_to_change_display_name', true) !== false) { |
| 445 | 445 | $permittedFields[] = 'display'; |
@@ -465,13 +465,13 @@ discard block |
||
| 465 | 465 | } |
| 466 | 466 | |
| 467 | 467 | // If admin they can edit their own quota |
| 468 | - if($this->groupManager->isAdmin($currentLoggedInUser->getUID())) { |
|
| 468 | + if ($this->groupManager->isAdmin($currentLoggedInUser->getUID())) { |
|
| 469 | 469 | $permittedFields[] = 'quota'; |
| 470 | 470 | } |
| 471 | 471 | } else { |
| 472 | 472 | // Check if admin / subadmin |
| 473 | 473 | $subAdminManager = $this->groupManager->getSubAdmin(); |
| 474 | - if($subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser) |
|
| 474 | + if ($subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser) |
|
| 475 | 475 | || $this->groupManager->isAdmin($currentLoggedInUser->getUID())) { |
| 476 | 476 | // They have permissions over the user |
| 477 | 477 | $permittedFields[] = 'display'; |
@@ -490,18 +490,18 @@ discard block |
||
| 490 | 490 | } |
| 491 | 491 | } |
| 492 | 492 | // Check if permitted to edit this field |
| 493 | - if(!in_array($key, $permittedFields)) { |
|
| 493 | + if (!in_array($key, $permittedFields)) { |
|
| 494 | 494 | throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
| 495 | 495 | } |
| 496 | 496 | // Process the edit |
| 497 | - switch($key) { |
|
| 497 | + switch ($key) { |
|
| 498 | 498 | case 'display': |
| 499 | 499 | case AccountManager::PROPERTY_DISPLAYNAME: |
| 500 | 500 | $targetUser->setDisplayName($value); |
| 501 | 501 | break; |
| 502 | 502 | case 'quota': |
| 503 | 503 | $quota = $value; |
| 504 | - if($quota !== 'none' && $quota !== 'default') { |
|
| 504 | + if ($quota !== 'none' && $quota !== 'default') { |
|
| 505 | 505 | if (is_numeric($quota)) { |
| 506 | 506 | $quota = (float) $quota; |
| 507 | 507 | } else { |
@@ -510,9 +510,9 @@ discard block |
||
| 510 | 510 | if ($quota === false) { |
| 511 | 511 | throw new OCSException('Invalid quota value '.$value, 103); |
| 512 | 512 | } |
| 513 | - if($quota === 0) { |
|
| 513 | + if ($quota === 0) { |
|
| 514 | 514 | $quota = 'default'; |
| 515 | - }else if($quota === -1) { |
|
| 515 | + } else if ($quota === -1) { |
|
| 516 | 516 | $quota = 'none'; |
| 517 | 517 | } else { |
| 518 | 518 | $quota = \OCP\Util::humanFileSize($quota); |
@@ -531,7 +531,7 @@ discard block |
||
| 531 | 531 | $this->config->setUserValue($targetUser->getUID(), 'core', 'lang', $value); |
| 532 | 532 | break; |
| 533 | 533 | case AccountManager::PROPERTY_EMAIL: |
| 534 | - if(filter_var($value, FILTER_VALIDATE_EMAIL) || $value === '') { |
|
| 534 | + if (filter_var($value, FILTER_VALIDATE_EMAIL) || $value === '') { |
|
| 535 | 535 | $targetUser->setEMailAddress($value); |
| 536 | 536 | } else { |
| 537 | 537 | throw new OCSException('', 102); |
@@ -566,18 +566,18 @@ discard block |
||
| 566 | 566 | |
| 567 | 567 | $targetUser = $this->userManager->get($userId); |
| 568 | 568 | |
| 569 | - if($targetUser === null || $targetUser->getUID() === $currentLoggedInUser->getUID()) { |
|
| 569 | + if ($targetUser === null || $targetUser->getUID() === $currentLoggedInUser->getUID()) { |
|
| 570 | 570 | throw new OCSException('', 101); |
| 571 | 571 | } |
| 572 | 572 | |
| 573 | 573 | // If not permitted |
| 574 | 574 | $subAdminManager = $this->groupManager->getSubAdmin(); |
| 575 | - if(!$this->groupManager->isAdmin($currentLoggedInUser->getUID()) && !$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)) { |
|
| 575 | + if (!$this->groupManager->isAdmin($currentLoggedInUser->getUID()) && !$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)) { |
|
| 576 | 576 | throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
| 577 | 577 | } |
| 578 | 578 | |
| 579 | 579 | // Go ahead with the delete |
| 580 | - if($targetUser->delete()) { |
|
| 580 | + if ($targetUser->delete()) { |
|
| 581 | 581 | return new DataResponse(); |
| 582 | 582 | } else { |
| 583 | 583 | throw new OCSException('', 101); |
@@ -620,13 +620,13 @@ discard block |
||
| 620 | 620 | $currentLoggedInUser = $this->userSession->getUser(); |
| 621 | 621 | |
| 622 | 622 | $targetUser = $this->userManager->get($userId); |
| 623 | - if($targetUser === null || $targetUser->getUID() === $currentLoggedInUser->getUID()) { |
|
| 623 | + if ($targetUser === null || $targetUser->getUID() === $currentLoggedInUser->getUID()) { |
|
| 624 | 624 | throw new OCSException('', 101); |
| 625 | 625 | } |
| 626 | 626 | |
| 627 | 627 | // If not permitted |
| 628 | 628 | $subAdminManager = $this->groupManager->getSubAdmin(); |
| 629 | - if(!$this->groupManager->isAdmin($currentLoggedInUser->getUID()) && !$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)) { |
|
| 629 | + if (!$this->groupManager->isAdmin($currentLoggedInUser->getUID()) && !$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)) { |
|
| 630 | 630 | throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
| 631 | 631 | } |
| 632 | 632 | |
@@ -647,11 +647,11 @@ discard block |
||
| 647 | 647 | $loggedInUser = $this->userSession->getUser(); |
| 648 | 648 | |
| 649 | 649 | $targetUser = $this->userManager->get($userId); |
| 650 | - if($targetUser === null) { |
|
| 650 | + if ($targetUser === null) { |
|
| 651 | 651 | throw new OCSException('', \OCP\API::RESPOND_NOT_FOUND); |
| 652 | 652 | } |
| 653 | 653 | |
| 654 | - if($targetUser->getUID() === $loggedInUser->getUID() || $this->groupManager->isAdmin($loggedInUser->getUID())) { |
|
| 654 | + if ($targetUser->getUID() === $loggedInUser->getUID() || $this->groupManager->isAdmin($loggedInUser->getUID())) { |
|
| 655 | 655 | // Self lookup or admin lookup |
| 656 | 656 | return new DataResponse([ |
| 657 | 657 | 'groups' => $this->groupManager->getUserGroupIds($targetUser) |
@@ -660,7 +660,7 @@ discard block |
||
| 660 | 660 | $subAdminManager = $this->groupManager->getSubAdmin(); |
| 661 | 661 | |
| 662 | 662 | // Looking up someone else |
| 663 | - if($subAdminManager->isUserAccessible($loggedInUser, $targetUser)) { |
|
| 663 | + if ($subAdminManager->isUserAccessible($loggedInUser, $targetUser)) { |
|
| 664 | 664 | // Return the group that the method caller is subadmin of for the user in question |
| 665 | 665 | /** @var IGroup[] $getSubAdminsGroups */ |
| 666 | 666 | $getSubAdminsGroups = $subAdminManager->getSubAdminsGroups($loggedInUser); |
@@ -690,16 +690,16 @@ discard block |
||
| 690 | 690 | * @throws OCSException |
| 691 | 691 | */ |
| 692 | 692 | public function addToGroup(string $userId, string $groupid = ''): DataResponse { |
| 693 | - if($groupid === '') { |
|
| 693 | + if ($groupid === '') { |
|
| 694 | 694 | throw new OCSException('', 101); |
| 695 | 695 | } |
| 696 | 696 | |
| 697 | 697 | $group = $this->groupManager->get($groupid); |
| 698 | 698 | $targetUser = $this->userManager->get($userId); |
| 699 | - if($group === null) { |
|
| 699 | + if ($group === null) { |
|
| 700 | 700 | throw new OCSException('', 102); |
| 701 | 701 | } |
| 702 | - if($targetUser === null) { |
|
| 702 | + if ($targetUser === null) { |
|
| 703 | 703 | throw new OCSException('', 103); |
| 704 | 704 | } |
| 705 | 705 | |
@@ -727,17 +727,17 @@ discard block |
||
| 727 | 727 | public function removeFromGroup(string $userId, string $groupid): DataResponse { |
| 728 | 728 | $loggedInUser = $this->userSession->getUser(); |
| 729 | 729 | |
| 730 | - if($groupid === null || trim($groupid) === '') { |
|
| 730 | + if ($groupid === null || trim($groupid) === '') { |
|
| 731 | 731 | throw new OCSException('', 101); |
| 732 | 732 | } |
| 733 | 733 | |
| 734 | 734 | $group = $this->groupManager->get($groupid); |
| 735 | - if($group === null) { |
|
| 735 | + if ($group === null) { |
|
| 736 | 736 | throw new OCSException('', 102); |
| 737 | 737 | } |
| 738 | 738 | |
| 739 | 739 | $targetUser = $this->userManager->get($userId); |
| 740 | - if($targetUser === null) { |
|
| 740 | + if ($targetUser === null) { |
|
| 741 | 741 | throw new OCSException('', 103); |
| 742 | 742 | } |
| 743 | 743 | |
@@ -761,7 +761,7 @@ discard block |
||
| 761 | 761 | } else if (!$this->groupManager->isAdmin($loggedInUser->getUID())) { |
| 762 | 762 | /** @var IGroup[] $subAdminGroups */ |
| 763 | 763 | $subAdminGroups = $subAdminManager->getSubAdminsGroups($loggedInUser); |
| 764 | - $subAdminGroups = array_map(function (IGroup $subAdminGroup) { |
|
| 764 | + $subAdminGroups = array_map(function(IGroup $subAdminGroup) { |
|
| 765 | 765 | return $subAdminGroup->getGID(); |
| 766 | 766 | }, $subAdminGroups); |
| 767 | 767 | $userGroups = $this->groupManager->getUserGroupIds($targetUser); |
@@ -793,15 +793,15 @@ discard block |
||
| 793 | 793 | $user = $this->userManager->get($userId); |
| 794 | 794 | |
| 795 | 795 | // Check if the user exists |
| 796 | - if($user === null) { |
|
| 796 | + if ($user === null) { |
|
| 797 | 797 | throw new OCSException('User does not exist', 101); |
| 798 | 798 | } |
| 799 | 799 | // Check if group exists |
| 800 | - if($group === null) { |
|
| 801 | - throw new OCSException('Group does not exist', 102); |
|
| 800 | + if ($group === null) { |
|
| 801 | + throw new OCSException('Group does not exist', 102); |
|
| 802 | 802 | } |
| 803 | 803 | // Check if trying to make subadmin of admin group |
| 804 | - if($group->getGID() === 'admin') { |
|
| 804 | + if ($group->getGID() === 'admin') { |
|
| 805 | 805 | throw new OCSException('Cannot create subadmins for admin group', 103); |
| 806 | 806 | } |
| 807 | 807 | |
@@ -812,7 +812,7 @@ discard block |
||
| 812 | 812 | return new DataResponse(); |
| 813 | 813 | } |
| 814 | 814 | // Go |
| 815 | - if($subAdminManager->createSubAdmin($user, $group)) { |
|
| 815 | + if ($subAdminManager->createSubAdmin($user, $group)) { |
|
| 816 | 816 | return new DataResponse(); |
| 817 | 817 | } else { |
| 818 | 818 | throw new OCSException('Unknown error occurred', 103); |
@@ -835,20 +835,20 @@ discard block |
||
| 835 | 835 | $subAdminManager = $this->groupManager->getSubAdmin(); |
| 836 | 836 | |
| 837 | 837 | // Check if the user exists |
| 838 | - if($user === null) { |
|
| 838 | + if ($user === null) { |
|
| 839 | 839 | throw new OCSException('User does not exist', 101); |
| 840 | 840 | } |
| 841 | 841 | // Check if the group exists |
| 842 | - if($group === null) { |
|
| 842 | + if ($group === null) { |
|
| 843 | 843 | throw new OCSException('Group does not exist', 101); |
| 844 | 844 | } |
| 845 | 845 | // Check if they are a subadmin of this said group |
| 846 | - if(!$subAdminManager->isSubAdminOfGroup($user, $group)) { |
|
| 846 | + if (!$subAdminManager->isSubAdminOfGroup($user, $group)) { |
|
| 847 | 847 | throw new OCSException('User is not a subadmin of this group', 102); |
| 848 | 848 | } |
| 849 | 849 | |
| 850 | 850 | // Go |
| 851 | - if($subAdminManager->deleteSubAdmin($user, $group)) { |
|
| 851 | + if ($subAdminManager->deleteSubAdmin($user, $group)) { |
|
| 852 | 852 | return new DataResponse(); |
| 853 | 853 | } else { |
| 854 | 854 | throw new OCSException('Unknown error occurred', 103); |
@@ -865,7 +865,7 @@ discard block |
||
| 865 | 865 | protected function getUserSubAdminGroupsData(string $userId): array { |
| 866 | 866 | $user = $this->userManager->get($userId); |
| 867 | 867 | // Check if the user exists |
| 868 | - if($user === null) { |
|
| 868 | + if ($user === null) { |
|
| 869 | 869 | throw new OCSException('User does not exist', 101); |
| 870 | 870 | } |
| 871 | 871 | |
@@ -928,13 +928,13 @@ discard block |
||
| 928 | 928 | $currentLoggedInUser = $this->userSession->getUser(); |
| 929 | 929 | |
| 930 | 930 | $targetUser = $this->userManager->get($userId); |
| 931 | - if($targetUser === null) { |
|
| 931 | + if ($targetUser === null) { |
|
| 932 | 932 | throw new OCSException('', \OCP\API::RESPOND_NOT_FOUND); |
| 933 | 933 | } |
| 934 | 934 | |
| 935 | 935 | // Check if admin / subadmin |
| 936 | 936 | $subAdminManager = $this->groupManager->getSubAdmin(); |
| 937 | - if(!$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser) |
|
| 937 | + if (!$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser) |
|
| 938 | 938 | && !$this->groupManager->isAdmin($currentLoggedInUser->getUID())) { |
| 939 | 939 | // No rights |
| 940 | 940 | throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
@@ -956,7 +956,7 @@ discard block |
||
| 956 | 956 | $this->newUserMailHelper->setL10N($l10n); |
| 957 | 957 | $emailTemplate = $this->newUserMailHelper->generateTemplate($targetUser, false); |
| 958 | 958 | $this->newUserMailHelper->sendMail($targetUser, $emailTemplate); |
| 959 | - } catch(\Exception $e) { |
|
| 959 | + } catch (\Exception $e) { |
|
| 960 | 960 | $this->logger->logException($e, [ |
| 961 | 961 | 'message' => "Can't send new user mail to $email", |
| 962 | 962 | 'level' => \OCP\Util::ERROR, |
@@ -5,7 +5,7 @@ |
||
| 5 | 5 | use OCP\AppFramework\Http; |
| 6 | 6 | |
| 7 | 7 | class NotSubAdminException extends \Exception { |
| 8 | - public function __construct() { |
|
| 9 | - parent::__construct('Logged in user must be at least a sub admin', Http::STATUS_FORBIDDEN); |
|
| 10 | - } |
|
| 8 | + public function __construct() { |
|
| 9 | + parent::__construct('Logged in user must be at least a sub admin', Http::STATUS_FORBIDDEN); |
|
| 10 | + } |
|
| 11 | 11 | } |
| 12 | 12 | \ No newline at end of file |
@@ -1,6 +1,5 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - |
|
| 4 | 3 | * |
| 5 | 4 | * @author Bjoern Schiessle <[email protected]> |
| 6 | 5 | * @author Jan-Christoph Borchardt <[email protected]> |