Completed
Push — master ( 7971ba...bae3ba )
by Morris
14:40
created

Security   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 61
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 3

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getForm() 0 23 3
A getSection() 0 3 1
A getPriority() 0 3 1
1
<?php
2
/**
3
 * @copyright Copyright (c) 2016 Arthur Schiwon <[email protected]>
4
 *
5
 * @author Arthur Schiwon <[email protected]>
6
 * @author Lukas Reschke <[email protected]>
7
 * @author Robin Appelman <[email protected]>
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
26
namespace OC\Settings\Admin;
27
28
use OCP\AppFramework\Http\TemplateResponse;
29
use OCP\Encryption\IManager;
30
use OCP\IUserManager;
31
use OCP\Settings\ISettings;
32
33
class Security implements ISettings {
34
	/** @var IManager */
35
	private $manager;
36
37
	/** @var IUserManager */
38
	private $userManager;
39
40
	/**
41
	 * @param IManager $manager
42
	 * @param IUserManager $userManager
43
	 */
44
	public function __construct(IManager $manager, IUserManager $userManager) {
45
		$this->manager = $manager;
46
		$this->userManager = $userManager;
47
	}
48
49
	/**
50
	 * @return TemplateResponse
51
	 */
52
	public function getForm() {
53
		$encryptionModules = $this->manager->getEncryptionModules();
54
		$defaultEncryptionModuleId = $this->manager->getDefaultEncryptionModuleId();
55
		$encryptionModuleList = [];
56
		foreach ($encryptionModules as $module) {
57
			$encryptionModuleList[$module['id']]['displayName'] = $module['displayName'];
58
			$encryptionModuleList[$module['id']]['default'] = false;
59
			if ($module['id'] === $defaultEncryptionModuleId) {
60
				$encryptionModuleList[$module['id']]['default'] = true;
61
			}
62
		}
63
64
		$parameters = [
65
			// Encryption API
66
			'encryptionEnabled'       => $this->manager->isEnabled(),
67
			'encryptionReady'         => $this->manager->isReady(),
68
			'externalBackendsEnabled' => count($this->userManager->getBackends()) > 1,
69
			// Modules
70
			'encryptionModules'       => $encryptionModuleList,
71
		];
72
73
		return new TemplateResponse('settings', 'settings/admin/security', $parameters, '');
74
	}
75
76
	/**
77
	 * @return string the section ID, e.g. 'sharing'
78
	 */
79
	public function getSection() {
80
		return 'security';
81
	}
82
83
	/**
84
	 * @return int whether the form should be rather on the top or bottom of
85
	 * the admin section. The forms are arranged in ascending order of the
86
	 * priority values. It is required to return a value between 0 and 100.
87
	 *
88
	 * E.g.: 70
89
	 */
90
	public function getPriority() {
91
		return 10;
92
	}
93
}
94