Application.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Björn Schießle <bjoern@schiessle.org>
  6. * @author Christoph Wurst <christoph@owncloud.com>
  7. * @author Georg Ehrke <georg@owncloud.com>
  8. * @author Joas Schilling <coding@schilljs.com>
  9. * @author Lukas Reschke <lukas@statuscode.ch>
  10. * @author Morris Jobke <hey@morrisjobke.de>
  11. * @author Robin Appelman <robin@icewind.nl>
  12. * @author Roeland Jago Douma <roeland@famdouma.nl>
  13. * @author Thomas Müller <thomas.mueller@tmit.eu>
  14. *
  15. * @license AGPL-3.0
  16. *
  17. * This code is free software: you can redistribute it and/or modify
  18. * it under the terms of the GNU Affero General Public License, version 3,
  19. * as published by the Free Software Foundation.
  20. *
  21. * This program is distributed in the hope that it will be useful,
  22. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. * GNU Affero General Public License for more details.
  25. *
  26. * You should have received a copy of the GNU Affero General Public License, version 3,
  27. * along with this program. If not, see <http://www.gnu.org/licenses/>
  28. *
  29. */
  30. namespace OC\Settings;
  31. use OC\App\AppStore\Fetcher\AppFetcher;
  32. use OC\App\AppStore\Fetcher\CategoryFetcher;
  33. use OC\AppFramework\Utility\TimeFactory;
  34. use OC\Authentication\Token\IProvider;
  35. use OC\Server;
  36. use OC\Settings\Middleware\SubadminMiddleware;
  37. use OCP\AppFramework\App;
  38. use OCP\IContainer;
  39. use OCP\Settings\IManager;
  40. use OCP\Util;
  41. /**
  42. * @package OC\Settings
  43. */
  44. class Application extends App {
  45. /**
  46. * @param array $urlParams
  47. */
  48. public function __construct(array $urlParams=[]){
  49. parent::__construct('settings', $urlParams);
  50. $container = $this->getContainer();
  51. // Register Middleware
  52. $container->registerAlias('SubadminMiddleware', SubadminMiddleware::class);
  53. $container->registerMiddleWare('SubadminMiddleware');
  54. /**
  55. * Core class wrappers
  56. */
  57. /** FIXME: Remove once OC_User is non-static and mockable */
  58. $container->registerService('isAdmin', function() {
  59. return \OC_User::isAdminUser(\OC_User::getUser());
  60. });
  61. /** FIXME: Remove once OC_SubAdmin is non-static and mockable */
  62. $container->registerService('isSubAdmin', function(IContainer $c) {
  63. $userObject = \OC::$server->getUserSession()->getUser();
  64. $isSubAdmin = false;
  65. if($userObject !== null) {
  66. $isSubAdmin = \OC::$server->getGroupManager()->getSubAdmin()->isSubAdmin($userObject);
  67. }
  68. return $isSubAdmin;
  69. });
  70. $container->registerService('fromMailAddress', function() {
  71. return Util::getDefaultEmailAddress('no-reply');
  72. });
  73. $container->registerService('userCertificateManager', function(IContainer $c) {
  74. return $c->query('ServerContainer')->getCertificateManager();
  75. }, false);
  76. $container->registerService('systemCertificateManager', function (IContainer $c) {
  77. return $c->query('ServerContainer')->getCertificateManager(null);
  78. }, false);
  79. $container->registerService(IProvider::class, function (IContainer $c) {
  80. return $c->query('ServerContainer')->query(IProvider::class);
  81. });
  82. $container->registerService(IManager::class, function (IContainer $c) {
  83. return $c->query('ServerContainer')->getSettingsManager();
  84. });
  85. $container->registerService(AppFetcher::class, function (IContainer $c) {
  86. /** @var Server $server */
  87. $server = $c->query('ServerContainer');
  88. return new AppFetcher(
  89. $server->getAppDataDir('appstore'),
  90. $server->getHTTPClientService(),
  91. $server->query(TimeFactory::class),
  92. $server->getConfig()
  93. );
  94. });
  95. $container->registerService(CategoryFetcher::class, function (IContainer $c) {
  96. /** @var Server $server */
  97. $server = $c->query('ServerContainer');
  98. return new CategoryFetcher(
  99. $server->getAppDataDir('appstore'),
  100. $server->getHTTPClientService(),
  101. $server->query(TimeFactory::class)
  102. );
  103. });
  104. }
  105. }