diff options
author | Morris Jobke <hey@morrisjobke.de> | 2020-10-05 21:50:50 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-05 21:50:50 +0200 |
commit | 482b42c4a70f2a2cfa30e329405052afbbea3de4 (patch) | |
tree | c7bcf3d68d58a6ac2746210bf72276f20abd87f5 /apps/provisioning_api/lib | |
parent | 0f7fb7cb4e296f6b90d668eb9cd01bcd6ef0c582 (diff) | |
parent | a65b431f518db2b3146b89fc0a9b8be600673bf0 (diff) | |
download | nextcloud-server-482b42c4a70f2a2cfa30e329405052afbbea3de4.tar.gz nextcloud-server-482b42c4a70f2a2cfa30e329405052afbbea3de4.zip |
Merge pull request #22891 from nextcloud/techdebt/18680/improve-ProvisioningApiMiddleware-service-logic
Improve registerService logic for ProvisioningApiMiddleware for static code analysis
Diffstat (limited to 'apps/provisioning_api/lib')
-rw-r--r-- | apps/provisioning_api/lib/AppInfo/Application.php | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/apps/provisioning_api/lib/AppInfo/Application.php b/apps/provisioning_api/lib/AppInfo/Application.php index 6d99c48be5d..c706cd38a10 100644 --- a/apps/provisioning_api/lib/AppInfo/Application.php +++ b/apps/provisioning_api/lib/AppInfo/Application.php @@ -29,11 +29,14 @@ 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; use OCP\AppFramework\App; use OCP\AppFramework\Utility\IControllerMethodReflector; use OCP\Defaults; +use OCP\IGroupManager; +use OCP\IUser; use OCP\Util; class Application extends App { @@ -58,8 +61,16 @@ class Application extends App { }); $container->registerService('ProvisioningApiMiddleware', function (SimpleContainer $c) use ($server) { $user = $server->getUserManager()->get($c['UserId']); - $isAdmin = $user !== null ? $server->getGroupManager()->isAdmin($user->getUID()) : false; - $isSubAdmin = $user !== null ? $server->getGroupManager()->getSubAdmin()->isSubAdmin($user) : false; + $isAdmin = false; + $isSubAdmin = false; + + if ($user instanceof IUser) { + $groupManager = $server->get(IGroupManager::class); + assert($groupManager instanceof GroupManager); + $isAdmin = $groupManager->isAdmin($user->getUID()); + $isSubAdmin = $groupManager->getSubAdmin()->isSubAdmin($user); + } + return new ProvisioningApiMiddleware( $c->query(IControllerMethodReflector::class), $isAdmin, |