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