From fa2dc9abc5553f3bbac5f86869502a9c4d1958b1 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Tue, 9 Mar 2021 20:17:44 +0100 Subject: [PATCH 1/2] Provisioning API to IBootstrap Signed-off-by: Roeland Jago Douma --- .../lib/AppInfo/Application.php | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/apps/provisioning_api/lib/AppInfo/Application.php b/apps/provisioning_api/lib/AppInfo/Application.php index 9e386e9906..de9d91e0b6 100644 --- a/apps/provisioning_api/lib/AppInfo/Application.php +++ b/apps/provisioning_api/lib/AppInfo/Application.php @@ -34,20 +34,24 @@ use OC\Group\Manager as GroupManager; use OCA\Provisioning_API\Middleware\ProvisioningApiMiddleware; use OCA\Settings\Mailer\NewUserMailHelper; use OCP\AppFramework\App; +use OCP\AppFramework\Bootstrap\IBootContext; +use OCP\AppFramework\Bootstrap\IBootstrap; +use OCP\AppFramework\Bootstrap\IRegistrationContext; use OCP\AppFramework\Utility\IControllerMethodReflector; use OCP\Defaults; use OCP\IGroupManager; use OCP\IUser; use OCP\Util; -class Application extends App { +class Application extends App implements IBootstrap { public function __construct(array $urlParams = []) { parent::__construct('provisioning_api', $urlParams); + } - $container = $this->getContainer(); - $server = $container->getServer(); + public function register(IRegistrationContext $context): void { + $server = $this->getContainer()->getServer(); - $container->registerService(NewUserMailHelper::class, function (SimpleContainer $c) use ($server) { + $context->registerService(NewUserMailHelper::class, function (SimpleContainer $c) use ($server) { return new NewUserMailHelper( $server->query(Defaults::class), $server->getURLGenerator(), @@ -60,7 +64,7 @@ class Application extends App { Util::getDefaultEmailAddress('no-reply') ); }); - $container->registerService('ProvisioningApiMiddleware', function (SimpleContainer $c) use ($server) { + $context->registerService(ProvisioningApiMiddleware::class, function (SimpleContainer $c) use ($server) { $user = $server->getUserManager()->get($c['UserId']); $isAdmin = false; $isSubAdmin = false; @@ -78,6 +82,9 @@ class Application extends App { $isSubAdmin ); }); - $container->registerMiddleWare('ProvisioningApiMiddleware'); + $context->registerMiddleware(ProvisioningApiMiddleware::class); + } + + public function boot(IBootContext $context): void { } } From a659ee1c2d6f07936f96d75d856dd2356b5e962d Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 10 Mar 2021 12:20:45 +0100 Subject: [PATCH 2/2] Fix some psalm warnings Signed-off-by: Joas Schilling --- .../lib/AppInfo/Application.php | 39 +++++++++++-------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/apps/provisioning_api/lib/AppInfo/Application.php b/apps/provisioning_api/lib/AppInfo/Application.php index de9d91e0b6..863f8861d8 100644 --- a/apps/provisioning_api/lib/AppInfo/Application.php +++ b/apps/provisioning_api/lib/AppInfo/Application.php @@ -28,8 +28,6 @@ namespace OCA\Provisioning_API\AppInfo; -use OC\AppFramework\Utility\SimpleContainer; -use OC\AppFramework\Utility\TimeFactory; use OC\Group\Manager as GroupManager; use OCA\Provisioning_API\Middleware\ProvisioningApiMiddleware; use OCA\Settings\Mailer\NewUserMailHelper; @@ -38,10 +36,19 @@ use OCP\AppFramework\Bootstrap\IBootContext; use OCP\AppFramework\Bootstrap\IBootstrap; use OCP\AppFramework\Bootstrap\IRegistrationContext; use OCP\AppFramework\Utility\IControllerMethodReflector; +use OCP\AppFramework\Utility\ITimeFactory; use OCP\Defaults; +use OCP\IConfig; use OCP\IGroupManager; +use OCP\IURLGenerator; use OCP\IUser; +use OCP\IUserManager; +use OCP\L10N\IFactory; +use OCP\Mail\IMailer; +use OCP\Security\ICrypto; +use OCP\Security\ISecureRandom; use OCP\Util; +use Psr\Container\ContainerInterface; class Application extends App implements IBootstrap { public function __construct(array $urlParams = []) { @@ -49,35 +56,33 @@ class Application extends App implements IBootstrap { } public function register(IRegistrationContext $context): void { - $server = $this->getContainer()->getServer(); - - $context->registerService(NewUserMailHelper::class, function (SimpleContainer $c) use ($server) { + $context->registerService(NewUserMailHelper::class, function (ContainerInterface $c) { return new NewUserMailHelper( - $server->query(Defaults::class), - $server->getURLGenerator(), - $server->getL10NFactory(), - $server->getMailer(), - $server->getSecureRandom(), - new TimeFactory(), - $server->getConfig(), - $server->getCrypto(), + $c->get(Defaults::class), + $c->get(IURLGenerator::class), + $c->get(IFactory::class), + $c->get(IMailer::class), + $c->get(ISecureRandom::class), + $c->get(ITimeFactory::class), + $c->get(IConfig::class), + $c->get(ICrypto::class), Util::getDefaultEmailAddress('no-reply') ); }); - $context->registerService(ProvisioningApiMiddleware::class, function (SimpleContainer $c) use ($server) { - $user = $server->getUserManager()->get($c['UserId']); + $context->registerService(ProvisioningApiMiddleware::class, function (ContainerInterface $c) { + $user = $c->get(IUserManager::class)->get($c->get('UserId')); $isAdmin = false; $isSubAdmin = false; if ($user instanceof IUser) { - $groupManager = $server->get(IGroupManager::class); + $groupManager = $c->get(IGroupManager::class); assert($groupManager instanceof GroupManager); $isAdmin = $groupManager->isAdmin($user->getUID()); $isSubAdmin = $groupManager->getSubAdmin()->isSubAdmin($user); } return new ProvisioningApiMiddleware( - $c->query(IControllerMethodReflector::class), + $c->get(IControllerMethodReflector::class), $isAdmin, $isSubAdmin );