diff options
-rw-r--r-- | settings/Application.php | 187 | ||||
-rw-r--r-- | settings/Controller/AuthSettingsController.php | 6 | ||||
-rw-r--r-- | settings/Controller/EncryptionController.php | 21 | ||||
-rw-r--r-- | settings/Controller/MailSettingsController.php | 25 | ||||
-rw-r--r-- | tests/Settings/ApplicationTest.php | 46 |
5 files changed, 68 insertions, 217 deletions
diff --git a/settings/Application.php b/settings/Application.php index 5a47be7b3d4..dd237e40c9d 100644 --- a/settings/Application.php +++ b/settings/Application.php @@ -30,18 +30,11 @@ namespace OC\Settings; -use OC\Files\View; -use OC\Server; -use OC\Settings\Controller\AdminSettingsController; -use OC\Settings\Controller\AuthSettingsController; -use OC\Settings\Controller\CertificateController; -use OC\Settings\Controller\EncryptionController; -use OC\Settings\Controller\GroupsController; -use OC\Settings\Controller\MailSettingsController; -use OC\Settings\Controller\UsersController; +use OC\Authentication\Token\IProvider; use OC\Settings\Middleware\SubadminMiddleware; use OCP\AppFramework\App; use OCP\IContainer; +use OCP\Settings\IManager; use OCP\Util; /** @@ -58,131 +51,19 @@ class Application extends App { $container = $this->getContainer(); - /** - * Controllers - */ - $container->registerService('MailSettingsController', function(IContainer $c) { - return new MailSettingsController( - $c->query('AppName'), - $c->query('Request'), - $c->query('L10N'), - $c->query('Config'), - $c->query('UserSession'), - $c->query('Defaults'), - $c->query('Mailer'), - $c->query('DefaultMailAddress') - ); - }); - $container->registerService('EncryptionController', function(IContainer $c) { - return new EncryptionController( - $c->query('AppName'), - $c->query('Request'), - $c->query('L10N'), - $c->query('Config'), - $c->query('DatabaseConnection'), - $c->query('UserManager'), - new View(), - $c->query('Logger') - ); - }); - $container->registerService('AuthSettingsController', function(IContainer $c) { - return new AuthSettingsController( - $c->query('AppName'), - $c->query('Request'), - $c->query('ServerContainer')->query('OC\Authentication\Token\IProvider'), - $c->query('UserManager'), - $c->query('ServerContainer')->getSession(), - $c->query('ServerContainer')->getSecureRandom(), - $c->query('UserId') - ); - }); - $container->registerService('CertificateController', function(IContainer $c) { - return new CertificateController( - $c->query('AppName'), - $c->query('Request'), - $c->query('CertificateManager'), - $c->query('SystemCertificateManager'), - $c->query('L10N'), - $c->query('IAppManager') - ); - }); - $container->registerService('GroupsController', function(IContainer $c) { - return new GroupsController( - $c->query('AppName'), - $c->query('Request'), - $c->query('GroupManager'), - $c->query('UserSession'), - $c->query('IsAdmin'), - $c->query('L10N') - ); - }); - $container->registerService('UsersController', function(IContainer $c) { - return new UsersController( - $c->query('AppName'), - $c->query('Request'), - $c->query('UserManager'), - $c->query('GroupManager'), - $c->query('UserSession'), - $c->query('Config'), - $c->query('IsAdmin'), - $c->query('L10N'), - $c->query('Logger'), - $c->query('Defaults'), - $c->query('Mailer'), - $c->query('DefaultMailAddress'), - $c->query('URLGenerator'), - $c->query('OCP\\App\\IAppManager'), - $c->query('OCP\\IAvatarManager') - ); - }); - $container->registerService('AdminSettingsController', function(IContainer $c) { - return new AdminSettingsController( - $c->query('AppName'), - $c->query('Request'), - $c->query('INavigationManager'), - $c->query('SettingsManager') - ); - }); - - /** - * Middleware - */ - $container->registerService('SubadminMiddleware', function(IContainer $c){ - return new SubadminMiddleware( - $c->query('ControllerMethodReflector'), - $c->query('IsSubAdmin') - ); - }); - // Execute middlewares - $container->registerMiddleware('SubadminMiddleware'); + // Register Middleware + $container->registerAlias('SubadminMiddleware', SubadminMiddleware::class); + $container->registerMiddleWare('SubadminMiddleware'); /** * Core class wrappers */ - $container->registerService('Config', function(IContainer $c) { - return $c->query('ServerContainer')->getConfig(); - }); - $container->registerService('ICacheFactory', function(IContainer $c) { - return $c->query('ServerContainer')->getMemCacheFactory(); - }); - $container->registerService('L10N', function(IContainer $c) { - return $c->query('ServerContainer')->getL10N('settings'); - }); - $container->registerService('GroupManager', function(IContainer $c) { - return $c->query('ServerContainer')->getGroupManager(); - }); - $container->registerService('UserManager', function(IContainer $c) { - return $c->query('ServerContainer')->getUserManager(); - }); - $container->registerService('UserSession', function(IContainer $c) { - return $c->query('ServerContainer')->getUserSession(); - }); /** FIXME: Remove once OC_User is non-static and mockable */ - $container->registerService('IsAdmin', function(IContainer $c) { + $container->registerService('isAdmin', function() { return \OC_User::isAdminUser(\OC_User::getUser()); }); /** FIXME: Remove once OC_SubAdmin is non-static and mockable */ - $container->registerService('IsSubAdmin', function(IContainer $c) { + $container->registerService('isSubAdmin', function(IContainer $c) { $userObject = \OC::$server->getUserSession()->getUser(); $isSubAdmin = false; if($userObject !== null) { @@ -190,57 +71,19 @@ class Application extends App { } return $isSubAdmin; }); - $container->registerService('Mailer', function(IContainer $c) { - return $c->query('ServerContainer')->getMailer(); - }); - $container->registerService('Defaults', function(IContainer $c) { - return $c->query('ServerContainer')->getThemingDefaults(); - }); - $container->registerService('DefaultMailAddress', function(IContainer $c) { + $container->registerService('fromMailAddress', function() { return Util::getDefaultEmailAddress('no-reply'); }); - $container->registerService('Logger', function(IContainer $c) { - return $c->query('ServerContainer')->getLogger(); - }); - $container->registerService('URLGenerator', function(IContainer $c) { - return $c->query('ServerContainer')->getURLGenerator(); - }); - $container->registerService('ClientService', function(IContainer $c) { - return $c->query('ServerContainer')->getHTTPClientService(); - }); - $container->registerService('INavigationManager', function(IContainer $c) { - return $c->query('ServerContainer')->getNavigationManager(); - }); - $container->registerService('IAppManager', function(IContainer $c) { - return $c->query('ServerContainer')->getAppManager(); - }); - $container->registerService('OcsClient', function(IContainer $c) { - return $c->query('ServerContainer')->getOcsClient(); - }); - $container->registerService('Util', function(IContainer $c) { - return new \OC_Util(); - }); - $container->registerService('DatabaseConnection', function(IContainer $c) { - return $c->query('ServerContainer')->getDatabaseConnection(); - }); - $container->registerService('CertificateManager', function(IContainer $c){ + $container->registerService('userCertificateManager', function(IContainer $c) { return $c->query('ServerContainer')->getCertificateManager(); - }); - $container->registerService('SystemCertificateManager', function (IContainer $c) { + }, false); + $container->registerService('systemCertificateManager', function (IContainer $c) { return $c->query('ServerContainer')->getCertificateManager(null); + }, false); + $container->registerService(IProvider::class, function (IContainer $c) { + return $c->query('ServerContainer')->query(IProvider::class); }); - $container->registerService('Checker', function(IContainer $c) { - /** @var Server $server */ - $server = $c->query('ServerContainer'); - return $server->getIntegrityCodeChecker(); - }); - $container->registerService('EventDispatcher', function (IContainer $c) { - return $c->query('ServerContainer')->getEventDispatcher(); - }); - $container->registerService('EncryptionManager', function (IContainer $c) { - return $c->query('ServerContainer')->getEncryptionManager(); - }); - $container->registerService('SettingsManager', function (IContainer $c) { + $container->registerService(IManager::class, function (IContainer $c) { return $c->query('ServerContainer')->getSettingsManager(); }); } diff --git a/settings/Controller/AuthSettingsController.php b/settings/Controller/AuthSettingsController.php index 5e6ad7859a7..58994f0d59c 100644 --- a/settings/Controller/AuthSettingsController.php +++ b/settings/Controller/AuthSettingsController.php @@ -60,14 +60,14 @@ class AuthSettingsController extends Controller { * @param IUserManager $userManager * @param ISession $session * @param ISecureRandom $random - * @param string $uid + * @param string $userId */ public function __construct($appName, IRequest $request, IProvider $tokenProvider, IUserManager $userManager, - ISession $session, ISecureRandom $random, $uid) { + ISession $session, ISecureRandom $random, $userId) { parent::__construct($appName, $request); $this->tokenProvider = $tokenProvider; $this->userManager = $userManager; - $this->uid = $uid; + $this->uid = $userId; $this->session = $session; $this->random = $random; } diff --git a/settings/Controller/EncryptionController.php b/settings/Controller/EncryptionController.php index b2757b0965f..cda50853fdc 100644 --- a/settings/Controller/EncryptionController.php +++ b/settings/Controller/EncryptionController.php @@ -23,14 +23,15 @@ namespace OC\Settings\Controller; + use OC\Files\View; use OCA\Encryption\Migration; +use OCP\IDBConnection; use OCP\IL10N; use OCP\AppFramework\Controller; use OCP\ILogger; use OCP\IRequest; use OCP\IConfig; -use OC\DB\Connection; use OCP\IUserManager; /** @@ -38,10 +39,10 @@ use OCP\IUserManager; */ class EncryptionController extends Controller { - /** @var \OCP\IL10N */ + /** @var IL10N */ private $l10n; - /** @var Connection */ + /** @var IDBConnection */ private $connection; /** @var IConfig */ @@ -53,15 +54,15 @@ class EncryptionController extends Controller { /** @var View */ private $view; - /** @var ILogger */ + /** @var ILogger */ private $logger; /** * @param string $appName * @param IRequest $request - * @param \OCP\IL10N $l10n - * @param \OCP\IConfig $config - * @param \OC\DB\Connection $connection + * @param IL10N $l10n + * @param IConfig $config + * @param IDBConnection $connection * @param IUserManager $userManager * @param View $view * @param ILogger $logger @@ -70,7 +71,7 @@ class EncryptionController extends Controller { IRequest $request, IL10N $l10n, IConfig $config, - Connection $connection, + IDBConnection $connection, IUserManager $userManager, View $view, ILogger $logger) { @@ -86,13 +87,13 @@ class EncryptionController extends Controller { /** * @param IConfig $config * @param View $view - * @param Connection $connection + * @param IDBConnection $connection * @param ILogger $logger * @return Migration */ protected function getMigration(IConfig $config, View $view, - Connection $connection, + IDBConnection $connection, ILogger $logger) { return new Migration($config, $view, $connection, $logger); } diff --git a/settings/Controller/MailSettingsController.php b/settings/Controller/MailSettingsController.php index 6ff12dec40c..84423aa8e29 100644 --- a/settings/Controller/MailSettingsController.php +++ b/settings/Controller/MailSettingsController.php @@ -24,11 +24,11 @@ namespace OC\Settings\Controller; -use OC\User\Session; -use \OCP\AppFramework\Controller; +use OCP\AppFramework\Controller; use OCP\IRequest; use OCP\IL10N; use OCP\IConfig; +use OCP\IUserSession; use OCP\Mail\IMailer; /** @@ -36,14 +36,12 @@ use OCP\Mail\IMailer; */ class MailSettingsController extends Controller { - /** @var \OCP\IL10N */ + /** @var IL10N */ private $l10n; - /** @var \OCP\IConfig */ + /** @var IConfig */ private $config; - /** @var Session */ + /** @var IUserSession */ private $userSession; - /** @var \OC_Defaults */ - private $defaults; /** @var IMailer */ private $mailer; /** @var string */ @@ -54,26 +52,23 @@ class MailSettingsController extends Controller { * @param IRequest $request * @param IL10N $l10n * @param IConfig $config - * @param Session $userSession - * @param \OC_Defaults $defaults + * @param IUserSession $userSession * @param IMailer $mailer - * @param string $defaultMailAddress + * @param string $fromMailAddress */ public function __construct($appName, IRequest $request, IL10N $l10n, IConfig $config, - Session $userSession, - \OC_Defaults $defaults, + IUserSession $userSession, IMailer $mailer, - $defaultMailAddress) { + $fromMailAddress) { parent::__construct($appName, $request); $this->l10n = $l10n; $this->config = $config; $this->userSession = $userSession; - $this->defaults = $defaults; $this->mailer = $mailer; - $this->defaultMailAddress = $defaultMailAddress; + $this->defaultMailAddress = $fromMailAddress; } /** diff --git a/tests/Settings/ApplicationTest.php b/tests/Settings/ApplicationTest.php index d07bfe83301..32ec4c2273c 100644 --- a/tests/Settings/ApplicationTest.php +++ b/tests/Settings/ApplicationTest.php @@ -25,6 +25,18 @@ namespace Tests\Settings; use OC\Settings\Application; +use OC\Settings\Controller\AdminSettingsController; +use OC\Settings\Controller\AppSettingsController; +use OC\Settings\Controller\AuthSettingsController; +use OC\Settings\Controller\CertificateController; +use OC\Settings\Controller\CheckSetupController; +use OC\Settings\Controller\EncryptionController; +use OC\Settings\Controller\GroupsController; +use OC\Settings\Controller\LogSettingsController; +use OC\Settings\Controller\MailSettingsController; +use OC\Settings\Controller\SecuritySettingsController; +use OC\Settings\Controller\UsersController; +use OC\Settings\Middleware\SubadminMiddleware; use OCP\AppFramework\Controller; use OCP\AppFramework\Middleware; use OCP\IUser; @@ -56,21 +68,21 @@ class ApplicationTest extends TestCase { } public function dataContainerQuery() { - return array( - array('AdminSettingsController', Controller::class), - array('AppSettingsController', Controller::class), - array('AuthSettingsController', Controller::class), - // Needs session: array('CertificateController', Controller::class), - array('CheckSetupController', Controller::class), - array('EncryptionController', Controller::class), - array('GroupsController', Controller::class), - array('LogSettingsController', Controller::class), - array('MailSettingsController', Controller::class), - array('SecuritySettingsController', Controller::class), - array('UsersController', Controller::class), + return [ + [AdminSettingsController::class, Controller::class], + [AppSettingsController::class, Controller::class], + [AuthSettingsController::class, Controller::class], + // Needs session: [CertificateController::class, Controller::class], + [CheckSetupController::class, Controller::class], + [EncryptionController::class, Controller::class], + [GroupsController::class, Controller::class], + [LogSettingsController::class, Controller::class], + [MailSettingsController::class, Controller::class], + [SecuritySettingsController::class, Controller::class], + [UsersController::class, Controller::class], - array('SubadminMiddleware', Middleware::class), - ); + [SubadminMiddleware::class, Middleware::class], + ]; } /** @@ -83,9 +95,9 @@ class ApplicationTest extends TestCase { } public function dataContainerQueryRequiresSession() { - return array( - array('CertificateController', Controller::class), - ); + return [ + [CertificateController::class, Controller::class], + ]; } /** |