Completed
Push — stable10 ( 737591...a2942c )
by Lukas
09:58 queued 09:42
created

Encryption   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 4
Bugs 0 Features 2
Metric Value
c 4
b 0
f 2
dl 0
loc 61
rs 10
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
 *
7
 * @license GNU AGPL version 3 or any later version
8
 *
9
 * This program is free software: you can redistribute it and/or modify
10
 * it under the terms of the GNU Affero General Public License as
11
 * published by the Free Software Foundation, either version 3 of the
12
 * License, or (at your option) any later version.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU Affero General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU Affero General Public License
20
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
 *
22
 */
23
24
namespace OC\Settings\Admin;
25
26
use OC\Encryption\Manager;
27
use OCP\AppFramework\Http\TemplateResponse;
28
use OCP\IUserManager;
29
use OCP\Settings\ISettings;
30
31
class Encryption implements ISettings {
32
	/** @var Manager */
33
	private $manager;
34
35
	/** @var IUserManager */
36
	private $userManager;
37
38
	/**
39
	 * @param Manager $manager
40
	 * @param IUserManager $userManager
41
	 */
42
	public function __construct(Manager $manager, IUserManager $userManager) {
43
		$this->manager = $manager;
44
		$this->userManager = $userManager;
45
	}
46
47
	/**
48
	 * @return TemplateResponse
49
	 */
50
	public function getForm() {
51
		$encryptionModules = $this->manager->getEncryptionModules();
52
		$defaultEncryptionModuleId = $this->manager->getDefaultEncryptionModuleId();
53
		$encryptionModuleList = [];
54
		foreach ($encryptionModules as $module) {
55
			$encryptionModuleList[$module['id']]['displayName'] = $module['displayName'];
56
			$encryptionModuleList[$module['id']]['default'] = false;
57
			if ($module['id'] === $defaultEncryptionModuleId) {
58
				$encryptionModuleList[$module['id']]['default'] = true;
59
			}
60
		}
61
62
		$parameters = [
63
			// Encryption API
64
			'encryptionEnabled'       => $this->manager->isEnabled(),
65
			'encryptionReady'         => $this->manager->isReady(),
66
			'externalBackendsEnabled' => count($this->userManager->getBackends()) > 1,
67
			// Modules
68
			'encryptionModules'       => $encryptionModuleList,
69
		];
70
71
		return new TemplateResponse('settings', 'admin/encryption', $parameters, '');
72
	}
73
74
	/**
75
	 * @return string the section ID, e.g. 'sharing'
76
	 */
77
	public function getSection() {
78
		return 'encryption';
79
	}
80
81
	/**
82
	 * @return int whether the form should be rather on the top or bottom of
83
	 * the admin section. The forms are arranged in ascending order of the
84
	 * priority values. It is required to return a value between 0 and 100.
85
	 *
86
	 * E.g.: 70
87
	 */
88
	public function getPriority() {
89
		return 0;
90
	}
91
}
92