@@ -33,7 +33,6 @@ |
||
33 | 33 | use OC\Settings\Mailer\NewUserMailHelper; |
34 | 34 | use \OC_Helper; |
35 | 35 | use OCP\AppFramework\Http\DataResponse; |
36 | -use OCP\AppFramework\Http\TemplateResponse; |
|
37 | 36 | use OCP\AppFramework\OCS\OCSException; |
38 | 37 | use OCP\AppFramework\OCS\OCSForbiddenException; |
39 | 38 | use OCP\AppFramework\OCSController; |
@@ -51,756 +51,756 @@ |
||
51 | 51 | |
52 | 52 | class UsersController extends OCSController { |
53 | 53 | |
54 | - /** @var IUserManager */ |
|
55 | - private $userManager; |
|
56 | - /** @var IConfig */ |
|
57 | - private $config; |
|
58 | - /** @var IGroupManager|\OC\Group\Manager */ // FIXME Requires a method that is not on the interface |
|
59 | - private $groupManager; |
|
60 | - /** @var IUserSession */ |
|
61 | - private $userSession; |
|
62 | - /** @var AccountManager */ |
|
63 | - private $accountManager; |
|
64 | - /** @var ILogger */ |
|
65 | - private $logger; |
|
66 | - /** @var string */ |
|
67 | - private $fromMailAddress; |
|
68 | - /** @var IURLGenerator */ |
|
69 | - private $urlGenerator; |
|
70 | - /** @var IMailer */ |
|
71 | - private $mailer; |
|
72 | - /** @var \OC_Defaults */ |
|
73 | - private $defaults; |
|
74 | - /** @var IFactory */ |
|
75 | - private $l10nFactory; |
|
76 | - /** @var NewUserMailHelper */ |
|
77 | - private $newUserMailHelper; |
|
78 | - |
|
79 | - /** |
|
80 | - * @param string $appName |
|
81 | - * @param IRequest $request |
|
82 | - * @param IUserManager $userManager |
|
83 | - * @param IConfig $config |
|
84 | - * @param IGroupManager $groupManager |
|
85 | - * @param IUserSession $userSession |
|
86 | - * @param AccountManager $accountManager |
|
87 | - * @param ILogger $logger |
|
88 | - * @param string $fromMailAddress |
|
89 | - * @param IURLGenerator $urlGenerator |
|
90 | - * @param IMailer $mailer |
|
91 | - * @param \OC_Defaults $defaults |
|
92 | - * @param IFactory $l10nFactory |
|
93 | - * @param NewUserMailHelper $newUserMailHelper |
|
94 | - */ |
|
95 | - public function __construct($appName, |
|
96 | - IRequest $request, |
|
97 | - IUserManager $userManager, |
|
98 | - IConfig $config, |
|
99 | - IGroupManager $groupManager, |
|
100 | - IUserSession $userSession, |
|
101 | - AccountManager $accountManager, |
|
102 | - ILogger $logger, |
|
103 | - $fromMailAddress, |
|
104 | - IURLGenerator $urlGenerator, |
|
105 | - IMailer $mailer, |
|
106 | - \OC_Defaults $defaults, |
|
107 | - IFactory $l10nFactory, |
|
108 | - NewUserMailHelper $newUserMailHelper) { |
|
109 | - parent::__construct($appName, $request); |
|
110 | - |
|
111 | - $this->userManager = $userManager; |
|
112 | - $this->config = $config; |
|
113 | - $this->groupManager = $groupManager; |
|
114 | - $this->userSession = $userSession; |
|
115 | - $this->accountManager = $accountManager; |
|
116 | - $this->logger = $logger; |
|
117 | - $this->fromMailAddress = $fromMailAddress; |
|
118 | - $this->urlGenerator = $urlGenerator; |
|
119 | - $this->mailer = $mailer; |
|
120 | - $this->defaults = $defaults; |
|
121 | - $this->l10nFactory = $l10nFactory; |
|
122 | - $this->newUserMailHelper = $newUserMailHelper; |
|
123 | - } |
|
124 | - |
|
125 | - /** |
|
126 | - * @NoAdminRequired |
|
127 | - * |
|
128 | - * returns a list of users |
|
129 | - * |
|
130 | - * @param string $search |
|
131 | - * @param int $limit |
|
132 | - * @param int $offset |
|
133 | - * @return DataResponse |
|
134 | - */ |
|
135 | - public function getUsers($search = '', $limit = null, $offset = null) { |
|
136 | - $user = $this->userSession->getUser(); |
|
137 | - $users = []; |
|
138 | - |
|
139 | - // Admin? Or SubAdmin? |
|
140 | - $uid = $user->getUID(); |
|
141 | - $subAdminManager = $this->groupManager->getSubAdmin(); |
|
142 | - if($this->groupManager->isAdmin($uid)){ |
|
143 | - $users = $this->userManager->search($search, $limit, $offset); |
|
144 | - } else if ($subAdminManager->isSubAdmin($user)) { |
|
145 | - $subAdminOfGroups = $subAdminManager->getSubAdminsGroups($user); |
|
146 | - foreach ($subAdminOfGroups as $key => $group) { |
|
147 | - $subAdminOfGroups[$key] = $group->getGID(); |
|
148 | - } |
|
149 | - |
|
150 | - if($offset === null) { |
|
151 | - $offset = 0; |
|
152 | - } |
|
153 | - |
|
154 | - $users = []; |
|
155 | - foreach ($subAdminOfGroups as $group) { |
|
156 | - $users = array_merge($users, $this->groupManager->displayNamesInGroup($group, $search)); |
|
157 | - } |
|
158 | - |
|
159 | - $users = array_slice($users, $offset, $limit); |
|
160 | - } |
|
161 | - |
|
162 | - $users = array_keys($users); |
|
163 | - |
|
164 | - return new DataResponse([ |
|
165 | - 'users' => $users |
|
166 | - ]); |
|
167 | - } |
|
168 | - |
|
169 | - /** |
|
170 | - * @PasswordConfirmationRequired |
|
171 | - * @NoAdminRequired |
|
172 | - * |
|
173 | - * @param string $userid |
|
174 | - * @param string $password |
|
175 | - * @param array $groups |
|
176 | - * @return DataResponse |
|
177 | - * @throws OCSException |
|
178 | - */ |
|
179 | - public function addUser($userid, $password, $groups = null) { |
|
180 | - $user = $this->userSession->getUser(); |
|
181 | - $isAdmin = $this->groupManager->isAdmin($user->getUID()); |
|
182 | - $subAdminManager = $this->groupManager->getSubAdmin(); |
|
183 | - |
|
184 | - if($this->userManager->userExists($userid)) { |
|
185 | - $this->logger->error('Failed addUser attempt: User already exists.', ['app' => 'ocs_api']); |
|
186 | - throw new OCSException('User already exists', 102); |
|
187 | - } |
|
188 | - |
|
189 | - if(is_array($groups)) { |
|
190 | - foreach ($groups as $group) { |
|
191 | - if(!$this->groupManager->groupExists($group)) { |
|
192 | - throw new OCSException('group '.$group.' does not exist', 104); |
|
193 | - } |
|
194 | - if(!$isAdmin && !$subAdminManager->isSubAdminofGroup($user, $this->groupManager->get($group))) { |
|
195 | - throw new OCSException('insufficient privileges for group '. $group, 105); |
|
196 | - } |
|
197 | - } |
|
198 | - } else { |
|
199 | - if(!$isAdmin) { |
|
200 | - throw new OCSException('no group specified (required for subadmins)', 106); |
|
201 | - } |
|
202 | - } |
|
203 | - |
|
204 | - try { |
|
205 | - $newUser = $this->userManager->createUser($userid, $password); |
|
206 | - $this->logger->info('Successful addUser call with userid: '.$userid, ['app' => 'ocs_api']); |
|
207 | - |
|
208 | - if (is_array($groups)) { |
|
209 | - foreach ($groups as $group) { |
|
210 | - $this->groupManager->get($group)->addUser($newUser); |
|
211 | - $this->logger->info('Added userid '.$userid.' to group '.$group, ['app' => 'ocs_api']); |
|
212 | - } |
|
213 | - } |
|
214 | - return new DataResponse(); |
|
215 | - } catch (\Exception $e) { |
|
216 | - $this->logger->error('Failed addUser attempt with exception: '.$e->getMessage(), ['app' => 'ocs_api']); |
|
217 | - throw new OCSException('Bad request', 101); |
|
218 | - } |
|
219 | - } |
|
220 | - |
|
221 | - /** |
|
222 | - * @NoAdminRequired |
|
223 | - * @NoSubAdminRequired |
|
224 | - * |
|
225 | - * gets user info |
|
226 | - * |
|
227 | - * @param string $userId |
|
228 | - * @return DataResponse |
|
229 | - * @throws OCSException |
|
230 | - */ |
|
231 | - public function getUser($userId) { |
|
232 | - $data = $this->getUserData($userId); |
|
233 | - return new DataResponse($data); |
|
234 | - } |
|
235 | - |
|
236 | - /** |
|
237 | - * @NoAdminRequired |
|
238 | - * @NoSubAdminRequired |
|
239 | - * |
|
240 | - * gets user info from the currently logged in user |
|
241 | - * |
|
242 | - * @return DataResponse |
|
243 | - * @throws OCSException |
|
244 | - */ |
|
245 | - public function getCurrentUser() { |
|
246 | - $user = $this->userSession->getUser(); |
|
247 | - if ($user) { |
|
248 | - $data = $this->getUserData($user->getUID()); |
|
249 | - // rename "displayname" to "display-name" only for this call to keep |
|
250 | - // the API stable. |
|
251 | - $data['display-name'] = $data['displayname']; |
|
252 | - unset($data['displayname']); |
|
253 | - return new DataResponse($data); |
|
254 | - |
|
255 | - } |
|
256 | - |
|
257 | - throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
258 | - } |
|
259 | - |
|
260 | - /** |
|
261 | - * creates a array with all user data |
|
262 | - * |
|
263 | - * @param $userId |
|
264 | - * @return array |
|
265 | - * @throws OCSException |
|
266 | - */ |
|
267 | - protected function getUserData($userId) { |
|
268 | - $currentLoggedInUser = $this->userSession->getUser(); |
|
269 | - |
|
270 | - $data = []; |
|
271 | - |
|
272 | - // Check if the target user exists |
|
273 | - $targetUserObject = $this->userManager->get($userId); |
|
274 | - if($targetUserObject === null) { |
|
275 | - throw new OCSException('The requested user could not be found', \OCP\API::RESPOND_NOT_FOUND); |
|
276 | - } |
|
277 | - |
|
278 | - // Admin? Or SubAdmin? |
|
279 | - if($this->groupManager->isAdmin($currentLoggedInUser->getUID()) |
|
280 | - || $this->groupManager->getSubAdmin()->isUserAccessible($currentLoggedInUser, $targetUserObject)) { |
|
281 | - $data['enabled'] = $this->config->getUserValue($userId, 'core', 'enabled', 'true'); |
|
282 | - } else { |
|
283 | - // Check they are looking up themselves |
|
284 | - if($currentLoggedInUser->getUID() !== $userId) { |
|
285 | - throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
286 | - } |
|
287 | - } |
|
288 | - |
|
289 | - $userAccount = $this->accountManager->getUser($targetUserObject); |
|
290 | - $groups = $this->groupManager->getUserGroups($targetUserObject); |
|
291 | - $gids = []; |
|
292 | - foreach ($groups as $group) { |
|
293 | - $gids[] = $group->getDisplayName(); |
|
294 | - } |
|
295 | - |
|
296 | - // Find the data |
|
297 | - $data['id'] = $targetUserObject->getUID(); |
|
298 | - $data['quota'] = $this->fillStorageInfo($userId); |
|
299 | - $data['email'] = $targetUserObject->getEMailAddress(); |
|
300 | - $data['displayname'] = $targetUserObject->getDisplayName(); |
|
301 | - $data['phone'] = $userAccount[\OC\Accounts\AccountManager::PROPERTY_PHONE]['value']; |
|
302 | - $data['address'] = $userAccount[\OC\Accounts\AccountManager::PROPERTY_ADDRESS]['value']; |
|
303 | - $data['webpage'] = $userAccount[\OC\Accounts\AccountManager::PROPERTY_WEBSITE]['value']; |
|
304 | - $data['twitter'] = $userAccount[\OC\Accounts\AccountManager::PROPERTY_TWITTER]['value']; |
|
305 | - $data['groups'] = $gids; |
|
306 | - |
|
307 | - return $data; |
|
308 | - } |
|
309 | - |
|
310 | - /** |
|
311 | - * @NoAdminRequired |
|
312 | - * @NoSubAdminRequired |
|
313 | - * @PasswordConfirmationRequired |
|
314 | - * |
|
315 | - * edit users |
|
316 | - * |
|
317 | - * @param string $userId |
|
318 | - * @param string $key |
|
319 | - * @param string $value |
|
320 | - * @return DataResponse |
|
321 | - * @throws OCSException |
|
322 | - * @throws OCSForbiddenException |
|
323 | - */ |
|
324 | - public function editUser($userId, $key, $value) { |
|
325 | - $currentLoggedInUser = $this->userSession->getUser(); |
|
326 | - |
|
327 | - $targetUser = $this->userManager->get($userId); |
|
328 | - if($targetUser === null) { |
|
329 | - throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
330 | - } |
|
331 | - |
|
332 | - $permittedFields = []; |
|
333 | - if($userId === $currentLoggedInUser->getUID()) { |
|
334 | - // Editing self (display, email) |
|
335 | - $permittedFields[] = 'display'; |
|
336 | - $permittedFields[] = 'email'; |
|
337 | - $permittedFields[] = 'password'; |
|
338 | - // If admin they can edit their own quota |
|
339 | - if($this->groupManager->isAdmin($currentLoggedInUser->getUID())) { |
|
340 | - $permittedFields[] = 'quota'; |
|
341 | - } |
|
342 | - } else { |
|
343 | - // Check if admin / subadmin |
|
344 | - $subAdminManager = $this->groupManager->getSubAdmin(); |
|
345 | - if($subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser) |
|
346 | - || $this->groupManager->isAdmin($currentLoggedInUser->getUID())) { |
|
347 | - // They have permissions over the user |
|
348 | - $permittedFields[] = 'display'; |
|
349 | - $permittedFields[] = 'quota'; |
|
350 | - $permittedFields[] = 'password'; |
|
351 | - $permittedFields[] = 'email'; |
|
352 | - } else { |
|
353 | - // No rights |
|
354 | - throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
355 | - } |
|
356 | - } |
|
357 | - // Check if permitted to edit this field |
|
358 | - if(!in_array($key, $permittedFields)) { |
|
359 | - throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
360 | - } |
|
361 | - // Process the edit |
|
362 | - switch($key) { |
|
363 | - case 'display': |
|
364 | - $targetUser->setDisplayName($value); |
|
365 | - break; |
|
366 | - case 'quota': |
|
367 | - $quota = $value; |
|
368 | - if($quota !== 'none' && $quota !== 'default') { |
|
369 | - if (is_numeric($quota)) { |
|
370 | - $quota = (float) $quota; |
|
371 | - } else { |
|
372 | - $quota = \OCP\Util::computerFileSize($quota); |
|
373 | - } |
|
374 | - if ($quota === false) { |
|
375 | - throw new OCSException('Invalid quota value '.$value, 103); |
|
376 | - } |
|
377 | - if($quota === 0) { |
|
378 | - $quota = 'default'; |
|
379 | - }else if($quota === -1) { |
|
380 | - $quota = 'none'; |
|
381 | - } else { |
|
382 | - $quota = \OCP\Util::humanFileSize($quota); |
|
383 | - } |
|
384 | - } |
|
385 | - $targetUser->setQuota($quota); |
|
386 | - break; |
|
387 | - case 'password': |
|
388 | - $targetUser->setPassword($value); |
|
389 | - break; |
|
390 | - case 'email': |
|
391 | - if(filter_var($value, FILTER_VALIDATE_EMAIL)) { |
|
392 | - $targetUser->setEMailAddress($value); |
|
393 | - } else { |
|
394 | - throw new OCSException('', 102); |
|
395 | - } |
|
396 | - break; |
|
397 | - default: |
|
398 | - throw new OCSException('', 103); |
|
399 | - } |
|
400 | - return new DataResponse(); |
|
401 | - } |
|
402 | - |
|
403 | - /** |
|
404 | - * @PasswordConfirmationRequired |
|
405 | - * @NoAdminRequired |
|
406 | - * |
|
407 | - * @param string $userId |
|
408 | - * @return DataResponse |
|
409 | - * @throws OCSException |
|
410 | - * @throws OCSForbiddenException |
|
411 | - */ |
|
412 | - public function deleteUser($userId) { |
|
413 | - $currentLoggedInUser = $this->userSession->getUser(); |
|
414 | - |
|
415 | - $targetUser = $this->userManager->get($userId); |
|
416 | - |
|
417 | - if($targetUser === null || $targetUser->getUID() === $currentLoggedInUser->getUID()) { |
|
418 | - throw new OCSException('', 101); |
|
419 | - } |
|
420 | - |
|
421 | - // If not permitted |
|
422 | - $subAdminManager = $this->groupManager->getSubAdmin(); |
|
423 | - if(!$this->groupManager->isAdmin($currentLoggedInUser->getUID()) && !$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)) { |
|
424 | - throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
425 | - } |
|
426 | - |
|
427 | - // Go ahead with the delete |
|
428 | - if($targetUser->delete()) { |
|
429 | - return new DataResponse(); |
|
430 | - } else { |
|
431 | - throw new OCSException('', 101); |
|
432 | - } |
|
433 | - } |
|
434 | - |
|
435 | - /** |
|
436 | - * @PasswordConfirmationRequired |
|
437 | - * @NoAdminRequired |
|
438 | - * |
|
439 | - * @param string $userId |
|
440 | - * @return DataResponse |
|
441 | - * @throws OCSException |
|
442 | - * @throws OCSForbiddenException |
|
443 | - */ |
|
444 | - public function disableUser($userId) { |
|
445 | - return $this->setEnabled($userId, false); |
|
446 | - } |
|
447 | - |
|
448 | - /** |
|
449 | - * @PasswordConfirmationRequired |
|
450 | - * @NoAdminRequired |
|
451 | - * |
|
452 | - * @param string $userId |
|
453 | - * @return DataResponse |
|
454 | - * @throws OCSException |
|
455 | - * @throws OCSForbiddenException |
|
456 | - */ |
|
457 | - public function enableUser($userId) { |
|
458 | - return $this->setEnabled($userId, true); |
|
459 | - } |
|
460 | - |
|
461 | - /** |
|
462 | - * @param string $userId |
|
463 | - * @param bool $value |
|
464 | - * @return DataResponse |
|
465 | - * @throws OCSException |
|
466 | - * @throws OCSForbiddenException |
|
467 | - */ |
|
468 | - private function setEnabled($userId, $value) { |
|
469 | - $currentLoggedInUser = $this->userSession->getUser(); |
|
470 | - |
|
471 | - $targetUser = $this->userManager->get($userId); |
|
472 | - if($targetUser === null || $targetUser->getUID() === $currentLoggedInUser->getUID()) { |
|
473 | - throw new OCSException('', 101); |
|
474 | - } |
|
475 | - |
|
476 | - // If not permitted |
|
477 | - $subAdminManager = $this->groupManager->getSubAdmin(); |
|
478 | - if(!$this->groupManager->isAdmin($currentLoggedInUser->getUID()) && !$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)) { |
|
479 | - throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
480 | - } |
|
481 | - |
|
482 | - // enable/disable the user now |
|
483 | - $targetUser->setEnabled($value); |
|
484 | - return new DataResponse(); |
|
485 | - } |
|
486 | - |
|
487 | - /** |
|
488 | - * @NoAdminRequired |
|
489 | - * @NoSubAdminRequired |
|
490 | - * |
|
491 | - * @param string $userId |
|
492 | - * @return DataResponse |
|
493 | - * @throws OCSException |
|
494 | - */ |
|
495 | - public function getUsersGroups($userId) { |
|
496 | - $loggedInUser = $this->userSession->getUser(); |
|
497 | - |
|
498 | - $targetUser = $this->userManager->get($userId); |
|
499 | - if($targetUser === null) { |
|
500 | - throw new OCSException('', \OCP\API::RESPOND_NOT_FOUND); |
|
501 | - } |
|
502 | - |
|
503 | - if($targetUser->getUID() === $loggedInUser->getUID() || $this->groupManager->isAdmin($loggedInUser->getUID())) { |
|
504 | - // Self lookup or admin lookup |
|
505 | - return new DataResponse([ |
|
506 | - 'groups' => $this->groupManager->getUserGroupIds($targetUser) |
|
507 | - ]); |
|
508 | - } else { |
|
509 | - $subAdminManager = $this->groupManager->getSubAdmin(); |
|
510 | - |
|
511 | - // Looking up someone else |
|
512 | - if($subAdminManager->isUserAccessible($loggedInUser, $targetUser)) { |
|
513 | - // Return the group that the method caller is subadmin of for the user in question |
|
514 | - /** @var IGroup[] $getSubAdminsGroups */ |
|
515 | - $getSubAdminsGroups = $subAdminManager->getSubAdminsGroups($loggedInUser); |
|
516 | - foreach ($getSubAdminsGroups as $key => $group) { |
|
517 | - $getSubAdminsGroups[$key] = $group->getGID(); |
|
518 | - } |
|
519 | - $groups = array_intersect( |
|
520 | - $getSubAdminsGroups, |
|
521 | - $this->groupManager->getUserGroupIds($targetUser) |
|
522 | - ); |
|
523 | - return new DataResponse(['groups' => $groups]); |
|
524 | - } else { |
|
525 | - // Not permitted |
|
526 | - throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
527 | - } |
|
528 | - } |
|
529 | - |
|
530 | - } |
|
531 | - |
|
532 | - /** |
|
533 | - * @PasswordConfirmationRequired |
|
534 | - * @NoAdminRequired |
|
535 | - * |
|
536 | - * @param string $userId |
|
537 | - * @param string $groupid |
|
538 | - * @return DataResponse |
|
539 | - * @throws OCSException |
|
540 | - */ |
|
541 | - public function addToGroup($userId, $groupid = '') { |
|
542 | - if($groupid === '') { |
|
543 | - throw new OCSException('', 101); |
|
544 | - } |
|
545 | - |
|
546 | - $group = $this->groupManager->get($groupid); |
|
547 | - $targetUser = $this->userManager->get($userId); |
|
548 | - if($group === null) { |
|
549 | - throw new OCSException('', 102); |
|
550 | - } |
|
551 | - if($targetUser === null) { |
|
552 | - throw new OCSException('', 103); |
|
553 | - } |
|
554 | - |
|
555 | - // If they're not an admin, check they are a subadmin of the group in question |
|
556 | - $loggedInUser = $this->userSession->getUser(); |
|
557 | - $subAdminManager = $this->groupManager->getSubAdmin(); |
|
558 | - if (!$this->groupManager->isAdmin($loggedInUser->getUID()) && !$subAdminManager->isSubAdminOfGroup($loggedInUser, $group)) { |
|
559 | - throw new OCSException('', 104); |
|
560 | - } |
|
561 | - |
|
562 | - // Add user to group |
|
563 | - $group->addUser($targetUser); |
|
564 | - return new DataResponse(); |
|
565 | - } |
|
566 | - |
|
567 | - /** |
|
568 | - * @PasswordConfirmationRequired |
|
569 | - * @NoAdminRequired |
|
570 | - * |
|
571 | - * @param string $userId |
|
572 | - * @param string $groupid |
|
573 | - * @return DataResponse |
|
574 | - * @throws OCSException |
|
575 | - */ |
|
576 | - public function removeFromGroup($userId, $groupid) { |
|
577 | - $loggedInUser = $this->userSession->getUser(); |
|
578 | - |
|
579 | - if($groupid === null) { |
|
580 | - throw new OCSException('', 101); |
|
581 | - } |
|
582 | - |
|
583 | - $group = $this->groupManager->get($groupid); |
|
584 | - if($group === null) { |
|
585 | - throw new OCSException('', 102); |
|
586 | - } |
|
587 | - |
|
588 | - $targetUser = $this->userManager->get($userId); |
|
589 | - if($targetUser === null) { |
|
590 | - throw new OCSException('', 103); |
|
591 | - } |
|
592 | - |
|
593 | - // If they're not an admin, check they are a subadmin of the group in question |
|
594 | - $subAdminManager = $this->groupManager->getSubAdmin(); |
|
595 | - if (!$this->groupManager->isAdmin($loggedInUser->getUID()) && !$subAdminManager->isSubAdminOfGroup($loggedInUser, $group)) { |
|
596 | - throw new OCSException('', 104); |
|
597 | - } |
|
598 | - |
|
599 | - // Check they aren't removing themselves from 'admin' or their 'subadmin; group |
|
600 | - if ($userId === $loggedInUser->getUID()) { |
|
601 | - if ($this->groupManager->isAdmin($loggedInUser->getUID())) { |
|
602 | - if ($group->getGID() === 'admin') { |
|
603 | - throw new OCSException('Cannot remove yourself from the admin group', 105); |
|
604 | - } |
|
605 | - } else { |
|
606 | - // Not an admin, so the user must be a subadmin of this group, but that is not allowed. |
|
607 | - throw new OCSException('Cannot remove yourself from this group as you are a SubAdmin', 105); |
|
608 | - } |
|
609 | - |
|
610 | - } else if (!$this->groupManager->isAdmin($loggedInUser->getUID())) { |
|
611 | - /** @var IGroup[] $subAdminGroups */ |
|
612 | - $subAdminGroups = $subAdminManager->getSubAdminsGroups($loggedInUser); |
|
613 | - $subAdminGroups = array_map(function (IGroup $subAdminGroup) { |
|
614 | - return $subAdminGroup->getGID(); |
|
615 | - }, $subAdminGroups); |
|
616 | - $userGroups = $this->groupManager->getUserGroupIds($targetUser); |
|
617 | - $userSubAdminGroups = array_intersect($subAdminGroups, $userGroups); |
|
618 | - |
|
619 | - if (count($userSubAdminGroups) <= 1) { |
|
620 | - // Subadmin must not be able to remove a user from all their subadmin groups. |
|
621 | - throw new OCSException('Cannot remove user from this group as this is the only remaining group you are a SubAdmin of', 105); |
|
622 | - } |
|
623 | - } |
|
624 | - |
|
625 | - // Remove user from group |
|
626 | - $group->removeUser($targetUser); |
|
627 | - return new DataResponse(); |
|
628 | - } |
|
629 | - |
|
630 | - /** |
|
631 | - * Creates a subadmin |
|
632 | - * |
|
633 | - * @PasswordConfirmationRequired |
|
634 | - * |
|
635 | - * @param string $userId |
|
636 | - * @param string $groupid |
|
637 | - * @return DataResponse |
|
638 | - * @throws OCSException |
|
639 | - */ |
|
640 | - public function addSubAdmin($userId, $groupid) { |
|
641 | - $group = $this->groupManager->get($groupid); |
|
642 | - $user = $this->userManager->get($userId); |
|
643 | - |
|
644 | - // Check if the user exists |
|
645 | - if($user === null) { |
|
646 | - throw new OCSException('User does not exist', 101); |
|
647 | - } |
|
648 | - // Check if group exists |
|
649 | - if($group === null) { |
|
650 | - throw new OCSException('Group:'.$groupid.' does not exist', 102); |
|
651 | - } |
|
652 | - // Check if trying to make subadmin of admin group |
|
653 | - if(strtolower($groupid) === 'admin') { |
|
654 | - throw new OCSException('Cannot create subadmins for admin group', 103); |
|
655 | - } |
|
656 | - |
|
657 | - $subAdminManager = $this->groupManager->getSubAdmin(); |
|
658 | - |
|
659 | - // We cannot be subadmin twice |
|
660 | - if ($subAdminManager->isSubAdminofGroup($user, $group)) { |
|
661 | - return new DataResponse(); |
|
662 | - } |
|
663 | - // Go |
|
664 | - if($subAdminManager->createSubAdmin($user, $group)) { |
|
665 | - return new DataResponse(); |
|
666 | - } else { |
|
667 | - throw new OCSException('Unknown error occurred', 103); |
|
668 | - } |
|
669 | - } |
|
670 | - |
|
671 | - /** |
|
672 | - * Removes a subadmin from a group |
|
673 | - * |
|
674 | - * @PasswordConfirmationRequired |
|
675 | - * |
|
676 | - * @param string $userId |
|
677 | - * @param string $groupid |
|
678 | - * @return DataResponse |
|
679 | - * @throws OCSException |
|
680 | - */ |
|
681 | - public function removeSubAdmin($userId, $groupid) { |
|
682 | - $group = $this->groupManager->get($groupid); |
|
683 | - $user = $this->userManager->get($userId); |
|
684 | - $subAdminManager = $this->groupManager->getSubAdmin(); |
|
685 | - |
|
686 | - // Check if the user exists |
|
687 | - if($user === null) { |
|
688 | - throw new OCSException('User does not exist', 101); |
|
689 | - } |
|
690 | - // Check if the group exists |
|
691 | - if($group === null) { |
|
692 | - throw new OCSException('Group does not exist', 101); |
|
693 | - } |
|
694 | - // Check if they are a subadmin of this said group |
|
695 | - if(!$subAdminManager->isSubAdminofGroup($user, $group)) { |
|
696 | - throw new OCSException('User is not a subadmin of this group', 102); |
|
697 | - } |
|
698 | - |
|
699 | - // Go |
|
700 | - if($subAdminManager->deleteSubAdmin($user, $group)) { |
|
701 | - return new DataResponse(); |
|
702 | - } else { |
|
703 | - throw new OCSException('Unknown error occurred', 103); |
|
704 | - } |
|
705 | - } |
|
706 | - |
|
707 | - /** |
|
708 | - * Get the groups a user is a subadmin of |
|
709 | - * |
|
710 | - * @param string $userId |
|
711 | - * @return DataResponse |
|
712 | - * @throws OCSException |
|
713 | - */ |
|
714 | - public function getUserSubAdminGroups($userId) { |
|
715 | - $user = $this->userManager->get($userId); |
|
716 | - // Check if the user exists |
|
717 | - if($user === null) { |
|
718 | - throw new OCSException('User does not exist', 101); |
|
719 | - } |
|
720 | - |
|
721 | - // Get the subadmin groups |
|
722 | - $groups = $this->groupManager->getSubAdmin()->getSubAdminsGroups($user); |
|
723 | - foreach ($groups as $key => $group) { |
|
724 | - $groups[$key] = $group->getGID(); |
|
725 | - } |
|
726 | - |
|
727 | - if(!$groups) { |
|
728 | - throw new OCSException('Unknown error occurred', 102); |
|
729 | - } else { |
|
730 | - return new DataResponse($groups); |
|
731 | - } |
|
732 | - } |
|
733 | - |
|
734 | - /** |
|
735 | - * @param string $userId |
|
736 | - * @return array |
|
737 | - * @throws \OCP\Files\NotFoundException |
|
738 | - */ |
|
739 | - protected function fillStorageInfo($userId) { |
|
740 | - try { |
|
741 | - \OC_Util::tearDownFS(); |
|
742 | - \OC_Util::setupFS($userId); |
|
743 | - $storage = OC_Helper::getStorageInfo('/'); |
|
744 | - $data = [ |
|
745 | - 'free' => $storage['free'], |
|
746 | - 'used' => $storage['used'], |
|
747 | - 'total' => $storage['total'], |
|
748 | - 'relative' => $storage['relative'], |
|
749 | - 'quota' => $storage['quota'], |
|
750 | - ]; |
|
751 | - } catch (NotFoundException $ex) { |
|
752 | - $data = []; |
|
753 | - } |
|
754 | - return $data; |
|
755 | - } |
|
756 | - |
|
757 | - /** |
|
758 | - * @NoAdminRequired |
|
759 | - * @PasswordConfirmationRequired |
|
760 | - * |
|
761 | - * resend welcome message |
|
762 | - * |
|
763 | - * @param string $userId |
|
764 | - * @return DataResponse |
|
765 | - * @throws OCSException |
|
766 | - */ |
|
767 | - public function resendWelcomeMessage($userId) { |
|
768 | - $currentLoggedInUser = $this->userSession->getUser(); |
|
769 | - |
|
770 | - $targetUser = $this->userManager->get($userId); |
|
771 | - if($targetUser === null) { |
|
772 | - throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
773 | - } |
|
774 | - |
|
775 | - // Check if admin / subadmin |
|
776 | - $subAdminManager = $this->groupManager->getSubAdmin(); |
|
777 | - if(!$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser) |
|
778 | - && !$this->groupManager->isAdmin($currentLoggedInUser->getUID())) { |
|
779 | - // No rights |
|
780 | - throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
781 | - } |
|
782 | - |
|
783 | - $email = $targetUser->getEMailAddress(); |
|
784 | - if ($email === '' || $email === null) { |
|
785 | - throw new OCSException('Email address not available', 101); |
|
786 | - } |
|
787 | - $username = $targetUser->getUID(); |
|
788 | - $lang = $this->config->getUserValue($username, 'core', 'lang', 'en'); |
|
789 | - if (!$this->l10nFactory->languageExists('settings', $lang)) { |
|
790 | - $lang = 'en'; |
|
791 | - } |
|
792 | - |
|
793 | - $l10n = $this->l10nFactory->get('settings', $lang); |
|
794 | - |
|
795 | - try { |
|
796 | - $this->newUserMailHelper->setL10N($l10n); |
|
797 | - $emailTemplate = $this->newUserMailHelper->generateTemplate($targetUser, false); |
|
798 | - $this->newUserMailHelper->sendMail($targetUser, $emailTemplate); |
|
799 | - } catch(\Exception $e) { |
|
800 | - $this->logger->error("Can't send new user mail to $email: " . $e->getMessage(), array('app' => 'settings')); |
|
801 | - throw new OCSException('Sending email failed', 102); |
|
802 | - } |
|
803 | - |
|
804 | - return new DataResponse(); |
|
805 | - } |
|
54 | + /** @var IUserManager */ |
|
55 | + private $userManager; |
|
56 | + /** @var IConfig */ |
|
57 | + private $config; |
|
58 | + /** @var IGroupManager|\OC\Group\Manager */ // FIXME Requires a method that is not on the interface |
|
59 | + private $groupManager; |
|
60 | + /** @var IUserSession */ |
|
61 | + private $userSession; |
|
62 | + /** @var AccountManager */ |
|
63 | + private $accountManager; |
|
64 | + /** @var ILogger */ |
|
65 | + private $logger; |
|
66 | + /** @var string */ |
|
67 | + private $fromMailAddress; |
|
68 | + /** @var IURLGenerator */ |
|
69 | + private $urlGenerator; |
|
70 | + /** @var IMailer */ |
|
71 | + private $mailer; |
|
72 | + /** @var \OC_Defaults */ |
|
73 | + private $defaults; |
|
74 | + /** @var IFactory */ |
|
75 | + private $l10nFactory; |
|
76 | + /** @var NewUserMailHelper */ |
|
77 | + private $newUserMailHelper; |
|
78 | + |
|
79 | + /** |
|
80 | + * @param string $appName |
|
81 | + * @param IRequest $request |
|
82 | + * @param IUserManager $userManager |
|
83 | + * @param IConfig $config |
|
84 | + * @param IGroupManager $groupManager |
|
85 | + * @param IUserSession $userSession |
|
86 | + * @param AccountManager $accountManager |
|
87 | + * @param ILogger $logger |
|
88 | + * @param string $fromMailAddress |
|
89 | + * @param IURLGenerator $urlGenerator |
|
90 | + * @param IMailer $mailer |
|
91 | + * @param \OC_Defaults $defaults |
|
92 | + * @param IFactory $l10nFactory |
|
93 | + * @param NewUserMailHelper $newUserMailHelper |
|
94 | + */ |
|
95 | + public function __construct($appName, |
|
96 | + IRequest $request, |
|
97 | + IUserManager $userManager, |
|
98 | + IConfig $config, |
|
99 | + IGroupManager $groupManager, |
|
100 | + IUserSession $userSession, |
|
101 | + AccountManager $accountManager, |
|
102 | + ILogger $logger, |
|
103 | + $fromMailAddress, |
|
104 | + IURLGenerator $urlGenerator, |
|
105 | + IMailer $mailer, |
|
106 | + \OC_Defaults $defaults, |
|
107 | + IFactory $l10nFactory, |
|
108 | + NewUserMailHelper $newUserMailHelper) { |
|
109 | + parent::__construct($appName, $request); |
|
110 | + |
|
111 | + $this->userManager = $userManager; |
|
112 | + $this->config = $config; |
|
113 | + $this->groupManager = $groupManager; |
|
114 | + $this->userSession = $userSession; |
|
115 | + $this->accountManager = $accountManager; |
|
116 | + $this->logger = $logger; |
|
117 | + $this->fromMailAddress = $fromMailAddress; |
|
118 | + $this->urlGenerator = $urlGenerator; |
|
119 | + $this->mailer = $mailer; |
|
120 | + $this->defaults = $defaults; |
|
121 | + $this->l10nFactory = $l10nFactory; |
|
122 | + $this->newUserMailHelper = $newUserMailHelper; |
|
123 | + } |
|
124 | + |
|
125 | + /** |
|
126 | + * @NoAdminRequired |
|
127 | + * |
|
128 | + * returns a list of users |
|
129 | + * |
|
130 | + * @param string $search |
|
131 | + * @param int $limit |
|
132 | + * @param int $offset |
|
133 | + * @return DataResponse |
|
134 | + */ |
|
135 | + public function getUsers($search = '', $limit = null, $offset = null) { |
|
136 | + $user = $this->userSession->getUser(); |
|
137 | + $users = []; |
|
138 | + |
|
139 | + // Admin? Or SubAdmin? |
|
140 | + $uid = $user->getUID(); |
|
141 | + $subAdminManager = $this->groupManager->getSubAdmin(); |
|
142 | + if($this->groupManager->isAdmin($uid)){ |
|
143 | + $users = $this->userManager->search($search, $limit, $offset); |
|
144 | + } else if ($subAdminManager->isSubAdmin($user)) { |
|
145 | + $subAdminOfGroups = $subAdminManager->getSubAdminsGroups($user); |
|
146 | + foreach ($subAdminOfGroups as $key => $group) { |
|
147 | + $subAdminOfGroups[$key] = $group->getGID(); |
|
148 | + } |
|
149 | + |
|
150 | + if($offset === null) { |
|
151 | + $offset = 0; |
|
152 | + } |
|
153 | + |
|
154 | + $users = []; |
|
155 | + foreach ($subAdminOfGroups as $group) { |
|
156 | + $users = array_merge($users, $this->groupManager->displayNamesInGroup($group, $search)); |
|
157 | + } |
|
158 | + |
|
159 | + $users = array_slice($users, $offset, $limit); |
|
160 | + } |
|
161 | + |
|
162 | + $users = array_keys($users); |
|
163 | + |
|
164 | + return new DataResponse([ |
|
165 | + 'users' => $users |
|
166 | + ]); |
|
167 | + } |
|
168 | + |
|
169 | + /** |
|
170 | + * @PasswordConfirmationRequired |
|
171 | + * @NoAdminRequired |
|
172 | + * |
|
173 | + * @param string $userid |
|
174 | + * @param string $password |
|
175 | + * @param array $groups |
|
176 | + * @return DataResponse |
|
177 | + * @throws OCSException |
|
178 | + */ |
|
179 | + public function addUser($userid, $password, $groups = null) { |
|
180 | + $user = $this->userSession->getUser(); |
|
181 | + $isAdmin = $this->groupManager->isAdmin($user->getUID()); |
|
182 | + $subAdminManager = $this->groupManager->getSubAdmin(); |
|
183 | + |
|
184 | + if($this->userManager->userExists($userid)) { |
|
185 | + $this->logger->error('Failed addUser attempt: User already exists.', ['app' => 'ocs_api']); |
|
186 | + throw new OCSException('User already exists', 102); |
|
187 | + } |
|
188 | + |
|
189 | + if(is_array($groups)) { |
|
190 | + foreach ($groups as $group) { |
|
191 | + if(!$this->groupManager->groupExists($group)) { |
|
192 | + throw new OCSException('group '.$group.' does not exist', 104); |
|
193 | + } |
|
194 | + if(!$isAdmin && !$subAdminManager->isSubAdminofGroup($user, $this->groupManager->get($group))) { |
|
195 | + throw new OCSException('insufficient privileges for group '. $group, 105); |
|
196 | + } |
|
197 | + } |
|
198 | + } else { |
|
199 | + if(!$isAdmin) { |
|
200 | + throw new OCSException('no group specified (required for subadmins)', 106); |
|
201 | + } |
|
202 | + } |
|
203 | + |
|
204 | + try { |
|
205 | + $newUser = $this->userManager->createUser($userid, $password); |
|
206 | + $this->logger->info('Successful addUser call with userid: '.$userid, ['app' => 'ocs_api']); |
|
207 | + |
|
208 | + if (is_array($groups)) { |
|
209 | + foreach ($groups as $group) { |
|
210 | + $this->groupManager->get($group)->addUser($newUser); |
|
211 | + $this->logger->info('Added userid '.$userid.' to group '.$group, ['app' => 'ocs_api']); |
|
212 | + } |
|
213 | + } |
|
214 | + return new DataResponse(); |
|
215 | + } catch (\Exception $e) { |
|
216 | + $this->logger->error('Failed addUser attempt with exception: '.$e->getMessage(), ['app' => 'ocs_api']); |
|
217 | + throw new OCSException('Bad request', 101); |
|
218 | + } |
|
219 | + } |
|
220 | + |
|
221 | + /** |
|
222 | + * @NoAdminRequired |
|
223 | + * @NoSubAdminRequired |
|
224 | + * |
|
225 | + * gets user info |
|
226 | + * |
|
227 | + * @param string $userId |
|
228 | + * @return DataResponse |
|
229 | + * @throws OCSException |
|
230 | + */ |
|
231 | + public function getUser($userId) { |
|
232 | + $data = $this->getUserData($userId); |
|
233 | + return new DataResponse($data); |
|
234 | + } |
|
235 | + |
|
236 | + /** |
|
237 | + * @NoAdminRequired |
|
238 | + * @NoSubAdminRequired |
|
239 | + * |
|
240 | + * gets user info from the currently logged in user |
|
241 | + * |
|
242 | + * @return DataResponse |
|
243 | + * @throws OCSException |
|
244 | + */ |
|
245 | + public function getCurrentUser() { |
|
246 | + $user = $this->userSession->getUser(); |
|
247 | + if ($user) { |
|
248 | + $data = $this->getUserData($user->getUID()); |
|
249 | + // rename "displayname" to "display-name" only for this call to keep |
|
250 | + // the API stable. |
|
251 | + $data['display-name'] = $data['displayname']; |
|
252 | + unset($data['displayname']); |
|
253 | + return new DataResponse($data); |
|
254 | + |
|
255 | + } |
|
256 | + |
|
257 | + throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
258 | + } |
|
259 | + |
|
260 | + /** |
|
261 | + * creates a array with all user data |
|
262 | + * |
|
263 | + * @param $userId |
|
264 | + * @return array |
|
265 | + * @throws OCSException |
|
266 | + */ |
|
267 | + protected function getUserData($userId) { |
|
268 | + $currentLoggedInUser = $this->userSession->getUser(); |
|
269 | + |
|
270 | + $data = []; |
|
271 | + |
|
272 | + // Check if the target user exists |
|
273 | + $targetUserObject = $this->userManager->get($userId); |
|
274 | + if($targetUserObject === null) { |
|
275 | + throw new OCSException('The requested user could not be found', \OCP\API::RESPOND_NOT_FOUND); |
|
276 | + } |
|
277 | + |
|
278 | + // Admin? Or SubAdmin? |
|
279 | + if($this->groupManager->isAdmin($currentLoggedInUser->getUID()) |
|
280 | + || $this->groupManager->getSubAdmin()->isUserAccessible($currentLoggedInUser, $targetUserObject)) { |
|
281 | + $data['enabled'] = $this->config->getUserValue($userId, 'core', 'enabled', 'true'); |
|
282 | + } else { |
|
283 | + // Check they are looking up themselves |
|
284 | + if($currentLoggedInUser->getUID() !== $userId) { |
|
285 | + throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
286 | + } |
|
287 | + } |
|
288 | + |
|
289 | + $userAccount = $this->accountManager->getUser($targetUserObject); |
|
290 | + $groups = $this->groupManager->getUserGroups($targetUserObject); |
|
291 | + $gids = []; |
|
292 | + foreach ($groups as $group) { |
|
293 | + $gids[] = $group->getDisplayName(); |
|
294 | + } |
|
295 | + |
|
296 | + // Find the data |
|
297 | + $data['id'] = $targetUserObject->getUID(); |
|
298 | + $data['quota'] = $this->fillStorageInfo($userId); |
|
299 | + $data['email'] = $targetUserObject->getEMailAddress(); |
|
300 | + $data['displayname'] = $targetUserObject->getDisplayName(); |
|
301 | + $data['phone'] = $userAccount[\OC\Accounts\AccountManager::PROPERTY_PHONE]['value']; |
|
302 | + $data['address'] = $userAccount[\OC\Accounts\AccountManager::PROPERTY_ADDRESS]['value']; |
|
303 | + $data['webpage'] = $userAccount[\OC\Accounts\AccountManager::PROPERTY_WEBSITE]['value']; |
|
304 | + $data['twitter'] = $userAccount[\OC\Accounts\AccountManager::PROPERTY_TWITTER]['value']; |
|
305 | + $data['groups'] = $gids; |
|
306 | + |
|
307 | + return $data; |
|
308 | + } |
|
309 | + |
|
310 | + /** |
|
311 | + * @NoAdminRequired |
|
312 | + * @NoSubAdminRequired |
|
313 | + * @PasswordConfirmationRequired |
|
314 | + * |
|
315 | + * edit users |
|
316 | + * |
|
317 | + * @param string $userId |
|
318 | + * @param string $key |
|
319 | + * @param string $value |
|
320 | + * @return DataResponse |
|
321 | + * @throws OCSException |
|
322 | + * @throws OCSForbiddenException |
|
323 | + */ |
|
324 | + public function editUser($userId, $key, $value) { |
|
325 | + $currentLoggedInUser = $this->userSession->getUser(); |
|
326 | + |
|
327 | + $targetUser = $this->userManager->get($userId); |
|
328 | + if($targetUser === null) { |
|
329 | + throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
330 | + } |
|
331 | + |
|
332 | + $permittedFields = []; |
|
333 | + if($userId === $currentLoggedInUser->getUID()) { |
|
334 | + // Editing self (display, email) |
|
335 | + $permittedFields[] = 'display'; |
|
336 | + $permittedFields[] = 'email'; |
|
337 | + $permittedFields[] = 'password'; |
|
338 | + // If admin they can edit their own quota |
|
339 | + if($this->groupManager->isAdmin($currentLoggedInUser->getUID())) { |
|
340 | + $permittedFields[] = 'quota'; |
|
341 | + } |
|
342 | + } else { |
|
343 | + // Check if admin / subadmin |
|
344 | + $subAdminManager = $this->groupManager->getSubAdmin(); |
|
345 | + if($subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser) |
|
346 | + || $this->groupManager->isAdmin($currentLoggedInUser->getUID())) { |
|
347 | + // They have permissions over the user |
|
348 | + $permittedFields[] = 'display'; |
|
349 | + $permittedFields[] = 'quota'; |
|
350 | + $permittedFields[] = 'password'; |
|
351 | + $permittedFields[] = 'email'; |
|
352 | + } else { |
|
353 | + // No rights |
|
354 | + throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
355 | + } |
|
356 | + } |
|
357 | + // Check if permitted to edit this field |
|
358 | + if(!in_array($key, $permittedFields)) { |
|
359 | + throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
360 | + } |
|
361 | + // Process the edit |
|
362 | + switch($key) { |
|
363 | + case 'display': |
|
364 | + $targetUser->setDisplayName($value); |
|
365 | + break; |
|
366 | + case 'quota': |
|
367 | + $quota = $value; |
|
368 | + if($quota !== 'none' && $quota !== 'default') { |
|
369 | + if (is_numeric($quota)) { |
|
370 | + $quota = (float) $quota; |
|
371 | + } else { |
|
372 | + $quota = \OCP\Util::computerFileSize($quota); |
|
373 | + } |
|
374 | + if ($quota === false) { |
|
375 | + throw new OCSException('Invalid quota value '.$value, 103); |
|
376 | + } |
|
377 | + if($quota === 0) { |
|
378 | + $quota = 'default'; |
|
379 | + }else if($quota === -1) { |
|
380 | + $quota = 'none'; |
|
381 | + } else { |
|
382 | + $quota = \OCP\Util::humanFileSize($quota); |
|
383 | + } |
|
384 | + } |
|
385 | + $targetUser->setQuota($quota); |
|
386 | + break; |
|
387 | + case 'password': |
|
388 | + $targetUser->setPassword($value); |
|
389 | + break; |
|
390 | + case 'email': |
|
391 | + if(filter_var($value, FILTER_VALIDATE_EMAIL)) { |
|
392 | + $targetUser->setEMailAddress($value); |
|
393 | + } else { |
|
394 | + throw new OCSException('', 102); |
|
395 | + } |
|
396 | + break; |
|
397 | + default: |
|
398 | + throw new OCSException('', 103); |
|
399 | + } |
|
400 | + return new DataResponse(); |
|
401 | + } |
|
402 | + |
|
403 | + /** |
|
404 | + * @PasswordConfirmationRequired |
|
405 | + * @NoAdminRequired |
|
406 | + * |
|
407 | + * @param string $userId |
|
408 | + * @return DataResponse |
|
409 | + * @throws OCSException |
|
410 | + * @throws OCSForbiddenException |
|
411 | + */ |
|
412 | + public function deleteUser($userId) { |
|
413 | + $currentLoggedInUser = $this->userSession->getUser(); |
|
414 | + |
|
415 | + $targetUser = $this->userManager->get($userId); |
|
416 | + |
|
417 | + if($targetUser === null || $targetUser->getUID() === $currentLoggedInUser->getUID()) { |
|
418 | + throw new OCSException('', 101); |
|
419 | + } |
|
420 | + |
|
421 | + // If not permitted |
|
422 | + $subAdminManager = $this->groupManager->getSubAdmin(); |
|
423 | + if(!$this->groupManager->isAdmin($currentLoggedInUser->getUID()) && !$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)) { |
|
424 | + throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
425 | + } |
|
426 | + |
|
427 | + // Go ahead with the delete |
|
428 | + if($targetUser->delete()) { |
|
429 | + return new DataResponse(); |
|
430 | + } else { |
|
431 | + throw new OCSException('', 101); |
|
432 | + } |
|
433 | + } |
|
434 | + |
|
435 | + /** |
|
436 | + * @PasswordConfirmationRequired |
|
437 | + * @NoAdminRequired |
|
438 | + * |
|
439 | + * @param string $userId |
|
440 | + * @return DataResponse |
|
441 | + * @throws OCSException |
|
442 | + * @throws OCSForbiddenException |
|
443 | + */ |
|
444 | + public function disableUser($userId) { |
|
445 | + return $this->setEnabled($userId, false); |
|
446 | + } |
|
447 | + |
|
448 | + /** |
|
449 | + * @PasswordConfirmationRequired |
|
450 | + * @NoAdminRequired |
|
451 | + * |
|
452 | + * @param string $userId |
|
453 | + * @return DataResponse |
|
454 | + * @throws OCSException |
|
455 | + * @throws OCSForbiddenException |
|
456 | + */ |
|
457 | + public function enableUser($userId) { |
|
458 | + return $this->setEnabled($userId, true); |
|
459 | + } |
|
460 | + |
|
461 | + /** |
|
462 | + * @param string $userId |
|
463 | + * @param bool $value |
|
464 | + * @return DataResponse |
|
465 | + * @throws OCSException |
|
466 | + * @throws OCSForbiddenException |
|
467 | + */ |
|
468 | + private function setEnabled($userId, $value) { |
|
469 | + $currentLoggedInUser = $this->userSession->getUser(); |
|
470 | + |
|
471 | + $targetUser = $this->userManager->get($userId); |
|
472 | + if($targetUser === null || $targetUser->getUID() === $currentLoggedInUser->getUID()) { |
|
473 | + throw new OCSException('', 101); |
|
474 | + } |
|
475 | + |
|
476 | + // If not permitted |
|
477 | + $subAdminManager = $this->groupManager->getSubAdmin(); |
|
478 | + if(!$this->groupManager->isAdmin($currentLoggedInUser->getUID()) && !$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)) { |
|
479 | + throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
480 | + } |
|
481 | + |
|
482 | + // enable/disable the user now |
|
483 | + $targetUser->setEnabled($value); |
|
484 | + return new DataResponse(); |
|
485 | + } |
|
486 | + |
|
487 | + /** |
|
488 | + * @NoAdminRequired |
|
489 | + * @NoSubAdminRequired |
|
490 | + * |
|
491 | + * @param string $userId |
|
492 | + * @return DataResponse |
|
493 | + * @throws OCSException |
|
494 | + */ |
|
495 | + public function getUsersGroups($userId) { |
|
496 | + $loggedInUser = $this->userSession->getUser(); |
|
497 | + |
|
498 | + $targetUser = $this->userManager->get($userId); |
|
499 | + if($targetUser === null) { |
|
500 | + throw new OCSException('', \OCP\API::RESPOND_NOT_FOUND); |
|
501 | + } |
|
502 | + |
|
503 | + if($targetUser->getUID() === $loggedInUser->getUID() || $this->groupManager->isAdmin($loggedInUser->getUID())) { |
|
504 | + // Self lookup or admin lookup |
|
505 | + return new DataResponse([ |
|
506 | + 'groups' => $this->groupManager->getUserGroupIds($targetUser) |
|
507 | + ]); |
|
508 | + } else { |
|
509 | + $subAdminManager = $this->groupManager->getSubAdmin(); |
|
510 | + |
|
511 | + // Looking up someone else |
|
512 | + if($subAdminManager->isUserAccessible($loggedInUser, $targetUser)) { |
|
513 | + // Return the group that the method caller is subadmin of for the user in question |
|
514 | + /** @var IGroup[] $getSubAdminsGroups */ |
|
515 | + $getSubAdminsGroups = $subAdminManager->getSubAdminsGroups($loggedInUser); |
|
516 | + foreach ($getSubAdminsGroups as $key => $group) { |
|
517 | + $getSubAdminsGroups[$key] = $group->getGID(); |
|
518 | + } |
|
519 | + $groups = array_intersect( |
|
520 | + $getSubAdminsGroups, |
|
521 | + $this->groupManager->getUserGroupIds($targetUser) |
|
522 | + ); |
|
523 | + return new DataResponse(['groups' => $groups]); |
|
524 | + } else { |
|
525 | + // Not permitted |
|
526 | + throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
527 | + } |
|
528 | + } |
|
529 | + |
|
530 | + } |
|
531 | + |
|
532 | + /** |
|
533 | + * @PasswordConfirmationRequired |
|
534 | + * @NoAdminRequired |
|
535 | + * |
|
536 | + * @param string $userId |
|
537 | + * @param string $groupid |
|
538 | + * @return DataResponse |
|
539 | + * @throws OCSException |
|
540 | + */ |
|
541 | + public function addToGroup($userId, $groupid = '') { |
|
542 | + if($groupid === '') { |
|
543 | + throw new OCSException('', 101); |
|
544 | + } |
|
545 | + |
|
546 | + $group = $this->groupManager->get($groupid); |
|
547 | + $targetUser = $this->userManager->get($userId); |
|
548 | + if($group === null) { |
|
549 | + throw new OCSException('', 102); |
|
550 | + } |
|
551 | + if($targetUser === null) { |
|
552 | + throw new OCSException('', 103); |
|
553 | + } |
|
554 | + |
|
555 | + // If they're not an admin, check they are a subadmin of the group in question |
|
556 | + $loggedInUser = $this->userSession->getUser(); |
|
557 | + $subAdminManager = $this->groupManager->getSubAdmin(); |
|
558 | + if (!$this->groupManager->isAdmin($loggedInUser->getUID()) && !$subAdminManager->isSubAdminOfGroup($loggedInUser, $group)) { |
|
559 | + throw new OCSException('', 104); |
|
560 | + } |
|
561 | + |
|
562 | + // Add user to group |
|
563 | + $group->addUser($targetUser); |
|
564 | + return new DataResponse(); |
|
565 | + } |
|
566 | + |
|
567 | + /** |
|
568 | + * @PasswordConfirmationRequired |
|
569 | + * @NoAdminRequired |
|
570 | + * |
|
571 | + * @param string $userId |
|
572 | + * @param string $groupid |
|
573 | + * @return DataResponse |
|
574 | + * @throws OCSException |
|
575 | + */ |
|
576 | + public function removeFromGroup($userId, $groupid) { |
|
577 | + $loggedInUser = $this->userSession->getUser(); |
|
578 | + |
|
579 | + if($groupid === null) { |
|
580 | + throw new OCSException('', 101); |
|
581 | + } |
|
582 | + |
|
583 | + $group = $this->groupManager->get($groupid); |
|
584 | + if($group === null) { |
|
585 | + throw new OCSException('', 102); |
|
586 | + } |
|
587 | + |
|
588 | + $targetUser = $this->userManager->get($userId); |
|
589 | + if($targetUser === null) { |
|
590 | + throw new OCSException('', 103); |
|
591 | + } |
|
592 | + |
|
593 | + // If they're not an admin, check they are a subadmin of the group in question |
|
594 | + $subAdminManager = $this->groupManager->getSubAdmin(); |
|
595 | + if (!$this->groupManager->isAdmin($loggedInUser->getUID()) && !$subAdminManager->isSubAdminOfGroup($loggedInUser, $group)) { |
|
596 | + throw new OCSException('', 104); |
|
597 | + } |
|
598 | + |
|
599 | + // Check they aren't removing themselves from 'admin' or their 'subadmin; group |
|
600 | + if ($userId === $loggedInUser->getUID()) { |
|
601 | + if ($this->groupManager->isAdmin($loggedInUser->getUID())) { |
|
602 | + if ($group->getGID() === 'admin') { |
|
603 | + throw new OCSException('Cannot remove yourself from the admin group', 105); |
|
604 | + } |
|
605 | + } else { |
|
606 | + // Not an admin, so the user must be a subadmin of this group, but that is not allowed. |
|
607 | + throw new OCSException('Cannot remove yourself from this group as you are a SubAdmin', 105); |
|
608 | + } |
|
609 | + |
|
610 | + } else if (!$this->groupManager->isAdmin($loggedInUser->getUID())) { |
|
611 | + /** @var IGroup[] $subAdminGroups */ |
|
612 | + $subAdminGroups = $subAdminManager->getSubAdminsGroups($loggedInUser); |
|
613 | + $subAdminGroups = array_map(function (IGroup $subAdminGroup) { |
|
614 | + return $subAdminGroup->getGID(); |
|
615 | + }, $subAdminGroups); |
|
616 | + $userGroups = $this->groupManager->getUserGroupIds($targetUser); |
|
617 | + $userSubAdminGroups = array_intersect($subAdminGroups, $userGroups); |
|
618 | + |
|
619 | + if (count($userSubAdminGroups) <= 1) { |
|
620 | + // Subadmin must not be able to remove a user from all their subadmin groups. |
|
621 | + throw new OCSException('Cannot remove user from this group as this is the only remaining group you are a SubAdmin of', 105); |
|
622 | + } |
|
623 | + } |
|
624 | + |
|
625 | + // Remove user from group |
|
626 | + $group->removeUser($targetUser); |
|
627 | + return new DataResponse(); |
|
628 | + } |
|
629 | + |
|
630 | + /** |
|
631 | + * Creates a subadmin |
|
632 | + * |
|
633 | + * @PasswordConfirmationRequired |
|
634 | + * |
|
635 | + * @param string $userId |
|
636 | + * @param string $groupid |
|
637 | + * @return DataResponse |
|
638 | + * @throws OCSException |
|
639 | + */ |
|
640 | + public function addSubAdmin($userId, $groupid) { |
|
641 | + $group = $this->groupManager->get($groupid); |
|
642 | + $user = $this->userManager->get($userId); |
|
643 | + |
|
644 | + // Check if the user exists |
|
645 | + if($user === null) { |
|
646 | + throw new OCSException('User does not exist', 101); |
|
647 | + } |
|
648 | + // Check if group exists |
|
649 | + if($group === null) { |
|
650 | + throw new OCSException('Group:'.$groupid.' does not exist', 102); |
|
651 | + } |
|
652 | + // Check if trying to make subadmin of admin group |
|
653 | + if(strtolower($groupid) === 'admin') { |
|
654 | + throw new OCSException('Cannot create subadmins for admin group', 103); |
|
655 | + } |
|
656 | + |
|
657 | + $subAdminManager = $this->groupManager->getSubAdmin(); |
|
658 | + |
|
659 | + // We cannot be subadmin twice |
|
660 | + if ($subAdminManager->isSubAdminofGroup($user, $group)) { |
|
661 | + return new DataResponse(); |
|
662 | + } |
|
663 | + // Go |
|
664 | + if($subAdminManager->createSubAdmin($user, $group)) { |
|
665 | + return new DataResponse(); |
|
666 | + } else { |
|
667 | + throw new OCSException('Unknown error occurred', 103); |
|
668 | + } |
|
669 | + } |
|
670 | + |
|
671 | + /** |
|
672 | + * Removes a subadmin from a group |
|
673 | + * |
|
674 | + * @PasswordConfirmationRequired |
|
675 | + * |
|
676 | + * @param string $userId |
|
677 | + * @param string $groupid |
|
678 | + * @return DataResponse |
|
679 | + * @throws OCSException |
|
680 | + */ |
|
681 | + public function removeSubAdmin($userId, $groupid) { |
|
682 | + $group = $this->groupManager->get($groupid); |
|
683 | + $user = $this->userManager->get($userId); |
|
684 | + $subAdminManager = $this->groupManager->getSubAdmin(); |
|
685 | + |
|
686 | + // Check if the user exists |
|
687 | + if($user === null) { |
|
688 | + throw new OCSException('User does not exist', 101); |
|
689 | + } |
|
690 | + // Check if the group exists |
|
691 | + if($group === null) { |
|
692 | + throw new OCSException('Group does not exist', 101); |
|
693 | + } |
|
694 | + // Check if they are a subadmin of this said group |
|
695 | + if(!$subAdminManager->isSubAdminofGroup($user, $group)) { |
|
696 | + throw new OCSException('User is not a subadmin of this group', 102); |
|
697 | + } |
|
698 | + |
|
699 | + // Go |
|
700 | + if($subAdminManager->deleteSubAdmin($user, $group)) { |
|
701 | + return new DataResponse(); |
|
702 | + } else { |
|
703 | + throw new OCSException('Unknown error occurred', 103); |
|
704 | + } |
|
705 | + } |
|
706 | + |
|
707 | + /** |
|
708 | + * Get the groups a user is a subadmin of |
|
709 | + * |
|
710 | + * @param string $userId |
|
711 | + * @return DataResponse |
|
712 | + * @throws OCSException |
|
713 | + */ |
|
714 | + public function getUserSubAdminGroups($userId) { |
|
715 | + $user = $this->userManager->get($userId); |
|
716 | + // Check if the user exists |
|
717 | + if($user === null) { |
|
718 | + throw new OCSException('User does not exist', 101); |
|
719 | + } |
|
720 | + |
|
721 | + // Get the subadmin groups |
|
722 | + $groups = $this->groupManager->getSubAdmin()->getSubAdminsGroups($user); |
|
723 | + foreach ($groups as $key => $group) { |
|
724 | + $groups[$key] = $group->getGID(); |
|
725 | + } |
|
726 | + |
|
727 | + if(!$groups) { |
|
728 | + throw new OCSException('Unknown error occurred', 102); |
|
729 | + } else { |
|
730 | + return new DataResponse($groups); |
|
731 | + } |
|
732 | + } |
|
733 | + |
|
734 | + /** |
|
735 | + * @param string $userId |
|
736 | + * @return array |
|
737 | + * @throws \OCP\Files\NotFoundException |
|
738 | + */ |
|
739 | + protected function fillStorageInfo($userId) { |
|
740 | + try { |
|
741 | + \OC_Util::tearDownFS(); |
|
742 | + \OC_Util::setupFS($userId); |
|
743 | + $storage = OC_Helper::getStorageInfo('/'); |
|
744 | + $data = [ |
|
745 | + 'free' => $storage['free'], |
|
746 | + 'used' => $storage['used'], |
|
747 | + 'total' => $storage['total'], |
|
748 | + 'relative' => $storage['relative'], |
|
749 | + 'quota' => $storage['quota'], |
|
750 | + ]; |
|
751 | + } catch (NotFoundException $ex) { |
|
752 | + $data = []; |
|
753 | + } |
|
754 | + return $data; |
|
755 | + } |
|
756 | + |
|
757 | + /** |
|
758 | + * @NoAdminRequired |
|
759 | + * @PasswordConfirmationRequired |
|
760 | + * |
|
761 | + * resend welcome message |
|
762 | + * |
|
763 | + * @param string $userId |
|
764 | + * @return DataResponse |
|
765 | + * @throws OCSException |
|
766 | + */ |
|
767 | + public function resendWelcomeMessage($userId) { |
|
768 | + $currentLoggedInUser = $this->userSession->getUser(); |
|
769 | + |
|
770 | + $targetUser = $this->userManager->get($userId); |
|
771 | + if($targetUser === null) { |
|
772 | + throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
773 | + } |
|
774 | + |
|
775 | + // Check if admin / subadmin |
|
776 | + $subAdminManager = $this->groupManager->getSubAdmin(); |
|
777 | + if(!$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser) |
|
778 | + && !$this->groupManager->isAdmin($currentLoggedInUser->getUID())) { |
|
779 | + // No rights |
|
780 | + throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
781 | + } |
|
782 | + |
|
783 | + $email = $targetUser->getEMailAddress(); |
|
784 | + if ($email === '' || $email === null) { |
|
785 | + throw new OCSException('Email address not available', 101); |
|
786 | + } |
|
787 | + $username = $targetUser->getUID(); |
|
788 | + $lang = $this->config->getUserValue($username, 'core', 'lang', 'en'); |
|
789 | + if (!$this->l10nFactory->languageExists('settings', $lang)) { |
|
790 | + $lang = 'en'; |
|
791 | + } |
|
792 | + |
|
793 | + $l10n = $this->l10nFactory->get('settings', $lang); |
|
794 | + |
|
795 | + try { |
|
796 | + $this->newUserMailHelper->setL10N($l10n); |
|
797 | + $emailTemplate = $this->newUserMailHelper->generateTemplate($targetUser, false); |
|
798 | + $this->newUserMailHelper->sendMail($targetUser, $emailTemplate); |
|
799 | + } catch(\Exception $e) { |
|
800 | + $this->logger->error("Can't send new user mail to $email: " . $e->getMessage(), array('app' => 'settings')); |
|
801 | + throw new OCSException('Sending email failed', 102); |
|
802 | + } |
|
803 | + |
|
804 | + return new DataResponse(); |
|
805 | + } |
|
806 | 806 | } |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | // Admin? Or SubAdmin? |
140 | 140 | $uid = $user->getUID(); |
141 | 141 | $subAdminManager = $this->groupManager->getSubAdmin(); |
142 | - if($this->groupManager->isAdmin($uid)){ |
|
142 | + if ($this->groupManager->isAdmin($uid)) { |
|
143 | 143 | $users = $this->userManager->search($search, $limit, $offset); |
144 | 144 | } else if ($subAdminManager->isSubAdmin($user)) { |
145 | 145 | $subAdminOfGroups = $subAdminManager->getSubAdminsGroups($user); |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | $subAdminOfGroups[$key] = $group->getGID(); |
148 | 148 | } |
149 | 149 | |
150 | - if($offset === null) { |
|
150 | + if ($offset === null) { |
|
151 | 151 | $offset = 0; |
152 | 152 | } |
153 | 153 | |
@@ -181,22 +181,22 @@ discard block |
||
181 | 181 | $isAdmin = $this->groupManager->isAdmin($user->getUID()); |
182 | 182 | $subAdminManager = $this->groupManager->getSubAdmin(); |
183 | 183 | |
184 | - if($this->userManager->userExists($userid)) { |
|
184 | + if ($this->userManager->userExists($userid)) { |
|
185 | 185 | $this->logger->error('Failed addUser attempt: User already exists.', ['app' => 'ocs_api']); |
186 | 186 | throw new OCSException('User already exists', 102); |
187 | 187 | } |
188 | 188 | |
189 | - if(is_array($groups)) { |
|
189 | + if (is_array($groups)) { |
|
190 | 190 | foreach ($groups as $group) { |
191 | - if(!$this->groupManager->groupExists($group)) { |
|
191 | + if (!$this->groupManager->groupExists($group)) { |
|
192 | 192 | throw new OCSException('group '.$group.' does not exist', 104); |
193 | 193 | } |
194 | - if(!$isAdmin && !$subAdminManager->isSubAdminofGroup($user, $this->groupManager->get($group))) { |
|
195 | - throw new OCSException('insufficient privileges for group '. $group, 105); |
|
194 | + if (!$isAdmin && !$subAdminManager->isSubAdminofGroup($user, $this->groupManager->get($group))) { |
|
195 | + throw new OCSException('insufficient privileges for group '.$group, 105); |
|
196 | 196 | } |
197 | 197 | } |
198 | 198 | } else { |
199 | - if(!$isAdmin) { |
|
199 | + if (!$isAdmin) { |
|
200 | 200 | throw new OCSException('no group specified (required for subadmins)', 106); |
201 | 201 | } |
202 | 202 | } |
@@ -245,7 +245,7 @@ discard block |
||
245 | 245 | public function getCurrentUser() { |
246 | 246 | $user = $this->userSession->getUser(); |
247 | 247 | if ($user) { |
248 | - $data = $this->getUserData($user->getUID()); |
|
248 | + $data = $this->getUserData($user->getUID()); |
|
249 | 249 | // rename "displayname" to "display-name" only for this call to keep |
250 | 250 | // the API stable. |
251 | 251 | $data['display-name'] = $data['displayname']; |
@@ -271,17 +271,17 @@ discard block |
||
271 | 271 | |
272 | 272 | // Check if the target user exists |
273 | 273 | $targetUserObject = $this->userManager->get($userId); |
274 | - if($targetUserObject === null) { |
|
274 | + if ($targetUserObject === null) { |
|
275 | 275 | throw new OCSException('The requested user could not be found', \OCP\API::RESPOND_NOT_FOUND); |
276 | 276 | } |
277 | 277 | |
278 | 278 | // Admin? Or SubAdmin? |
279 | - if($this->groupManager->isAdmin($currentLoggedInUser->getUID()) |
|
279 | + if ($this->groupManager->isAdmin($currentLoggedInUser->getUID()) |
|
280 | 280 | || $this->groupManager->getSubAdmin()->isUserAccessible($currentLoggedInUser, $targetUserObject)) { |
281 | 281 | $data['enabled'] = $this->config->getUserValue($userId, 'core', 'enabled', 'true'); |
282 | 282 | } else { |
283 | 283 | // Check they are looking up themselves |
284 | - if($currentLoggedInUser->getUID() !== $userId) { |
|
284 | + if ($currentLoggedInUser->getUID() !== $userId) { |
|
285 | 285 | throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
286 | 286 | } |
287 | 287 | } |
@@ -325,24 +325,24 @@ discard block |
||
325 | 325 | $currentLoggedInUser = $this->userSession->getUser(); |
326 | 326 | |
327 | 327 | $targetUser = $this->userManager->get($userId); |
328 | - if($targetUser === null) { |
|
328 | + if ($targetUser === null) { |
|
329 | 329 | throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
330 | 330 | } |
331 | 331 | |
332 | 332 | $permittedFields = []; |
333 | - if($userId === $currentLoggedInUser->getUID()) { |
|
333 | + if ($userId === $currentLoggedInUser->getUID()) { |
|
334 | 334 | // Editing self (display, email) |
335 | 335 | $permittedFields[] = 'display'; |
336 | 336 | $permittedFields[] = 'email'; |
337 | 337 | $permittedFields[] = 'password'; |
338 | 338 | // If admin they can edit their own quota |
339 | - if($this->groupManager->isAdmin($currentLoggedInUser->getUID())) { |
|
339 | + if ($this->groupManager->isAdmin($currentLoggedInUser->getUID())) { |
|
340 | 340 | $permittedFields[] = 'quota'; |
341 | 341 | } |
342 | 342 | } else { |
343 | 343 | // Check if admin / subadmin |
344 | 344 | $subAdminManager = $this->groupManager->getSubAdmin(); |
345 | - if($subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser) |
|
345 | + if ($subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser) |
|
346 | 346 | || $this->groupManager->isAdmin($currentLoggedInUser->getUID())) { |
347 | 347 | // They have permissions over the user |
348 | 348 | $permittedFields[] = 'display'; |
@@ -355,17 +355,17 @@ discard block |
||
355 | 355 | } |
356 | 356 | } |
357 | 357 | // Check if permitted to edit this field |
358 | - if(!in_array($key, $permittedFields)) { |
|
358 | + if (!in_array($key, $permittedFields)) { |
|
359 | 359 | throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
360 | 360 | } |
361 | 361 | // Process the edit |
362 | - switch($key) { |
|
362 | + switch ($key) { |
|
363 | 363 | case 'display': |
364 | 364 | $targetUser->setDisplayName($value); |
365 | 365 | break; |
366 | 366 | case 'quota': |
367 | 367 | $quota = $value; |
368 | - if($quota !== 'none' && $quota !== 'default') { |
|
368 | + if ($quota !== 'none' && $quota !== 'default') { |
|
369 | 369 | if (is_numeric($quota)) { |
370 | 370 | $quota = (float) $quota; |
371 | 371 | } else { |
@@ -374,9 +374,9 @@ discard block |
||
374 | 374 | if ($quota === false) { |
375 | 375 | throw new OCSException('Invalid quota value '.$value, 103); |
376 | 376 | } |
377 | - if($quota === 0) { |
|
377 | + if ($quota === 0) { |
|
378 | 378 | $quota = 'default'; |
379 | - }else if($quota === -1) { |
|
379 | + } else if ($quota === -1) { |
|
380 | 380 | $quota = 'none'; |
381 | 381 | } else { |
382 | 382 | $quota = \OCP\Util::humanFileSize($quota); |
@@ -388,7 +388,7 @@ discard block |
||
388 | 388 | $targetUser->setPassword($value); |
389 | 389 | break; |
390 | 390 | case 'email': |
391 | - if(filter_var($value, FILTER_VALIDATE_EMAIL)) { |
|
391 | + if (filter_var($value, FILTER_VALIDATE_EMAIL)) { |
|
392 | 392 | $targetUser->setEMailAddress($value); |
393 | 393 | } else { |
394 | 394 | throw new OCSException('', 102); |
@@ -414,18 +414,18 @@ discard block |
||
414 | 414 | |
415 | 415 | $targetUser = $this->userManager->get($userId); |
416 | 416 | |
417 | - if($targetUser === null || $targetUser->getUID() === $currentLoggedInUser->getUID()) { |
|
417 | + if ($targetUser === null || $targetUser->getUID() === $currentLoggedInUser->getUID()) { |
|
418 | 418 | throw new OCSException('', 101); |
419 | 419 | } |
420 | 420 | |
421 | 421 | // If not permitted |
422 | 422 | $subAdminManager = $this->groupManager->getSubAdmin(); |
423 | - if(!$this->groupManager->isAdmin($currentLoggedInUser->getUID()) && !$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)) { |
|
423 | + if (!$this->groupManager->isAdmin($currentLoggedInUser->getUID()) && !$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)) { |
|
424 | 424 | throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
425 | 425 | } |
426 | 426 | |
427 | 427 | // Go ahead with the delete |
428 | - if($targetUser->delete()) { |
|
428 | + if ($targetUser->delete()) { |
|
429 | 429 | return new DataResponse(); |
430 | 430 | } else { |
431 | 431 | throw new OCSException('', 101); |
@@ -469,13 +469,13 @@ discard block |
||
469 | 469 | $currentLoggedInUser = $this->userSession->getUser(); |
470 | 470 | |
471 | 471 | $targetUser = $this->userManager->get($userId); |
472 | - if($targetUser === null || $targetUser->getUID() === $currentLoggedInUser->getUID()) { |
|
472 | + if ($targetUser === null || $targetUser->getUID() === $currentLoggedInUser->getUID()) { |
|
473 | 473 | throw new OCSException('', 101); |
474 | 474 | } |
475 | 475 | |
476 | 476 | // If not permitted |
477 | 477 | $subAdminManager = $this->groupManager->getSubAdmin(); |
478 | - if(!$this->groupManager->isAdmin($currentLoggedInUser->getUID()) && !$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)) { |
|
478 | + if (!$this->groupManager->isAdmin($currentLoggedInUser->getUID()) && !$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)) { |
|
479 | 479 | throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
480 | 480 | } |
481 | 481 | |
@@ -496,11 +496,11 @@ discard block |
||
496 | 496 | $loggedInUser = $this->userSession->getUser(); |
497 | 497 | |
498 | 498 | $targetUser = $this->userManager->get($userId); |
499 | - if($targetUser === null) { |
|
499 | + if ($targetUser === null) { |
|
500 | 500 | throw new OCSException('', \OCP\API::RESPOND_NOT_FOUND); |
501 | 501 | } |
502 | 502 | |
503 | - if($targetUser->getUID() === $loggedInUser->getUID() || $this->groupManager->isAdmin($loggedInUser->getUID())) { |
|
503 | + if ($targetUser->getUID() === $loggedInUser->getUID() || $this->groupManager->isAdmin($loggedInUser->getUID())) { |
|
504 | 504 | // Self lookup or admin lookup |
505 | 505 | return new DataResponse([ |
506 | 506 | 'groups' => $this->groupManager->getUserGroupIds($targetUser) |
@@ -509,7 +509,7 @@ discard block |
||
509 | 509 | $subAdminManager = $this->groupManager->getSubAdmin(); |
510 | 510 | |
511 | 511 | // Looking up someone else |
512 | - if($subAdminManager->isUserAccessible($loggedInUser, $targetUser)) { |
|
512 | + if ($subAdminManager->isUserAccessible($loggedInUser, $targetUser)) { |
|
513 | 513 | // Return the group that the method caller is subadmin of for the user in question |
514 | 514 | /** @var IGroup[] $getSubAdminsGroups */ |
515 | 515 | $getSubAdminsGroups = $subAdminManager->getSubAdminsGroups($loggedInUser); |
@@ -539,16 +539,16 @@ discard block |
||
539 | 539 | * @throws OCSException |
540 | 540 | */ |
541 | 541 | public function addToGroup($userId, $groupid = '') { |
542 | - if($groupid === '') { |
|
542 | + if ($groupid === '') { |
|
543 | 543 | throw new OCSException('', 101); |
544 | 544 | } |
545 | 545 | |
546 | 546 | $group = $this->groupManager->get($groupid); |
547 | 547 | $targetUser = $this->userManager->get($userId); |
548 | - if($group === null) { |
|
548 | + if ($group === null) { |
|
549 | 549 | throw new OCSException('', 102); |
550 | 550 | } |
551 | - if($targetUser === null) { |
|
551 | + if ($targetUser === null) { |
|
552 | 552 | throw new OCSException('', 103); |
553 | 553 | } |
554 | 554 | |
@@ -576,17 +576,17 @@ discard block |
||
576 | 576 | public function removeFromGroup($userId, $groupid) { |
577 | 577 | $loggedInUser = $this->userSession->getUser(); |
578 | 578 | |
579 | - if($groupid === null) { |
|
579 | + if ($groupid === null) { |
|
580 | 580 | throw new OCSException('', 101); |
581 | 581 | } |
582 | 582 | |
583 | 583 | $group = $this->groupManager->get($groupid); |
584 | - if($group === null) { |
|
584 | + if ($group === null) { |
|
585 | 585 | throw new OCSException('', 102); |
586 | 586 | } |
587 | 587 | |
588 | 588 | $targetUser = $this->userManager->get($userId); |
589 | - if($targetUser === null) { |
|
589 | + if ($targetUser === null) { |
|
590 | 590 | throw new OCSException('', 103); |
591 | 591 | } |
592 | 592 | |
@@ -610,7 +610,7 @@ discard block |
||
610 | 610 | } else if (!$this->groupManager->isAdmin($loggedInUser->getUID())) { |
611 | 611 | /** @var IGroup[] $subAdminGroups */ |
612 | 612 | $subAdminGroups = $subAdminManager->getSubAdminsGroups($loggedInUser); |
613 | - $subAdminGroups = array_map(function (IGroup $subAdminGroup) { |
|
613 | + $subAdminGroups = array_map(function(IGroup $subAdminGroup) { |
|
614 | 614 | return $subAdminGroup->getGID(); |
615 | 615 | }, $subAdminGroups); |
616 | 616 | $userGroups = $this->groupManager->getUserGroupIds($targetUser); |
@@ -642,15 +642,15 @@ discard block |
||
642 | 642 | $user = $this->userManager->get($userId); |
643 | 643 | |
644 | 644 | // Check if the user exists |
645 | - if($user === null) { |
|
645 | + if ($user === null) { |
|
646 | 646 | throw new OCSException('User does not exist', 101); |
647 | 647 | } |
648 | 648 | // Check if group exists |
649 | - if($group === null) { |
|
650 | - throw new OCSException('Group:'.$groupid.' does not exist', 102); |
|
649 | + if ($group === null) { |
|
650 | + throw new OCSException('Group:'.$groupid.' does not exist', 102); |
|
651 | 651 | } |
652 | 652 | // Check if trying to make subadmin of admin group |
653 | - if(strtolower($groupid) === 'admin') { |
|
653 | + if (strtolower($groupid) === 'admin') { |
|
654 | 654 | throw new OCSException('Cannot create subadmins for admin group', 103); |
655 | 655 | } |
656 | 656 | |
@@ -661,7 +661,7 @@ discard block |
||
661 | 661 | return new DataResponse(); |
662 | 662 | } |
663 | 663 | // Go |
664 | - if($subAdminManager->createSubAdmin($user, $group)) { |
|
664 | + if ($subAdminManager->createSubAdmin($user, $group)) { |
|
665 | 665 | return new DataResponse(); |
666 | 666 | } else { |
667 | 667 | throw new OCSException('Unknown error occurred', 103); |
@@ -684,20 +684,20 @@ discard block |
||
684 | 684 | $subAdminManager = $this->groupManager->getSubAdmin(); |
685 | 685 | |
686 | 686 | // Check if the user exists |
687 | - if($user === null) { |
|
687 | + if ($user === null) { |
|
688 | 688 | throw new OCSException('User does not exist', 101); |
689 | 689 | } |
690 | 690 | // Check if the group exists |
691 | - if($group === null) { |
|
691 | + if ($group === null) { |
|
692 | 692 | throw new OCSException('Group does not exist', 101); |
693 | 693 | } |
694 | 694 | // Check if they are a subadmin of this said group |
695 | - if(!$subAdminManager->isSubAdminofGroup($user, $group)) { |
|
695 | + if (!$subAdminManager->isSubAdminofGroup($user, $group)) { |
|
696 | 696 | throw new OCSException('User is not a subadmin of this group', 102); |
697 | 697 | } |
698 | 698 | |
699 | 699 | // Go |
700 | - if($subAdminManager->deleteSubAdmin($user, $group)) { |
|
700 | + if ($subAdminManager->deleteSubAdmin($user, $group)) { |
|
701 | 701 | return new DataResponse(); |
702 | 702 | } else { |
703 | 703 | throw new OCSException('Unknown error occurred', 103); |
@@ -714,7 +714,7 @@ discard block |
||
714 | 714 | public function getUserSubAdminGroups($userId) { |
715 | 715 | $user = $this->userManager->get($userId); |
716 | 716 | // Check if the user exists |
717 | - if($user === null) { |
|
717 | + if ($user === null) { |
|
718 | 718 | throw new OCSException('User does not exist', 101); |
719 | 719 | } |
720 | 720 | |
@@ -724,7 +724,7 @@ discard block |
||
724 | 724 | $groups[$key] = $group->getGID(); |
725 | 725 | } |
726 | 726 | |
727 | - if(!$groups) { |
|
727 | + if (!$groups) { |
|
728 | 728 | throw new OCSException('Unknown error occurred', 102); |
729 | 729 | } else { |
730 | 730 | return new DataResponse($groups); |
@@ -768,13 +768,13 @@ discard block |
||
768 | 768 | $currentLoggedInUser = $this->userSession->getUser(); |
769 | 769 | |
770 | 770 | $targetUser = $this->userManager->get($userId); |
771 | - if($targetUser === null) { |
|
771 | + if ($targetUser === null) { |
|
772 | 772 | throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
773 | 773 | } |
774 | 774 | |
775 | 775 | // Check if admin / subadmin |
776 | 776 | $subAdminManager = $this->groupManager->getSubAdmin(); |
777 | - if(!$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser) |
|
777 | + if (!$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser) |
|
778 | 778 | && !$this->groupManager->isAdmin($currentLoggedInUser->getUID())) { |
779 | 779 | // No rights |
780 | 780 | throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
@@ -796,8 +796,8 @@ discard block |
||
796 | 796 | $this->newUserMailHelper->setL10N($l10n); |
797 | 797 | $emailTemplate = $this->newUserMailHelper->generateTemplate($targetUser, false); |
798 | 798 | $this->newUserMailHelper->sendMail($targetUser, $emailTemplate); |
799 | - } catch(\Exception $e) { |
|
800 | - $this->logger->error("Can't send new user mail to $email: " . $e->getMessage(), array('app' => 'settings')); |
|
799 | + } catch (\Exception $e) { |
|
800 | + $this->logger->error("Can't send new user mail to $email: ".$e->getMessage(), array('app' => 'settings')); |
|
801 | 801 | throw new OCSException('Sending email failed', 102); |
802 | 802 | } |
803 | 803 |
@@ -38,7 +38,6 @@ |
||
38 | 38 | use OC\ServerContainer; |
39 | 39 | use OC\Settings\Mailer\NewUserMailHelper; |
40 | 40 | use OC\Settings\Middleware\SubadminMiddleware; |
41 | -use OCA\Theming\ThemingDefaults; |
|
42 | 41 | use OCP\AppFramework\App; |
43 | 42 | use OCP\IContainer; |
44 | 43 | use OCP\Settings\IManager; |
@@ -50,82 +50,82 @@ |
||
50 | 50 | class Application extends App { |
51 | 51 | |
52 | 52 | |
53 | - /** |
|
54 | - * @param array $urlParams |
|
55 | - */ |
|
56 | - public function __construct(array $urlParams=[]){ |
|
57 | - parent::__construct('settings', $urlParams); |
|
53 | + /** |
|
54 | + * @param array $urlParams |
|
55 | + */ |
|
56 | + public function __construct(array $urlParams=[]){ |
|
57 | + parent::__construct('settings', $urlParams); |
|
58 | 58 | |
59 | - $container = $this->getContainer(); |
|
59 | + $container = $this->getContainer(); |
|
60 | 60 | |
61 | - // Register Middleware |
|
62 | - $container->registerAlias('SubadminMiddleware', SubadminMiddleware::class); |
|
63 | - $container->registerMiddleWare('SubadminMiddleware'); |
|
61 | + // Register Middleware |
|
62 | + $container->registerAlias('SubadminMiddleware', SubadminMiddleware::class); |
|
63 | + $container->registerMiddleWare('SubadminMiddleware'); |
|
64 | 64 | |
65 | - /** |
|
66 | - * Core class wrappers |
|
67 | - */ |
|
68 | - /** FIXME: Remove once OC_User is non-static and mockable */ |
|
69 | - $container->registerService('isAdmin', function() { |
|
70 | - return \OC_User::isAdminUser(\OC_User::getUser()); |
|
71 | - }); |
|
72 | - /** FIXME: Remove once OC_SubAdmin is non-static and mockable */ |
|
73 | - $container->registerService('isSubAdmin', function(IContainer $c) { |
|
74 | - $userObject = \OC::$server->getUserSession()->getUser(); |
|
75 | - $isSubAdmin = false; |
|
76 | - if($userObject !== null) { |
|
77 | - $isSubAdmin = \OC::$server->getGroupManager()->getSubAdmin()->isSubAdmin($userObject); |
|
78 | - } |
|
79 | - return $isSubAdmin; |
|
80 | - }); |
|
81 | - $container->registerService('userCertificateManager', function(IContainer $c) { |
|
82 | - return $c->query('ServerContainer')->getCertificateManager(); |
|
83 | - }, false); |
|
84 | - $container->registerService('systemCertificateManager', function (IContainer $c) { |
|
85 | - return $c->query('ServerContainer')->getCertificateManager(null); |
|
86 | - }, false); |
|
87 | - $container->registerService(IProvider::class, function (IContainer $c) { |
|
88 | - return $c->query('ServerContainer')->query(IProvider::class); |
|
89 | - }); |
|
90 | - $container->registerService(IManager::class, function (IContainer $c) { |
|
91 | - return $c->query('ServerContainer')->getSettingsManager(); |
|
92 | - }); |
|
65 | + /** |
|
66 | + * Core class wrappers |
|
67 | + */ |
|
68 | + /** FIXME: Remove once OC_User is non-static and mockable */ |
|
69 | + $container->registerService('isAdmin', function() { |
|
70 | + return \OC_User::isAdminUser(\OC_User::getUser()); |
|
71 | + }); |
|
72 | + /** FIXME: Remove once OC_SubAdmin is non-static and mockable */ |
|
73 | + $container->registerService('isSubAdmin', function(IContainer $c) { |
|
74 | + $userObject = \OC::$server->getUserSession()->getUser(); |
|
75 | + $isSubAdmin = false; |
|
76 | + if($userObject !== null) { |
|
77 | + $isSubAdmin = \OC::$server->getGroupManager()->getSubAdmin()->isSubAdmin($userObject); |
|
78 | + } |
|
79 | + return $isSubAdmin; |
|
80 | + }); |
|
81 | + $container->registerService('userCertificateManager', function(IContainer $c) { |
|
82 | + return $c->query('ServerContainer')->getCertificateManager(); |
|
83 | + }, false); |
|
84 | + $container->registerService('systemCertificateManager', function (IContainer $c) { |
|
85 | + return $c->query('ServerContainer')->getCertificateManager(null); |
|
86 | + }, false); |
|
87 | + $container->registerService(IProvider::class, function (IContainer $c) { |
|
88 | + return $c->query('ServerContainer')->query(IProvider::class); |
|
89 | + }); |
|
90 | + $container->registerService(IManager::class, function (IContainer $c) { |
|
91 | + return $c->query('ServerContainer')->getSettingsManager(); |
|
92 | + }); |
|
93 | 93 | |
94 | - $container->registerService(NewUserMailHelper::class, function (IContainer $c) { |
|
95 | - /** @var Server $server */ |
|
96 | - $server = $c->query('ServerContainer'); |
|
94 | + $container->registerService(NewUserMailHelper::class, function (IContainer $c) { |
|
95 | + /** @var Server $server */ |
|
96 | + $server = $c->query('ServerContainer'); |
|
97 | 97 | |
98 | - return new NewUserMailHelper( |
|
99 | - $server->getThemingDefaults(), |
|
100 | - $server->getURLGenerator(), |
|
101 | - $server->getL10N('settings'), |
|
102 | - $server->getMailer(), |
|
103 | - $server->getSecureRandom(), |
|
104 | - new TimeFactory(), |
|
105 | - $server->getConfig(), |
|
106 | - $server->getCrypto(), |
|
107 | - Util::getDefaultEmailAddress('no-reply') |
|
108 | - ); |
|
109 | - }); |
|
110 | - $container->registerService(AppFetcher::class, function (IContainer $c) { |
|
111 | - /** @var Server $server */ |
|
112 | - $server = $c->query('ServerContainer'); |
|
113 | - return new AppFetcher( |
|
114 | - $server->getAppDataDir('appstore'), |
|
115 | - $server->getHTTPClientService(), |
|
116 | - $server->query(TimeFactory::class), |
|
117 | - $server->getConfig() |
|
118 | - ); |
|
119 | - }); |
|
120 | - $container->registerService(CategoryFetcher::class, function (IContainer $c) { |
|
121 | - /** @var Server $server */ |
|
122 | - $server = $c->query('ServerContainer'); |
|
123 | - return new CategoryFetcher( |
|
124 | - $server->getAppDataDir('appstore'), |
|
125 | - $server->getHTTPClientService(), |
|
126 | - $server->query(TimeFactory::class), |
|
127 | - $server->getConfig() |
|
128 | - ); |
|
129 | - }); |
|
130 | - } |
|
98 | + return new NewUserMailHelper( |
|
99 | + $server->getThemingDefaults(), |
|
100 | + $server->getURLGenerator(), |
|
101 | + $server->getL10N('settings'), |
|
102 | + $server->getMailer(), |
|
103 | + $server->getSecureRandom(), |
|
104 | + new TimeFactory(), |
|
105 | + $server->getConfig(), |
|
106 | + $server->getCrypto(), |
|
107 | + Util::getDefaultEmailAddress('no-reply') |
|
108 | + ); |
|
109 | + }); |
|
110 | + $container->registerService(AppFetcher::class, function (IContainer $c) { |
|
111 | + /** @var Server $server */ |
|
112 | + $server = $c->query('ServerContainer'); |
|
113 | + return new AppFetcher( |
|
114 | + $server->getAppDataDir('appstore'), |
|
115 | + $server->getHTTPClientService(), |
|
116 | + $server->query(TimeFactory::class), |
|
117 | + $server->getConfig() |
|
118 | + ); |
|
119 | + }); |
|
120 | + $container->registerService(CategoryFetcher::class, function (IContainer $c) { |
|
121 | + /** @var Server $server */ |
|
122 | + $server = $c->query('ServerContainer'); |
|
123 | + return new CategoryFetcher( |
|
124 | + $server->getAppDataDir('appstore'), |
|
125 | + $server->getHTTPClientService(), |
|
126 | + $server->query(TimeFactory::class), |
|
127 | + $server->getConfig() |
|
128 | + ); |
|
129 | + }); |
|
130 | + } |
|
131 | 131 | } |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | /** |
54 | 54 | * @param array $urlParams |
55 | 55 | */ |
56 | - public function __construct(array $urlParams=[]){ |
|
56 | + public function __construct(array $urlParams = []) { |
|
57 | 57 | parent::__construct('settings', $urlParams); |
58 | 58 | |
59 | 59 | $container = $this->getContainer(); |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | $container->registerService('isSubAdmin', function(IContainer $c) { |
74 | 74 | $userObject = \OC::$server->getUserSession()->getUser(); |
75 | 75 | $isSubAdmin = false; |
76 | - if($userObject !== null) { |
|
76 | + if ($userObject !== null) { |
|
77 | 77 | $isSubAdmin = \OC::$server->getGroupManager()->getSubAdmin()->isSubAdmin($userObject); |
78 | 78 | } |
79 | 79 | return $isSubAdmin; |
@@ -81,17 +81,17 @@ discard block |
||
81 | 81 | $container->registerService('userCertificateManager', function(IContainer $c) { |
82 | 82 | return $c->query('ServerContainer')->getCertificateManager(); |
83 | 83 | }, false); |
84 | - $container->registerService('systemCertificateManager', function (IContainer $c) { |
|
84 | + $container->registerService('systemCertificateManager', function(IContainer $c) { |
|
85 | 85 | return $c->query('ServerContainer')->getCertificateManager(null); |
86 | 86 | }, false); |
87 | - $container->registerService(IProvider::class, function (IContainer $c) { |
|
87 | + $container->registerService(IProvider::class, function(IContainer $c) { |
|
88 | 88 | return $c->query('ServerContainer')->query(IProvider::class); |
89 | 89 | }); |
90 | - $container->registerService(IManager::class, function (IContainer $c) { |
|
90 | + $container->registerService(IManager::class, function(IContainer $c) { |
|
91 | 91 | return $c->query('ServerContainer')->getSettingsManager(); |
92 | 92 | }); |
93 | 93 | |
94 | - $container->registerService(NewUserMailHelper::class, function (IContainer $c) { |
|
94 | + $container->registerService(NewUserMailHelper::class, function(IContainer $c) { |
|
95 | 95 | /** @var Server $server */ |
96 | 96 | $server = $c->query('ServerContainer'); |
97 | 97 | |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | Util::getDefaultEmailAddress('no-reply') |
108 | 108 | ); |
109 | 109 | }); |
110 | - $container->registerService(AppFetcher::class, function (IContainer $c) { |
|
110 | + $container->registerService(AppFetcher::class, function(IContainer $c) { |
|
111 | 111 | /** @var Server $server */ |
112 | 112 | $server = $c->query('ServerContainer'); |
113 | 113 | return new AppFetcher( |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | $server->getConfig() |
118 | 118 | ); |
119 | 119 | }); |
120 | - $container->registerService(CategoryFetcher::class, function (IContainer $c) { |
|
120 | + $container->registerService(CategoryFetcher::class, function(IContainer $c) { |
|
121 | 121 | /** @var Server $server */ |
122 | 122 | $server = $c->query('ServerContainer'); |
123 | 123 | return new CategoryFetcher( |
@@ -115,1590 +115,1590 @@ |
||
115 | 115 | * TODO: hookup all manager classes |
116 | 116 | */ |
117 | 117 | class Server extends ServerContainer implements IServerContainer { |
118 | - /** @var string */ |
|
119 | - private $webRoot; |
|
120 | - |
|
121 | - /** |
|
122 | - * @param string $webRoot |
|
123 | - * @param \OC\Config $config |
|
124 | - */ |
|
125 | - public function __construct($webRoot, \OC\Config $config) { |
|
126 | - parent::__construct(); |
|
127 | - $this->webRoot = $webRoot; |
|
128 | - |
|
129 | - $this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class); |
|
130 | - $this->registerAlias('ContactsManager', \OCP\Contacts\IManager::class); |
|
131 | - |
|
132 | - $this->registerService(\OCP\IPreview::class, function (Server $c) { |
|
133 | - return new PreviewManager( |
|
134 | - $c->getConfig(), |
|
135 | - $c->getRootFolder(), |
|
136 | - $c->getAppDataDir('preview'), |
|
137 | - $c->getEventDispatcher(), |
|
138 | - $c->getSession()->get('user_id') |
|
139 | - ); |
|
140 | - }); |
|
141 | - $this->registerAlias('PreviewManager', \OCP\IPreview::class); |
|
142 | - |
|
143 | - $this->registerService(\OC\Preview\Watcher::class, function (Server $c) { |
|
144 | - return new \OC\Preview\Watcher( |
|
145 | - $c->getAppDataDir('preview') |
|
146 | - ); |
|
147 | - }); |
|
148 | - |
|
149 | - $this->registerService('EncryptionManager', function (Server $c) { |
|
150 | - $view = new View(); |
|
151 | - $util = new Encryption\Util( |
|
152 | - $view, |
|
153 | - $c->getUserManager(), |
|
154 | - $c->getGroupManager(), |
|
155 | - $c->getConfig() |
|
156 | - ); |
|
157 | - return new Encryption\Manager( |
|
158 | - $c->getConfig(), |
|
159 | - $c->getLogger(), |
|
160 | - $c->getL10N('core'), |
|
161 | - new View(), |
|
162 | - $util, |
|
163 | - new ArrayCache() |
|
164 | - ); |
|
165 | - }); |
|
166 | - |
|
167 | - $this->registerService('EncryptionFileHelper', function (Server $c) { |
|
168 | - $util = new Encryption\Util( |
|
169 | - new View(), |
|
170 | - $c->getUserManager(), |
|
171 | - $c->getGroupManager(), |
|
172 | - $c->getConfig() |
|
173 | - ); |
|
174 | - return new Encryption\File($util); |
|
175 | - }); |
|
176 | - |
|
177 | - $this->registerService('EncryptionKeyStorage', function (Server $c) { |
|
178 | - $view = new View(); |
|
179 | - $util = new Encryption\Util( |
|
180 | - $view, |
|
181 | - $c->getUserManager(), |
|
182 | - $c->getGroupManager(), |
|
183 | - $c->getConfig() |
|
184 | - ); |
|
185 | - |
|
186 | - return new Encryption\Keys\Storage($view, $util); |
|
187 | - }); |
|
188 | - $this->registerService('TagMapper', function (Server $c) { |
|
189 | - return new TagMapper($c->getDatabaseConnection()); |
|
190 | - }); |
|
191 | - |
|
192 | - $this->registerService(\OCP\ITagManager::class, function (Server $c) { |
|
193 | - $tagMapper = $c->query('TagMapper'); |
|
194 | - return new TagManager($tagMapper, $c->getUserSession()); |
|
195 | - }); |
|
196 | - $this->registerAlias('TagManager', \OCP\ITagManager::class); |
|
197 | - |
|
198 | - $this->registerService('SystemTagManagerFactory', function (Server $c) { |
|
199 | - $config = $c->getConfig(); |
|
200 | - $factoryClass = $config->getSystemValue('systemtags.managerFactory', '\OC\SystemTag\ManagerFactory'); |
|
201 | - /** @var \OC\SystemTag\ManagerFactory $factory */ |
|
202 | - $factory = new $factoryClass($this); |
|
203 | - return $factory; |
|
204 | - }); |
|
205 | - $this->registerService(\OCP\SystemTag\ISystemTagManager::class, function (Server $c) { |
|
206 | - return $c->query('SystemTagManagerFactory')->getManager(); |
|
207 | - }); |
|
208 | - $this->registerAlias('SystemTagManager', \OCP\SystemTag\ISystemTagManager::class); |
|
209 | - |
|
210 | - $this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function (Server $c) { |
|
211 | - return $c->query('SystemTagManagerFactory')->getObjectMapper(); |
|
212 | - }); |
|
213 | - $this->registerService('RootFolder', function (Server $c) { |
|
214 | - $manager = \OC\Files\Filesystem::getMountManager(null); |
|
215 | - $view = new View(); |
|
216 | - $root = new Root( |
|
217 | - $manager, |
|
218 | - $view, |
|
219 | - null, |
|
220 | - $c->getUserMountCache(), |
|
221 | - $this->getLogger(), |
|
222 | - $this->getUserManager() |
|
223 | - ); |
|
224 | - $connector = new HookConnector($root, $view); |
|
225 | - $connector->viewToNode(); |
|
226 | - |
|
227 | - $previewConnector = new \OC\Preview\WatcherConnector($root, $c->getSystemConfig()); |
|
228 | - $previewConnector->connectWatcher(); |
|
229 | - |
|
230 | - return $root; |
|
231 | - }); |
|
232 | - $this->registerAlias('SystemTagObjectMapper', \OCP\SystemTag\ISystemTagObjectMapper::class); |
|
233 | - |
|
234 | - $this->registerService(\OCP\Files\IRootFolder::class, function(Server $c) { |
|
235 | - return new LazyRoot(function() use ($c) { |
|
236 | - return $c->query('RootFolder'); |
|
237 | - }); |
|
238 | - }); |
|
239 | - $this->registerAlias('LazyRootFolder', \OCP\Files\IRootFolder::class); |
|
240 | - |
|
241 | - $this->registerService(\OCP\IUserManager::class, function (Server $c) { |
|
242 | - $config = $c->getConfig(); |
|
243 | - return new \OC\User\Manager($config); |
|
244 | - }); |
|
245 | - $this->registerAlias('UserManager', \OCP\IUserManager::class); |
|
246 | - |
|
247 | - $this->registerService(\OCP\IGroupManager::class, function (Server $c) { |
|
248 | - $groupManager = new \OC\Group\Manager($this->getUserManager(), $this->getLogger()); |
|
249 | - $groupManager->listen('\OC\Group', 'preCreate', function ($gid) { |
|
250 | - \OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid)); |
|
251 | - }); |
|
252 | - $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) { |
|
253 | - \OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID())); |
|
254 | - }); |
|
255 | - $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) { |
|
256 | - \OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID())); |
|
257 | - }); |
|
258 | - $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) { |
|
259 | - \OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID())); |
|
260 | - }); |
|
261 | - $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
262 | - \OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
263 | - }); |
|
264 | - $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
265 | - \OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
266 | - //Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks |
|
267 | - \OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
268 | - }); |
|
269 | - return $groupManager; |
|
270 | - }); |
|
271 | - $this->registerAlias('GroupManager', \OCP\IGroupManager::class); |
|
272 | - |
|
273 | - $this->registerService(Store::class, function(Server $c) { |
|
274 | - $session = $c->getSession(); |
|
275 | - if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
276 | - $tokenProvider = $c->query('OC\Authentication\Token\IProvider'); |
|
277 | - } else { |
|
278 | - $tokenProvider = null; |
|
279 | - } |
|
280 | - $logger = $c->getLogger(); |
|
281 | - return new Store($session, $logger, $tokenProvider); |
|
282 | - }); |
|
283 | - $this->registerAlias(IStore::class, Store::class); |
|
284 | - $this->registerService('OC\Authentication\Token\DefaultTokenMapper', function (Server $c) { |
|
285 | - $dbConnection = $c->getDatabaseConnection(); |
|
286 | - return new Authentication\Token\DefaultTokenMapper($dbConnection); |
|
287 | - }); |
|
288 | - $this->registerService('OC\Authentication\Token\DefaultTokenProvider', function (Server $c) { |
|
289 | - $mapper = $c->query('OC\Authentication\Token\DefaultTokenMapper'); |
|
290 | - $crypto = $c->getCrypto(); |
|
291 | - $config = $c->getConfig(); |
|
292 | - $logger = $c->getLogger(); |
|
293 | - $timeFactory = new TimeFactory(); |
|
294 | - return new \OC\Authentication\Token\DefaultTokenProvider($mapper, $crypto, $config, $logger, $timeFactory); |
|
295 | - }); |
|
296 | - $this->registerAlias('OC\Authentication\Token\IProvider', 'OC\Authentication\Token\DefaultTokenProvider'); |
|
297 | - |
|
298 | - $this->registerService(\OCP\IUserSession::class, function (Server $c) { |
|
299 | - $manager = $c->getUserManager(); |
|
300 | - $session = new \OC\Session\Memory(''); |
|
301 | - $timeFactory = new TimeFactory(); |
|
302 | - // Token providers might require a working database. This code |
|
303 | - // might however be called when ownCloud is not yet setup. |
|
304 | - if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
305 | - $defaultTokenProvider = $c->query('OC\Authentication\Token\IProvider'); |
|
306 | - } else { |
|
307 | - $defaultTokenProvider = null; |
|
308 | - } |
|
309 | - |
|
310 | - $userSession = new \OC\User\Session($manager, $session, $timeFactory, $defaultTokenProvider, $c->getConfig(), $c->getSecureRandom(), $c->getLockdownManager()); |
|
311 | - $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { |
|
312 | - \OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password)); |
|
313 | - }); |
|
314 | - $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) { |
|
315 | - /** @var $user \OC\User\User */ |
|
316 | - \OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password)); |
|
317 | - }); |
|
318 | - $userSession->listen('\OC\User', 'preDelete', function ($user) { |
|
319 | - /** @var $user \OC\User\User */ |
|
320 | - \OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID())); |
|
321 | - }); |
|
322 | - $userSession->listen('\OC\User', 'postDelete', function ($user) { |
|
323 | - /** @var $user \OC\User\User */ |
|
324 | - \OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID())); |
|
325 | - }); |
|
326 | - $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { |
|
327 | - /** @var $user \OC\User\User */ |
|
328 | - \OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
|
329 | - }); |
|
330 | - $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) { |
|
331 | - /** @var $user \OC\User\User */ |
|
332 | - \OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
|
333 | - }); |
|
334 | - $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) { |
|
335 | - \OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password)); |
|
336 | - }); |
|
337 | - $userSession->listen('\OC\User', 'postLogin', function ($user, $password) { |
|
338 | - /** @var $user \OC\User\User */ |
|
339 | - \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); |
|
340 | - }); |
|
341 | - $userSession->listen('\OC\User', 'logout', function () { |
|
342 | - \OC_Hook::emit('OC_User', 'logout', array()); |
|
343 | - }); |
|
344 | - $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value) { |
|
345 | - /** @var $user \OC\User\User */ |
|
346 | - \OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value)); |
|
347 | - }); |
|
348 | - return $userSession; |
|
349 | - }); |
|
350 | - $this->registerAlias('UserSession', \OCP\IUserSession::class); |
|
351 | - |
|
352 | - $this->registerService(\OC\Authentication\TwoFactorAuth\Manager::class, function (Server $c) { |
|
353 | - return new \OC\Authentication\TwoFactorAuth\Manager($c->getAppManager(), $c->getSession(), $c->getConfig(), $c->getActivityManager(), $c->getLogger()); |
|
354 | - }); |
|
355 | - |
|
356 | - $this->registerAlias(\OCP\INavigationManager::class, \OC\NavigationManager::class); |
|
357 | - $this->registerAlias('NavigationManager', \OCP\INavigationManager::class); |
|
358 | - |
|
359 | - $this->registerService(\OC\AllConfig::class, function (Server $c) { |
|
360 | - return new \OC\AllConfig( |
|
361 | - $c->getSystemConfig() |
|
362 | - ); |
|
363 | - }); |
|
364 | - $this->registerAlias('AllConfig', \OC\AllConfig::class); |
|
365 | - $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class); |
|
366 | - |
|
367 | - $this->registerService('SystemConfig', function ($c) use ($config) { |
|
368 | - return new \OC\SystemConfig($config); |
|
369 | - }); |
|
370 | - |
|
371 | - $this->registerService(\OC\AppConfig::class, function (Server $c) { |
|
372 | - return new \OC\AppConfig($c->getDatabaseConnection()); |
|
373 | - }); |
|
374 | - $this->registerAlias('AppConfig', \OC\AppConfig::class); |
|
375 | - $this->registerAlias(\OCP\IAppConfig::class, \OC\AppConfig::class); |
|
376 | - |
|
377 | - $this->registerService(\OCP\L10N\IFactory::class, function (Server $c) { |
|
378 | - return new \OC\L10N\Factory( |
|
379 | - $c->getConfig(), |
|
380 | - $c->getRequest(), |
|
381 | - $c->getUserSession(), |
|
382 | - \OC::$SERVERROOT |
|
383 | - ); |
|
384 | - }); |
|
385 | - $this->registerAlias('L10NFactory', \OCP\L10N\IFactory::class); |
|
386 | - |
|
387 | - $this->registerService(\OCP\IURLGenerator::class, function (Server $c) { |
|
388 | - $config = $c->getConfig(); |
|
389 | - $cacheFactory = $c->getMemCacheFactory(); |
|
390 | - return new \OC\URLGenerator( |
|
391 | - $config, |
|
392 | - $cacheFactory |
|
393 | - ); |
|
394 | - }); |
|
395 | - $this->registerAlias('URLGenerator', \OCP\IURLGenerator::class); |
|
396 | - |
|
397 | - $this->registerService('AppHelper', function ($c) { |
|
398 | - return new \OC\AppHelper(); |
|
399 | - }); |
|
400 | - $this->registerService('AppFetcher', function ($c) { |
|
401 | - return new AppFetcher( |
|
402 | - $this->getAppDataDir('appstore'), |
|
403 | - $this->getHTTPClientService(), |
|
404 | - $this->query(TimeFactory::class), |
|
405 | - $this->getConfig() |
|
406 | - ); |
|
407 | - }); |
|
408 | - $this->registerService('CategoryFetcher', function ($c) { |
|
409 | - return new CategoryFetcher( |
|
410 | - $this->getAppDataDir('appstore'), |
|
411 | - $this->getHTTPClientService(), |
|
412 | - $this->query(TimeFactory::class), |
|
413 | - $this->getConfig() |
|
414 | - ); |
|
415 | - }); |
|
416 | - |
|
417 | - $this->registerService(\OCP\ICache::class, function ($c) { |
|
418 | - return new Cache\File(); |
|
419 | - }); |
|
420 | - $this->registerAlias('UserCache', \OCP\ICache::class); |
|
421 | - |
|
422 | - $this->registerService(Factory::class, function (Server $c) { |
|
423 | - $config = $c->getConfig(); |
|
424 | - |
|
425 | - if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
426 | - $v = \OC_App::getAppVersions(); |
|
427 | - $v['core'] = md5(file_get_contents(\OC::$SERVERROOT . '/version.php')); |
|
428 | - $version = implode(',', $v); |
|
429 | - $instanceId = \OC_Util::getInstanceId(); |
|
430 | - $path = \OC::$SERVERROOT; |
|
431 | - $prefix = md5($instanceId . '-' . $version . '-' . $path . '-' . \OC::$WEBROOT); |
|
432 | - return new \OC\Memcache\Factory($prefix, $c->getLogger(), |
|
433 | - $config->getSystemValue('memcache.local', null), |
|
434 | - $config->getSystemValue('memcache.distributed', null), |
|
435 | - $config->getSystemValue('memcache.locking', null) |
|
436 | - ); |
|
437 | - } |
|
438 | - |
|
439 | - return new \OC\Memcache\Factory('', $c->getLogger(), |
|
440 | - '\\OC\\Memcache\\ArrayCache', |
|
441 | - '\\OC\\Memcache\\ArrayCache', |
|
442 | - '\\OC\\Memcache\\ArrayCache' |
|
443 | - ); |
|
444 | - }); |
|
445 | - $this->registerAlias('MemCacheFactory', Factory::class); |
|
446 | - $this->registerAlias(ICacheFactory::class, Factory::class); |
|
447 | - |
|
448 | - $this->registerService('RedisFactory', function (Server $c) { |
|
449 | - $systemConfig = $c->getSystemConfig(); |
|
450 | - return new RedisFactory($systemConfig); |
|
451 | - }); |
|
452 | - |
|
453 | - $this->registerService(\OCP\Activity\IManager::class, function (Server $c) { |
|
454 | - return new \OC\Activity\Manager( |
|
455 | - $c->getRequest(), |
|
456 | - $c->getUserSession(), |
|
457 | - $c->getConfig(), |
|
458 | - $c->query(IValidator::class) |
|
459 | - ); |
|
460 | - }); |
|
461 | - $this->registerAlias('ActivityManager', \OCP\Activity\IManager::class); |
|
462 | - |
|
463 | - $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) { |
|
464 | - return new \OC\Activity\EventMerger( |
|
465 | - $c->getL10N('lib') |
|
466 | - ); |
|
467 | - }); |
|
468 | - $this->registerAlias(IValidator::class, Validator::class); |
|
469 | - |
|
470 | - $this->registerService(\OCP\IAvatarManager::class, function (Server $c) { |
|
471 | - return new AvatarManager( |
|
472 | - $c->getUserManager(), |
|
473 | - $c->getAppDataDir('avatar'), |
|
474 | - $c->getL10N('lib'), |
|
475 | - $c->getLogger(), |
|
476 | - $c->getConfig() |
|
477 | - ); |
|
478 | - }); |
|
479 | - $this->registerAlias('AvatarManager', \OCP\IAvatarManager::class); |
|
480 | - |
|
481 | - $this->registerService(\OCP\ILogger::class, function (Server $c) { |
|
482 | - $logType = $c->query('AllConfig')->getSystemValue('log_type', 'file'); |
|
483 | - $logger = Log::getLogClass($logType); |
|
484 | - call_user_func(array($logger, 'init')); |
|
485 | - |
|
486 | - return new Log($logger); |
|
487 | - }); |
|
488 | - $this->registerAlias('Logger', \OCP\ILogger::class); |
|
489 | - |
|
490 | - $this->registerService(\OCP\BackgroundJob\IJobList::class, function (Server $c) { |
|
491 | - $config = $c->getConfig(); |
|
492 | - return new \OC\BackgroundJob\JobList( |
|
493 | - $c->getDatabaseConnection(), |
|
494 | - $config, |
|
495 | - new TimeFactory() |
|
496 | - ); |
|
497 | - }); |
|
498 | - $this->registerAlias('JobList', \OCP\BackgroundJob\IJobList::class); |
|
499 | - |
|
500 | - $this->registerService(\OCP\Route\IRouter::class, function (Server $c) { |
|
501 | - $cacheFactory = $c->getMemCacheFactory(); |
|
502 | - $logger = $c->getLogger(); |
|
503 | - if ($cacheFactory->isAvailable()) { |
|
504 | - $router = new \OC\Route\CachingRouter($cacheFactory->create('route'), $logger); |
|
505 | - } else { |
|
506 | - $router = new \OC\Route\Router($logger); |
|
507 | - } |
|
508 | - return $router; |
|
509 | - }); |
|
510 | - $this->registerAlias('Router', \OCP\Route\IRouter::class); |
|
511 | - |
|
512 | - $this->registerService(\OCP\ISearch::class, function ($c) { |
|
513 | - return new Search(); |
|
514 | - }); |
|
515 | - $this->registerAlias('Search', \OCP\ISearch::class); |
|
516 | - |
|
517 | - $this->registerService(\OCP\Security\ISecureRandom::class, function ($c) { |
|
518 | - return new SecureRandom(); |
|
519 | - }); |
|
520 | - $this->registerAlias('SecureRandom', \OCP\Security\ISecureRandom::class); |
|
521 | - |
|
522 | - $this->registerService(\OCP\Security\ICrypto::class, function (Server $c) { |
|
523 | - return new Crypto($c->getConfig(), $c->getSecureRandom()); |
|
524 | - }); |
|
525 | - $this->registerAlias('Crypto', \OCP\Security\ICrypto::class); |
|
526 | - |
|
527 | - $this->registerService(\OCP\Security\IHasher::class, function (Server $c) { |
|
528 | - return new Hasher($c->getConfig()); |
|
529 | - }); |
|
530 | - $this->registerAlias('Hasher', \OCP\Security\IHasher::class); |
|
531 | - |
|
532 | - $this->registerService(\OCP\Security\ICredentialsManager::class, function (Server $c) { |
|
533 | - return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection()); |
|
534 | - }); |
|
535 | - $this->registerAlias('CredentialsManager', \OCP\Security\ICredentialsManager::class); |
|
536 | - |
|
537 | - $this->registerService(IDBConnection::class, function (Server $c) { |
|
538 | - $systemConfig = $c->getSystemConfig(); |
|
539 | - $factory = new \OC\DB\ConnectionFactory($systemConfig); |
|
540 | - $type = $systemConfig->getValue('dbtype', 'sqlite'); |
|
541 | - if (!$factory->isValidType($type)) { |
|
542 | - throw new \OC\DatabaseException('Invalid database type'); |
|
543 | - } |
|
544 | - $connectionParams = $factory->createConnectionParams(); |
|
545 | - $connection = $factory->getConnection($type, $connectionParams); |
|
546 | - $connection->getConfiguration()->setSQLLogger($c->getQueryLogger()); |
|
547 | - return $connection; |
|
548 | - }); |
|
549 | - $this->registerAlias('DatabaseConnection', IDBConnection::class); |
|
550 | - |
|
551 | - $this->registerService('HTTPHelper', function (Server $c) { |
|
552 | - $config = $c->getConfig(); |
|
553 | - return new HTTPHelper( |
|
554 | - $config, |
|
555 | - $c->getHTTPClientService() |
|
556 | - ); |
|
557 | - }); |
|
558 | - |
|
559 | - $this->registerService(\OCP\Http\Client\IClientService::class, function (Server $c) { |
|
560 | - $user = \OC_User::getUser(); |
|
561 | - $uid = $user ? $user : null; |
|
562 | - return new ClientService( |
|
563 | - $c->getConfig(), |
|
564 | - new \OC\Security\CertificateManager($uid, new View(), $c->getConfig(), $c->getLogger()) |
|
565 | - ); |
|
566 | - }); |
|
567 | - $this->registerAlias('HttpClientService', \OCP\Http\Client\IClientService::class); |
|
568 | - |
|
569 | - $this->registerService(\OCP\Diagnostics\IEventLogger::class, function (Server $c) { |
|
570 | - if ($c->getSystemConfig()->getValue('debug', false)) { |
|
571 | - return new EventLogger(); |
|
572 | - } else { |
|
573 | - return new NullEventLogger(); |
|
574 | - } |
|
575 | - }); |
|
576 | - $this->registerAlias('EventLogger', \OCP\Diagnostics\IEventLogger::class); |
|
577 | - |
|
578 | - $this->registerService(\OCP\Diagnostics\IQueryLogger::class, function (Server $c) { |
|
579 | - if ($c->getSystemConfig()->getValue('debug', false)) { |
|
580 | - return new QueryLogger(); |
|
581 | - } else { |
|
582 | - return new NullQueryLogger(); |
|
583 | - } |
|
584 | - }); |
|
585 | - $this->registerAlias('QueryLogger', \OCP\Diagnostics\IQueryLogger::class); |
|
586 | - |
|
587 | - $this->registerService(TempManager::class, function (Server $c) { |
|
588 | - return new TempManager( |
|
589 | - $c->getLogger(), |
|
590 | - $c->getConfig() |
|
591 | - ); |
|
592 | - }); |
|
593 | - $this->registerAlias('TempManager', TempManager::class); |
|
594 | - $this->registerAlias(ITempManager::class, TempManager::class); |
|
595 | - |
|
596 | - $this->registerService(AppManager::class, function (Server $c) { |
|
597 | - return new \OC\App\AppManager( |
|
598 | - $c->getUserSession(), |
|
599 | - $c->getAppConfig(), |
|
600 | - $c->getGroupManager(), |
|
601 | - $c->getMemCacheFactory(), |
|
602 | - $c->getEventDispatcher() |
|
603 | - ); |
|
604 | - }); |
|
605 | - $this->registerAlias('AppManager', AppManager::class); |
|
606 | - $this->registerAlias(IAppManager::class, AppManager::class); |
|
607 | - |
|
608 | - $this->registerService(\OCP\IDateTimeZone::class, function (Server $c) { |
|
609 | - return new DateTimeZone( |
|
610 | - $c->getConfig(), |
|
611 | - $c->getSession() |
|
612 | - ); |
|
613 | - }); |
|
614 | - $this->registerAlias('DateTimeZone', \OCP\IDateTimeZone::class); |
|
615 | - |
|
616 | - $this->registerService(\OCP\IDateTimeFormatter::class, function (Server $c) { |
|
617 | - $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null); |
|
618 | - |
|
619 | - return new DateTimeFormatter( |
|
620 | - $c->getDateTimeZone()->getTimeZone(), |
|
621 | - $c->getL10N('lib', $language) |
|
622 | - ); |
|
623 | - }); |
|
624 | - $this->registerAlias('DateTimeFormatter', \OCP\IDateTimeFormatter::class); |
|
625 | - |
|
626 | - $this->registerService(\OCP\Files\Config\IUserMountCache::class, function (Server $c) { |
|
627 | - $mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger()); |
|
628 | - $listener = new UserMountCacheListener($mountCache); |
|
629 | - $listener->listen($c->getUserManager()); |
|
630 | - return $mountCache; |
|
631 | - }); |
|
632 | - $this->registerAlias('UserMountCache', \OCP\Files\Config\IUserMountCache::class); |
|
633 | - |
|
634 | - $this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function (Server $c) { |
|
635 | - $loader = \OC\Files\Filesystem::getLoader(); |
|
636 | - $mountCache = $c->query('UserMountCache'); |
|
637 | - $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache); |
|
638 | - |
|
639 | - // builtin providers |
|
640 | - |
|
641 | - $config = $c->getConfig(); |
|
642 | - $manager->registerProvider(new CacheMountProvider($config)); |
|
643 | - $manager->registerHomeProvider(new LocalHomeMountProvider()); |
|
644 | - $manager->registerHomeProvider(new ObjectHomeMountProvider($config)); |
|
645 | - |
|
646 | - return $manager; |
|
647 | - }); |
|
648 | - $this->registerAlias('MountConfigManager', \OCP\Files\Config\IMountProviderCollection::class); |
|
649 | - |
|
650 | - $this->registerService('IniWrapper', function ($c) { |
|
651 | - return new IniGetWrapper(); |
|
652 | - }); |
|
653 | - $this->registerService('AsyncCommandBus', function (Server $c) { |
|
654 | - $jobList = $c->getJobList(); |
|
655 | - return new AsyncBus($jobList); |
|
656 | - }); |
|
657 | - $this->registerService('TrustedDomainHelper', function ($c) { |
|
658 | - return new TrustedDomainHelper($this->getConfig()); |
|
659 | - }); |
|
660 | - $this->registerService('Throttler', function(Server $c) { |
|
661 | - return new Throttler( |
|
662 | - $c->getDatabaseConnection(), |
|
663 | - new TimeFactory(), |
|
664 | - $c->getLogger(), |
|
665 | - $c->getConfig() |
|
666 | - ); |
|
667 | - }); |
|
668 | - $this->registerService('IntegrityCodeChecker', function (Server $c) { |
|
669 | - // IConfig and IAppManager requires a working database. This code |
|
670 | - // might however be called when ownCloud is not yet setup. |
|
671 | - if(\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
672 | - $config = $c->getConfig(); |
|
673 | - $appManager = $c->getAppManager(); |
|
674 | - } else { |
|
675 | - $config = null; |
|
676 | - $appManager = null; |
|
677 | - } |
|
678 | - |
|
679 | - return new Checker( |
|
680 | - new EnvironmentHelper(), |
|
681 | - new FileAccessHelper(), |
|
682 | - new AppLocator(), |
|
683 | - $config, |
|
684 | - $c->getMemCacheFactory(), |
|
685 | - $appManager, |
|
686 | - $c->getTempManager() |
|
687 | - ); |
|
688 | - }); |
|
689 | - $this->registerService(\OCP\IRequest::class, function ($c) { |
|
690 | - if (isset($this['urlParams'])) { |
|
691 | - $urlParams = $this['urlParams']; |
|
692 | - } else { |
|
693 | - $urlParams = []; |
|
694 | - } |
|
695 | - |
|
696 | - if (defined('PHPUNIT_RUN') && PHPUNIT_RUN |
|
697 | - && in_array('fakeinput', stream_get_wrappers()) |
|
698 | - ) { |
|
699 | - $stream = 'fakeinput://data'; |
|
700 | - } else { |
|
701 | - $stream = 'php://input'; |
|
702 | - } |
|
703 | - |
|
704 | - return new Request( |
|
705 | - [ |
|
706 | - 'get' => $_GET, |
|
707 | - 'post' => $_POST, |
|
708 | - 'files' => $_FILES, |
|
709 | - 'server' => $_SERVER, |
|
710 | - 'env' => $_ENV, |
|
711 | - 'cookies' => $_COOKIE, |
|
712 | - 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
713 | - ? $_SERVER['REQUEST_METHOD'] |
|
714 | - : null, |
|
715 | - 'urlParams' => $urlParams, |
|
716 | - ], |
|
717 | - $this->getSecureRandom(), |
|
718 | - $this->getConfig(), |
|
719 | - $this->getCsrfTokenManager(), |
|
720 | - $stream |
|
721 | - ); |
|
722 | - }); |
|
723 | - $this->registerAlias('Request', \OCP\IRequest::class); |
|
724 | - |
|
725 | - $this->registerService(\OCP\Mail\IMailer::class, function (Server $c) { |
|
726 | - return new Mailer( |
|
727 | - $c->getConfig(), |
|
728 | - $c->getLogger(), |
|
729 | - $c->getThemingDefaults() |
|
730 | - ); |
|
731 | - }); |
|
732 | - $this->registerAlias('Mailer', \OCP\Mail\IMailer::class); |
|
733 | - |
|
734 | - $this->registerService('LDAPProvider', function(Server $c) { |
|
735 | - $config = $c->getConfig(); |
|
736 | - $factoryClass = $config->getSystemValue('ldapProviderFactory', null); |
|
737 | - if(is_null($factoryClass)) { |
|
738 | - throw new \Exception('ldapProviderFactory not set'); |
|
739 | - } |
|
740 | - /** @var \OCP\LDAP\ILDAPProviderFactory $factory */ |
|
741 | - $factory = new $factoryClass($this); |
|
742 | - return $factory->getLDAPProvider(); |
|
743 | - }); |
|
744 | - $this->registerService('LockingProvider', function (Server $c) { |
|
745 | - $ini = $c->getIniWrapper(); |
|
746 | - $config = $c->getConfig(); |
|
747 | - $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time'))); |
|
748 | - if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
749 | - /** @var \OC\Memcache\Factory $memcacheFactory */ |
|
750 | - $memcacheFactory = $c->getMemCacheFactory(); |
|
751 | - $memcache = $memcacheFactory->createLocking('lock'); |
|
752 | - if (!($memcache instanceof \OC\Memcache\NullCache)) { |
|
753 | - return new MemcacheLockingProvider($memcache, $ttl); |
|
754 | - } |
|
755 | - return new DBLockingProvider($c->getDatabaseConnection(), $c->getLogger(), new TimeFactory(), $ttl); |
|
756 | - } |
|
757 | - return new NoopLockingProvider(); |
|
758 | - }); |
|
759 | - |
|
760 | - $this->registerService(\OCP\Files\Mount\IMountManager::class, function () { |
|
761 | - return new \OC\Files\Mount\Manager(); |
|
762 | - }); |
|
763 | - $this->registerAlias('MountManager', \OCP\Files\Mount\IMountManager::class); |
|
764 | - |
|
765 | - $this->registerService(\OCP\Files\IMimeTypeDetector::class, function (Server $c) { |
|
766 | - return new \OC\Files\Type\Detection( |
|
767 | - $c->getURLGenerator(), |
|
768 | - \OC::$configDir, |
|
769 | - \OC::$SERVERROOT . '/resources/config/' |
|
770 | - ); |
|
771 | - }); |
|
772 | - $this->registerAlias('MimeTypeDetector', \OCP\Files\IMimeTypeDetector::class); |
|
773 | - |
|
774 | - $this->registerService(\OCP\Files\IMimeTypeLoader::class, function (Server $c) { |
|
775 | - return new \OC\Files\Type\Loader( |
|
776 | - $c->getDatabaseConnection() |
|
777 | - ); |
|
778 | - }); |
|
779 | - $this->registerAlias('MimeTypeLoader', \OCP\Files\IMimeTypeLoader::class); |
|
780 | - |
|
781 | - $this->registerService(\OCP\Notification\IManager::class, function (Server $c) { |
|
782 | - return new Manager( |
|
783 | - $c->query(IValidator::class) |
|
784 | - ); |
|
785 | - }); |
|
786 | - $this->registerAlias('NotificationManager', \OCP\Notification\IManager::class); |
|
787 | - |
|
788 | - $this->registerService(\OC\CapabilitiesManager::class, function (Server $c) { |
|
789 | - $manager = new \OC\CapabilitiesManager($c->getLogger()); |
|
790 | - $manager->registerCapability(function () use ($c) { |
|
791 | - return new \OC\OCS\CoreCapabilities($c->getConfig()); |
|
792 | - }); |
|
793 | - return $manager; |
|
794 | - }); |
|
795 | - $this->registerAlias('CapabilitiesManager', \OC\CapabilitiesManager::class); |
|
796 | - |
|
797 | - $this->registerService(\OCP\Comments\ICommentsManager::class, function(Server $c) { |
|
798 | - $config = $c->getConfig(); |
|
799 | - $factoryClass = $config->getSystemValue('comments.managerFactory', '\OC\Comments\ManagerFactory'); |
|
800 | - /** @var \OCP\Comments\ICommentsManagerFactory $factory */ |
|
801 | - $factory = new $factoryClass($this); |
|
802 | - return $factory->getManager(); |
|
803 | - }); |
|
804 | - $this->registerAlias('CommentsManager', \OCP\Comments\ICommentsManager::class); |
|
805 | - |
|
806 | - $this->registerService('ThemingDefaults', function(Server $c) { |
|
807 | - /* |
|
118 | + /** @var string */ |
|
119 | + private $webRoot; |
|
120 | + |
|
121 | + /** |
|
122 | + * @param string $webRoot |
|
123 | + * @param \OC\Config $config |
|
124 | + */ |
|
125 | + public function __construct($webRoot, \OC\Config $config) { |
|
126 | + parent::__construct(); |
|
127 | + $this->webRoot = $webRoot; |
|
128 | + |
|
129 | + $this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class); |
|
130 | + $this->registerAlias('ContactsManager', \OCP\Contacts\IManager::class); |
|
131 | + |
|
132 | + $this->registerService(\OCP\IPreview::class, function (Server $c) { |
|
133 | + return new PreviewManager( |
|
134 | + $c->getConfig(), |
|
135 | + $c->getRootFolder(), |
|
136 | + $c->getAppDataDir('preview'), |
|
137 | + $c->getEventDispatcher(), |
|
138 | + $c->getSession()->get('user_id') |
|
139 | + ); |
|
140 | + }); |
|
141 | + $this->registerAlias('PreviewManager', \OCP\IPreview::class); |
|
142 | + |
|
143 | + $this->registerService(\OC\Preview\Watcher::class, function (Server $c) { |
|
144 | + return new \OC\Preview\Watcher( |
|
145 | + $c->getAppDataDir('preview') |
|
146 | + ); |
|
147 | + }); |
|
148 | + |
|
149 | + $this->registerService('EncryptionManager', function (Server $c) { |
|
150 | + $view = new View(); |
|
151 | + $util = new Encryption\Util( |
|
152 | + $view, |
|
153 | + $c->getUserManager(), |
|
154 | + $c->getGroupManager(), |
|
155 | + $c->getConfig() |
|
156 | + ); |
|
157 | + return new Encryption\Manager( |
|
158 | + $c->getConfig(), |
|
159 | + $c->getLogger(), |
|
160 | + $c->getL10N('core'), |
|
161 | + new View(), |
|
162 | + $util, |
|
163 | + new ArrayCache() |
|
164 | + ); |
|
165 | + }); |
|
166 | + |
|
167 | + $this->registerService('EncryptionFileHelper', function (Server $c) { |
|
168 | + $util = new Encryption\Util( |
|
169 | + new View(), |
|
170 | + $c->getUserManager(), |
|
171 | + $c->getGroupManager(), |
|
172 | + $c->getConfig() |
|
173 | + ); |
|
174 | + return new Encryption\File($util); |
|
175 | + }); |
|
176 | + |
|
177 | + $this->registerService('EncryptionKeyStorage', function (Server $c) { |
|
178 | + $view = new View(); |
|
179 | + $util = new Encryption\Util( |
|
180 | + $view, |
|
181 | + $c->getUserManager(), |
|
182 | + $c->getGroupManager(), |
|
183 | + $c->getConfig() |
|
184 | + ); |
|
185 | + |
|
186 | + return new Encryption\Keys\Storage($view, $util); |
|
187 | + }); |
|
188 | + $this->registerService('TagMapper', function (Server $c) { |
|
189 | + return new TagMapper($c->getDatabaseConnection()); |
|
190 | + }); |
|
191 | + |
|
192 | + $this->registerService(\OCP\ITagManager::class, function (Server $c) { |
|
193 | + $tagMapper = $c->query('TagMapper'); |
|
194 | + return new TagManager($tagMapper, $c->getUserSession()); |
|
195 | + }); |
|
196 | + $this->registerAlias('TagManager', \OCP\ITagManager::class); |
|
197 | + |
|
198 | + $this->registerService('SystemTagManagerFactory', function (Server $c) { |
|
199 | + $config = $c->getConfig(); |
|
200 | + $factoryClass = $config->getSystemValue('systemtags.managerFactory', '\OC\SystemTag\ManagerFactory'); |
|
201 | + /** @var \OC\SystemTag\ManagerFactory $factory */ |
|
202 | + $factory = new $factoryClass($this); |
|
203 | + return $factory; |
|
204 | + }); |
|
205 | + $this->registerService(\OCP\SystemTag\ISystemTagManager::class, function (Server $c) { |
|
206 | + return $c->query('SystemTagManagerFactory')->getManager(); |
|
207 | + }); |
|
208 | + $this->registerAlias('SystemTagManager', \OCP\SystemTag\ISystemTagManager::class); |
|
209 | + |
|
210 | + $this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function (Server $c) { |
|
211 | + return $c->query('SystemTagManagerFactory')->getObjectMapper(); |
|
212 | + }); |
|
213 | + $this->registerService('RootFolder', function (Server $c) { |
|
214 | + $manager = \OC\Files\Filesystem::getMountManager(null); |
|
215 | + $view = new View(); |
|
216 | + $root = new Root( |
|
217 | + $manager, |
|
218 | + $view, |
|
219 | + null, |
|
220 | + $c->getUserMountCache(), |
|
221 | + $this->getLogger(), |
|
222 | + $this->getUserManager() |
|
223 | + ); |
|
224 | + $connector = new HookConnector($root, $view); |
|
225 | + $connector->viewToNode(); |
|
226 | + |
|
227 | + $previewConnector = new \OC\Preview\WatcherConnector($root, $c->getSystemConfig()); |
|
228 | + $previewConnector->connectWatcher(); |
|
229 | + |
|
230 | + return $root; |
|
231 | + }); |
|
232 | + $this->registerAlias('SystemTagObjectMapper', \OCP\SystemTag\ISystemTagObjectMapper::class); |
|
233 | + |
|
234 | + $this->registerService(\OCP\Files\IRootFolder::class, function(Server $c) { |
|
235 | + return new LazyRoot(function() use ($c) { |
|
236 | + return $c->query('RootFolder'); |
|
237 | + }); |
|
238 | + }); |
|
239 | + $this->registerAlias('LazyRootFolder', \OCP\Files\IRootFolder::class); |
|
240 | + |
|
241 | + $this->registerService(\OCP\IUserManager::class, function (Server $c) { |
|
242 | + $config = $c->getConfig(); |
|
243 | + return new \OC\User\Manager($config); |
|
244 | + }); |
|
245 | + $this->registerAlias('UserManager', \OCP\IUserManager::class); |
|
246 | + |
|
247 | + $this->registerService(\OCP\IGroupManager::class, function (Server $c) { |
|
248 | + $groupManager = new \OC\Group\Manager($this->getUserManager(), $this->getLogger()); |
|
249 | + $groupManager->listen('\OC\Group', 'preCreate', function ($gid) { |
|
250 | + \OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid)); |
|
251 | + }); |
|
252 | + $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) { |
|
253 | + \OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID())); |
|
254 | + }); |
|
255 | + $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) { |
|
256 | + \OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID())); |
|
257 | + }); |
|
258 | + $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) { |
|
259 | + \OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID())); |
|
260 | + }); |
|
261 | + $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
262 | + \OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
263 | + }); |
|
264 | + $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
265 | + \OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
266 | + //Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks |
|
267 | + \OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
268 | + }); |
|
269 | + return $groupManager; |
|
270 | + }); |
|
271 | + $this->registerAlias('GroupManager', \OCP\IGroupManager::class); |
|
272 | + |
|
273 | + $this->registerService(Store::class, function(Server $c) { |
|
274 | + $session = $c->getSession(); |
|
275 | + if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
276 | + $tokenProvider = $c->query('OC\Authentication\Token\IProvider'); |
|
277 | + } else { |
|
278 | + $tokenProvider = null; |
|
279 | + } |
|
280 | + $logger = $c->getLogger(); |
|
281 | + return new Store($session, $logger, $tokenProvider); |
|
282 | + }); |
|
283 | + $this->registerAlias(IStore::class, Store::class); |
|
284 | + $this->registerService('OC\Authentication\Token\DefaultTokenMapper', function (Server $c) { |
|
285 | + $dbConnection = $c->getDatabaseConnection(); |
|
286 | + return new Authentication\Token\DefaultTokenMapper($dbConnection); |
|
287 | + }); |
|
288 | + $this->registerService('OC\Authentication\Token\DefaultTokenProvider', function (Server $c) { |
|
289 | + $mapper = $c->query('OC\Authentication\Token\DefaultTokenMapper'); |
|
290 | + $crypto = $c->getCrypto(); |
|
291 | + $config = $c->getConfig(); |
|
292 | + $logger = $c->getLogger(); |
|
293 | + $timeFactory = new TimeFactory(); |
|
294 | + return new \OC\Authentication\Token\DefaultTokenProvider($mapper, $crypto, $config, $logger, $timeFactory); |
|
295 | + }); |
|
296 | + $this->registerAlias('OC\Authentication\Token\IProvider', 'OC\Authentication\Token\DefaultTokenProvider'); |
|
297 | + |
|
298 | + $this->registerService(\OCP\IUserSession::class, function (Server $c) { |
|
299 | + $manager = $c->getUserManager(); |
|
300 | + $session = new \OC\Session\Memory(''); |
|
301 | + $timeFactory = new TimeFactory(); |
|
302 | + // Token providers might require a working database. This code |
|
303 | + // might however be called when ownCloud is not yet setup. |
|
304 | + if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
305 | + $defaultTokenProvider = $c->query('OC\Authentication\Token\IProvider'); |
|
306 | + } else { |
|
307 | + $defaultTokenProvider = null; |
|
308 | + } |
|
309 | + |
|
310 | + $userSession = new \OC\User\Session($manager, $session, $timeFactory, $defaultTokenProvider, $c->getConfig(), $c->getSecureRandom(), $c->getLockdownManager()); |
|
311 | + $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { |
|
312 | + \OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password)); |
|
313 | + }); |
|
314 | + $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) { |
|
315 | + /** @var $user \OC\User\User */ |
|
316 | + \OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password)); |
|
317 | + }); |
|
318 | + $userSession->listen('\OC\User', 'preDelete', function ($user) { |
|
319 | + /** @var $user \OC\User\User */ |
|
320 | + \OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID())); |
|
321 | + }); |
|
322 | + $userSession->listen('\OC\User', 'postDelete', function ($user) { |
|
323 | + /** @var $user \OC\User\User */ |
|
324 | + \OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID())); |
|
325 | + }); |
|
326 | + $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { |
|
327 | + /** @var $user \OC\User\User */ |
|
328 | + \OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
|
329 | + }); |
|
330 | + $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) { |
|
331 | + /** @var $user \OC\User\User */ |
|
332 | + \OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
|
333 | + }); |
|
334 | + $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) { |
|
335 | + \OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password)); |
|
336 | + }); |
|
337 | + $userSession->listen('\OC\User', 'postLogin', function ($user, $password) { |
|
338 | + /** @var $user \OC\User\User */ |
|
339 | + \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); |
|
340 | + }); |
|
341 | + $userSession->listen('\OC\User', 'logout', function () { |
|
342 | + \OC_Hook::emit('OC_User', 'logout', array()); |
|
343 | + }); |
|
344 | + $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value) { |
|
345 | + /** @var $user \OC\User\User */ |
|
346 | + \OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value)); |
|
347 | + }); |
|
348 | + return $userSession; |
|
349 | + }); |
|
350 | + $this->registerAlias('UserSession', \OCP\IUserSession::class); |
|
351 | + |
|
352 | + $this->registerService(\OC\Authentication\TwoFactorAuth\Manager::class, function (Server $c) { |
|
353 | + return new \OC\Authentication\TwoFactorAuth\Manager($c->getAppManager(), $c->getSession(), $c->getConfig(), $c->getActivityManager(), $c->getLogger()); |
|
354 | + }); |
|
355 | + |
|
356 | + $this->registerAlias(\OCP\INavigationManager::class, \OC\NavigationManager::class); |
|
357 | + $this->registerAlias('NavigationManager', \OCP\INavigationManager::class); |
|
358 | + |
|
359 | + $this->registerService(\OC\AllConfig::class, function (Server $c) { |
|
360 | + return new \OC\AllConfig( |
|
361 | + $c->getSystemConfig() |
|
362 | + ); |
|
363 | + }); |
|
364 | + $this->registerAlias('AllConfig', \OC\AllConfig::class); |
|
365 | + $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class); |
|
366 | + |
|
367 | + $this->registerService('SystemConfig', function ($c) use ($config) { |
|
368 | + return new \OC\SystemConfig($config); |
|
369 | + }); |
|
370 | + |
|
371 | + $this->registerService(\OC\AppConfig::class, function (Server $c) { |
|
372 | + return new \OC\AppConfig($c->getDatabaseConnection()); |
|
373 | + }); |
|
374 | + $this->registerAlias('AppConfig', \OC\AppConfig::class); |
|
375 | + $this->registerAlias(\OCP\IAppConfig::class, \OC\AppConfig::class); |
|
376 | + |
|
377 | + $this->registerService(\OCP\L10N\IFactory::class, function (Server $c) { |
|
378 | + return new \OC\L10N\Factory( |
|
379 | + $c->getConfig(), |
|
380 | + $c->getRequest(), |
|
381 | + $c->getUserSession(), |
|
382 | + \OC::$SERVERROOT |
|
383 | + ); |
|
384 | + }); |
|
385 | + $this->registerAlias('L10NFactory', \OCP\L10N\IFactory::class); |
|
386 | + |
|
387 | + $this->registerService(\OCP\IURLGenerator::class, function (Server $c) { |
|
388 | + $config = $c->getConfig(); |
|
389 | + $cacheFactory = $c->getMemCacheFactory(); |
|
390 | + return new \OC\URLGenerator( |
|
391 | + $config, |
|
392 | + $cacheFactory |
|
393 | + ); |
|
394 | + }); |
|
395 | + $this->registerAlias('URLGenerator', \OCP\IURLGenerator::class); |
|
396 | + |
|
397 | + $this->registerService('AppHelper', function ($c) { |
|
398 | + return new \OC\AppHelper(); |
|
399 | + }); |
|
400 | + $this->registerService('AppFetcher', function ($c) { |
|
401 | + return new AppFetcher( |
|
402 | + $this->getAppDataDir('appstore'), |
|
403 | + $this->getHTTPClientService(), |
|
404 | + $this->query(TimeFactory::class), |
|
405 | + $this->getConfig() |
|
406 | + ); |
|
407 | + }); |
|
408 | + $this->registerService('CategoryFetcher', function ($c) { |
|
409 | + return new CategoryFetcher( |
|
410 | + $this->getAppDataDir('appstore'), |
|
411 | + $this->getHTTPClientService(), |
|
412 | + $this->query(TimeFactory::class), |
|
413 | + $this->getConfig() |
|
414 | + ); |
|
415 | + }); |
|
416 | + |
|
417 | + $this->registerService(\OCP\ICache::class, function ($c) { |
|
418 | + return new Cache\File(); |
|
419 | + }); |
|
420 | + $this->registerAlias('UserCache', \OCP\ICache::class); |
|
421 | + |
|
422 | + $this->registerService(Factory::class, function (Server $c) { |
|
423 | + $config = $c->getConfig(); |
|
424 | + |
|
425 | + if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
426 | + $v = \OC_App::getAppVersions(); |
|
427 | + $v['core'] = md5(file_get_contents(\OC::$SERVERROOT . '/version.php')); |
|
428 | + $version = implode(',', $v); |
|
429 | + $instanceId = \OC_Util::getInstanceId(); |
|
430 | + $path = \OC::$SERVERROOT; |
|
431 | + $prefix = md5($instanceId . '-' . $version . '-' . $path . '-' . \OC::$WEBROOT); |
|
432 | + return new \OC\Memcache\Factory($prefix, $c->getLogger(), |
|
433 | + $config->getSystemValue('memcache.local', null), |
|
434 | + $config->getSystemValue('memcache.distributed', null), |
|
435 | + $config->getSystemValue('memcache.locking', null) |
|
436 | + ); |
|
437 | + } |
|
438 | + |
|
439 | + return new \OC\Memcache\Factory('', $c->getLogger(), |
|
440 | + '\\OC\\Memcache\\ArrayCache', |
|
441 | + '\\OC\\Memcache\\ArrayCache', |
|
442 | + '\\OC\\Memcache\\ArrayCache' |
|
443 | + ); |
|
444 | + }); |
|
445 | + $this->registerAlias('MemCacheFactory', Factory::class); |
|
446 | + $this->registerAlias(ICacheFactory::class, Factory::class); |
|
447 | + |
|
448 | + $this->registerService('RedisFactory', function (Server $c) { |
|
449 | + $systemConfig = $c->getSystemConfig(); |
|
450 | + return new RedisFactory($systemConfig); |
|
451 | + }); |
|
452 | + |
|
453 | + $this->registerService(\OCP\Activity\IManager::class, function (Server $c) { |
|
454 | + return new \OC\Activity\Manager( |
|
455 | + $c->getRequest(), |
|
456 | + $c->getUserSession(), |
|
457 | + $c->getConfig(), |
|
458 | + $c->query(IValidator::class) |
|
459 | + ); |
|
460 | + }); |
|
461 | + $this->registerAlias('ActivityManager', \OCP\Activity\IManager::class); |
|
462 | + |
|
463 | + $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) { |
|
464 | + return new \OC\Activity\EventMerger( |
|
465 | + $c->getL10N('lib') |
|
466 | + ); |
|
467 | + }); |
|
468 | + $this->registerAlias(IValidator::class, Validator::class); |
|
469 | + |
|
470 | + $this->registerService(\OCP\IAvatarManager::class, function (Server $c) { |
|
471 | + return new AvatarManager( |
|
472 | + $c->getUserManager(), |
|
473 | + $c->getAppDataDir('avatar'), |
|
474 | + $c->getL10N('lib'), |
|
475 | + $c->getLogger(), |
|
476 | + $c->getConfig() |
|
477 | + ); |
|
478 | + }); |
|
479 | + $this->registerAlias('AvatarManager', \OCP\IAvatarManager::class); |
|
480 | + |
|
481 | + $this->registerService(\OCP\ILogger::class, function (Server $c) { |
|
482 | + $logType = $c->query('AllConfig')->getSystemValue('log_type', 'file'); |
|
483 | + $logger = Log::getLogClass($logType); |
|
484 | + call_user_func(array($logger, 'init')); |
|
485 | + |
|
486 | + return new Log($logger); |
|
487 | + }); |
|
488 | + $this->registerAlias('Logger', \OCP\ILogger::class); |
|
489 | + |
|
490 | + $this->registerService(\OCP\BackgroundJob\IJobList::class, function (Server $c) { |
|
491 | + $config = $c->getConfig(); |
|
492 | + return new \OC\BackgroundJob\JobList( |
|
493 | + $c->getDatabaseConnection(), |
|
494 | + $config, |
|
495 | + new TimeFactory() |
|
496 | + ); |
|
497 | + }); |
|
498 | + $this->registerAlias('JobList', \OCP\BackgroundJob\IJobList::class); |
|
499 | + |
|
500 | + $this->registerService(\OCP\Route\IRouter::class, function (Server $c) { |
|
501 | + $cacheFactory = $c->getMemCacheFactory(); |
|
502 | + $logger = $c->getLogger(); |
|
503 | + if ($cacheFactory->isAvailable()) { |
|
504 | + $router = new \OC\Route\CachingRouter($cacheFactory->create('route'), $logger); |
|
505 | + } else { |
|
506 | + $router = new \OC\Route\Router($logger); |
|
507 | + } |
|
508 | + return $router; |
|
509 | + }); |
|
510 | + $this->registerAlias('Router', \OCP\Route\IRouter::class); |
|
511 | + |
|
512 | + $this->registerService(\OCP\ISearch::class, function ($c) { |
|
513 | + return new Search(); |
|
514 | + }); |
|
515 | + $this->registerAlias('Search', \OCP\ISearch::class); |
|
516 | + |
|
517 | + $this->registerService(\OCP\Security\ISecureRandom::class, function ($c) { |
|
518 | + return new SecureRandom(); |
|
519 | + }); |
|
520 | + $this->registerAlias('SecureRandom', \OCP\Security\ISecureRandom::class); |
|
521 | + |
|
522 | + $this->registerService(\OCP\Security\ICrypto::class, function (Server $c) { |
|
523 | + return new Crypto($c->getConfig(), $c->getSecureRandom()); |
|
524 | + }); |
|
525 | + $this->registerAlias('Crypto', \OCP\Security\ICrypto::class); |
|
526 | + |
|
527 | + $this->registerService(\OCP\Security\IHasher::class, function (Server $c) { |
|
528 | + return new Hasher($c->getConfig()); |
|
529 | + }); |
|
530 | + $this->registerAlias('Hasher', \OCP\Security\IHasher::class); |
|
531 | + |
|
532 | + $this->registerService(\OCP\Security\ICredentialsManager::class, function (Server $c) { |
|
533 | + return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection()); |
|
534 | + }); |
|
535 | + $this->registerAlias('CredentialsManager', \OCP\Security\ICredentialsManager::class); |
|
536 | + |
|
537 | + $this->registerService(IDBConnection::class, function (Server $c) { |
|
538 | + $systemConfig = $c->getSystemConfig(); |
|
539 | + $factory = new \OC\DB\ConnectionFactory($systemConfig); |
|
540 | + $type = $systemConfig->getValue('dbtype', 'sqlite'); |
|
541 | + if (!$factory->isValidType($type)) { |
|
542 | + throw new \OC\DatabaseException('Invalid database type'); |
|
543 | + } |
|
544 | + $connectionParams = $factory->createConnectionParams(); |
|
545 | + $connection = $factory->getConnection($type, $connectionParams); |
|
546 | + $connection->getConfiguration()->setSQLLogger($c->getQueryLogger()); |
|
547 | + return $connection; |
|
548 | + }); |
|
549 | + $this->registerAlias('DatabaseConnection', IDBConnection::class); |
|
550 | + |
|
551 | + $this->registerService('HTTPHelper', function (Server $c) { |
|
552 | + $config = $c->getConfig(); |
|
553 | + return new HTTPHelper( |
|
554 | + $config, |
|
555 | + $c->getHTTPClientService() |
|
556 | + ); |
|
557 | + }); |
|
558 | + |
|
559 | + $this->registerService(\OCP\Http\Client\IClientService::class, function (Server $c) { |
|
560 | + $user = \OC_User::getUser(); |
|
561 | + $uid = $user ? $user : null; |
|
562 | + return new ClientService( |
|
563 | + $c->getConfig(), |
|
564 | + new \OC\Security\CertificateManager($uid, new View(), $c->getConfig(), $c->getLogger()) |
|
565 | + ); |
|
566 | + }); |
|
567 | + $this->registerAlias('HttpClientService', \OCP\Http\Client\IClientService::class); |
|
568 | + |
|
569 | + $this->registerService(\OCP\Diagnostics\IEventLogger::class, function (Server $c) { |
|
570 | + if ($c->getSystemConfig()->getValue('debug', false)) { |
|
571 | + return new EventLogger(); |
|
572 | + } else { |
|
573 | + return new NullEventLogger(); |
|
574 | + } |
|
575 | + }); |
|
576 | + $this->registerAlias('EventLogger', \OCP\Diagnostics\IEventLogger::class); |
|
577 | + |
|
578 | + $this->registerService(\OCP\Diagnostics\IQueryLogger::class, function (Server $c) { |
|
579 | + if ($c->getSystemConfig()->getValue('debug', false)) { |
|
580 | + return new QueryLogger(); |
|
581 | + } else { |
|
582 | + return new NullQueryLogger(); |
|
583 | + } |
|
584 | + }); |
|
585 | + $this->registerAlias('QueryLogger', \OCP\Diagnostics\IQueryLogger::class); |
|
586 | + |
|
587 | + $this->registerService(TempManager::class, function (Server $c) { |
|
588 | + return new TempManager( |
|
589 | + $c->getLogger(), |
|
590 | + $c->getConfig() |
|
591 | + ); |
|
592 | + }); |
|
593 | + $this->registerAlias('TempManager', TempManager::class); |
|
594 | + $this->registerAlias(ITempManager::class, TempManager::class); |
|
595 | + |
|
596 | + $this->registerService(AppManager::class, function (Server $c) { |
|
597 | + return new \OC\App\AppManager( |
|
598 | + $c->getUserSession(), |
|
599 | + $c->getAppConfig(), |
|
600 | + $c->getGroupManager(), |
|
601 | + $c->getMemCacheFactory(), |
|
602 | + $c->getEventDispatcher() |
|
603 | + ); |
|
604 | + }); |
|
605 | + $this->registerAlias('AppManager', AppManager::class); |
|
606 | + $this->registerAlias(IAppManager::class, AppManager::class); |
|
607 | + |
|
608 | + $this->registerService(\OCP\IDateTimeZone::class, function (Server $c) { |
|
609 | + return new DateTimeZone( |
|
610 | + $c->getConfig(), |
|
611 | + $c->getSession() |
|
612 | + ); |
|
613 | + }); |
|
614 | + $this->registerAlias('DateTimeZone', \OCP\IDateTimeZone::class); |
|
615 | + |
|
616 | + $this->registerService(\OCP\IDateTimeFormatter::class, function (Server $c) { |
|
617 | + $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null); |
|
618 | + |
|
619 | + return new DateTimeFormatter( |
|
620 | + $c->getDateTimeZone()->getTimeZone(), |
|
621 | + $c->getL10N('lib', $language) |
|
622 | + ); |
|
623 | + }); |
|
624 | + $this->registerAlias('DateTimeFormatter', \OCP\IDateTimeFormatter::class); |
|
625 | + |
|
626 | + $this->registerService(\OCP\Files\Config\IUserMountCache::class, function (Server $c) { |
|
627 | + $mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger()); |
|
628 | + $listener = new UserMountCacheListener($mountCache); |
|
629 | + $listener->listen($c->getUserManager()); |
|
630 | + return $mountCache; |
|
631 | + }); |
|
632 | + $this->registerAlias('UserMountCache', \OCP\Files\Config\IUserMountCache::class); |
|
633 | + |
|
634 | + $this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function (Server $c) { |
|
635 | + $loader = \OC\Files\Filesystem::getLoader(); |
|
636 | + $mountCache = $c->query('UserMountCache'); |
|
637 | + $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache); |
|
638 | + |
|
639 | + // builtin providers |
|
640 | + |
|
641 | + $config = $c->getConfig(); |
|
642 | + $manager->registerProvider(new CacheMountProvider($config)); |
|
643 | + $manager->registerHomeProvider(new LocalHomeMountProvider()); |
|
644 | + $manager->registerHomeProvider(new ObjectHomeMountProvider($config)); |
|
645 | + |
|
646 | + return $manager; |
|
647 | + }); |
|
648 | + $this->registerAlias('MountConfigManager', \OCP\Files\Config\IMountProviderCollection::class); |
|
649 | + |
|
650 | + $this->registerService('IniWrapper', function ($c) { |
|
651 | + return new IniGetWrapper(); |
|
652 | + }); |
|
653 | + $this->registerService('AsyncCommandBus', function (Server $c) { |
|
654 | + $jobList = $c->getJobList(); |
|
655 | + return new AsyncBus($jobList); |
|
656 | + }); |
|
657 | + $this->registerService('TrustedDomainHelper', function ($c) { |
|
658 | + return new TrustedDomainHelper($this->getConfig()); |
|
659 | + }); |
|
660 | + $this->registerService('Throttler', function(Server $c) { |
|
661 | + return new Throttler( |
|
662 | + $c->getDatabaseConnection(), |
|
663 | + new TimeFactory(), |
|
664 | + $c->getLogger(), |
|
665 | + $c->getConfig() |
|
666 | + ); |
|
667 | + }); |
|
668 | + $this->registerService('IntegrityCodeChecker', function (Server $c) { |
|
669 | + // IConfig and IAppManager requires a working database. This code |
|
670 | + // might however be called when ownCloud is not yet setup. |
|
671 | + if(\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
672 | + $config = $c->getConfig(); |
|
673 | + $appManager = $c->getAppManager(); |
|
674 | + } else { |
|
675 | + $config = null; |
|
676 | + $appManager = null; |
|
677 | + } |
|
678 | + |
|
679 | + return new Checker( |
|
680 | + new EnvironmentHelper(), |
|
681 | + new FileAccessHelper(), |
|
682 | + new AppLocator(), |
|
683 | + $config, |
|
684 | + $c->getMemCacheFactory(), |
|
685 | + $appManager, |
|
686 | + $c->getTempManager() |
|
687 | + ); |
|
688 | + }); |
|
689 | + $this->registerService(\OCP\IRequest::class, function ($c) { |
|
690 | + if (isset($this['urlParams'])) { |
|
691 | + $urlParams = $this['urlParams']; |
|
692 | + } else { |
|
693 | + $urlParams = []; |
|
694 | + } |
|
695 | + |
|
696 | + if (defined('PHPUNIT_RUN') && PHPUNIT_RUN |
|
697 | + && in_array('fakeinput', stream_get_wrappers()) |
|
698 | + ) { |
|
699 | + $stream = 'fakeinput://data'; |
|
700 | + } else { |
|
701 | + $stream = 'php://input'; |
|
702 | + } |
|
703 | + |
|
704 | + return new Request( |
|
705 | + [ |
|
706 | + 'get' => $_GET, |
|
707 | + 'post' => $_POST, |
|
708 | + 'files' => $_FILES, |
|
709 | + 'server' => $_SERVER, |
|
710 | + 'env' => $_ENV, |
|
711 | + 'cookies' => $_COOKIE, |
|
712 | + 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
713 | + ? $_SERVER['REQUEST_METHOD'] |
|
714 | + : null, |
|
715 | + 'urlParams' => $urlParams, |
|
716 | + ], |
|
717 | + $this->getSecureRandom(), |
|
718 | + $this->getConfig(), |
|
719 | + $this->getCsrfTokenManager(), |
|
720 | + $stream |
|
721 | + ); |
|
722 | + }); |
|
723 | + $this->registerAlias('Request', \OCP\IRequest::class); |
|
724 | + |
|
725 | + $this->registerService(\OCP\Mail\IMailer::class, function (Server $c) { |
|
726 | + return new Mailer( |
|
727 | + $c->getConfig(), |
|
728 | + $c->getLogger(), |
|
729 | + $c->getThemingDefaults() |
|
730 | + ); |
|
731 | + }); |
|
732 | + $this->registerAlias('Mailer', \OCP\Mail\IMailer::class); |
|
733 | + |
|
734 | + $this->registerService('LDAPProvider', function(Server $c) { |
|
735 | + $config = $c->getConfig(); |
|
736 | + $factoryClass = $config->getSystemValue('ldapProviderFactory', null); |
|
737 | + if(is_null($factoryClass)) { |
|
738 | + throw new \Exception('ldapProviderFactory not set'); |
|
739 | + } |
|
740 | + /** @var \OCP\LDAP\ILDAPProviderFactory $factory */ |
|
741 | + $factory = new $factoryClass($this); |
|
742 | + return $factory->getLDAPProvider(); |
|
743 | + }); |
|
744 | + $this->registerService('LockingProvider', function (Server $c) { |
|
745 | + $ini = $c->getIniWrapper(); |
|
746 | + $config = $c->getConfig(); |
|
747 | + $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time'))); |
|
748 | + if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
749 | + /** @var \OC\Memcache\Factory $memcacheFactory */ |
|
750 | + $memcacheFactory = $c->getMemCacheFactory(); |
|
751 | + $memcache = $memcacheFactory->createLocking('lock'); |
|
752 | + if (!($memcache instanceof \OC\Memcache\NullCache)) { |
|
753 | + return new MemcacheLockingProvider($memcache, $ttl); |
|
754 | + } |
|
755 | + return new DBLockingProvider($c->getDatabaseConnection(), $c->getLogger(), new TimeFactory(), $ttl); |
|
756 | + } |
|
757 | + return new NoopLockingProvider(); |
|
758 | + }); |
|
759 | + |
|
760 | + $this->registerService(\OCP\Files\Mount\IMountManager::class, function () { |
|
761 | + return new \OC\Files\Mount\Manager(); |
|
762 | + }); |
|
763 | + $this->registerAlias('MountManager', \OCP\Files\Mount\IMountManager::class); |
|
764 | + |
|
765 | + $this->registerService(\OCP\Files\IMimeTypeDetector::class, function (Server $c) { |
|
766 | + return new \OC\Files\Type\Detection( |
|
767 | + $c->getURLGenerator(), |
|
768 | + \OC::$configDir, |
|
769 | + \OC::$SERVERROOT . '/resources/config/' |
|
770 | + ); |
|
771 | + }); |
|
772 | + $this->registerAlias('MimeTypeDetector', \OCP\Files\IMimeTypeDetector::class); |
|
773 | + |
|
774 | + $this->registerService(\OCP\Files\IMimeTypeLoader::class, function (Server $c) { |
|
775 | + return new \OC\Files\Type\Loader( |
|
776 | + $c->getDatabaseConnection() |
|
777 | + ); |
|
778 | + }); |
|
779 | + $this->registerAlias('MimeTypeLoader', \OCP\Files\IMimeTypeLoader::class); |
|
780 | + |
|
781 | + $this->registerService(\OCP\Notification\IManager::class, function (Server $c) { |
|
782 | + return new Manager( |
|
783 | + $c->query(IValidator::class) |
|
784 | + ); |
|
785 | + }); |
|
786 | + $this->registerAlias('NotificationManager', \OCP\Notification\IManager::class); |
|
787 | + |
|
788 | + $this->registerService(\OC\CapabilitiesManager::class, function (Server $c) { |
|
789 | + $manager = new \OC\CapabilitiesManager($c->getLogger()); |
|
790 | + $manager->registerCapability(function () use ($c) { |
|
791 | + return new \OC\OCS\CoreCapabilities($c->getConfig()); |
|
792 | + }); |
|
793 | + return $manager; |
|
794 | + }); |
|
795 | + $this->registerAlias('CapabilitiesManager', \OC\CapabilitiesManager::class); |
|
796 | + |
|
797 | + $this->registerService(\OCP\Comments\ICommentsManager::class, function(Server $c) { |
|
798 | + $config = $c->getConfig(); |
|
799 | + $factoryClass = $config->getSystemValue('comments.managerFactory', '\OC\Comments\ManagerFactory'); |
|
800 | + /** @var \OCP\Comments\ICommentsManagerFactory $factory */ |
|
801 | + $factory = new $factoryClass($this); |
|
802 | + return $factory->getManager(); |
|
803 | + }); |
|
804 | + $this->registerAlias('CommentsManager', \OCP\Comments\ICommentsManager::class); |
|
805 | + |
|
806 | + $this->registerService('ThemingDefaults', function(Server $c) { |
|
807 | + /* |
|
808 | 808 | * Dark magic for autoloader. |
809 | 809 | * If we do a class_exists it will try to load the class which will |
810 | 810 | * make composer cache the result. Resulting in errors when enabling |
811 | 811 | * the theming app. |
812 | 812 | */ |
813 | - $prefixes = \OC::$composerAutoloader->getPrefixesPsr4(); |
|
814 | - if (isset($prefixes['OCA\\Theming\\'])) { |
|
815 | - $classExists = true; |
|
816 | - } else { |
|
817 | - $classExists = false; |
|
818 | - } |
|
819 | - |
|
820 | - if ($classExists && $c->getConfig()->getSystemValue('installed', false) && $c->getAppManager()->isInstalled('theming')) { |
|
821 | - return new ThemingDefaults( |
|
822 | - $c->getConfig(), |
|
823 | - $c->getL10N('theming'), |
|
824 | - $c->getURLGenerator(), |
|
825 | - new \OC_Defaults(), |
|
826 | - $c->getAppDataDir('theming'), |
|
827 | - $c->getMemCacheFactory() |
|
828 | - ); |
|
829 | - } |
|
830 | - return new \OC_Defaults(); |
|
831 | - }); |
|
832 | - $this->registerService(EventDispatcher::class, function () { |
|
833 | - return new EventDispatcher(); |
|
834 | - }); |
|
835 | - $this->registerAlias('EventDispatcher', EventDispatcher::class); |
|
836 | - $this->registerAlias(EventDispatcherInterface::class, EventDispatcher::class); |
|
837 | - |
|
838 | - $this->registerService('CryptoWrapper', function (Server $c) { |
|
839 | - // FIXME: Instantiiated here due to cyclic dependency |
|
840 | - $request = new Request( |
|
841 | - [ |
|
842 | - 'get' => $_GET, |
|
843 | - 'post' => $_POST, |
|
844 | - 'files' => $_FILES, |
|
845 | - 'server' => $_SERVER, |
|
846 | - 'env' => $_ENV, |
|
847 | - 'cookies' => $_COOKIE, |
|
848 | - 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
849 | - ? $_SERVER['REQUEST_METHOD'] |
|
850 | - : null, |
|
851 | - ], |
|
852 | - $c->getSecureRandom(), |
|
853 | - $c->getConfig() |
|
854 | - ); |
|
855 | - |
|
856 | - return new CryptoWrapper( |
|
857 | - $c->getConfig(), |
|
858 | - $c->getCrypto(), |
|
859 | - $c->getSecureRandom(), |
|
860 | - $request |
|
861 | - ); |
|
862 | - }); |
|
863 | - $this->registerService('CsrfTokenManager', function (Server $c) { |
|
864 | - $tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom()); |
|
865 | - |
|
866 | - return new CsrfTokenManager( |
|
867 | - $tokenGenerator, |
|
868 | - $c->query(SessionStorage::class) |
|
869 | - ); |
|
870 | - }); |
|
871 | - $this->registerService(SessionStorage::class, function (Server $c) { |
|
872 | - return new SessionStorage($c->getSession()); |
|
873 | - }); |
|
874 | - $this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function (Server $c) { |
|
875 | - return new ContentSecurityPolicyManager(); |
|
876 | - }); |
|
877 | - $this->registerAlias('ContentSecurityPolicyManager', \OCP\Security\IContentSecurityPolicyManager::class); |
|
878 | - |
|
879 | - $this->registerService('ContentSecurityPolicyNonceManager', function(Server $c) { |
|
880 | - return new ContentSecurityPolicyNonceManager( |
|
881 | - $c->getCsrfTokenManager(), |
|
882 | - $c->getRequest() |
|
883 | - ); |
|
884 | - }); |
|
885 | - |
|
886 | - $this->registerService(\OCP\Share\IManager::class, function(Server $c) { |
|
887 | - $config = $c->getConfig(); |
|
888 | - $factoryClass = $config->getSystemValue('sharing.managerFactory', '\OC\Share20\ProviderFactory'); |
|
889 | - /** @var \OCP\Share\IProviderFactory $factory */ |
|
890 | - $factory = new $factoryClass($this); |
|
891 | - |
|
892 | - $manager = new \OC\Share20\Manager( |
|
893 | - $c->getLogger(), |
|
894 | - $c->getConfig(), |
|
895 | - $c->getSecureRandom(), |
|
896 | - $c->getHasher(), |
|
897 | - $c->getMountManager(), |
|
898 | - $c->getGroupManager(), |
|
899 | - $c->getL10N('core'), |
|
900 | - $factory, |
|
901 | - $c->getUserManager(), |
|
902 | - $c->getLazyRootFolder(), |
|
903 | - $c->getEventDispatcher() |
|
904 | - ); |
|
905 | - |
|
906 | - return $manager; |
|
907 | - }); |
|
908 | - $this->registerAlias('ShareManager', \OCP\Share\IManager::class); |
|
909 | - |
|
910 | - $this->registerService('SettingsManager', function(Server $c) { |
|
911 | - $manager = new \OC\Settings\Manager( |
|
912 | - $c->getLogger(), |
|
913 | - $c->getDatabaseConnection(), |
|
914 | - $c->getL10N('lib'), |
|
915 | - $c->getConfig(), |
|
916 | - $c->getEncryptionManager(), |
|
917 | - $c->getUserManager(), |
|
918 | - $c->getLockingProvider(), |
|
919 | - $c->getRequest(), |
|
920 | - new \OC\Settings\Mapper($c->getDatabaseConnection()), |
|
921 | - $c->getURLGenerator() |
|
922 | - ); |
|
923 | - return $manager; |
|
924 | - }); |
|
925 | - $this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) { |
|
926 | - return new \OC\Files\AppData\Factory( |
|
927 | - $c->getRootFolder(), |
|
928 | - $c->getSystemConfig() |
|
929 | - ); |
|
930 | - }); |
|
931 | - |
|
932 | - $this->registerService('LockdownManager', function (Server $c) { |
|
933 | - return new LockdownManager(function() use ($c) { |
|
934 | - return $c->getSession(); |
|
935 | - }); |
|
936 | - }); |
|
937 | - |
|
938 | - $this->registerService(ICloudIdManager::class, function (Server $c) { |
|
939 | - return new CloudIdManager(); |
|
940 | - }); |
|
941 | - |
|
942 | - /* To trick DI since we don't extend the DIContainer here */ |
|
943 | - $this->registerService(CleanPreviewsBackgroundJob::class, function (Server $c) { |
|
944 | - return new CleanPreviewsBackgroundJob( |
|
945 | - $c->getRootFolder(), |
|
946 | - $c->getLogger(), |
|
947 | - $c->getJobList(), |
|
948 | - new TimeFactory() |
|
949 | - ); |
|
950 | - }); |
|
951 | - |
|
952 | - $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class); |
|
953 | - $this->registerAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class); |
|
954 | - |
|
955 | - $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class); |
|
956 | - $this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class); |
|
957 | - |
|
958 | - $this->registerService(\OCP\ISession::class, function(SimpleContainer $c) { |
|
959 | - return $c->query(\OCP\IUserSession::class)->getSession(); |
|
960 | - }); |
|
961 | - } |
|
962 | - |
|
963 | - /** |
|
964 | - * @return \OCP\Contacts\IManager |
|
965 | - */ |
|
966 | - public function getContactsManager() { |
|
967 | - return $this->query('ContactsManager'); |
|
968 | - } |
|
969 | - |
|
970 | - /** |
|
971 | - * @return \OC\Encryption\Manager |
|
972 | - */ |
|
973 | - public function getEncryptionManager() { |
|
974 | - return $this->query('EncryptionManager'); |
|
975 | - } |
|
976 | - |
|
977 | - /** |
|
978 | - * @return \OC\Encryption\File |
|
979 | - */ |
|
980 | - public function getEncryptionFilesHelper() { |
|
981 | - return $this->query('EncryptionFileHelper'); |
|
982 | - } |
|
983 | - |
|
984 | - /** |
|
985 | - * @return \OCP\Encryption\Keys\IStorage |
|
986 | - */ |
|
987 | - public function getEncryptionKeyStorage() { |
|
988 | - return $this->query('EncryptionKeyStorage'); |
|
989 | - } |
|
990 | - |
|
991 | - /** |
|
992 | - * The current request object holding all information about the request |
|
993 | - * currently being processed is returned from this method. |
|
994 | - * In case the current execution was not initiated by a web request null is returned |
|
995 | - * |
|
996 | - * @return \OCP\IRequest |
|
997 | - */ |
|
998 | - public function getRequest() { |
|
999 | - return $this->query('Request'); |
|
1000 | - } |
|
1001 | - |
|
1002 | - /** |
|
1003 | - * Returns the preview manager which can create preview images for a given file |
|
1004 | - * |
|
1005 | - * @return \OCP\IPreview |
|
1006 | - */ |
|
1007 | - public function getPreviewManager() { |
|
1008 | - return $this->query('PreviewManager'); |
|
1009 | - } |
|
1010 | - |
|
1011 | - /** |
|
1012 | - * Returns the tag manager which can get and set tags for different object types |
|
1013 | - * |
|
1014 | - * @see \OCP\ITagManager::load() |
|
1015 | - * @return \OCP\ITagManager |
|
1016 | - */ |
|
1017 | - public function getTagManager() { |
|
1018 | - return $this->query('TagManager'); |
|
1019 | - } |
|
1020 | - |
|
1021 | - /** |
|
1022 | - * Returns the system-tag manager |
|
1023 | - * |
|
1024 | - * @return \OCP\SystemTag\ISystemTagManager |
|
1025 | - * |
|
1026 | - * @since 9.0.0 |
|
1027 | - */ |
|
1028 | - public function getSystemTagManager() { |
|
1029 | - return $this->query('SystemTagManager'); |
|
1030 | - } |
|
1031 | - |
|
1032 | - /** |
|
1033 | - * Returns the system-tag object mapper |
|
1034 | - * |
|
1035 | - * @return \OCP\SystemTag\ISystemTagObjectMapper |
|
1036 | - * |
|
1037 | - * @since 9.0.0 |
|
1038 | - */ |
|
1039 | - public function getSystemTagObjectMapper() { |
|
1040 | - return $this->query('SystemTagObjectMapper'); |
|
1041 | - } |
|
1042 | - |
|
1043 | - /** |
|
1044 | - * Returns the avatar manager, used for avatar functionality |
|
1045 | - * |
|
1046 | - * @return \OCP\IAvatarManager |
|
1047 | - */ |
|
1048 | - public function getAvatarManager() { |
|
1049 | - return $this->query('AvatarManager'); |
|
1050 | - } |
|
1051 | - |
|
1052 | - /** |
|
1053 | - * Returns the root folder of ownCloud's data directory |
|
1054 | - * |
|
1055 | - * @return \OCP\Files\IRootFolder |
|
1056 | - */ |
|
1057 | - public function getRootFolder() { |
|
1058 | - return $this->query('LazyRootFolder'); |
|
1059 | - } |
|
1060 | - |
|
1061 | - /** |
|
1062 | - * Returns the root folder of ownCloud's data directory |
|
1063 | - * This is the lazy variant so this gets only initialized once it |
|
1064 | - * is actually used. |
|
1065 | - * |
|
1066 | - * @return \OCP\Files\IRootFolder |
|
1067 | - */ |
|
1068 | - public function getLazyRootFolder() { |
|
1069 | - return $this->query('LazyRootFolder'); |
|
1070 | - } |
|
1071 | - |
|
1072 | - /** |
|
1073 | - * Returns a view to ownCloud's files folder |
|
1074 | - * |
|
1075 | - * @param string $userId user ID |
|
1076 | - * @return \OCP\Files\Folder|null |
|
1077 | - */ |
|
1078 | - public function getUserFolder($userId = null) { |
|
1079 | - if ($userId === null) { |
|
1080 | - $user = $this->getUserSession()->getUser(); |
|
1081 | - if (!$user) { |
|
1082 | - return null; |
|
1083 | - } |
|
1084 | - $userId = $user->getUID(); |
|
1085 | - } |
|
1086 | - $root = $this->getRootFolder(); |
|
1087 | - return $root->getUserFolder($userId); |
|
1088 | - } |
|
1089 | - |
|
1090 | - /** |
|
1091 | - * Returns an app-specific view in ownClouds data directory |
|
1092 | - * |
|
1093 | - * @return \OCP\Files\Folder |
|
1094 | - * @deprecated since 9.2.0 use IAppData |
|
1095 | - */ |
|
1096 | - public function getAppFolder() { |
|
1097 | - $dir = '/' . \OC_App::getCurrentApp(); |
|
1098 | - $root = $this->getRootFolder(); |
|
1099 | - if (!$root->nodeExists($dir)) { |
|
1100 | - $folder = $root->newFolder($dir); |
|
1101 | - } else { |
|
1102 | - $folder = $root->get($dir); |
|
1103 | - } |
|
1104 | - return $folder; |
|
1105 | - } |
|
1106 | - |
|
1107 | - /** |
|
1108 | - * @return \OC\User\Manager |
|
1109 | - */ |
|
1110 | - public function getUserManager() { |
|
1111 | - return $this->query('UserManager'); |
|
1112 | - } |
|
1113 | - |
|
1114 | - /** |
|
1115 | - * @return \OC\Group\Manager |
|
1116 | - */ |
|
1117 | - public function getGroupManager() { |
|
1118 | - return $this->query('GroupManager'); |
|
1119 | - } |
|
1120 | - |
|
1121 | - /** |
|
1122 | - * @return \OC\User\Session |
|
1123 | - */ |
|
1124 | - public function getUserSession() { |
|
1125 | - return $this->query('UserSession'); |
|
1126 | - } |
|
1127 | - |
|
1128 | - /** |
|
1129 | - * @return \OCP\ISession |
|
1130 | - */ |
|
1131 | - public function getSession() { |
|
1132 | - return $this->query('UserSession')->getSession(); |
|
1133 | - } |
|
1134 | - |
|
1135 | - /** |
|
1136 | - * @param \OCP\ISession $session |
|
1137 | - */ |
|
1138 | - public function setSession(\OCP\ISession $session) { |
|
1139 | - $this->query(SessionStorage::class)->setSession($session); |
|
1140 | - $this->query('UserSession')->setSession($session); |
|
1141 | - $this->query(Store::class)->setSession($session); |
|
1142 | - } |
|
1143 | - |
|
1144 | - /** |
|
1145 | - * @return \OC\Authentication\TwoFactorAuth\Manager |
|
1146 | - */ |
|
1147 | - public function getTwoFactorAuthManager() { |
|
1148 | - return $this->query('\OC\Authentication\TwoFactorAuth\Manager'); |
|
1149 | - } |
|
1150 | - |
|
1151 | - /** |
|
1152 | - * @return \OC\NavigationManager |
|
1153 | - */ |
|
1154 | - public function getNavigationManager() { |
|
1155 | - return $this->query('NavigationManager'); |
|
1156 | - } |
|
1157 | - |
|
1158 | - /** |
|
1159 | - * @return \OCP\IConfig |
|
1160 | - */ |
|
1161 | - public function getConfig() { |
|
1162 | - return $this->query('AllConfig'); |
|
1163 | - } |
|
1164 | - |
|
1165 | - /** |
|
1166 | - * @internal For internal use only |
|
1167 | - * @return \OC\SystemConfig |
|
1168 | - */ |
|
1169 | - public function getSystemConfig() { |
|
1170 | - return $this->query('SystemConfig'); |
|
1171 | - } |
|
1172 | - |
|
1173 | - /** |
|
1174 | - * Returns the app config manager |
|
1175 | - * |
|
1176 | - * @return \OCP\IAppConfig |
|
1177 | - */ |
|
1178 | - public function getAppConfig() { |
|
1179 | - return $this->query('AppConfig'); |
|
1180 | - } |
|
1181 | - |
|
1182 | - /** |
|
1183 | - * @return \OCP\L10N\IFactory |
|
1184 | - */ |
|
1185 | - public function getL10NFactory() { |
|
1186 | - return $this->query('L10NFactory'); |
|
1187 | - } |
|
1188 | - |
|
1189 | - /** |
|
1190 | - * get an L10N instance |
|
1191 | - * |
|
1192 | - * @param string $app appid |
|
1193 | - * @param string $lang |
|
1194 | - * @return IL10N |
|
1195 | - */ |
|
1196 | - public function getL10N($app, $lang = null) { |
|
1197 | - return $this->getL10NFactory()->get($app, $lang); |
|
1198 | - } |
|
1199 | - |
|
1200 | - /** |
|
1201 | - * @return \OCP\IURLGenerator |
|
1202 | - */ |
|
1203 | - public function getURLGenerator() { |
|
1204 | - return $this->query('URLGenerator'); |
|
1205 | - } |
|
1206 | - |
|
1207 | - /** |
|
1208 | - * @return \OCP\IHelper |
|
1209 | - */ |
|
1210 | - public function getHelper() { |
|
1211 | - return $this->query('AppHelper'); |
|
1212 | - } |
|
1213 | - |
|
1214 | - /** |
|
1215 | - * @return AppFetcher |
|
1216 | - */ |
|
1217 | - public function getAppFetcher() { |
|
1218 | - return $this->query('AppFetcher'); |
|
1219 | - } |
|
1220 | - |
|
1221 | - /** |
|
1222 | - * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use |
|
1223 | - * getMemCacheFactory() instead. |
|
1224 | - * |
|
1225 | - * @return \OCP\ICache |
|
1226 | - * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache |
|
1227 | - */ |
|
1228 | - public function getCache() { |
|
1229 | - return $this->query('UserCache'); |
|
1230 | - } |
|
1231 | - |
|
1232 | - /** |
|
1233 | - * Returns an \OCP\CacheFactory instance |
|
1234 | - * |
|
1235 | - * @return \OCP\ICacheFactory |
|
1236 | - */ |
|
1237 | - public function getMemCacheFactory() { |
|
1238 | - return $this->query('MemCacheFactory'); |
|
1239 | - } |
|
1240 | - |
|
1241 | - /** |
|
1242 | - * Returns an \OC\RedisFactory instance |
|
1243 | - * |
|
1244 | - * @return \OC\RedisFactory |
|
1245 | - */ |
|
1246 | - public function getGetRedisFactory() { |
|
1247 | - return $this->query('RedisFactory'); |
|
1248 | - } |
|
1249 | - |
|
1250 | - |
|
1251 | - /** |
|
1252 | - * Returns the current session |
|
1253 | - * |
|
1254 | - * @return \OCP\IDBConnection |
|
1255 | - */ |
|
1256 | - public function getDatabaseConnection() { |
|
1257 | - return $this->query('DatabaseConnection'); |
|
1258 | - } |
|
1259 | - |
|
1260 | - /** |
|
1261 | - * Returns the activity manager |
|
1262 | - * |
|
1263 | - * @return \OCP\Activity\IManager |
|
1264 | - */ |
|
1265 | - public function getActivityManager() { |
|
1266 | - return $this->query('ActivityManager'); |
|
1267 | - } |
|
1268 | - |
|
1269 | - /** |
|
1270 | - * Returns an job list for controlling background jobs |
|
1271 | - * |
|
1272 | - * @return \OCP\BackgroundJob\IJobList |
|
1273 | - */ |
|
1274 | - public function getJobList() { |
|
1275 | - return $this->query('JobList'); |
|
1276 | - } |
|
1277 | - |
|
1278 | - /** |
|
1279 | - * Returns a logger instance |
|
1280 | - * |
|
1281 | - * @return \OCP\ILogger |
|
1282 | - */ |
|
1283 | - public function getLogger() { |
|
1284 | - return $this->query('Logger'); |
|
1285 | - } |
|
1286 | - |
|
1287 | - /** |
|
1288 | - * Returns a router for generating and matching urls |
|
1289 | - * |
|
1290 | - * @return \OCP\Route\IRouter |
|
1291 | - */ |
|
1292 | - public function getRouter() { |
|
1293 | - return $this->query('Router'); |
|
1294 | - } |
|
1295 | - |
|
1296 | - /** |
|
1297 | - * Returns a search instance |
|
1298 | - * |
|
1299 | - * @return \OCP\ISearch |
|
1300 | - */ |
|
1301 | - public function getSearch() { |
|
1302 | - return $this->query('Search'); |
|
1303 | - } |
|
1304 | - |
|
1305 | - /** |
|
1306 | - * Returns a SecureRandom instance |
|
1307 | - * |
|
1308 | - * @return \OCP\Security\ISecureRandom |
|
1309 | - */ |
|
1310 | - public function getSecureRandom() { |
|
1311 | - return $this->query('SecureRandom'); |
|
1312 | - } |
|
1313 | - |
|
1314 | - /** |
|
1315 | - * Returns a Crypto instance |
|
1316 | - * |
|
1317 | - * @return \OCP\Security\ICrypto |
|
1318 | - */ |
|
1319 | - public function getCrypto() { |
|
1320 | - return $this->query('Crypto'); |
|
1321 | - } |
|
1322 | - |
|
1323 | - /** |
|
1324 | - * Returns a Hasher instance |
|
1325 | - * |
|
1326 | - * @return \OCP\Security\IHasher |
|
1327 | - */ |
|
1328 | - public function getHasher() { |
|
1329 | - return $this->query('Hasher'); |
|
1330 | - } |
|
1331 | - |
|
1332 | - /** |
|
1333 | - * Returns a CredentialsManager instance |
|
1334 | - * |
|
1335 | - * @return \OCP\Security\ICredentialsManager |
|
1336 | - */ |
|
1337 | - public function getCredentialsManager() { |
|
1338 | - return $this->query('CredentialsManager'); |
|
1339 | - } |
|
1340 | - |
|
1341 | - /** |
|
1342 | - * Returns an instance of the HTTP helper class |
|
1343 | - * |
|
1344 | - * @deprecated Use getHTTPClientService() |
|
1345 | - * @return \OC\HTTPHelper |
|
1346 | - */ |
|
1347 | - public function getHTTPHelper() { |
|
1348 | - return $this->query('HTTPHelper'); |
|
1349 | - } |
|
1350 | - |
|
1351 | - /** |
|
1352 | - * Get the certificate manager for the user |
|
1353 | - * |
|
1354 | - * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager |
|
1355 | - * @return \OCP\ICertificateManager | null if $uid is null and no user is logged in |
|
1356 | - */ |
|
1357 | - public function getCertificateManager($userId = '') { |
|
1358 | - if ($userId === '') { |
|
1359 | - $userSession = $this->getUserSession(); |
|
1360 | - $user = $userSession->getUser(); |
|
1361 | - if (is_null($user)) { |
|
1362 | - return null; |
|
1363 | - } |
|
1364 | - $userId = $user->getUID(); |
|
1365 | - } |
|
1366 | - return new CertificateManager($userId, new View(), $this->getConfig(), $this->getLogger()); |
|
1367 | - } |
|
1368 | - |
|
1369 | - /** |
|
1370 | - * Returns an instance of the HTTP client service |
|
1371 | - * |
|
1372 | - * @return \OCP\Http\Client\IClientService |
|
1373 | - */ |
|
1374 | - public function getHTTPClientService() { |
|
1375 | - return $this->query('HttpClientService'); |
|
1376 | - } |
|
1377 | - |
|
1378 | - /** |
|
1379 | - * Create a new event source |
|
1380 | - * |
|
1381 | - * @return \OCP\IEventSource |
|
1382 | - */ |
|
1383 | - public function createEventSource() { |
|
1384 | - return new \OC_EventSource(); |
|
1385 | - } |
|
1386 | - |
|
1387 | - /** |
|
1388 | - * Get the active event logger |
|
1389 | - * |
|
1390 | - * The returned logger only logs data when debug mode is enabled |
|
1391 | - * |
|
1392 | - * @return \OCP\Diagnostics\IEventLogger |
|
1393 | - */ |
|
1394 | - public function getEventLogger() { |
|
1395 | - return $this->query('EventLogger'); |
|
1396 | - } |
|
1397 | - |
|
1398 | - /** |
|
1399 | - * Get the active query logger |
|
1400 | - * |
|
1401 | - * The returned logger only logs data when debug mode is enabled |
|
1402 | - * |
|
1403 | - * @return \OCP\Diagnostics\IQueryLogger |
|
1404 | - */ |
|
1405 | - public function getQueryLogger() { |
|
1406 | - return $this->query('QueryLogger'); |
|
1407 | - } |
|
1408 | - |
|
1409 | - /** |
|
1410 | - * Get the manager for temporary files and folders |
|
1411 | - * |
|
1412 | - * @return \OCP\ITempManager |
|
1413 | - */ |
|
1414 | - public function getTempManager() { |
|
1415 | - return $this->query('TempManager'); |
|
1416 | - } |
|
1417 | - |
|
1418 | - /** |
|
1419 | - * Get the app manager |
|
1420 | - * |
|
1421 | - * @return \OCP\App\IAppManager |
|
1422 | - */ |
|
1423 | - public function getAppManager() { |
|
1424 | - return $this->query('AppManager'); |
|
1425 | - } |
|
1426 | - |
|
1427 | - /** |
|
1428 | - * Creates a new mailer |
|
1429 | - * |
|
1430 | - * @return \OCP\Mail\IMailer |
|
1431 | - */ |
|
1432 | - public function getMailer() { |
|
1433 | - return $this->query('Mailer'); |
|
1434 | - } |
|
1435 | - |
|
1436 | - /** |
|
1437 | - * Get the webroot |
|
1438 | - * |
|
1439 | - * @return string |
|
1440 | - */ |
|
1441 | - public function getWebRoot() { |
|
1442 | - return $this->webRoot; |
|
1443 | - } |
|
1444 | - |
|
1445 | - /** |
|
1446 | - * @return \OC\OCSClient |
|
1447 | - */ |
|
1448 | - public function getOcsClient() { |
|
1449 | - return $this->query('OcsClient'); |
|
1450 | - } |
|
1451 | - |
|
1452 | - /** |
|
1453 | - * @return \OCP\IDateTimeZone |
|
1454 | - */ |
|
1455 | - public function getDateTimeZone() { |
|
1456 | - return $this->query('DateTimeZone'); |
|
1457 | - } |
|
1458 | - |
|
1459 | - /** |
|
1460 | - * @return \OCP\IDateTimeFormatter |
|
1461 | - */ |
|
1462 | - public function getDateTimeFormatter() { |
|
1463 | - return $this->query('DateTimeFormatter'); |
|
1464 | - } |
|
1465 | - |
|
1466 | - /** |
|
1467 | - * @return \OCP\Files\Config\IMountProviderCollection |
|
1468 | - */ |
|
1469 | - public function getMountProviderCollection() { |
|
1470 | - return $this->query('MountConfigManager'); |
|
1471 | - } |
|
1472 | - |
|
1473 | - /** |
|
1474 | - * Get the IniWrapper |
|
1475 | - * |
|
1476 | - * @return IniGetWrapper |
|
1477 | - */ |
|
1478 | - public function getIniWrapper() { |
|
1479 | - return $this->query('IniWrapper'); |
|
1480 | - } |
|
1481 | - |
|
1482 | - /** |
|
1483 | - * @return \OCP\Command\IBus |
|
1484 | - */ |
|
1485 | - public function getCommandBus() { |
|
1486 | - return $this->query('AsyncCommandBus'); |
|
1487 | - } |
|
1488 | - |
|
1489 | - /** |
|
1490 | - * Get the trusted domain helper |
|
1491 | - * |
|
1492 | - * @return TrustedDomainHelper |
|
1493 | - */ |
|
1494 | - public function getTrustedDomainHelper() { |
|
1495 | - return $this->query('TrustedDomainHelper'); |
|
1496 | - } |
|
1497 | - |
|
1498 | - /** |
|
1499 | - * Get the locking provider |
|
1500 | - * |
|
1501 | - * @return \OCP\Lock\ILockingProvider |
|
1502 | - * @since 8.1.0 |
|
1503 | - */ |
|
1504 | - public function getLockingProvider() { |
|
1505 | - return $this->query('LockingProvider'); |
|
1506 | - } |
|
1507 | - |
|
1508 | - /** |
|
1509 | - * @return \OCP\Files\Mount\IMountManager |
|
1510 | - **/ |
|
1511 | - function getMountManager() { |
|
1512 | - return $this->query('MountManager'); |
|
1513 | - } |
|
1514 | - |
|
1515 | - /** @return \OCP\Files\Config\IUserMountCache */ |
|
1516 | - function getUserMountCache() { |
|
1517 | - return $this->query('UserMountCache'); |
|
1518 | - } |
|
1519 | - |
|
1520 | - /** |
|
1521 | - * Get the MimeTypeDetector |
|
1522 | - * |
|
1523 | - * @return \OCP\Files\IMimeTypeDetector |
|
1524 | - */ |
|
1525 | - public function getMimeTypeDetector() { |
|
1526 | - return $this->query('MimeTypeDetector'); |
|
1527 | - } |
|
1528 | - |
|
1529 | - /** |
|
1530 | - * Get the MimeTypeLoader |
|
1531 | - * |
|
1532 | - * @return \OCP\Files\IMimeTypeLoader |
|
1533 | - */ |
|
1534 | - public function getMimeTypeLoader() { |
|
1535 | - return $this->query('MimeTypeLoader'); |
|
1536 | - } |
|
1537 | - |
|
1538 | - /** |
|
1539 | - * Get the manager of all the capabilities |
|
1540 | - * |
|
1541 | - * @return \OC\CapabilitiesManager |
|
1542 | - */ |
|
1543 | - public function getCapabilitiesManager() { |
|
1544 | - return $this->query('CapabilitiesManager'); |
|
1545 | - } |
|
1546 | - |
|
1547 | - /** |
|
1548 | - * Get the EventDispatcher |
|
1549 | - * |
|
1550 | - * @return EventDispatcherInterface |
|
1551 | - * @since 8.2.0 |
|
1552 | - */ |
|
1553 | - public function getEventDispatcher() { |
|
1554 | - return $this->query('EventDispatcher'); |
|
1555 | - } |
|
1556 | - |
|
1557 | - /** |
|
1558 | - * Get the Notification Manager |
|
1559 | - * |
|
1560 | - * @return \OCP\Notification\IManager |
|
1561 | - * @since 8.2.0 |
|
1562 | - */ |
|
1563 | - public function getNotificationManager() { |
|
1564 | - return $this->query('NotificationManager'); |
|
1565 | - } |
|
1566 | - |
|
1567 | - /** |
|
1568 | - * @return \OCP\Comments\ICommentsManager |
|
1569 | - */ |
|
1570 | - public function getCommentsManager() { |
|
1571 | - return $this->query('CommentsManager'); |
|
1572 | - } |
|
1573 | - |
|
1574 | - /** |
|
1575 | - * @return \OCA\Theming\ThemingDefaults |
|
1576 | - */ |
|
1577 | - public function getThemingDefaults() { |
|
1578 | - return $this->query('ThemingDefaults'); |
|
1579 | - } |
|
1580 | - |
|
1581 | - /** |
|
1582 | - * @return \OC\IntegrityCheck\Checker |
|
1583 | - */ |
|
1584 | - public function getIntegrityCodeChecker() { |
|
1585 | - return $this->query('IntegrityCodeChecker'); |
|
1586 | - } |
|
1587 | - |
|
1588 | - /** |
|
1589 | - * @return \OC\Session\CryptoWrapper |
|
1590 | - */ |
|
1591 | - public function getSessionCryptoWrapper() { |
|
1592 | - return $this->query('CryptoWrapper'); |
|
1593 | - } |
|
1594 | - |
|
1595 | - /** |
|
1596 | - * @return CsrfTokenManager |
|
1597 | - */ |
|
1598 | - public function getCsrfTokenManager() { |
|
1599 | - return $this->query('CsrfTokenManager'); |
|
1600 | - } |
|
1601 | - |
|
1602 | - /** |
|
1603 | - * @return Throttler |
|
1604 | - */ |
|
1605 | - public function getBruteForceThrottler() { |
|
1606 | - return $this->query('Throttler'); |
|
1607 | - } |
|
1608 | - |
|
1609 | - /** |
|
1610 | - * @return IContentSecurityPolicyManager |
|
1611 | - */ |
|
1612 | - public function getContentSecurityPolicyManager() { |
|
1613 | - return $this->query('ContentSecurityPolicyManager'); |
|
1614 | - } |
|
1615 | - |
|
1616 | - /** |
|
1617 | - * @return ContentSecurityPolicyNonceManager |
|
1618 | - */ |
|
1619 | - public function getContentSecurityPolicyNonceManager() { |
|
1620 | - return $this->query('ContentSecurityPolicyNonceManager'); |
|
1621 | - } |
|
1622 | - |
|
1623 | - /** |
|
1624 | - * Not a public API as of 8.2, wait for 9.0 |
|
1625 | - * |
|
1626 | - * @return \OCA\Files_External\Service\BackendService |
|
1627 | - */ |
|
1628 | - public function getStoragesBackendService() { |
|
1629 | - return $this->query('OCA\\Files_External\\Service\\BackendService'); |
|
1630 | - } |
|
1631 | - |
|
1632 | - /** |
|
1633 | - * Not a public API as of 8.2, wait for 9.0 |
|
1634 | - * |
|
1635 | - * @return \OCA\Files_External\Service\GlobalStoragesService |
|
1636 | - */ |
|
1637 | - public function getGlobalStoragesService() { |
|
1638 | - return $this->query('OCA\\Files_External\\Service\\GlobalStoragesService'); |
|
1639 | - } |
|
1640 | - |
|
1641 | - /** |
|
1642 | - * Not a public API as of 8.2, wait for 9.0 |
|
1643 | - * |
|
1644 | - * @return \OCA\Files_External\Service\UserGlobalStoragesService |
|
1645 | - */ |
|
1646 | - public function getUserGlobalStoragesService() { |
|
1647 | - return $this->query('OCA\\Files_External\\Service\\UserGlobalStoragesService'); |
|
1648 | - } |
|
1649 | - |
|
1650 | - /** |
|
1651 | - * Not a public API as of 8.2, wait for 9.0 |
|
1652 | - * |
|
1653 | - * @return \OCA\Files_External\Service\UserStoragesService |
|
1654 | - */ |
|
1655 | - public function getUserStoragesService() { |
|
1656 | - return $this->query('OCA\\Files_External\\Service\\UserStoragesService'); |
|
1657 | - } |
|
1658 | - |
|
1659 | - /** |
|
1660 | - * @return \OCP\Share\IManager |
|
1661 | - */ |
|
1662 | - public function getShareManager() { |
|
1663 | - return $this->query('ShareManager'); |
|
1664 | - } |
|
1665 | - |
|
1666 | - /** |
|
1667 | - * Returns the LDAP Provider |
|
1668 | - * |
|
1669 | - * @return \OCP\LDAP\ILDAPProvider |
|
1670 | - */ |
|
1671 | - public function getLDAPProvider() { |
|
1672 | - return $this->query('LDAPProvider'); |
|
1673 | - } |
|
1674 | - |
|
1675 | - /** |
|
1676 | - * @return \OCP\Settings\IManager |
|
1677 | - */ |
|
1678 | - public function getSettingsManager() { |
|
1679 | - return $this->query('SettingsManager'); |
|
1680 | - } |
|
1681 | - |
|
1682 | - /** |
|
1683 | - * @return \OCP\Files\IAppData |
|
1684 | - */ |
|
1685 | - public function getAppDataDir($app) { |
|
1686 | - /** @var \OC\Files\AppData\Factory $factory */ |
|
1687 | - $factory = $this->query(\OC\Files\AppData\Factory::class); |
|
1688 | - return $factory->get($app); |
|
1689 | - } |
|
1690 | - |
|
1691 | - /** |
|
1692 | - * @return \OCP\Lockdown\ILockdownManager |
|
1693 | - */ |
|
1694 | - public function getLockdownManager() { |
|
1695 | - return $this->query('LockdownManager'); |
|
1696 | - } |
|
1697 | - |
|
1698 | - /** |
|
1699 | - * @return \OCP\Federation\ICloudIdManager |
|
1700 | - */ |
|
1701 | - public function getCloudIdManager() { |
|
1702 | - return $this->query(ICloudIdManager::class); |
|
1703 | - } |
|
813 | + $prefixes = \OC::$composerAutoloader->getPrefixesPsr4(); |
|
814 | + if (isset($prefixes['OCA\\Theming\\'])) { |
|
815 | + $classExists = true; |
|
816 | + } else { |
|
817 | + $classExists = false; |
|
818 | + } |
|
819 | + |
|
820 | + if ($classExists && $c->getConfig()->getSystemValue('installed', false) && $c->getAppManager()->isInstalled('theming')) { |
|
821 | + return new ThemingDefaults( |
|
822 | + $c->getConfig(), |
|
823 | + $c->getL10N('theming'), |
|
824 | + $c->getURLGenerator(), |
|
825 | + new \OC_Defaults(), |
|
826 | + $c->getAppDataDir('theming'), |
|
827 | + $c->getMemCacheFactory() |
|
828 | + ); |
|
829 | + } |
|
830 | + return new \OC_Defaults(); |
|
831 | + }); |
|
832 | + $this->registerService(EventDispatcher::class, function () { |
|
833 | + return new EventDispatcher(); |
|
834 | + }); |
|
835 | + $this->registerAlias('EventDispatcher', EventDispatcher::class); |
|
836 | + $this->registerAlias(EventDispatcherInterface::class, EventDispatcher::class); |
|
837 | + |
|
838 | + $this->registerService('CryptoWrapper', function (Server $c) { |
|
839 | + // FIXME: Instantiiated here due to cyclic dependency |
|
840 | + $request = new Request( |
|
841 | + [ |
|
842 | + 'get' => $_GET, |
|
843 | + 'post' => $_POST, |
|
844 | + 'files' => $_FILES, |
|
845 | + 'server' => $_SERVER, |
|
846 | + 'env' => $_ENV, |
|
847 | + 'cookies' => $_COOKIE, |
|
848 | + 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
849 | + ? $_SERVER['REQUEST_METHOD'] |
|
850 | + : null, |
|
851 | + ], |
|
852 | + $c->getSecureRandom(), |
|
853 | + $c->getConfig() |
|
854 | + ); |
|
855 | + |
|
856 | + return new CryptoWrapper( |
|
857 | + $c->getConfig(), |
|
858 | + $c->getCrypto(), |
|
859 | + $c->getSecureRandom(), |
|
860 | + $request |
|
861 | + ); |
|
862 | + }); |
|
863 | + $this->registerService('CsrfTokenManager', function (Server $c) { |
|
864 | + $tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom()); |
|
865 | + |
|
866 | + return new CsrfTokenManager( |
|
867 | + $tokenGenerator, |
|
868 | + $c->query(SessionStorage::class) |
|
869 | + ); |
|
870 | + }); |
|
871 | + $this->registerService(SessionStorage::class, function (Server $c) { |
|
872 | + return new SessionStorage($c->getSession()); |
|
873 | + }); |
|
874 | + $this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function (Server $c) { |
|
875 | + return new ContentSecurityPolicyManager(); |
|
876 | + }); |
|
877 | + $this->registerAlias('ContentSecurityPolicyManager', \OCP\Security\IContentSecurityPolicyManager::class); |
|
878 | + |
|
879 | + $this->registerService('ContentSecurityPolicyNonceManager', function(Server $c) { |
|
880 | + return new ContentSecurityPolicyNonceManager( |
|
881 | + $c->getCsrfTokenManager(), |
|
882 | + $c->getRequest() |
|
883 | + ); |
|
884 | + }); |
|
885 | + |
|
886 | + $this->registerService(\OCP\Share\IManager::class, function(Server $c) { |
|
887 | + $config = $c->getConfig(); |
|
888 | + $factoryClass = $config->getSystemValue('sharing.managerFactory', '\OC\Share20\ProviderFactory'); |
|
889 | + /** @var \OCP\Share\IProviderFactory $factory */ |
|
890 | + $factory = new $factoryClass($this); |
|
891 | + |
|
892 | + $manager = new \OC\Share20\Manager( |
|
893 | + $c->getLogger(), |
|
894 | + $c->getConfig(), |
|
895 | + $c->getSecureRandom(), |
|
896 | + $c->getHasher(), |
|
897 | + $c->getMountManager(), |
|
898 | + $c->getGroupManager(), |
|
899 | + $c->getL10N('core'), |
|
900 | + $factory, |
|
901 | + $c->getUserManager(), |
|
902 | + $c->getLazyRootFolder(), |
|
903 | + $c->getEventDispatcher() |
|
904 | + ); |
|
905 | + |
|
906 | + return $manager; |
|
907 | + }); |
|
908 | + $this->registerAlias('ShareManager', \OCP\Share\IManager::class); |
|
909 | + |
|
910 | + $this->registerService('SettingsManager', function(Server $c) { |
|
911 | + $manager = new \OC\Settings\Manager( |
|
912 | + $c->getLogger(), |
|
913 | + $c->getDatabaseConnection(), |
|
914 | + $c->getL10N('lib'), |
|
915 | + $c->getConfig(), |
|
916 | + $c->getEncryptionManager(), |
|
917 | + $c->getUserManager(), |
|
918 | + $c->getLockingProvider(), |
|
919 | + $c->getRequest(), |
|
920 | + new \OC\Settings\Mapper($c->getDatabaseConnection()), |
|
921 | + $c->getURLGenerator() |
|
922 | + ); |
|
923 | + return $manager; |
|
924 | + }); |
|
925 | + $this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) { |
|
926 | + return new \OC\Files\AppData\Factory( |
|
927 | + $c->getRootFolder(), |
|
928 | + $c->getSystemConfig() |
|
929 | + ); |
|
930 | + }); |
|
931 | + |
|
932 | + $this->registerService('LockdownManager', function (Server $c) { |
|
933 | + return new LockdownManager(function() use ($c) { |
|
934 | + return $c->getSession(); |
|
935 | + }); |
|
936 | + }); |
|
937 | + |
|
938 | + $this->registerService(ICloudIdManager::class, function (Server $c) { |
|
939 | + return new CloudIdManager(); |
|
940 | + }); |
|
941 | + |
|
942 | + /* To trick DI since we don't extend the DIContainer here */ |
|
943 | + $this->registerService(CleanPreviewsBackgroundJob::class, function (Server $c) { |
|
944 | + return new CleanPreviewsBackgroundJob( |
|
945 | + $c->getRootFolder(), |
|
946 | + $c->getLogger(), |
|
947 | + $c->getJobList(), |
|
948 | + new TimeFactory() |
|
949 | + ); |
|
950 | + }); |
|
951 | + |
|
952 | + $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class); |
|
953 | + $this->registerAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class); |
|
954 | + |
|
955 | + $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class); |
|
956 | + $this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class); |
|
957 | + |
|
958 | + $this->registerService(\OCP\ISession::class, function(SimpleContainer $c) { |
|
959 | + return $c->query(\OCP\IUserSession::class)->getSession(); |
|
960 | + }); |
|
961 | + } |
|
962 | + |
|
963 | + /** |
|
964 | + * @return \OCP\Contacts\IManager |
|
965 | + */ |
|
966 | + public function getContactsManager() { |
|
967 | + return $this->query('ContactsManager'); |
|
968 | + } |
|
969 | + |
|
970 | + /** |
|
971 | + * @return \OC\Encryption\Manager |
|
972 | + */ |
|
973 | + public function getEncryptionManager() { |
|
974 | + return $this->query('EncryptionManager'); |
|
975 | + } |
|
976 | + |
|
977 | + /** |
|
978 | + * @return \OC\Encryption\File |
|
979 | + */ |
|
980 | + public function getEncryptionFilesHelper() { |
|
981 | + return $this->query('EncryptionFileHelper'); |
|
982 | + } |
|
983 | + |
|
984 | + /** |
|
985 | + * @return \OCP\Encryption\Keys\IStorage |
|
986 | + */ |
|
987 | + public function getEncryptionKeyStorage() { |
|
988 | + return $this->query('EncryptionKeyStorage'); |
|
989 | + } |
|
990 | + |
|
991 | + /** |
|
992 | + * The current request object holding all information about the request |
|
993 | + * currently being processed is returned from this method. |
|
994 | + * In case the current execution was not initiated by a web request null is returned |
|
995 | + * |
|
996 | + * @return \OCP\IRequest |
|
997 | + */ |
|
998 | + public function getRequest() { |
|
999 | + return $this->query('Request'); |
|
1000 | + } |
|
1001 | + |
|
1002 | + /** |
|
1003 | + * Returns the preview manager which can create preview images for a given file |
|
1004 | + * |
|
1005 | + * @return \OCP\IPreview |
|
1006 | + */ |
|
1007 | + public function getPreviewManager() { |
|
1008 | + return $this->query('PreviewManager'); |
|
1009 | + } |
|
1010 | + |
|
1011 | + /** |
|
1012 | + * Returns the tag manager which can get and set tags for different object types |
|
1013 | + * |
|
1014 | + * @see \OCP\ITagManager::load() |
|
1015 | + * @return \OCP\ITagManager |
|
1016 | + */ |
|
1017 | + public function getTagManager() { |
|
1018 | + return $this->query('TagManager'); |
|
1019 | + } |
|
1020 | + |
|
1021 | + /** |
|
1022 | + * Returns the system-tag manager |
|
1023 | + * |
|
1024 | + * @return \OCP\SystemTag\ISystemTagManager |
|
1025 | + * |
|
1026 | + * @since 9.0.0 |
|
1027 | + */ |
|
1028 | + public function getSystemTagManager() { |
|
1029 | + return $this->query('SystemTagManager'); |
|
1030 | + } |
|
1031 | + |
|
1032 | + /** |
|
1033 | + * Returns the system-tag object mapper |
|
1034 | + * |
|
1035 | + * @return \OCP\SystemTag\ISystemTagObjectMapper |
|
1036 | + * |
|
1037 | + * @since 9.0.0 |
|
1038 | + */ |
|
1039 | + public function getSystemTagObjectMapper() { |
|
1040 | + return $this->query('SystemTagObjectMapper'); |
|
1041 | + } |
|
1042 | + |
|
1043 | + /** |
|
1044 | + * Returns the avatar manager, used for avatar functionality |
|
1045 | + * |
|
1046 | + * @return \OCP\IAvatarManager |
|
1047 | + */ |
|
1048 | + public function getAvatarManager() { |
|
1049 | + return $this->query('AvatarManager'); |
|
1050 | + } |
|
1051 | + |
|
1052 | + /** |
|
1053 | + * Returns the root folder of ownCloud's data directory |
|
1054 | + * |
|
1055 | + * @return \OCP\Files\IRootFolder |
|
1056 | + */ |
|
1057 | + public function getRootFolder() { |
|
1058 | + return $this->query('LazyRootFolder'); |
|
1059 | + } |
|
1060 | + |
|
1061 | + /** |
|
1062 | + * Returns the root folder of ownCloud's data directory |
|
1063 | + * This is the lazy variant so this gets only initialized once it |
|
1064 | + * is actually used. |
|
1065 | + * |
|
1066 | + * @return \OCP\Files\IRootFolder |
|
1067 | + */ |
|
1068 | + public function getLazyRootFolder() { |
|
1069 | + return $this->query('LazyRootFolder'); |
|
1070 | + } |
|
1071 | + |
|
1072 | + /** |
|
1073 | + * Returns a view to ownCloud's files folder |
|
1074 | + * |
|
1075 | + * @param string $userId user ID |
|
1076 | + * @return \OCP\Files\Folder|null |
|
1077 | + */ |
|
1078 | + public function getUserFolder($userId = null) { |
|
1079 | + if ($userId === null) { |
|
1080 | + $user = $this->getUserSession()->getUser(); |
|
1081 | + if (!$user) { |
|
1082 | + return null; |
|
1083 | + } |
|
1084 | + $userId = $user->getUID(); |
|
1085 | + } |
|
1086 | + $root = $this->getRootFolder(); |
|
1087 | + return $root->getUserFolder($userId); |
|
1088 | + } |
|
1089 | + |
|
1090 | + /** |
|
1091 | + * Returns an app-specific view in ownClouds data directory |
|
1092 | + * |
|
1093 | + * @return \OCP\Files\Folder |
|
1094 | + * @deprecated since 9.2.0 use IAppData |
|
1095 | + */ |
|
1096 | + public function getAppFolder() { |
|
1097 | + $dir = '/' . \OC_App::getCurrentApp(); |
|
1098 | + $root = $this->getRootFolder(); |
|
1099 | + if (!$root->nodeExists($dir)) { |
|
1100 | + $folder = $root->newFolder($dir); |
|
1101 | + } else { |
|
1102 | + $folder = $root->get($dir); |
|
1103 | + } |
|
1104 | + return $folder; |
|
1105 | + } |
|
1106 | + |
|
1107 | + /** |
|
1108 | + * @return \OC\User\Manager |
|
1109 | + */ |
|
1110 | + public function getUserManager() { |
|
1111 | + return $this->query('UserManager'); |
|
1112 | + } |
|
1113 | + |
|
1114 | + /** |
|
1115 | + * @return \OC\Group\Manager |
|
1116 | + */ |
|
1117 | + public function getGroupManager() { |
|
1118 | + return $this->query('GroupManager'); |
|
1119 | + } |
|
1120 | + |
|
1121 | + /** |
|
1122 | + * @return \OC\User\Session |
|
1123 | + */ |
|
1124 | + public function getUserSession() { |
|
1125 | + return $this->query('UserSession'); |
|
1126 | + } |
|
1127 | + |
|
1128 | + /** |
|
1129 | + * @return \OCP\ISession |
|
1130 | + */ |
|
1131 | + public function getSession() { |
|
1132 | + return $this->query('UserSession')->getSession(); |
|
1133 | + } |
|
1134 | + |
|
1135 | + /** |
|
1136 | + * @param \OCP\ISession $session |
|
1137 | + */ |
|
1138 | + public function setSession(\OCP\ISession $session) { |
|
1139 | + $this->query(SessionStorage::class)->setSession($session); |
|
1140 | + $this->query('UserSession')->setSession($session); |
|
1141 | + $this->query(Store::class)->setSession($session); |
|
1142 | + } |
|
1143 | + |
|
1144 | + /** |
|
1145 | + * @return \OC\Authentication\TwoFactorAuth\Manager |
|
1146 | + */ |
|
1147 | + public function getTwoFactorAuthManager() { |
|
1148 | + return $this->query('\OC\Authentication\TwoFactorAuth\Manager'); |
|
1149 | + } |
|
1150 | + |
|
1151 | + /** |
|
1152 | + * @return \OC\NavigationManager |
|
1153 | + */ |
|
1154 | + public function getNavigationManager() { |
|
1155 | + return $this->query('NavigationManager'); |
|
1156 | + } |
|
1157 | + |
|
1158 | + /** |
|
1159 | + * @return \OCP\IConfig |
|
1160 | + */ |
|
1161 | + public function getConfig() { |
|
1162 | + return $this->query('AllConfig'); |
|
1163 | + } |
|
1164 | + |
|
1165 | + /** |
|
1166 | + * @internal For internal use only |
|
1167 | + * @return \OC\SystemConfig |
|
1168 | + */ |
|
1169 | + public function getSystemConfig() { |
|
1170 | + return $this->query('SystemConfig'); |
|
1171 | + } |
|
1172 | + |
|
1173 | + /** |
|
1174 | + * Returns the app config manager |
|
1175 | + * |
|
1176 | + * @return \OCP\IAppConfig |
|
1177 | + */ |
|
1178 | + public function getAppConfig() { |
|
1179 | + return $this->query('AppConfig'); |
|
1180 | + } |
|
1181 | + |
|
1182 | + /** |
|
1183 | + * @return \OCP\L10N\IFactory |
|
1184 | + */ |
|
1185 | + public function getL10NFactory() { |
|
1186 | + return $this->query('L10NFactory'); |
|
1187 | + } |
|
1188 | + |
|
1189 | + /** |
|
1190 | + * get an L10N instance |
|
1191 | + * |
|
1192 | + * @param string $app appid |
|
1193 | + * @param string $lang |
|
1194 | + * @return IL10N |
|
1195 | + */ |
|
1196 | + public function getL10N($app, $lang = null) { |
|
1197 | + return $this->getL10NFactory()->get($app, $lang); |
|
1198 | + } |
|
1199 | + |
|
1200 | + /** |
|
1201 | + * @return \OCP\IURLGenerator |
|
1202 | + */ |
|
1203 | + public function getURLGenerator() { |
|
1204 | + return $this->query('URLGenerator'); |
|
1205 | + } |
|
1206 | + |
|
1207 | + /** |
|
1208 | + * @return \OCP\IHelper |
|
1209 | + */ |
|
1210 | + public function getHelper() { |
|
1211 | + return $this->query('AppHelper'); |
|
1212 | + } |
|
1213 | + |
|
1214 | + /** |
|
1215 | + * @return AppFetcher |
|
1216 | + */ |
|
1217 | + public function getAppFetcher() { |
|
1218 | + return $this->query('AppFetcher'); |
|
1219 | + } |
|
1220 | + |
|
1221 | + /** |
|
1222 | + * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use |
|
1223 | + * getMemCacheFactory() instead. |
|
1224 | + * |
|
1225 | + * @return \OCP\ICache |
|
1226 | + * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache |
|
1227 | + */ |
|
1228 | + public function getCache() { |
|
1229 | + return $this->query('UserCache'); |
|
1230 | + } |
|
1231 | + |
|
1232 | + /** |
|
1233 | + * Returns an \OCP\CacheFactory instance |
|
1234 | + * |
|
1235 | + * @return \OCP\ICacheFactory |
|
1236 | + */ |
|
1237 | + public function getMemCacheFactory() { |
|
1238 | + return $this->query('MemCacheFactory'); |
|
1239 | + } |
|
1240 | + |
|
1241 | + /** |
|
1242 | + * Returns an \OC\RedisFactory instance |
|
1243 | + * |
|
1244 | + * @return \OC\RedisFactory |
|
1245 | + */ |
|
1246 | + public function getGetRedisFactory() { |
|
1247 | + return $this->query('RedisFactory'); |
|
1248 | + } |
|
1249 | + |
|
1250 | + |
|
1251 | + /** |
|
1252 | + * Returns the current session |
|
1253 | + * |
|
1254 | + * @return \OCP\IDBConnection |
|
1255 | + */ |
|
1256 | + public function getDatabaseConnection() { |
|
1257 | + return $this->query('DatabaseConnection'); |
|
1258 | + } |
|
1259 | + |
|
1260 | + /** |
|
1261 | + * Returns the activity manager |
|
1262 | + * |
|
1263 | + * @return \OCP\Activity\IManager |
|
1264 | + */ |
|
1265 | + public function getActivityManager() { |
|
1266 | + return $this->query('ActivityManager'); |
|
1267 | + } |
|
1268 | + |
|
1269 | + /** |
|
1270 | + * Returns an job list for controlling background jobs |
|
1271 | + * |
|
1272 | + * @return \OCP\BackgroundJob\IJobList |
|
1273 | + */ |
|
1274 | + public function getJobList() { |
|
1275 | + return $this->query('JobList'); |
|
1276 | + } |
|
1277 | + |
|
1278 | + /** |
|
1279 | + * Returns a logger instance |
|
1280 | + * |
|
1281 | + * @return \OCP\ILogger |
|
1282 | + */ |
|
1283 | + public function getLogger() { |
|
1284 | + return $this->query('Logger'); |
|
1285 | + } |
|
1286 | + |
|
1287 | + /** |
|
1288 | + * Returns a router for generating and matching urls |
|
1289 | + * |
|
1290 | + * @return \OCP\Route\IRouter |
|
1291 | + */ |
|
1292 | + public function getRouter() { |
|
1293 | + return $this->query('Router'); |
|
1294 | + } |
|
1295 | + |
|
1296 | + /** |
|
1297 | + * Returns a search instance |
|
1298 | + * |
|
1299 | + * @return \OCP\ISearch |
|
1300 | + */ |
|
1301 | + public function getSearch() { |
|
1302 | + return $this->query('Search'); |
|
1303 | + } |
|
1304 | + |
|
1305 | + /** |
|
1306 | + * Returns a SecureRandom instance |
|
1307 | + * |
|
1308 | + * @return \OCP\Security\ISecureRandom |
|
1309 | + */ |
|
1310 | + public function getSecureRandom() { |
|
1311 | + return $this->query('SecureRandom'); |
|
1312 | + } |
|
1313 | + |
|
1314 | + /** |
|
1315 | + * Returns a Crypto instance |
|
1316 | + * |
|
1317 | + * @return \OCP\Security\ICrypto |
|
1318 | + */ |
|
1319 | + public function getCrypto() { |
|
1320 | + return $this->query('Crypto'); |
|
1321 | + } |
|
1322 | + |
|
1323 | + /** |
|
1324 | + * Returns a Hasher instance |
|
1325 | + * |
|
1326 | + * @return \OCP\Security\IHasher |
|
1327 | + */ |
|
1328 | + public function getHasher() { |
|
1329 | + return $this->query('Hasher'); |
|
1330 | + } |
|
1331 | + |
|
1332 | + /** |
|
1333 | + * Returns a CredentialsManager instance |
|
1334 | + * |
|
1335 | + * @return \OCP\Security\ICredentialsManager |
|
1336 | + */ |
|
1337 | + public function getCredentialsManager() { |
|
1338 | + return $this->query('CredentialsManager'); |
|
1339 | + } |
|
1340 | + |
|
1341 | + /** |
|
1342 | + * Returns an instance of the HTTP helper class |
|
1343 | + * |
|
1344 | + * @deprecated Use getHTTPClientService() |
|
1345 | + * @return \OC\HTTPHelper |
|
1346 | + */ |
|
1347 | + public function getHTTPHelper() { |
|
1348 | + return $this->query('HTTPHelper'); |
|
1349 | + } |
|
1350 | + |
|
1351 | + /** |
|
1352 | + * Get the certificate manager for the user |
|
1353 | + * |
|
1354 | + * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager |
|
1355 | + * @return \OCP\ICertificateManager | null if $uid is null and no user is logged in |
|
1356 | + */ |
|
1357 | + public function getCertificateManager($userId = '') { |
|
1358 | + if ($userId === '') { |
|
1359 | + $userSession = $this->getUserSession(); |
|
1360 | + $user = $userSession->getUser(); |
|
1361 | + if (is_null($user)) { |
|
1362 | + return null; |
|
1363 | + } |
|
1364 | + $userId = $user->getUID(); |
|
1365 | + } |
|
1366 | + return new CertificateManager($userId, new View(), $this->getConfig(), $this->getLogger()); |
|
1367 | + } |
|
1368 | + |
|
1369 | + /** |
|
1370 | + * Returns an instance of the HTTP client service |
|
1371 | + * |
|
1372 | + * @return \OCP\Http\Client\IClientService |
|
1373 | + */ |
|
1374 | + public function getHTTPClientService() { |
|
1375 | + return $this->query('HttpClientService'); |
|
1376 | + } |
|
1377 | + |
|
1378 | + /** |
|
1379 | + * Create a new event source |
|
1380 | + * |
|
1381 | + * @return \OCP\IEventSource |
|
1382 | + */ |
|
1383 | + public function createEventSource() { |
|
1384 | + return new \OC_EventSource(); |
|
1385 | + } |
|
1386 | + |
|
1387 | + /** |
|
1388 | + * Get the active event logger |
|
1389 | + * |
|
1390 | + * The returned logger only logs data when debug mode is enabled |
|
1391 | + * |
|
1392 | + * @return \OCP\Diagnostics\IEventLogger |
|
1393 | + */ |
|
1394 | + public function getEventLogger() { |
|
1395 | + return $this->query('EventLogger'); |
|
1396 | + } |
|
1397 | + |
|
1398 | + /** |
|
1399 | + * Get the active query logger |
|
1400 | + * |
|
1401 | + * The returned logger only logs data when debug mode is enabled |
|
1402 | + * |
|
1403 | + * @return \OCP\Diagnostics\IQueryLogger |
|
1404 | + */ |
|
1405 | + public function getQueryLogger() { |
|
1406 | + return $this->query('QueryLogger'); |
|
1407 | + } |
|
1408 | + |
|
1409 | + /** |
|
1410 | + * Get the manager for temporary files and folders |
|
1411 | + * |
|
1412 | + * @return \OCP\ITempManager |
|
1413 | + */ |
|
1414 | + public function getTempManager() { |
|
1415 | + return $this->query('TempManager'); |
|
1416 | + } |
|
1417 | + |
|
1418 | + /** |
|
1419 | + * Get the app manager |
|
1420 | + * |
|
1421 | + * @return \OCP\App\IAppManager |
|
1422 | + */ |
|
1423 | + public function getAppManager() { |
|
1424 | + return $this->query('AppManager'); |
|
1425 | + } |
|
1426 | + |
|
1427 | + /** |
|
1428 | + * Creates a new mailer |
|
1429 | + * |
|
1430 | + * @return \OCP\Mail\IMailer |
|
1431 | + */ |
|
1432 | + public function getMailer() { |
|
1433 | + return $this->query('Mailer'); |
|
1434 | + } |
|
1435 | + |
|
1436 | + /** |
|
1437 | + * Get the webroot |
|
1438 | + * |
|
1439 | + * @return string |
|
1440 | + */ |
|
1441 | + public function getWebRoot() { |
|
1442 | + return $this->webRoot; |
|
1443 | + } |
|
1444 | + |
|
1445 | + /** |
|
1446 | + * @return \OC\OCSClient |
|
1447 | + */ |
|
1448 | + public function getOcsClient() { |
|
1449 | + return $this->query('OcsClient'); |
|
1450 | + } |
|
1451 | + |
|
1452 | + /** |
|
1453 | + * @return \OCP\IDateTimeZone |
|
1454 | + */ |
|
1455 | + public function getDateTimeZone() { |
|
1456 | + return $this->query('DateTimeZone'); |
|
1457 | + } |
|
1458 | + |
|
1459 | + /** |
|
1460 | + * @return \OCP\IDateTimeFormatter |
|
1461 | + */ |
|
1462 | + public function getDateTimeFormatter() { |
|
1463 | + return $this->query('DateTimeFormatter'); |
|
1464 | + } |
|
1465 | + |
|
1466 | + /** |
|
1467 | + * @return \OCP\Files\Config\IMountProviderCollection |
|
1468 | + */ |
|
1469 | + public function getMountProviderCollection() { |
|
1470 | + return $this->query('MountConfigManager'); |
|
1471 | + } |
|
1472 | + |
|
1473 | + /** |
|
1474 | + * Get the IniWrapper |
|
1475 | + * |
|
1476 | + * @return IniGetWrapper |
|
1477 | + */ |
|
1478 | + public function getIniWrapper() { |
|
1479 | + return $this->query('IniWrapper'); |
|
1480 | + } |
|
1481 | + |
|
1482 | + /** |
|
1483 | + * @return \OCP\Command\IBus |
|
1484 | + */ |
|
1485 | + public function getCommandBus() { |
|
1486 | + return $this->query('AsyncCommandBus'); |
|
1487 | + } |
|
1488 | + |
|
1489 | + /** |
|
1490 | + * Get the trusted domain helper |
|
1491 | + * |
|
1492 | + * @return TrustedDomainHelper |
|
1493 | + */ |
|
1494 | + public function getTrustedDomainHelper() { |
|
1495 | + return $this->query('TrustedDomainHelper'); |
|
1496 | + } |
|
1497 | + |
|
1498 | + /** |
|
1499 | + * Get the locking provider |
|
1500 | + * |
|
1501 | + * @return \OCP\Lock\ILockingProvider |
|
1502 | + * @since 8.1.0 |
|
1503 | + */ |
|
1504 | + public function getLockingProvider() { |
|
1505 | + return $this->query('LockingProvider'); |
|
1506 | + } |
|
1507 | + |
|
1508 | + /** |
|
1509 | + * @return \OCP\Files\Mount\IMountManager |
|
1510 | + **/ |
|
1511 | + function getMountManager() { |
|
1512 | + return $this->query('MountManager'); |
|
1513 | + } |
|
1514 | + |
|
1515 | + /** @return \OCP\Files\Config\IUserMountCache */ |
|
1516 | + function getUserMountCache() { |
|
1517 | + return $this->query('UserMountCache'); |
|
1518 | + } |
|
1519 | + |
|
1520 | + /** |
|
1521 | + * Get the MimeTypeDetector |
|
1522 | + * |
|
1523 | + * @return \OCP\Files\IMimeTypeDetector |
|
1524 | + */ |
|
1525 | + public function getMimeTypeDetector() { |
|
1526 | + return $this->query('MimeTypeDetector'); |
|
1527 | + } |
|
1528 | + |
|
1529 | + /** |
|
1530 | + * Get the MimeTypeLoader |
|
1531 | + * |
|
1532 | + * @return \OCP\Files\IMimeTypeLoader |
|
1533 | + */ |
|
1534 | + public function getMimeTypeLoader() { |
|
1535 | + return $this->query('MimeTypeLoader'); |
|
1536 | + } |
|
1537 | + |
|
1538 | + /** |
|
1539 | + * Get the manager of all the capabilities |
|
1540 | + * |
|
1541 | + * @return \OC\CapabilitiesManager |
|
1542 | + */ |
|
1543 | + public function getCapabilitiesManager() { |
|
1544 | + return $this->query('CapabilitiesManager'); |
|
1545 | + } |
|
1546 | + |
|
1547 | + /** |
|
1548 | + * Get the EventDispatcher |
|
1549 | + * |
|
1550 | + * @return EventDispatcherInterface |
|
1551 | + * @since 8.2.0 |
|
1552 | + */ |
|
1553 | + public function getEventDispatcher() { |
|
1554 | + return $this->query('EventDispatcher'); |
|
1555 | + } |
|
1556 | + |
|
1557 | + /** |
|
1558 | + * Get the Notification Manager |
|
1559 | + * |
|
1560 | + * @return \OCP\Notification\IManager |
|
1561 | + * @since 8.2.0 |
|
1562 | + */ |
|
1563 | + public function getNotificationManager() { |
|
1564 | + return $this->query('NotificationManager'); |
|
1565 | + } |
|
1566 | + |
|
1567 | + /** |
|
1568 | + * @return \OCP\Comments\ICommentsManager |
|
1569 | + */ |
|
1570 | + public function getCommentsManager() { |
|
1571 | + return $this->query('CommentsManager'); |
|
1572 | + } |
|
1573 | + |
|
1574 | + /** |
|
1575 | + * @return \OCA\Theming\ThemingDefaults |
|
1576 | + */ |
|
1577 | + public function getThemingDefaults() { |
|
1578 | + return $this->query('ThemingDefaults'); |
|
1579 | + } |
|
1580 | + |
|
1581 | + /** |
|
1582 | + * @return \OC\IntegrityCheck\Checker |
|
1583 | + */ |
|
1584 | + public function getIntegrityCodeChecker() { |
|
1585 | + return $this->query('IntegrityCodeChecker'); |
|
1586 | + } |
|
1587 | + |
|
1588 | + /** |
|
1589 | + * @return \OC\Session\CryptoWrapper |
|
1590 | + */ |
|
1591 | + public function getSessionCryptoWrapper() { |
|
1592 | + return $this->query('CryptoWrapper'); |
|
1593 | + } |
|
1594 | + |
|
1595 | + /** |
|
1596 | + * @return CsrfTokenManager |
|
1597 | + */ |
|
1598 | + public function getCsrfTokenManager() { |
|
1599 | + return $this->query('CsrfTokenManager'); |
|
1600 | + } |
|
1601 | + |
|
1602 | + /** |
|
1603 | + * @return Throttler |
|
1604 | + */ |
|
1605 | + public function getBruteForceThrottler() { |
|
1606 | + return $this->query('Throttler'); |
|
1607 | + } |
|
1608 | + |
|
1609 | + /** |
|
1610 | + * @return IContentSecurityPolicyManager |
|
1611 | + */ |
|
1612 | + public function getContentSecurityPolicyManager() { |
|
1613 | + return $this->query('ContentSecurityPolicyManager'); |
|
1614 | + } |
|
1615 | + |
|
1616 | + /** |
|
1617 | + * @return ContentSecurityPolicyNonceManager |
|
1618 | + */ |
|
1619 | + public function getContentSecurityPolicyNonceManager() { |
|
1620 | + return $this->query('ContentSecurityPolicyNonceManager'); |
|
1621 | + } |
|
1622 | + |
|
1623 | + /** |
|
1624 | + * Not a public API as of 8.2, wait for 9.0 |
|
1625 | + * |
|
1626 | + * @return \OCA\Files_External\Service\BackendService |
|
1627 | + */ |
|
1628 | + public function getStoragesBackendService() { |
|
1629 | + return $this->query('OCA\\Files_External\\Service\\BackendService'); |
|
1630 | + } |
|
1631 | + |
|
1632 | + /** |
|
1633 | + * Not a public API as of 8.2, wait for 9.0 |
|
1634 | + * |
|
1635 | + * @return \OCA\Files_External\Service\GlobalStoragesService |
|
1636 | + */ |
|
1637 | + public function getGlobalStoragesService() { |
|
1638 | + return $this->query('OCA\\Files_External\\Service\\GlobalStoragesService'); |
|
1639 | + } |
|
1640 | + |
|
1641 | + /** |
|
1642 | + * Not a public API as of 8.2, wait for 9.0 |
|
1643 | + * |
|
1644 | + * @return \OCA\Files_External\Service\UserGlobalStoragesService |
|
1645 | + */ |
|
1646 | + public function getUserGlobalStoragesService() { |
|
1647 | + return $this->query('OCA\\Files_External\\Service\\UserGlobalStoragesService'); |
|
1648 | + } |
|
1649 | + |
|
1650 | + /** |
|
1651 | + * Not a public API as of 8.2, wait for 9.0 |
|
1652 | + * |
|
1653 | + * @return \OCA\Files_External\Service\UserStoragesService |
|
1654 | + */ |
|
1655 | + public function getUserStoragesService() { |
|
1656 | + return $this->query('OCA\\Files_External\\Service\\UserStoragesService'); |
|
1657 | + } |
|
1658 | + |
|
1659 | + /** |
|
1660 | + * @return \OCP\Share\IManager |
|
1661 | + */ |
|
1662 | + public function getShareManager() { |
|
1663 | + return $this->query('ShareManager'); |
|
1664 | + } |
|
1665 | + |
|
1666 | + /** |
|
1667 | + * Returns the LDAP Provider |
|
1668 | + * |
|
1669 | + * @return \OCP\LDAP\ILDAPProvider |
|
1670 | + */ |
|
1671 | + public function getLDAPProvider() { |
|
1672 | + return $this->query('LDAPProvider'); |
|
1673 | + } |
|
1674 | + |
|
1675 | + /** |
|
1676 | + * @return \OCP\Settings\IManager |
|
1677 | + */ |
|
1678 | + public function getSettingsManager() { |
|
1679 | + return $this->query('SettingsManager'); |
|
1680 | + } |
|
1681 | + |
|
1682 | + /** |
|
1683 | + * @return \OCP\Files\IAppData |
|
1684 | + */ |
|
1685 | + public function getAppDataDir($app) { |
|
1686 | + /** @var \OC\Files\AppData\Factory $factory */ |
|
1687 | + $factory = $this->query(\OC\Files\AppData\Factory::class); |
|
1688 | + return $factory->get($app); |
|
1689 | + } |
|
1690 | + |
|
1691 | + /** |
|
1692 | + * @return \OCP\Lockdown\ILockdownManager |
|
1693 | + */ |
|
1694 | + public function getLockdownManager() { |
|
1695 | + return $this->query('LockdownManager'); |
|
1696 | + } |
|
1697 | + |
|
1698 | + /** |
|
1699 | + * @return \OCP\Federation\ICloudIdManager |
|
1700 | + */ |
|
1701 | + public function getCloudIdManager() { |
|
1702 | + return $this->query(ICloudIdManager::class); |
|
1703 | + } |
|
1704 | 1704 | } |
@@ -49,62 +49,62 @@ |
||
49 | 49 | * $plainContent = $emailTemplate->renderText(); |
50 | 50 | */ |
51 | 51 | interface IEMailTemplate { |
52 | - /** |
|
53 | - * @param \OCA\Theming\ThemingDefaults $themingDefaults |
|
54 | - * @param \OCP\IURLGenerator $urlGenerator |
|
55 | - * @param \OCP\IL10N $l10n |
|
56 | - */ |
|
57 | - public function __construct(\OCA\Theming\ThemingDefaults $themingDefaults, |
|
58 | - \OCP\IURLGenerator $urlGenerator, |
|
59 | - \OCP\IL10N $l10n); |
|
52 | + /** |
|
53 | + * @param \OCA\Theming\ThemingDefaults $themingDefaults |
|
54 | + * @param \OCP\IURLGenerator $urlGenerator |
|
55 | + * @param \OCP\IL10N $l10n |
|
56 | + */ |
|
57 | + public function __construct(\OCA\Theming\ThemingDefaults $themingDefaults, |
|
58 | + \OCP\IURLGenerator $urlGenerator, |
|
59 | + \OCP\IL10N $l10n); |
|
60 | 60 | |
61 | - /** |
|
62 | - * Adds a header to the email |
|
63 | - */ |
|
64 | - public function addHeader(); |
|
61 | + /** |
|
62 | + * Adds a header to the email |
|
63 | + */ |
|
64 | + public function addHeader(); |
|
65 | 65 | |
66 | - /** |
|
67 | - * Adds a heading to the email |
|
68 | - * |
|
69 | - * @param string $title |
|
70 | - */ |
|
71 | - public function addHeading($title); |
|
66 | + /** |
|
67 | + * Adds a heading to the email |
|
68 | + * |
|
69 | + * @param string $title |
|
70 | + */ |
|
71 | + public function addHeading($title); |
|
72 | 72 | |
73 | - /** |
|
74 | - * Adds a paragraph to the body of the email |
|
75 | - * |
|
76 | - * @param string $text |
|
77 | - */ |
|
78 | - public function addBodyText($text); |
|
73 | + /** |
|
74 | + * Adds a paragraph to the body of the email |
|
75 | + * |
|
76 | + * @param string $text |
|
77 | + */ |
|
78 | + public function addBodyText($text); |
|
79 | 79 | |
80 | - /** |
|
81 | - * Adds a button group of two buttons to the body of the email |
|
82 | - * |
|
83 | - * @param string $textLeft Text of left button |
|
84 | - * @param string $urlLeft URL of left button |
|
85 | - * @param string $textRight Text of right button |
|
86 | - * @param string $urlRight URL of right button |
|
87 | - */ |
|
88 | - public function addBodyButtonGroup($textLeft, $urlLeft, $textRight, $urlRight); |
|
80 | + /** |
|
81 | + * Adds a button group of two buttons to the body of the email |
|
82 | + * |
|
83 | + * @param string $textLeft Text of left button |
|
84 | + * @param string $urlLeft URL of left button |
|
85 | + * @param string $textRight Text of right button |
|
86 | + * @param string $urlRight URL of right button |
|
87 | + */ |
|
88 | + public function addBodyButtonGroup($textLeft, $urlLeft, $textRight, $urlRight); |
|
89 | 89 | |
90 | - /** |
|
91 | - * Adds a logo and a text to the footer. <br> in the text will be replaced by new lines in the plain text email |
|
92 | - * |
|
93 | - * @param string $text |
|
94 | - */ |
|
95 | - public function addFooter($text = ''); |
|
90 | + /** |
|
91 | + * Adds a logo and a text to the footer. <br> in the text will be replaced by new lines in the plain text email |
|
92 | + * |
|
93 | + * @param string $text |
|
94 | + */ |
|
95 | + public function addFooter($text = ''); |
|
96 | 96 | |
97 | - /** |
|
98 | - * Returns the rendered HTML email as string |
|
99 | - * |
|
100 | - * @return string |
|
101 | - */ |
|
102 | - public function renderHTML(); |
|
97 | + /** |
|
98 | + * Returns the rendered HTML email as string |
|
99 | + * |
|
100 | + * @return string |
|
101 | + */ |
|
102 | + public function renderHTML(); |
|
103 | 103 | |
104 | - /** |
|
105 | - * Returns the rendered plain text email as string |
|
106 | - * |
|
107 | - * @return string |
|
108 | - */ |
|
109 | - public function renderText(); |
|
104 | + /** |
|
105 | + * Returns the rendered plain text email as string |
|
106 | + * |
|
107 | + * @return string |
|
108 | + */ |
|
109 | + public function renderText(); |
|
110 | 110 | } |
@@ -38,25 +38,25 @@ discard block |
||
38 | 38 | * @package OC\Mail |
39 | 39 | */ |
40 | 40 | class EMailTemplate implements IEMailTemplate { |
41 | - /** @var ThemingDefaults */ |
|
42 | - protected $themingDefaults; |
|
43 | - /** @var IURLGenerator */ |
|
44 | - protected $urlGenerator; |
|
45 | - /** @var IL10N */ |
|
46 | - protected $l10n; |
|
47 | - |
|
48 | - /** @var string */ |
|
49 | - protected $htmlBody = ''; |
|
50 | - /** @var string */ |
|
51 | - protected $plainBody = ''; |
|
52 | - /** @var bool indicated if the footer is added */ |
|
53 | - protected $headerAdded = false; |
|
54 | - /** @var bool indicated if the body is already opened */ |
|
55 | - protected $bodyOpened = false; |
|
56 | - /** @var bool indicated if the footer is added */ |
|
57 | - protected $footerAdded = false; |
|
58 | - |
|
59 | - protected $head = <<<EOF |
|
41 | + /** @var ThemingDefaults */ |
|
42 | + protected $themingDefaults; |
|
43 | + /** @var IURLGenerator */ |
|
44 | + protected $urlGenerator; |
|
45 | + /** @var IL10N */ |
|
46 | + protected $l10n; |
|
47 | + |
|
48 | + /** @var string */ |
|
49 | + protected $htmlBody = ''; |
|
50 | + /** @var string */ |
|
51 | + protected $plainBody = ''; |
|
52 | + /** @var bool indicated if the footer is added */ |
|
53 | + protected $headerAdded = false; |
|
54 | + /** @var bool indicated if the body is already opened */ |
|
55 | + protected $bodyOpened = false; |
|
56 | + /** @var bool indicated if the footer is added */ |
|
57 | + protected $footerAdded = false; |
|
58 | + |
|
59 | + protected $head = <<<EOF |
|
60 | 60 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
61 | 61 | <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en" style="-webkit-font-smoothing:antialiased;background:#f3f3f3!important"> |
62 | 62 | <head> |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | <center data-parsed="" style="min-width:580px;width:100%"> |
75 | 75 | EOF; |
76 | 76 | |
77 | - protected $tail = <<<EOF |
|
77 | + protected $tail = <<<EOF |
|
78 | 78 | </center> |
79 | 79 | </td> |
80 | 80 | </tr> |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | </html> |
86 | 86 | EOF; |
87 | 87 | |
88 | - protected $header = <<<EOF |
|
88 | + protected $header = <<<EOF |
|
89 | 89 | <table align="center" class="wrapper header float-center" style="Margin:0 auto;background:#8a8a8a;background-color:%s;border-collapse:collapse;border-spacing:0;float:none;margin:0 auto;padding:0;text-align:center;vertical-align:top;width:100%%"> |
90 | 90 | <tr style="padding:0;text-align:left;vertical-align:top"> |
91 | 91 | <td class="wrapper-inner" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:20px;text-align:left;vertical-align:top;word-wrap:break-word"> |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | </table> |
119 | 119 | EOF; |
120 | 120 | |
121 | - protected $heading = <<<EOF |
|
121 | + protected $heading = <<<EOF |
|
122 | 122 | <table align="center" class="container main-heading float-center" style="Margin:0 auto;background:0 0!important;border-collapse:collapse;border-spacing:0;float:none;margin:0 auto;padding:0;text-align:center;vertical-align:top;width:580px"> |
123 | 123 | <tbody> |
124 | 124 | <tr style="padding:0;text-align:left;vertical-align:top"> |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | </table> |
138 | 138 | EOF; |
139 | 139 | |
140 | - protected $bodyBegin = <<<EOF |
|
140 | + protected $bodyBegin = <<<EOF |
|
141 | 141 | <table align="center" class="wrapper content float-center" style="Margin:0 auto;border-collapse:collapse;border-spacing:0;float:none;margin:0 auto;padding:0;text-align:center;vertical-align:top;width:100%"> |
142 | 142 | <tr style="padding:0;text-align:left;vertical-align:top"> |
143 | 143 | <td class="wrapper-inner" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word"> |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | </table> |
155 | 155 | EOF; |
156 | 156 | |
157 | - protected $bodyText = <<<EOF |
|
157 | + protected $bodyText = <<<EOF |
|
158 | 158 | <table class="row description" style="border-collapse:collapse;border-spacing:0;display:table;padding:0;position:relative;text-align:left;vertical-align:top;width:100%%"> |
159 | 159 | <tbody> |
160 | 160 | <tr style="padding:0;text-align:left;vertical-align:top"> |
@@ -173,7 +173,7 @@ discard block |
||
173 | 173 | </table> |
174 | 174 | EOF; |
175 | 175 | |
176 | - protected $buttonGroup = <<<EOF |
|
176 | + protected $buttonGroup = <<<EOF |
|
177 | 177 | <table class="spacer" style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%%"> |
178 | 178 | <tbody> |
179 | 179 | <tr style="padding:0;text-align:left;vertical-align:top"> |
@@ -226,7 +226,7 @@ discard block |
||
226 | 226 | </table> |
227 | 227 | EOF; |
228 | 228 | |
229 | - protected $bodyEnd = <<<EOF |
|
229 | + protected $bodyEnd = <<<EOF |
|
230 | 230 | |
231 | 231 | </td> |
232 | 232 | </tr> |
@@ -237,7 +237,7 @@ discard block |
||
237 | 237 | </table> |
238 | 238 | EOF; |
239 | 239 | |
240 | - protected $footer = <<<EOF |
|
240 | + protected $footer = <<<EOF |
|
241 | 241 | <table class="spacer float-center" style="Margin:0 auto;border-collapse:collapse;border-spacing:0;float:none;margin:0 auto;padding:0;text-align:center;vertical-align:top;width:100%%"> |
242 | 242 | <tbody> |
243 | 243 | <tr style="padding:0;text-align:left;vertical-align:top"> |
@@ -263,146 +263,146 @@ discard block |
||
263 | 263 | </table> |
264 | 264 | EOF; |
265 | 265 | |
266 | - /** |
|
267 | - * @param ThemingDefaults $themingDefaults |
|
268 | - * @param IURLGenerator $urlGenerator |
|
269 | - * @param IL10N $l10n |
|
270 | - */ |
|
271 | - public function __construct(ThemingDefaults $themingDefaults, |
|
272 | - IURLGenerator $urlGenerator, |
|
273 | - IL10N $l10n) { |
|
274 | - $this->themingDefaults = $themingDefaults; |
|
275 | - $this->urlGenerator = $urlGenerator; |
|
276 | - $this->l10n = $l10n; |
|
277 | - $this->htmlBody .= $this->head; |
|
278 | - } |
|
279 | - |
|
280 | - /** |
|
281 | - * Adds a header to the email |
|
282 | - */ |
|
283 | - public function addHeader() { |
|
284 | - if ($this->headerAdded) { |
|
285 | - return; |
|
286 | - } |
|
287 | - $this->headerAdded = true; |
|
288 | - |
|
289 | - $logoUrl = $this->urlGenerator->getAbsoluteURL($this->themingDefaults->getLogo()) . '?v='. $this->themingDefaults->getCacheBusterCounter(); |
|
290 | - $this->htmlBody .= vsprintf($this->header, [$this->themingDefaults->getColorPrimary(), $logoUrl]); |
|
291 | - } |
|
292 | - |
|
293 | - /** |
|
294 | - * Adds a heading to the email |
|
295 | - * |
|
296 | - * @param string $title |
|
297 | - */ |
|
298 | - public function addHeading($title) { |
|
299 | - if ($this->footerAdded) { |
|
300 | - return; |
|
301 | - } |
|
302 | - |
|
303 | - $this->htmlBody .= vsprintf($this->heading, [$title]); |
|
304 | - $this->plainBody .= $title . PHP_EOL . PHP_EOL; |
|
305 | - } |
|
306 | - |
|
307 | - /** |
|
308 | - * Adds a paragraph to the body of the email |
|
309 | - * |
|
310 | - * @param string $text |
|
311 | - */ |
|
312 | - public function addBodyText($text) { |
|
313 | - if ($this->footerAdded) { |
|
314 | - return; |
|
315 | - } |
|
316 | - |
|
317 | - if (!$this->bodyOpened) { |
|
318 | - $this->htmlBody .= $this->bodyBegin; |
|
319 | - $this->bodyOpened = true; |
|
320 | - } |
|
321 | - |
|
322 | - $this->htmlBody .= vsprintf($this->bodyText, [$text]); |
|
323 | - $this->plainBody .= $text . PHP_EOL . PHP_EOL; |
|
324 | - } |
|
325 | - |
|
326 | - /** |
|
327 | - * Adds a button group of two buttons to the body of the email |
|
328 | - * |
|
329 | - * @param string $textLeft Text of left button |
|
330 | - * @param string $urlLeft URL of left button |
|
331 | - * @param string $textRight Text of right button |
|
332 | - * @param string $urlRight URL of right button |
|
333 | - */ |
|
334 | - public function addBodyButtonGroup($textLeft, $urlLeft, $textRight, $urlRight) { |
|
335 | - if ($this->footerAdded) { |
|
336 | - return; |
|
337 | - } |
|
338 | - |
|
339 | - if (!$this->bodyOpened) { |
|
340 | - $this->htmlBody .= $this->bodyBegin; |
|
341 | - $this->bodyOpened = true; |
|
342 | - } |
|
343 | - |
|
344 | - $color = $this->themingDefaults->getColorPrimary(); |
|
345 | - $this->htmlBody .= vsprintf($this->buttonGroup, [$color, $color, $urlLeft, $color, $textLeft, $urlRight, $textRight]); |
|
346 | - $this->plainBody .= $textLeft . ': ' . $urlLeft . PHP_EOL; |
|
347 | - $this->plainBody .= $textRight . ': ' . $urlRight . PHP_EOL . PHP_EOL; |
|
348 | - |
|
349 | - } |
|
350 | - |
|
351 | - /** |
|
352 | - * Adds a logo and a text to the footer. <br> in the text will be replaced by new lines in the plain text email |
|
353 | - * |
|
354 | - * @param string $text |
|
355 | - */ |
|
356 | - public function addFooter($text = '') { |
|
357 | - if($text === '') { |
|
358 | - $text = $this->themingDefaults->getName() . ' - ' . $this->themingDefaults->getSlogan() . '<br>' . $this->l10n->t('This is an automatically generated email, please do not reply.'); |
|
359 | - } |
|
360 | - |
|
361 | - if ($this->footerAdded) { |
|
362 | - return; |
|
363 | - } |
|
364 | - $this->footerAdded = true; |
|
365 | - |
|
366 | - if ($this->bodyOpened) { |
|
367 | - $this->htmlBody .= $this->bodyEnd; |
|
368 | - $this->bodyOpened = false; |
|
369 | - } |
|
370 | - |
|
371 | - $this->htmlBody .= vsprintf($this->footer, [$text]); |
|
372 | - $this->htmlBody .= $this->tail; |
|
373 | - $this->plainBody .= '--' . PHP_EOL; |
|
374 | - $this->plainBody .= str_replace('<br>', PHP_EOL, $text); |
|
375 | - } |
|
376 | - |
|
377 | - /** |
|
378 | - * Returns the rendered HTML email as string |
|
379 | - * |
|
380 | - * @return string |
|
381 | - */ |
|
382 | - public function renderHTML() { |
|
383 | - if (!$this->footerAdded) { |
|
384 | - $this->footerAdded = true; |
|
385 | - if ($this->bodyOpened) { |
|
386 | - $this->htmlBody .= $this->bodyEnd; |
|
387 | - } |
|
388 | - $this->htmlBody .= $this->tail; |
|
389 | - } |
|
390 | - return $this->htmlBody; |
|
391 | - } |
|
392 | - |
|
393 | - /** |
|
394 | - * Returns the rendered plain text email as string |
|
395 | - * |
|
396 | - * @return string |
|
397 | - */ |
|
398 | - public function renderText() { |
|
399 | - if (!$this->footerAdded) { |
|
400 | - $this->footerAdded = true; |
|
401 | - if ($this->bodyOpened) { |
|
402 | - $this->htmlBody .= $this->bodyEnd; |
|
403 | - } |
|
404 | - $this->htmlBody .= $this->tail; |
|
405 | - } |
|
406 | - return $this->plainBody; |
|
407 | - } |
|
266 | + /** |
|
267 | + * @param ThemingDefaults $themingDefaults |
|
268 | + * @param IURLGenerator $urlGenerator |
|
269 | + * @param IL10N $l10n |
|
270 | + */ |
|
271 | + public function __construct(ThemingDefaults $themingDefaults, |
|
272 | + IURLGenerator $urlGenerator, |
|
273 | + IL10N $l10n) { |
|
274 | + $this->themingDefaults = $themingDefaults; |
|
275 | + $this->urlGenerator = $urlGenerator; |
|
276 | + $this->l10n = $l10n; |
|
277 | + $this->htmlBody .= $this->head; |
|
278 | + } |
|
279 | + |
|
280 | + /** |
|
281 | + * Adds a header to the email |
|
282 | + */ |
|
283 | + public function addHeader() { |
|
284 | + if ($this->headerAdded) { |
|
285 | + return; |
|
286 | + } |
|
287 | + $this->headerAdded = true; |
|
288 | + |
|
289 | + $logoUrl = $this->urlGenerator->getAbsoluteURL($this->themingDefaults->getLogo()) . '?v='. $this->themingDefaults->getCacheBusterCounter(); |
|
290 | + $this->htmlBody .= vsprintf($this->header, [$this->themingDefaults->getColorPrimary(), $logoUrl]); |
|
291 | + } |
|
292 | + |
|
293 | + /** |
|
294 | + * Adds a heading to the email |
|
295 | + * |
|
296 | + * @param string $title |
|
297 | + */ |
|
298 | + public function addHeading($title) { |
|
299 | + if ($this->footerAdded) { |
|
300 | + return; |
|
301 | + } |
|
302 | + |
|
303 | + $this->htmlBody .= vsprintf($this->heading, [$title]); |
|
304 | + $this->plainBody .= $title . PHP_EOL . PHP_EOL; |
|
305 | + } |
|
306 | + |
|
307 | + /** |
|
308 | + * Adds a paragraph to the body of the email |
|
309 | + * |
|
310 | + * @param string $text |
|
311 | + */ |
|
312 | + public function addBodyText($text) { |
|
313 | + if ($this->footerAdded) { |
|
314 | + return; |
|
315 | + } |
|
316 | + |
|
317 | + if (!$this->bodyOpened) { |
|
318 | + $this->htmlBody .= $this->bodyBegin; |
|
319 | + $this->bodyOpened = true; |
|
320 | + } |
|
321 | + |
|
322 | + $this->htmlBody .= vsprintf($this->bodyText, [$text]); |
|
323 | + $this->plainBody .= $text . PHP_EOL . PHP_EOL; |
|
324 | + } |
|
325 | + |
|
326 | + /** |
|
327 | + * Adds a button group of two buttons to the body of the email |
|
328 | + * |
|
329 | + * @param string $textLeft Text of left button |
|
330 | + * @param string $urlLeft URL of left button |
|
331 | + * @param string $textRight Text of right button |
|
332 | + * @param string $urlRight URL of right button |
|
333 | + */ |
|
334 | + public function addBodyButtonGroup($textLeft, $urlLeft, $textRight, $urlRight) { |
|
335 | + if ($this->footerAdded) { |
|
336 | + return; |
|
337 | + } |
|
338 | + |
|
339 | + if (!$this->bodyOpened) { |
|
340 | + $this->htmlBody .= $this->bodyBegin; |
|
341 | + $this->bodyOpened = true; |
|
342 | + } |
|
343 | + |
|
344 | + $color = $this->themingDefaults->getColorPrimary(); |
|
345 | + $this->htmlBody .= vsprintf($this->buttonGroup, [$color, $color, $urlLeft, $color, $textLeft, $urlRight, $textRight]); |
|
346 | + $this->plainBody .= $textLeft . ': ' . $urlLeft . PHP_EOL; |
|
347 | + $this->plainBody .= $textRight . ': ' . $urlRight . PHP_EOL . PHP_EOL; |
|
348 | + |
|
349 | + } |
|
350 | + |
|
351 | + /** |
|
352 | + * Adds a logo and a text to the footer. <br> in the text will be replaced by new lines in the plain text email |
|
353 | + * |
|
354 | + * @param string $text |
|
355 | + */ |
|
356 | + public function addFooter($text = '') { |
|
357 | + if($text === '') { |
|
358 | + $text = $this->themingDefaults->getName() . ' - ' . $this->themingDefaults->getSlogan() . '<br>' . $this->l10n->t('This is an automatically generated email, please do not reply.'); |
|
359 | + } |
|
360 | + |
|
361 | + if ($this->footerAdded) { |
|
362 | + return; |
|
363 | + } |
|
364 | + $this->footerAdded = true; |
|
365 | + |
|
366 | + if ($this->bodyOpened) { |
|
367 | + $this->htmlBody .= $this->bodyEnd; |
|
368 | + $this->bodyOpened = false; |
|
369 | + } |
|
370 | + |
|
371 | + $this->htmlBody .= vsprintf($this->footer, [$text]); |
|
372 | + $this->htmlBody .= $this->tail; |
|
373 | + $this->plainBody .= '--' . PHP_EOL; |
|
374 | + $this->plainBody .= str_replace('<br>', PHP_EOL, $text); |
|
375 | + } |
|
376 | + |
|
377 | + /** |
|
378 | + * Returns the rendered HTML email as string |
|
379 | + * |
|
380 | + * @return string |
|
381 | + */ |
|
382 | + public function renderHTML() { |
|
383 | + if (!$this->footerAdded) { |
|
384 | + $this->footerAdded = true; |
|
385 | + if ($this->bodyOpened) { |
|
386 | + $this->htmlBody .= $this->bodyEnd; |
|
387 | + } |
|
388 | + $this->htmlBody .= $this->tail; |
|
389 | + } |
|
390 | + return $this->htmlBody; |
|
391 | + } |
|
392 | + |
|
393 | + /** |
|
394 | + * Returns the rendered plain text email as string |
|
395 | + * |
|
396 | + * @return string |
|
397 | + */ |
|
398 | + public function renderText() { |
|
399 | + if (!$this->footerAdded) { |
|
400 | + $this->footerAdded = true; |
|
401 | + if ($this->bodyOpened) { |
|
402 | + $this->htmlBody .= $this->bodyEnd; |
|
403 | + } |
|
404 | + $this->htmlBody .= $this->tail; |
|
405 | + } |
|
406 | + return $this->plainBody; |
|
407 | + } |
|
408 | 408 | } |
@@ -286,7 +286,7 @@ discard block |
||
286 | 286 | } |
287 | 287 | $this->headerAdded = true; |
288 | 288 | |
289 | - $logoUrl = $this->urlGenerator->getAbsoluteURL($this->themingDefaults->getLogo()) . '?v='. $this->themingDefaults->getCacheBusterCounter(); |
|
289 | + $logoUrl = $this->urlGenerator->getAbsoluteURL($this->themingDefaults->getLogo()).'?v='.$this->themingDefaults->getCacheBusterCounter(); |
|
290 | 290 | $this->htmlBody .= vsprintf($this->header, [$this->themingDefaults->getColorPrimary(), $logoUrl]); |
291 | 291 | } |
292 | 292 | |
@@ -301,7 +301,7 @@ discard block |
||
301 | 301 | } |
302 | 302 | |
303 | 303 | $this->htmlBody .= vsprintf($this->heading, [$title]); |
304 | - $this->plainBody .= $title . PHP_EOL . PHP_EOL; |
|
304 | + $this->plainBody .= $title.PHP_EOL.PHP_EOL; |
|
305 | 305 | } |
306 | 306 | |
307 | 307 | /** |
@@ -320,7 +320,7 @@ discard block |
||
320 | 320 | } |
321 | 321 | |
322 | 322 | $this->htmlBody .= vsprintf($this->bodyText, [$text]); |
323 | - $this->plainBody .= $text . PHP_EOL . PHP_EOL; |
|
323 | + $this->plainBody .= $text.PHP_EOL.PHP_EOL; |
|
324 | 324 | } |
325 | 325 | |
326 | 326 | /** |
@@ -343,8 +343,8 @@ discard block |
||
343 | 343 | |
344 | 344 | $color = $this->themingDefaults->getColorPrimary(); |
345 | 345 | $this->htmlBody .= vsprintf($this->buttonGroup, [$color, $color, $urlLeft, $color, $textLeft, $urlRight, $textRight]); |
346 | - $this->plainBody .= $textLeft . ': ' . $urlLeft . PHP_EOL; |
|
347 | - $this->plainBody .= $textRight . ': ' . $urlRight . PHP_EOL . PHP_EOL; |
|
346 | + $this->plainBody .= $textLeft.': '.$urlLeft.PHP_EOL; |
|
347 | + $this->plainBody .= $textRight.': '.$urlRight.PHP_EOL.PHP_EOL; |
|
348 | 348 | |
349 | 349 | } |
350 | 350 | |
@@ -354,8 +354,8 @@ discard block |
||
354 | 354 | * @param string $text |
355 | 355 | */ |
356 | 356 | public function addFooter($text = '') { |
357 | - if($text === '') { |
|
358 | - $text = $this->themingDefaults->getName() . ' - ' . $this->themingDefaults->getSlogan() . '<br>' . $this->l10n->t('This is an automatically generated email, please do not reply.'); |
|
357 | + if ($text === '') { |
|
358 | + $text = $this->themingDefaults->getName().' - '.$this->themingDefaults->getSlogan().'<br>'.$this->l10n->t('This is an automatically generated email, please do not reply.'); |
|
359 | 359 | } |
360 | 360 | |
361 | 361 | if ($this->footerAdded) { |
@@ -370,7 +370,7 @@ discard block |
||
370 | 370 | |
371 | 371 | $this->htmlBody .= vsprintf($this->footer, [$text]); |
372 | 372 | $this->htmlBody .= $this->tail; |
373 | - $this->plainBody .= '--' . PHP_EOL; |
|
373 | + $this->plainBody .= '--'.PHP_EOL; |
|
374 | 374 | $this->plainBody .= str_replace('<br>', PHP_EOL, $text); |
375 | 375 | } |
376 | 376 |
@@ -34,133 +34,133 @@ |
||
34 | 34 | use OCP\Security\ISecureRandom; |
35 | 35 | |
36 | 36 | class NewUserMailHelper { |
37 | - /** @var ThemingDefaults */ |
|
38 | - private $themingDefaults; |
|
39 | - /** @var IURLGenerator */ |
|
40 | - private $urlGenerator; |
|
41 | - /** @var IL10N */ |
|
42 | - private $l10n; |
|
43 | - /** @var IMailer */ |
|
44 | - private $mailer; |
|
45 | - /** @var ISecureRandom */ |
|
46 | - private $secureRandom; |
|
47 | - /** @var ITimeFactory */ |
|
48 | - private $timeFactory; |
|
49 | - /** @var IConfig */ |
|
50 | - private $config; |
|
51 | - /** @var ICrypto */ |
|
52 | - private $crypto; |
|
53 | - /** @var string */ |
|
54 | - private $fromAddress; |
|
37 | + /** @var ThemingDefaults */ |
|
38 | + private $themingDefaults; |
|
39 | + /** @var IURLGenerator */ |
|
40 | + private $urlGenerator; |
|
41 | + /** @var IL10N */ |
|
42 | + private $l10n; |
|
43 | + /** @var IMailer */ |
|
44 | + private $mailer; |
|
45 | + /** @var ISecureRandom */ |
|
46 | + private $secureRandom; |
|
47 | + /** @var ITimeFactory */ |
|
48 | + private $timeFactory; |
|
49 | + /** @var IConfig */ |
|
50 | + private $config; |
|
51 | + /** @var ICrypto */ |
|
52 | + private $crypto; |
|
53 | + /** @var string */ |
|
54 | + private $fromAddress; |
|
55 | 55 | |
56 | - /** |
|
57 | - * @param ThemingDefaults $themingDefaults |
|
58 | - * @param IURLGenerator $urlGenerator |
|
59 | - * @param IL10N $l10n |
|
60 | - * @param IMailer $mailer |
|
61 | - * @param ISecureRandom $secureRandom |
|
62 | - * @param ITimeFactory $timeFactory |
|
63 | - * @param IConfig $config |
|
64 | - * @param ICrypto $crypto |
|
65 | - * @param string $fromAddress |
|
66 | - */ |
|
67 | - public function __construct(ThemingDefaults $themingDefaults, |
|
68 | - IURLGenerator $urlGenerator, |
|
69 | - IL10N $l10n, |
|
70 | - IMailer $mailer, |
|
71 | - ISecureRandom $secureRandom, |
|
72 | - ITimeFactory $timeFactory, |
|
73 | - IConfig $config, |
|
74 | - ICrypto $crypto, |
|
75 | - $fromAddress) { |
|
76 | - $this->themingDefaults = $themingDefaults; |
|
77 | - $this->urlGenerator = $urlGenerator; |
|
78 | - $this->l10n = $l10n; |
|
79 | - $this->mailer = $mailer; |
|
80 | - $this->secureRandom = $secureRandom; |
|
81 | - $this->timeFactory = $timeFactory; |
|
82 | - $this->config = $config; |
|
83 | - $this->crypto = $crypto; |
|
84 | - $this->fromAddress = $fromAddress; |
|
85 | - } |
|
56 | + /** |
|
57 | + * @param ThemingDefaults $themingDefaults |
|
58 | + * @param IURLGenerator $urlGenerator |
|
59 | + * @param IL10N $l10n |
|
60 | + * @param IMailer $mailer |
|
61 | + * @param ISecureRandom $secureRandom |
|
62 | + * @param ITimeFactory $timeFactory |
|
63 | + * @param IConfig $config |
|
64 | + * @param ICrypto $crypto |
|
65 | + * @param string $fromAddress |
|
66 | + */ |
|
67 | + public function __construct(ThemingDefaults $themingDefaults, |
|
68 | + IURLGenerator $urlGenerator, |
|
69 | + IL10N $l10n, |
|
70 | + IMailer $mailer, |
|
71 | + ISecureRandom $secureRandom, |
|
72 | + ITimeFactory $timeFactory, |
|
73 | + IConfig $config, |
|
74 | + ICrypto $crypto, |
|
75 | + $fromAddress) { |
|
76 | + $this->themingDefaults = $themingDefaults; |
|
77 | + $this->urlGenerator = $urlGenerator; |
|
78 | + $this->l10n = $l10n; |
|
79 | + $this->mailer = $mailer; |
|
80 | + $this->secureRandom = $secureRandom; |
|
81 | + $this->timeFactory = $timeFactory; |
|
82 | + $this->config = $config; |
|
83 | + $this->crypto = $crypto; |
|
84 | + $this->fromAddress = $fromAddress; |
|
85 | + } |
|
86 | 86 | |
87 | - /** |
|
88 | - * Set the IL10N object |
|
89 | - * |
|
90 | - * @param IL10N $l10n |
|
91 | - */ |
|
92 | - public function setL10N(IL10N $l10n) { |
|
93 | - $this->l10n = $l10n; |
|
94 | - } |
|
87 | + /** |
|
88 | + * Set the IL10N object |
|
89 | + * |
|
90 | + * @param IL10N $l10n |
|
91 | + */ |
|
92 | + public function setL10N(IL10N $l10n) { |
|
93 | + $this->l10n = $l10n; |
|
94 | + } |
|
95 | 95 | |
96 | - /** |
|
97 | - * @param IUser $user |
|
98 | - * @param bool $generatePasswordResetToken |
|
99 | - * @return EMailTemplate |
|
100 | - */ |
|
101 | - public function generateTemplate(IUser $user, $generatePasswordResetToken = false) { |
|
102 | - if ($generatePasswordResetToken) { |
|
103 | - $token = $this->secureRandom->generate( |
|
104 | - 21, |
|
105 | - ISecureRandom::CHAR_DIGITS . |
|
106 | - ISecureRandom::CHAR_LOWER . |
|
107 | - ISecureRandom::CHAR_UPPER |
|
108 | - ); |
|
109 | - $tokenValue = $this->timeFactory->getTime() . ':' . $token; |
|
110 | - $mailAddress = (null !== $user->getEMailAddress()) ? $user->getEMailAddress() : ''; |
|
111 | - $encryptedValue = $this->crypto->encrypt($tokenValue, $mailAddress . $this->config->getSystemValue('secret')); |
|
112 | - $this->config->setUserValue($user->getUID(), 'core', 'lostpassword', $encryptedValue); |
|
113 | - $link = $this->urlGenerator->linkToRouteAbsolute('core.lost.resetform', ['userId' => $user->getUID(), 'token' => $token]); |
|
114 | - } else { |
|
115 | - $link = $this->urlGenerator->getAbsoluteURL('/'); |
|
116 | - } |
|
96 | + /** |
|
97 | + * @param IUser $user |
|
98 | + * @param bool $generatePasswordResetToken |
|
99 | + * @return EMailTemplate |
|
100 | + */ |
|
101 | + public function generateTemplate(IUser $user, $generatePasswordResetToken = false) { |
|
102 | + if ($generatePasswordResetToken) { |
|
103 | + $token = $this->secureRandom->generate( |
|
104 | + 21, |
|
105 | + ISecureRandom::CHAR_DIGITS . |
|
106 | + ISecureRandom::CHAR_LOWER . |
|
107 | + ISecureRandom::CHAR_UPPER |
|
108 | + ); |
|
109 | + $tokenValue = $this->timeFactory->getTime() . ':' . $token; |
|
110 | + $mailAddress = (null !== $user->getEMailAddress()) ? $user->getEMailAddress() : ''; |
|
111 | + $encryptedValue = $this->crypto->encrypt($tokenValue, $mailAddress . $this->config->getSystemValue('secret')); |
|
112 | + $this->config->setUserValue($user->getUID(), 'core', 'lostpassword', $encryptedValue); |
|
113 | + $link = $this->urlGenerator->linkToRouteAbsolute('core.lost.resetform', ['userId' => $user->getUID(), 'token' => $token]); |
|
114 | + } else { |
|
115 | + $link = $this->urlGenerator->getAbsoluteURL('/'); |
|
116 | + } |
|
117 | 117 | |
118 | - $emailTemplate = new EMailTemplate( |
|
119 | - $this->themingDefaults, |
|
120 | - $this->urlGenerator, |
|
121 | - $this->l10n |
|
122 | - ); |
|
123 | - $emailTemplate->addHeader(); |
|
124 | - $displayName = $user->getDisplayName(); |
|
125 | - $userName = $user->getUID(); |
|
126 | - if ($displayName === $userName) { |
|
127 | - $emailTemplate->addHeading($this->l10n->t('Welcome aboard')); |
|
128 | - } else { |
|
129 | - $emailTemplate->addHeading($this->l10n->t('Welcome aboard %s', [$displayName])); |
|
130 | - } |
|
131 | - $emailTemplate->addBodyText($this->l10n->t('You have now an %s account, you can add, protect, and share your data.', [$this->themingDefaults->getName()])); |
|
132 | - $emailTemplate->addBodyText($this->l10n->t('Your username is: %s', [$userName])); |
|
133 | - if ($generatePasswordResetToken) { |
|
134 | - $leftButtonText = $this->l10n->t('Set your password'); |
|
135 | - } else { |
|
136 | - $leftButtonText = $this->l10n->t('Go to %s', [$this->themingDefaults->getName()]); |
|
137 | - } |
|
138 | - $emailTemplate->addBodyButtonGroup( |
|
139 | - $leftButtonText, |
|
140 | - $link, |
|
141 | - $this->l10n->t('Install Client'), |
|
142 | - 'https://nextcloud.com/install/#install-clients' |
|
143 | - ); |
|
144 | - $emailTemplate->addFooter(); |
|
118 | + $emailTemplate = new EMailTemplate( |
|
119 | + $this->themingDefaults, |
|
120 | + $this->urlGenerator, |
|
121 | + $this->l10n |
|
122 | + ); |
|
123 | + $emailTemplate->addHeader(); |
|
124 | + $displayName = $user->getDisplayName(); |
|
125 | + $userName = $user->getUID(); |
|
126 | + if ($displayName === $userName) { |
|
127 | + $emailTemplate->addHeading($this->l10n->t('Welcome aboard')); |
|
128 | + } else { |
|
129 | + $emailTemplate->addHeading($this->l10n->t('Welcome aboard %s', [$displayName])); |
|
130 | + } |
|
131 | + $emailTemplate->addBodyText($this->l10n->t('You have now an %s account, you can add, protect, and share your data.', [$this->themingDefaults->getName()])); |
|
132 | + $emailTemplate->addBodyText($this->l10n->t('Your username is: %s', [$userName])); |
|
133 | + if ($generatePasswordResetToken) { |
|
134 | + $leftButtonText = $this->l10n->t('Set your password'); |
|
135 | + } else { |
|
136 | + $leftButtonText = $this->l10n->t('Go to %s', [$this->themingDefaults->getName()]); |
|
137 | + } |
|
138 | + $emailTemplate->addBodyButtonGroup( |
|
139 | + $leftButtonText, |
|
140 | + $link, |
|
141 | + $this->l10n->t('Install Client'), |
|
142 | + 'https://nextcloud.com/install/#install-clients' |
|
143 | + ); |
|
144 | + $emailTemplate->addFooter(); |
|
145 | 145 | |
146 | - return $emailTemplate; |
|
147 | - } |
|
146 | + return $emailTemplate; |
|
147 | + } |
|
148 | 148 | |
149 | - /** |
|
150 | - * Sends a welcome mail to $user |
|
151 | - * |
|
152 | - * @param IUser $user |
|
153 | - * @param IEmailTemplate $emailTemplate |
|
154 | - * @throws \Exception If mail could not be sent |
|
155 | - */ |
|
156 | - public function sendMail(IUser $user, |
|
157 | - IEMailTemplate $emailTemplate) { |
|
158 | - $message = $this->mailer->createMessage(); |
|
159 | - $message->setTo([$user->getEMailAddress() => $user->getDisplayName()]); |
|
160 | - $message->setSubject($this->l10n->t('Your %s account was created', [$this->themingDefaults->getName()])); |
|
161 | - $message->setHtmlBody($emailTemplate->renderHTML()); |
|
162 | - $message->setPlainBody($emailTemplate->renderText()); |
|
163 | - $message->setFrom([$this->fromAddress => $this->themingDefaults->getName()]); |
|
164 | - $this->mailer->send($message); |
|
165 | - } |
|
149 | + /** |
|
150 | + * Sends a welcome mail to $user |
|
151 | + * |
|
152 | + * @param IUser $user |
|
153 | + * @param IEmailTemplate $emailTemplate |
|
154 | + * @throws \Exception If mail could not be sent |
|
155 | + */ |
|
156 | + public function sendMail(IUser $user, |
|
157 | + IEMailTemplate $emailTemplate) { |
|
158 | + $message = $this->mailer->createMessage(); |
|
159 | + $message->setTo([$user->getEMailAddress() => $user->getDisplayName()]); |
|
160 | + $message->setSubject($this->l10n->t('Your %s account was created', [$this->themingDefaults->getName()])); |
|
161 | + $message->setHtmlBody($emailTemplate->renderHTML()); |
|
162 | + $message->setPlainBody($emailTemplate->renderText()); |
|
163 | + $message->setFrom([$this->fromAddress => $this->themingDefaults->getName()]); |
|
164 | + $this->mailer->send($message); |
|
165 | + } |
|
166 | 166 | } |
@@ -102,13 +102,13 @@ |
||
102 | 102 | if ($generatePasswordResetToken) { |
103 | 103 | $token = $this->secureRandom->generate( |
104 | 104 | 21, |
105 | - ISecureRandom::CHAR_DIGITS . |
|
106 | - ISecureRandom::CHAR_LOWER . |
|
105 | + ISecureRandom::CHAR_DIGITS. |
|
106 | + ISecureRandom::CHAR_LOWER. |
|
107 | 107 | ISecureRandom::CHAR_UPPER |
108 | 108 | ); |
109 | - $tokenValue = $this->timeFactory->getTime() . ':' . $token; |
|
109 | + $tokenValue = $this->timeFactory->getTime().':'.$token; |
|
110 | 110 | $mailAddress = (null !== $user->getEMailAddress()) ? $user->getEMailAddress() : ''; |
111 | - $encryptedValue = $this->crypto->encrypt($tokenValue, $mailAddress . $this->config->getSystemValue('secret')); |
|
111 | + $encryptedValue = $this->crypto->encrypt($tokenValue, $mailAddress.$this->config->getSystemValue('secret')); |
|
112 | 112 | $this->config->setUserValue($user->getUID(), 'core', 'lostpassword', $encryptedValue); |
113 | 113 | $link = $this->urlGenerator->linkToRouteAbsolute('core.lost.resetform', ['userId' => $user->getUID(), 'token' => $token]); |
114 | 114 | } else { |
@@ -54,754 +54,754 @@ |
||
54 | 54 | * @package OC\Settings\Controller |
55 | 55 | */ |
56 | 56 | class UsersController extends Controller { |
57 | - /** @var IL10N */ |
|
58 | - private $l10n; |
|
59 | - /** @var IUserSession */ |
|
60 | - private $userSession; |
|
61 | - /** @var bool */ |
|
62 | - private $isAdmin; |
|
63 | - /** @var IUserManager */ |
|
64 | - private $userManager; |
|
65 | - /** @var IGroupManager */ |
|
66 | - private $groupManager; |
|
67 | - /** @var IConfig */ |
|
68 | - private $config; |
|
69 | - /** @var ILogger */ |
|
70 | - private $log; |
|
71 | - /** @var IMailer */ |
|
72 | - private $mailer; |
|
73 | - /** @var bool contains the state of the encryption app */ |
|
74 | - private $isEncryptionAppEnabled; |
|
75 | - /** @var bool contains the state of the admin recovery setting */ |
|
76 | - private $isRestoreEnabled = false; |
|
77 | - /** @var IAvatarManager */ |
|
78 | - private $avatarManager; |
|
79 | - /** @var AccountManager */ |
|
80 | - private $accountManager; |
|
81 | - /** @var ISecureRandom */ |
|
82 | - private $secureRandom; |
|
83 | - /** @var NewUserMailHelper */ |
|
84 | - private $newUserMailHelper; |
|
85 | - |
|
86 | - /** |
|
87 | - * @param string $appName |
|
88 | - * @param IRequest $request |
|
89 | - * @param IUserManager $userManager |
|
90 | - * @param IGroupManager $groupManager |
|
91 | - * @param IUserSession $userSession |
|
92 | - * @param IConfig $config |
|
93 | - * @param bool $isAdmin |
|
94 | - * @param IL10N $l10n |
|
95 | - * @param ILogger $log |
|
96 | - * @param IMailer $mailer |
|
97 | - * @param IURLGenerator $urlGenerator |
|
98 | - * @param IAppManager $appManager |
|
99 | - * @param IAvatarManager $avatarManager |
|
100 | - * @param AccountManager $accountManager |
|
101 | - * @param ISecureRandom $secureRandom |
|
102 | - * @param NewUserMailHelper $newUserMailHelper |
|
103 | - */ |
|
104 | - public function __construct($appName, |
|
105 | - IRequest $request, |
|
106 | - IUserManager $userManager, |
|
107 | - IGroupManager $groupManager, |
|
108 | - IUserSession $userSession, |
|
109 | - IConfig $config, |
|
110 | - $isAdmin, |
|
111 | - IL10N $l10n, |
|
112 | - ILogger $log, |
|
113 | - IMailer $mailer, |
|
114 | - IURLGenerator $urlGenerator, |
|
115 | - IAppManager $appManager, |
|
116 | - IAvatarManager $avatarManager, |
|
117 | - AccountManager $accountManager, |
|
118 | - ISecureRandom $secureRandom, |
|
119 | - NewUserMailHelper $newUserMailHelper) { |
|
120 | - parent::__construct($appName, $request); |
|
121 | - $this->userManager = $userManager; |
|
122 | - $this->groupManager = $groupManager; |
|
123 | - $this->userSession = $userSession; |
|
124 | - $this->config = $config; |
|
125 | - $this->isAdmin = $isAdmin; |
|
126 | - $this->l10n = $l10n; |
|
127 | - $this->log = $log; |
|
128 | - $this->mailer = $mailer; |
|
129 | - $this->avatarManager = $avatarManager; |
|
130 | - $this->accountManager = $accountManager; |
|
131 | - $this->secureRandom = $secureRandom; |
|
132 | - $this->newUserMailHelper = $newUserMailHelper; |
|
133 | - |
|
134 | - // check for encryption state - TODO see formatUserForIndex |
|
135 | - $this->isEncryptionAppEnabled = $appManager->isEnabledForUser('encryption'); |
|
136 | - if($this->isEncryptionAppEnabled) { |
|
137 | - // putting this directly in empty is possible in PHP 5.5+ |
|
138 | - $result = $config->getAppValue('encryption', 'recoveryAdminEnabled', 0); |
|
139 | - $this->isRestoreEnabled = !empty($result); |
|
140 | - } |
|
141 | - } |
|
142 | - |
|
143 | - /** |
|
144 | - * @param IUser $user |
|
145 | - * @param array $userGroups |
|
146 | - * @return array |
|
147 | - */ |
|
148 | - private function formatUserForIndex(IUser $user, array $userGroups = null) { |
|
149 | - |
|
150 | - // TODO: eliminate this encryption specific code below and somehow |
|
151 | - // hook in additional user info from other apps |
|
152 | - |
|
153 | - // recovery isn't possible if admin or user has it disabled and encryption |
|
154 | - // is enabled - so we eliminate the else paths in the conditional tree |
|
155 | - // below |
|
156 | - $restorePossible = false; |
|
157 | - |
|
158 | - if ($this->isEncryptionAppEnabled) { |
|
159 | - if ($this->isRestoreEnabled) { |
|
160 | - // check for the users recovery setting |
|
161 | - $recoveryMode = $this->config->getUserValue($user->getUID(), 'encryption', 'recoveryEnabled', '0'); |
|
162 | - // method call inside empty is possible with PHP 5.5+ |
|
163 | - $recoveryModeEnabled = !empty($recoveryMode); |
|
164 | - if ($recoveryModeEnabled) { |
|
165 | - // user also has recovery mode enabled |
|
166 | - $restorePossible = true; |
|
167 | - } |
|
168 | - } |
|
169 | - } else { |
|
170 | - // recovery is possible if encryption is disabled (plain files are |
|
171 | - // available) |
|
172 | - $restorePossible = true; |
|
173 | - } |
|
174 | - |
|
175 | - $subAdminGroups = $this->groupManager->getSubAdmin()->getSubAdminsGroups($user); |
|
176 | - foreach($subAdminGroups as $key => $subAdminGroup) { |
|
177 | - $subAdminGroups[$key] = $subAdminGroup->getGID(); |
|
178 | - } |
|
179 | - |
|
180 | - $displayName = $user->getEMailAddress(); |
|
181 | - if (is_null($displayName)) { |
|
182 | - $displayName = ''; |
|
183 | - } |
|
184 | - |
|
185 | - $avatarAvailable = false; |
|
186 | - try { |
|
187 | - $avatarAvailable = $this->avatarManager->getAvatar($user->getUID())->exists(); |
|
188 | - } catch (\Exception $e) { |
|
189 | - //No avatar yet |
|
190 | - } |
|
191 | - |
|
192 | - return [ |
|
193 | - 'name' => $user->getUID(), |
|
194 | - 'displayname' => $user->getDisplayName(), |
|
195 | - 'groups' => (empty($userGroups)) ? $this->groupManager->getUserGroupIds($user) : $userGroups, |
|
196 | - 'subadmin' => $subAdminGroups, |
|
197 | - 'quota' => $user->getQuota(), |
|
198 | - 'storageLocation' => $user->getHome(), |
|
199 | - 'lastLogin' => $user->getLastLogin() * 1000, |
|
200 | - 'backend' => $user->getBackendClassName(), |
|
201 | - 'email' => $displayName, |
|
202 | - 'isRestoreDisabled' => !$restorePossible, |
|
203 | - 'isAvatarAvailable' => $avatarAvailable, |
|
204 | - ]; |
|
205 | - } |
|
206 | - |
|
207 | - /** |
|
208 | - * @param array $userIDs Array with schema [$uid => $displayName] |
|
209 | - * @return IUser[] |
|
210 | - */ |
|
211 | - private function getUsersForUID(array $userIDs) { |
|
212 | - $users = []; |
|
213 | - foreach ($userIDs as $uid => $displayName) { |
|
214 | - $users[$uid] = $this->userManager->get($uid); |
|
215 | - } |
|
216 | - return $users; |
|
217 | - } |
|
218 | - |
|
219 | - /** |
|
220 | - * @NoAdminRequired |
|
221 | - * |
|
222 | - * @param int $offset |
|
223 | - * @param int $limit |
|
224 | - * @param string $gid GID to filter for |
|
225 | - * @param string $pattern Pattern to search for in the username |
|
226 | - * @param string $backend Backend to filter for (class-name) |
|
227 | - * @return DataResponse |
|
228 | - * |
|
229 | - * TODO: Tidy up and write unit tests - code is mainly static method calls |
|
230 | - */ |
|
231 | - public function index($offset = 0, $limit = 10, $gid = '', $pattern = '', $backend = '') { |
|
232 | - // FIXME: The JS sends the group '_everyone' instead of no GID for the "all users" group. |
|
233 | - if($gid === '_everyone') { |
|
234 | - $gid = ''; |
|
235 | - } |
|
236 | - |
|
237 | - // Remove backends |
|
238 | - if(!empty($backend)) { |
|
239 | - $activeBackends = $this->userManager->getBackends(); |
|
240 | - $this->userManager->clearBackends(); |
|
241 | - foreach($activeBackends as $singleActiveBackend) { |
|
242 | - if($backend === get_class($singleActiveBackend)) { |
|
243 | - $this->userManager->registerBackend($singleActiveBackend); |
|
244 | - break; |
|
245 | - } |
|
246 | - } |
|
247 | - } |
|
248 | - |
|
249 | - $users = []; |
|
250 | - if ($this->isAdmin) { |
|
251 | - |
|
252 | - if($gid !== '') { |
|
253 | - $batch = $this->getUsersForUID($this->groupManager->displayNamesInGroup($gid, $pattern, $limit, $offset)); |
|
254 | - } else { |
|
255 | - $batch = $this->userManager->search($pattern, $limit, $offset); |
|
256 | - } |
|
257 | - |
|
258 | - foreach ($batch as $user) { |
|
259 | - $users[] = $this->formatUserForIndex($user); |
|
260 | - } |
|
261 | - |
|
262 | - } else { |
|
263 | - $subAdminOfGroups = $this->groupManager->getSubAdmin()->getSubAdminsGroups($this->userSession->getUser()); |
|
264 | - // New class returns IGroup[] so convert back |
|
265 | - $gids = []; |
|
266 | - foreach ($subAdminOfGroups as $group) { |
|
267 | - $gids[] = $group->getGID(); |
|
268 | - } |
|
269 | - $subAdminOfGroups = $gids; |
|
270 | - |
|
271 | - // Set the $gid parameter to an empty value if the subadmin has no rights to access a specific group |
|
272 | - if($gid !== '' && !in_array($gid, $subAdminOfGroups)) { |
|
273 | - $gid = ''; |
|
274 | - } |
|
275 | - |
|
276 | - // Batch all groups the user is subadmin of when a group is specified |
|
277 | - $batch = []; |
|
278 | - if($gid === '') { |
|
279 | - foreach($subAdminOfGroups as $group) { |
|
280 | - $groupUsers = $this->groupManager->displayNamesInGroup($group, $pattern, $limit, $offset); |
|
281 | - |
|
282 | - foreach($groupUsers as $uid => $displayName) { |
|
283 | - $batch[$uid] = $displayName; |
|
284 | - } |
|
285 | - } |
|
286 | - } else { |
|
287 | - $batch = $this->groupManager->displayNamesInGroup($gid, $pattern, $limit, $offset); |
|
288 | - } |
|
289 | - $batch = $this->getUsersForUID($batch); |
|
290 | - |
|
291 | - foreach ($batch as $user) { |
|
292 | - // Only add the groups, this user is a subadmin of |
|
293 | - $userGroups = array_values(array_intersect( |
|
294 | - $this->groupManager->getUserGroupIds($user), |
|
295 | - $subAdminOfGroups |
|
296 | - )); |
|
297 | - $users[] = $this->formatUserForIndex($user, $userGroups); |
|
298 | - } |
|
299 | - } |
|
300 | - |
|
301 | - return new DataResponse($users); |
|
302 | - } |
|
303 | - |
|
304 | - /** |
|
305 | - * @NoAdminRequired |
|
306 | - * @PasswordConfirmationRequired |
|
307 | - * |
|
308 | - * @param string $username |
|
309 | - * @param string $password |
|
310 | - * @param array $groups |
|
311 | - * @param string $email |
|
312 | - * @return DataResponse |
|
313 | - */ |
|
314 | - public function create($username, $password, array $groups=array(), $email='') { |
|
315 | - if($email !== '' && !$this->mailer->validateMailAddress($email)) { |
|
316 | - return new DataResponse( |
|
317 | - array( |
|
318 | - 'message' => (string)$this->l10n->t('Invalid mail address') |
|
319 | - ), |
|
320 | - Http::STATUS_UNPROCESSABLE_ENTITY |
|
321 | - ); |
|
322 | - } |
|
323 | - |
|
324 | - $currentUser = $this->userSession->getUser(); |
|
325 | - |
|
326 | - if (!$this->isAdmin) { |
|
327 | - if (!empty($groups)) { |
|
328 | - foreach ($groups as $key => $group) { |
|
329 | - $groupObject = $this->groupManager->get($group); |
|
330 | - if($groupObject === null) { |
|
331 | - unset($groups[$key]); |
|
332 | - continue; |
|
333 | - } |
|
334 | - |
|
335 | - if (!$this->groupManager->getSubAdmin()->isSubAdminofGroup($currentUser, $groupObject)) { |
|
336 | - unset($groups[$key]); |
|
337 | - } |
|
338 | - } |
|
339 | - } |
|
340 | - |
|
341 | - if (empty($groups)) { |
|
342 | - return new DataResponse( |
|
343 | - array( |
|
344 | - 'message' => $this->l10n->t('No valid group selected'), |
|
345 | - ), |
|
346 | - Http::STATUS_FORBIDDEN |
|
347 | - ); |
|
348 | - } |
|
349 | - } |
|
350 | - |
|
351 | - if ($this->userManager->userExists($username)) { |
|
352 | - return new DataResponse( |
|
353 | - array( |
|
354 | - 'message' => (string)$this->l10n->t('A user with that name already exists.') |
|
355 | - ), |
|
356 | - Http::STATUS_CONFLICT |
|
357 | - ); |
|
358 | - } |
|
359 | - |
|
360 | - $generatePasswordResetToken = false; |
|
361 | - if ($password === '') { |
|
362 | - if ($email === '') { |
|
363 | - return new DataResponse( |
|
364 | - array( |
|
365 | - 'message' => (string)$this->l10n->t('To send a password link to the user an email address is required.') |
|
366 | - ), |
|
367 | - Http::STATUS_UNPROCESSABLE_ENTITY |
|
368 | - ); |
|
369 | - } |
|
370 | - |
|
371 | - $password = $this->secureRandom->generate(32); |
|
372 | - $generatePasswordResetToken = true; |
|
373 | - } |
|
374 | - |
|
375 | - try { |
|
376 | - $user = $this->userManager->createUser($username, $password); |
|
377 | - } catch (\Exception $exception) { |
|
378 | - $message = $exception->getMessage(); |
|
379 | - if (!$message) { |
|
380 | - $message = $this->l10n->t('Unable to create user.'); |
|
381 | - } |
|
382 | - return new DataResponse( |
|
383 | - array( |
|
384 | - 'message' => (string) $message, |
|
385 | - ), |
|
386 | - Http::STATUS_FORBIDDEN |
|
387 | - ); |
|
388 | - } |
|
389 | - |
|
390 | - if($user instanceof IUser) { |
|
391 | - if($groups !== null) { |
|
392 | - foreach($groups as $groupName) { |
|
393 | - $group = $this->groupManager->get($groupName); |
|
394 | - |
|
395 | - if(empty($group)) { |
|
396 | - $group = $this->groupManager->createGroup($groupName); |
|
397 | - } |
|
398 | - $group->addUser($user); |
|
399 | - } |
|
400 | - } |
|
401 | - /** |
|
402 | - * Send new user mail only if a mail is set |
|
403 | - */ |
|
404 | - if($email !== '') { |
|
405 | - $user->setEMailAddress($email); |
|
406 | - try { |
|
407 | - $emailTemplate = $this->newUserMailHelper->generateTemplate($user, $generatePasswordResetToken); |
|
408 | - $this->newUserMailHelper->sendMail($user, $emailTemplate); |
|
409 | - } catch(\Exception $e) { |
|
410 | - $this->log->error("Can't send new user mail to $email: " . $e->getMessage(), array('app' => 'settings')); |
|
411 | - } |
|
412 | - } |
|
413 | - // fetch users groups |
|
414 | - $userGroups = $this->groupManager->getUserGroupIds($user); |
|
415 | - |
|
416 | - return new DataResponse( |
|
417 | - $this->formatUserForIndex($user, $userGroups), |
|
418 | - Http::STATUS_CREATED |
|
419 | - ); |
|
420 | - } |
|
421 | - |
|
422 | - return new DataResponse( |
|
423 | - array( |
|
424 | - 'message' => (string)$this->l10n->t('Unable to create user.') |
|
425 | - ), |
|
426 | - Http::STATUS_FORBIDDEN |
|
427 | - ); |
|
428 | - |
|
429 | - } |
|
430 | - |
|
431 | - /** |
|
432 | - * @NoAdminRequired |
|
433 | - * @PasswordConfirmationRequired |
|
434 | - * |
|
435 | - * @param string $id |
|
436 | - * @return DataResponse |
|
437 | - */ |
|
438 | - public function destroy($id) { |
|
439 | - $userId = $this->userSession->getUser()->getUID(); |
|
440 | - $user = $this->userManager->get($id); |
|
441 | - |
|
442 | - if($userId === $id) { |
|
443 | - return new DataResponse( |
|
444 | - array( |
|
445 | - 'status' => 'error', |
|
446 | - 'data' => array( |
|
447 | - 'message' => (string)$this->l10n->t('Unable to delete user.') |
|
448 | - ) |
|
449 | - ), |
|
450 | - Http::STATUS_FORBIDDEN |
|
451 | - ); |
|
452 | - } |
|
453 | - |
|
454 | - if(!$this->isAdmin && !$this->groupManager->getSubAdmin()->isUserAccessible($this->userSession->getUser(), $user)) { |
|
455 | - return new DataResponse( |
|
456 | - array( |
|
457 | - 'status' => 'error', |
|
458 | - 'data' => array( |
|
459 | - 'message' => (string)$this->l10n->t('Authentication error') |
|
460 | - ) |
|
461 | - ), |
|
462 | - Http::STATUS_FORBIDDEN |
|
463 | - ); |
|
464 | - } |
|
465 | - |
|
466 | - if($user) { |
|
467 | - if($user->delete()) { |
|
468 | - return new DataResponse( |
|
469 | - array( |
|
470 | - 'status' => 'success', |
|
471 | - 'data' => array( |
|
472 | - 'username' => $id |
|
473 | - ) |
|
474 | - ), |
|
475 | - Http::STATUS_NO_CONTENT |
|
476 | - ); |
|
477 | - } |
|
478 | - } |
|
479 | - |
|
480 | - return new DataResponse( |
|
481 | - array( |
|
482 | - 'status' => 'error', |
|
483 | - 'data' => array( |
|
484 | - 'message' => (string)$this->l10n->t('Unable to delete user.') |
|
485 | - ) |
|
486 | - ), |
|
487 | - Http::STATUS_FORBIDDEN |
|
488 | - ); |
|
489 | - } |
|
490 | - |
|
491 | - /** |
|
492 | - * @NoAdminRequired |
|
493 | - * @NoSubadminRequired |
|
494 | - * @PasswordConfirmationRequired |
|
495 | - * |
|
496 | - * @param string $avatarScope |
|
497 | - * @param string $displayname |
|
498 | - * @param string $displaynameScope |
|
499 | - * @param string $phone |
|
500 | - * @param string $phoneScope |
|
501 | - * @param string $email |
|
502 | - * @param string $emailScope |
|
503 | - * @param string $website |
|
504 | - * @param string $websiteScope |
|
505 | - * @param string $address |
|
506 | - * @param string $addressScope |
|
507 | - * @param string $twitter |
|
508 | - * @param string $twitterScope |
|
509 | - * @return DataResponse |
|
510 | - */ |
|
511 | - public function setUserSettings($avatarScope, |
|
512 | - $displayname, |
|
513 | - $displaynameScope, |
|
514 | - $phone, |
|
515 | - $phoneScope, |
|
516 | - $email, |
|
517 | - $emailScope, |
|
518 | - $website, |
|
519 | - $websiteScope, |
|
520 | - $address, |
|
521 | - $addressScope, |
|
522 | - $twitter, |
|
523 | - $twitterScope |
|
524 | - ) { |
|
525 | - |
|
526 | - if(!empty($email) && !$this->mailer->validateMailAddress($email)) { |
|
527 | - return new DataResponse( |
|
528 | - array( |
|
529 | - 'status' => 'error', |
|
530 | - 'data' => array( |
|
531 | - 'message' => (string)$this->l10n->t('Invalid mail address') |
|
532 | - ) |
|
533 | - ), |
|
534 | - Http::STATUS_UNPROCESSABLE_ENTITY |
|
535 | - ); |
|
536 | - } |
|
537 | - |
|
538 | - $data = [ |
|
539 | - AccountManager::PROPERTY_AVATAR => ['scope' => $avatarScope], |
|
540 | - AccountManager::PROPERTY_DISPLAYNAME => ['value' => $displayname, 'scope' => $displaynameScope], |
|
541 | - AccountManager::PROPERTY_EMAIL=> ['value' => $email, 'scope' => $emailScope], |
|
542 | - AccountManager::PROPERTY_WEBSITE => ['value' => $website, 'scope' => $websiteScope], |
|
543 | - AccountManager::PROPERTY_ADDRESS => ['value' => $address, 'scope' => $addressScope], |
|
544 | - AccountManager::PROPERTY_PHONE => ['value' => $phone, 'scope' => $phoneScope], |
|
545 | - AccountManager::PROPERTY_TWITTER => ['value' => $twitter, 'scope' => $twitterScope] |
|
546 | - ]; |
|
547 | - |
|
548 | - $user = $this->userSession->getUser(); |
|
549 | - |
|
550 | - try { |
|
551 | - $this->saveUserSettings($user, $data); |
|
552 | - return new DataResponse( |
|
553 | - array( |
|
554 | - 'status' => 'success', |
|
555 | - 'data' => array( |
|
556 | - 'userId' => $user->getUID(), |
|
557 | - 'avatarScope' => $avatarScope, |
|
558 | - 'displayname' => $displayname, |
|
559 | - 'displaynameScope' => $displaynameScope, |
|
560 | - 'email' => $email, |
|
561 | - 'emailScope' => $emailScope, |
|
562 | - 'website' => $website, |
|
563 | - 'websiteScope' => $websiteScope, |
|
564 | - 'address' => $address, |
|
565 | - 'addressScope' => $addressScope, |
|
566 | - 'message' => (string)$this->l10n->t('Settings saved') |
|
567 | - ) |
|
568 | - ), |
|
569 | - Http::STATUS_OK |
|
570 | - ); |
|
571 | - } catch (ForbiddenException $e) { |
|
572 | - return new DataResponse([ |
|
573 | - 'status' => 'error', |
|
574 | - 'data' => [ |
|
575 | - 'message' => $e->getMessage() |
|
576 | - ], |
|
577 | - ]); |
|
578 | - } |
|
579 | - |
|
580 | - } |
|
581 | - |
|
582 | - |
|
583 | - /** |
|
584 | - * update account manager with new user data |
|
585 | - * |
|
586 | - * @param IUser $user |
|
587 | - * @param array $data |
|
588 | - * @throws ForbiddenException |
|
589 | - */ |
|
590 | - protected function saveUserSettings(IUser $user, $data) { |
|
591 | - |
|
592 | - // keep the user back-end up-to-date with the latest display name and email |
|
593 | - // address |
|
594 | - $oldDisplayName = $user->getDisplayName(); |
|
595 | - $oldDisplayName = is_null($oldDisplayName) ? '' : $oldDisplayName; |
|
596 | - if (isset($data[AccountManager::PROPERTY_DISPLAYNAME]['value']) |
|
597 | - && $oldDisplayName !== $data[AccountManager::PROPERTY_DISPLAYNAME]['value'] |
|
598 | - ) { |
|
599 | - $result = $user->setDisplayName($data[AccountManager::PROPERTY_DISPLAYNAME]['value']); |
|
600 | - if ($result === false) { |
|
601 | - throw new ForbiddenException($this->l10n->t('Unable to change full name')); |
|
602 | - } |
|
603 | - } |
|
604 | - |
|
605 | - $oldEmailAddress = $user->getEMailAddress(); |
|
606 | - $oldEmailAddress = is_null($oldEmailAddress) ? '' : $oldEmailAddress; |
|
607 | - if (isset($data[AccountManager::PROPERTY_EMAIL]['value']) |
|
608 | - && $oldEmailAddress !== $data[AccountManager::PROPERTY_EMAIL]['value'] |
|
609 | - ) { |
|
610 | - // this is the only permission a backend provides and is also used |
|
611 | - // for the permission of setting a email address |
|
612 | - if (!$user->canChangeDisplayName()) { |
|
613 | - throw new ForbiddenException($this->l10n->t('Unable to change email address')); |
|
614 | - } |
|
615 | - $user->setEMailAddress($data[AccountManager::PROPERTY_EMAIL]['value']); |
|
616 | - } |
|
617 | - |
|
618 | - $this->accountManager->updateUser($user, $data); |
|
619 | - } |
|
620 | - |
|
621 | - /** |
|
622 | - * Count all unique users visible for the current admin/subadmin. |
|
623 | - * |
|
624 | - * @NoAdminRequired |
|
625 | - * |
|
626 | - * @return DataResponse |
|
627 | - */ |
|
628 | - public function stats() { |
|
629 | - $userCount = 0; |
|
630 | - if ($this->isAdmin) { |
|
631 | - $countByBackend = $this->userManager->countUsers(); |
|
632 | - |
|
633 | - if (!empty($countByBackend)) { |
|
634 | - foreach ($countByBackend as $count) { |
|
635 | - $userCount += $count; |
|
636 | - } |
|
637 | - } |
|
638 | - } else { |
|
639 | - $groups = $this->groupManager->getSubAdmin()->getSubAdminsGroups($this->userSession->getUser()); |
|
640 | - |
|
641 | - $uniqueUsers = []; |
|
642 | - foreach ($groups as $group) { |
|
643 | - foreach($group->getUsers() as $uid => $displayName) { |
|
644 | - $uniqueUsers[$uid] = true; |
|
645 | - } |
|
646 | - } |
|
647 | - |
|
648 | - $userCount = count($uniqueUsers); |
|
649 | - } |
|
650 | - |
|
651 | - return new DataResponse( |
|
652 | - [ |
|
653 | - 'totalUsers' => $userCount |
|
654 | - ] |
|
655 | - ); |
|
656 | - } |
|
657 | - |
|
658 | - |
|
659 | - /** |
|
660 | - * Set the displayName of a user |
|
661 | - * |
|
662 | - * @NoAdminRequired |
|
663 | - * @NoSubadminRequired |
|
664 | - * @PasswordConfirmationRequired |
|
665 | - * @todo merge into saveUserSettings |
|
666 | - * |
|
667 | - * @param string $username |
|
668 | - * @param string $displayName |
|
669 | - * @return DataResponse |
|
670 | - */ |
|
671 | - public function setDisplayName($username, $displayName) { |
|
672 | - $currentUser = $this->userSession->getUser(); |
|
673 | - $user = $this->userManager->get($username); |
|
674 | - |
|
675 | - if ($user === null || |
|
676 | - !$user->canChangeDisplayName() || |
|
677 | - ( |
|
678 | - !$this->groupManager->isAdmin($currentUser->getUID()) && |
|
679 | - !$this->groupManager->getSubAdmin()->isUserAccessible($currentUser, $user) && |
|
680 | - $currentUser->getUID() !== $username |
|
681 | - |
|
682 | - ) |
|
683 | - ) { |
|
684 | - return new DataResponse([ |
|
685 | - 'status' => 'error', |
|
686 | - 'data' => [ |
|
687 | - 'message' => $this->l10n->t('Authentication error'), |
|
688 | - ], |
|
689 | - ]); |
|
690 | - } |
|
691 | - |
|
692 | - $userData = $this->accountManager->getUser($user); |
|
693 | - $userData[AccountManager::PROPERTY_DISPLAYNAME]['value'] = $displayName; |
|
694 | - |
|
695 | - |
|
696 | - try { |
|
697 | - $this->saveUserSettings($user, $userData); |
|
698 | - return new DataResponse([ |
|
699 | - 'status' => 'success', |
|
700 | - 'data' => [ |
|
701 | - 'message' => $this->l10n->t('Your full name has been changed.'), |
|
702 | - 'username' => $username, |
|
703 | - 'displayName' => $displayName, |
|
704 | - ], |
|
705 | - ]); |
|
706 | - } catch (ForbiddenException $e) { |
|
707 | - return new DataResponse([ |
|
708 | - 'status' => 'error', |
|
709 | - 'data' => [ |
|
710 | - 'message' => $e->getMessage(), |
|
711 | - 'displayName' => $user->getDisplayName(), |
|
712 | - ], |
|
713 | - ]); |
|
714 | - } |
|
715 | - } |
|
716 | - |
|
717 | - /** |
|
718 | - * Set the mail address of a user |
|
719 | - * |
|
720 | - * @NoAdminRequired |
|
721 | - * @NoSubadminRequired |
|
722 | - * @PasswordConfirmationRequired |
|
723 | - * |
|
724 | - * @param string $id |
|
725 | - * @param string $mailAddress |
|
726 | - * @return DataResponse |
|
727 | - */ |
|
728 | - public function setEMailAddress($id, $mailAddress) { |
|
729 | - $user = $this->userManager->get($id); |
|
730 | - if (!$this->isAdmin |
|
731 | - && !$this->groupManager->getSubAdmin()->isUserAccessible($this->userSession->getUser(), $user) |
|
732 | - ) { |
|
733 | - return new DataResponse( |
|
734 | - array( |
|
735 | - 'status' => 'error', |
|
736 | - 'data' => array( |
|
737 | - 'message' => (string)$this->l10n->t('Forbidden') |
|
738 | - ) |
|
739 | - ), |
|
740 | - Http::STATUS_FORBIDDEN |
|
741 | - ); |
|
742 | - } |
|
743 | - |
|
744 | - if($mailAddress !== '' && !$this->mailer->validateMailAddress($mailAddress)) { |
|
745 | - return new DataResponse( |
|
746 | - array( |
|
747 | - 'status' => 'error', |
|
748 | - 'data' => array( |
|
749 | - 'message' => (string)$this->l10n->t('Invalid mail address') |
|
750 | - ) |
|
751 | - ), |
|
752 | - Http::STATUS_UNPROCESSABLE_ENTITY |
|
753 | - ); |
|
754 | - } |
|
755 | - |
|
756 | - if (!$user) { |
|
757 | - return new DataResponse( |
|
758 | - array( |
|
759 | - 'status' => 'error', |
|
760 | - 'data' => array( |
|
761 | - 'message' => (string)$this->l10n->t('Invalid user') |
|
762 | - ) |
|
763 | - ), |
|
764 | - Http::STATUS_UNPROCESSABLE_ENTITY |
|
765 | - ); |
|
766 | - } |
|
767 | - // this is the only permission a backend provides and is also used |
|
768 | - // for the permission of setting a email address |
|
769 | - if (!$user->canChangeDisplayName()) { |
|
770 | - return new DataResponse( |
|
771 | - array( |
|
772 | - 'status' => 'error', |
|
773 | - 'data' => array( |
|
774 | - 'message' => (string)$this->l10n->t('Unable to change mail address') |
|
775 | - ) |
|
776 | - ), |
|
777 | - Http::STATUS_FORBIDDEN |
|
778 | - ); |
|
779 | - } |
|
780 | - |
|
781 | - $userData = $this->accountManager->getUser($user); |
|
782 | - $userData[AccountManager::PROPERTY_EMAIL]['value'] = $mailAddress; |
|
783 | - |
|
784 | - try { |
|
785 | - $this->saveUserSettings($user, $userData); |
|
786 | - return new DataResponse( |
|
787 | - array( |
|
788 | - 'status' => 'success', |
|
789 | - 'data' => array( |
|
790 | - 'username' => $id, |
|
791 | - 'mailAddress' => $mailAddress, |
|
792 | - 'message' => (string)$this->l10n->t('Email saved') |
|
793 | - ) |
|
794 | - ), |
|
795 | - Http::STATUS_OK |
|
796 | - ); |
|
797 | - } catch (ForbiddenException $e) { |
|
798 | - return new DataResponse([ |
|
799 | - 'status' => 'error', |
|
800 | - 'data' => [ |
|
801 | - 'message' => $e->getMessage() |
|
802 | - ], |
|
803 | - ]); |
|
804 | - } |
|
805 | - } |
|
57 | + /** @var IL10N */ |
|
58 | + private $l10n; |
|
59 | + /** @var IUserSession */ |
|
60 | + private $userSession; |
|
61 | + /** @var bool */ |
|
62 | + private $isAdmin; |
|
63 | + /** @var IUserManager */ |
|
64 | + private $userManager; |
|
65 | + /** @var IGroupManager */ |
|
66 | + private $groupManager; |
|
67 | + /** @var IConfig */ |
|
68 | + private $config; |
|
69 | + /** @var ILogger */ |
|
70 | + private $log; |
|
71 | + /** @var IMailer */ |
|
72 | + private $mailer; |
|
73 | + /** @var bool contains the state of the encryption app */ |
|
74 | + private $isEncryptionAppEnabled; |
|
75 | + /** @var bool contains the state of the admin recovery setting */ |
|
76 | + private $isRestoreEnabled = false; |
|
77 | + /** @var IAvatarManager */ |
|
78 | + private $avatarManager; |
|
79 | + /** @var AccountManager */ |
|
80 | + private $accountManager; |
|
81 | + /** @var ISecureRandom */ |
|
82 | + private $secureRandom; |
|
83 | + /** @var NewUserMailHelper */ |
|
84 | + private $newUserMailHelper; |
|
85 | + |
|
86 | + /** |
|
87 | + * @param string $appName |
|
88 | + * @param IRequest $request |
|
89 | + * @param IUserManager $userManager |
|
90 | + * @param IGroupManager $groupManager |
|
91 | + * @param IUserSession $userSession |
|
92 | + * @param IConfig $config |
|
93 | + * @param bool $isAdmin |
|
94 | + * @param IL10N $l10n |
|
95 | + * @param ILogger $log |
|
96 | + * @param IMailer $mailer |
|
97 | + * @param IURLGenerator $urlGenerator |
|
98 | + * @param IAppManager $appManager |
|
99 | + * @param IAvatarManager $avatarManager |
|
100 | + * @param AccountManager $accountManager |
|
101 | + * @param ISecureRandom $secureRandom |
|
102 | + * @param NewUserMailHelper $newUserMailHelper |
|
103 | + */ |
|
104 | + public function __construct($appName, |
|
105 | + IRequest $request, |
|
106 | + IUserManager $userManager, |
|
107 | + IGroupManager $groupManager, |
|
108 | + IUserSession $userSession, |
|
109 | + IConfig $config, |
|
110 | + $isAdmin, |
|
111 | + IL10N $l10n, |
|
112 | + ILogger $log, |
|
113 | + IMailer $mailer, |
|
114 | + IURLGenerator $urlGenerator, |
|
115 | + IAppManager $appManager, |
|
116 | + IAvatarManager $avatarManager, |
|
117 | + AccountManager $accountManager, |
|
118 | + ISecureRandom $secureRandom, |
|
119 | + NewUserMailHelper $newUserMailHelper) { |
|
120 | + parent::__construct($appName, $request); |
|
121 | + $this->userManager = $userManager; |
|
122 | + $this->groupManager = $groupManager; |
|
123 | + $this->userSession = $userSession; |
|
124 | + $this->config = $config; |
|
125 | + $this->isAdmin = $isAdmin; |
|
126 | + $this->l10n = $l10n; |
|
127 | + $this->log = $log; |
|
128 | + $this->mailer = $mailer; |
|
129 | + $this->avatarManager = $avatarManager; |
|
130 | + $this->accountManager = $accountManager; |
|
131 | + $this->secureRandom = $secureRandom; |
|
132 | + $this->newUserMailHelper = $newUserMailHelper; |
|
133 | + |
|
134 | + // check for encryption state - TODO see formatUserForIndex |
|
135 | + $this->isEncryptionAppEnabled = $appManager->isEnabledForUser('encryption'); |
|
136 | + if($this->isEncryptionAppEnabled) { |
|
137 | + // putting this directly in empty is possible in PHP 5.5+ |
|
138 | + $result = $config->getAppValue('encryption', 'recoveryAdminEnabled', 0); |
|
139 | + $this->isRestoreEnabled = !empty($result); |
|
140 | + } |
|
141 | + } |
|
142 | + |
|
143 | + /** |
|
144 | + * @param IUser $user |
|
145 | + * @param array $userGroups |
|
146 | + * @return array |
|
147 | + */ |
|
148 | + private function formatUserForIndex(IUser $user, array $userGroups = null) { |
|
149 | + |
|
150 | + // TODO: eliminate this encryption specific code below and somehow |
|
151 | + // hook in additional user info from other apps |
|
152 | + |
|
153 | + // recovery isn't possible if admin or user has it disabled and encryption |
|
154 | + // is enabled - so we eliminate the else paths in the conditional tree |
|
155 | + // below |
|
156 | + $restorePossible = false; |
|
157 | + |
|
158 | + if ($this->isEncryptionAppEnabled) { |
|
159 | + if ($this->isRestoreEnabled) { |
|
160 | + // check for the users recovery setting |
|
161 | + $recoveryMode = $this->config->getUserValue($user->getUID(), 'encryption', 'recoveryEnabled', '0'); |
|
162 | + // method call inside empty is possible with PHP 5.5+ |
|
163 | + $recoveryModeEnabled = !empty($recoveryMode); |
|
164 | + if ($recoveryModeEnabled) { |
|
165 | + // user also has recovery mode enabled |
|
166 | + $restorePossible = true; |
|
167 | + } |
|
168 | + } |
|
169 | + } else { |
|
170 | + // recovery is possible if encryption is disabled (plain files are |
|
171 | + // available) |
|
172 | + $restorePossible = true; |
|
173 | + } |
|
174 | + |
|
175 | + $subAdminGroups = $this->groupManager->getSubAdmin()->getSubAdminsGroups($user); |
|
176 | + foreach($subAdminGroups as $key => $subAdminGroup) { |
|
177 | + $subAdminGroups[$key] = $subAdminGroup->getGID(); |
|
178 | + } |
|
179 | + |
|
180 | + $displayName = $user->getEMailAddress(); |
|
181 | + if (is_null($displayName)) { |
|
182 | + $displayName = ''; |
|
183 | + } |
|
184 | + |
|
185 | + $avatarAvailable = false; |
|
186 | + try { |
|
187 | + $avatarAvailable = $this->avatarManager->getAvatar($user->getUID())->exists(); |
|
188 | + } catch (\Exception $e) { |
|
189 | + //No avatar yet |
|
190 | + } |
|
191 | + |
|
192 | + return [ |
|
193 | + 'name' => $user->getUID(), |
|
194 | + 'displayname' => $user->getDisplayName(), |
|
195 | + 'groups' => (empty($userGroups)) ? $this->groupManager->getUserGroupIds($user) : $userGroups, |
|
196 | + 'subadmin' => $subAdminGroups, |
|
197 | + 'quota' => $user->getQuota(), |
|
198 | + 'storageLocation' => $user->getHome(), |
|
199 | + 'lastLogin' => $user->getLastLogin() * 1000, |
|
200 | + 'backend' => $user->getBackendClassName(), |
|
201 | + 'email' => $displayName, |
|
202 | + 'isRestoreDisabled' => !$restorePossible, |
|
203 | + 'isAvatarAvailable' => $avatarAvailable, |
|
204 | + ]; |
|
205 | + } |
|
206 | + |
|
207 | + /** |
|
208 | + * @param array $userIDs Array with schema [$uid => $displayName] |
|
209 | + * @return IUser[] |
|
210 | + */ |
|
211 | + private function getUsersForUID(array $userIDs) { |
|
212 | + $users = []; |
|
213 | + foreach ($userIDs as $uid => $displayName) { |
|
214 | + $users[$uid] = $this->userManager->get($uid); |
|
215 | + } |
|
216 | + return $users; |
|
217 | + } |
|
218 | + |
|
219 | + /** |
|
220 | + * @NoAdminRequired |
|
221 | + * |
|
222 | + * @param int $offset |
|
223 | + * @param int $limit |
|
224 | + * @param string $gid GID to filter for |
|
225 | + * @param string $pattern Pattern to search for in the username |
|
226 | + * @param string $backend Backend to filter for (class-name) |
|
227 | + * @return DataResponse |
|
228 | + * |
|
229 | + * TODO: Tidy up and write unit tests - code is mainly static method calls |
|
230 | + */ |
|
231 | + public function index($offset = 0, $limit = 10, $gid = '', $pattern = '', $backend = '') { |
|
232 | + // FIXME: The JS sends the group '_everyone' instead of no GID for the "all users" group. |
|
233 | + if($gid === '_everyone') { |
|
234 | + $gid = ''; |
|
235 | + } |
|
236 | + |
|
237 | + // Remove backends |
|
238 | + if(!empty($backend)) { |
|
239 | + $activeBackends = $this->userManager->getBackends(); |
|
240 | + $this->userManager->clearBackends(); |
|
241 | + foreach($activeBackends as $singleActiveBackend) { |
|
242 | + if($backend === get_class($singleActiveBackend)) { |
|
243 | + $this->userManager->registerBackend($singleActiveBackend); |
|
244 | + break; |
|
245 | + } |
|
246 | + } |
|
247 | + } |
|
248 | + |
|
249 | + $users = []; |
|
250 | + if ($this->isAdmin) { |
|
251 | + |
|
252 | + if($gid !== '') { |
|
253 | + $batch = $this->getUsersForUID($this->groupManager->displayNamesInGroup($gid, $pattern, $limit, $offset)); |
|
254 | + } else { |
|
255 | + $batch = $this->userManager->search($pattern, $limit, $offset); |
|
256 | + } |
|
257 | + |
|
258 | + foreach ($batch as $user) { |
|
259 | + $users[] = $this->formatUserForIndex($user); |
|
260 | + } |
|
261 | + |
|
262 | + } else { |
|
263 | + $subAdminOfGroups = $this->groupManager->getSubAdmin()->getSubAdminsGroups($this->userSession->getUser()); |
|
264 | + // New class returns IGroup[] so convert back |
|
265 | + $gids = []; |
|
266 | + foreach ($subAdminOfGroups as $group) { |
|
267 | + $gids[] = $group->getGID(); |
|
268 | + } |
|
269 | + $subAdminOfGroups = $gids; |
|
270 | + |
|
271 | + // Set the $gid parameter to an empty value if the subadmin has no rights to access a specific group |
|
272 | + if($gid !== '' && !in_array($gid, $subAdminOfGroups)) { |
|
273 | + $gid = ''; |
|
274 | + } |
|
275 | + |
|
276 | + // Batch all groups the user is subadmin of when a group is specified |
|
277 | + $batch = []; |
|
278 | + if($gid === '') { |
|
279 | + foreach($subAdminOfGroups as $group) { |
|
280 | + $groupUsers = $this->groupManager->displayNamesInGroup($group, $pattern, $limit, $offset); |
|
281 | + |
|
282 | + foreach($groupUsers as $uid => $displayName) { |
|
283 | + $batch[$uid] = $displayName; |
|
284 | + } |
|
285 | + } |
|
286 | + } else { |
|
287 | + $batch = $this->groupManager->displayNamesInGroup($gid, $pattern, $limit, $offset); |
|
288 | + } |
|
289 | + $batch = $this->getUsersForUID($batch); |
|
290 | + |
|
291 | + foreach ($batch as $user) { |
|
292 | + // Only add the groups, this user is a subadmin of |
|
293 | + $userGroups = array_values(array_intersect( |
|
294 | + $this->groupManager->getUserGroupIds($user), |
|
295 | + $subAdminOfGroups |
|
296 | + )); |
|
297 | + $users[] = $this->formatUserForIndex($user, $userGroups); |
|
298 | + } |
|
299 | + } |
|
300 | + |
|
301 | + return new DataResponse($users); |
|
302 | + } |
|
303 | + |
|
304 | + /** |
|
305 | + * @NoAdminRequired |
|
306 | + * @PasswordConfirmationRequired |
|
307 | + * |
|
308 | + * @param string $username |
|
309 | + * @param string $password |
|
310 | + * @param array $groups |
|
311 | + * @param string $email |
|
312 | + * @return DataResponse |
|
313 | + */ |
|
314 | + public function create($username, $password, array $groups=array(), $email='') { |
|
315 | + if($email !== '' && !$this->mailer->validateMailAddress($email)) { |
|
316 | + return new DataResponse( |
|
317 | + array( |
|
318 | + 'message' => (string)$this->l10n->t('Invalid mail address') |
|
319 | + ), |
|
320 | + Http::STATUS_UNPROCESSABLE_ENTITY |
|
321 | + ); |
|
322 | + } |
|
323 | + |
|
324 | + $currentUser = $this->userSession->getUser(); |
|
325 | + |
|
326 | + if (!$this->isAdmin) { |
|
327 | + if (!empty($groups)) { |
|
328 | + foreach ($groups as $key => $group) { |
|
329 | + $groupObject = $this->groupManager->get($group); |
|
330 | + if($groupObject === null) { |
|
331 | + unset($groups[$key]); |
|
332 | + continue; |
|
333 | + } |
|
334 | + |
|
335 | + if (!$this->groupManager->getSubAdmin()->isSubAdminofGroup($currentUser, $groupObject)) { |
|
336 | + unset($groups[$key]); |
|
337 | + } |
|
338 | + } |
|
339 | + } |
|
340 | + |
|
341 | + if (empty($groups)) { |
|
342 | + return new DataResponse( |
|
343 | + array( |
|
344 | + 'message' => $this->l10n->t('No valid group selected'), |
|
345 | + ), |
|
346 | + Http::STATUS_FORBIDDEN |
|
347 | + ); |
|
348 | + } |
|
349 | + } |
|
350 | + |
|
351 | + if ($this->userManager->userExists($username)) { |
|
352 | + return new DataResponse( |
|
353 | + array( |
|
354 | + 'message' => (string)$this->l10n->t('A user with that name already exists.') |
|
355 | + ), |
|
356 | + Http::STATUS_CONFLICT |
|
357 | + ); |
|
358 | + } |
|
359 | + |
|
360 | + $generatePasswordResetToken = false; |
|
361 | + if ($password === '') { |
|
362 | + if ($email === '') { |
|
363 | + return new DataResponse( |
|
364 | + array( |
|
365 | + 'message' => (string)$this->l10n->t('To send a password link to the user an email address is required.') |
|
366 | + ), |
|
367 | + Http::STATUS_UNPROCESSABLE_ENTITY |
|
368 | + ); |
|
369 | + } |
|
370 | + |
|
371 | + $password = $this->secureRandom->generate(32); |
|
372 | + $generatePasswordResetToken = true; |
|
373 | + } |
|
374 | + |
|
375 | + try { |
|
376 | + $user = $this->userManager->createUser($username, $password); |
|
377 | + } catch (\Exception $exception) { |
|
378 | + $message = $exception->getMessage(); |
|
379 | + if (!$message) { |
|
380 | + $message = $this->l10n->t('Unable to create user.'); |
|
381 | + } |
|
382 | + return new DataResponse( |
|
383 | + array( |
|
384 | + 'message' => (string) $message, |
|
385 | + ), |
|
386 | + Http::STATUS_FORBIDDEN |
|
387 | + ); |
|
388 | + } |
|
389 | + |
|
390 | + if($user instanceof IUser) { |
|
391 | + if($groups !== null) { |
|
392 | + foreach($groups as $groupName) { |
|
393 | + $group = $this->groupManager->get($groupName); |
|
394 | + |
|
395 | + if(empty($group)) { |
|
396 | + $group = $this->groupManager->createGroup($groupName); |
|
397 | + } |
|
398 | + $group->addUser($user); |
|
399 | + } |
|
400 | + } |
|
401 | + /** |
|
402 | + * Send new user mail only if a mail is set |
|
403 | + */ |
|
404 | + if($email !== '') { |
|
405 | + $user->setEMailAddress($email); |
|
406 | + try { |
|
407 | + $emailTemplate = $this->newUserMailHelper->generateTemplate($user, $generatePasswordResetToken); |
|
408 | + $this->newUserMailHelper->sendMail($user, $emailTemplate); |
|
409 | + } catch(\Exception $e) { |
|
410 | + $this->log->error("Can't send new user mail to $email: " . $e->getMessage(), array('app' => 'settings')); |
|
411 | + } |
|
412 | + } |
|
413 | + // fetch users groups |
|
414 | + $userGroups = $this->groupManager->getUserGroupIds($user); |
|
415 | + |
|
416 | + return new DataResponse( |
|
417 | + $this->formatUserForIndex($user, $userGroups), |
|
418 | + Http::STATUS_CREATED |
|
419 | + ); |
|
420 | + } |
|
421 | + |
|
422 | + return new DataResponse( |
|
423 | + array( |
|
424 | + 'message' => (string)$this->l10n->t('Unable to create user.') |
|
425 | + ), |
|
426 | + Http::STATUS_FORBIDDEN |
|
427 | + ); |
|
428 | + |
|
429 | + } |
|
430 | + |
|
431 | + /** |
|
432 | + * @NoAdminRequired |
|
433 | + * @PasswordConfirmationRequired |
|
434 | + * |
|
435 | + * @param string $id |
|
436 | + * @return DataResponse |
|
437 | + */ |
|
438 | + public function destroy($id) { |
|
439 | + $userId = $this->userSession->getUser()->getUID(); |
|
440 | + $user = $this->userManager->get($id); |
|
441 | + |
|
442 | + if($userId === $id) { |
|
443 | + return new DataResponse( |
|
444 | + array( |
|
445 | + 'status' => 'error', |
|
446 | + 'data' => array( |
|
447 | + 'message' => (string)$this->l10n->t('Unable to delete user.') |
|
448 | + ) |
|
449 | + ), |
|
450 | + Http::STATUS_FORBIDDEN |
|
451 | + ); |
|
452 | + } |
|
453 | + |
|
454 | + if(!$this->isAdmin && !$this->groupManager->getSubAdmin()->isUserAccessible($this->userSession->getUser(), $user)) { |
|
455 | + return new DataResponse( |
|
456 | + array( |
|
457 | + 'status' => 'error', |
|
458 | + 'data' => array( |
|
459 | + 'message' => (string)$this->l10n->t('Authentication error') |
|
460 | + ) |
|
461 | + ), |
|
462 | + Http::STATUS_FORBIDDEN |
|
463 | + ); |
|
464 | + } |
|
465 | + |
|
466 | + if($user) { |
|
467 | + if($user->delete()) { |
|
468 | + return new DataResponse( |
|
469 | + array( |
|
470 | + 'status' => 'success', |
|
471 | + 'data' => array( |
|
472 | + 'username' => $id |
|
473 | + ) |
|
474 | + ), |
|
475 | + Http::STATUS_NO_CONTENT |
|
476 | + ); |
|
477 | + } |
|
478 | + } |
|
479 | + |
|
480 | + return new DataResponse( |
|
481 | + array( |
|
482 | + 'status' => 'error', |
|
483 | + 'data' => array( |
|
484 | + 'message' => (string)$this->l10n->t('Unable to delete user.') |
|
485 | + ) |
|
486 | + ), |
|
487 | + Http::STATUS_FORBIDDEN |
|
488 | + ); |
|
489 | + } |
|
490 | + |
|
491 | + /** |
|
492 | + * @NoAdminRequired |
|
493 | + * @NoSubadminRequired |
|
494 | + * @PasswordConfirmationRequired |
|
495 | + * |
|
496 | + * @param string $avatarScope |
|
497 | + * @param string $displayname |
|
498 | + * @param string $displaynameScope |
|
499 | + * @param string $phone |
|
500 | + * @param string $phoneScope |
|
501 | + * @param string $email |
|
502 | + * @param string $emailScope |
|
503 | + * @param string $website |
|
504 | + * @param string $websiteScope |
|
505 | + * @param string $address |
|
506 | + * @param string $addressScope |
|
507 | + * @param string $twitter |
|
508 | + * @param string $twitterScope |
|
509 | + * @return DataResponse |
|
510 | + */ |
|
511 | + public function setUserSettings($avatarScope, |
|
512 | + $displayname, |
|
513 | + $displaynameScope, |
|
514 | + $phone, |
|
515 | + $phoneScope, |
|
516 | + $email, |
|
517 | + $emailScope, |
|
518 | + $website, |
|
519 | + $websiteScope, |
|
520 | + $address, |
|
521 | + $addressScope, |
|
522 | + $twitter, |
|
523 | + $twitterScope |
|
524 | + ) { |
|
525 | + |
|
526 | + if(!empty($email) && !$this->mailer->validateMailAddress($email)) { |
|
527 | + return new DataResponse( |
|
528 | + array( |
|
529 | + 'status' => 'error', |
|
530 | + 'data' => array( |
|
531 | + 'message' => (string)$this->l10n->t('Invalid mail address') |
|
532 | + ) |
|
533 | + ), |
|
534 | + Http::STATUS_UNPROCESSABLE_ENTITY |
|
535 | + ); |
|
536 | + } |
|
537 | + |
|
538 | + $data = [ |
|
539 | + AccountManager::PROPERTY_AVATAR => ['scope' => $avatarScope], |
|
540 | + AccountManager::PROPERTY_DISPLAYNAME => ['value' => $displayname, 'scope' => $displaynameScope], |
|
541 | + AccountManager::PROPERTY_EMAIL=> ['value' => $email, 'scope' => $emailScope], |
|
542 | + AccountManager::PROPERTY_WEBSITE => ['value' => $website, 'scope' => $websiteScope], |
|
543 | + AccountManager::PROPERTY_ADDRESS => ['value' => $address, 'scope' => $addressScope], |
|
544 | + AccountManager::PROPERTY_PHONE => ['value' => $phone, 'scope' => $phoneScope], |
|
545 | + AccountManager::PROPERTY_TWITTER => ['value' => $twitter, 'scope' => $twitterScope] |
|
546 | + ]; |
|
547 | + |
|
548 | + $user = $this->userSession->getUser(); |
|
549 | + |
|
550 | + try { |
|
551 | + $this->saveUserSettings($user, $data); |
|
552 | + return new DataResponse( |
|
553 | + array( |
|
554 | + 'status' => 'success', |
|
555 | + 'data' => array( |
|
556 | + 'userId' => $user->getUID(), |
|
557 | + 'avatarScope' => $avatarScope, |
|
558 | + 'displayname' => $displayname, |
|
559 | + 'displaynameScope' => $displaynameScope, |
|
560 | + 'email' => $email, |
|
561 | + 'emailScope' => $emailScope, |
|
562 | + 'website' => $website, |
|
563 | + 'websiteScope' => $websiteScope, |
|
564 | + 'address' => $address, |
|
565 | + 'addressScope' => $addressScope, |
|
566 | + 'message' => (string)$this->l10n->t('Settings saved') |
|
567 | + ) |
|
568 | + ), |
|
569 | + Http::STATUS_OK |
|
570 | + ); |
|
571 | + } catch (ForbiddenException $e) { |
|
572 | + return new DataResponse([ |
|
573 | + 'status' => 'error', |
|
574 | + 'data' => [ |
|
575 | + 'message' => $e->getMessage() |
|
576 | + ], |
|
577 | + ]); |
|
578 | + } |
|
579 | + |
|
580 | + } |
|
581 | + |
|
582 | + |
|
583 | + /** |
|
584 | + * update account manager with new user data |
|
585 | + * |
|
586 | + * @param IUser $user |
|
587 | + * @param array $data |
|
588 | + * @throws ForbiddenException |
|
589 | + */ |
|
590 | + protected function saveUserSettings(IUser $user, $data) { |
|
591 | + |
|
592 | + // keep the user back-end up-to-date with the latest display name and email |
|
593 | + // address |
|
594 | + $oldDisplayName = $user->getDisplayName(); |
|
595 | + $oldDisplayName = is_null($oldDisplayName) ? '' : $oldDisplayName; |
|
596 | + if (isset($data[AccountManager::PROPERTY_DISPLAYNAME]['value']) |
|
597 | + && $oldDisplayName !== $data[AccountManager::PROPERTY_DISPLAYNAME]['value'] |
|
598 | + ) { |
|
599 | + $result = $user->setDisplayName($data[AccountManager::PROPERTY_DISPLAYNAME]['value']); |
|
600 | + if ($result === false) { |
|
601 | + throw new ForbiddenException($this->l10n->t('Unable to change full name')); |
|
602 | + } |
|
603 | + } |
|
604 | + |
|
605 | + $oldEmailAddress = $user->getEMailAddress(); |
|
606 | + $oldEmailAddress = is_null($oldEmailAddress) ? '' : $oldEmailAddress; |
|
607 | + if (isset($data[AccountManager::PROPERTY_EMAIL]['value']) |
|
608 | + && $oldEmailAddress !== $data[AccountManager::PROPERTY_EMAIL]['value'] |
|
609 | + ) { |
|
610 | + // this is the only permission a backend provides and is also used |
|
611 | + // for the permission of setting a email address |
|
612 | + if (!$user->canChangeDisplayName()) { |
|
613 | + throw new ForbiddenException($this->l10n->t('Unable to change email address')); |
|
614 | + } |
|
615 | + $user->setEMailAddress($data[AccountManager::PROPERTY_EMAIL]['value']); |
|
616 | + } |
|
617 | + |
|
618 | + $this->accountManager->updateUser($user, $data); |
|
619 | + } |
|
620 | + |
|
621 | + /** |
|
622 | + * Count all unique users visible for the current admin/subadmin. |
|
623 | + * |
|
624 | + * @NoAdminRequired |
|
625 | + * |
|
626 | + * @return DataResponse |
|
627 | + */ |
|
628 | + public function stats() { |
|
629 | + $userCount = 0; |
|
630 | + if ($this->isAdmin) { |
|
631 | + $countByBackend = $this->userManager->countUsers(); |
|
632 | + |
|
633 | + if (!empty($countByBackend)) { |
|
634 | + foreach ($countByBackend as $count) { |
|
635 | + $userCount += $count; |
|
636 | + } |
|
637 | + } |
|
638 | + } else { |
|
639 | + $groups = $this->groupManager->getSubAdmin()->getSubAdminsGroups($this->userSession->getUser()); |
|
640 | + |
|
641 | + $uniqueUsers = []; |
|
642 | + foreach ($groups as $group) { |
|
643 | + foreach($group->getUsers() as $uid => $displayName) { |
|
644 | + $uniqueUsers[$uid] = true; |
|
645 | + } |
|
646 | + } |
|
647 | + |
|
648 | + $userCount = count($uniqueUsers); |
|
649 | + } |
|
650 | + |
|
651 | + return new DataResponse( |
|
652 | + [ |
|
653 | + 'totalUsers' => $userCount |
|
654 | + ] |
|
655 | + ); |
|
656 | + } |
|
657 | + |
|
658 | + |
|
659 | + /** |
|
660 | + * Set the displayName of a user |
|
661 | + * |
|
662 | + * @NoAdminRequired |
|
663 | + * @NoSubadminRequired |
|
664 | + * @PasswordConfirmationRequired |
|
665 | + * @todo merge into saveUserSettings |
|
666 | + * |
|
667 | + * @param string $username |
|
668 | + * @param string $displayName |
|
669 | + * @return DataResponse |
|
670 | + */ |
|
671 | + public function setDisplayName($username, $displayName) { |
|
672 | + $currentUser = $this->userSession->getUser(); |
|
673 | + $user = $this->userManager->get($username); |
|
674 | + |
|
675 | + if ($user === null || |
|
676 | + !$user->canChangeDisplayName() || |
|
677 | + ( |
|
678 | + !$this->groupManager->isAdmin($currentUser->getUID()) && |
|
679 | + !$this->groupManager->getSubAdmin()->isUserAccessible($currentUser, $user) && |
|
680 | + $currentUser->getUID() !== $username |
|
681 | + |
|
682 | + ) |
|
683 | + ) { |
|
684 | + return new DataResponse([ |
|
685 | + 'status' => 'error', |
|
686 | + 'data' => [ |
|
687 | + 'message' => $this->l10n->t('Authentication error'), |
|
688 | + ], |
|
689 | + ]); |
|
690 | + } |
|
691 | + |
|
692 | + $userData = $this->accountManager->getUser($user); |
|
693 | + $userData[AccountManager::PROPERTY_DISPLAYNAME]['value'] = $displayName; |
|
694 | + |
|
695 | + |
|
696 | + try { |
|
697 | + $this->saveUserSettings($user, $userData); |
|
698 | + return new DataResponse([ |
|
699 | + 'status' => 'success', |
|
700 | + 'data' => [ |
|
701 | + 'message' => $this->l10n->t('Your full name has been changed.'), |
|
702 | + 'username' => $username, |
|
703 | + 'displayName' => $displayName, |
|
704 | + ], |
|
705 | + ]); |
|
706 | + } catch (ForbiddenException $e) { |
|
707 | + return new DataResponse([ |
|
708 | + 'status' => 'error', |
|
709 | + 'data' => [ |
|
710 | + 'message' => $e->getMessage(), |
|
711 | + 'displayName' => $user->getDisplayName(), |
|
712 | + ], |
|
713 | + ]); |
|
714 | + } |
|
715 | + } |
|
716 | + |
|
717 | + /** |
|
718 | + * Set the mail address of a user |
|
719 | + * |
|
720 | + * @NoAdminRequired |
|
721 | + * @NoSubadminRequired |
|
722 | + * @PasswordConfirmationRequired |
|
723 | + * |
|
724 | + * @param string $id |
|
725 | + * @param string $mailAddress |
|
726 | + * @return DataResponse |
|
727 | + */ |
|
728 | + public function setEMailAddress($id, $mailAddress) { |
|
729 | + $user = $this->userManager->get($id); |
|
730 | + if (!$this->isAdmin |
|
731 | + && !$this->groupManager->getSubAdmin()->isUserAccessible($this->userSession->getUser(), $user) |
|
732 | + ) { |
|
733 | + return new DataResponse( |
|
734 | + array( |
|
735 | + 'status' => 'error', |
|
736 | + 'data' => array( |
|
737 | + 'message' => (string)$this->l10n->t('Forbidden') |
|
738 | + ) |
|
739 | + ), |
|
740 | + Http::STATUS_FORBIDDEN |
|
741 | + ); |
|
742 | + } |
|
743 | + |
|
744 | + if($mailAddress !== '' && !$this->mailer->validateMailAddress($mailAddress)) { |
|
745 | + return new DataResponse( |
|
746 | + array( |
|
747 | + 'status' => 'error', |
|
748 | + 'data' => array( |
|
749 | + 'message' => (string)$this->l10n->t('Invalid mail address') |
|
750 | + ) |
|
751 | + ), |
|
752 | + Http::STATUS_UNPROCESSABLE_ENTITY |
|
753 | + ); |
|
754 | + } |
|
755 | + |
|
756 | + if (!$user) { |
|
757 | + return new DataResponse( |
|
758 | + array( |
|
759 | + 'status' => 'error', |
|
760 | + 'data' => array( |
|
761 | + 'message' => (string)$this->l10n->t('Invalid user') |
|
762 | + ) |
|
763 | + ), |
|
764 | + Http::STATUS_UNPROCESSABLE_ENTITY |
|
765 | + ); |
|
766 | + } |
|
767 | + // this is the only permission a backend provides and is also used |
|
768 | + // for the permission of setting a email address |
|
769 | + if (!$user->canChangeDisplayName()) { |
|
770 | + return new DataResponse( |
|
771 | + array( |
|
772 | + 'status' => 'error', |
|
773 | + 'data' => array( |
|
774 | + 'message' => (string)$this->l10n->t('Unable to change mail address') |
|
775 | + ) |
|
776 | + ), |
|
777 | + Http::STATUS_FORBIDDEN |
|
778 | + ); |
|
779 | + } |
|
780 | + |
|
781 | + $userData = $this->accountManager->getUser($user); |
|
782 | + $userData[AccountManager::PROPERTY_EMAIL]['value'] = $mailAddress; |
|
783 | + |
|
784 | + try { |
|
785 | + $this->saveUserSettings($user, $userData); |
|
786 | + return new DataResponse( |
|
787 | + array( |
|
788 | + 'status' => 'success', |
|
789 | + 'data' => array( |
|
790 | + 'username' => $id, |
|
791 | + 'mailAddress' => $mailAddress, |
|
792 | + 'message' => (string)$this->l10n->t('Email saved') |
|
793 | + ) |
|
794 | + ), |
|
795 | + Http::STATUS_OK |
|
796 | + ); |
|
797 | + } catch (ForbiddenException $e) { |
|
798 | + return new DataResponse([ |
|
799 | + 'status' => 'error', |
|
800 | + 'data' => [ |
|
801 | + 'message' => $e->getMessage() |
|
802 | + ], |
|
803 | + ]); |
|
804 | + } |
|
805 | + } |
|
806 | 806 | |
807 | 807 | } |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | |
134 | 134 | // check for encryption state - TODO see formatUserForIndex |
135 | 135 | $this->isEncryptionAppEnabled = $appManager->isEnabledForUser('encryption'); |
136 | - if($this->isEncryptionAppEnabled) { |
|
136 | + if ($this->isEncryptionAppEnabled) { |
|
137 | 137 | // putting this directly in empty is possible in PHP 5.5+ |
138 | 138 | $result = $config->getAppValue('encryption', 'recoveryAdminEnabled', 0); |
139 | 139 | $this->isRestoreEnabled = !empty($result); |
@@ -173,7 +173,7 @@ discard block |
||
173 | 173 | } |
174 | 174 | |
175 | 175 | $subAdminGroups = $this->groupManager->getSubAdmin()->getSubAdminsGroups($user); |
176 | - foreach($subAdminGroups as $key => $subAdminGroup) { |
|
176 | + foreach ($subAdminGroups as $key => $subAdminGroup) { |
|
177 | 177 | $subAdminGroups[$key] = $subAdminGroup->getGID(); |
178 | 178 | } |
179 | 179 | |
@@ -230,16 +230,16 @@ discard block |
||
230 | 230 | */ |
231 | 231 | public function index($offset = 0, $limit = 10, $gid = '', $pattern = '', $backend = '') { |
232 | 232 | // FIXME: The JS sends the group '_everyone' instead of no GID for the "all users" group. |
233 | - if($gid === '_everyone') { |
|
233 | + if ($gid === '_everyone') { |
|
234 | 234 | $gid = ''; |
235 | 235 | } |
236 | 236 | |
237 | 237 | // Remove backends |
238 | - if(!empty($backend)) { |
|
238 | + if (!empty($backend)) { |
|
239 | 239 | $activeBackends = $this->userManager->getBackends(); |
240 | 240 | $this->userManager->clearBackends(); |
241 | - foreach($activeBackends as $singleActiveBackend) { |
|
242 | - if($backend === get_class($singleActiveBackend)) { |
|
241 | + foreach ($activeBackends as $singleActiveBackend) { |
|
242 | + if ($backend === get_class($singleActiveBackend)) { |
|
243 | 243 | $this->userManager->registerBackend($singleActiveBackend); |
244 | 244 | break; |
245 | 245 | } |
@@ -249,7 +249,7 @@ discard block |
||
249 | 249 | $users = []; |
250 | 250 | if ($this->isAdmin) { |
251 | 251 | |
252 | - if($gid !== '') { |
|
252 | + if ($gid !== '') { |
|
253 | 253 | $batch = $this->getUsersForUID($this->groupManager->displayNamesInGroup($gid, $pattern, $limit, $offset)); |
254 | 254 | } else { |
255 | 255 | $batch = $this->userManager->search($pattern, $limit, $offset); |
@@ -269,17 +269,17 @@ discard block |
||
269 | 269 | $subAdminOfGroups = $gids; |
270 | 270 | |
271 | 271 | // Set the $gid parameter to an empty value if the subadmin has no rights to access a specific group |
272 | - if($gid !== '' && !in_array($gid, $subAdminOfGroups)) { |
|
272 | + if ($gid !== '' && !in_array($gid, $subAdminOfGroups)) { |
|
273 | 273 | $gid = ''; |
274 | 274 | } |
275 | 275 | |
276 | 276 | // Batch all groups the user is subadmin of when a group is specified |
277 | 277 | $batch = []; |
278 | - if($gid === '') { |
|
279 | - foreach($subAdminOfGroups as $group) { |
|
278 | + if ($gid === '') { |
|
279 | + foreach ($subAdminOfGroups as $group) { |
|
280 | 280 | $groupUsers = $this->groupManager->displayNamesInGroup($group, $pattern, $limit, $offset); |
281 | 281 | |
282 | - foreach($groupUsers as $uid => $displayName) { |
|
282 | + foreach ($groupUsers as $uid => $displayName) { |
|
283 | 283 | $batch[$uid] = $displayName; |
284 | 284 | } |
285 | 285 | } |
@@ -311,11 +311,11 @@ discard block |
||
311 | 311 | * @param string $email |
312 | 312 | * @return DataResponse |
313 | 313 | */ |
314 | - public function create($username, $password, array $groups=array(), $email='') { |
|
315 | - if($email !== '' && !$this->mailer->validateMailAddress($email)) { |
|
314 | + public function create($username, $password, array $groups = array(), $email = '') { |
|
315 | + if ($email !== '' && !$this->mailer->validateMailAddress($email)) { |
|
316 | 316 | return new DataResponse( |
317 | 317 | array( |
318 | - 'message' => (string)$this->l10n->t('Invalid mail address') |
|
318 | + 'message' => (string) $this->l10n->t('Invalid mail address') |
|
319 | 319 | ), |
320 | 320 | Http::STATUS_UNPROCESSABLE_ENTITY |
321 | 321 | ); |
@@ -327,7 +327,7 @@ discard block |
||
327 | 327 | if (!empty($groups)) { |
328 | 328 | foreach ($groups as $key => $group) { |
329 | 329 | $groupObject = $this->groupManager->get($group); |
330 | - if($groupObject === null) { |
|
330 | + if ($groupObject === null) { |
|
331 | 331 | unset($groups[$key]); |
332 | 332 | continue; |
333 | 333 | } |
@@ -351,7 +351,7 @@ discard block |
||
351 | 351 | if ($this->userManager->userExists($username)) { |
352 | 352 | return new DataResponse( |
353 | 353 | array( |
354 | - 'message' => (string)$this->l10n->t('A user with that name already exists.') |
|
354 | + 'message' => (string) $this->l10n->t('A user with that name already exists.') |
|
355 | 355 | ), |
356 | 356 | Http::STATUS_CONFLICT |
357 | 357 | ); |
@@ -362,7 +362,7 @@ discard block |
||
362 | 362 | if ($email === '') { |
363 | 363 | return new DataResponse( |
364 | 364 | array( |
365 | - 'message' => (string)$this->l10n->t('To send a password link to the user an email address is required.') |
|
365 | + 'message' => (string) $this->l10n->t('To send a password link to the user an email address is required.') |
|
366 | 366 | ), |
367 | 367 | Http::STATUS_UNPROCESSABLE_ENTITY |
368 | 368 | ); |
@@ -387,12 +387,12 @@ discard block |
||
387 | 387 | ); |
388 | 388 | } |
389 | 389 | |
390 | - if($user instanceof IUser) { |
|
391 | - if($groups !== null) { |
|
392 | - foreach($groups as $groupName) { |
|
390 | + if ($user instanceof IUser) { |
|
391 | + if ($groups !== null) { |
|
392 | + foreach ($groups as $groupName) { |
|
393 | 393 | $group = $this->groupManager->get($groupName); |
394 | 394 | |
395 | - if(empty($group)) { |
|
395 | + if (empty($group)) { |
|
396 | 396 | $group = $this->groupManager->createGroup($groupName); |
397 | 397 | } |
398 | 398 | $group->addUser($user); |
@@ -401,13 +401,13 @@ discard block |
||
401 | 401 | /** |
402 | 402 | * Send new user mail only if a mail is set |
403 | 403 | */ |
404 | - if($email !== '') { |
|
404 | + if ($email !== '') { |
|
405 | 405 | $user->setEMailAddress($email); |
406 | 406 | try { |
407 | 407 | $emailTemplate = $this->newUserMailHelper->generateTemplate($user, $generatePasswordResetToken); |
408 | 408 | $this->newUserMailHelper->sendMail($user, $emailTemplate); |
409 | - } catch(\Exception $e) { |
|
410 | - $this->log->error("Can't send new user mail to $email: " . $e->getMessage(), array('app' => 'settings')); |
|
409 | + } catch (\Exception $e) { |
|
410 | + $this->log->error("Can't send new user mail to $email: ".$e->getMessage(), array('app' => 'settings')); |
|
411 | 411 | } |
412 | 412 | } |
413 | 413 | // fetch users groups |
@@ -421,7 +421,7 @@ discard block |
||
421 | 421 | |
422 | 422 | return new DataResponse( |
423 | 423 | array( |
424 | - 'message' => (string)$this->l10n->t('Unable to create user.') |
|
424 | + 'message' => (string) $this->l10n->t('Unable to create user.') |
|
425 | 425 | ), |
426 | 426 | Http::STATUS_FORBIDDEN |
427 | 427 | ); |
@@ -439,32 +439,32 @@ discard block |
||
439 | 439 | $userId = $this->userSession->getUser()->getUID(); |
440 | 440 | $user = $this->userManager->get($id); |
441 | 441 | |
442 | - if($userId === $id) { |
|
442 | + if ($userId === $id) { |
|
443 | 443 | return new DataResponse( |
444 | 444 | array( |
445 | 445 | 'status' => 'error', |
446 | 446 | 'data' => array( |
447 | - 'message' => (string)$this->l10n->t('Unable to delete user.') |
|
447 | + 'message' => (string) $this->l10n->t('Unable to delete user.') |
|
448 | 448 | ) |
449 | 449 | ), |
450 | 450 | Http::STATUS_FORBIDDEN |
451 | 451 | ); |
452 | 452 | } |
453 | 453 | |
454 | - if(!$this->isAdmin && !$this->groupManager->getSubAdmin()->isUserAccessible($this->userSession->getUser(), $user)) { |
|
454 | + if (!$this->isAdmin && !$this->groupManager->getSubAdmin()->isUserAccessible($this->userSession->getUser(), $user)) { |
|
455 | 455 | return new DataResponse( |
456 | 456 | array( |
457 | 457 | 'status' => 'error', |
458 | 458 | 'data' => array( |
459 | - 'message' => (string)$this->l10n->t('Authentication error') |
|
459 | + 'message' => (string) $this->l10n->t('Authentication error') |
|
460 | 460 | ) |
461 | 461 | ), |
462 | 462 | Http::STATUS_FORBIDDEN |
463 | 463 | ); |
464 | 464 | } |
465 | 465 | |
466 | - if($user) { |
|
467 | - if($user->delete()) { |
|
466 | + if ($user) { |
|
467 | + if ($user->delete()) { |
|
468 | 468 | return new DataResponse( |
469 | 469 | array( |
470 | 470 | 'status' => 'success', |
@@ -481,7 +481,7 @@ discard block |
||
481 | 481 | array( |
482 | 482 | 'status' => 'error', |
483 | 483 | 'data' => array( |
484 | - 'message' => (string)$this->l10n->t('Unable to delete user.') |
|
484 | + 'message' => (string) $this->l10n->t('Unable to delete user.') |
|
485 | 485 | ) |
486 | 486 | ), |
487 | 487 | Http::STATUS_FORBIDDEN |
@@ -523,12 +523,12 @@ discard block |
||
523 | 523 | $twitterScope |
524 | 524 | ) { |
525 | 525 | |
526 | - if(!empty($email) && !$this->mailer->validateMailAddress($email)) { |
|
526 | + if (!empty($email) && !$this->mailer->validateMailAddress($email)) { |
|
527 | 527 | return new DataResponse( |
528 | 528 | array( |
529 | 529 | 'status' => 'error', |
530 | 530 | 'data' => array( |
531 | - 'message' => (string)$this->l10n->t('Invalid mail address') |
|
531 | + 'message' => (string) $this->l10n->t('Invalid mail address') |
|
532 | 532 | ) |
533 | 533 | ), |
534 | 534 | Http::STATUS_UNPROCESSABLE_ENTITY |
@@ -563,7 +563,7 @@ discard block |
||
563 | 563 | 'websiteScope' => $websiteScope, |
564 | 564 | 'address' => $address, |
565 | 565 | 'addressScope' => $addressScope, |
566 | - 'message' => (string)$this->l10n->t('Settings saved') |
|
566 | + 'message' => (string) $this->l10n->t('Settings saved') |
|
567 | 567 | ) |
568 | 568 | ), |
569 | 569 | Http::STATUS_OK |
@@ -640,7 +640,7 @@ discard block |
||
640 | 640 | |
641 | 641 | $uniqueUsers = []; |
642 | 642 | foreach ($groups as $group) { |
643 | - foreach($group->getUsers() as $uid => $displayName) { |
|
643 | + foreach ($group->getUsers() as $uid => $displayName) { |
|
644 | 644 | $uniqueUsers[$uid] = true; |
645 | 645 | } |
646 | 646 | } |
@@ -734,19 +734,19 @@ discard block |
||
734 | 734 | array( |
735 | 735 | 'status' => 'error', |
736 | 736 | 'data' => array( |
737 | - 'message' => (string)$this->l10n->t('Forbidden') |
|
737 | + 'message' => (string) $this->l10n->t('Forbidden') |
|
738 | 738 | ) |
739 | 739 | ), |
740 | 740 | Http::STATUS_FORBIDDEN |
741 | 741 | ); |
742 | 742 | } |
743 | 743 | |
744 | - if($mailAddress !== '' && !$this->mailer->validateMailAddress($mailAddress)) { |
|
744 | + if ($mailAddress !== '' && !$this->mailer->validateMailAddress($mailAddress)) { |
|
745 | 745 | return new DataResponse( |
746 | 746 | array( |
747 | 747 | 'status' => 'error', |
748 | 748 | 'data' => array( |
749 | - 'message' => (string)$this->l10n->t('Invalid mail address') |
|
749 | + 'message' => (string) $this->l10n->t('Invalid mail address') |
|
750 | 750 | ) |
751 | 751 | ), |
752 | 752 | Http::STATUS_UNPROCESSABLE_ENTITY |
@@ -758,7 +758,7 @@ discard block |
||
758 | 758 | array( |
759 | 759 | 'status' => 'error', |
760 | 760 | 'data' => array( |
761 | - 'message' => (string)$this->l10n->t('Invalid user') |
|
761 | + 'message' => (string) $this->l10n->t('Invalid user') |
|
762 | 762 | ) |
763 | 763 | ), |
764 | 764 | Http::STATUS_UNPROCESSABLE_ENTITY |
@@ -771,7 +771,7 @@ discard block |
||
771 | 771 | array( |
772 | 772 | 'status' => 'error', |
773 | 773 | 'data' => array( |
774 | - 'message' => (string)$this->l10n->t('Unable to change mail address') |
|
774 | + 'message' => (string) $this->l10n->t('Unable to change mail address') |
|
775 | 775 | ) |
776 | 776 | ), |
777 | 777 | Http::STATUS_FORBIDDEN |
@@ -789,7 +789,7 @@ discard block |
||
789 | 789 | 'data' => array( |
790 | 790 | 'username' => $id, |
791 | 791 | 'mailAddress' => $mailAddress, |
792 | - 'message' => (string)$this->l10n->t('Email saved') |
|
792 | + 'message' => (string) $this->l10n->t('Email saved') |
|
793 | 793 | ) |
794 | 794 | ), |
795 | 795 | Http::STATUS_OK |
@@ -10,35 +10,35 @@ |
||
10 | 10 | use OCP\Util; |
11 | 11 | |
12 | 12 | class Application extends App { |
13 | - public function __construct(array $urlParams = array()) { |
|
14 | - parent::__construct('provisioning_api', $urlParams); |
|
13 | + public function __construct(array $urlParams = array()) { |
|
14 | + parent::__construct('provisioning_api', $urlParams); |
|
15 | 15 | |
16 | - $container = $this->getContainer(); |
|
17 | - $server = $container->getServer(); |
|
16 | + $container = $this->getContainer(); |
|
17 | + $server = $container->getServer(); |
|
18 | 18 | |
19 | - $container->registerService(NewUserMailHelper::class, function(SimpleContainer $c) use ($server) { |
|
20 | - return new NewUserMailHelper( |
|
21 | - $server->getThemingDefaults(), |
|
22 | - $server->getURLGenerator(), |
|
23 | - $server->getL10N('settings'), |
|
24 | - $server->getMailer(), |
|
25 | - $server->getSecureRandom(), |
|
26 | - new TimeFactory(), |
|
27 | - $server->getConfig(), |
|
28 | - $server->getCrypto(), |
|
29 | - Util::getDefaultEmailAddress('no-reply') |
|
30 | - ); |
|
31 | - }); |
|
32 | - $container->registerService('ProvisioningApiMiddleware', function(SimpleContainer $c) use ($server) { |
|
33 | - $user = $server->getUserManager()->get($c['UserId']); |
|
34 | - $isAdmin = $user !== null ? $server->getGroupManager()->isAdmin($user->getUID()) : false; |
|
35 | - $isSubAdmin = $user !== null ? $server->getGroupManager()->getSubAdmin()->isSubAdmin($user) : false; |
|
36 | - return new ProvisioningApiMiddleware( |
|
37 | - $c['ControllerMethodReflector'], |
|
38 | - $isAdmin, |
|
39 | - $isSubAdmin |
|
40 | - ); |
|
41 | - }); |
|
42 | - $container->registerMiddleWare('ProvisioningApiMiddleware'); |
|
43 | - } |
|
19 | + $container->registerService(NewUserMailHelper::class, function(SimpleContainer $c) use ($server) { |
|
20 | + return new NewUserMailHelper( |
|
21 | + $server->getThemingDefaults(), |
|
22 | + $server->getURLGenerator(), |
|
23 | + $server->getL10N('settings'), |
|
24 | + $server->getMailer(), |
|
25 | + $server->getSecureRandom(), |
|
26 | + new TimeFactory(), |
|
27 | + $server->getConfig(), |
|
28 | + $server->getCrypto(), |
|
29 | + Util::getDefaultEmailAddress('no-reply') |
|
30 | + ); |
|
31 | + }); |
|
32 | + $container->registerService('ProvisioningApiMiddleware', function(SimpleContainer $c) use ($server) { |
|
33 | + $user = $server->getUserManager()->get($c['UserId']); |
|
34 | + $isAdmin = $user !== null ? $server->getGroupManager()->isAdmin($user->getUID()) : false; |
|
35 | + $isSubAdmin = $user !== null ? $server->getGroupManager()->getSubAdmin()->isSubAdmin($user) : false; |
|
36 | + return new ProvisioningApiMiddleware( |
|
37 | + $c['ControllerMethodReflector'], |
|
38 | + $isAdmin, |
|
39 | + $isSubAdmin |
|
40 | + ); |
|
41 | + }); |
|
42 | + $container->registerMiddleWare('ProvisioningApiMiddleware'); |
|
43 | + } |
|
44 | 44 | } |
@@ -32,221 +32,221 @@ |
||
32 | 32 | |
33 | 33 | class ThemingDefaults extends \OC_Defaults { |
34 | 34 | |
35 | - /** @var IConfig */ |
|
36 | - private $config; |
|
37 | - /** @var IL10N */ |
|
38 | - private $l; |
|
39 | - /** @var IURLGenerator */ |
|
40 | - private $urlGenerator; |
|
41 | - /** @var IAppData */ |
|
42 | - private $appData; |
|
43 | - /** @var ICacheFactory */ |
|
44 | - private $cacheFactory; |
|
45 | - /** @var string */ |
|
46 | - private $name; |
|
47 | - /** @var string */ |
|
48 | - private $url; |
|
49 | - /** @var string */ |
|
50 | - private $slogan; |
|
51 | - /** @var string */ |
|
52 | - private $color; |
|
53 | - |
|
54 | - /** |
|
55 | - * ThemingDefaults constructor. |
|
56 | - * |
|
57 | - * @param IConfig $config |
|
58 | - * @param IL10N $l |
|
59 | - * @param IURLGenerator $urlGenerator |
|
60 | - * @param \OC_Defaults $defaults |
|
61 | - * @param IAppData $appData |
|
62 | - * @param ICacheFactory $cacheFactory |
|
63 | - */ |
|
64 | - public function __construct(IConfig $config, |
|
65 | - IL10N $l, |
|
66 | - IURLGenerator $urlGenerator, |
|
67 | - \OC_Defaults $defaults, |
|
68 | - IAppData $appData, |
|
69 | - ICacheFactory $cacheFactory |
|
70 | - ) { |
|
71 | - parent::__construct(); |
|
72 | - $this->config = $config; |
|
73 | - $this->l = $l; |
|
74 | - $this->urlGenerator = $urlGenerator; |
|
75 | - $this->appData = $appData; |
|
76 | - $this->cacheFactory = $cacheFactory; |
|
77 | - |
|
78 | - $this->name = $defaults->getName(); |
|
79 | - $this->url = $defaults->getBaseUrl(); |
|
80 | - $this->slogan = $defaults->getSlogan(); |
|
81 | - $this->color = $defaults->getColorPrimary(); |
|
82 | - } |
|
83 | - |
|
84 | - public function getName() { |
|
85 | - return strip_tags($this->config->getAppValue('theming', 'name', $this->name)); |
|
86 | - } |
|
87 | - |
|
88 | - public function getHTMLName() { |
|
89 | - return $this->config->getAppValue('theming', 'name', $this->name); |
|
90 | - } |
|
91 | - |
|
92 | - public function getTitle() { |
|
93 | - return $this->getName(); |
|
94 | - } |
|
95 | - |
|
96 | - public function getEntity() { |
|
97 | - return $this->getName(); |
|
98 | - } |
|
99 | - |
|
100 | - public function getBaseUrl() { |
|
101 | - return $this->config->getAppValue('theming', 'url', $this->url); |
|
102 | - } |
|
103 | - |
|
104 | - public function getSlogan() { |
|
105 | - return Util::sanitizeHTML($this->config->getAppValue('theming', 'slogan', $this->slogan)); |
|
106 | - } |
|
107 | - |
|
108 | - public function getShortFooter() { |
|
109 | - $slogan = $this->getSlogan(); |
|
110 | - $footer = '<a href="'. $this->getBaseUrl() . '" target="_blank"' . |
|
111 | - ' rel="noreferrer">' .$this->getEntity() . '</a>'. |
|
112 | - ($slogan !== '' ? ' – ' . $slogan : ''); |
|
113 | - |
|
114 | - return $footer; |
|
115 | - } |
|
116 | - |
|
117 | - /** |
|
118 | - * Color that is used for the header as well as for mail headers |
|
119 | - * |
|
120 | - * @return string |
|
121 | - */ |
|
122 | - public function getColorPrimary() { |
|
123 | - return $this->config->getAppValue('theming', 'color', $this->color); |
|
124 | - } |
|
125 | - |
|
126 | - /** |
|
127 | - * Themed logo url |
|
128 | - * |
|
129 | - * @return string |
|
130 | - */ |
|
131 | - public function getLogo() { |
|
132 | - $logo = $this->config->getAppValue('theming', 'logoMime'); |
|
133 | - |
|
134 | - $logoExists = true; |
|
135 | - try { |
|
136 | - $this->appData->getFolder('images')->getFile('logo'); |
|
137 | - } catch (\Exception $e) { |
|
138 | - $logoExists = false; |
|
139 | - } |
|
140 | - |
|
141 | - if(!$logo || !$logoExists) { |
|
142 | - return $this->urlGenerator->imagePath('core','logo.svg'); |
|
143 | - } |
|
144 | - |
|
145 | - return $this->urlGenerator->linkToRoute('theming.Theming.getLogo'); |
|
146 | - } |
|
147 | - |
|
148 | - /** |
|
149 | - * Themed background image url |
|
150 | - * |
|
151 | - * @return string |
|
152 | - */ |
|
153 | - public function getBackground() { |
|
154 | - $backgroundLogo = $this->config->getAppValue('theming', 'backgroundMime'); |
|
155 | - |
|
156 | - $backgroundExists = true; |
|
157 | - try { |
|
158 | - $this->appData->getFolder('images')->getFile('background'); |
|
159 | - } catch (\Exception $e) { |
|
160 | - $backgroundExists = false; |
|
161 | - } |
|
162 | - |
|
163 | - if(!$backgroundLogo || !$backgroundExists) { |
|
164 | - return $this->urlGenerator->imagePath('core','background.jpg'); |
|
165 | - } |
|
166 | - |
|
167 | - return $this->urlGenerator->linkToRoute('theming.Theming.getLoginBackground'); |
|
168 | - } |
|
169 | - |
|
170 | - /** |
|
171 | - * Check if Imagemagick is enabled and if SVG is supported |
|
172 | - * otherwise we can't render custom icons |
|
173 | - * |
|
174 | - * @return bool |
|
175 | - */ |
|
176 | - public function shouldReplaceIcons() { |
|
177 | - $cache = $this->cacheFactory->create('theming'); |
|
178 | - if($value = $cache->get('shouldReplaceIcons')) { |
|
179 | - return (bool)$value; |
|
180 | - } |
|
181 | - $value = false; |
|
182 | - if(extension_loaded('imagick')) { |
|
183 | - $checkImagick = new \Imagick(); |
|
184 | - if (count($checkImagick->queryFormats('SVG')) >= 1) { |
|
185 | - $value = true; |
|
186 | - } |
|
187 | - $checkImagick->clear(); |
|
188 | - } |
|
189 | - $cache->set('shouldReplaceIcons', $value); |
|
190 | - return $value; |
|
191 | - } |
|
192 | - |
|
193 | - /** |
|
194 | - * Gets the current cache buster count |
|
195 | - * |
|
196 | - * @return string |
|
197 | - */ |
|
198 | - public function getCacheBusterCounter() { |
|
199 | - return $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
200 | - } |
|
201 | - |
|
202 | - /** |
|
203 | - * Increases the cache buster key |
|
204 | - */ |
|
205 | - private function increaseCacheBuster() { |
|
206 | - $cacheBusterKey = $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
207 | - $this->config->setAppValue('theming', 'cachebuster', (int)$cacheBusterKey+1); |
|
208 | - } |
|
209 | - |
|
210 | - /** |
|
211 | - * Update setting in the database |
|
212 | - * |
|
213 | - * @param string $setting |
|
214 | - * @param string $value |
|
215 | - */ |
|
216 | - public function set($setting, $value) { |
|
217 | - $this->config->setAppValue('theming', $setting, $value); |
|
218 | - $this->increaseCacheBuster(); |
|
219 | - } |
|
220 | - |
|
221 | - /** |
|
222 | - * Revert settings to the default value |
|
223 | - * |
|
224 | - * @param string $setting setting which should be reverted |
|
225 | - * @return string default value |
|
226 | - */ |
|
227 | - public function undo($setting) { |
|
228 | - $this->config->deleteAppValue('theming', $setting); |
|
229 | - $this->increaseCacheBuster(); |
|
230 | - |
|
231 | - switch ($setting) { |
|
232 | - case 'name': |
|
233 | - $returnValue = $this->getEntity(); |
|
234 | - break; |
|
235 | - case 'url': |
|
236 | - $returnValue = $this->getBaseUrl(); |
|
237 | - break; |
|
238 | - case 'slogan': |
|
239 | - $returnValue = $this->getSlogan(); |
|
240 | - break; |
|
241 | - case 'color': |
|
242 | - $returnValue = $this->getColorPrimary(); |
|
243 | - break; |
|
244 | - default: |
|
245 | - $returnValue = ''; |
|
246 | - break; |
|
247 | - } |
|
248 | - |
|
249 | - return $returnValue; |
|
250 | - } |
|
35 | + /** @var IConfig */ |
|
36 | + private $config; |
|
37 | + /** @var IL10N */ |
|
38 | + private $l; |
|
39 | + /** @var IURLGenerator */ |
|
40 | + private $urlGenerator; |
|
41 | + /** @var IAppData */ |
|
42 | + private $appData; |
|
43 | + /** @var ICacheFactory */ |
|
44 | + private $cacheFactory; |
|
45 | + /** @var string */ |
|
46 | + private $name; |
|
47 | + /** @var string */ |
|
48 | + private $url; |
|
49 | + /** @var string */ |
|
50 | + private $slogan; |
|
51 | + /** @var string */ |
|
52 | + private $color; |
|
53 | + |
|
54 | + /** |
|
55 | + * ThemingDefaults constructor. |
|
56 | + * |
|
57 | + * @param IConfig $config |
|
58 | + * @param IL10N $l |
|
59 | + * @param IURLGenerator $urlGenerator |
|
60 | + * @param \OC_Defaults $defaults |
|
61 | + * @param IAppData $appData |
|
62 | + * @param ICacheFactory $cacheFactory |
|
63 | + */ |
|
64 | + public function __construct(IConfig $config, |
|
65 | + IL10N $l, |
|
66 | + IURLGenerator $urlGenerator, |
|
67 | + \OC_Defaults $defaults, |
|
68 | + IAppData $appData, |
|
69 | + ICacheFactory $cacheFactory |
|
70 | + ) { |
|
71 | + parent::__construct(); |
|
72 | + $this->config = $config; |
|
73 | + $this->l = $l; |
|
74 | + $this->urlGenerator = $urlGenerator; |
|
75 | + $this->appData = $appData; |
|
76 | + $this->cacheFactory = $cacheFactory; |
|
77 | + |
|
78 | + $this->name = $defaults->getName(); |
|
79 | + $this->url = $defaults->getBaseUrl(); |
|
80 | + $this->slogan = $defaults->getSlogan(); |
|
81 | + $this->color = $defaults->getColorPrimary(); |
|
82 | + } |
|
83 | + |
|
84 | + public function getName() { |
|
85 | + return strip_tags($this->config->getAppValue('theming', 'name', $this->name)); |
|
86 | + } |
|
87 | + |
|
88 | + public function getHTMLName() { |
|
89 | + return $this->config->getAppValue('theming', 'name', $this->name); |
|
90 | + } |
|
91 | + |
|
92 | + public function getTitle() { |
|
93 | + return $this->getName(); |
|
94 | + } |
|
95 | + |
|
96 | + public function getEntity() { |
|
97 | + return $this->getName(); |
|
98 | + } |
|
99 | + |
|
100 | + public function getBaseUrl() { |
|
101 | + return $this->config->getAppValue('theming', 'url', $this->url); |
|
102 | + } |
|
103 | + |
|
104 | + public function getSlogan() { |
|
105 | + return Util::sanitizeHTML($this->config->getAppValue('theming', 'slogan', $this->slogan)); |
|
106 | + } |
|
107 | + |
|
108 | + public function getShortFooter() { |
|
109 | + $slogan = $this->getSlogan(); |
|
110 | + $footer = '<a href="'. $this->getBaseUrl() . '" target="_blank"' . |
|
111 | + ' rel="noreferrer">' .$this->getEntity() . '</a>'. |
|
112 | + ($slogan !== '' ? ' – ' . $slogan : ''); |
|
113 | + |
|
114 | + return $footer; |
|
115 | + } |
|
116 | + |
|
117 | + /** |
|
118 | + * Color that is used for the header as well as for mail headers |
|
119 | + * |
|
120 | + * @return string |
|
121 | + */ |
|
122 | + public function getColorPrimary() { |
|
123 | + return $this->config->getAppValue('theming', 'color', $this->color); |
|
124 | + } |
|
125 | + |
|
126 | + /** |
|
127 | + * Themed logo url |
|
128 | + * |
|
129 | + * @return string |
|
130 | + */ |
|
131 | + public function getLogo() { |
|
132 | + $logo = $this->config->getAppValue('theming', 'logoMime'); |
|
133 | + |
|
134 | + $logoExists = true; |
|
135 | + try { |
|
136 | + $this->appData->getFolder('images')->getFile('logo'); |
|
137 | + } catch (\Exception $e) { |
|
138 | + $logoExists = false; |
|
139 | + } |
|
140 | + |
|
141 | + if(!$logo || !$logoExists) { |
|
142 | + return $this->urlGenerator->imagePath('core','logo.svg'); |
|
143 | + } |
|
144 | + |
|
145 | + return $this->urlGenerator->linkToRoute('theming.Theming.getLogo'); |
|
146 | + } |
|
147 | + |
|
148 | + /** |
|
149 | + * Themed background image url |
|
150 | + * |
|
151 | + * @return string |
|
152 | + */ |
|
153 | + public function getBackground() { |
|
154 | + $backgroundLogo = $this->config->getAppValue('theming', 'backgroundMime'); |
|
155 | + |
|
156 | + $backgroundExists = true; |
|
157 | + try { |
|
158 | + $this->appData->getFolder('images')->getFile('background'); |
|
159 | + } catch (\Exception $e) { |
|
160 | + $backgroundExists = false; |
|
161 | + } |
|
162 | + |
|
163 | + if(!$backgroundLogo || !$backgroundExists) { |
|
164 | + return $this->urlGenerator->imagePath('core','background.jpg'); |
|
165 | + } |
|
166 | + |
|
167 | + return $this->urlGenerator->linkToRoute('theming.Theming.getLoginBackground'); |
|
168 | + } |
|
169 | + |
|
170 | + /** |
|
171 | + * Check if Imagemagick is enabled and if SVG is supported |
|
172 | + * otherwise we can't render custom icons |
|
173 | + * |
|
174 | + * @return bool |
|
175 | + */ |
|
176 | + public function shouldReplaceIcons() { |
|
177 | + $cache = $this->cacheFactory->create('theming'); |
|
178 | + if($value = $cache->get('shouldReplaceIcons')) { |
|
179 | + return (bool)$value; |
|
180 | + } |
|
181 | + $value = false; |
|
182 | + if(extension_loaded('imagick')) { |
|
183 | + $checkImagick = new \Imagick(); |
|
184 | + if (count($checkImagick->queryFormats('SVG')) >= 1) { |
|
185 | + $value = true; |
|
186 | + } |
|
187 | + $checkImagick->clear(); |
|
188 | + } |
|
189 | + $cache->set('shouldReplaceIcons', $value); |
|
190 | + return $value; |
|
191 | + } |
|
192 | + |
|
193 | + /** |
|
194 | + * Gets the current cache buster count |
|
195 | + * |
|
196 | + * @return string |
|
197 | + */ |
|
198 | + public function getCacheBusterCounter() { |
|
199 | + return $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
200 | + } |
|
201 | + |
|
202 | + /** |
|
203 | + * Increases the cache buster key |
|
204 | + */ |
|
205 | + private function increaseCacheBuster() { |
|
206 | + $cacheBusterKey = $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
207 | + $this->config->setAppValue('theming', 'cachebuster', (int)$cacheBusterKey+1); |
|
208 | + } |
|
209 | + |
|
210 | + /** |
|
211 | + * Update setting in the database |
|
212 | + * |
|
213 | + * @param string $setting |
|
214 | + * @param string $value |
|
215 | + */ |
|
216 | + public function set($setting, $value) { |
|
217 | + $this->config->setAppValue('theming', $setting, $value); |
|
218 | + $this->increaseCacheBuster(); |
|
219 | + } |
|
220 | + |
|
221 | + /** |
|
222 | + * Revert settings to the default value |
|
223 | + * |
|
224 | + * @param string $setting setting which should be reverted |
|
225 | + * @return string default value |
|
226 | + */ |
|
227 | + public function undo($setting) { |
|
228 | + $this->config->deleteAppValue('theming', $setting); |
|
229 | + $this->increaseCacheBuster(); |
|
230 | + |
|
231 | + switch ($setting) { |
|
232 | + case 'name': |
|
233 | + $returnValue = $this->getEntity(); |
|
234 | + break; |
|
235 | + case 'url': |
|
236 | + $returnValue = $this->getBaseUrl(); |
|
237 | + break; |
|
238 | + case 'slogan': |
|
239 | + $returnValue = $this->getSlogan(); |
|
240 | + break; |
|
241 | + case 'color': |
|
242 | + $returnValue = $this->getColorPrimary(); |
|
243 | + break; |
|
244 | + default: |
|
245 | + $returnValue = ''; |
|
246 | + break; |
|
247 | + } |
|
248 | + |
|
249 | + return $returnValue; |
|
250 | + } |
|
251 | 251 | |
252 | 252 | } |
@@ -107,9 +107,9 @@ discard block |
||
107 | 107 | |
108 | 108 | public function getShortFooter() { |
109 | 109 | $slogan = $this->getSlogan(); |
110 | - $footer = '<a href="'. $this->getBaseUrl() . '" target="_blank"' . |
|
111 | - ' rel="noreferrer">' .$this->getEntity() . '</a>'. |
|
112 | - ($slogan !== '' ? ' – ' . $slogan : ''); |
|
110 | + $footer = '<a href="'.$this->getBaseUrl().'" target="_blank"'. |
|
111 | + ' rel="noreferrer">'.$this->getEntity().'</a>'. |
|
112 | + ($slogan !== '' ? ' – '.$slogan : ''); |
|
113 | 113 | |
114 | 114 | return $footer; |
115 | 115 | } |
@@ -138,8 +138,8 @@ discard block |
||
138 | 138 | $logoExists = false; |
139 | 139 | } |
140 | 140 | |
141 | - if(!$logo || !$logoExists) { |
|
142 | - return $this->urlGenerator->imagePath('core','logo.svg'); |
|
141 | + if (!$logo || !$logoExists) { |
|
142 | + return $this->urlGenerator->imagePath('core', 'logo.svg'); |
|
143 | 143 | } |
144 | 144 | |
145 | 145 | return $this->urlGenerator->linkToRoute('theming.Theming.getLogo'); |
@@ -160,8 +160,8 @@ discard block |
||
160 | 160 | $backgroundExists = false; |
161 | 161 | } |
162 | 162 | |
163 | - if(!$backgroundLogo || !$backgroundExists) { |
|
164 | - return $this->urlGenerator->imagePath('core','background.jpg'); |
|
163 | + if (!$backgroundLogo || !$backgroundExists) { |
|
164 | + return $this->urlGenerator->imagePath('core', 'background.jpg'); |
|
165 | 165 | } |
166 | 166 | |
167 | 167 | return $this->urlGenerator->linkToRoute('theming.Theming.getLoginBackground'); |
@@ -175,11 +175,11 @@ discard block |
||
175 | 175 | */ |
176 | 176 | public function shouldReplaceIcons() { |
177 | 177 | $cache = $this->cacheFactory->create('theming'); |
178 | - if($value = $cache->get('shouldReplaceIcons')) { |
|
179 | - return (bool)$value; |
|
178 | + if ($value = $cache->get('shouldReplaceIcons')) { |
|
179 | + return (bool) $value; |
|
180 | 180 | } |
181 | 181 | $value = false; |
182 | - if(extension_loaded('imagick')) { |
|
182 | + if (extension_loaded('imagick')) { |
|
183 | 183 | $checkImagick = new \Imagick(); |
184 | 184 | if (count($checkImagick->queryFormats('SVG')) >= 1) { |
185 | 185 | $value = true; |
@@ -204,7 +204,7 @@ discard block |
||
204 | 204 | */ |
205 | 205 | private function increaseCacheBuster() { |
206 | 206 | $cacheBusterKey = $this->config->getAppValue('theming', 'cachebuster', '0'); |
207 | - $this->config->setAppValue('theming', 'cachebuster', (int)$cacheBusterKey+1); |
|
207 | + $this->config->setAppValue('theming', 'cachebuster', (int) $cacheBusterKey + 1); |
|
208 | 208 | } |
209 | 209 | |
210 | 210 | /** |