1
0

Application.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. */
  29. namespace OCA\Provisioning_API\AppInfo;
  30. use OC\Group\Manager as GroupManager;
  31. use OCA\Provisioning_API\Capabilities;
  32. use OCA\Provisioning_API\Listener\UserDeletedListener;
  33. use OCA\Provisioning_API\Middleware\ProvisioningApiMiddleware;
  34. use OCA\Settings\Mailer\NewUserMailHelper;
  35. use OCP\AppFramework\App;
  36. use OCP\AppFramework\Bootstrap\IBootContext;
  37. use OCP\AppFramework\Bootstrap\IBootstrap;
  38. use OCP\AppFramework\Bootstrap\IRegistrationContext;
  39. use OCP\AppFramework\Utility\IControllerMethodReflector;
  40. use OCP\AppFramework\Utility\ITimeFactory;
  41. use OCP\Defaults;
  42. use OCP\IConfig;
  43. use OCP\IGroupManager;
  44. use OCP\IURLGenerator;
  45. use OCP\IUser;
  46. use OCP\IUserManager;
  47. use OCP\L10N\IFactory;
  48. use OCP\Mail\IMailer;
  49. use OCP\Security\ICrypto;
  50. use OCP\Security\ISecureRandom;
  51. use OCP\User\Events\UserDeletedEvent;
  52. use OCP\Util;
  53. use Psr\Container\ContainerInterface;
  54. class Application extends App implements IBootstrap {
  55. public function __construct(array $urlParams = []) {
  56. parent::__construct('provisioning_api', $urlParams);
  57. }
  58. public function register(IRegistrationContext $context): void {
  59. $context->registerEventListener(UserDeletedEvent::class, UserDeletedListener::class);
  60. $context->registerService(NewUserMailHelper::class, function (ContainerInterface $c) {
  61. return new NewUserMailHelper(
  62. $c->get(Defaults::class),
  63. $c->get(IURLGenerator::class),
  64. $c->get(IFactory::class),
  65. $c->get(IMailer::class),
  66. $c->get(ISecureRandom::class),
  67. $c->get(ITimeFactory::class),
  68. $c->get(IConfig::class),
  69. $c->get(ICrypto::class),
  70. Util::getDefaultEmailAddress('no-reply')
  71. );
  72. });
  73. $context->registerService(ProvisioningApiMiddleware::class, function (ContainerInterface $c) {
  74. $user = $c->get(IUserManager::class)->get($c->get('UserId'));
  75. $isAdmin = false;
  76. $isSubAdmin = false;
  77. if ($user instanceof IUser) {
  78. $groupManager = $c->get(IGroupManager::class);
  79. assert($groupManager instanceof GroupManager);
  80. $isAdmin = $groupManager->isAdmin($user->getUID());
  81. $isSubAdmin = $groupManager->getSubAdmin()->isSubAdmin($user);
  82. }
  83. return new ProvisioningApiMiddleware(
  84. $c->get(IControllerMethodReflector::class),
  85. $isAdmin,
  86. $isSubAdmin
  87. );
  88. });
  89. $context->registerMiddleware(ProvisioningApiMiddleware::class);
  90. $context->registerCapability(Capabilities::class);
  91. }
  92. public function boot(IBootContext $context): void {
  93. }
  94. }