1<?php 2/** 3 * @copyright Copyright (c) 2016 Roeland Jago Douma <roeland@famdouma.nl> 4 * 5 * @author Christoph Wurst <christoph@winzerhof-wurst.at> 6 * @author Daniel Kesselberg <mail@danielkesselberg.de> 7 * @author Joas Schilling <coding@schilljs.com> 8 * @author Lukas Reschke <lukas@statuscode.ch> 9 * @author Morris Jobke <hey@morrisjobke.de> 10 * @author Roeland Jago Douma <roeland@famdouma.nl> 11 * @author Vincent Petry <vincent@nextcloud.com> 12 * 13 * @license GNU AGPL version 3 or any later version 14 * 15 * This program is free software: you can redistribute it and/or modify 16 * it under the terms of the GNU Affero General Public License as 17 * published by the Free Software Foundation, either version 3 of the 18 * License, or (at your option) any later version. 19 * 20 * This program is distributed in the hope that it will be useful, 21 * but WITHOUT ANY WARRANTY; without even the implied warranty of 22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 23 * GNU Affero General Public License for more details. 24 * 25 * You should have received a copy of the GNU Affero General Public License 26 * along with this program. If not, see <http://www.gnu.org/licenses/>. 27 * 28 */ 29namespace OCA\Provisioning_API\AppInfo; 30 31use OC\Group\Manager as GroupManager; 32use OCA\Provisioning_API\Capabilities; 33use OCA\Provisioning_API\Listener\UserDeletedListener; 34use OCA\Provisioning_API\Middleware\ProvisioningApiMiddleware; 35use OCA\Settings\Mailer\NewUserMailHelper; 36use OCP\AppFramework\App; 37use OCP\AppFramework\Bootstrap\IBootContext; 38use OCP\AppFramework\Bootstrap\IBootstrap; 39use OCP\AppFramework\Bootstrap\IRegistrationContext; 40use OCP\AppFramework\Utility\IControllerMethodReflector; 41use OCP\AppFramework\Utility\ITimeFactory; 42use OCP\Defaults; 43use OCP\IConfig; 44use OCP\IGroupManager; 45use OCP\IURLGenerator; 46use OCP\IUser; 47use OCP\IUserManager; 48use OCP\L10N\IFactory; 49use OCP\Mail\IMailer; 50use OCP\Security\ICrypto; 51use OCP\Security\ISecureRandom; 52use OCP\User\Events\UserDeletedEvent; 53use OCP\Util; 54use Psr\Container\ContainerInterface; 55 56class Application extends App implements IBootstrap { 57 public function __construct(array $urlParams = []) { 58 parent::__construct('provisioning_api', $urlParams); 59 } 60 61 public function register(IRegistrationContext $context): void { 62 $context->registerEventListener(UserDeletedEvent::class, UserDeletedListener::class); 63 64 $context->registerService(NewUserMailHelper::class, function (ContainerInterface $c) { 65 return new NewUserMailHelper( 66 $c->get(Defaults::class), 67 $c->get(IURLGenerator::class), 68 $c->get(IFactory::class), 69 $c->get(IMailer::class), 70 $c->get(ISecureRandom::class), 71 $c->get(ITimeFactory::class), 72 $c->get(IConfig::class), 73 $c->get(ICrypto::class), 74 Util::getDefaultEmailAddress('no-reply') 75 ); 76 }); 77 $context->registerService(ProvisioningApiMiddleware::class, function (ContainerInterface $c) { 78 $user = $c->get(IUserManager::class)->get($c->get('UserId')); 79 $isAdmin = false; 80 $isSubAdmin = false; 81 82 if ($user instanceof IUser) { 83 $groupManager = $c->get(IGroupManager::class); 84 assert($groupManager instanceof GroupManager); 85 $isAdmin = $groupManager->isAdmin($user->getUID()); 86 $isSubAdmin = $groupManager->getSubAdmin()->isSubAdmin($user); 87 } 88 89 return new ProvisioningApiMiddleware( 90 $c->get(IControllerMethodReflector::class), 91 $isAdmin, 92 $isSubAdmin 93 ); 94 }); 95 $context->registerMiddleware(ProvisioningApiMiddleware::class); 96 $context->registerCapability(Capabilities::class); 97 } 98 99 public function boot(IBootContext $context): void { 100 } 101} 102