Passed
Push — master ( 6b6536...139055 )
by Roeland
15:14 queued 05:29
created
apps/provisioning_api/lib/Controller/UsersController.php 1 patch
Indentation   +849 added lines, -849 removed lines patch added patch discarded remove patch
@@ -54,853 +54,853 @@
 block discarded – undo
54 54
 
55 55
 class UsersController extends AUserData {
56 56
 
57
-	/** @var IAppManager */
58
-	private $appManager;
59
-	/** @var ILogger */
60
-	private $logger;
61
-	/** @var IFactory */
62
-	private $l10nFactory;
63
-	/** @var NewUserMailHelper */
64
-	private $newUserMailHelper;
65
-	/** @var FederatedFileSharingFactory */
66
-	private $federatedFileSharingFactory;
67
-	/** @var ISecureRandom */
68
-	private $secureRandom;
69
-
70
-	/**
71
-	 * @param string $appName
72
-	 * @param IRequest $request
73
-	 * @param IUserManager $userManager
74
-	 * @param IConfig $config
75
-	 * @param IAppManager $appManager
76
-	 * @param IGroupManager $groupManager
77
-	 * @param IUserSession $userSession
78
-	 * @param AccountManager $accountManager
79
-	 * @param ILogger $logger
80
-	 * @param IFactory $l10nFactory
81
-	 * @param NewUserMailHelper $newUserMailHelper
82
-	 * @param FederatedFileSharingFactory $federatedFileSharingFactory
83
-	 * @param ISecureRandom $secureRandom
84
-	 */
85
-	public function __construct(string $appName,
86
-								IRequest $request,
87
-								IUserManager $userManager,
88
-								IConfig $config,
89
-								IAppManager $appManager,
90
-								IGroupManager $groupManager,
91
-								IUserSession $userSession,
92
-								AccountManager $accountManager,
93
-								ILogger $logger,
94
-								IFactory $l10nFactory,
95
-								NewUserMailHelper $newUserMailHelper,
96
-								FederatedFileSharingFactory $federatedFileSharingFactory,
97
-								ISecureRandom $secureRandom) {
98
-		parent::__construct($appName,
99
-							$request,
100
-							$userManager,
101
-							$config,
102
-							$groupManager,
103
-							$userSession,
104
-							$accountManager);
105
-
106
-		$this->appManager = $appManager;
107
-		$this->logger = $logger;
108
-		$this->l10nFactory = $l10nFactory;
109
-		$this->newUserMailHelper = $newUserMailHelper;
110
-		$this->federatedFileSharingFactory = $federatedFileSharingFactory;
111
-		$this->secureRandom = $secureRandom;
112
-	}
113
-
114
-	/**
115
-	 * @NoAdminRequired
116
-	 *
117
-	 * returns a list of users
118
-	 *
119
-	 * @param string $search
120
-	 * @param int $limit
121
-	 * @param int $offset
122
-	 * @return DataResponse
123
-	 */
124
-	public function getUsers(string $search = '', $limit = null, $offset = 0): DataResponse {
125
-		$user = $this->userSession->getUser();
126
-		$users = [];
127
-
128
-		// Admin? Or SubAdmin?
129
-		$uid = $user->getUID();
130
-		$subAdminManager = $this->groupManager->getSubAdmin();
131
-		if ($this->groupManager->isAdmin($uid)){
132
-			$users = $this->userManager->search($search, $limit, $offset);
133
-		} else if ($subAdminManager->isSubAdmin($user)) {
134
-			$subAdminOfGroups = $subAdminManager->getSubAdminsGroups($user);
135
-			foreach ($subAdminOfGroups as $key => $group) {
136
-				$subAdminOfGroups[$key] = $group->getGID();
137
-			}
138
-
139
-			$users = [];
140
-			foreach ($subAdminOfGroups as $group) {
141
-				$users = array_merge($users, $this->groupManager->displayNamesInGroup($group, $search, $limit, $offset));
142
-			}
143
-		}
144
-
145
-		$users = array_keys($users);
146
-
147
-		return new DataResponse([
148
-			'users' => $users
149
-		]);
150
-	}
151
-
152
-	/**
153
-	 * @NoAdminRequired
154
-	 *
155
-	 * returns a list of users and their data
156
-	 */
157
-	public function getUsersDetails(string $search = '', $limit = null, $offset = 0): DataResponse {
158
-		$currentUser = $this->userSession->getUser();
159
-		$users = [];
160
-
161
-		// Admin? Or SubAdmin?
162
-		$uid = $currentUser->getUID();
163
-		$subAdminManager = $this->groupManager->getSubAdmin();
164
-		if ($this->groupManager->isAdmin($uid)){
165
-			$users = $this->userManager->search($search, $limit, $offset);
166
-			$users = array_keys($users);
167
-		} else if ($subAdminManager->isSubAdmin($currentUser)) {
168
-			$subAdminOfGroups = $subAdminManager->getSubAdminsGroups($currentUser);
169
-			foreach ($subAdminOfGroups as $key => $group) {
170
-				$subAdminOfGroups[$key] = $group->getGID();
171
-			}
172
-
173
-			$users = [];
174
-			foreach ($subAdminOfGroups as $group) {
175
-				$users[] = array_keys($this->groupManager->displayNamesInGroup($group, $search, $limit, $offset));
176
-			}
177
-			$users = array_merge(...$users);
178
-		}
179
-
180
-		$usersDetails = [];
181
-		foreach ($users as $userId) {
182
-			$userId = (string) $userId;
183
-			$userData = $this->getUserData($userId);
184
-			// Do not insert empty entry
185
-			if (!empty($userData)) {
186
-				$usersDetails[$userId] = $userData;
187
-			} else {
188
-				// Logged user does not have permissions to see this user
189
-				// only showing its id
190
-				$usersDetails[$userId] = ['id' => $userId];
191
-			}
192
-		}
193
-
194
-		return new DataResponse([
195
-			'users' => $usersDetails
196
-		]);
197
-	}
198
-
199
-	/**
200
-	 * @PasswordConfirmationRequired
201
-	 * @NoAdminRequired
202
-	 *
203
-	 * @param string $userid
204
-	 * @param string $password
205
-	 * @param string $displayName
206
-	 * @param string $email
207
-	 * @param array $groups
208
-	 * @param array $subadmin
209
-	 * @param string $quota
210
-	 * @param string $language
211
-	 * @return DataResponse
212
-	 * @throws OCSException
213
-	 */
214
-	public function addUser(string $userid,
215
-							string $password = '',
216
-							string $displayName = '',
217
-							string $email = '',
218
-							array $groups = [],
219
-							array $subadmin = [],
220
-							string $quota = '',
221
-							string $language = ''): DataResponse {
222
-		$user = $this->userSession->getUser();
223
-		$isAdmin = $this->groupManager->isAdmin($user->getUID());
224
-		$subAdminManager = $this->groupManager->getSubAdmin();
225
-
226
-		if ($this->userManager->userExists($userid)) {
227
-			$this->logger->error('Failed addUser attempt: User already exists.', ['app' => 'ocs_api']);
228
-			throw new OCSException('User already exists', 102);
229
-		}
230
-
231
-		if ($groups !== []) {
232
-			foreach ($groups as $group) {
233
-				if (!$this->groupManager->groupExists($group)) {
234
-					throw new OCSException('group '.$group.' does not exist', 104);
235
-				}
236
-				if (!$isAdmin && !$subAdminManager->isSubAdminOfGroup($user, $this->groupManager->get($group))) {
237
-					throw new OCSException('insufficient privileges for group '. $group, 105);
238
-				}
239
-			}
240
-		} else {
241
-			if (!$isAdmin) {
242
-				throw new OCSException('no group specified (required for subadmins)', 106);
243
-			}
244
-		}
245
-
246
-		$subadminGroups = [];
247
-		if ($subadmin !== []) {
248
-			foreach ($subadmin as $groupid) {
249
-				$group = $this->groupManager->get($groupid);
250
-				// Check if group exists
251
-				if ($group === null) {
252
-					throw new OCSException('Subadmin group does not exist',  102);
253
-				}
254
-				// Check if trying to make subadmin of admin group
255
-				if ($group->getGID() === 'admin') {
256
-					throw new OCSException('Cannot create subadmins for admin group', 103);
257
-				}
258
-				// Check if has permission to promote subadmins
259
-				if (!$subAdminManager->isSubAdminOfGroup($user, $group) && !$isAdmin) {
260
-					throw new OCSForbiddenException('No permissions to promote subadmins');
261
-				}
262
-				$subadminGroups[] = $group;
263
-			}
264
-		}
265
-
266
-		$generatePasswordResetToken = false;
267
-		if ($password === '') {
268
-			if ($email === '') {
269
-				throw new OCSException('To send a password link to the user an email address is required.', 108);
270
-			}
271
-
272
-			$password = $this->secureRandom->generate(10);
273
-			// Make sure we pass the password_policy
274
-			$password .= $this->secureRandom->generate(2, '$!.,;:-~+*[]{}()');
275
-			$generatePasswordResetToken = true;
276
-		}
277
-
278
-		try {
279
-			$newUser = $this->userManager->createUser($userid, $password);
280
-			$this->logger->info('Successful addUser call with userid: ' . $userid, ['app' => 'ocs_api']);
281
-
282
-			foreach ($groups as $group) {
283
-				$this->groupManager->get($group)->addUser($newUser);
284
-				$this->logger->info('Added userid ' . $userid . ' to group ' . $group, ['app' => 'ocs_api']);
285
-			}
286
-			foreach ($subadminGroups as $group) {
287
-				$subAdminManager->createSubAdmin($newUser, $group);
288
-			}
289
-
290
-			if ($displayName !== '') {
291
-				$this->editUser($userid, 'display', $displayName);
292
-			}
293
-
294
-			if ($quota !== '') {
295
-				$this->editUser($userid, 'quota', $quota);
296
-			}
297
-
298
-			if ($language !== '') {
299
-				$this->editUser($userid, 'language', $language);
300
-			}
301
-
302
-			// Send new user mail only if a mail is set
303
-			if ($email !== '') {
304
-				$newUser->setEMailAddress($email);
305
-				try {
306
-					$emailTemplate = $this->newUserMailHelper->generateTemplate($newUser, $generatePasswordResetToken);
307
-					$this->newUserMailHelper->sendMail($newUser, $emailTemplate);
308
-				} catch (\Exception $e) {
309
-					$this->logger->logException($e, [
310
-						'message' => "Can't send new user mail to $email",
311
-						'level' => ILogger::ERROR,
312
-						'app' => 'ocs_api',
313
-					]);
314
-					throw new OCSException('Unable to send the invitation mail', 109);
315
-				}
316
-			}
317
-
318
-			return new DataResponse();
319
-
320
-		} catch (HintException $e ) {
321
-			$this->logger->logException($e, [
322
-				'message' => 'Failed addUser attempt with hint exception.',
323
-				'level' => ILogger::WARN,
324
-				'app' => 'ocs_api',
325
-			]);
326
-			throw new OCSException($e->getHint(), 107);
327
-		} catch (\Exception $e) {
328
-			$this->logger->logException($e, [
329
-				'message' => 'Failed addUser attempt with exception.',
330
-				'level' => ILogger::ERROR,
331
-				'app' => 'ocs_api',
332
-			]);
333
-			throw new OCSException('Bad request', 101);
334
-		}
335
-	}
336
-
337
-	/**
338
-	 * @NoAdminRequired
339
-	 * @NoSubAdminRequired
340
-	 *
341
-	 * gets user info
342
-	 *
343
-	 * @param string $userId
344
-	 * @return DataResponse
345
-	 * @throws OCSException
346
-	 */
347
-	public function getUser(string $userId): DataResponse {
348
-		$data = $this->getUserData($userId);
349
-		// getUserData returns empty array if not enough permissions
350
-		if (empty($data)) {
351
-			throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED);
352
-		}
353
-		return new DataResponse($data);
354
-	}
355
-
356
-	/**
357
-	 * @NoAdminRequired
358
-	 * @NoSubAdminRequired
359
-	 *
360
-	 * gets user info from the currently logged in user
361
-	 *
362
-	 * @return DataResponse
363
-	 * @throws OCSException
364
-	 */
365
-	public function getCurrentUser(): DataResponse {
366
-		$user = $this->userSession->getUser();
367
-		if ($user) {
368
-			$data =  $this->getUserData($user->getUID());
369
-			// rename "displayname" to "display-name" only for this call to keep
370
-			// the API stable.
371
-			$data['display-name'] = $data['displayname'];
372
-			unset($data['displayname']);
373
-			return new DataResponse($data);
374
-
375
-		}
376
-
377
-		throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED);
378
-	}
379
-
380
-	/**
381
-	 * @NoAdminRequired
382
-	 * @NoSubAdminRequired
383
-	 */
384
-	public function getEditableFields(): DataResponse {
385
-		$permittedFields = [];
386
-
387
-		// Editing self (display, email)
388
-		if ($this->config->getSystemValue('allow_user_to_change_display_name', true) !== false) {
389
-			$permittedFields[] = AccountManager::PROPERTY_DISPLAYNAME;
390
-			$permittedFields[] = AccountManager::PROPERTY_EMAIL;
391
-		}
392
-
393
-		if ($this->appManager->isEnabledForUser('federatedfilesharing')) {
394
-			$federatedFileSharing = $this->federatedFileSharingFactory->get();
395
-			$shareProvider = $federatedFileSharing->getFederatedShareProvider();
396
-			if ($shareProvider->isLookupServerUploadEnabled()) {
397
-				$permittedFields[] = AccountManager::PROPERTY_PHONE;
398
-				$permittedFields[] = AccountManager::PROPERTY_ADDRESS;
399
-				$permittedFields[] = AccountManager::PROPERTY_WEBSITE;
400
-				$permittedFields[] = AccountManager::PROPERTY_TWITTER;
401
-			}
402
-		}
403
-
404
-		return new DataResponse($permittedFields);
405
-	}
406
-
407
-	/**
408
-	 * @NoAdminRequired
409
-	 * @NoSubAdminRequired
410
-	 * @PasswordConfirmationRequired
411
-	 *
412
-	 * edit users
413
-	 *
414
-	 * @param string $userId
415
-	 * @param string $key
416
-	 * @param string $value
417
-	 * @return DataResponse
418
-	 * @throws OCSException
419
-	 */
420
-	public function editUser(string $userId, string $key, string $value): DataResponse {
421
-		$currentLoggedInUser = $this->userSession->getUser();
422
-
423
-		$targetUser = $this->userManager->get($userId);
424
-		if ($targetUser === null) {
425
-			throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED);
426
-		}
427
-
428
-		$permittedFields = [];
429
-		if ($targetUser->getUID() === $currentLoggedInUser->getUID()) {
430
-			// Editing self (display, email)
431
-			if ($this->config->getSystemValue('allow_user_to_change_display_name', true) !== false) {
432
-				$permittedFields[] = 'display';
433
-				$permittedFields[] = AccountManager::PROPERTY_DISPLAYNAME;
434
-				$permittedFields[] = AccountManager::PROPERTY_EMAIL;
435
-			}
436
-
437
-			$permittedFields[] = 'password';
438
-			if ($this->config->getSystemValue('force_language', false) === false ||
439
-				$this->groupManager->isAdmin($currentLoggedInUser->getUID())) {
440
-				$permittedFields[] = 'language';
441
-			}
442
-
443
-			if ($this->config->getSystemValue('force_locale', false) === false ||
444
-				$this->groupManager->isAdmin($currentLoggedInUser->getUID())) {
445
-				$permittedFields[] = 'locale';
446
-			}
447
-
448
-			if ($this->appManager->isEnabledForUser('federatedfilesharing')) {
449
-				$federatedFileSharing = new \OCA\FederatedFileSharing\AppInfo\Application();
450
-				$shareProvider = $federatedFileSharing->getFederatedShareProvider();
451
-				if ($shareProvider->isLookupServerUploadEnabled()) {
452
-					$permittedFields[] = AccountManager::PROPERTY_PHONE;
453
-					$permittedFields[] = AccountManager::PROPERTY_ADDRESS;
454
-					$permittedFields[] = AccountManager::PROPERTY_WEBSITE;
455
-					$permittedFields[] = AccountManager::PROPERTY_TWITTER;
456
-				}
457
-			}
458
-
459
-			// If admin they can edit their own quota
460
-			if ($this->groupManager->isAdmin($currentLoggedInUser->getUID())) {
461
-				$permittedFields[] = 'quota';
462
-			}
463
-		} else {
464
-			// Check if admin / subadmin
465
-			$subAdminManager = $this->groupManager->getSubAdmin();
466
-			if ($subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)
467
-			|| $this->groupManager->isAdmin($currentLoggedInUser->getUID())) {
468
-				// They have permissions over the user
469
-				$permittedFields[] = 'display';
470
-				$permittedFields[] = AccountManager::PROPERTY_DISPLAYNAME;
471
-				$permittedFields[] = AccountManager::PROPERTY_EMAIL;
472
-				$permittedFields[] = 'password';
473
-				$permittedFields[] = 'language';
474
-				$permittedFields[] = 'locale';
475
-				$permittedFields[] = AccountManager::PROPERTY_PHONE;
476
-				$permittedFields[] = AccountManager::PROPERTY_ADDRESS;
477
-				$permittedFields[] = AccountManager::PROPERTY_WEBSITE;
478
-				$permittedFields[] = AccountManager::PROPERTY_TWITTER;
479
-				$permittedFields[] = 'quota';
480
-			} else {
481
-				// No rights
482
-				throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED);
483
-			}
484
-		}
485
-		// Check if permitted to edit this field
486
-		if (!in_array($key, $permittedFields)) {
487
-			throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED);
488
-		}
489
-		// Process the edit
490
-		switch($key) {
491
-			case 'display':
492
-			case AccountManager::PROPERTY_DISPLAYNAME:
493
-				$targetUser->setDisplayName($value);
494
-				break;
495
-			case 'quota':
496
-				$quota = $value;
497
-				if ($quota !== 'none' && $quota !== 'default') {
498
-					if (is_numeric($quota)) {
499
-						$quota = (float) $quota;
500
-					} else {
501
-						$quota = \OCP\Util::computerFileSize($quota);
502
-					}
503
-					if ($quota === false) {
504
-						throw new OCSException('Invalid quota value '.$value, 103);
505
-					}
506
-					if ($quota === -1) {
507
-						$quota = 'none';
508
-					} else {
509
-						$quota = \OCP\Util::humanFileSize($quota);
510
-					}
511
-				}
512
-				$targetUser->setQuota($quota);
513
-				break;
514
-			case 'password':
515
-				$targetUser->setPassword($value);
516
-				break;
517
-			case 'language':
518
-				$languagesCodes = $this->l10nFactory->findAvailableLanguages();
519
-				if (!in_array($value, $languagesCodes, true) && $value !== 'en') {
520
-					throw new OCSException('Invalid language', 102);
521
-				}
522
-				$this->config->setUserValue($targetUser->getUID(), 'core', 'lang', $value);
523
-				break;
524
-			case 'locale':
525
-				if (!$this->l10nFactory->localeExists($value)) {
526
-					throw new OCSException('Invalid locale', 102);
527
-				}
528
-				$this->config->setUserValue($targetUser->getUID(), 'core', 'locale', $value);
529
-				break;
530
-			case AccountManager::PROPERTY_EMAIL:
531
-				if (filter_var($value, FILTER_VALIDATE_EMAIL) || $value === '') {
532
-					$targetUser->setEMailAddress($value);
533
-				} else {
534
-					throw new OCSException('', 102);
535
-				}
536
-				break;
537
-			case AccountManager::PROPERTY_PHONE:
538
-			case AccountManager::PROPERTY_ADDRESS:
539
-			case AccountManager::PROPERTY_WEBSITE:
540
-			case AccountManager::PROPERTY_TWITTER:
541
-				$userAccount = $this->accountManager->getUser($targetUser);
542
-				if ($userAccount[$key]['value'] !== $value) {
543
-					$userAccount[$key]['value'] = $value;
544
-					$this->accountManager->updateUser($targetUser, $userAccount);
545
-				}
546
-				break;
547
-			default:
548
-				throw new OCSException('', 103);
549
-		}
550
-		return new DataResponse();
551
-	}
552
-
553
-	/**
554
-	 * @PasswordConfirmationRequired
555
-	 * @NoAdminRequired
556
-	 *
557
-	 * @param string $userId
558
-	 * @return DataResponse
559
-	 * @throws OCSException
560
-	 */
561
-	public function deleteUser(string $userId): DataResponse {
562
-		$currentLoggedInUser = $this->userSession->getUser();
563
-
564
-		$targetUser = $this->userManager->get($userId);
565
-
566
-		if ($targetUser === null || $targetUser->getUID() === $currentLoggedInUser->getUID()) {
567
-			throw new OCSException('', 101);
568
-		}
569
-
570
-		// If not permitted
571
-		$subAdminManager = $this->groupManager->getSubAdmin();
572
-		if (!$this->groupManager->isAdmin($currentLoggedInUser->getUID()) && !$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)) {
573
-			throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED);
574
-		}
575
-
576
-		// Go ahead with the delete
577
-		if ($targetUser->delete()) {
578
-			return new DataResponse();
579
-		} else {
580
-			throw new OCSException('', 101);
581
-		}
582
-	}
583
-
584
-	/**
585
-	 * @PasswordConfirmationRequired
586
-	 * @NoAdminRequired
587
-	 *
588
-	 * @param string $userId
589
-	 * @return DataResponse
590
-	 * @throws OCSException
591
-	 * @throws OCSForbiddenException
592
-	 */
593
-	public function disableUser(string $userId): DataResponse {
594
-		return $this->setEnabled($userId, false);
595
-	}
596
-
597
-	/**
598
-	 * @PasswordConfirmationRequired
599
-	 * @NoAdminRequired
600
-	 *
601
-	 * @param string $userId
602
-	 * @return DataResponse
603
-	 * @throws OCSException
604
-	 * @throws OCSForbiddenException
605
-	 */
606
-	public function enableUser(string $userId): DataResponse {
607
-		return $this->setEnabled($userId, true);
608
-	}
609
-
610
-	/**
611
-	 * @param string $userId
612
-	 * @param bool $value
613
-	 * @return DataResponse
614
-	 * @throws OCSException
615
-	 */
616
-	private function setEnabled(string $userId, bool $value): DataResponse {
617
-		$currentLoggedInUser = $this->userSession->getUser();
618
-
619
-		$targetUser = $this->userManager->get($userId);
620
-		if ($targetUser === null || $targetUser->getUID() === $currentLoggedInUser->getUID()) {
621
-			throw new OCSException('', 101);
622
-		}
623
-
624
-		// If not permitted
625
-		$subAdminManager = $this->groupManager->getSubAdmin();
626
-		if (!$this->groupManager->isAdmin($currentLoggedInUser->getUID()) && !$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)) {
627
-			throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED);
628
-		}
629
-
630
-		// enable/disable the user now
631
-		$targetUser->setEnabled($value);
632
-		return new DataResponse();
633
-	}
634
-
635
-	/**
636
-	 * @NoAdminRequired
637
-	 * @NoSubAdminRequired
638
-	 *
639
-	 * @param string $userId
640
-	 * @return DataResponse
641
-	 * @throws OCSException
642
-	 */
643
-	public function getUsersGroups(string $userId): DataResponse {
644
-		$loggedInUser = $this->userSession->getUser();
645
-
646
-		$targetUser = $this->userManager->get($userId);
647
-		if ($targetUser === null) {
648
-			throw new OCSException('', \OCP\API::RESPOND_NOT_FOUND);
649
-		}
650
-
651
-		if ($targetUser->getUID() === $loggedInUser->getUID() || $this->groupManager->isAdmin($loggedInUser->getUID())) {
652
-			// Self lookup or admin lookup
653
-			return new DataResponse([
654
-				'groups' => $this->groupManager->getUserGroupIds($targetUser)
655
-			]);
656
-		} else {
657
-			$subAdminManager = $this->groupManager->getSubAdmin();
658
-
659
-			// Looking up someone else
660
-			if ($subAdminManager->isUserAccessible($loggedInUser, $targetUser)) {
661
-				// Return the group that the method caller is subadmin of for the user in question
662
-				/** @var IGroup[] $getSubAdminsGroups */
663
-				$getSubAdminsGroups = $subAdminManager->getSubAdminsGroups($loggedInUser);
664
-				foreach ($getSubAdminsGroups as $key => $group) {
665
-					$getSubAdminsGroups[$key] = $group->getGID();
666
-				}
667
-				$groups = array_intersect(
668
-					$getSubAdminsGroups,
669
-					$this->groupManager->getUserGroupIds($targetUser)
670
-				);
671
-				return new DataResponse(['groups' => $groups]);
672
-			} else {
673
-				// Not permitted
674
-				throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED);
675
-			}
676
-		}
677
-
678
-	}
679
-
680
-	/**
681
-	 * @PasswordConfirmationRequired
682
-	 * @NoAdminRequired
683
-	 *
684
-	 * @param string $userId
685
-	 * @param string $groupid
686
-	 * @return DataResponse
687
-	 * @throws OCSException
688
-	 */
689
-	public function addToGroup(string $userId, string $groupid = ''): DataResponse {
690
-		if ($groupid === '') {
691
-			throw new OCSException('', 101);
692
-		}
693
-
694
-		$group = $this->groupManager->get($groupid);
695
-		$targetUser = $this->userManager->get($userId);
696
-		if ($group === null) {
697
-			throw new OCSException('', 102);
698
-		}
699
-		if ($targetUser === null) {
700
-			throw new OCSException('', 103);
701
-		}
702
-
703
-		// If they're not an admin, check they are a subadmin of the group in question
704
-		$loggedInUser = $this->userSession->getUser();
705
-		$subAdminManager = $this->groupManager->getSubAdmin();
706
-		if (!$this->groupManager->isAdmin($loggedInUser->getUID()) && !$subAdminManager->isSubAdminOfGroup($loggedInUser, $group)) {
707
-			throw new OCSException('', 104);
708
-		}
709
-
710
-		// Add user to group
711
-		$group->addUser($targetUser);
712
-		return new DataResponse();
713
-	}
714
-
715
-	/**
716
-	 * @PasswordConfirmationRequired
717
-	 * @NoAdminRequired
718
-	 *
719
-	 * @param string $userId
720
-	 * @param string $groupid
721
-	 * @return DataResponse
722
-	 * @throws OCSException
723
-	 */
724
-	public function removeFromGroup(string $userId, string $groupid): DataResponse {
725
-		$loggedInUser = $this->userSession->getUser();
726
-
727
-		if ($groupid === null || trim($groupid) === '') {
728
-			throw new OCSException('', 101);
729
-		}
730
-
731
-		$group = $this->groupManager->get($groupid);
732
-		if ($group === null) {
733
-			throw new OCSException('', 102);
734
-		}
735
-
736
-		$targetUser = $this->userManager->get($userId);
737
-		if ($targetUser === null) {
738
-			throw new OCSException('', 103);
739
-		}
740
-
741
-		// If they're not an admin, check they are a subadmin of the group in question
742
-		$subAdminManager = $this->groupManager->getSubAdmin();
743
-		if (!$this->groupManager->isAdmin($loggedInUser->getUID()) && !$subAdminManager->isSubAdminOfGroup($loggedInUser, $group)) {
744
-			throw new OCSException('', 104);
745
-		}
746
-
747
-		// Check they aren't removing themselves from 'admin' or their 'subadmin; group
748
-		if ($targetUser->getUID() === $loggedInUser->getUID()) {
749
-			if ($this->groupManager->isAdmin($loggedInUser->getUID())) {
750
-				if ($group->getGID() === 'admin') {
751
-					throw new OCSException('Cannot remove yourself from the admin group', 105);
752
-				}
753
-			} else {
754
-				// Not an admin, so the user must be a subadmin of this group, but that is not allowed.
755
-				throw new OCSException('Cannot remove yourself from this group as you are a SubAdmin', 105);
756
-			}
757
-
758
-		} else if (!$this->groupManager->isAdmin($loggedInUser->getUID())) {
759
-			/** @var IGroup[] $subAdminGroups */
760
-			$subAdminGroups = $subAdminManager->getSubAdminsGroups($loggedInUser);
761
-			$subAdminGroups = array_map(function (IGroup $subAdminGroup) {
762
-				return $subAdminGroup->getGID();
763
-			}, $subAdminGroups);
764
-			$userGroups = $this->groupManager->getUserGroupIds($targetUser);
765
-			$userSubAdminGroups = array_intersect($subAdminGroups, $userGroups);
766
-
767
-			if (count($userSubAdminGroups) <= 1) {
768
-				// Subadmin must not be able to remove a user from all their subadmin groups.
769
-				throw new OCSException('Cannot remove user from this group as this is the only remaining group you are a SubAdmin of', 105);
770
-			}
771
-		}
772
-
773
-		// Remove user from group
774
-		$group->removeUser($targetUser);
775
-		return new DataResponse();
776
-	}
777
-
778
-	/**
779
-	 * Creates a subadmin
780
-	 *
781
-	 * @PasswordConfirmationRequired
782
-	 *
783
-	 * @param string $userId
784
-	 * @param string $groupid
785
-	 * @return DataResponse
786
-	 * @throws OCSException
787
-	 */
788
-	public function addSubAdmin(string $userId, string $groupid): DataResponse {
789
-		$group = $this->groupManager->get($groupid);
790
-		$user = $this->userManager->get($userId);
791
-
792
-		// Check if the user exists
793
-		if ($user === null) {
794
-			throw new OCSException('User does not exist', 101);
795
-		}
796
-		// Check if group exists
797
-		if ($group === null) {
798
-			throw new OCSException('Group does not exist',  102);
799
-		}
800
-		// Check if trying to make subadmin of admin group
801
-		if ($group->getGID() === 'admin') {
802
-			throw new OCSException('Cannot create subadmins for admin group', 103);
803
-		}
804
-
805
-		$subAdminManager = $this->groupManager->getSubAdmin();
806
-
807
-		// We cannot be subadmin twice
808
-		if ($subAdminManager->isSubAdminOfGroup($user, $group)) {
809
-			return new DataResponse();
810
-		}
811
-		// Go
812
-		$subAdminManager->createSubAdmin($user, $group);
813
-		return new DataResponse();
814
-	}
815
-
816
-	/**
817
-	 * Removes a subadmin from a group
818
-	 *
819
-	 * @PasswordConfirmationRequired
820
-	 *
821
-	 * @param string $userId
822
-	 * @param string $groupid
823
-	 * @return DataResponse
824
-	 * @throws OCSException
825
-	 */
826
-	public function removeSubAdmin(string $userId, string $groupid): DataResponse {
827
-		$group = $this->groupManager->get($groupid);
828
-		$user = $this->userManager->get($userId);
829
-		$subAdminManager = $this->groupManager->getSubAdmin();
830
-
831
-		// Check if the user exists
832
-		if ($user === null) {
833
-			throw new OCSException('User does not exist', 101);
834
-		}
835
-		// Check if the group exists
836
-		if ($group === null) {
837
-			throw new OCSException('Group does not exist', 101);
838
-		}
839
-		// Check if they are a subadmin of this said group
840
-		if (!$subAdminManager->isSubAdminOfGroup($user, $group)) {
841
-			throw new OCSException('User is not a subadmin of this group', 102);
842
-		}
843
-
844
-		// Go
845
-		$subAdminManager->deleteSubAdmin($user, $group);
846
-		return new DataResponse();
847
-	}
848
-
849
-	/**
850
-	 * Get the groups a user is a subadmin of
851
-	 *
852
-	 * @param string $userId
853
-	 * @return DataResponse
854
-	 * @throws OCSException
855
-	 */
856
-	public function getUserSubAdminGroups(string $userId): DataResponse {
857
-		$groups = $this->getUserSubAdminGroupsData($userId);
858
-		return new DataResponse($groups);
859
-	}
860
-
861
-	/**
862
-	 * @NoAdminRequired
863
-	 * @PasswordConfirmationRequired
864
-	 *
865
-	 * resend welcome message
866
-	 *
867
-	 * @param string $userId
868
-	 * @return DataResponse
869
-	 * @throws OCSException
870
-	 */
871
-	public function resendWelcomeMessage(string $userId): DataResponse {
872
-		$currentLoggedInUser = $this->userSession->getUser();
873
-
874
-		$targetUser = $this->userManager->get($userId);
875
-		if ($targetUser === null) {
876
-			throw new OCSException('', \OCP\API::RESPOND_NOT_FOUND);
877
-		}
878
-
879
-		// Check if admin / subadmin
880
-		$subAdminManager = $this->groupManager->getSubAdmin();
881
-		if (!$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)
882
-			&& !$this->groupManager->isAdmin($currentLoggedInUser->getUID())) {
883
-			// No rights
884
-			throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED);
885
-		}
886
-
887
-		$email = $targetUser->getEMailAddress();
888
-		if ($email === '' || $email === null) {
889
-			throw new OCSException('Email address not available', 101);
890
-		}
891
-
892
-		try {
893
-			$emailTemplate = $this->newUserMailHelper->generateTemplate($targetUser, false);
894
-			$this->newUserMailHelper->sendMail($targetUser, $emailTemplate);
895
-		} catch(\Exception $e) {
896
-			$this->logger->logException($e, [
897
-				'message' => "Can't send new user mail to $email",
898
-				'level' => ILogger::ERROR,
899
-				'app' => 'settings',
900
-			]);
901
-			throw new OCSException('Sending email failed', 102);
902
-		}
903
-
904
-		return new DataResponse();
905
-	}
57
+    /** @var IAppManager */
58
+    private $appManager;
59
+    /** @var ILogger */
60
+    private $logger;
61
+    /** @var IFactory */
62
+    private $l10nFactory;
63
+    /** @var NewUserMailHelper */
64
+    private $newUserMailHelper;
65
+    /** @var FederatedFileSharingFactory */
66
+    private $federatedFileSharingFactory;
67
+    /** @var ISecureRandom */
68
+    private $secureRandom;
69
+
70
+    /**
71
+     * @param string $appName
72
+     * @param IRequest $request
73
+     * @param IUserManager $userManager
74
+     * @param IConfig $config
75
+     * @param IAppManager $appManager
76
+     * @param IGroupManager $groupManager
77
+     * @param IUserSession $userSession
78
+     * @param AccountManager $accountManager
79
+     * @param ILogger $logger
80
+     * @param IFactory $l10nFactory
81
+     * @param NewUserMailHelper $newUserMailHelper
82
+     * @param FederatedFileSharingFactory $federatedFileSharingFactory
83
+     * @param ISecureRandom $secureRandom
84
+     */
85
+    public function __construct(string $appName,
86
+                                IRequest $request,
87
+                                IUserManager $userManager,
88
+                                IConfig $config,
89
+                                IAppManager $appManager,
90
+                                IGroupManager $groupManager,
91
+                                IUserSession $userSession,
92
+                                AccountManager $accountManager,
93
+                                ILogger $logger,
94
+                                IFactory $l10nFactory,
95
+                                NewUserMailHelper $newUserMailHelper,
96
+                                FederatedFileSharingFactory $federatedFileSharingFactory,
97
+                                ISecureRandom $secureRandom) {
98
+        parent::__construct($appName,
99
+                            $request,
100
+                            $userManager,
101
+                            $config,
102
+                            $groupManager,
103
+                            $userSession,
104
+                            $accountManager);
105
+
106
+        $this->appManager = $appManager;
107
+        $this->logger = $logger;
108
+        $this->l10nFactory = $l10nFactory;
109
+        $this->newUserMailHelper = $newUserMailHelper;
110
+        $this->federatedFileSharingFactory = $federatedFileSharingFactory;
111
+        $this->secureRandom = $secureRandom;
112
+    }
113
+
114
+    /**
115
+     * @NoAdminRequired
116
+     *
117
+     * returns a list of users
118
+     *
119
+     * @param string $search
120
+     * @param int $limit
121
+     * @param int $offset
122
+     * @return DataResponse
123
+     */
124
+    public function getUsers(string $search = '', $limit = null, $offset = 0): DataResponse {
125
+        $user = $this->userSession->getUser();
126
+        $users = [];
127
+
128
+        // Admin? Or SubAdmin?
129
+        $uid = $user->getUID();
130
+        $subAdminManager = $this->groupManager->getSubAdmin();
131
+        if ($this->groupManager->isAdmin($uid)){
132
+            $users = $this->userManager->search($search, $limit, $offset);
133
+        } else if ($subAdminManager->isSubAdmin($user)) {
134
+            $subAdminOfGroups = $subAdminManager->getSubAdminsGroups($user);
135
+            foreach ($subAdminOfGroups as $key => $group) {
136
+                $subAdminOfGroups[$key] = $group->getGID();
137
+            }
138
+
139
+            $users = [];
140
+            foreach ($subAdminOfGroups as $group) {
141
+                $users = array_merge($users, $this->groupManager->displayNamesInGroup($group, $search, $limit, $offset));
142
+            }
143
+        }
144
+
145
+        $users = array_keys($users);
146
+
147
+        return new DataResponse([
148
+            'users' => $users
149
+        ]);
150
+    }
151
+
152
+    /**
153
+     * @NoAdminRequired
154
+     *
155
+     * returns a list of users and their data
156
+     */
157
+    public function getUsersDetails(string $search = '', $limit = null, $offset = 0): DataResponse {
158
+        $currentUser = $this->userSession->getUser();
159
+        $users = [];
160
+
161
+        // Admin? Or SubAdmin?
162
+        $uid = $currentUser->getUID();
163
+        $subAdminManager = $this->groupManager->getSubAdmin();
164
+        if ($this->groupManager->isAdmin($uid)){
165
+            $users = $this->userManager->search($search, $limit, $offset);
166
+            $users = array_keys($users);
167
+        } else if ($subAdminManager->isSubAdmin($currentUser)) {
168
+            $subAdminOfGroups = $subAdminManager->getSubAdminsGroups($currentUser);
169
+            foreach ($subAdminOfGroups as $key => $group) {
170
+                $subAdminOfGroups[$key] = $group->getGID();
171
+            }
172
+
173
+            $users = [];
174
+            foreach ($subAdminOfGroups as $group) {
175
+                $users[] = array_keys($this->groupManager->displayNamesInGroup($group, $search, $limit, $offset));
176
+            }
177
+            $users = array_merge(...$users);
178
+        }
179
+
180
+        $usersDetails = [];
181
+        foreach ($users as $userId) {
182
+            $userId = (string) $userId;
183
+            $userData = $this->getUserData($userId);
184
+            // Do not insert empty entry
185
+            if (!empty($userData)) {
186
+                $usersDetails[$userId] = $userData;
187
+            } else {
188
+                // Logged user does not have permissions to see this user
189
+                // only showing its id
190
+                $usersDetails[$userId] = ['id' => $userId];
191
+            }
192
+        }
193
+
194
+        return new DataResponse([
195
+            'users' => $usersDetails
196
+        ]);
197
+    }
198
+
199
+    /**
200
+     * @PasswordConfirmationRequired
201
+     * @NoAdminRequired
202
+     *
203
+     * @param string $userid
204
+     * @param string $password
205
+     * @param string $displayName
206
+     * @param string $email
207
+     * @param array $groups
208
+     * @param array $subadmin
209
+     * @param string $quota
210
+     * @param string $language
211
+     * @return DataResponse
212
+     * @throws OCSException
213
+     */
214
+    public function addUser(string $userid,
215
+                            string $password = '',
216
+                            string $displayName = '',
217
+                            string $email = '',
218
+                            array $groups = [],
219
+                            array $subadmin = [],
220
+                            string $quota = '',
221
+                            string $language = ''): DataResponse {
222
+        $user = $this->userSession->getUser();
223
+        $isAdmin = $this->groupManager->isAdmin($user->getUID());
224
+        $subAdminManager = $this->groupManager->getSubAdmin();
225
+
226
+        if ($this->userManager->userExists($userid)) {
227
+            $this->logger->error('Failed addUser attempt: User already exists.', ['app' => 'ocs_api']);
228
+            throw new OCSException('User already exists', 102);
229
+        }
230
+
231
+        if ($groups !== []) {
232
+            foreach ($groups as $group) {
233
+                if (!$this->groupManager->groupExists($group)) {
234
+                    throw new OCSException('group '.$group.' does not exist', 104);
235
+                }
236
+                if (!$isAdmin && !$subAdminManager->isSubAdminOfGroup($user, $this->groupManager->get($group))) {
237
+                    throw new OCSException('insufficient privileges for group '. $group, 105);
238
+                }
239
+            }
240
+        } else {
241
+            if (!$isAdmin) {
242
+                throw new OCSException('no group specified (required for subadmins)', 106);
243
+            }
244
+        }
245
+
246
+        $subadminGroups = [];
247
+        if ($subadmin !== []) {
248
+            foreach ($subadmin as $groupid) {
249
+                $group = $this->groupManager->get($groupid);
250
+                // Check if group exists
251
+                if ($group === null) {
252
+                    throw new OCSException('Subadmin group does not exist',  102);
253
+                }
254
+                // Check if trying to make subadmin of admin group
255
+                if ($group->getGID() === 'admin') {
256
+                    throw new OCSException('Cannot create subadmins for admin group', 103);
257
+                }
258
+                // Check if has permission to promote subadmins
259
+                if (!$subAdminManager->isSubAdminOfGroup($user, $group) && !$isAdmin) {
260
+                    throw new OCSForbiddenException('No permissions to promote subadmins');
261
+                }
262
+                $subadminGroups[] = $group;
263
+            }
264
+        }
265
+
266
+        $generatePasswordResetToken = false;
267
+        if ($password === '') {
268
+            if ($email === '') {
269
+                throw new OCSException('To send a password link to the user an email address is required.', 108);
270
+            }
271
+
272
+            $password = $this->secureRandom->generate(10);
273
+            // Make sure we pass the password_policy
274
+            $password .= $this->secureRandom->generate(2, '$!.,;:-~+*[]{}()');
275
+            $generatePasswordResetToken = true;
276
+        }
277
+
278
+        try {
279
+            $newUser = $this->userManager->createUser($userid, $password);
280
+            $this->logger->info('Successful addUser call with userid: ' . $userid, ['app' => 'ocs_api']);
281
+
282
+            foreach ($groups as $group) {
283
+                $this->groupManager->get($group)->addUser($newUser);
284
+                $this->logger->info('Added userid ' . $userid . ' to group ' . $group, ['app' => 'ocs_api']);
285
+            }
286
+            foreach ($subadminGroups as $group) {
287
+                $subAdminManager->createSubAdmin($newUser, $group);
288
+            }
289
+
290
+            if ($displayName !== '') {
291
+                $this->editUser($userid, 'display', $displayName);
292
+            }
293
+
294
+            if ($quota !== '') {
295
+                $this->editUser($userid, 'quota', $quota);
296
+            }
297
+
298
+            if ($language !== '') {
299
+                $this->editUser($userid, 'language', $language);
300
+            }
301
+
302
+            // Send new user mail only if a mail is set
303
+            if ($email !== '') {
304
+                $newUser->setEMailAddress($email);
305
+                try {
306
+                    $emailTemplate = $this->newUserMailHelper->generateTemplate($newUser, $generatePasswordResetToken);
307
+                    $this->newUserMailHelper->sendMail($newUser, $emailTemplate);
308
+                } catch (\Exception $e) {
309
+                    $this->logger->logException($e, [
310
+                        'message' => "Can't send new user mail to $email",
311
+                        'level' => ILogger::ERROR,
312
+                        'app' => 'ocs_api',
313
+                    ]);
314
+                    throw new OCSException('Unable to send the invitation mail', 109);
315
+                }
316
+            }
317
+
318
+            return new DataResponse();
319
+
320
+        } catch (HintException $e ) {
321
+            $this->logger->logException($e, [
322
+                'message' => 'Failed addUser attempt with hint exception.',
323
+                'level' => ILogger::WARN,
324
+                'app' => 'ocs_api',
325
+            ]);
326
+            throw new OCSException($e->getHint(), 107);
327
+        } catch (\Exception $e) {
328
+            $this->logger->logException($e, [
329
+                'message' => 'Failed addUser attempt with exception.',
330
+                'level' => ILogger::ERROR,
331
+                'app' => 'ocs_api',
332
+            ]);
333
+            throw new OCSException('Bad request', 101);
334
+        }
335
+    }
336
+
337
+    /**
338
+     * @NoAdminRequired
339
+     * @NoSubAdminRequired
340
+     *
341
+     * gets user info
342
+     *
343
+     * @param string $userId
344
+     * @return DataResponse
345
+     * @throws OCSException
346
+     */
347
+    public function getUser(string $userId): DataResponse {
348
+        $data = $this->getUserData($userId);
349
+        // getUserData returns empty array if not enough permissions
350
+        if (empty($data)) {
351
+            throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED);
352
+        }
353
+        return new DataResponse($data);
354
+    }
355
+
356
+    /**
357
+     * @NoAdminRequired
358
+     * @NoSubAdminRequired
359
+     *
360
+     * gets user info from the currently logged in user
361
+     *
362
+     * @return DataResponse
363
+     * @throws OCSException
364
+     */
365
+    public function getCurrentUser(): DataResponse {
366
+        $user = $this->userSession->getUser();
367
+        if ($user) {
368
+            $data =  $this->getUserData($user->getUID());
369
+            // rename "displayname" to "display-name" only for this call to keep
370
+            // the API stable.
371
+            $data['display-name'] = $data['displayname'];
372
+            unset($data['displayname']);
373
+            return new DataResponse($data);
374
+
375
+        }
376
+
377
+        throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED);
378
+    }
379
+
380
+    /**
381
+     * @NoAdminRequired
382
+     * @NoSubAdminRequired
383
+     */
384
+    public function getEditableFields(): DataResponse {
385
+        $permittedFields = [];
386
+
387
+        // Editing self (display, email)
388
+        if ($this->config->getSystemValue('allow_user_to_change_display_name', true) !== false) {
389
+            $permittedFields[] = AccountManager::PROPERTY_DISPLAYNAME;
390
+            $permittedFields[] = AccountManager::PROPERTY_EMAIL;
391
+        }
392
+
393
+        if ($this->appManager->isEnabledForUser('federatedfilesharing')) {
394
+            $federatedFileSharing = $this->federatedFileSharingFactory->get();
395
+            $shareProvider = $federatedFileSharing->getFederatedShareProvider();
396
+            if ($shareProvider->isLookupServerUploadEnabled()) {
397
+                $permittedFields[] = AccountManager::PROPERTY_PHONE;
398
+                $permittedFields[] = AccountManager::PROPERTY_ADDRESS;
399
+                $permittedFields[] = AccountManager::PROPERTY_WEBSITE;
400
+                $permittedFields[] = AccountManager::PROPERTY_TWITTER;
401
+            }
402
+        }
403
+
404
+        return new DataResponse($permittedFields);
405
+    }
406
+
407
+    /**
408
+     * @NoAdminRequired
409
+     * @NoSubAdminRequired
410
+     * @PasswordConfirmationRequired
411
+     *
412
+     * edit users
413
+     *
414
+     * @param string $userId
415
+     * @param string $key
416
+     * @param string $value
417
+     * @return DataResponse
418
+     * @throws OCSException
419
+     */
420
+    public function editUser(string $userId, string $key, string $value): DataResponse {
421
+        $currentLoggedInUser = $this->userSession->getUser();
422
+
423
+        $targetUser = $this->userManager->get($userId);
424
+        if ($targetUser === null) {
425
+            throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED);
426
+        }
427
+
428
+        $permittedFields = [];
429
+        if ($targetUser->getUID() === $currentLoggedInUser->getUID()) {
430
+            // Editing self (display, email)
431
+            if ($this->config->getSystemValue('allow_user_to_change_display_name', true) !== false) {
432
+                $permittedFields[] = 'display';
433
+                $permittedFields[] = AccountManager::PROPERTY_DISPLAYNAME;
434
+                $permittedFields[] = AccountManager::PROPERTY_EMAIL;
435
+            }
436
+
437
+            $permittedFields[] = 'password';
438
+            if ($this->config->getSystemValue('force_language', false) === false ||
439
+                $this->groupManager->isAdmin($currentLoggedInUser->getUID())) {
440
+                $permittedFields[] = 'language';
441
+            }
442
+
443
+            if ($this->config->getSystemValue('force_locale', false) === false ||
444
+                $this->groupManager->isAdmin($currentLoggedInUser->getUID())) {
445
+                $permittedFields[] = 'locale';
446
+            }
447
+
448
+            if ($this->appManager->isEnabledForUser('federatedfilesharing')) {
449
+                $federatedFileSharing = new \OCA\FederatedFileSharing\AppInfo\Application();
450
+                $shareProvider = $federatedFileSharing->getFederatedShareProvider();
451
+                if ($shareProvider->isLookupServerUploadEnabled()) {
452
+                    $permittedFields[] = AccountManager::PROPERTY_PHONE;
453
+                    $permittedFields[] = AccountManager::PROPERTY_ADDRESS;
454
+                    $permittedFields[] = AccountManager::PROPERTY_WEBSITE;
455
+                    $permittedFields[] = AccountManager::PROPERTY_TWITTER;
456
+                }
457
+            }
458
+
459
+            // If admin they can edit their own quota
460
+            if ($this->groupManager->isAdmin($currentLoggedInUser->getUID())) {
461
+                $permittedFields[] = 'quota';
462
+            }
463
+        } else {
464
+            // Check if admin / subadmin
465
+            $subAdminManager = $this->groupManager->getSubAdmin();
466
+            if ($subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)
467
+            || $this->groupManager->isAdmin($currentLoggedInUser->getUID())) {
468
+                // They have permissions over the user
469
+                $permittedFields[] = 'display';
470
+                $permittedFields[] = AccountManager::PROPERTY_DISPLAYNAME;
471
+                $permittedFields[] = AccountManager::PROPERTY_EMAIL;
472
+                $permittedFields[] = 'password';
473
+                $permittedFields[] = 'language';
474
+                $permittedFields[] = 'locale';
475
+                $permittedFields[] = AccountManager::PROPERTY_PHONE;
476
+                $permittedFields[] = AccountManager::PROPERTY_ADDRESS;
477
+                $permittedFields[] = AccountManager::PROPERTY_WEBSITE;
478
+                $permittedFields[] = AccountManager::PROPERTY_TWITTER;
479
+                $permittedFields[] = 'quota';
480
+            } else {
481
+                // No rights
482
+                throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED);
483
+            }
484
+        }
485
+        // Check if permitted to edit this field
486
+        if (!in_array($key, $permittedFields)) {
487
+            throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED);
488
+        }
489
+        // Process the edit
490
+        switch($key) {
491
+            case 'display':
492
+            case AccountManager::PROPERTY_DISPLAYNAME:
493
+                $targetUser->setDisplayName($value);
494
+                break;
495
+            case 'quota':
496
+                $quota = $value;
497
+                if ($quota !== 'none' && $quota !== 'default') {
498
+                    if (is_numeric($quota)) {
499
+                        $quota = (float) $quota;
500
+                    } else {
501
+                        $quota = \OCP\Util::computerFileSize($quota);
502
+                    }
503
+                    if ($quota === false) {
504
+                        throw new OCSException('Invalid quota value '.$value, 103);
505
+                    }
506
+                    if ($quota === -1) {
507
+                        $quota = 'none';
508
+                    } else {
509
+                        $quota = \OCP\Util::humanFileSize($quota);
510
+                    }
511
+                }
512
+                $targetUser->setQuota($quota);
513
+                break;
514
+            case 'password':
515
+                $targetUser->setPassword($value);
516
+                break;
517
+            case 'language':
518
+                $languagesCodes = $this->l10nFactory->findAvailableLanguages();
519
+                if (!in_array($value, $languagesCodes, true) && $value !== 'en') {
520
+                    throw new OCSException('Invalid language', 102);
521
+                }
522
+                $this->config->setUserValue($targetUser->getUID(), 'core', 'lang', $value);
523
+                break;
524
+            case 'locale':
525
+                if (!$this->l10nFactory->localeExists($value)) {
526
+                    throw new OCSException('Invalid locale', 102);
527
+                }
528
+                $this->config->setUserValue($targetUser->getUID(), 'core', 'locale', $value);
529
+                break;
530
+            case AccountManager::PROPERTY_EMAIL:
531
+                if (filter_var($value, FILTER_VALIDATE_EMAIL) || $value === '') {
532
+                    $targetUser->setEMailAddress($value);
533
+                } else {
534
+                    throw new OCSException('', 102);
535
+                }
536
+                break;
537
+            case AccountManager::PROPERTY_PHONE:
538
+            case AccountManager::PROPERTY_ADDRESS:
539
+            case AccountManager::PROPERTY_WEBSITE:
540
+            case AccountManager::PROPERTY_TWITTER:
541
+                $userAccount = $this->accountManager->getUser($targetUser);
542
+                if ($userAccount[$key]['value'] !== $value) {
543
+                    $userAccount[$key]['value'] = $value;
544
+                    $this->accountManager->updateUser($targetUser, $userAccount);
545
+                }
546
+                break;
547
+            default:
548
+                throw new OCSException('', 103);
549
+        }
550
+        return new DataResponse();
551
+    }
552
+
553
+    /**
554
+     * @PasswordConfirmationRequired
555
+     * @NoAdminRequired
556
+     *
557
+     * @param string $userId
558
+     * @return DataResponse
559
+     * @throws OCSException
560
+     */
561
+    public function deleteUser(string $userId): DataResponse {
562
+        $currentLoggedInUser = $this->userSession->getUser();
563
+
564
+        $targetUser = $this->userManager->get($userId);
565
+
566
+        if ($targetUser === null || $targetUser->getUID() === $currentLoggedInUser->getUID()) {
567
+            throw new OCSException('', 101);
568
+        }
569
+
570
+        // If not permitted
571
+        $subAdminManager = $this->groupManager->getSubAdmin();
572
+        if (!$this->groupManager->isAdmin($currentLoggedInUser->getUID()) && !$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)) {
573
+            throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED);
574
+        }
575
+
576
+        // Go ahead with the delete
577
+        if ($targetUser->delete()) {
578
+            return new DataResponse();
579
+        } else {
580
+            throw new OCSException('', 101);
581
+        }
582
+    }
583
+
584
+    /**
585
+     * @PasswordConfirmationRequired
586
+     * @NoAdminRequired
587
+     *
588
+     * @param string $userId
589
+     * @return DataResponse
590
+     * @throws OCSException
591
+     * @throws OCSForbiddenException
592
+     */
593
+    public function disableUser(string $userId): DataResponse {
594
+        return $this->setEnabled($userId, false);
595
+    }
596
+
597
+    /**
598
+     * @PasswordConfirmationRequired
599
+     * @NoAdminRequired
600
+     *
601
+     * @param string $userId
602
+     * @return DataResponse
603
+     * @throws OCSException
604
+     * @throws OCSForbiddenException
605
+     */
606
+    public function enableUser(string $userId): DataResponse {
607
+        return $this->setEnabled($userId, true);
608
+    }
609
+
610
+    /**
611
+     * @param string $userId
612
+     * @param bool $value
613
+     * @return DataResponse
614
+     * @throws OCSException
615
+     */
616
+    private function setEnabled(string $userId, bool $value): DataResponse {
617
+        $currentLoggedInUser = $this->userSession->getUser();
618
+
619
+        $targetUser = $this->userManager->get($userId);
620
+        if ($targetUser === null || $targetUser->getUID() === $currentLoggedInUser->getUID()) {
621
+            throw new OCSException('', 101);
622
+        }
623
+
624
+        // If not permitted
625
+        $subAdminManager = $this->groupManager->getSubAdmin();
626
+        if (!$this->groupManager->isAdmin($currentLoggedInUser->getUID()) && !$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)) {
627
+            throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED);
628
+        }
629
+
630
+        // enable/disable the user now
631
+        $targetUser->setEnabled($value);
632
+        return new DataResponse();
633
+    }
634
+
635
+    /**
636
+     * @NoAdminRequired
637
+     * @NoSubAdminRequired
638
+     *
639
+     * @param string $userId
640
+     * @return DataResponse
641
+     * @throws OCSException
642
+     */
643
+    public function getUsersGroups(string $userId): DataResponse {
644
+        $loggedInUser = $this->userSession->getUser();
645
+
646
+        $targetUser = $this->userManager->get($userId);
647
+        if ($targetUser === null) {
648
+            throw new OCSException('', \OCP\API::RESPOND_NOT_FOUND);
649
+        }
650
+
651
+        if ($targetUser->getUID() === $loggedInUser->getUID() || $this->groupManager->isAdmin($loggedInUser->getUID())) {
652
+            // Self lookup or admin lookup
653
+            return new DataResponse([
654
+                'groups' => $this->groupManager->getUserGroupIds($targetUser)
655
+            ]);
656
+        } else {
657
+            $subAdminManager = $this->groupManager->getSubAdmin();
658
+
659
+            // Looking up someone else
660
+            if ($subAdminManager->isUserAccessible($loggedInUser, $targetUser)) {
661
+                // Return the group that the method caller is subadmin of for the user in question
662
+                /** @var IGroup[] $getSubAdminsGroups */
663
+                $getSubAdminsGroups = $subAdminManager->getSubAdminsGroups($loggedInUser);
664
+                foreach ($getSubAdminsGroups as $key => $group) {
665
+                    $getSubAdminsGroups[$key] = $group->getGID();
666
+                }
667
+                $groups = array_intersect(
668
+                    $getSubAdminsGroups,
669
+                    $this->groupManager->getUserGroupIds($targetUser)
670
+                );
671
+                return new DataResponse(['groups' => $groups]);
672
+            } else {
673
+                // Not permitted
674
+                throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED);
675
+            }
676
+        }
677
+
678
+    }
679
+
680
+    /**
681
+     * @PasswordConfirmationRequired
682
+     * @NoAdminRequired
683
+     *
684
+     * @param string $userId
685
+     * @param string $groupid
686
+     * @return DataResponse
687
+     * @throws OCSException
688
+     */
689
+    public function addToGroup(string $userId, string $groupid = ''): DataResponse {
690
+        if ($groupid === '') {
691
+            throw new OCSException('', 101);
692
+        }
693
+
694
+        $group = $this->groupManager->get($groupid);
695
+        $targetUser = $this->userManager->get($userId);
696
+        if ($group === null) {
697
+            throw new OCSException('', 102);
698
+        }
699
+        if ($targetUser === null) {
700
+            throw new OCSException('', 103);
701
+        }
702
+
703
+        // If they're not an admin, check they are a subadmin of the group in question
704
+        $loggedInUser = $this->userSession->getUser();
705
+        $subAdminManager = $this->groupManager->getSubAdmin();
706
+        if (!$this->groupManager->isAdmin($loggedInUser->getUID()) && !$subAdminManager->isSubAdminOfGroup($loggedInUser, $group)) {
707
+            throw new OCSException('', 104);
708
+        }
709
+
710
+        // Add user to group
711
+        $group->addUser($targetUser);
712
+        return new DataResponse();
713
+    }
714
+
715
+    /**
716
+     * @PasswordConfirmationRequired
717
+     * @NoAdminRequired
718
+     *
719
+     * @param string $userId
720
+     * @param string $groupid
721
+     * @return DataResponse
722
+     * @throws OCSException
723
+     */
724
+    public function removeFromGroup(string $userId, string $groupid): DataResponse {
725
+        $loggedInUser = $this->userSession->getUser();
726
+
727
+        if ($groupid === null || trim($groupid) === '') {
728
+            throw new OCSException('', 101);
729
+        }
730
+
731
+        $group = $this->groupManager->get($groupid);
732
+        if ($group === null) {
733
+            throw new OCSException('', 102);
734
+        }
735
+
736
+        $targetUser = $this->userManager->get($userId);
737
+        if ($targetUser === null) {
738
+            throw new OCSException('', 103);
739
+        }
740
+
741
+        // If they're not an admin, check they are a subadmin of the group in question
742
+        $subAdminManager = $this->groupManager->getSubAdmin();
743
+        if (!$this->groupManager->isAdmin($loggedInUser->getUID()) && !$subAdminManager->isSubAdminOfGroup($loggedInUser, $group)) {
744
+            throw new OCSException('', 104);
745
+        }
746
+
747
+        // Check they aren't removing themselves from 'admin' or their 'subadmin; group
748
+        if ($targetUser->getUID() === $loggedInUser->getUID()) {
749
+            if ($this->groupManager->isAdmin($loggedInUser->getUID())) {
750
+                if ($group->getGID() === 'admin') {
751
+                    throw new OCSException('Cannot remove yourself from the admin group', 105);
752
+                }
753
+            } else {
754
+                // Not an admin, so the user must be a subadmin of this group, but that is not allowed.
755
+                throw new OCSException('Cannot remove yourself from this group as you are a SubAdmin', 105);
756
+            }
757
+
758
+        } else if (!$this->groupManager->isAdmin($loggedInUser->getUID())) {
759
+            /** @var IGroup[] $subAdminGroups */
760
+            $subAdminGroups = $subAdminManager->getSubAdminsGroups($loggedInUser);
761
+            $subAdminGroups = array_map(function (IGroup $subAdminGroup) {
762
+                return $subAdminGroup->getGID();
763
+            }, $subAdminGroups);
764
+            $userGroups = $this->groupManager->getUserGroupIds($targetUser);
765
+            $userSubAdminGroups = array_intersect($subAdminGroups, $userGroups);
766
+
767
+            if (count($userSubAdminGroups) <= 1) {
768
+                // Subadmin must not be able to remove a user from all their subadmin groups.
769
+                throw new OCSException('Cannot remove user from this group as this is the only remaining group you are a SubAdmin of', 105);
770
+            }
771
+        }
772
+
773
+        // Remove user from group
774
+        $group->removeUser($targetUser);
775
+        return new DataResponse();
776
+    }
777
+
778
+    /**
779
+     * Creates a subadmin
780
+     *
781
+     * @PasswordConfirmationRequired
782
+     *
783
+     * @param string $userId
784
+     * @param string $groupid
785
+     * @return DataResponse
786
+     * @throws OCSException
787
+     */
788
+    public function addSubAdmin(string $userId, string $groupid): DataResponse {
789
+        $group = $this->groupManager->get($groupid);
790
+        $user = $this->userManager->get($userId);
791
+
792
+        // Check if the user exists
793
+        if ($user === null) {
794
+            throw new OCSException('User does not exist', 101);
795
+        }
796
+        // Check if group exists
797
+        if ($group === null) {
798
+            throw new OCSException('Group does not exist',  102);
799
+        }
800
+        // Check if trying to make subadmin of admin group
801
+        if ($group->getGID() === 'admin') {
802
+            throw new OCSException('Cannot create subadmins for admin group', 103);
803
+        }
804
+
805
+        $subAdminManager = $this->groupManager->getSubAdmin();
806
+
807
+        // We cannot be subadmin twice
808
+        if ($subAdminManager->isSubAdminOfGroup($user, $group)) {
809
+            return new DataResponse();
810
+        }
811
+        // Go
812
+        $subAdminManager->createSubAdmin($user, $group);
813
+        return new DataResponse();
814
+    }
815
+
816
+    /**
817
+     * Removes a subadmin from a group
818
+     *
819
+     * @PasswordConfirmationRequired
820
+     *
821
+     * @param string $userId
822
+     * @param string $groupid
823
+     * @return DataResponse
824
+     * @throws OCSException
825
+     */
826
+    public function removeSubAdmin(string $userId, string $groupid): DataResponse {
827
+        $group = $this->groupManager->get($groupid);
828
+        $user = $this->userManager->get($userId);
829
+        $subAdminManager = $this->groupManager->getSubAdmin();
830
+
831
+        // Check if the user exists
832
+        if ($user === null) {
833
+            throw new OCSException('User does not exist', 101);
834
+        }
835
+        // Check if the group exists
836
+        if ($group === null) {
837
+            throw new OCSException('Group does not exist', 101);
838
+        }
839
+        // Check if they are a subadmin of this said group
840
+        if (!$subAdminManager->isSubAdminOfGroup($user, $group)) {
841
+            throw new OCSException('User is not a subadmin of this group', 102);
842
+        }
843
+
844
+        // Go
845
+        $subAdminManager->deleteSubAdmin($user, $group);
846
+        return new DataResponse();
847
+    }
848
+
849
+    /**
850
+     * Get the groups a user is a subadmin of
851
+     *
852
+     * @param string $userId
853
+     * @return DataResponse
854
+     * @throws OCSException
855
+     */
856
+    public function getUserSubAdminGroups(string $userId): DataResponse {
857
+        $groups = $this->getUserSubAdminGroupsData($userId);
858
+        return new DataResponse($groups);
859
+    }
860
+
861
+    /**
862
+     * @NoAdminRequired
863
+     * @PasswordConfirmationRequired
864
+     *
865
+     * resend welcome message
866
+     *
867
+     * @param string $userId
868
+     * @return DataResponse
869
+     * @throws OCSException
870
+     */
871
+    public function resendWelcomeMessage(string $userId): DataResponse {
872
+        $currentLoggedInUser = $this->userSession->getUser();
873
+
874
+        $targetUser = $this->userManager->get($userId);
875
+        if ($targetUser === null) {
876
+            throw new OCSException('', \OCP\API::RESPOND_NOT_FOUND);
877
+        }
878
+
879
+        // Check if admin / subadmin
880
+        $subAdminManager = $this->groupManager->getSubAdmin();
881
+        if (!$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)
882
+            && !$this->groupManager->isAdmin($currentLoggedInUser->getUID())) {
883
+            // No rights
884
+            throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED);
885
+        }
886
+
887
+        $email = $targetUser->getEMailAddress();
888
+        if ($email === '' || $email === null) {
889
+            throw new OCSException('Email address not available', 101);
890
+        }
891
+
892
+        try {
893
+            $emailTemplate = $this->newUserMailHelper->generateTemplate($targetUser, false);
894
+            $this->newUserMailHelper->sendMail($targetUser, $emailTemplate);
895
+        } catch(\Exception $e) {
896
+            $this->logger->logException($e, [
897
+                'message' => "Can't send new user mail to $email",
898
+                'level' => ILogger::ERROR,
899
+                'app' => 'settings',
900
+            ]);
901
+            throw new OCSException('Sending email failed', 102);
902
+        }
903
+
904
+        return new DataResponse();
905
+    }
906 906
 }
Please login to merge, or discard this patch.
lib/private/Server.php 1 patch
Indentation   +1886 added lines, -1886 removed lines patch added patch discarded remove patch
@@ -168,1895 +168,1895 @@
 block discarded – undo
168 168
  * TODO: hookup all manager classes
169 169
  */
170 170
 class Server extends ServerContainer implements IServerContainer {
171
-	/** @var string */
172
-	private $webRoot;
173
-
174
-	/**
175
-	 * @param string $webRoot
176
-	 * @param \OC\Config $config
177
-	 */
178
-	public function __construct($webRoot, \OC\Config $config) {
179
-		parent::__construct();
180
-		$this->webRoot = $webRoot;
181
-
182
-		// To find out if we are running from CLI or not
183
-		$this->registerParameter('isCLI', \OC::$CLI);
184
-
185
-		$this->registerService(\OCP\IServerContainer::class, function (IServerContainer $c) {
186
-			return $c;
187
-		});
188
-
189
-		$this->registerAlias(\OCP\Calendar\IManager::class, \OC\Calendar\Manager::class);
190
-		$this->registerAlias('CalendarManager', \OC\Calendar\Manager::class);
191
-
192
-		$this->registerAlias(\OCP\Calendar\Resource\IManager::class, \OC\Calendar\Resource\Manager::class);
193
-		$this->registerAlias('CalendarResourceBackendManager', \OC\Calendar\Resource\Manager::class);
194
-
195
-		$this->registerAlias(\OCP\Calendar\Room\IManager::class, \OC\Calendar\Room\Manager::class);
196
-		$this->registerAlias('CalendarRoomBackendManager', \OC\Calendar\Room\Manager::class);
197
-
198
-		$this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class);
199
-		$this->registerAlias('ContactsManager', \OCP\Contacts\IManager::class);
200
-
201
-		$this->registerAlias(IActionFactory::class, ActionFactory::class);
202
-
203
-
204
-		$this->registerService(\OCP\IPreview::class, function (Server $c) {
205
-			return new PreviewManager(
206
-				$c->getConfig(),
207
-				$c->getRootFolder(),
208
-				$c->getAppDataDir('preview'),
209
-				$c->getEventDispatcher(),
210
-				$c->getSession()->get('user_id')
211
-			);
212
-		});
213
-		$this->registerAlias('PreviewManager', \OCP\IPreview::class);
214
-
215
-		$this->registerService(\OC\Preview\Watcher::class, function (Server $c) {
216
-			return new \OC\Preview\Watcher(
217
-				$c->getAppDataDir('preview')
218
-			);
219
-		});
220
-
221
-		$this->registerService(\OCP\Encryption\IManager::class, function (Server $c) {
222
-			$view = new View();
223
-			$util = new Encryption\Util(
224
-				$view,
225
-				$c->getUserManager(),
226
-				$c->getGroupManager(),
227
-				$c->getConfig()
228
-			);
229
-			return new Encryption\Manager(
230
-				$c->getConfig(),
231
-				$c->getLogger(),
232
-				$c->getL10N('core'),
233
-				new View(),
234
-				$util,
235
-				new ArrayCache()
236
-			);
237
-		});
238
-		$this->registerAlias('EncryptionManager', \OCP\Encryption\IManager::class);
239
-
240
-		$this->registerService('EncryptionFileHelper', function (Server $c) {
241
-			$util = new Encryption\Util(
242
-				new View(),
243
-				$c->getUserManager(),
244
-				$c->getGroupManager(),
245
-				$c->getConfig()
246
-			);
247
-			return new Encryption\File(
248
-				$util,
249
-				$c->getRootFolder(),
250
-				$c->getShareManager()
251
-			);
252
-		});
253
-
254
-		$this->registerService('EncryptionKeyStorage', function (Server $c) {
255
-			$view = new View();
256
-			$util = new Encryption\Util(
257
-				$view,
258
-				$c->getUserManager(),
259
-				$c->getGroupManager(),
260
-				$c->getConfig()
261
-			);
262
-
263
-			return new Encryption\Keys\Storage($view, $util);
264
-		});
265
-		$this->registerService('TagMapper', function (Server $c) {
266
-			return new TagMapper($c->getDatabaseConnection());
267
-		});
268
-
269
-		$this->registerService(\OCP\ITagManager::class, function (Server $c) {
270
-			$tagMapper = $c->query('TagMapper');
271
-			return new TagManager($tagMapper, $c->getUserSession());
272
-		});
273
-		$this->registerAlias('TagManager', \OCP\ITagManager::class);
274
-
275
-		$this->registerService('SystemTagManagerFactory', function (Server $c) {
276
-			$config = $c->getConfig();
277
-			$factoryClass = $config->getSystemValue('systemtags.managerFactory', SystemTagManagerFactory::class);
278
-			return new $factoryClass($this);
279
-		});
280
-		$this->registerService(\OCP\SystemTag\ISystemTagManager::class, function (Server $c) {
281
-			return $c->query('SystemTagManagerFactory')->getManager();
282
-		});
283
-		$this->registerAlias('SystemTagManager', \OCP\SystemTag\ISystemTagManager::class);
284
-
285
-		$this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function (Server $c) {
286
-			return $c->query('SystemTagManagerFactory')->getObjectMapper();
287
-		});
288
-		$this->registerService('RootFolder', function (Server $c) {
289
-			$manager = \OC\Files\Filesystem::getMountManager(null);
290
-			$view = new View();
291
-			$root = new Root(
292
-				$manager,
293
-				$view,
294
-				null,
295
-				$c->getUserMountCache(),
296
-				$this->getLogger(),
297
-				$this->getUserManager()
298
-			);
299
-			$connector = new HookConnector($root, $view);
300
-			$connector->viewToNode();
301
-
302
-			$previewConnector = new \OC\Preview\WatcherConnector($root, $c->getSystemConfig());
303
-			$previewConnector->connectWatcher();
304
-
305
-			return $root;
306
-		});
307
-		$this->registerAlias('SystemTagObjectMapper', \OCP\SystemTag\ISystemTagObjectMapper::class);
308
-
309
-		$this->registerService(\OCP\Files\IRootFolder::class, function (Server $c) {
310
-			return new LazyRoot(function () use ($c) {
311
-				return $c->query('RootFolder');
312
-			});
313
-		});
314
-		$this->registerAlias('LazyRootFolder', \OCP\Files\IRootFolder::class);
315
-
316
-		$this->registerService(\OC\User\Manager::class, function (Server $c) {
317
-			$config = $c->getConfig();
318
-			return new \OC\User\Manager($config);
319
-		});
320
-		$this->registerAlias('UserManager', \OC\User\Manager::class);
321
-		$this->registerAlias(\OCP\IUserManager::class, \OC\User\Manager::class);
322
-
323
-		$this->registerService(\OCP\IGroupManager::class, function (Server $c) {
324
-			$groupManager = new \OC\Group\Manager($this->getUserManager(), $this->getLogger());
325
-			$groupManager->listen('\OC\Group', 'preCreate', function ($gid) {
326
-				\OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid));
327
-			});
328
-			$groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) {
329
-				\OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID()));
330
-			});
331
-			$groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) {
332
-				\OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID()));
333
-			});
334
-			$groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) {
335
-				\OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID()));
336
-			});
337
-			$groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
338
-				\OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID()));
339
-			});
340
-			$groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
341
-				\OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID()));
342
-				//Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks
343
-				\OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID()));
344
-			});
345
-			return $groupManager;
346
-		});
347
-		$this->registerAlias('GroupManager', \OCP\IGroupManager::class);
348
-
349
-		$this->registerService(Store::class, function (Server $c) {
350
-			$session = $c->getSession();
351
-			if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
352
-				$tokenProvider = $c->query(IProvider::class);
353
-			} else {
354
-				$tokenProvider = null;
355
-			}
356
-			$logger = $c->getLogger();
357
-			return new Store($session, $logger, $tokenProvider);
358
-		});
359
-		$this->registerAlias(IStore::class, Store::class);
360
-		$this->registerService(Authentication\Token\DefaultTokenMapper::class, function (Server $c) {
361
-			$dbConnection = $c->getDatabaseConnection();
362
-			return new Authentication\Token\DefaultTokenMapper($dbConnection);
363
-		});
364
-		$this->registerAlias(IProvider::class, Authentication\Token\Manager::class);
365
-
366
-		$this->registerService(\OC\User\Session::class, function (Server $c) {
367
-			$manager = $c->getUserManager();
368
-			$session = new \OC\Session\Memory('');
369
-			$timeFactory = new TimeFactory();
370
-			// Token providers might require a working database. This code
371
-			// might however be called when ownCloud is not yet setup.
372
-			if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
373
-				$defaultTokenProvider = $c->query(IProvider::class);
374
-			} else {
375
-				$defaultTokenProvider = null;
376
-			}
377
-
378
-			$dispatcher = $c->getEventDispatcher();
379
-
380
-			$userSession = new \OC\User\Session(
381
-				$manager,
382
-				$session,
383
-				$timeFactory,
384
-				$defaultTokenProvider,
385
-				$c->getConfig(),
386
-				$c->getSecureRandom(),
387
-				$c->getLockdownManager(),
388
-				$c->getLogger()
389
-			);
390
-			$userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) {
391
-				\OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password));
392
-			});
393
-			$userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) {
394
-				/** @var $user \OC\User\User */
395
-				\OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password));
396
-			});
397
-			$userSession->listen('\OC\User', 'preDelete', function ($user) use ($dispatcher) {
398
-				/** @var $user \OC\User\User */
399
-				\OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID()));
400
-				$dispatcher->dispatch('OCP\IUser::preDelete', new GenericEvent($user));
401
-			});
402
-			$userSession->listen('\OC\User', 'postDelete', function ($user) {
403
-				/** @var $user \OC\User\User */
404
-				\OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID()));
405
-			});
406
-			$userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) {
407
-				/** @var $user \OC\User\User */
408
-				\OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
409
-			});
410
-			$userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) {
411
-				/** @var $user \OC\User\User */
412
-				\OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
413
-			});
414
-			$userSession->listen('\OC\User', 'preLogin', function ($uid, $password) {
415
-				\OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password));
416
-			});
417
-			$userSession->listen('\OC\User', 'postLogin', function ($user, $password, $isTokenLogin) {
418
-				/** @var $user \OC\User\User */
419
-				\OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'isTokenLogin' => $isTokenLogin));
420
-			});
421
-			$userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) {
422
-				/** @var $user \OC\User\User */
423
-				\OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password));
424
-			});
425
-			$userSession->listen('\OC\User', 'logout', function () {
426
-				\OC_Hook::emit('OC_User', 'logout', array());
427
-			});
428
-			$userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) use ($dispatcher) {
429
-				/** @var $user \OC\User\User */
430
-				\OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue));
431
-				$dispatcher->dispatch('OCP\IUser::changeUser', new GenericEvent($user, ['feature' => $feature, 'oldValue' => $oldValue, 'value' => $value]));
432
-			});
433
-			return $userSession;
434
-		});
435
-		$this->registerAlias(\OCP\IUserSession::class, \OC\User\Session::class);
436
-		$this->registerAlias('UserSession', \OC\User\Session::class);
437
-
438
-		$this->registerAlias(\OCP\Authentication\TwoFactorAuth\IRegistry::class, \OC\Authentication\TwoFactorAuth\Registry::class);
439
-
440
-		$this->registerAlias(\OCP\INavigationManager::class, \OC\NavigationManager::class);
441
-		$this->registerAlias('NavigationManager', \OCP\INavigationManager::class);
442
-
443
-		$this->registerService(\OC\AllConfig::class, function (Server $c) {
444
-			return new \OC\AllConfig(
445
-				$c->getSystemConfig()
446
-			);
447
-		});
448
-		$this->registerAlias('AllConfig', \OC\AllConfig::class);
449
-		$this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class);
450
-
451
-		$this->registerService('SystemConfig', function ($c) use ($config) {
452
-			return new \OC\SystemConfig($config);
453
-		});
454
-
455
-		$this->registerService(\OC\AppConfig::class, function (Server $c) {
456
-			return new \OC\AppConfig($c->getDatabaseConnection());
457
-		});
458
-		$this->registerAlias('AppConfig', \OC\AppConfig::class);
459
-		$this->registerAlias(\OCP\IAppConfig::class, \OC\AppConfig::class);
460
-
461
-		$this->registerService(\OCP\L10N\IFactory::class, function (Server $c) {
462
-			return new \OC\L10N\Factory(
463
-				$c->getConfig(),
464
-				$c->getRequest(),
465
-				$c->getUserSession(),
466
-				\OC::$SERVERROOT
467
-			);
468
-		});
469
-		$this->registerAlias('L10NFactory', \OCP\L10N\IFactory::class);
470
-
471
-		$this->registerService(\OCP\IURLGenerator::class, function (Server $c) {
472
-			$config = $c->getConfig();
473
-			$cacheFactory = $c->getMemCacheFactory();
474
-			$request = $c->getRequest();
475
-			return new \OC\URLGenerator(
476
-				$config,
477
-				$cacheFactory,
478
-				$request
479
-			);
480
-		});
481
-		$this->registerAlias('URLGenerator', \OCP\IURLGenerator::class);
482
-
483
-		$this->registerAlias('AppFetcher', AppFetcher::class);
484
-		$this->registerAlias('CategoryFetcher', CategoryFetcher::class);
485
-
486
-		$this->registerService(\OCP\ICache::class, function ($c) {
487
-			return new Cache\File();
488
-		});
489
-		$this->registerAlias('UserCache', \OCP\ICache::class);
490
-
491
-		$this->registerService(Factory::class, function (Server $c) {
492
-
493
-			$arrayCacheFactory = new \OC\Memcache\Factory('', $c->getLogger(),
494
-				ArrayCache::class,
495
-				ArrayCache::class,
496
-				ArrayCache::class
497
-			);
498
-			$config = $c->getConfig();
499
-			$request = $c->getRequest();
500
-			$urlGenerator = new URLGenerator($config, $arrayCacheFactory, $request);
501
-
502
-			if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
503
-				$v = \OC_App::getAppVersions();
504
-				$v['core'] = implode(',', \OC_Util::getVersion());
505
-				$version = implode(',', $v);
506
-				$instanceId = \OC_Util::getInstanceId();
507
-				$path = \OC::$SERVERROOT;
508
-				$prefix = md5($instanceId . '-' . $version . '-' . $path);
509
-				return new \OC\Memcache\Factory($prefix, $c->getLogger(),
510
-					$config->getSystemValue('memcache.local', null),
511
-					$config->getSystemValue('memcache.distributed', null),
512
-					$config->getSystemValue('memcache.locking', null)
513
-				);
514
-			}
515
-			return $arrayCacheFactory;
516
-
517
-		});
518
-		$this->registerAlias('MemCacheFactory', Factory::class);
519
-		$this->registerAlias(ICacheFactory::class, Factory::class);
520
-
521
-		$this->registerService('RedisFactory', function (Server $c) {
522
-			$systemConfig = $c->getSystemConfig();
523
-			return new RedisFactory($systemConfig);
524
-		});
525
-
526
-		$this->registerService(\OCP\Activity\IManager::class, function (Server $c) {
527
-			return new \OC\Activity\Manager(
528
-				$c->getRequest(),
529
-				$c->getUserSession(),
530
-				$c->getConfig(),
531
-				$c->query(IValidator::class)
532
-			);
533
-		});
534
-		$this->registerAlias('ActivityManager', \OCP\Activity\IManager::class);
535
-
536
-		$this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) {
537
-			return new \OC\Activity\EventMerger(
538
-				$c->getL10N('lib')
539
-			);
540
-		});
541
-		$this->registerAlias(IValidator::class, Validator::class);
542
-
543
-		$this->registerService(AvatarManager::class, function(Server $c) {
544
-			return new AvatarManager(
545
-				$c->query(\OC\User\Manager::class),
546
-				$c->getAppDataDir('avatar'),
547
-				$c->getL10N('lib'),
548
-				$c->getLogger(),
549
-				$c->getConfig()
550
-			);
551
-		});
552
-		$this->registerAlias(\OCP\IAvatarManager::class, AvatarManager::class);
553
-		$this->registerAlias('AvatarManager', AvatarManager::class);
554
-
555
-		$this->registerAlias(\OCP\Support\CrashReport\IRegistry::class, \OC\Support\CrashReport\Registry::class);
556
-
557
-		$this->registerService(\OC\Log::class, function (Server $c) {
558
-			$logType = $c->query('AllConfig')->getSystemValue('log_type', 'file');
559
-			$factory = new LogFactory($c, $this->getSystemConfig());
560
-			$logger = $factory->get($logType);
561
-			$registry = $c->query(\OCP\Support\CrashReport\IRegistry::class);
562
-
563
-			return new Log($logger, $this->getSystemConfig(), null, $registry);
564
-		});
565
-		$this->registerAlias(\OCP\ILogger::class, \OC\Log::class);
566
-		$this->registerAlias('Logger', \OC\Log::class);
567
-
568
-		$this->registerService(ILogFactory::class, function (Server $c) {
569
-			return new LogFactory($c, $this->getSystemConfig());
570
-		});
571
-
572
-		$this->registerService(\OCP\BackgroundJob\IJobList::class, function (Server $c) {
573
-			$config = $c->getConfig();
574
-			return new \OC\BackgroundJob\JobList(
575
-				$c->getDatabaseConnection(),
576
-				$config,
577
-				new TimeFactory()
578
-			);
579
-		});
580
-		$this->registerAlias('JobList', \OCP\BackgroundJob\IJobList::class);
581
-
582
-		$this->registerService(\OCP\Route\IRouter::class, function (Server $c) {
583
-			$cacheFactory = $c->getMemCacheFactory();
584
-			$logger = $c->getLogger();
585
-			if ($cacheFactory->isLocalCacheAvailable()) {
586
-				$router = new \OC\Route\CachingRouter($cacheFactory->createLocal('route'), $logger);
587
-			} else {
588
-				$router = new \OC\Route\Router($logger);
589
-			}
590
-			return $router;
591
-		});
592
-		$this->registerAlias('Router', \OCP\Route\IRouter::class);
593
-
594
-		$this->registerService(\OCP\ISearch::class, function ($c) {
595
-			return new Search();
596
-		});
597
-		$this->registerAlias('Search', \OCP\ISearch::class);
598
-
599
-		$this->registerService(\OC\Security\RateLimiting\Limiter::class, function (Server $c) {
600
-			return new \OC\Security\RateLimiting\Limiter(
601
-				$this->getUserSession(),
602
-				$this->getRequest(),
603
-				new \OC\AppFramework\Utility\TimeFactory(),
604
-				$c->query(\OC\Security\RateLimiting\Backend\IBackend::class)
605
-			);
606
-		});
607
-		$this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) {
608
-			return new \OC\Security\RateLimiting\Backend\MemoryCache(
609
-				$this->getMemCacheFactory(),
610
-				new \OC\AppFramework\Utility\TimeFactory()
611
-			);
612
-		});
613
-
614
-		$this->registerService(\OCP\Security\ISecureRandom::class, function ($c) {
615
-			return new SecureRandom();
616
-		});
617
-		$this->registerAlias('SecureRandom', \OCP\Security\ISecureRandom::class);
618
-
619
-		$this->registerService(\OCP\Security\ICrypto::class, function (Server $c) {
620
-			return new Crypto($c->getConfig(), $c->getSecureRandom());
621
-		});
622
-		$this->registerAlias('Crypto', \OCP\Security\ICrypto::class);
623
-
624
-		$this->registerService(\OCP\Security\IHasher::class, function (Server $c) {
625
-			return new Hasher($c->getConfig());
626
-		});
627
-		$this->registerAlias('Hasher', \OCP\Security\IHasher::class);
628
-
629
-		$this->registerService(\OCP\Security\ICredentialsManager::class, function (Server $c) {
630
-			return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection());
631
-		});
632
-		$this->registerAlias('CredentialsManager', \OCP\Security\ICredentialsManager::class);
633
-
634
-		$this->registerService(IDBConnection::class, function (Server $c) {
635
-			$systemConfig = $c->getSystemConfig();
636
-			$factory = new \OC\DB\ConnectionFactory($systemConfig);
637
-			$type = $systemConfig->getValue('dbtype', 'sqlite');
638
-			if (!$factory->isValidType($type)) {
639
-				throw new \OC\DatabaseException('Invalid database type');
640
-			}
641
-			$connectionParams = $factory->createConnectionParams();
642
-			$connection = $factory->getConnection($type, $connectionParams);
643
-			$connection->getConfiguration()->setSQLLogger($c->getQueryLogger());
644
-			return $connection;
645
-		});
646
-		$this->registerAlias('DatabaseConnection', IDBConnection::class);
647
-
648
-
649
-		$this->registerService(\OCP\Http\Client\IClientService::class, function (Server $c) {
650
-			$user = \OC_User::getUser();
651
-			$uid = $user ? $user : null;
652
-			return new ClientService(
653
-				$c->getConfig(),
654
-				new \OC\Security\CertificateManager(
655
-					$uid,
656
-					new View(),
657
-					$c->getConfig(),
658
-					$c->getLogger(),
659
-					$c->getSecureRandom()
660
-				)
661
-			);
662
-		});
663
-		$this->registerAlias('HttpClientService', \OCP\Http\Client\IClientService::class);
664
-		$this->registerService(\OCP\Diagnostics\IEventLogger::class, function (Server $c) {
665
-			$eventLogger = new EventLogger();
666
-			if ($c->getSystemConfig()->getValue('debug', false)) {
667
-				// In debug mode, module is being activated by default
668
-				$eventLogger->activate();
669
-			}
670
-			return $eventLogger;
671
-		});
672
-		$this->registerAlias('EventLogger', \OCP\Diagnostics\IEventLogger::class);
673
-
674
-		$this->registerService(\OCP\Diagnostics\IQueryLogger::class, function (Server $c) {
675
-			$queryLogger = new QueryLogger();
676
-			if ($c->getSystemConfig()->getValue('debug', false)) {
677
-				// In debug mode, module is being activated by default
678
-				$queryLogger->activate();
679
-			}
680
-			return $queryLogger;
681
-		});
682
-		$this->registerAlias('QueryLogger', \OCP\Diagnostics\IQueryLogger::class);
683
-
684
-		$this->registerService(TempManager::class, function (Server $c) {
685
-			return new TempManager(
686
-				$c->getLogger(),
687
-				$c->getConfig()
688
-			);
689
-		});
690
-		$this->registerAlias('TempManager', TempManager::class);
691
-		$this->registerAlias(ITempManager::class, TempManager::class);
692
-
693
-		$this->registerService(AppManager::class, function (Server $c) {
694
-			return new \OC\App\AppManager(
695
-				$c->getUserSession(),
696
-				$c->query(\OC\AppConfig::class),
697
-				$c->getGroupManager(),
698
-				$c->getMemCacheFactory(),
699
-				$c->getEventDispatcher()
700
-			);
701
-		});
702
-		$this->registerAlias('AppManager', AppManager::class);
703
-		$this->registerAlias(IAppManager::class, AppManager::class);
704
-
705
-		$this->registerService(\OCP\IDateTimeZone::class, function (Server $c) {
706
-			return new DateTimeZone(
707
-				$c->getConfig(),
708
-				$c->getSession()
709
-			);
710
-		});
711
-		$this->registerAlias('DateTimeZone', \OCP\IDateTimeZone::class);
712
-
713
-		$this->registerService(\OCP\IDateTimeFormatter::class, function (Server $c) {
714
-			$language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null);
715
-
716
-			return new DateTimeFormatter(
717
-				$c->getDateTimeZone()->getTimeZone(),
718
-				$c->getL10N('lib', $language)
719
-			);
720
-		});
721
-		$this->registerAlias('DateTimeFormatter', \OCP\IDateTimeFormatter::class);
722
-
723
-		$this->registerService(\OCP\Files\Config\IUserMountCache::class, function (Server $c) {
724
-			$mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger());
725
-			$listener = new UserMountCacheListener($mountCache);
726
-			$listener->listen($c->getUserManager());
727
-			return $mountCache;
728
-		});
729
-		$this->registerAlias('UserMountCache', \OCP\Files\Config\IUserMountCache::class);
730
-
731
-		$this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function (Server $c) {
732
-			$loader = \OC\Files\Filesystem::getLoader();
733
-			$mountCache = $c->query('UserMountCache');
734
-			$manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache);
735
-
736
-			// builtin providers
737
-
738
-			$config = $c->getConfig();
739
-			$manager->registerProvider(new CacheMountProvider($config));
740
-			$manager->registerHomeProvider(new LocalHomeMountProvider());
741
-			$manager->registerHomeProvider(new ObjectHomeMountProvider($config));
742
-
743
-			return $manager;
744
-		});
745
-		$this->registerAlias('MountConfigManager', \OCP\Files\Config\IMountProviderCollection::class);
746
-
747
-		$this->registerService('IniWrapper', function ($c) {
748
-			return new IniGetWrapper();
749
-		});
750
-		$this->registerService('AsyncCommandBus', function (Server $c) {
751
-			$busClass = $c->getConfig()->getSystemValue('commandbus');
752
-			if ($busClass) {
753
-				list($app, $class) = explode('::', $busClass, 2);
754
-				if ($c->getAppManager()->isInstalled($app)) {
755
-					\OC_App::loadApp($app);
756
-					return $c->query($class);
757
-				} else {
758
-					throw new ServiceUnavailableException("The app providing the command bus ($app) is not enabled");
759
-				}
760
-			} else {
761
-				$jobList = $c->getJobList();
762
-				return new CronBus($jobList);
763
-			}
764
-		});
765
-		$this->registerService('TrustedDomainHelper', function ($c) {
766
-			return new TrustedDomainHelper($this->getConfig());
767
-		});
768
-		$this->registerService(Throttler::class, function (Server $c) {
769
-			return new Throttler(
770
-				$c->getDatabaseConnection(),
771
-				new TimeFactory(),
772
-				$c->getLogger(),
773
-				$c->getConfig()
774
-			);
775
-		});
776
-		$this->registerAlias('Throttler', Throttler::class);
777
-		$this->registerService('IntegrityCodeChecker', function (Server $c) {
778
-			// IConfig and IAppManager requires a working database. This code
779
-			// might however be called when ownCloud is not yet setup.
780
-			if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
781
-				$config = $c->getConfig();
782
-				$appManager = $c->getAppManager();
783
-			} else {
784
-				$config = null;
785
-				$appManager = null;
786
-			}
787
-
788
-			return new Checker(
789
-				new EnvironmentHelper(),
790
-				new FileAccessHelper(),
791
-				new AppLocator(),
792
-				$config,
793
-				$c->getMemCacheFactory(),
794
-				$appManager,
795
-				$c->getTempManager()
796
-			);
797
-		});
798
-		$this->registerService(\OCP\IRequest::class, function ($c) {
799
-			if (isset($this['urlParams'])) {
800
-				$urlParams = $this['urlParams'];
801
-			} else {
802
-				$urlParams = [];
803
-			}
804
-
805
-			if (defined('PHPUNIT_RUN') && PHPUNIT_RUN
806
-				&& in_array('fakeinput', stream_get_wrappers())
807
-			) {
808
-				$stream = 'fakeinput://data';
809
-			} else {
810
-				$stream = 'php://input';
811
-			}
812
-
813
-			return new Request(
814
-				[
815
-					'get' => $_GET,
816
-					'post' => $_POST,
817
-					'files' => $_FILES,
818
-					'server' => $_SERVER,
819
-					'env' => $_ENV,
820
-					'cookies' => $_COOKIE,
821
-					'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
822
-						? $_SERVER['REQUEST_METHOD']
823
-						: '',
824
-					'urlParams' => $urlParams,
825
-				],
826
-				$this->getSecureRandom(),
827
-				$this->getConfig(),
828
-				$this->getCsrfTokenManager(),
829
-				$stream
830
-			);
831
-		});
832
-		$this->registerAlias('Request', \OCP\IRequest::class);
833
-
834
-		$this->registerService(\OCP\Mail\IMailer::class, function (Server $c) {
835
-			return new Mailer(
836
-				$c->getConfig(),
837
-				$c->getLogger(),
838
-				$c->query(Defaults::class),
839
-				$c->getURLGenerator(),
840
-				$c->getL10N('lib')
841
-			);
842
-		});
843
-		$this->registerAlias('Mailer', \OCP\Mail\IMailer::class);
844
-
845
-		$this->registerService('LDAPProvider', function (Server $c) {
846
-			$config = $c->getConfig();
847
-			$factoryClass = $config->getSystemValue('ldapProviderFactory', null);
848
-			if (is_null($factoryClass)) {
849
-				throw new \Exception('ldapProviderFactory not set');
850
-			}
851
-			/** @var \OCP\LDAP\ILDAPProviderFactory $factory */
852
-			$factory = new $factoryClass($this);
853
-			return $factory->getLDAPProvider();
854
-		});
855
-		$this->registerService(ILockingProvider::class, function (Server $c) {
856
-			$ini = $c->getIniWrapper();
857
-			$config = $c->getConfig();
858
-			$ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time')));
859
-			if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
860
-				/** @var \OC\Memcache\Factory $memcacheFactory */
861
-				$memcacheFactory = $c->getMemCacheFactory();
862
-				$memcache = $memcacheFactory->createLocking('lock');
863
-				if (!($memcache instanceof \OC\Memcache\NullCache)) {
864
-					return new MemcacheLockingProvider($memcache, $ttl);
865
-				}
866
-				return new DBLockingProvider(
867
-					$c->getDatabaseConnection(),
868
-					$c->getLogger(),
869
-					new TimeFactory(),
870
-					$ttl,
871
-					!\OC::$CLI
872
-				);
873
-			}
874
-			return new NoopLockingProvider();
875
-		});
876
-		$this->registerAlias('LockingProvider', ILockingProvider::class);
877
-
878
-		$this->registerService(\OCP\Files\Mount\IMountManager::class, function () {
879
-			return new \OC\Files\Mount\Manager();
880
-		});
881
-		$this->registerAlias('MountManager', \OCP\Files\Mount\IMountManager::class);
882
-
883
-		$this->registerService(\OCP\Files\IMimeTypeDetector::class, function (Server $c) {
884
-			return new \OC\Files\Type\Detection(
885
-				$c->getURLGenerator(),
886
-				\OC::$configDir,
887
-				\OC::$SERVERROOT . '/resources/config/'
888
-			);
889
-		});
890
-		$this->registerAlias('MimeTypeDetector', \OCP\Files\IMimeTypeDetector::class);
891
-
892
-		$this->registerService(\OCP\Files\IMimeTypeLoader::class, function (Server $c) {
893
-			return new \OC\Files\Type\Loader(
894
-				$c->getDatabaseConnection()
895
-			);
896
-		});
897
-		$this->registerAlias('MimeTypeLoader', \OCP\Files\IMimeTypeLoader::class);
898
-		$this->registerService(BundleFetcher::class, function () {
899
-			return new BundleFetcher($this->getL10N('lib'));
900
-		});
901
-		$this->registerService(\OCP\Notification\IManager::class, function (Server $c) {
902
-			return new Manager(
903
-				$c->query(IValidator::class)
904
-			);
905
-		});
906
-		$this->registerAlias('NotificationManager', \OCP\Notification\IManager::class);
907
-
908
-		$this->registerService(\OC\CapabilitiesManager::class, function (Server $c) {
909
-			$manager = new \OC\CapabilitiesManager($c->getLogger());
910
-			$manager->registerCapability(function () use ($c) {
911
-				return new \OC\OCS\CoreCapabilities($c->getConfig());
912
-			});
913
-			$manager->registerCapability(function () use ($c) {
914
-				return $c->query(\OC\Security\Bruteforce\Capabilities::class);
915
-			});
916
-			return $manager;
917
-		});
918
-		$this->registerAlias('CapabilitiesManager', \OC\CapabilitiesManager::class);
919
-
920
-		$this->registerService(\OCP\Comments\ICommentsManager::class, function (Server $c) {
921
-			$config = $c->getConfig();
922
-			$factoryClass = $config->getSystemValue('comments.managerFactory', CommentsManagerFactory::class);
923
-			/** @var \OCP\Comments\ICommentsManagerFactory $factory */
924
-			$factory = new $factoryClass($this);
925
-			$manager = $factory->getManager();
926
-
927
-			$manager->registerDisplayNameResolver('user', function($id) use ($c) {
928
-				$manager = $c->getUserManager();
929
-				$user = $manager->get($id);
930
-				if(is_null($user)) {
931
-					$l = $c->getL10N('core');
932
-					$displayName = $l->t('Unknown user');
933
-				} else {
934
-					$displayName = $user->getDisplayName();
935
-				}
936
-				return $displayName;
937
-			});
938
-
939
-			return $manager;
940
-		});
941
-		$this->registerAlias('CommentsManager', \OCP\Comments\ICommentsManager::class);
942
-
943
-		$this->registerService('ThemingDefaults', function (Server $c) {
944
-			/*
171
+    /** @var string */
172
+    private $webRoot;
173
+
174
+    /**
175
+     * @param string $webRoot
176
+     * @param \OC\Config $config
177
+     */
178
+    public function __construct($webRoot, \OC\Config $config) {
179
+        parent::__construct();
180
+        $this->webRoot = $webRoot;
181
+
182
+        // To find out if we are running from CLI or not
183
+        $this->registerParameter('isCLI', \OC::$CLI);
184
+
185
+        $this->registerService(\OCP\IServerContainer::class, function (IServerContainer $c) {
186
+            return $c;
187
+        });
188
+
189
+        $this->registerAlias(\OCP\Calendar\IManager::class, \OC\Calendar\Manager::class);
190
+        $this->registerAlias('CalendarManager', \OC\Calendar\Manager::class);
191
+
192
+        $this->registerAlias(\OCP\Calendar\Resource\IManager::class, \OC\Calendar\Resource\Manager::class);
193
+        $this->registerAlias('CalendarResourceBackendManager', \OC\Calendar\Resource\Manager::class);
194
+
195
+        $this->registerAlias(\OCP\Calendar\Room\IManager::class, \OC\Calendar\Room\Manager::class);
196
+        $this->registerAlias('CalendarRoomBackendManager', \OC\Calendar\Room\Manager::class);
197
+
198
+        $this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class);
199
+        $this->registerAlias('ContactsManager', \OCP\Contacts\IManager::class);
200
+
201
+        $this->registerAlias(IActionFactory::class, ActionFactory::class);
202
+
203
+
204
+        $this->registerService(\OCP\IPreview::class, function (Server $c) {
205
+            return new PreviewManager(
206
+                $c->getConfig(),
207
+                $c->getRootFolder(),
208
+                $c->getAppDataDir('preview'),
209
+                $c->getEventDispatcher(),
210
+                $c->getSession()->get('user_id')
211
+            );
212
+        });
213
+        $this->registerAlias('PreviewManager', \OCP\IPreview::class);
214
+
215
+        $this->registerService(\OC\Preview\Watcher::class, function (Server $c) {
216
+            return new \OC\Preview\Watcher(
217
+                $c->getAppDataDir('preview')
218
+            );
219
+        });
220
+
221
+        $this->registerService(\OCP\Encryption\IManager::class, function (Server $c) {
222
+            $view = new View();
223
+            $util = new Encryption\Util(
224
+                $view,
225
+                $c->getUserManager(),
226
+                $c->getGroupManager(),
227
+                $c->getConfig()
228
+            );
229
+            return new Encryption\Manager(
230
+                $c->getConfig(),
231
+                $c->getLogger(),
232
+                $c->getL10N('core'),
233
+                new View(),
234
+                $util,
235
+                new ArrayCache()
236
+            );
237
+        });
238
+        $this->registerAlias('EncryptionManager', \OCP\Encryption\IManager::class);
239
+
240
+        $this->registerService('EncryptionFileHelper', function (Server $c) {
241
+            $util = new Encryption\Util(
242
+                new View(),
243
+                $c->getUserManager(),
244
+                $c->getGroupManager(),
245
+                $c->getConfig()
246
+            );
247
+            return new Encryption\File(
248
+                $util,
249
+                $c->getRootFolder(),
250
+                $c->getShareManager()
251
+            );
252
+        });
253
+
254
+        $this->registerService('EncryptionKeyStorage', function (Server $c) {
255
+            $view = new View();
256
+            $util = new Encryption\Util(
257
+                $view,
258
+                $c->getUserManager(),
259
+                $c->getGroupManager(),
260
+                $c->getConfig()
261
+            );
262
+
263
+            return new Encryption\Keys\Storage($view, $util);
264
+        });
265
+        $this->registerService('TagMapper', function (Server $c) {
266
+            return new TagMapper($c->getDatabaseConnection());
267
+        });
268
+
269
+        $this->registerService(\OCP\ITagManager::class, function (Server $c) {
270
+            $tagMapper = $c->query('TagMapper');
271
+            return new TagManager($tagMapper, $c->getUserSession());
272
+        });
273
+        $this->registerAlias('TagManager', \OCP\ITagManager::class);
274
+
275
+        $this->registerService('SystemTagManagerFactory', function (Server $c) {
276
+            $config = $c->getConfig();
277
+            $factoryClass = $config->getSystemValue('systemtags.managerFactory', SystemTagManagerFactory::class);
278
+            return new $factoryClass($this);
279
+        });
280
+        $this->registerService(\OCP\SystemTag\ISystemTagManager::class, function (Server $c) {
281
+            return $c->query('SystemTagManagerFactory')->getManager();
282
+        });
283
+        $this->registerAlias('SystemTagManager', \OCP\SystemTag\ISystemTagManager::class);
284
+
285
+        $this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function (Server $c) {
286
+            return $c->query('SystemTagManagerFactory')->getObjectMapper();
287
+        });
288
+        $this->registerService('RootFolder', function (Server $c) {
289
+            $manager = \OC\Files\Filesystem::getMountManager(null);
290
+            $view = new View();
291
+            $root = new Root(
292
+                $manager,
293
+                $view,
294
+                null,
295
+                $c->getUserMountCache(),
296
+                $this->getLogger(),
297
+                $this->getUserManager()
298
+            );
299
+            $connector = new HookConnector($root, $view);
300
+            $connector->viewToNode();
301
+
302
+            $previewConnector = new \OC\Preview\WatcherConnector($root, $c->getSystemConfig());
303
+            $previewConnector->connectWatcher();
304
+
305
+            return $root;
306
+        });
307
+        $this->registerAlias('SystemTagObjectMapper', \OCP\SystemTag\ISystemTagObjectMapper::class);
308
+
309
+        $this->registerService(\OCP\Files\IRootFolder::class, function (Server $c) {
310
+            return new LazyRoot(function () use ($c) {
311
+                return $c->query('RootFolder');
312
+            });
313
+        });
314
+        $this->registerAlias('LazyRootFolder', \OCP\Files\IRootFolder::class);
315
+
316
+        $this->registerService(\OC\User\Manager::class, function (Server $c) {
317
+            $config = $c->getConfig();
318
+            return new \OC\User\Manager($config);
319
+        });
320
+        $this->registerAlias('UserManager', \OC\User\Manager::class);
321
+        $this->registerAlias(\OCP\IUserManager::class, \OC\User\Manager::class);
322
+
323
+        $this->registerService(\OCP\IGroupManager::class, function (Server $c) {
324
+            $groupManager = new \OC\Group\Manager($this->getUserManager(), $this->getLogger());
325
+            $groupManager->listen('\OC\Group', 'preCreate', function ($gid) {
326
+                \OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid));
327
+            });
328
+            $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) {
329
+                \OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID()));
330
+            });
331
+            $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) {
332
+                \OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID()));
333
+            });
334
+            $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) {
335
+                \OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID()));
336
+            });
337
+            $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
338
+                \OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID()));
339
+            });
340
+            $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
341
+                \OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID()));
342
+                //Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks
343
+                \OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID()));
344
+            });
345
+            return $groupManager;
346
+        });
347
+        $this->registerAlias('GroupManager', \OCP\IGroupManager::class);
348
+
349
+        $this->registerService(Store::class, function (Server $c) {
350
+            $session = $c->getSession();
351
+            if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
352
+                $tokenProvider = $c->query(IProvider::class);
353
+            } else {
354
+                $tokenProvider = null;
355
+            }
356
+            $logger = $c->getLogger();
357
+            return new Store($session, $logger, $tokenProvider);
358
+        });
359
+        $this->registerAlias(IStore::class, Store::class);
360
+        $this->registerService(Authentication\Token\DefaultTokenMapper::class, function (Server $c) {
361
+            $dbConnection = $c->getDatabaseConnection();
362
+            return new Authentication\Token\DefaultTokenMapper($dbConnection);
363
+        });
364
+        $this->registerAlias(IProvider::class, Authentication\Token\Manager::class);
365
+
366
+        $this->registerService(\OC\User\Session::class, function (Server $c) {
367
+            $manager = $c->getUserManager();
368
+            $session = new \OC\Session\Memory('');
369
+            $timeFactory = new TimeFactory();
370
+            // Token providers might require a working database. This code
371
+            // might however be called when ownCloud is not yet setup.
372
+            if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
373
+                $defaultTokenProvider = $c->query(IProvider::class);
374
+            } else {
375
+                $defaultTokenProvider = null;
376
+            }
377
+
378
+            $dispatcher = $c->getEventDispatcher();
379
+
380
+            $userSession = new \OC\User\Session(
381
+                $manager,
382
+                $session,
383
+                $timeFactory,
384
+                $defaultTokenProvider,
385
+                $c->getConfig(),
386
+                $c->getSecureRandom(),
387
+                $c->getLockdownManager(),
388
+                $c->getLogger()
389
+            );
390
+            $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) {
391
+                \OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password));
392
+            });
393
+            $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) {
394
+                /** @var $user \OC\User\User */
395
+                \OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password));
396
+            });
397
+            $userSession->listen('\OC\User', 'preDelete', function ($user) use ($dispatcher) {
398
+                /** @var $user \OC\User\User */
399
+                \OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID()));
400
+                $dispatcher->dispatch('OCP\IUser::preDelete', new GenericEvent($user));
401
+            });
402
+            $userSession->listen('\OC\User', 'postDelete', function ($user) {
403
+                /** @var $user \OC\User\User */
404
+                \OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID()));
405
+            });
406
+            $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) {
407
+                /** @var $user \OC\User\User */
408
+                \OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
409
+            });
410
+            $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) {
411
+                /** @var $user \OC\User\User */
412
+                \OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
413
+            });
414
+            $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) {
415
+                \OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password));
416
+            });
417
+            $userSession->listen('\OC\User', 'postLogin', function ($user, $password, $isTokenLogin) {
418
+                /** @var $user \OC\User\User */
419
+                \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'isTokenLogin' => $isTokenLogin));
420
+            });
421
+            $userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) {
422
+                /** @var $user \OC\User\User */
423
+                \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password));
424
+            });
425
+            $userSession->listen('\OC\User', 'logout', function () {
426
+                \OC_Hook::emit('OC_User', 'logout', array());
427
+            });
428
+            $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) use ($dispatcher) {
429
+                /** @var $user \OC\User\User */
430
+                \OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue));
431
+                $dispatcher->dispatch('OCP\IUser::changeUser', new GenericEvent($user, ['feature' => $feature, 'oldValue' => $oldValue, 'value' => $value]));
432
+            });
433
+            return $userSession;
434
+        });
435
+        $this->registerAlias(\OCP\IUserSession::class, \OC\User\Session::class);
436
+        $this->registerAlias('UserSession', \OC\User\Session::class);
437
+
438
+        $this->registerAlias(\OCP\Authentication\TwoFactorAuth\IRegistry::class, \OC\Authentication\TwoFactorAuth\Registry::class);
439
+
440
+        $this->registerAlias(\OCP\INavigationManager::class, \OC\NavigationManager::class);
441
+        $this->registerAlias('NavigationManager', \OCP\INavigationManager::class);
442
+
443
+        $this->registerService(\OC\AllConfig::class, function (Server $c) {
444
+            return new \OC\AllConfig(
445
+                $c->getSystemConfig()
446
+            );
447
+        });
448
+        $this->registerAlias('AllConfig', \OC\AllConfig::class);
449
+        $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class);
450
+
451
+        $this->registerService('SystemConfig', function ($c) use ($config) {
452
+            return new \OC\SystemConfig($config);
453
+        });
454
+
455
+        $this->registerService(\OC\AppConfig::class, function (Server $c) {
456
+            return new \OC\AppConfig($c->getDatabaseConnection());
457
+        });
458
+        $this->registerAlias('AppConfig', \OC\AppConfig::class);
459
+        $this->registerAlias(\OCP\IAppConfig::class, \OC\AppConfig::class);
460
+
461
+        $this->registerService(\OCP\L10N\IFactory::class, function (Server $c) {
462
+            return new \OC\L10N\Factory(
463
+                $c->getConfig(),
464
+                $c->getRequest(),
465
+                $c->getUserSession(),
466
+                \OC::$SERVERROOT
467
+            );
468
+        });
469
+        $this->registerAlias('L10NFactory', \OCP\L10N\IFactory::class);
470
+
471
+        $this->registerService(\OCP\IURLGenerator::class, function (Server $c) {
472
+            $config = $c->getConfig();
473
+            $cacheFactory = $c->getMemCacheFactory();
474
+            $request = $c->getRequest();
475
+            return new \OC\URLGenerator(
476
+                $config,
477
+                $cacheFactory,
478
+                $request
479
+            );
480
+        });
481
+        $this->registerAlias('URLGenerator', \OCP\IURLGenerator::class);
482
+
483
+        $this->registerAlias('AppFetcher', AppFetcher::class);
484
+        $this->registerAlias('CategoryFetcher', CategoryFetcher::class);
485
+
486
+        $this->registerService(\OCP\ICache::class, function ($c) {
487
+            return new Cache\File();
488
+        });
489
+        $this->registerAlias('UserCache', \OCP\ICache::class);
490
+
491
+        $this->registerService(Factory::class, function (Server $c) {
492
+
493
+            $arrayCacheFactory = new \OC\Memcache\Factory('', $c->getLogger(),
494
+                ArrayCache::class,
495
+                ArrayCache::class,
496
+                ArrayCache::class
497
+            );
498
+            $config = $c->getConfig();
499
+            $request = $c->getRequest();
500
+            $urlGenerator = new URLGenerator($config, $arrayCacheFactory, $request);
501
+
502
+            if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
503
+                $v = \OC_App::getAppVersions();
504
+                $v['core'] = implode(',', \OC_Util::getVersion());
505
+                $version = implode(',', $v);
506
+                $instanceId = \OC_Util::getInstanceId();
507
+                $path = \OC::$SERVERROOT;
508
+                $prefix = md5($instanceId . '-' . $version . '-' . $path);
509
+                return new \OC\Memcache\Factory($prefix, $c->getLogger(),
510
+                    $config->getSystemValue('memcache.local', null),
511
+                    $config->getSystemValue('memcache.distributed', null),
512
+                    $config->getSystemValue('memcache.locking', null)
513
+                );
514
+            }
515
+            return $arrayCacheFactory;
516
+
517
+        });
518
+        $this->registerAlias('MemCacheFactory', Factory::class);
519
+        $this->registerAlias(ICacheFactory::class, Factory::class);
520
+
521
+        $this->registerService('RedisFactory', function (Server $c) {
522
+            $systemConfig = $c->getSystemConfig();
523
+            return new RedisFactory($systemConfig);
524
+        });
525
+
526
+        $this->registerService(\OCP\Activity\IManager::class, function (Server $c) {
527
+            return new \OC\Activity\Manager(
528
+                $c->getRequest(),
529
+                $c->getUserSession(),
530
+                $c->getConfig(),
531
+                $c->query(IValidator::class)
532
+            );
533
+        });
534
+        $this->registerAlias('ActivityManager', \OCP\Activity\IManager::class);
535
+
536
+        $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) {
537
+            return new \OC\Activity\EventMerger(
538
+                $c->getL10N('lib')
539
+            );
540
+        });
541
+        $this->registerAlias(IValidator::class, Validator::class);
542
+
543
+        $this->registerService(AvatarManager::class, function(Server $c) {
544
+            return new AvatarManager(
545
+                $c->query(\OC\User\Manager::class),
546
+                $c->getAppDataDir('avatar'),
547
+                $c->getL10N('lib'),
548
+                $c->getLogger(),
549
+                $c->getConfig()
550
+            );
551
+        });
552
+        $this->registerAlias(\OCP\IAvatarManager::class, AvatarManager::class);
553
+        $this->registerAlias('AvatarManager', AvatarManager::class);
554
+
555
+        $this->registerAlias(\OCP\Support\CrashReport\IRegistry::class, \OC\Support\CrashReport\Registry::class);
556
+
557
+        $this->registerService(\OC\Log::class, function (Server $c) {
558
+            $logType = $c->query('AllConfig')->getSystemValue('log_type', 'file');
559
+            $factory = new LogFactory($c, $this->getSystemConfig());
560
+            $logger = $factory->get($logType);
561
+            $registry = $c->query(\OCP\Support\CrashReport\IRegistry::class);
562
+
563
+            return new Log($logger, $this->getSystemConfig(), null, $registry);
564
+        });
565
+        $this->registerAlias(\OCP\ILogger::class, \OC\Log::class);
566
+        $this->registerAlias('Logger', \OC\Log::class);
567
+
568
+        $this->registerService(ILogFactory::class, function (Server $c) {
569
+            return new LogFactory($c, $this->getSystemConfig());
570
+        });
571
+
572
+        $this->registerService(\OCP\BackgroundJob\IJobList::class, function (Server $c) {
573
+            $config = $c->getConfig();
574
+            return new \OC\BackgroundJob\JobList(
575
+                $c->getDatabaseConnection(),
576
+                $config,
577
+                new TimeFactory()
578
+            );
579
+        });
580
+        $this->registerAlias('JobList', \OCP\BackgroundJob\IJobList::class);
581
+
582
+        $this->registerService(\OCP\Route\IRouter::class, function (Server $c) {
583
+            $cacheFactory = $c->getMemCacheFactory();
584
+            $logger = $c->getLogger();
585
+            if ($cacheFactory->isLocalCacheAvailable()) {
586
+                $router = new \OC\Route\CachingRouter($cacheFactory->createLocal('route'), $logger);
587
+            } else {
588
+                $router = new \OC\Route\Router($logger);
589
+            }
590
+            return $router;
591
+        });
592
+        $this->registerAlias('Router', \OCP\Route\IRouter::class);
593
+
594
+        $this->registerService(\OCP\ISearch::class, function ($c) {
595
+            return new Search();
596
+        });
597
+        $this->registerAlias('Search', \OCP\ISearch::class);
598
+
599
+        $this->registerService(\OC\Security\RateLimiting\Limiter::class, function (Server $c) {
600
+            return new \OC\Security\RateLimiting\Limiter(
601
+                $this->getUserSession(),
602
+                $this->getRequest(),
603
+                new \OC\AppFramework\Utility\TimeFactory(),
604
+                $c->query(\OC\Security\RateLimiting\Backend\IBackend::class)
605
+            );
606
+        });
607
+        $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) {
608
+            return new \OC\Security\RateLimiting\Backend\MemoryCache(
609
+                $this->getMemCacheFactory(),
610
+                new \OC\AppFramework\Utility\TimeFactory()
611
+            );
612
+        });
613
+
614
+        $this->registerService(\OCP\Security\ISecureRandom::class, function ($c) {
615
+            return new SecureRandom();
616
+        });
617
+        $this->registerAlias('SecureRandom', \OCP\Security\ISecureRandom::class);
618
+
619
+        $this->registerService(\OCP\Security\ICrypto::class, function (Server $c) {
620
+            return new Crypto($c->getConfig(), $c->getSecureRandom());
621
+        });
622
+        $this->registerAlias('Crypto', \OCP\Security\ICrypto::class);
623
+
624
+        $this->registerService(\OCP\Security\IHasher::class, function (Server $c) {
625
+            return new Hasher($c->getConfig());
626
+        });
627
+        $this->registerAlias('Hasher', \OCP\Security\IHasher::class);
628
+
629
+        $this->registerService(\OCP\Security\ICredentialsManager::class, function (Server $c) {
630
+            return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection());
631
+        });
632
+        $this->registerAlias('CredentialsManager', \OCP\Security\ICredentialsManager::class);
633
+
634
+        $this->registerService(IDBConnection::class, function (Server $c) {
635
+            $systemConfig = $c->getSystemConfig();
636
+            $factory = new \OC\DB\ConnectionFactory($systemConfig);
637
+            $type = $systemConfig->getValue('dbtype', 'sqlite');
638
+            if (!$factory->isValidType($type)) {
639
+                throw new \OC\DatabaseException('Invalid database type');
640
+            }
641
+            $connectionParams = $factory->createConnectionParams();
642
+            $connection = $factory->getConnection($type, $connectionParams);
643
+            $connection->getConfiguration()->setSQLLogger($c->getQueryLogger());
644
+            return $connection;
645
+        });
646
+        $this->registerAlias('DatabaseConnection', IDBConnection::class);
647
+
648
+
649
+        $this->registerService(\OCP\Http\Client\IClientService::class, function (Server $c) {
650
+            $user = \OC_User::getUser();
651
+            $uid = $user ? $user : null;
652
+            return new ClientService(
653
+                $c->getConfig(),
654
+                new \OC\Security\CertificateManager(
655
+                    $uid,
656
+                    new View(),
657
+                    $c->getConfig(),
658
+                    $c->getLogger(),
659
+                    $c->getSecureRandom()
660
+                )
661
+            );
662
+        });
663
+        $this->registerAlias('HttpClientService', \OCP\Http\Client\IClientService::class);
664
+        $this->registerService(\OCP\Diagnostics\IEventLogger::class, function (Server $c) {
665
+            $eventLogger = new EventLogger();
666
+            if ($c->getSystemConfig()->getValue('debug', false)) {
667
+                // In debug mode, module is being activated by default
668
+                $eventLogger->activate();
669
+            }
670
+            return $eventLogger;
671
+        });
672
+        $this->registerAlias('EventLogger', \OCP\Diagnostics\IEventLogger::class);
673
+
674
+        $this->registerService(\OCP\Diagnostics\IQueryLogger::class, function (Server $c) {
675
+            $queryLogger = new QueryLogger();
676
+            if ($c->getSystemConfig()->getValue('debug', false)) {
677
+                // In debug mode, module is being activated by default
678
+                $queryLogger->activate();
679
+            }
680
+            return $queryLogger;
681
+        });
682
+        $this->registerAlias('QueryLogger', \OCP\Diagnostics\IQueryLogger::class);
683
+
684
+        $this->registerService(TempManager::class, function (Server $c) {
685
+            return new TempManager(
686
+                $c->getLogger(),
687
+                $c->getConfig()
688
+            );
689
+        });
690
+        $this->registerAlias('TempManager', TempManager::class);
691
+        $this->registerAlias(ITempManager::class, TempManager::class);
692
+
693
+        $this->registerService(AppManager::class, function (Server $c) {
694
+            return new \OC\App\AppManager(
695
+                $c->getUserSession(),
696
+                $c->query(\OC\AppConfig::class),
697
+                $c->getGroupManager(),
698
+                $c->getMemCacheFactory(),
699
+                $c->getEventDispatcher()
700
+            );
701
+        });
702
+        $this->registerAlias('AppManager', AppManager::class);
703
+        $this->registerAlias(IAppManager::class, AppManager::class);
704
+
705
+        $this->registerService(\OCP\IDateTimeZone::class, function (Server $c) {
706
+            return new DateTimeZone(
707
+                $c->getConfig(),
708
+                $c->getSession()
709
+            );
710
+        });
711
+        $this->registerAlias('DateTimeZone', \OCP\IDateTimeZone::class);
712
+
713
+        $this->registerService(\OCP\IDateTimeFormatter::class, function (Server $c) {
714
+            $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null);
715
+
716
+            return new DateTimeFormatter(
717
+                $c->getDateTimeZone()->getTimeZone(),
718
+                $c->getL10N('lib', $language)
719
+            );
720
+        });
721
+        $this->registerAlias('DateTimeFormatter', \OCP\IDateTimeFormatter::class);
722
+
723
+        $this->registerService(\OCP\Files\Config\IUserMountCache::class, function (Server $c) {
724
+            $mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger());
725
+            $listener = new UserMountCacheListener($mountCache);
726
+            $listener->listen($c->getUserManager());
727
+            return $mountCache;
728
+        });
729
+        $this->registerAlias('UserMountCache', \OCP\Files\Config\IUserMountCache::class);
730
+
731
+        $this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function (Server $c) {
732
+            $loader = \OC\Files\Filesystem::getLoader();
733
+            $mountCache = $c->query('UserMountCache');
734
+            $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache);
735
+
736
+            // builtin providers
737
+
738
+            $config = $c->getConfig();
739
+            $manager->registerProvider(new CacheMountProvider($config));
740
+            $manager->registerHomeProvider(new LocalHomeMountProvider());
741
+            $manager->registerHomeProvider(new ObjectHomeMountProvider($config));
742
+
743
+            return $manager;
744
+        });
745
+        $this->registerAlias('MountConfigManager', \OCP\Files\Config\IMountProviderCollection::class);
746
+
747
+        $this->registerService('IniWrapper', function ($c) {
748
+            return new IniGetWrapper();
749
+        });
750
+        $this->registerService('AsyncCommandBus', function (Server $c) {
751
+            $busClass = $c->getConfig()->getSystemValue('commandbus');
752
+            if ($busClass) {
753
+                list($app, $class) = explode('::', $busClass, 2);
754
+                if ($c->getAppManager()->isInstalled($app)) {
755
+                    \OC_App::loadApp($app);
756
+                    return $c->query($class);
757
+                } else {
758
+                    throw new ServiceUnavailableException("The app providing the command bus ($app) is not enabled");
759
+                }
760
+            } else {
761
+                $jobList = $c->getJobList();
762
+                return new CronBus($jobList);
763
+            }
764
+        });
765
+        $this->registerService('TrustedDomainHelper', function ($c) {
766
+            return new TrustedDomainHelper($this->getConfig());
767
+        });
768
+        $this->registerService(Throttler::class, function (Server $c) {
769
+            return new Throttler(
770
+                $c->getDatabaseConnection(),
771
+                new TimeFactory(),
772
+                $c->getLogger(),
773
+                $c->getConfig()
774
+            );
775
+        });
776
+        $this->registerAlias('Throttler', Throttler::class);
777
+        $this->registerService('IntegrityCodeChecker', function (Server $c) {
778
+            // IConfig and IAppManager requires a working database. This code
779
+            // might however be called when ownCloud is not yet setup.
780
+            if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
781
+                $config = $c->getConfig();
782
+                $appManager = $c->getAppManager();
783
+            } else {
784
+                $config = null;
785
+                $appManager = null;
786
+            }
787
+
788
+            return new Checker(
789
+                new EnvironmentHelper(),
790
+                new FileAccessHelper(),
791
+                new AppLocator(),
792
+                $config,
793
+                $c->getMemCacheFactory(),
794
+                $appManager,
795
+                $c->getTempManager()
796
+            );
797
+        });
798
+        $this->registerService(\OCP\IRequest::class, function ($c) {
799
+            if (isset($this['urlParams'])) {
800
+                $urlParams = $this['urlParams'];
801
+            } else {
802
+                $urlParams = [];
803
+            }
804
+
805
+            if (defined('PHPUNIT_RUN') && PHPUNIT_RUN
806
+                && in_array('fakeinput', stream_get_wrappers())
807
+            ) {
808
+                $stream = 'fakeinput://data';
809
+            } else {
810
+                $stream = 'php://input';
811
+            }
812
+
813
+            return new Request(
814
+                [
815
+                    'get' => $_GET,
816
+                    'post' => $_POST,
817
+                    'files' => $_FILES,
818
+                    'server' => $_SERVER,
819
+                    'env' => $_ENV,
820
+                    'cookies' => $_COOKIE,
821
+                    'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
822
+                        ? $_SERVER['REQUEST_METHOD']
823
+                        : '',
824
+                    'urlParams' => $urlParams,
825
+                ],
826
+                $this->getSecureRandom(),
827
+                $this->getConfig(),
828
+                $this->getCsrfTokenManager(),
829
+                $stream
830
+            );
831
+        });
832
+        $this->registerAlias('Request', \OCP\IRequest::class);
833
+
834
+        $this->registerService(\OCP\Mail\IMailer::class, function (Server $c) {
835
+            return new Mailer(
836
+                $c->getConfig(),
837
+                $c->getLogger(),
838
+                $c->query(Defaults::class),
839
+                $c->getURLGenerator(),
840
+                $c->getL10N('lib')
841
+            );
842
+        });
843
+        $this->registerAlias('Mailer', \OCP\Mail\IMailer::class);
844
+
845
+        $this->registerService('LDAPProvider', function (Server $c) {
846
+            $config = $c->getConfig();
847
+            $factoryClass = $config->getSystemValue('ldapProviderFactory', null);
848
+            if (is_null($factoryClass)) {
849
+                throw new \Exception('ldapProviderFactory not set');
850
+            }
851
+            /** @var \OCP\LDAP\ILDAPProviderFactory $factory */
852
+            $factory = new $factoryClass($this);
853
+            return $factory->getLDAPProvider();
854
+        });
855
+        $this->registerService(ILockingProvider::class, function (Server $c) {
856
+            $ini = $c->getIniWrapper();
857
+            $config = $c->getConfig();
858
+            $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time')));
859
+            if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
860
+                /** @var \OC\Memcache\Factory $memcacheFactory */
861
+                $memcacheFactory = $c->getMemCacheFactory();
862
+                $memcache = $memcacheFactory->createLocking('lock');
863
+                if (!($memcache instanceof \OC\Memcache\NullCache)) {
864
+                    return new MemcacheLockingProvider($memcache, $ttl);
865
+                }
866
+                return new DBLockingProvider(
867
+                    $c->getDatabaseConnection(),
868
+                    $c->getLogger(),
869
+                    new TimeFactory(),
870
+                    $ttl,
871
+                    !\OC::$CLI
872
+                );
873
+            }
874
+            return new NoopLockingProvider();
875
+        });
876
+        $this->registerAlias('LockingProvider', ILockingProvider::class);
877
+
878
+        $this->registerService(\OCP\Files\Mount\IMountManager::class, function () {
879
+            return new \OC\Files\Mount\Manager();
880
+        });
881
+        $this->registerAlias('MountManager', \OCP\Files\Mount\IMountManager::class);
882
+
883
+        $this->registerService(\OCP\Files\IMimeTypeDetector::class, function (Server $c) {
884
+            return new \OC\Files\Type\Detection(
885
+                $c->getURLGenerator(),
886
+                \OC::$configDir,
887
+                \OC::$SERVERROOT . '/resources/config/'
888
+            );
889
+        });
890
+        $this->registerAlias('MimeTypeDetector', \OCP\Files\IMimeTypeDetector::class);
891
+
892
+        $this->registerService(\OCP\Files\IMimeTypeLoader::class, function (Server $c) {
893
+            return new \OC\Files\Type\Loader(
894
+                $c->getDatabaseConnection()
895
+            );
896
+        });
897
+        $this->registerAlias('MimeTypeLoader', \OCP\Files\IMimeTypeLoader::class);
898
+        $this->registerService(BundleFetcher::class, function () {
899
+            return new BundleFetcher($this->getL10N('lib'));
900
+        });
901
+        $this->registerService(\OCP\Notification\IManager::class, function (Server $c) {
902
+            return new Manager(
903
+                $c->query(IValidator::class)
904
+            );
905
+        });
906
+        $this->registerAlias('NotificationManager', \OCP\Notification\IManager::class);
907
+
908
+        $this->registerService(\OC\CapabilitiesManager::class, function (Server $c) {
909
+            $manager = new \OC\CapabilitiesManager($c->getLogger());
910
+            $manager->registerCapability(function () use ($c) {
911
+                return new \OC\OCS\CoreCapabilities($c->getConfig());
912
+            });
913
+            $manager->registerCapability(function () use ($c) {
914
+                return $c->query(\OC\Security\Bruteforce\Capabilities::class);
915
+            });
916
+            return $manager;
917
+        });
918
+        $this->registerAlias('CapabilitiesManager', \OC\CapabilitiesManager::class);
919
+
920
+        $this->registerService(\OCP\Comments\ICommentsManager::class, function (Server $c) {
921
+            $config = $c->getConfig();
922
+            $factoryClass = $config->getSystemValue('comments.managerFactory', CommentsManagerFactory::class);
923
+            /** @var \OCP\Comments\ICommentsManagerFactory $factory */
924
+            $factory = new $factoryClass($this);
925
+            $manager = $factory->getManager();
926
+
927
+            $manager->registerDisplayNameResolver('user', function($id) use ($c) {
928
+                $manager = $c->getUserManager();
929
+                $user = $manager->get($id);
930
+                if(is_null($user)) {
931
+                    $l = $c->getL10N('core');
932
+                    $displayName = $l->t('Unknown user');
933
+                } else {
934
+                    $displayName = $user->getDisplayName();
935
+                }
936
+                return $displayName;
937
+            });
938
+
939
+            return $manager;
940
+        });
941
+        $this->registerAlias('CommentsManager', \OCP\Comments\ICommentsManager::class);
942
+
943
+        $this->registerService('ThemingDefaults', function (Server $c) {
944
+            /*
945 945
 			 * Dark magic for autoloader.
946 946
 			 * If we do a class_exists it will try to load the class which will
947 947
 			 * make composer cache the result. Resulting in errors when enabling
948 948
 			 * the theming app.
949 949
 			 */
950
-			$prefixes = \OC::$composerAutoloader->getPrefixesPsr4();
951
-			if (isset($prefixes['OCA\\Theming\\'])) {
952
-				$classExists = true;
953
-			} else {
954
-				$classExists = false;
955
-			}
956
-
957
-			if ($classExists && $c->getConfig()->getSystemValue('installed', false) && $c->getAppManager()->isInstalled('theming') && $c->getTrustedDomainHelper()->isTrustedDomain($c->getRequest()->getInsecureServerHost())) {
958
-				return new ThemingDefaults(
959
-					$c->getConfig(),
960
-					$c->getL10N('theming'),
961
-					$c->getURLGenerator(),
962
-					$c->getMemCacheFactory(),
963
-					new Util($c->getConfig(), $this->getAppManager(), $c->getAppDataDir('theming')),
964
-					new ImageManager($c->getConfig(), $c->getAppDataDir('theming'), $c->getURLGenerator(), $this->getMemCacheFactory(), $this->getLogger()),
965
-					$c->getAppManager()
966
-				);
967
-			}
968
-			return new \OC_Defaults();
969
-		});
970
-		$this->registerService(SCSSCacher::class, function (Server $c) {
971
-			/** @var Factory $cacheFactory */
972
-			$cacheFactory = $c->query(Factory::class);
973
-			return new SCSSCacher(
974
-				$c->getLogger(),
975
-				$c->query(\OC\Files\AppData\Factory::class),
976
-				$c->getURLGenerator(),
977
-				$c->getConfig(),
978
-				$c->getThemingDefaults(),
979
-				\OC::$SERVERROOT,
980
-				$this->getMemCacheFactory(),
981
-				$c->query(IconsCacher::class),
982
-				new TimeFactory()
983
-			);
984
-		});
985
-		$this->registerService(JSCombiner::class, function (Server $c) {
986
-			/** @var Factory $cacheFactory */
987
-			$cacheFactory = $c->query(Factory::class);
988
-			return new JSCombiner(
989
-				$c->getAppDataDir('js'),
990
-				$c->getURLGenerator(),
991
-				$this->getMemCacheFactory(),
992
-				$c->getSystemConfig(),
993
-				$c->getLogger()
994
-			);
995
-		});
996
-		$this->registerService(EventDispatcher::class, function () {
997
-			return new EventDispatcher();
998
-		});
999
-		$this->registerAlias('EventDispatcher', EventDispatcher::class);
1000
-		$this->registerAlias(EventDispatcherInterface::class, EventDispatcher::class);
1001
-
1002
-		$this->registerService('CryptoWrapper', function (Server $c) {
1003
-			// FIXME: Instantiiated here due to cyclic dependency
1004
-			$request = new Request(
1005
-				[
1006
-					'get' => $_GET,
1007
-					'post' => $_POST,
1008
-					'files' => $_FILES,
1009
-					'server' => $_SERVER,
1010
-					'env' => $_ENV,
1011
-					'cookies' => $_COOKIE,
1012
-					'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
1013
-						? $_SERVER['REQUEST_METHOD']
1014
-						: null,
1015
-				],
1016
-				$c->getSecureRandom(),
1017
-				$c->getConfig()
1018
-			);
1019
-
1020
-			return new CryptoWrapper(
1021
-				$c->getConfig(),
1022
-				$c->getCrypto(),
1023
-				$c->getSecureRandom(),
1024
-				$request
1025
-			);
1026
-		});
1027
-		$this->registerService('CsrfTokenManager', function (Server $c) {
1028
-			$tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom());
1029
-
1030
-			return new CsrfTokenManager(
1031
-				$tokenGenerator,
1032
-				$c->query(SessionStorage::class)
1033
-			);
1034
-		});
1035
-		$this->registerService(SessionStorage::class, function (Server $c) {
1036
-			return new SessionStorage($c->getSession());
1037
-		});
1038
-		$this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function (Server $c) {
1039
-			return new ContentSecurityPolicyManager();
1040
-		});
1041
-		$this->registerAlias('ContentSecurityPolicyManager', \OCP\Security\IContentSecurityPolicyManager::class);
1042
-
1043
-		$this->registerService('ContentSecurityPolicyNonceManager', function (Server $c) {
1044
-			return new ContentSecurityPolicyNonceManager(
1045
-				$c->getCsrfTokenManager(),
1046
-				$c->getRequest()
1047
-			);
1048
-		});
1049
-
1050
-		$this->registerService(\OCP\Share\IManager::class, function (Server $c) {
1051
-			$config = $c->getConfig();
1052
-			$factoryClass = $config->getSystemValue('sharing.managerFactory', ProviderFactory::class);
1053
-			/** @var \OCP\Share\IProviderFactory $factory */
1054
-			$factory = new $factoryClass($this);
1055
-
1056
-			$manager = new \OC\Share20\Manager(
1057
-				$c->getLogger(),
1058
-				$c->getConfig(),
1059
-				$c->getSecureRandom(),
1060
-				$c->getHasher(),
1061
-				$c->getMountManager(),
1062
-				$c->getGroupManager(),
1063
-				$c->getL10N('lib'),
1064
-				$c->getL10NFactory(),
1065
-				$factory,
1066
-				$c->getUserManager(),
1067
-				$c->getLazyRootFolder(),
1068
-				$c->getEventDispatcher(),
1069
-				$c->getMailer(),
1070
-				$c->getURLGenerator(),
1071
-				$c->getThemingDefaults()
1072
-			);
1073
-
1074
-			return $manager;
1075
-		});
1076
-		$this->registerAlias('ShareManager', \OCP\Share\IManager::class);
1077
-
1078
-		$this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function(Server $c) {
1079
-			$instance = new Collaboration\Collaborators\Search($c);
1080
-
1081
-			// register default plugins
1082
-			$instance->registerPlugin(['shareType' => 'SHARE_TYPE_USER', 'class' => UserPlugin::class]);
1083
-			$instance->registerPlugin(['shareType' => 'SHARE_TYPE_GROUP', 'class' => GroupPlugin::class]);
1084
-			$instance->registerPlugin(['shareType' => 'SHARE_TYPE_EMAIL', 'class' => MailPlugin::class]);
1085
-			$instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE', 'class' => RemotePlugin::class]);
1086
-			$instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE_GROUP', 'class' => RemoteGroupPlugin::class]);
1087
-
1088
-			return $instance;
1089
-		});
1090
-		$this->registerAlias('CollaboratorSearch', \OCP\Collaboration\Collaborators\ISearch::class);
1091
-		$this->registerAlias(\OCP\Collaboration\Collaborators\ISearchResult::class, \OC\Collaboration\Collaborators\SearchResult::class);
1092
-
1093
-		$this->registerAlias(\OCP\Collaboration\AutoComplete\IManager::class, \OC\Collaboration\AutoComplete\Manager::class);
1094
-
1095
-		$this->registerService('SettingsManager', function (Server $c) {
1096
-			$manager = new \OC\Settings\Manager(
1097
-				$c->getLogger(),
1098
-				$c->getL10N('lib'),
1099
-				$c->getURLGenerator(),
1100
-				$c
1101
-			);
1102
-			return $manager;
1103
-		});
1104
-		$this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) {
1105
-			return new \OC\Files\AppData\Factory(
1106
-				$c->getRootFolder(),
1107
-				$c->getSystemConfig()
1108
-			);
1109
-		});
1110
-
1111
-		$this->registerService('LockdownManager', function (Server $c) {
1112
-			return new LockdownManager(function () use ($c) {
1113
-				return $c->getSession();
1114
-			});
1115
-		});
1116
-
1117
-		$this->registerService(\OCP\OCS\IDiscoveryService::class, function (Server $c) {
1118
-			return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService());
1119
-		});
1120
-
1121
-		$this->registerService(ICloudIdManager::class, function (Server $c) {
1122
-			return new CloudIdManager();
1123
-		});
1124
-
1125
-		$this->registerService(IConfig::class, function (Server $c) {
1126
-			return new GlobalScale\Config($c->getConfig());
1127
-		});
1128
-
1129
-		$this->registerService(ICloudFederationProviderManager::class, function (Server $c) {
1130
-			return new CloudFederationProviderManager($c->getAppManager(), $c->getHTTPClientService(), $c->getCloudIdManager(), $c->getLogger());
1131
-		});
1132
-
1133
-		$this->registerService(ICloudFederationFactory::class, function (Server $c) {
1134
-			return new CloudFederationFactory();
1135
-		});
1136
-
1137
-		$this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class);
1138
-		$this->registerAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class);
1139
-
1140
-		$this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class);
1141
-		$this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class);
1142
-
1143
-		$this->registerService(Defaults::class, function (Server $c) {
1144
-			return new Defaults(
1145
-				$c->getThemingDefaults()
1146
-			);
1147
-		});
1148
-		$this->registerAlias('Defaults', \OCP\Defaults::class);
1149
-
1150
-		$this->registerService(\OCP\ISession::class, function (SimpleContainer $c) {
1151
-			return $c->query(\OCP\IUserSession::class)->getSession();
1152
-		});
1153
-
1154
-		$this->registerService(IShareHelper::class, function (Server $c) {
1155
-			return new ShareHelper(
1156
-				$c->query(\OCP\Share\IManager::class)
1157
-			);
1158
-		});
1159
-
1160
-		$this->registerService(Installer::class, function(Server $c) {
1161
-			return new Installer(
1162
-				$c->getAppFetcher(),
1163
-				$c->getHTTPClientService(),
1164
-				$c->getTempManager(),
1165
-				$c->getLogger(),
1166
-				$c->getConfig()
1167
-			);
1168
-		});
1169
-
1170
-		$this->registerService(IApiFactory::class, function(Server $c) {
1171
-			return new ApiFactory($c->getHTTPClientService());
1172
-		});
1173
-
1174
-		$this->registerService(IInstanceFactory::class, function(Server $c) {
1175
-			$memcacheFactory = $c->getMemCacheFactory();
1176
-			return new InstanceFactory($memcacheFactory->createLocal('remoteinstance.'), $c->getHTTPClientService());
1177
-		});
1178
-
1179
-		$this->registerService(IContactsStore::class, function(Server $c) {
1180
-			return new ContactsStore(
1181
-				$c->getContactsManager(),
1182
-				$c->getConfig(),
1183
-				$c->getUserManager(),
1184
-				$c->getGroupManager()
1185
-			);
1186
-		});
1187
-		$this->registerAlias(IContactsStore::class, ContactsStore::class);
1188
-		$this->registerAlias(IAccountManager::class, AccountManager::class);
1189
-
1190
-		$this->registerService(IStorageFactory::class, function() {
1191
-			return new StorageFactory();
1192
-		});
1193
-
1194
-		$this->registerAlias(IDashboardManager::class, DashboardManager::class);
1195
-		$this->registerAlias(IFullTextSearchManager::class, FullTextSearchManager::class);
1196
-
1197
-		$this->registerService(\OC\Security\IdentityProof\Manager::class, function (Server $c) {
1198
-			return new \OC\Security\IdentityProof\Manager(
1199
-				$c->query(\OC\Files\AppData\Factory::class),
1200
-				$c->getCrypto(),
1201
-				$c->getConfig()
1202
-			);
1203
-		});
1204
-
1205
-		$this->registerAlias(ISubAdmin::class, SubAdmin::class);
1206
-
1207
-		$this->connectDispatcher();
1208
-	}
1209
-
1210
-	/**
1211
-	 * @return \OCP\Calendar\IManager
1212
-	 */
1213
-	public function getCalendarManager() {
1214
-		return $this->query('CalendarManager');
1215
-	}
1216
-
1217
-	/**
1218
-	 * @return \OCP\Calendar\Resource\IManager
1219
-	 */
1220
-	public function getCalendarResourceBackendManager() {
1221
-		return $this->query('CalendarResourceBackendManager');
1222
-	}
1223
-
1224
-	/**
1225
-	 * @return \OCP\Calendar\Room\IManager
1226
-	 */
1227
-	public function getCalendarRoomBackendManager() {
1228
-		return $this->query('CalendarRoomBackendManager');
1229
-	}
1230
-
1231
-	private function connectDispatcher() {
1232
-		$dispatcher = $this->getEventDispatcher();
1233
-
1234
-		// Delete avatar on user deletion
1235
-		$dispatcher->addListener('OCP\IUser::preDelete', function(GenericEvent $e) {
1236
-			$logger = $this->getLogger();
1237
-			$manager = $this->getAvatarManager();
1238
-			/** @var IUser $user */
1239
-			$user = $e->getSubject();
1240
-
1241
-			try {
1242
-				$avatar = $manager->getAvatar($user->getUID());
1243
-				$avatar->remove();
1244
-			} catch (NotFoundException $e) {
1245
-				// no avatar to remove
1246
-			} catch (\Exception $e) {
1247
-				// Ignore exceptions
1248
-				$logger->info('Could not cleanup avatar of ' . $user->getUID());
1249
-			}
1250
-		});
1251
-
1252
-		$dispatcher->addListener('OCP\IUser::changeUser', function (GenericEvent $e) {
1253
-			$manager = $this->getAvatarManager();
1254
-			/** @var IUser $user */
1255
-			$user = $e->getSubject();
1256
-			$feature = $e->getArgument('feature');
1257
-			$oldValue = $e->getArgument('oldValue');
1258
-			$value = $e->getArgument('value');
1259
-
1260
-			try {
1261
-				$avatar = $manager->getAvatar($user->getUID());
1262
-				$avatar->userChanged($feature, $oldValue, $value);
1263
-			} catch (NotFoundException $e) {
1264
-				// no avatar to remove
1265
-			}
1266
-		});
1267
-	}
1268
-
1269
-	/**
1270
-	 * @return \OCP\Contacts\IManager
1271
-	 */
1272
-	public function getContactsManager() {
1273
-		return $this->query('ContactsManager');
1274
-	}
1275
-
1276
-	/**
1277
-	 * @return \OC\Encryption\Manager
1278
-	 */
1279
-	public function getEncryptionManager() {
1280
-		return $this->query('EncryptionManager');
1281
-	}
1282
-
1283
-	/**
1284
-	 * @return \OC\Encryption\File
1285
-	 */
1286
-	public function getEncryptionFilesHelper() {
1287
-		return $this->query('EncryptionFileHelper');
1288
-	}
1289
-
1290
-	/**
1291
-	 * @return \OCP\Encryption\Keys\IStorage
1292
-	 */
1293
-	public function getEncryptionKeyStorage() {
1294
-		return $this->query('EncryptionKeyStorage');
1295
-	}
1296
-
1297
-	/**
1298
-	 * The current request object holding all information about the request
1299
-	 * currently being processed is returned from this method.
1300
-	 * In case the current execution was not initiated by a web request null is returned
1301
-	 *
1302
-	 * @return \OCP\IRequest
1303
-	 */
1304
-	public function getRequest() {
1305
-		return $this->query('Request');
1306
-	}
1307
-
1308
-	/**
1309
-	 * Returns the preview manager which can create preview images for a given file
1310
-	 *
1311
-	 * @return \OCP\IPreview
1312
-	 */
1313
-	public function getPreviewManager() {
1314
-		return $this->query('PreviewManager');
1315
-	}
1316
-
1317
-	/**
1318
-	 * Returns the tag manager which can get and set tags for different object types
1319
-	 *
1320
-	 * @see \OCP\ITagManager::load()
1321
-	 * @return \OCP\ITagManager
1322
-	 */
1323
-	public function getTagManager() {
1324
-		return $this->query('TagManager');
1325
-	}
1326
-
1327
-	/**
1328
-	 * Returns the system-tag manager
1329
-	 *
1330
-	 * @return \OCP\SystemTag\ISystemTagManager
1331
-	 *
1332
-	 * @since 9.0.0
1333
-	 */
1334
-	public function getSystemTagManager() {
1335
-		return $this->query('SystemTagManager');
1336
-	}
1337
-
1338
-	/**
1339
-	 * Returns the system-tag object mapper
1340
-	 *
1341
-	 * @return \OCP\SystemTag\ISystemTagObjectMapper
1342
-	 *
1343
-	 * @since 9.0.0
1344
-	 */
1345
-	public function getSystemTagObjectMapper() {
1346
-		return $this->query('SystemTagObjectMapper');
1347
-	}
1348
-
1349
-	/**
1350
-	 * Returns the avatar manager, used for avatar functionality
1351
-	 *
1352
-	 * @return \OCP\IAvatarManager
1353
-	 */
1354
-	public function getAvatarManager() {
1355
-		return $this->query('AvatarManager');
1356
-	}
1357
-
1358
-	/**
1359
-	 * Returns the root folder of ownCloud's data directory
1360
-	 *
1361
-	 * @return \OCP\Files\IRootFolder
1362
-	 */
1363
-	public function getRootFolder() {
1364
-		return $this->query('LazyRootFolder');
1365
-	}
1366
-
1367
-	/**
1368
-	 * Returns the root folder of ownCloud's data directory
1369
-	 * This is the lazy variant so this gets only initialized once it
1370
-	 * is actually used.
1371
-	 *
1372
-	 * @return \OCP\Files\IRootFolder
1373
-	 */
1374
-	public function getLazyRootFolder() {
1375
-		return $this->query('LazyRootFolder');
1376
-	}
1377
-
1378
-	/**
1379
-	 * Returns a view to ownCloud's files folder
1380
-	 *
1381
-	 * @param string $userId user ID
1382
-	 * @return \OCP\Files\Folder|null
1383
-	 */
1384
-	public function getUserFolder($userId = null) {
1385
-		if ($userId === null) {
1386
-			$user = $this->getUserSession()->getUser();
1387
-			if (!$user) {
1388
-				return null;
1389
-			}
1390
-			$userId = $user->getUID();
1391
-		}
1392
-		$root = $this->getRootFolder();
1393
-		return $root->getUserFolder($userId);
1394
-	}
1395
-
1396
-	/**
1397
-	 * Returns an app-specific view in ownClouds data directory
1398
-	 *
1399
-	 * @return \OCP\Files\Folder
1400
-	 * @deprecated since 9.2.0 use IAppData
1401
-	 */
1402
-	public function getAppFolder() {
1403
-		$dir = '/' . \OC_App::getCurrentApp();
1404
-		$root = $this->getRootFolder();
1405
-		if (!$root->nodeExists($dir)) {
1406
-			$folder = $root->newFolder($dir);
1407
-		} else {
1408
-			$folder = $root->get($dir);
1409
-		}
1410
-		return $folder;
1411
-	}
1412
-
1413
-	/**
1414
-	 * @return \OC\User\Manager
1415
-	 */
1416
-	public function getUserManager() {
1417
-		return $this->query('UserManager');
1418
-	}
1419
-
1420
-	/**
1421
-	 * @return \OC\Group\Manager
1422
-	 */
1423
-	public function getGroupManager() {
1424
-		return $this->query('GroupManager');
1425
-	}
1426
-
1427
-	/**
1428
-	 * @return \OC\User\Session
1429
-	 */
1430
-	public function getUserSession() {
1431
-		return $this->query('UserSession');
1432
-	}
1433
-
1434
-	/**
1435
-	 * @return \OCP\ISession
1436
-	 */
1437
-	public function getSession() {
1438
-		return $this->query('UserSession')->getSession();
1439
-	}
1440
-
1441
-	/**
1442
-	 * @param \OCP\ISession $session
1443
-	 */
1444
-	public function setSession(\OCP\ISession $session) {
1445
-		$this->query(SessionStorage::class)->setSession($session);
1446
-		$this->query('UserSession')->setSession($session);
1447
-		$this->query(Store::class)->setSession($session);
1448
-	}
1449
-
1450
-	/**
1451
-	 * @return \OC\Authentication\TwoFactorAuth\Manager
1452
-	 */
1453
-	public function getTwoFactorAuthManager() {
1454
-		return $this->query('\OC\Authentication\TwoFactorAuth\Manager');
1455
-	}
1456
-
1457
-	/**
1458
-	 * @return \OC\NavigationManager
1459
-	 */
1460
-	public function getNavigationManager() {
1461
-		return $this->query('NavigationManager');
1462
-	}
1463
-
1464
-	/**
1465
-	 * @return \OCP\IConfig
1466
-	 */
1467
-	public function getConfig() {
1468
-		return $this->query('AllConfig');
1469
-	}
1470
-
1471
-	/**
1472
-	 * @return \OC\SystemConfig
1473
-	 */
1474
-	public function getSystemConfig() {
1475
-		return $this->query('SystemConfig');
1476
-	}
1477
-
1478
-	/**
1479
-	 * Returns the app config manager
1480
-	 *
1481
-	 * @return \OCP\IAppConfig
1482
-	 */
1483
-	public function getAppConfig() {
1484
-		return $this->query('AppConfig');
1485
-	}
1486
-
1487
-	/**
1488
-	 * @return \OCP\L10N\IFactory
1489
-	 */
1490
-	public function getL10NFactory() {
1491
-		return $this->query('L10NFactory');
1492
-	}
1493
-
1494
-	/**
1495
-	 * get an L10N instance
1496
-	 *
1497
-	 * @param string $app appid
1498
-	 * @param string $lang
1499
-	 * @return IL10N
1500
-	 */
1501
-	public function getL10N($app, $lang = null) {
1502
-		return $this->getL10NFactory()->get($app, $lang);
1503
-	}
1504
-
1505
-	/**
1506
-	 * @return \OCP\IURLGenerator
1507
-	 */
1508
-	public function getURLGenerator() {
1509
-		return $this->query('URLGenerator');
1510
-	}
1511
-
1512
-	/**
1513
-	 * @return AppFetcher
1514
-	 */
1515
-	public function getAppFetcher() {
1516
-		return $this->query(AppFetcher::class);
1517
-	}
1518
-
1519
-	/**
1520
-	 * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use
1521
-	 * getMemCacheFactory() instead.
1522
-	 *
1523
-	 * @return \OCP\ICache
1524
-	 * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache
1525
-	 */
1526
-	public function getCache() {
1527
-		return $this->query('UserCache');
1528
-	}
1529
-
1530
-	/**
1531
-	 * Returns an \OCP\CacheFactory instance
1532
-	 *
1533
-	 * @return \OCP\ICacheFactory
1534
-	 */
1535
-	public function getMemCacheFactory() {
1536
-		return $this->query('MemCacheFactory');
1537
-	}
1538
-
1539
-	/**
1540
-	 * Returns an \OC\RedisFactory instance
1541
-	 *
1542
-	 * @return \OC\RedisFactory
1543
-	 */
1544
-	public function getGetRedisFactory() {
1545
-		return $this->query('RedisFactory');
1546
-	}
1547
-
1548
-
1549
-	/**
1550
-	 * Returns the current session
1551
-	 *
1552
-	 * @return \OCP\IDBConnection
1553
-	 */
1554
-	public function getDatabaseConnection() {
1555
-		return $this->query('DatabaseConnection');
1556
-	}
1557
-
1558
-	/**
1559
-	 * Returns the activity manager
1560
-	 *
1561
-	 * @return \OCP\Activity\IManager
1562
-	 */
1563
-	public function getActivityManager() {
1564
-		return $this->query('ActivityManager');
1565
-	}
1566
-
1567
-	/**
1568
-	 * Returns an job list for controlling background jobs
1569
-	 *
1570
-	 * @return \OCP\BackgroundJob\IJobList
1571
-	 */
1572
-	public function getJobList() {
1573
-		return $this->query('JobList');
1574
-	}
1575
-
1576
-	/**
1577
-	 * Returns a logger instance
1578
-	 *
1579
-	 * @return \OCP\ILogger
1580
-	 */
1581
-	public function getLogger() {
1582
-		return $this->query('Logger');
1583
-	}
1584
-
1585
-	/**
1586
-	 * @return ILogFactory
1587
-	 * @throws \OCP\AppFramework\QueryException
1588
-	 */
1589
-	public function getLogFactory() {
1590
-		return $this->query(ILogFactory::class);
1591
-	}
1592
-
1593
-	/**
1594
-	 * Returns a router for generating and matching urls
1595
-	 *
1596
-	 * @return \OCP\Route\IRouter
1597
-	 */
1598
-	public function getRouter() {
1599
-		return $this->query('Router');
1600
-	}
1601
-
1602
-	/**
1603
-	 * Returns a search instance
1604
-	 *
1605
-	 * @return \OCP\ISearch
1606
-	 */
1607
-	public function getSearch() {
1608
-		return $this->query('Search');
1609
-	}
1610
-
1611
-	/**
1612
-	 * Returns a SecureRandom instance
1613
-	 *
1614
-	 * @return \OCP\Security\ISecureRandom
1615
-	 */
1616
-	public function getSecureRandom() {
1617
-		return $this->query('SecureRandom');
1618
-	}
1619
-
1620
-	/**
1621
-	 * Returns a Crypto instance
1622
-	 *
1623
-	 * @return \OCP\Security\ICrypto
1624
-	 */
1625
-	public function getCrypto() {
1626
-		return $this->query('Crypto');
1627
-	}
1628
-
1629
-	/**
1630
-	 * Returns a Hasher instance
1631
-	 *
1632
-	 * @return \OCP\Security\IHasher
1633
-	 */
1634
-	public function getHasher() {
1635
-		return $this->query('Hasher');
1636
-	}
1637
-
1638
-	/**
1639
-	 * Returns a CredentialsManager instance
1640
-	 *
1641
-	 * @return \OCP\Security\ICredentialsManager
1642
-	 */
1643
-	public function getCredentialsManager() {
1644
-		return $this->query('CredentialsManager');
1645
-	}
1646
-
1647
-	/**
1648
-	 * Get the certificate manager for the user
1649
-	 *
1650
-	 * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager
1651
-	 * @return \OCP\ICertificateManager | null if $uid is null and no user is logged in
1652
-	 */
1653
-	public function getCertificateManager($userId = '') {
1654
-		if ($userId === '') {
1655
-			$userSession = $this->getUserSession();
1656
-			$user = $userSession->getUser();
1657
-			if (is_null($user)) {
1658
-				return null;
1659
-			}
1660
-			$userId = $user->getUID();
1661
-		}
1662
-		return new CertificateManager(
1663
-			$userId,
1664
-			new View(),
1665
-			$this->getConfig(),
1666
-			$this->getLogger(),
1667
-			$this->getSecureRandom()
1668
-		);
1669
-	}
1670
-
1671
-	/**
1672
-	 * Returns an instance of the HTTP client service
1673
-	 *
1674
-	 * @return \OCP\Http\Client\IClientService
1675
-	 */
1676
-	public function getHTTPClientService() {
1677
-		return $this->query('HttpClientService');
1678
-	}
1679
-
1680
-	/**
1681
-	 * Create a new event source
1682
-	 *
1683
-	 * @return \OCP\IEventSource
1684
-	 */
1685
-	public function createEventSource() {
1686
-		return new \OC_EventSource();
1687
-	}
1688
-
1689
-	/**
1690
-	 * Get the active event logger
1691
-	 *
1692
-	 * The returned logger only logs data when debug mode is enabled
1693
-	 *
1694
-	 * @return \OCP\Diagnostics\IEventLogger
1695
-	 */
1696
-	public function getEventLogger() {
1697
-		return $this->query('EventLogger');
1698
-	}
1699
-
1700
-	/**
1701
-	 * Get the active query logger
1702
-	 *
1703
-	 * The returned logger only logs data when debug mode is enabled
1704
-	 *
1705
-	 * @return \OCP\Diagnostics\IQueryLogger
1706
-	 */
1707
-	public function getQueryLogger() {
1708
-		return $this->query('QueryLogger');
1709
-	}
1710
-
1711
-	/**
1712
-	 * Get the manager for temporary files and folders
1713
-	 *
1714
-	 * @return \OCP\ITempManager
1715
-	 */
1716
-	public function getTempManager() {
1717
-		return $this->query('TempManager');
1718
-	}
1719
-
1720
-	/**
1721
-	 * Get the app manager
1722
-	 *
1723
-	 * @return \OCP\App\IAppManager
1724
-	 */
1725
-	public function getAppManager() {
1726
-		return $this->query('AppManager');
1727
-	}
1728
-
1729
-	/**
1730
-	 * Creates a new mailer
1731
-	 *
1732
-	 * @return \OCP\Mail\IMailer
1733
-	 */
1734
-	public function getMailer() {
1735
-		return $this->query('Mailer');
1736
-	}
1737
-
1738
-	/**
1739
-	 * Get the webroot
1740
-	 *
1741
-	 * @return string
1742
-	 */
1743
-	public function getWebRoot() {
1744
-		return $this->webRoot;
1745
-	}
1746
-
1747
-	/**
1748
-	 * @return \OC\OCSClient
1749
-	 */
1750
-	public function getOcsClient() {
1751
-		return $this->query('OcsClient');
1752
-	}
1753
-
1754
-	/**
1755
-	 * @return \OCP\IDateTimeZone
1756
-	 */
1757
-	public function getDateTimeZone() {
1758
-		return $this->query('DateTimeZone');
1759
-	}
1760
-
1761
-	/**
1762
-	 * @return \OCP\IDateTimeFormatter
1763
-	 */
1764
-	public function getDateTimeFormatter() {
1765
-		return $this->query('DateTimeFormatter');
1766
-	}
1767
-
1768
-	/**
1769
-	 * @return \OCP\Files\Config\IMountProviderCollection
1770
-	 */
1771
-	public function getMountProviderCollection() {
1772
-		return $this->query('MountConfigManager');
1773
-	}
1774
-
1775
-	/**
1776
-	 * Get the IniWrapper
1777
-	 *
1778
-	 * @return IniGetWrapper
1779
-	 */
1780
-	public function getIniWrapper() {
1781
-		return $this->query('IniWrapper');
1782
-	}
1783
-
1784
-	/**
1785
-	 * @return \OCP\Command\IBus
1786
-	 */
1787
-	public function getCommandBus() {
1788
-		return $this->query('AsyncCommandBus');
1789
-	}
1790
-
1791
-	/**
1792
-	 * Get the trusted domain helper
1793
-	 *
1794
-	 * @return TrustedDomainHelper
1795
-	 */
1796
-	public function getTrustedDomainHelper() {
1797
-		return $this->query('TrustedDomainHelper');
1798
-	}
1799
-
1800
-	/**
1801
-	 * Get the locking provider
1802
-	 *
1803
-	 * @return \OCP\Lock\ILockingProvider
1804
-	 * @since 8.1.0
1805
-	 */
1806
-	public function getLockingProvider() {
1807
-		return $this->query('LockingProvider');
1808
-	}
1809
-
1810
-	/**
1811
-	 * @return \OCP\Files\Mount\IMountManager
1812
-	 **/
1813
-	function getMountManager() {
1814
-		return $this->query('MountManager');
1815
-	}
1816
-
1817
-	/** @return \OCP\Files\Config\IUserMountCache */
1818
-	function getUserMountCache() {
1819
-		return $this->query('UserMountCache');
1820
-	}
1821
-
1822
-	/**
1823
-	 * Get the MimeTypeDetector
1824
-	 *
1825
-	 * @return \OCP\Files\IMimeTypeDetector
1826
-	 */
1827
-	public function getMimeTypeDetector() {
1828
-		return $this->query('MimeTypeDetector');
1829
-	}
1830
-
1831
-	/**
1832
-	 * Get the MimeTypeLoader
1833
-	 *
1834
-	 * @return \OCP\Files\IMimeTypeLoader
1835
-	 */
1836
-	public function getMimeTypeLoader() {
1837
-		return $this->query('MimeTypeLoader');
1838
-	}
1839
-
1840
-	/**
1841
-	 * Get the manager of all the capabilities
1842
-	 *
1843
-	 * @return \OC\CapabilitiesManager
1844
-	 */
1845
-	public function getCapabilitiesManager() {
1846
-		return $this->query('CapabilitiesManager');
1847
-	}
1848
-
1849
-	/**
1850
-	 * Get the EventDispatcher
1851
-	 *
1852
-	 * @return EventDispatcherInterface
1853
-	 * @since 8.2.0
1854
-	 */
1855
-	public function getEventDispatcher() {
1856
-		return $this->query('EventDispatcher');
1857
-	}
1858
-
1859
-	/**
1860
-	 * Get the Notification Manager
1861
-	 *
1862
-	 * @return \OCP\Notification\IManager
1863
-	 * @since 8.2.0
1864
-	 */
1865
-	public function getNotificationManager() {
1866
-		return $this->query('NotificationManager');
1867
-	}
1868
-
1869
-	/**
1870
-	 * @return \OCP\Comments\ICommentsManager
1871
-	 */
1872
-	public function getCommentsManager() {
1873
-		return $this->query('CommentsManager');
1874
-	}
1875
-
1876
-	/**
1877
-	 * @return \OCA\Theming\ThemingDefaults
1878
-	 */
1879
-	public function getThemingDefaults() {
1880
-		return $this->query('ThemingDefaults');
1881
-	}
1882
-
1883
-	/**
1884
-	 * @return \OC\IntegrityCheck\Checker
1885
-	 */
1886
-	public function getIntegrityCodeChecker() {
1887
-		return $this->query('IntegrityCodeChecker');
1888
-	}
1889
-
1890
-	/**
1891
-	 * @return \OC\Session\CryptoWrapper
1892
-	 */
1893
-	public function getSessionCryptoWrapper() {
1894
-		return $this->query('CryptoWrapper');
1895
-	}
1896
-
1897
-	/**
1898
-	 * @return CsrfTokenManager
1899
-	 */
1900
-	public function getCsrfTokenManager() {
1901
-		return $this->query('CsrfTokenManager');
1902
-	}
1903
-
1904
-	/**
1905
-	 * @return Throttler
1906
-	 */
1907
-	public function getBruteForceThrottler() {
1908
-		return $this->query('Throttler');
1909
-	}
1910
-
1911
-	/**
1912
-	 * @return IContentSecurityPolicyManager
1913
-	 */
1914
-	public function getContentSecurityPolicyManager() {
1915
-		return $this->query('ContentSecurityPolicyManager');
1916
-	}
1917
-
1918
-	/**
1919
-	 * @return ContentSecurityPolicyNonceManager
1920
-	 */
1921
-	public function getContentSecurityPolicyNonceManager() {
1922
-		return $this->query('ContentSecurityPolicyNonceManager');
1923
-	}
1924
-
1925
-	/**
1926
-	 * Not a public API as of 8.2, wait for 9.0
1927
-	 *
1928
-	 * @return \OCA\Files_External\Service\BackendService
1929
-	 */
1930
-	public function getStoragesBackendService() {
1931
-		return $this->query('OCA\\Files_External\\Service\\BackendService');
1932
-	}
1933
-
1934
-	/**
1935
-	 * Not a public API as of 8.2, wait for 9.0
1936
-	 *
1937
-	 * @return \OCA\Files_External\Service\GlobalStoragesService
1938
-	 */
1939
-	public function getGlobalStoragesService() {
1940
-		return $this->query('OCA\\Files_External\\Service\\GlobalStoragesService');
1941
-	}
1942
-
1943
-	/**
1944
-	 * Not a public API as of 8.2, wait for 9.0
1945
-	 *
1946
-	 * @return \OCA\Files_External\Service\UserGlobalStoragesService
1947
-	 */
1948
-	public function getUserGlobalStoragesService() {
1949
-		return $this->query('OCA\\Files_External\\Service\\UserGlobalStoragesService');
1950
-	}
1951
-
1952
-	/**
1953
-	 * Not a public API as of 8.2, wait for 9.0
1954
-	 *
1955
-	 * @return \OCA\Files_External\Service\UserStoragesService
1956
-	 */
1957
-	public function getUserStoragesService() {
1958
-		return $this->query('OCA\\Files_External\\Service\\UserStoragesService');
1959
-	}
1960
-
1961
-	/**
1962
-	 * @return \OCP\Share\IManager
1963
-	 */
1964
-	public function getShareManager() {
1965
-		return $this->query('ShareManager');
1966
-	}
1967
-
1968
-	/**
1969
-	 * @return \OCP\Collaboration\Collaborators\ISearch
1970
-	 */
1971
-	public function getCollaboratorSearch() {
1972
-		return $this->query('CollaboratorSearch');
1973
-	}
1974
-
1975
-	/**
1976
-	 * @return \OCP\Collaboration\AutoComplete\IManager
1977
-	 */
1978
-	public function getAutoCompleteManager(){
1979
-		return $this->query(IManager::class);
1980
-	}
1981
-
1982
-	/**
1983
-	 * Returns the LDAP Provider
1984
-	 *
1985
-	 * @return \OCP\LDAP\ILDAPProvider
1986
-	 */
1987
-	public function getLDAPProvider() {
1988
-		return $this->query('LDAPProvider');
1989
-	}
1990
-
1991
-	/**
1992
-	 * @return \OCP\Settings\IManager
1993
-	 */
1994
-	public function getSettingsManager() {
1995
-		return $this->query('SettingsManager');
1996
-	}
1997
-
1998
-	/**
1999
-	 * @return \OCP\Files\IAppData
2000
-	 */
2001
-	public function getAppDataDir($app) {
2002
-		/** @var \OC\Files\AppData\Factory $factory */
2003
-		$factory = $this->query(\OC\Files\AppData\Factory::class);
2004
-		return $factory->get($app);
2005
-	}
2006
-
2007
-	/**
2008
-	 * @return \OCP\Lockdown\ILockdownManager
2009
-	 */
2010
-	public function getLockdownManager() {
2011
-		return $this->query('LockdownManager');
2012
-	}
2013
-
2014
-	/**
2015
-	 * @return \OCP\Federation\ICloudIdManager
2016
-	 */
2017
-	public function getCloudIdManager() {
2018
-		return $this->query(ICloudIdManager::class);
2019
-	}
2020
-
2021
-	/**
2022
-	 * @return \OCP\GlobalScale\IConfig
2023
-	 */
2024
-	public function getGlobalScaleConfig() {
2025
-		return $this->query(IConfig::class);
2026
-	}
2027
-
2028
-	/**
2029
-	 * @return \OCP\Federation\ICloudFederationProviderManager
2030
-	 */
2031
-	public function getCloudFederationProviderManager() {
2032
-		return $this->query(ICloudFederationProviderManager::class);
2033
-	}
2034
-
2035
-	/**
2036
-	 * @return \OCP\Remote\Api\IApiFactory
2037
-	 */
2038
-	public function getRemoteApiFactory() {
2039
-		return $this->query(IApiFactory::class);
2040
-	}
2041
-
2042
-	/**
2043
-	 * @return \OCP\Federation\ICloudFederationFactory
2044
-	 */
2045
-	public function getCloudFederationFactory() {
2046
-		return $this->query(ICloudFederationFactory::class);
2047
-	}
2048
-
2049
-	/**
2050
-	 * @return \OCP\Remote\IInstanceFactory
2051
-	 */
2052
-	public function getRemoteInstanceFactory() {
2053
-		return $this->query(IInstanceFactory::class);
2054
-	}
2055
-
2056
-	/**
2057
-	 * @return IStorageFactory
2058
-	 */
2059
-	public function getStorageFactory() {
2060
-		return $this->query(IStorageFactory::class);
2061
-	}
950
+            $prefixes = \OC::$composerAutoloader->getPrefixesPsr4();
951
+            if (isset($prefixes['OCA\\Theming\\'])) {
952
+                $classExists = true;
953
+            } else {
954
+                $classExists = false;
955
+            }
956
+
957
+            if ($classExists && $c->getConfig()->getSystemValue('installed', false) && $c->getAppManager()->isInstalled('theming') && $c->getTrustedDomainHelper()->isTrustedDomain($c->getRequest()->getInsecureServerHost())) {
958
+                return new ThemingDefaults(
959
+                    $c->getConfig(),
960
+                    $c->getL10N('theming'),
961
+                    $c->getURLGenerator(),
962
+                    $c->getMemCacheFactory(),
963
+                    new Util($c->getConfig(), $this->getAppManager(), $c->getAppDataDir('theming')),
964
+                    new ImageManager($c->getConfig(), $c->getAppDataDir('theming'), $c->getURLGenerator(), $this->getMemCacheFactory(), $this->getLogger()),
965
+                    $c->getAppManager()
966
+                );
967
+            }
968
+            return new \OC_Defaults();
969
+        });
970
+        $this->registerService(SCSSCacher::class, function (Server $c) {
971
+            /** @var Factory $cacheFactory */
972
+            $cacheFactory = $c->query(Factory::class);
973
+            return new SCSSCacher(
974
+                $c->getLogger(),
975
+                $c->query(\OC\Files\AppData\Factory::class),
976
+                $c->getURLGenerator(),
977
+                $c->getConfig(),
978
+                $c->getThemingDefaults(),
979
+                \OC::$SERVERROOT,
980
+                $this->getMemCacheFactory(),
981
+                $c->query(IconsCacher::class),
982
+                new TimeFactory()
983
+            );
984
+        });
985
+        $this->registerService(JSCombiner::class, function (Server $c) {
986
+            /** @var Factory $cacheFactory */
987
+            $cacheFactory = $c->query(Factory::class);
988
+            return new JSCombiner(
989
+                $c->getAppDataDir('js'),
990
+                $c->getURLGenerator(),
991
+                $this->getMemCacheFactory(),
992
+                $c->getSystemConfig(),
993
+                $c->getLogger()
994
+            );
995
+        });
996
+        $this->registerService(EventDispatcher::class, function () {
997
+            return new EventDispatcher();
998
+        });
999
+        $this->registerAlias('EventDispatcher', EventDispatcher::class);
1000
+        $this->registerAlias(EventDispatcherInterface::class, EventDispatcher::class);
1001
+
1002
+        $this->registerService('CryptoWrapper', function (Server $c) {
1003
+            // FIXME: Instantiiated here due to cyclic dependency
1004
+            $request = new Request(
1005
+                [
1006
+                    'get' => $_GET,
1007
+                    'post' => $_POST,
1008
+                    'files' => $_FILES,
1009
+                    'server' => $_SERVER,
1010
+                    'env' => $_ENV,
1011
+                    'cookies' => $_COOKIE,
1012
+                    'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
1013
+                        ? $_SERVER['REQUEST_METHOD']
1014
+                        : null,
1015
+                ],
1016
+                $c->getSecureRandom(),
1017
+                $c->getConfig()
1018
+            );
1019
+
1020
+            return new CryptoWrapper(
1021
+                $c->getConfig(),
1022
+                $c->getCrypto(),
1023
+                $c->getSecureRandom(),
1024
+                $request
1025
+            );
1026
+        });
1027
+        $this->registerService('CsrfTokenManager', function (Server $c) {
1028
+            $tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom());
1029
+
1030
+            return new CsrfTokenManager(
1031
+                $tokenGenerator,
1032
+                $c->query(SessionStorage::class)
1033
+            );
1034
+        });
1035
+        $this->registerService(SessionStorage::class, function (Server $c) {
1036
+            return new SessionStorage($c->getSession());
1037
+        });
1038
+        $this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function (Server $c) {
1039
+            return new ContentSecurityPolicyManager();
1040
+        });
1041
+        $this->registerAlias('ContentSecurityPolicyManager', \OCP\Security\IContentSecurityPolicyManager::class);
1042
+
1043
+        $this->registerService('ContentSecurityPolicyNonceManager', function (Server $c) {
1044
+            return new ContentSecurityPolicyNonceManager(
1045
+                $c->getCsrfTokenManager(),
1046
+                $c->getRequest()
1047
+            );
1048
+        });
1049
+
1050
+        $this->registerService(\OCP\Share\IManager::class, function (Server $c) {
1051
+            $config = $c->getConfig();
1052
+            $factoryClass = $config->getSystemValue('sharing.managerFactory', ProviderFactory::class);
1053
+            /** @var \OCP\Share\IProviderFactory $factory */
1054
+            $factory = new $factoryClass($this);
1055
+
1056
+            $manager = new \OC\Share20\Manager(
1057
+                $c->getLogger(),
1058
+                $c->getConfig(),
1059
+                $c->getSecureRandom(),
1060
+                $c->getHasher(),
1061
+                $c->getMountManager(),
1062
+                $c->getGroupManager(),
1063
+                $c->getL10N('lib'),
1064
+                $c->getL10NFactory(),
1065
+                $factory,
1066
+                $c->getUserManager(),
1067
+                $c->getLazyRootFolder(),
1068
+                $c->getEventDispatcher(),
1069
+                $c->getMailer(),
1070
+                $c->getURLGenerator(),
1071
+                $c->getThemingDefaults()
1072
+            );
1073
+
1074
+            return $manager;
1075
+        });
1076
+        $this->registerAlias('ShareManager', \OCP\Share\IManager::class);
1077
+
1078
+        $this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function(Server $c) {
1079
+            $instance = new Collaboration\Collaborators\Search($c);
1080
+
1081
+            // register default plugins
1082
+            $instance->registerPlugin(['shareType' => 'SHARE_TYPE_USER', 'class' => UserPlugin::class]);
1083
+            $instance->registerPlugin(['shareType' => 'SHARE_TYPE_GROUP', 'class' => GroupPlugin::class]);
1084
+            $instance->registerPlugin(['shareType' => 'SHARE_TYPE_EMAIL', 'class' => MailPlugin::class]);
1085
+            $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE', 'class' => RemotePlugin::class]);
1086
+            $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE_GROUP', 'class' => RemoteGroupPlugin::class]);
1087
+
1088
+            return $instance;
1089
+        });
1090
+        $this->registerAlias('CollaboratorSearch', \OCP\Collaboration\Collaborators\ISearch::class);
1091
+        $this->registerAlias(\OCP\Collaboration\Collaborators\ISearchResult::class, \OC\Collaboration\Collaborators\SearchResult::class);
1092
+
1093
+        $this->registerAlias(\OCP\Collaboration\AutoComplete\IManager::class, \OC\Collaboration\AutoComplete\Manager::class);
1094
+
1095
+        $this->registerService('SettingsManager', function (Server $c) {
1096
+            $manager = new \OC\Settings\Manager(
1097
+                $c->getLogger(),
1098
+                $c->getL10N('lib'),
1099
+                $c->getURLGenerator(),
1100
+                $c
1101
+            );
1102
+            return $manager;
1103
+        });
1104
+        $this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) {
1105
+            return new \OC\Files\AppData\Factory(
1106
+                $c->getRootFolder(),
1107
+                $c->getSystemConfig()
1108
+            );
1109
+        });
1110
+
1111
+        $this->registerService('LockdownManager', function (Server $c) {
1112
+            return new LockdownManager(function () use ($c) {
1113
+                return $c->getSession();
1114
+            });
1115
+        });
1116
+
1117
+        $this->registerService(\OCP\OCS\IDiscoveryService::class, function (Server $c) {
1118
+            return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService());
1119
+        });
1120
+
1121
+        $this->registerService(ICloudIdManager::class, function (Server $c) {
1122
+            return new CloudIdManager();
1123
+        });
1124
+
1125
+        $this->registerService(IConfig::class, function (Server $c) {
1126
+            return new GlobalScale\Config($c->getConfig());
1127
+        });
1128
+
1129
+        $this->registerService(ICloudFederationProviderManager::class, function (Server $c) {
1130
+            return new CloudFederationProviderManager($c->getAppManager(), $c->getHTTPClientService(), $c->getCloudIdManager(), $c->getLogger());
1131
+        });
1132
+
1133
+        $this->registerService(ICloudFederationFactory::class, function (Server $c) {
1134
+            return new CloudFederationFactory();
1135
+        });
1136
+
1137
+        $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class);
1138
+        $this->registerAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class);
1139
+
1140
+        $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class);
1141
+        $this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class);
1142
+
1143
+        $this->registerService(Defaults::class, function (Server $c) {
1144
+            return new Defaults(
1145
+                $c->getThemingDefaults()
1146
+            );
1147
+        });
1148
+        $this->registerAlias('Defaults', \OCP\Defaults::class);
1149
+
1150
+        $this->registerService(\OCP\ISession::class, function (SimpleContainer $c) {
1151
+            return $c->query(\OCP\IUserSession::class)->getSession();
1152
+        });
1153
+
1154
+        $this->registerService(IShareHelper::class, function (Server $c) {
1155
+            return new ShareHelper(
1156
+                $c->query(\OCP\Share\IManager::class)
1157
+            );
1158
+        });
1159
+
1160
+        $this->registerService(Installer::class, function(Server $c) {
1161
+            return new Installer(
1162
+                $c->getAppFetcher(),
1163
+                $c->getHTTPClientService(),
1164
+                $c->getTempManager(),
1165
+                $c->getLogger(),
1166
+                $c->getConfig()
1167
+            );
1168
+        });
1169
+
1170
+        $this->registerService(IApiFactory::class, function(Server $c) {
1171
+            return new ApiFactory($c->getHTTPClientService());
1172
+        });
1173
+
1174
+        $this->registerService(IInstanceFactory::class, function(Server $c) {
1175
+            $memcacheFactory = $c->getMemCacheFactory();
1176
+            return new InstanceFactory($memcacheFactory->createLocal('remoteinstance.'), $c->getHTTPClientService());
1177
+        });
1178
+
1179
+        $this->registerService(IContactsStore::class, function(Server $c) {
1180
+            return new ContactsStore(
1181
+                $c->getContactsManager(),
1182
+                $c->getConfig(),
1183
+                $c->getUserManager(),
1184
+                $c->getGroupManager()
1185
+            );
1186
+        });
1187
+        $this->registerAlias(IContactsStore::class, ContactsStore::class);
1188
+        $this->registerAlias(IAccountManager::class, AccountManager::class);
1189
+
1190
+        $this->registerService(IStorageFactory::class, function() {
1191
+            return new StorageFactory();
1192
+        });
1193
+
1194
+        $this->registerAlias(IDashboardManager::class, DashboardManager::class);
1195
+        $this->registerAlias(IFullTextSearchManager::class, FullTextSearchManager::class);
1196
+
1197
+        $this->registerService(\OC\Security\IdentityProof\Manager::class, function (Server $c) {
1198
+            return new \OC\Security\IdentityProof\Manager(
1199
+                $c->query(\OC\Files\AppData\Factory::class),
1200
+                $c->getCrypto(),
1201
+                $c->getConfig()
1202
+            );
1203
+        });
1204
+
1205
+        $this->registerAlias(ISubAdmin::class, SubAdmin::class);
1206
+
1207
+        $this->connectDispatcher();
1208
+    }
1209
+
1210
+    /**
1211
+     * @return \OCP\Calendar\IManager
1212
+     */
1213
+    public function getCalendarManager() {
1214
+        return $this->query('CalendarManager');
1215
+    }
1216
+
1217
+    /**
1218
+     * @return \OCP\Calendar\Resource\IManager
1219
+     */
1220
+    public function getCalendarResourceBackendManager() {
1221
+        return $this->query('CalendarResourceBackendManager');
1222
+    }
1223
+
1224
+    /**
1225
+     * @return \OCP\Calendar\Room\IManager
1226
+     */
1227
+    public function getCalendarRoomBackendManager() {
1228
+        return $this->query('CalendarRoomBackendManager');
1229
+    }
1230
+
1231
+    private function connectDispatcher() {
1232
+        $dispatcher = $this->getEventDispatcher();
1233
+
1234
+        // Delete avatar on user deletion
1235
+        $dispatcher->addListener('OCP\IUser::preDelete', function(GenericEvent $e) {
1236
+            $logger = $this->getLogger();
1237
+            $manager = $this->getAvatarManager();
1238
+            /** @var IUser $user */
1239
+            $user = $e->getSubject();
1240
+
1241
+            try {
1242
+                $avatar = $manager->getAvatar($user->getUID());
1243
+                $avatar->remove();
1244
+            } catch (NotFoundException $e) {
1245
+                // no avatar to remove
1246
+            } catch (\Exception $e) {
1247
+                // Ignore exceptions
1248
+                $logger->info('Could not cleanup avatar of ' . $user->getUID());
1249
+            }
1250
+        });
1251
+
1252
+        $dispatcher->addListener('OCP\IUser::changeUser', function (GenericEvent $e) {
1253
+            $manager = $this->getAvatarManager();
1254
+            /** @var IUser $user */
1255
+            $user = $e->getSubject();
1256
+            $feature = $e->getArgument('feature');
1257
+            $oldValue = $e->getArgument('oldValue');
1258
+            $value = $e->getArgument('value');
1259
+
1260
+            try {
1261
+                $avatar = $manager->getAvatar($user->getUID());
1262
+                $avatar->userChanged($feature, $oldValue, $value);
1263
+            } catch (NotFoundException $e) {
1264
+                // no avatar to remove
1265
+            }
1266
+        });
1267
+    }
1268
+
1269
+    /**
1270
+     * @return \OCP\Contacts\IManager
1271
+     */
1272
+    public function getContactsManager() {
1273
+        return $this->query('ContactsManager');
1274
+    }
1275
+
1276
+    /**
1277
+     * @return \OC\Encryption\Manager
1278
+     */
1279
+    public function getEncryptionManager() {
1280
+        return $this->query('EncryptionManager');
1281
+    }
1282
+
1283
+    /**
1284
+     * @return \OC\Encryption\File
1285
+     */
1286
+    public function getEncryptionFilesHelper() {
1287
+        return $this->query('EncryptionFileHelper');
1288
+    }
1289
+
1290
+    /**
1291
+     * @return \OCP\Encryption\Keys\IStorage
1292
+     */
1293
+    public function getEncryptionKeyStorage() {
1294
+        return $this->query('EncryptionKeyStorage');
1295
+    }
1296
+
1297
+    /**
1298
+     * The current request object holding all information about the request
1299
+     * currently being processed is returned from this method.
1300
+     * In case the current execution was not initiated by a web request null is returned
1301
+     *
1302
+     * @return \OCP\IRequest
1303
+     */
1304
+    public function getRequest() {
1305
+        return $this->query('Request');
1306
+    }
1307
+
1308
+    /**
1309
+     * Returns the preview manager which can create preview images for a given file
1310
+     *
1311
+     * @return \OCP\IPreview
1312
+     */
1313
+    public function getPreviewManager() {
1314
+        return $this->query('PreviewManager');
1315
+    }
1316
+
1317
+    /**
1318
+     * Returns the tag manager which can get and set tags for different object types
1319
+     *
1320
+     * @see \OCP\ITagManager::load()
1321
+     * @return \OCP\ITagManager
1322
+     */
1323
+    public function getTagManager() {
1324
+        return $this->query('TagManager');
1325
+    }
1326
+
1327
+    /**
1328
+     * Returns the system-tag manager
1329
+     *
1330
+     * @return \OCP\SystemTag\ISystemTagManager
1331
+     *
1332
+     * @since 9.0.0
1333
+     */
1334
+    public function getSystemTagManager() {
1335
+        return $this->query('SystemTagManager');
1336
+    }
1337
+
1338
+    /**
1339
+     * Returns the system-tag object mapper
1340
+     *
1341
+     * @return \OCP\SystemTag\ISystemTagObjectMapper
1342
+     *
1343
+     * @since 9.0.0
1344
+     */
1345
+    public function getSystemTagObjectMapper() {
1346
+        return $this->query('SystemTagObjectMapper');
1347
+    }
1348
+
1349
+    /**
1350
+     * Returns the avatar manager, used for avatar functionality
1351
+     *
1352
+     * @return \OCP\IAvatarManager
1353
+     */
1354
+    public function getAvatarManager() {
1355
+        return $this->query('AvatarManager');
1356
+    }
1357
+
1358
+    /**
1359
+     * Returns the root folder of ownCloud's data directory
1360
+     *
1361
+     * @return \OCP\Files\IRootFolder
1362
+     */
1363
+    public function getRootFolder() {
1364
+        return $this->query('LazyRootFolder');
1365
+    }
1366
+
1367
+    /**
1368
+     * Returns the root folder of ownCloud's data directory
1369
+     * This is the lazy variant so this gets only initialized once it
1370
+     * is actually used.
1371
+     *
1372
+     * @return \OCP\Files\IRootFolder
1373
+     */
1374
+    public function getLazyRootFolder() {
1375
+        return $this->query('LazyRootFolder');
1376
+    }
1377
+
1378
+    /**
1379
+     * Returns a view to ownCloud's files folder
1380
+     *
1381
+     * @param string $userId user ID
1382
+     * @return \OCP\Files\Folder|null
1383
+     */
1384
+    public function getUserFolder($userId = null) {
1385
+        if ($userId === null) {
1386
+            $user = $this->getUserSession()->getUser();
1387
+            if (!$user) {
1388
+                return null;
1389
+            }
1390
+            $userId = $user->getUID();
1391
+        }
1392
+        $root = $this->getRootFolder();
1393
+        return $root->getUserFolder($userId);
1394
+    }
1395
+
1396
+    /**
1397
+     * Returns an app-specific view in ownClouds data directory
1398
+     *
1399
+     * @return \OCP\Files\Folder
1400
+     * @deprecated since 9.2.0 use IAppData
1401
+     */
1402
+    public function getAppFolder() {
1403
+        $dir = '/' . \OC_App::getCurrentApp();
1404
+        $root = $this->getRootFolder();
1405
+        if (!$root->nodeExists($dir)) {
1406
+            $folder = $root->newFolder($dir);
1407
+        } else {
1408
+            $folder = $root->get($dir);
1409
+        }
1410
+        return $folder;
1411
+    }
1412
+
1413
+    /**
1414
+     * @return \OC\User\Manager
1415
+     */
1416
+    public function getUserManager() {
1417
+        return $this->query('UserManager');
1418
+    }
1419
+
1420
+    /**
1421
+     * @return \OC\Group\Manager
1422
+     */
1423
+    public function getGroupManager() {
1424
+        return $this->query('GroupManager');
1425
+    }
1426
+
1427
+    /**
1428
+     * @return \OC\User\Session
1429
+     */
1430
+    public function getUserSession() {
1431
+        return $this->query('UserSession');
1432
+    }
1433
+
1434
+    /**
1435
+     * @return \OCP\ISession
1436
+     */
1437
+    public function getSession() {
1438
+        return $this->query('UserSession')->getSession();
1439
+    }
1440
+
1441
+    /**
1442
+     * @param \OCP\ISession $session
1443
+     */
1444
+    public function setSession(\OCP\ISession $session) {
1445
+        $this->query(SessionStorage::class)->setSession($session);
1446
+        $this->query('UserSession')->setSession($session);
1447
+        $this->query(Store::class)->setSession($session);
1448
+    }
1449
+
1450
+    /**
1451
+     * @return \OC\Authentication\TwoFactorAuth\Manager
1452
+     */
1453
+    public function getTwoFactorAuthManager() {
1454
+        return $this->query('\OC\Authentication\TwoFactorAuth\Manager');
1455
+    }
1456
+
1457
+    /**
1458
+     * @return \OC\NavigationManager
1459
+     */
1460
+    public function getNavigationManager() {
1461
+        return $this->query('NavigationManager');
1462
+    }
1463
+
1464
+    /**
1465
+     * @return \OCP\IConfig
1466
+     */
1467
+    public function getConfig() {
1468
+        return $this->query('AllConfig');
1469
+    }
1470
+
1471
+    /**
1472
+     * @return \OC\SystemConfig
1473
+     */
1474
+    public function getSystemConfig() {
1475
+        return $this->query('SystemConfig');
1476
+    }
1477
+
1478
+    /**
1479
+     * Returns the app config manager
1480
+     *
1481
+     * @return \OCP\IAppConfig
1482
+     */
1483
+    public function getAppConfig() {
1484
+        return $this->query('AppConfig');
1485
+    }
1486
+
1487
+    /**
1488
+     * @return \OCP\L10N\IFactory
1489
+     */
1490
+    public function getL10NFactory() {
1491
+        return $this->query('L10NFactory');
1492
+    }
1493
+
1494
+    /**
1495
+     * get an L10N instance
1496
+     *
1497
+     * @param string $app appid
1498
+     * @param string $lang
1499
+     * @return IL10N
1500
+     */
1501
+    public function getL10N($app, $lang = null) {
1502
+        return $this->getL10NFactory()->get($app, $lang);
1503
+    }
1504
+
1505
+    /**
1506
+     * @return \OCP\IURLGenerator
1507
+     */
1508
+    public function getURLGenerator() {
1509
+        return $this->query('URLGenerator');
1510
+    }
1511
+
1512
+    /**
1513
+     * @return AppFetcher
1514
+     */
1515
+    public function getAppFetcher() {
1516
+        return $this->query(AppFetcher::class);
1517
+    }
1518
+
1519
+    /**
1520
+     * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use
1521
+     * getMemCacheFactory() instead.
1522
+     *
1523
+     * @return \OCP\ICache
1524
+     * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache
1525
+     */
1526
+    public function getCache() {
1527
+        return $this->query('UserCache');
1528
+    }
1529
+
1530
+    /**
1531
+     * Returns an \OCP\CacheFactory instance
1532
+     *
1533
+     * @return \OCP\ICacheFactory
1534
+     */
1535
+    public function getMemCacheFactory() {
1536
+        return $this->query('MemCacheFactory');
1537
+    }
1538
+
1539
+    /**
1540
+     * Returns an \OC\RedisFactory instance
1541
+     *
1542
+     * @return \OC\RedisFactory
1543
+     */
1544
+    public function getGetRedisFactory() {
1545
+        return $this->query('RedisFactory');
1546
+    }
1547
+
1548
+
1549
+    /**
1550
+     * Returns the current session
1551
+     *
1552
+     * @return \OCP\IDBConnection
1553
+     */
1554
+    public function getDatabaseConnection() {
1555
+        return $this->query('DatabaseConnection');
1556
+    }
1557
+
1558
+    /**
1559
+     * Returns the activity manager
1560
+     *
1561
+     * @return \OCP\Activity\IManager
1562
+     */
1563
+    public function getActivityManager() {
1564
+        return $this->query('ActivityManager');
1565
+    }
1566
+
1567
+    /**
1568
+     * Returns an job list for controlling background jobs
1569
+     *
1570
+     * @return \OCP\BackgroundJob\IJobList
1571
+     */
1572
+    public function getJobList() {
1573
+        return $this->query('JobList');
1574
+    }
1575
+
1576
+    /**
1577
+     * Returns a logger instance
1578
+     *
1579
+     * @return \OCP\ILogger
1580
+     */
1581
+    public function getLogger() {
1582
+        return $this->query('Logger');
1583
+    }
1584
+
1585
+    /**
1586
+     * @return ILogFactory
1587
+     * @throws \OCP\AppFramework\QueryException
1588
+     */
1589
+    public function getLogFactory() {
1590
+        return $this->query(ILogFactory::class);
1591
+    }
1592
+
1593
+    /**
1594
+     * Returns a router for generating and matching urls
1595
+     *
1596
+     * @return \OCP\Route\IRouter
1597
+     */
1598
+    public function getRouter() {
1599
+        return $this->query('Router');
1600
+    }
1601
+
1602
+    /**
1603
+     * Returns a search instance
1604
+     *
1605
+     * @return \OCP\ISearch
1606
+     */
1607
+    public function getSearch() {
1608
+        return $this->query('Search');
1609
+    }
1610
+
1611
+    /**
1612
+     * Returns a SecureRandom instance
1613
+     *
1614
+     * @return \OCP\Security\ISecureRandom
1615
+     */
1616
+    public function getSecureRandom() {
1617
+        return $this->query('SecureRandom');
1618
+    }
1619
+
1620
+    /**
1621
+     * Returns a Crypto instance
1622
+     *
1623
+     * @return \OCP\Security\ICrypto
1624
+     */
1625
+    public function getCrypto() {
1626
+        return $this->query('Crypto');
1627
+    }
1628
+
1629
+    /**
1630
+     * Returns a Hasher instance
1631
+     *
1632
+     * @return \OCP\Security\IHasher
1633
+     */
1634
+    public function getHasher() {
1635
+        return $this->query('Hasher');
1636
+    }
1637
+
1638
+    /**
1639
+     * Returns a CredentialsManager instance
1640
+     *
1641
+     * @return \OCP\Security\ICredentialsManager
1642
+     */
1643
+    public function getCredentialsManager() {
1644
+        return $this->query('CredentialsManager');
1645
+    }
1646
+
1647
+    /**
1648
+     * Get the certificate manager for the user
1649
+     *
1650
+     * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager
1651
+     * @return \OCP\ICertificateManager | null if $uid is null and no user is logged in
1652
+     */
1653
+    public function getCertificateManager($userId = '') {
1654
+        if ($userId === '') {
1655
+            $userSession = $this->getUserSession();
1656
+            $user = $userSession->getUser();
1657
+            if (is_null($user)) {
1658
+                return null;
1659
+            }
1660
+            $userId = $user->getUID();
1661
+        }
1662
+        return new CertificateManager(
1663
+            $userId,
1664
+            new View(),
1665
+            $this->getConfig(),
1666
+            $this->getLogger(),
1667
+            $this->getSecureRandom()
1668
+        );
1669
+    }
1670
+
1671
+    /**
1672
+     * Returns an instance of the HTTP client service
1673
+     *
1674
+     * @return \OCP\Http\Client\IClientService
1675
+     */
1676
+    public function getHTTPClientService() {
1677
+        return $this->query('HttpClientService');
1678
+    }
1679
+
1680
+    /**
1681
+     * Create a new event source
1682
+     *
1683
+     * @return \OCP\IEventSource
1684
+     */
1685
+    public function createEventSource() {
1686
+        return new \OC_EventSource();
1687
+    }
1688
+
1689
+    /**
1690
+     * Get the active event logger
1691
+     *
1692
+     * The returned logger only logs data when debug mode is enabled
1693
+     *
1694
+     * @return \OCP\Diagnostics\IEventLogger
1695
+     */
1696
+    public function getEventLogger() {
1697
+        return $this->query('EventLogger');
1698
+    }
1699
+
1700
+    /**
1701
+     * Get the active query logger
1702
+     *
1703
+     * The returned logger only logs data when debug mode is enabled
1704
+     *
1705
+     * @return \OCP\Diagnostics\IQueryLogger
1706
+     */
1707
+    public function getQueryLogger() {
1708
+        return $this->query('QueryLogger');
1709
+    }
1710
+
1711
+    /**
1712
+     * Get the manager for temporary files and folders
1713
+     *
1714
+     * @return \OCP\ITempManager
1715
+     */
1716
+    public function getTempManager() {
1717
+        return $this->query('TempManager');
1718
+    }
1719
+
1720
+    /**
1721
+     * Get the app manager
1722
+     *
1723
+     * @return \OCP\App\IAppManager
1724
+     */
1725
+    public function getAppManager() {
1726
+        return $this->query('AppManager');
1727
+    }
1728
+
1729
+    /**
1730
+     * Creates a new mailer
1731
+     *
1732
+     * @return \OCP\Mail\IMailer
1733
+     */
1734
+    public function getMailer() {
1735
+        return $this->query('Mailer');
1736
+    }
1737
+
1738
+    /**
1739
+     * Get the webroot
1740
+     *
1741
+     * @return string
1742
+     */
1743
+    public function getWebRoot() {
1744
+        return $this->webRoot;
1745
+    }
1746
+
1747
+    /**
1748
+     * @return \OC\OCSClient
1749
+     */
1750
+    public function getOcsClient() {
1751
+        return $this->query('OcsClient');
1752
+    }
1753
+
1754
+    /**
1755
+     * @return \OCP\IDateTimeZone
1756
+     */
1757
+    public function getDateTimeZone() {
1758
+        return $this->query('DateTimeZone');
1759
+    }
1760
+
1761
+    /**
1762
+     * @return \OCP\IDateTimeFormatter
1763
+     */
1764
+    public function getDateTimeFormatter() {
1765
+        return $this->query('DateTimeFormatter');
1766
+    }
1767
+
1768
+    /**
1769
+     * @return \OCP\Files\Config\IMountProviderCollection
1770
+     */
1771
+    public function getMountProviderCollection() {
1772
+        return $this->query('MountConfigManager');
1773
+    }
1774
+
1775
+    /**
1776
+     * Get the IniWrapper
1777
+     *
1778
+     * @return IniGetWrapper
1779
+     */
1780
+    public function getIniWrapper() {
1781
+        return $this->query('IniWrapper');
1782
+    }
1783
+
1784
+    /**
1785
+     * @return \OCP\Command\IBus
1786
+     */
1787
+    public function getCommandBus() {
1788
+        return $this->query('AsyncCommandBus');
1789
+    }
1790
+
1791
+    /**
1792
+     * Get the trusted domain helper
1793
+     *
1794
+     * @return TrustedDomainHelper
1795
+     */
1796
+    public function getTrustedDomainHelper() {
1797
+        return $this->query('TrustedDomainHelper');
1798
+    }
1799
+
1800
+    /**
1801
+     * Get the locking provider
1802
+     *
1803
+     * @return \OCP\Lock\ILockingProvider
1804
+     * @since 8.1.0
1805
+     */
1806
+    public function getLockingProvider() {
1807
+        return $this->query('LockingProvider');
1808
+    }
1809
+
1810
+    /**
1811
+     * @return \OCP\Files\Mount\IMountManager
1812
+     **/
1813
+    function getMountManager() {
1814
+        return $this->query('MountManager');
1815
+    }
1816
+
1817
+    /** @return \OCP\Files\Config\IUserMountCache */
1818
+    function getUserMountCache() {
1819
+        return $this->query('UserMountCache');
1820
+    }
1821
+
1822
+    /**
1823
+     * Get the MimeTypeDetector
1824
+     *
1825
+     * @return \OCP\Files\IMimeTypeDetector
1826
+     */
1827
+    public function getMimeTypeDetector() {
1828
+        return $this->query('MimeTypeDetector');
1829
+    }
1830
+
1831
+    /**
1832
+     * Get the MimeTypeLoader
1833
+     *
1834
+     * @return \OCP\Files\IMimeTypeLoader
1835
+     */
1836
+    public function getMimeTypeLoader() {
1837
+        return $this->query('MimeTypeLoader');
1838
+    }
1839
+
1840
+    /**
1841
+     * Get the manager of all the capabilities
1842
+     *
1843
+     * @return \OC\CapabilitiesManager
1844
+     */
1845
+    public function getCapabilitiesManager() {
1846
+        return $this->query('CapabilitiesManager');
1847
+    }
1848
+
1849
+    /**
1850
+     * Get the EventDispatcher
1851
+     *
1852
+     * @return EventDispatcherInterface
1853
+     * @since 8.2.0
1854
+     */
1855
+    public function getEventDispatcher() {
1856
+        return $this->query('EventDispatcher');
1857
+    }
1858
+
1859
+    /**
1860
+     * Get the Notification Manager
1861
+     *
1862
+     * @return \OCP\Notification\IManager
1863
+     * @since 8.2.0
1864
+     */
1865
+    public function getNotificationManager() {
1866
+        return $this->query('NotificationManager');
1867
+    }
1868
+
1869
+    /**
1870
+     * @return \OCP\Comments\ICommentsManager
1871
+     */
1872
+    public function getCommentsManager() {
1873
+        return $this->query('CommentsManager');
1874
+    }
1875
+
1876
+    /**
1877
+     * @return \OCA\Theming\ThemingDefaults
1878
+     */
1879
+    public function getThemingDefaults() {
1880
+        return $this->query('ThemingDefaults');
1881
+    }
1882
+
1883
+    /**
1884
+     * @return \OC\IntegrityCheck\Checker
1885
+     */
1886
+    public function getIntegrityCodeChecker() {
1887
+        return $this->query('IntegrityCodeChecker');
1888
+    }
1889
+
1890
+    /**
1891
+     * @return \OC\Session\CryptoWrapper
1892
+     */
1893
+    public function getSessionCryptoWrapper() {
1894
+        return $this->query('CryptoWrapper');
1895
+    }
1896
+
1897
+    /**
1898
+     * @return CsrfTokenManager
1899
+     */
1900
+    public function getCsrfTokenManager() {
1901
+        return $this->query('CsrfTokenManager');
1902
+    }
1903
+
1904
+    /**
1905
+     * @return Throttler
1906
+     */
1907
+    public function getBruteForceThrottler() {
1908
+        return $this->query('Throttler');
1909
+    }
1910
+
1911
+    /**
1912
+     * @return IContentSecurityPolicyManager
1913
+     */
1914
+    public function getContentSecurityPolicyManager() {
1915
+        return $this->query('ContentSecurityPolicyManager');
1916
+    }
1917
+
1918
+    /**
1919
+     * @return ContentSecurityPolicyNonceManager
1920
+     */
1921
+    public function getContentSecurityPolicyNonceManager() {
1922
+        return $this->query('ContentSecurityPolicyNonceManager');
1923
+    }
1924
+
1925
+    /**
1926
+     * Not a public API as of 8.2, wait for 9.0
1927
+     *
1928
+     * @return \OCA\Files_External\Service\BackendService
1929
+     */
1930
+    public function getStoragesBackendService() {
1931
+        return $this->query('OCA\\Files_External\\Service\\BackendService');
1932
+    }
1933
+
1934
+    /**
1935
+     * Not a public API as of 8.2, wait for 9.0
1936
+     *
1937
+     * @return \OCA\Files_External\Service\GlobalStoragesService
1938
+     */
1939
+    public function getGlobalStoragesService() {
1940
+        return $this->query('OCA\\Files_External\\Service\\GlobalStoragesService');
1941
+    }
1942
+
1943
+    /**
1944
+     * Not a public API as of 8.2, wait for 9.0
1945
+     *
1946
+     * @return \OCA\Files_External\Service\UserGlobalStoragesService
1947
+     */
1948
+    public function getUserGlobalStoragesService() {
1949
+        return $this->query('OCA\\Files_External\\Service\\UserGlobalStoragesService');
1950
+    }
1951
+
1952
+    /**
1953
+     * Not a public API as of 8.2, wait for 9.0
1954
+     *
1955
+     * @return \OCA\Files_External\Service\UserStoragesService
1956
+     */
1957
+    public function getUserStoragesService() {
1958
+        return $this->query('OCA\\Files_External\\Service\\UserStoragesService');
1959
+    }
1960
+
1961
+    /**
1962
+     * @return \OCP\Share\IManager
1963
+     */
1964
+    public function getShareManager() {
1965
+        return $this->query('ShareManager');
1966
+    }
1967
+
1968
+    /**
1969
+     * @return \OCP\Collaboration\Collaborators\ISearch
1970
+     */
1971
+    public function getCollaboratorSearch() {
1972
+        return $this->query('CollaboratorSearch');
1973
+    }
1974
+
1975
+    /**
1976
+     * @return \OCP\Collaboration\AutoComplete\IManager
1977
+     */
1978
+    public function getAutoCompleteManager(){
1979
+        return $this->query(IManager::class);
1980
+    }
1981
+
1982
+    /**
1983
+     * Returns the LDAP Provider
1984
+     *
1985
+     * @return \OCP\LDAP\ILDAPProvider
1986
+     */
1987
+    public function getLDAPProvider() {
1988
+        return $this->query('LDAPProvider');
1989
+    }
1990
+
1991
+    /**
1992
+     * @return \OCP\Settings\IManager
1993
+     */
1994
+    public function getSettingsManager() {
1995
+        return $this->query('SettingsManager');
1996
+    }
1997
+
1998
+    /**
1999
+     * @return \OCP\Files\IAppData
2000
+     */
2001
+    public function getAppDataDir($app) {
2002
+        /** @var \OC\Files\AppData\Factory $factory */
2003
+        $factory = $this->query(\OC\Files\AppData\Factory::class);
2004
+        return $factory->get($app);
2005
+    }
2006
+
2007
+    /**
2008
+     * @return \OCP\Lockdown\ILockdownManager
2009
+     */
2010
+    public function getLockdownManager() {
2011
+        return $this->query('LockdownManager');
2012
+    }
2013
+
2014
+    /**
2015
+     * @return \OCP\Federation\ICloudIdManager
2016
+     */
2017
+    public function getCloudIdManager() {
2018
+        return $this->query(ICloudIdManager::class);
2019
+    }
2020
+
2021
+    /**
2022
+     * @return \OCP\GlobalScale\IConfig
2023
+     */
2024
+    public function getGlobalScaleConfig() {
2025
+        return $this->query(IConfig::class);
2026
+    }
2027
+
2028
+    /**
2029
+     * @return \OCP\Federation\ICloudFederationProviderManager
2030
+     */
2031
+    public function getCloudFederationProviderManager() {
2032
+        return $this->query(ICloudFederationProviderManager::class);
2033
+    }
2034
+
2035
+    /**
2036
+     * @return \OCP\Remote\Api\IApiFactory
2037
+     */
2038
+    public function getRemoteApiFactory() {
2039
+        return $this->query(IApiFactory::class);
2040
+    }
2041
+
2042
+    /**
2043
+     * @return \OCP\Federation\ICloudFederationFactory
2044
+     */
2045
+    public function getCloudFederationFactory() {
2046
+        return $this->query(ICloudFederationFactory::class);
2047
+    }
2048
+
2049
+    /**
2050
+     * @return \OCP\Remote\IInstanceFactory
2051
+     */
2052
+    public function getRemoteInstanceFactory() {
2053
+        return $this->query(IInstanceFactory::class);
2054
+    }
2055
+
2056
+    /**
2057
+     * @return IStorageFactory
2058
+     */
2059
+    public function getStorageFactory() {
2060
+        return $this->query(IStorageFactory::class);
2061
+    }
2062 2062
 }
Please login to merge, or discard this patch.
lib/private/SubAdmin.php 2 patches
Indentation   +246 added lines, -246 removed lines patch added patch discarded remove patch
@@ -38,252 +38,252 @@
 block discarded – undo
38 38
 
39 39
 class SubAdmin extends PublicEmitter implements ISubAdmin {
40 40
 
41
-	/** @var IUserManager */
42
-	private $userManager;
43
-
44
-	/** @var IGroupManager */
45
-	private $groupManager;
46
-
47
-	/** @var IDBConnection */
48
-	private $dbConn;
49
-
50
-	/**
51
-	 * @param IUserManager $userManager
52
-	 * @param IGroupManager $groupManager
53
-	 * @param IDBConnection $dbConn
54
-	 */
55
-	public function __construct(IUserManager $userManager,
56
-	                            IGroupManager $groupManager,
57
-								IDBConnection $dbConn) {
58
-		$this->userManager = $userManager;
59
-		$this->groupManager = $groupManager;
60
-		$this->dbConn = $dbConn;
61
-
62
-		$this->userManager->listen('\OC\User', 'postDelete', function($user) {
63
-			$this->post_deleteUser($user);
64
-		});
65
-		$this->groupManager->listen('\OC\Group', 'postDelete', function($group) {
66
-			$this->post_deleteGroup($group);
67
-		});
68
-	}
69
-
70
-	/**
71
-	 * add a SubAdmin
72
-	 * @param IUser $user user to be SubAdmin
73
-	 * @param IGroup $group group $user becomes subadmin of
74
-	 */
75
-	public function createSubAdmin(IUser $user, IGroup $group): void {
76
-		$qb = $this->dbConn->getQueryBuilder();
77
-
78
-		$qb->insert('group_admin')
79
-			->values([
80
-				'gid' => $qb->createNamedParameter($group->getGID()),
81
-				'uid' => $qb->createNamedParameter($user->getUID())
82
-			])
83
-			->execute();
84
-
85
-		$this->emit('\OC\SubAdmin', 'postCreateSubAdmin', [$user, $group]);
86
-		\OC_Hook::emit("OC_SubAdmin", "post_createSubAdmin", ["gid" => $group->getGID()]);
87
-	}
88
-
89
-	/**
90
-	 * delete a SubAdmin
91
-	 * @param IUser $user the user that is the SubAdmin
92
-	 * @param IGroup $group the group
93
-	 */
94
-	public function deleteSubAdmin(IUser $user, IGroup $group): void {
95
-		$qb = $this->dbConn->getQueryBuilder();
96
-
97
-		$qb->delete('group_admin')
98
-			->where($qb->expr()->eq('gid', $qb->createNamedParameter($group->getGID())))
99
-			->andWhere($qb->expr()->eq('uid', $qb->createNamedParameter($user->getUID())))
100
-			->execute();
101
-
102
-		$this->emit('\OC\SubAdmin', 'postDeleteSubAdmin', [$user, $group]);
103
-		\OC_Hook::emit("OC_SubAdmin", "post_deleteSubAdmin", ["gid" => $group->getGID()]);
104
-	}
105
-
106
-	/**
107
-	 * get groups of a SubAdmin
108
-	 * @param IUser $user the SubAdmin
109
-	 * @return IGroup[]
110
-	 */
111
-	public function getSubAdminsGroups(IUser $user): array {
112
-		$qb = $this->dbConn->getQueryBuilder();
113
-
114
-		$result = $qb->select('gid')
115
-			->from('group_admin')
116
-			->where($qb->expr()->eq('uid', $qb->createNamedParameter($user->getUID())))
117
-			->execute();
118
-
119
-		$groups = [];
120
-		while($row = $result->fetch()) {
121
-			$group = $this->groupManager->get($row['gid']);
122
-			if(!is_null($group)) {
123
-				$groups[$group->getGID()] = $group;
124
-			}
125
-		}
126
-		$result->closeCursor();
127
-
128
-		return $groups;
129
-	}
130
-
131
-	/**
132
-	 * get an array of groupid and displayName for a user
133
-	 * @param IUser $user
134
-	 * @return array ['displayName' => displayname]
135
-	 */
136
-	public function getSubAdminsGroupsName(IUser $user): array {
137
-		return array_map(function($group) {
138
-			return array('displayName' => $group->getDisplayName());
139
-		}, $this->getSubAdminsGroups($user));
140
-	}
141
-
142
-	/**
143
-	 * get SubAdmins of a group
144
-	 * @param IGroup $group the group
145
-	 * @return IUser[]
146
-	 */
147
-	public function getGroupsSubAdmins(IGroup $group): array {
148
-		$qb = $this->dbConn->getQueryBuilder();
149
-
150
-		$result = $qb->select('uid')
151
-			->from('group_admin')
152
-			->where($qb->expr()->eq('gid', $qb->createNamedParameter($group->getGID())))
153
-			->execute();
154
-
155
-		$users = [];
156
-		while($row = $result->fetch()) {
157
-			$user = $this->userManager->get($row['uid']);
158
-			if(!is_null($user)) {
159
-				$users[] = $user;
160
-			}
161
-		}
162
-		$result->closeCursor();
163
-
164
-		return $users;
165
-	}
166
-
167
-	/**
168
-	 * get all SubAdmins
169
-	 * @return array
170
-	 */
171
-	public function getAllSubAdmins(): array {
172
-		$qb = $this->dbConn->getQueryBuilder();
173
-
174
-		$result = $qb->select('*')
175
-			->from('group_admin')
176
-			->execute();
177
-
178
-		$subadmins = [];
179
-		while($row = $result->fetch()) {
180
-			$user = $this->userManager->get($row['uid']);
181
-			$group = $this->groupManager->get($row['gid']);
182
-			if(!is_null($user) && !is_null($group)) {
183
-				$subadmins[] = [
184
-					'user'  => $user,
185
-					'group' => $group
186
-				];
187
-			}
188
-		}
189
-		$result->closeCursor();
190
-
191
-		return $subadmins;
192
-	}
193
-
194
-	/**
195
-	 * checks if a user is a SubAdmin of a group
196
-	 * @param IUser $user
197
-	 * @param IGroup $group
198
-	 * @return bool
199
-	 */
200
-	public function isSubAdminOfGroup(IUser $user, IGroup $group): bool {
201
-		$qb = $this->dbConn->getQueryBuilder();
202
-
203
-		/*
41
+    /** @var IUserManager */
42
+    private $userManager;
43
+
44
+    /** @var IGroupManager */
45
+    private $groupManager;
46
+
47
+    /** @var IDBConnection */
48
+    private $dbConn;
49
+
50
+    /**
51
+     * @param IUserManager $userManager
52
+     * @param IGroupManager $groupManager
53
+     * @param IDBConnection $dbConn
54
+     */
55
+    public function __construct(IUserManager $userManager,
56
+                                IGroupManager $groupManager,
57
+                                IDBConnection $dbConn) {
58
+        $this->userManager = $userManager;
59
+        $this->groupManager = $groupManager;
60
+        $this->dbConn = $dbConn;
61
+
62
+        $this->userManager->listen('\OC\User', 'postDelete', function($user) {
63
+            $this->post_deleteUser($user);
64
+        });
65
+        $this->groupManager->listen('\OC\Group', 'postDelete', function($group) {
66
+            $this->post_deleteGroup($group);
67
+        });
68
+    }
69
+
70
+    /**
71
+     * add a SubAdmin
72
+     * @param IUser $user user to be SubAdmin
73
+     * @param IGroup $group group $user becomes subadmin of
74
+     */
75
+    public function createSubAdmin(IUser $user, IGroup $group): void {
76
+        $qb = $this->dbConn->getQueryBuilder();
77
+
78
+        $qb->insert('group_admin')
79
+            ->values([
80
+                'gid' => $qb->createNamedParameter($group->getGID()),
81
+                'uid' => $qb->createNamedParameter($user->getUID())
82
+            ])
83
+            ->execute();
84
+
85
+        $this->emit('\OC\SubAdmin', 'postCreateSubAdmin', [$user, $group]);
86
+        \OC_Hook::emit("OC_SubAdmin", "post_createSubAdmin", ["gid" => $group->getGID()]);
87
+    }
88
+
89
+    /**
90
+     * delete a SubAdmin
91
+     * @param IUser $user the user that is the SubAdmin
92
+     * @param IGroup $group the group
93
+     */
94
+    public function deleteSubAdmin(IUser $user, IGroup $group): void {
95
+        $qb = $this->dbConn->getQueryBuilder();
96
+
97
+        $qb->delete('group_admin')
98
+            ->where($qb->expr()->eq('gid', $qb->createNamedParameter($group->getGID())))
99
+            ->andWhere($qb->expr()->eq('uid', $qb->createNamedParameter($user->getUID())))
100
+            ->execute();
101
+
102
+        $this->emit('\OC\SubAdmin', 'postDeleteSubAdmin', [$user, $group]);
103
+        \OC_Hook::emit("OC_SubAdmin", "post_deleteSubAdmin", ["gid" => $group->getGID()]);
104
+    }
105
+
106
+    /**
107
+     * get groups of a SubAdmin
108
+     * @param IUser $user the SubAdmin
109
+     * @return IGroup[]
110
+     */
111
+    public function getSubAdminsGroups(IUser $user): array {
112
+        $qb = $this->dbConn->getQueryBuilder();
113
+
114
+        $result = $qb->select('gid')
115
+            ->from('group_admin')
116
+            ->where($qb->expr()->eq('uid', $qb->createNamedParameter($user->getUID())))
117
+            ->execute();
118
+
119
+        $groups = [];
120
+        while($row = $result->fetch()) {
121
+            $group = $this->groupManager->get($row['gid']);
122
+            if(!is_null($group)) {
123
+                $groups[$group->getGID()] = $group;
124
+            }
125
+        }
126
+        $result->closeCursor();
127
+
128
+        return $groups;
129
+    }
130
+
131
+    /**
132
+     * get an array of groupid and displayName for a user
133
+     * @param IUser $user
134
+     * @return array ['displayName' => displayname]
135
+     */
136
+    public function getSubAdminsGroupsName(IUser $user): array {
137
+        return array_map(function($group) {
138
+            return array('displayName' => $group->getDisplayName());
139
+        }, $this->getSubAdminsGroups($user));
140
+    }
141
+
142
+    /**
143
+     * get SubAdmins of a group
144
+     * @param IGroup $group the group
145
+     * @return IUser[]
146
+     */
147
+    public function getGroupsSubAdmins(IGroup $group): array {
148
+        $qb = $this->dbConn->getQueryBuilder();
149
+
150
+        $result = $qb->select('uid')
151
+            ->from('group_admin')
152
+            ->where($qb->expr()->eq('gid', $qb->createNamedParameter($group->getGID())))
153
+            ->execute();
154
+
155
+        $users = [];
156
+        while($row = $result->fetch()) {
157
+            $user = $this->userManager->get($row['uid']);
158
+            if(!is_null($user)) {
159
+                $users[] = $user;
160
+            }
161
+        }
162
+        $result->closeCursor();
163
+
164
+        return $users;
165
+    }
166
+
167
+    /**
168
+     * get all SubAdmins
169
+     * @return array
170
+     */
171
+    public function getAllSubAdmins(): array {
172
+        $qb = $this->dbConn->getQueryBuilder();
173
+
174
+        $result = $qb->select('*')
175
+            ->from('group_admin')
176
+            ->execute();
177
+
178
+        $subadmins = [];
179
+        while($row = $result->fetch()) {
180
+            $user = $this->userManager->get($row['uid']);
181
+            $group = $this->groupManager->get($row['gid']);
182
+            if(!is_null($user) && !is_null($group)) {
183
+                $subadmins[] = [
184
+                    'user'  => $user,
185
+                    'group' => $group
186
+                ];
187
+            }
188
+        }
189
+        $result->closeCursor();
190
+
191
+        return $subadmins;
192
+    }
193
+
194
+    /**
195
+     * checks if a user is a SubAdmin of a group
196
+     * @param IUser $user
197
+     * @param IGroup $group
198
+     * @return bool
199
+     */
200
+    public function isSubAdminOfGroup(IUser $user, IGroup $group): bool {
201
+        $qb = $this->dbConn->getQueryBuilder();
202
+
203
+        /*
204 204
 		 * Primary key is ('gid', 'uid') so max 1 result possible here
205 205
 		 */
206
-		$result = $qb->select('*')
207
-			->from('group_admin')
208
-			->where($qb->expr()->eq('gid', $qb->createNamedParameter($group->getGID())))
209
-			->andWhere($qb->expr()->eq('uid', $qb->createNamedParameter($user->getUID())))
210
-			->execute();
211
-
212
-		$fetch =  $result->fetch();
213
-		$result->closeCursor();
214
-		$result = !empty($fetch) ? true : false;
215
-
216
-		return $result;
217
-	}
218
-
219
-	/**
220
-	 * checks if a user is a SubAdmin
221
-	 * @param IUser $user
222
-	 * @return bool
223
-	 */
224
-	public function isSubAdmin(IUser $user): bool {
225
-		// Check if the user is already an admin
226
-		if ($this->groupManager->isAdmin($user->getUID())) {
227
-			return true;
228
-		}
229
-
230
-		$qb = $this->dbConn->getQueryBuilder();
231
-
232
-		$result = $qb->select('gid')
233
-			->from('group_admin')
234
-			->andWhere($qb->expr()->eq('uid', $qb->createNamedParameter($user->getUID())))
235
-			->setMaxResults(1)
236
-			->execute();
237
-
238
-		$isSubAdmin = $result->fetch();
239
-		$result->closeCursor();
240
-
241
-		return $isSubAdmin !== false;
242
-	}
243
-
244
-	/**
245
-	 * checks if a user is a accessible by a subadmin
246
-	 * @param IUser $subadmin
247
-	 * @param IUser $user
248
-	 * @return bool
249
-	 */
250
-	public function isUserAccessible(IUser $subadmin, IUser $user): bool {
251
-		if(!$this->isSubAdmin($subadmin)) {
252
-			return false;
253
-		}
254
-		if($this->groupManager->isAdmin($user->getUID())) {
255
-			return false;
256
-		}
257
-		$accessibleGroups = $this->getSubAdminsGroups($subadmin);
258
-		foreach($accessibleGroups as $accessibleGroup) {
259
-			if($accessibleGroup->inGroup($user)) {
260
-				return true;
261
-			}
262
-		}
263
-		return false;
264
-	}
265
-
266
-	/**
267
-	 * delete all SubAdmins by $user
268
-	 * @param IUser $user
269
-	 */
270
-	private function post_deleteUser(IUser $user) {
271
-		$qb = $this->dbConn->getQueryBuilder();
272
-
273
-		$qb->delete('group_admin')
274
-			->where($qb->expr()->eq('uid', $qb->createNamedParameter($user->getUID())))
275
-			->execute();
276
-	}
277
-
278
-	/**
279
-	 * delete all SubAdmins by $group
280
-	 * @param IGroup $group
281
-	 */
282
-	private function post_deleteGroup(IGroup $group) {
283
-		$qb = $this->dbConn->getQueryBuilder();
284
-
285
-		$qb->delete('group_admin')
286
-			->where($qb->expr()->eq('gid', $qb->createNamedParameter($group->getGID())))
287
-			->execute();
288
-	}
206
+        $result = $qb->select('*')
207
+            ->from('group_admin')
208
+            ->where($qb->expr()->eq('gid', $qb->createNamedParameter($group->getGID())))
209
+            ->andWhere($qb->expr()->eq('uid', $qb->createNamedParameter($user->getUID())))
210
+            ->execute();
211
+
212
+        $fetch =  $result->fetch();
213
+        $result->closeCursor();
214
+        $result = !empty($fetch) ? true : false;
215
+
216
+        return $result;
217
+    }
218
+
219
+    /**
220
+     * checks if a user is a SubAdmin
221
+     * @param IUser $user
222
+     * @return bool
223
+     */
224
+    public function isSubAdmin(IUser $user): bool {
225
+        // Check if the user is already an admin
226
+        if ($this->groupManager->isAdmin($user->getUID())) {
227
+            return true;
228
+        }
229
+
230
+        $qb = $this->dbConn->getQueryBuilder();
231
+
232
+        $result = $qb->select('gid')
233
+            ->from('group_admin')
234
+            ->andWhere($qb->expr()->eq('uid', $qb->createNamedParameter($user->getUID())))
235
+            ->setMaxResults(1)
236
+            ->execute();
237
+
238
+        $isSubAdmin = $result->fetch();
239
+        $result->closeCursor();
240
+
241
+        return $isSubAdmin !== false;
242
+    }
243
+
244
+    /**
245
+     * checks if a user is a accessible by a subadmin
246
+     * @param IUser $subadmin
247
+     * @param IUser $user
248
+     * @return bool
249
+     */
250
+    public function isUserAccessible(IUser $subadmin, IUser $user): bool {
251
+        if(!$this->isSubAdmin($subadmin)) {
252
+            return false;
253
+        }
254
+        if($this->groupManager->isAdmin($user->getUID())) {
255
+            return false;
256
+        }
257
+        $accessibleGroups = $this->getSubAdminsGroups($subadmin);
258
+        foreach($accessibleGroups as $accessibleGroup) {
259
+            if($accessibleGroup->inGroup($user)) {
260
+                return true;
261
+            }
262
+        }
263
+        return false;
264
+    }
265
+
266
+    /**
267
+     * delete all SubAdmins by $user
268
+     * @param IUser $user
269
+     */
270
+    private function post_deleteUser(IUser $user) {
271
+        $qb = $this->dbConn->getQueryBuilder();
272
+
273
+        $qb->delete('group_admin')
274
+            ->where($qb->expr()->eq('uid', $qb->createNamedParameter($user->getUID())))
275
+            ->execute();
276
+    }
277
+
278
+    /**
279
+     * delete all SubAdmins by $group
280
+     * @param IGroup $group
281
+     */
282
+    private function post_deleteGroup(IGroup $group) {
283
+        $qb = $this->dbConn->getQueryBuilder();
284
+
285
+        $qb->delete('group_admin')
286
+            ->where($qb->expr()->eq('gid', $qb->createNamedParameter($group->getGID())))
287
+            ->execute();
288
+    }
289 289
 }
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -117,9 +117,9 @@  discard block
 block discarded – undo
117 117
 			->execute();
118 118
 
119 119
 		$groups = [];
120
-		while($row = $result->fetch()) {
120
+		while ($row = $result->fetch()) {
121 121
 			$group = $this->groupManager->get($row['gid']);
122
-			if(!is_null($group)) {
122
+			if (!is_null($group)) {
123 123
 				$groups[$group->getGID()] = $group;
124 124
 			}
125 125
 		}
@@ -153,9 +153,9 @@  discard block
 block discarded – undo
153 153
 			->execute();
154 154
 
155 155
 		$users = [];
156
-		while($row = $result->fetch()) {
156
+		while ($row = $result->fetch()) {
157 157
 			$user = $this->userManager->get($row['uid']);
158
-			if(!is_null($user)) {
158
+			if (!is_null($user)) {
159 159
 				$users[] = $user;
160 160
 			}
161 161
 		}
@@ -176,10 +176,10 @@  discard block
 block discarded – undo
176 176
 			->execute();
177 177
 
178 178
 		$subadmins = [];
179
-		while($row = $result->fetch()) {
179
+		while ($row = $result->fetch()) {
180 180
 			$user = $this->userManager->get($row['uid']);
181 181
 			$group = $this->groupManager->get($row['gid']);
182
-			if(!is_null($user) && !is_null($group)) {
182
+			if (!is_null($user) && !is_null($group)) {
183 183
 				$subadmins[] = [
184 184
 					'user'  => $user,
185 185
 					'group' => $group
@@ -209,7 +209,7 @@  discard block
 block discarded – undo
209 209
 			->andWhere($qb->expr()->eq('uid', $qb->createNamedParameter($user->getUID())))
210 210
 			->execute();
211 211
 
212
-		$fetch =  $result->fetch();
212
+		$fetch = $result->fetch();
213 213
 		$result->closeCursor();
214 214
 		$result = !empty($fetch) ? true : false;
215 215
 
@@ -248,15 +248,15 @@  discard block
 block discarded – undo
248 248
 	 * @return bool
249 249
 	 */
250 250
 	public function isUserAccessible(IUser $subadmin, IUser $user): bool {
251
-		if(!$this->isSubAdmin($subadmin)) {
251
+		if (!$this->isSubAdmin($subadmin)) {
252 252
 			return false;
253 253
 		}
254
-		if($this->groupManager->isAdmin($user->getUID())) {
254
+		if ($this->groupManager->isAdmin($user->getUID())) {
255 255
 			return false;
256 256
 		}
257 257
 		$accessibleGroups = $this->getSubAdminsGroups($subadmin);
258
-		foreach($accessibleGroups as $accessibleGroup) {
259
-			if($accessibleGroup->inGroup($user)) {
258
+		foreach ($accessibleGroups as $accessibleGroup) {
259
+			if ($accessibleGroup->inGroup($user)) {
260 260
 				return true;
261 261
 			}
262 262
 		}
Please login to merge, or discard this patch.
lib/public/Group/ISubAdmin.php 1 patch
Indentation   +58 added lines, -58 removed lines patch added patch discarded remove patch
@@ -32,68 +32,68 @@
 block discarded – undo
32 32
  */
33 33
 interface ISubAdmin {
34 34
 
35
-	/**
36
-	 * add a SubAdmin
37
-	 * @param IUser $user user to be SubAdmin
38
-	 * @param IGroup $group group $user becomes subadmin of
39
-	 *
40
-	 * @since 16.0.0
41
-	 */
42
-	public function createSubAdmin(IUser $user, IGroup $group): void;
35
+    /**
36
+     * add a SubAdmin
37
+     * @param IUser $user user to be SubAdmin
38
+     * @param IGroup $group group $user becomes subadmin of
39
+     *
40
+     * @since 16.0.0
41
+     */
42
+    public function createSubAdmin(IUser $user, IGroup $group): void;
43 43
 
44
-	/**
45
-	 * delete a SubAdmin
46
-	 * @param IUser $user the user that is the SubAdmin
47
-	 * @param IGroup $group the group
48
-	 *
49
-	 * @since 16.0.0
50
-	 */
51
-	public function deleteSubAdmin(IUser $user, IGroup $group): void;
44
+    /**
45
+     * delete a SubAdmin
46
+     * @param IUser $user the user that is the SubAdmin
47
+     * @param IGroup $group the group
48
+     *
49
+     * @since 16.0.0
50
+     */
51
+    public function deleteSubAdmin(IUser $user, IGroup $group): void;
52 52
 
53
-	/**
54
-	 * get groups of a SubAdmin
55
-	 * @param IUser $user the SubAdmin
56
-	 * @return IGroup[]
57
-	 *
58
-	 * @since 16.0.0
59
-	 */
60
-	public function getSubAdminsGroups(IUser $user): array;
53
+    /**
54
+     * get groups of a SubAdmin
55
+     * @param IUser $user the SubAdmin
56
+     * @return IGroup[]
57
+     *
58
+     * @since 16.0.0
59
+     */
60
+    public function getSubAdminsGroups(IUser $user): array;
61 61
 
62
-	/**
63
-	 * get SubAdmins of a group
64
-	 * @param IGroup $group the group
65
-	 * @return IUser[]
66
-	 *
67
-	 * @since 16.0.0
68
-	 */
69
-	public function getGroupsSubAdmins(IGroup $group): array;
62
+    /**
63
+     * get SubAdmins of a group
64
+     * @param IGroup $group the group
65
+     * @return IUser[]
66
+     *
67
+     * @since 16.0.0
68
+     */
69
+    public function getGroupsSubAdmins(IGroup $group): array;
70 70
 
71
-	/**
72
-	 * checks if a user is a SubAdmin of a group
73
-	 * @param IUser $user
74
-	 * @param IGroup $group
75
-	 * @return bool
76
-	 *
77
-	 * @since 16.0.0
78
-	 */
79
-	public function isSubAdminOfGroup(IUser $user, IGroup $group): bool;
71
+    /**
72
+     * checks if a user is a SubAdmin of a group
73
+     * @param IUser $user
74
+     * @param IGroup $group
75
+     * @return bool
76
+     *
77
+     * @since 16.0.0
78
+     */
79
+    public function isSubAdminOfGroup(IUser $user, IGroup $group): bool;
80 80
 
81
-	/**
82
-	 * checks if a user is a SubAdmin
83
-	 * @param IUser $user
84
-	 * @return bool
85
-	 *
86
-	 * @since 16.0.0
87
-	 */
88
-	public function isSubAdmin(IUser $user): bool;
81
+    /**
82
+     * checks if a user is a SubAdmin
83
+     * @param IUser $user
84
+     * @return bool
85
+     *
86
+     * @since 16.0.0
87
+     */
88
+    public function isSubAdmin(IUser $user): bool;
89 89
 
90
-	/**
91
-	 * checks if a user is a accessible by a subadmin
92
-	 * @param IUser $subadmin
93
-	 * @param IUser $user
94
-	 * @return bool
95
-	 *
96
-	 * @since 16.0.0
97
-	 */
98
-	public function isUserAccessible(IUser $subadmin, IUser $user): bool;
90
+    /**
91
+     * checks if a user is a accessible by a subadmin
92
+     * @param IUser $subadmin
93
+     * @param IUser $user
94
+     * @return bool
95
+     *
96
+     * @since 16.0.0
97
+     */
98
+    public function isUserAccessible(IUser $subadmin, IUser $user): bool;
99 99
 }
Please login to merge, or discard this patch.