Browse Source
Merge pull request #22891 from nextcloud/techdebt/18680/improve-ProvisioningApiMiddleware-service-logic
Improve registerService logic for ProvisioningApiMiddleware for static code analysis
pull/23209/head
Morris Jobke
5 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
13 additions and
7 deletions
-
apps/provisioning_api/lib/AppInfo/Application.php
-
build/psalm-baseline.xml
|
|
|
@ -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, |
|
|
|
|
|
|
|
@ -2115,11 +2115,6 @@ |
|
|
|
<file src="apps/oauth2/lib/Db/ClientMapper.php"> |
|
|
|
<InvalidCatch occurrences="2"/> |
|
|
|
</file> |
|
|
|
<file src="apps/provisioning_api/lib/AppInfo/Application.php"> |
|
|
|
<UndefinedInterfaceMethod occurrences="1"> |
|
|
|
<code>getSubAdmin</code> |
|
|
|
</UndefinedInterfaceMethod> |
|
|
|
</file> |
|
|
|
<file src="apps/provisioning_api/lib/Controller/UsersController.php"> |
|
|
|
<InvalidScalarArgument occurrences="1"> |
|
|
|
<code>$quota</code> |
|
|
|
|