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