Passed
Push — master ( 37718d...df6e91 )
by Morris
77:43 queued 61:27
created

Application::extendJsConfig()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 1
dl 0
loc 9
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * @copyright Copyright (c) 2016, ownCloud, Inc.
4
 *
5
 * @author Arthur Schiwon <[email protected]>
6
 * @author Björn Schießle <[email protected]>
7
 * @author Christoph Wurst <[email protected]>
8
 * @author Joas Schilling <[email protected]>
9
 * @author Lukas Reschke <[email protected]>
10
 * @author Morris Jobke <[email protected]>
11
 * @author Robin Appelman <[email protected]>
12
 *
13
 * @license AGPL-3.0
14
 *
15
 * This code is free software: you can redistribute it and/or modify
16
 * it under the terms of the GNU Affero General Public License, version 3,
17
 * as published by the Free Software Foundation.
18
 *
19
 * This program is distributed in the hope that it will be useful,
20
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22
 * GNU Affero General Public License for more details.
23
 *
24
 * You should have received a copy of the GNU Affero General Public License, version 3,
25
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
26
 *
27
 */
28
29
namespace OC\Settings;
30
31
use OC\AppFramework\Utility\TimeFactory;
32
use OC\Authentication\Token\IProvider;
33
use OC\Server;
34
use OC\Settings\Activity\Provider;
35
use OC\Settings\Activity\SecurityFilter;
36
use OC\Settings\Activity\SecurityProvider;
37
use OC\Settings\Activity\SecuritySetting;
38
use OC\Settings\Activity\Setting;
39
use OC\Settings\Mailer\NewUserMailHelper;
40
use OC\Settings\Middleware\SubadminMiddleware;
41
use OCP\AppFramework\App;
42
use OCP\Defaults;
43
use OCP\IContainer;
44
use OCP\Settings\IManager;
45
use OCP\Util;
46
47
/**
48
 * @package OC\Settings
49
 */
50
class Application extends App {
51
52
53
	/**
54
	 * @param array $urlParams
55
	 */
56
	public function __construct(array $urlParams=[]){
57
		parent::__construct('settings', $urlParams);
58
59
		$container = $this->getContainer();
60
61
		// Register Middleware
62
		$container->registerAlias('SubadminMiddleware', SubadminMiddleware::class);
63
		$container->registerMiddleWare('SubadminMiddleware');
64
65
		/**
66
		 * Core class wrappers
67
		 */
68
		/** FIXME: Remove once OC_User is non-static and mockable */
69
		$container->registerService('isAdmin', function() {
70
			return \OC_User::isAdminUser(\OC_User::getUser());
71
		});
72
		/** FIXME: Remove once OC_SubAdmin is non-static and mockable */
73
		$container->registerService('isSubAdmin', function(IContainer $c) {
0 ignored issues
show
Unused Code introduced by
The parameter $c is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

73
		$container->registerService('isSubAdmin', function(/** @scrutinizer ignore-unused */ IContainer $c) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
74
			$userObject = \OC::$server->getUserSession()->getUser();
75
			$isSubAdmin = false;
76
			if($userObject !== null) {
77
				$isSubAdmin = \OC::$server->getGroupManager()->getSubAdmin()->isSubAdmin($userObject);
78
			}
79
			return $isSubAdmin;
80
		});
81
		$container->registerService('userCertificateManager', function(IContainer $c) {
82
			return $c->query('ServerContainer')->getCertificateManager();
83
		}, false);
84
		$container->registerService('systemCertificateManager', function (IContainer $c) {
85
			return $c->query('ServerContainer')->getCertificateManager(null);
86
		}, false);
87
		$container->registerService(IProvider::class, function (IContainer $c) {
88
			return $c->query('ServerContainer')->query(IProvider::class);
89
		});
90
		$container->registerService(IManager::class, function (IContainer $c) {
91
			return $c->query('ServerContainer')->getSettingsManager();
92
		});
93
94
		$container->registerService(NewUserMailHelper::class, function (IContainer $c) {
95
			/** @var Server $server */
96
			$server = $c->query('ServerContainer');
97
			/** @var Defaults $defaults */
98
			$defaults = $server->query(Defaults::class);
99
100
			return new NewUserMailHelper(
101
				$defaults,
102
				$server->getURLGenerator(),
103
				$server->getL10NFactory(),
104
				$server->getMailer(),
105
				$server->getSecureRandom(),
106
				new TimeFactory(),
107
				$server->getConfig(),
108
				$server->getCrypto(),
109
				Util::getDefaultEmailAddress('no-reply')
110
			);
111
		});
112
	}
113
114
	public function register() {
115
		$activityManager = $this->getContainer()->getServer()->getActivityManager();
116
		$activityManager->registerSetting(Setting::class); // FIXME move to info.xml
117
		$activityManager->registerProvider(Provider::class); // FIXME move to info.xml
118
		$activityManager->registerFilter(SecurityFilter::class); // FIXME move to info.xml
119
		$activityManager->registerSetting(SecuritySetting::class); // FIXME move to info.xml
120
		$activityManager->registerProvider(SecurityProvider::class); // FIXME move to info.xml
121
122
		Util::connectHook('OC_User', 'post_setPassword', $this, 'onChangePassword');
123
		Util::connectHook('OC_User', 'changeUser', $this, 'onChangeInfo');
124
125
		Util::connectHook('\OCP\Config', 'js', $this, 'extendJsConfig');
126
	}
127
128
	/**
129
	 * @param array $parameters
130
	 * @throws \InvalidArgumentException
131
	 * @throws \BadMethodCallException
132
	 * @throws \Exception
133
	 * @throws \OCP\AppFramework\QueryException
134
	 */
135
	public function onChangePassword(array $parameters) {
136
		/** @var Hooks $hooks */
137
		$hooks = $this->getContainer()->query(Hooks::class);
138
		$hooks->onChangePassword($parameters['uid']);
139
	}
140
141
	/**
142
	 * @param array $parameters
143
	 * @throws \InvalidArgumentException
144
	 * @throws \BadMethodCallException
145
	 * @throws \Exception
146
	 * @throws \OCP\AppFramework\QueryException
147
	 */
148
	public function onChangeInfo(array $parameters) {
149
		if ($parameters['feature'] !== 'eMailAddress') {
150
			return;
151
		}
152
153
		/** @var Hooks $hooks */
154
		$hooks = $this->getContainer()->query(Hooks::class);
155
		$hooks->onChangeEmail($parameters['user'], $parameters['old_value']);
156
	}
157
158
	/**
159
	 * @param array $settings
160
	 */
161
	public function extendJsConfig(array $settings) {
162
		$appConfig = json_decode($settings['array']['oc_appconfig'], true);
163
164
		$publicWebFinger = \OC::$server->getConfig()->getAppValue('core', 'public_webfinger', '');
165
		if (!empty($publicWebFinger)) {
166
			$appConfig['core']['public_webfinger'] = $publicWebFinger;
167
		}
168
169
		$settings['array']['oc_appconfig'] = json_encode($appConfig);
170
	}
171
}
172