Application.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. /**
  3. *
  4. *
  5. * @author Lukas Reschke <lukas@statuscode.ch>
  6. * @author Morris Jobke <hey@morrisjobke.de>
  7. * @author Roeland Jago Douma <roeland@famdouma.nl>
  8. *
  9. * @license GNU AGPL version 3 or any later version
  10. *
  11. * This program is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Affero General Public License as
  13. * published by the Free Software Foundation, either version 3 of the
  14. * License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  23. *
  24. */
  25. namespace OCA\Provisioning_API\AppInfo;
  26. use OC\AppFramework\Utility\SimpleContainer;
  27. use OC\AppFramework\Utility\TimeFactory;
  28. use OC\Settings\Mailer\NewUserMailHelper;
  29. use OCA\Provisioning_API\Middleware\ProvisioningApiMiddleware;
  30. use OCP\AppFramework\App;
  31. use OCP\AppFramework\Utility\IControllerMethodReflector;
  32. use OCP\Defaults;
  33. use OCP\Util;
  34. class Application extends App {
  35. public function __construct(array $urlParams = array()) {
  36. parent::__construct('provisioning_api', $urlParams);
  37. $container = $this->getContainer();
  38. $server = $container->getServer();
  39. $container->registerService(NewUserMailHelper::class, function(SimpleContainer $c) use ($server) {
  40. return new NewUserMailHelper(
  41. $server->query(Defaults::class),
  42. $server->getURLGenerator(),
  43. $server->getL10NFactory(),
  44. $server->getMailer(),
  45. $server->getSecureRandom(),
  46. new TimeFactory(),
  47. $server->getConfig(),
  48. $server->getCrypto(),
  49. Util::getDefaultEmailAddress('no-reply')
  50. );
  51. });
  52. $container->registerService('ProvisioningApiMiddleware', function(SimpleContainer $c) use ($server) {
  53. $user = $server->getUserManager()->get($c['UserId']);
  54. $isAdmin = $user !== null ? $server->getGroupManager()->isAdmin($user->getUID()) : false;
  55. $isSubAdmin = $user !== null ? $server->getGroupManager()->getSubAdmin()->isSubAdmin($user) : false;
  56. return new ProvisioningApiMiddleware(
  57. $c->query(IControllerMethodReflector::class),
  58. $isAdmin,
  59. $isSubAdmin
  60. );
  61. });
  62. $container->registerMiddleWare('ProvisioningApiMiddleware');
  63. }
  64. }