1
0

application.php 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Björn Schießle <bjoern@schiessle.org>
  6. * @author Georg Ehrke <georg@owncloud.com>
  7. * @author Joas Schilling <coding@schilljs.com>
  8. * @author Lukas Reschke <lukas@statuscode.ch>
  9. * @author Morris Jobke <hey@morrisjobke.de>
  10. * @author Robin Appelman <robin@icewind.nl>
  11. * @author Roeland Jago Douma <roeland@famdouma.nl>
  12. * @author Thomas Müller <thomas.mueller@tmit.eu>
  13. *
  14. * @license AGPL-3.0
  15. *
  16. * This code is free software: you can redistribute it and/or modify
  17. * it under the terms of the GNU Affero General Public License, version 3,
  18. * as published by the Free Software Foundation.
  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, version 3,
  26. * along with this program. If not, see <http://www.gnu.org/licenses/>
  27. *
  28. */
  29. namespace OC\Settings;
  30. use OC\Files\View;
  31. use OC\Settings\Controller\AppSettingsController;
  32. use OC\Settings\Controller\CertificateController;
  33. use OC\Settings\Controller\CheckSetupController;
  34. use OC\Settings\Controller\EncryptionController;
  35. use OC\Settings\Controller\GroupsController;
  36. use OC\Settings\Controller\LogSettingsController;
  37. use OC\Settings\Controller\MailSettingsController;
  38. use OC\Settings\Controller\SecuritySettingsController;
  39. use OC\Settings\Controller\UsersController;
  40. use OC\Settings\Middleware\SubadminMiddleware;
  41. use \OCP\AppFramework\App;
  42. use OCP\IContainer;
  43. use \OCP\Util;
  44. use OC\Server;
  45. /**
  46. * @package OC\Settings
  47. */
  48. class Application extends App {
  49. /**
  50. * @param array $urlParams
  51. */
  52. public function __construct(array $urlParams=[]){
  53. parent::__construct('settings', $urlParams);
  54. $container = $this->getContainer();
  55. /**
  56. * Controllers
  57. */
  58. $container->registerService('MailSettingsController', function(IContainer $c) {
  59. return new MailSettingsController(
  60. $c->query('AppName'),
  61. $c->query('Request'),
  62. $c->query('L10N'),
  63. $c->query('Config'),
  64. $c->query('UserSession'),
  65. $c->query('Defaults'),
  66. $c->query('Mailer'),
  67. $c->query('DefaultMailAddress')
  68. );
  69. });
  70. $container->registerService('EncryptionController', function(IContainer $c) {
  71. return new EncryptionController(
  72. $c->query('AppName'),
  73. $c->query('Request'),
  74. $c->query('L10N'),
  75. $c->query('Config'),
  76. $c->query('DatabaseConnection'),
  77. $c->query('UserManager'),
  78. new View(),
  79. $c->query('Logger')
  80. );
  81. });
  82. $container->registerService('AppSettingsController', function(IContainer $c) {
  83. return new AppSettingsController(
  84. $c->query('AppName'),
  85. $c->query('Request'),
  86. $c->query('L10N'),
  87. $c->query('Config'),
  88. $c->query('ICacheFactory'),
  89. $c->query('INavigationManager'),
  90. $c->query('IAppManager'),
  91. $c->query('OcsClient')
  92. );
  93. });
  94. $container->registerService('SecuritySettingsController', function(IContainer $c) {
  95. return new SecuritySettingsController(
  96. $c->query('AppName'),
  97. $c->query('Request'),
  98. $c->query('Config')
  99. );
  100. });
  101. $container->registerService('CertificateController', function(IContainer $c) {
  102. return new CertificateController(
  103. $c->query('AppName'),
  104. $c->query('Request'),
  105. $c->query('CertificateManager'),
  106. $c->query('SystemCertificateManager'),
  107. $c->query('L10N'),
  108. $c->query('IAppManager')
  109. );
  110. });
  111. $container->registerService('GroupsController', function(IContainer $c) {
  112. return new GroupsController(
  113. $c->query('AppName'),
  114. $c->query('Request'),
  115. $c->query('GroupManager'),
  116. $c->query('UserSession'),
  117. $c->query('IsAdmin'),
  118. $c->query('L10N')
  119. );
  120. });
  121. $container->registerService('UsersController', function(IContainer $c) {
  122. return new UsersController(
  123. $c->query('AppName'),
  124. $c->query('Request'),
  125. $c->query('UserManager'),
  126. $c->query('GroupManager'),
  127. $c->query('UserSession'),
  128. $c->query('Config'),
  129. $c->query('IsAdmin'),
  130. $c->query('L10N'),
  131. $c->query('Logger'),
  132. $c->query('Defaults'),
  133. $c->query('Mailer'),
  134. $c->query('DefaultMailAddress'),
  135. $c->query('URLGenerator'),
  136. $c->query('OCP\\App\\IAppManager'),
  137. $c->query('OCP\\IAvatarManager')
  138. );
  139. });
  140. $container->registerService('LogSettingsController', function(IContainer $c) {
  141. return new LogSettingsController(
  142. $c->query('AppName'),
  143. $c->query('Request'),
  144. $c->query('Config'),
  145. $c->query('L10N')
  146. );
  147. });
  148. $container->registerService('CheckSetupController', function(IContainer $c) {
  149. return new CheckSetupController(
  150. $c->query('AppName'),
  151. $c->query('Request'),
  152. $c->query('Config'),
  153. $c->query('ClientService'),
  154. $c->query('URLGenerator'),
  155. $c->query('Util'),
  156. $c->query('L10N'),
  157. $c->query('Checker')
  158. );
  159. });
  160. /**
  161. * Middleware
  162. */
  163. $container->registerService('SubadminMiddleware', function(IContainer $c){
  164. return new SubadminMiddleware(
  165. $c->query('ControllerMethodReflector'),
  166. $c->query('IsSubAdmin')
  167. );
  168. });
  169. // Execute middlewares
  170. $container->registerMiddleware('SubadminMiddleware');
  171. /**
  172. * Core class wrappers
  173. */
  174. $container->registerService('Config', function(IContainer $c) {
  175. return $c->query('ServerContainer')->getConfig();
  176. });
  177. $container->registerService('ICacheFactory', function(IContainer $c) {
  178. return $c->query('ServerContainer')->getMemCacheFactory();
  179. });
  180. $container->registerService('L10N', function(IContainer $c) {
  181. return $c->query('ServerContainer')->getL10N('settings');
  182. });
  183. $container->registerService('GroupManager', function(IContainer $c) {
  184. return $c->query('ServerContainer')->getGroupManager();
  185. });
  186. $container->registerService('UserManager', function(IContainer $c) {
  187. return $c->query('ServerContainer')->getUserManager();
  188. });
  189. $container->registerService('UserSession', function(IContainer $c) {
  190. return $c->query('ServerContainer')->getUserSession();
  191. });
  192. /** FIXME: Remove once OC_User is non-static and mockable */
  193. $container->registerService('IsAdmin', function(IContainer $c) {
  194. return \OC_User::isAdminUser(\OC_User::getUser());
  195. });
  196. /** FIXME: Remove once OC_SubAdmin is non-static and mockable */
  197. $container->registerService('IsSubAdmin', function(IContainer $c) {
  198. $userObject = \OC::$server->getUserSession()->getUser();
  199. $isSubAdmin = false;
  200. if($userObject !== null) {
  201. $isSubAdmin = \OC::$server->getGroupManager()->getSubAdmin()->isSubAdmin($userObject);
  202. }
  203. return $isSubAdmin;
  204. });
  205. $container->registerService('Mailer', function(IContainer $c) {
  206. return $c->query('ServerContainer')->getMailer();
  207. });
  208. $container->registerService('Defaults', function(IContainer $c) {
  209. return $c->query('ServerContainer')->getThemingDefaults();
  210. });
  211. $container->registerService('DefaultMailAddress', function(IContainer $c) {
  212. return Util::getDefaultEmailAddress('no-reply');
  213. });
  214. $container->registerService('Logger', function(IContainer $c) {
  215. return $c->query('ServerContainer')->getLogger();
  216. });
  217. $container->registerService('URLGenerator', function(IContainer $c) {
  218. return $c->query('ServerContainer')->getURLGenerator();
  219. });
  220. $container->registerService('ClientService', function(IContainer $c) {
  221. return $c->query('ServerContainer')->getHTTPClientService();
  222. });
  223. $container->registerService('INavigationManager', function(IContainer $c) {
  224. return $c->query('ServerContainer')->getNavigationManager();
  225. });
  226. $container->registerService('IAppManager', function(IContainer $c) {
  227. return $c->query('ServerContainer')->getAppManager();
  228. });
  229. $container->registerService('OcsClient', function(IContainer $c) {
  230. return $c->query('ServerContainer')->getOcsClient();
  231. });
  232. $container->registerService('Util', function(IContainer $c) {
  233. return new \OC_Util();
  234. });
  235. $container->registerService('DatabaseConnection', function(IContainer $c) {
  236. return $c->query('ServerContainer')->getDatabaseConnection();
  237. });
  238. $container->registerService('CertificateManager', function(IContainer $c){
  239. return $c->query('ServerContainer')->getCertificateManager();
  240. });
  241. $container->registerService('SystemCertificateManager', function (IContainer $c) {
  242. return $c->query('ServerContainer')->getCertificateManager(null);
  243. });
  244. $container->registerService('Checker', function(IContainer $c) {
  245. /** @var Server $server */
  246. $server = $c->query('ServerContainer');
  247. return $server->getIntegrityCodeChecker();
  248. });
  249. }
  250. }