Completed
Branch master (8ca3ab)
by Sander
03:07
created

SettingsController   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
lcom 1
cbo 1
dl 0
loc 75
ccs 13
cts 13
cp 1
rs 10
c 1
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getForm() 0 3 1
A getPriority() 0 3 1
A getSettings() 0 4 1
A saveUserSetting() 0 4 1
A saveAdminSetting() 0 4 1
A __construct() 0 11 1
A getSection() 0 3 1
1
<?php
2
/**
3
 * Nextcloud - passman
4
 *
5
 * This file is licensed under the Affero General Public License version 3 or
6
 * later. See the COPYING file.
7
 *
8
 * @author Sander Brand <[email protected]>
9
 * @copyright Sander Brand 2016
10
 */
11
12
namespace OCA\Passman\Controller;
13
14
use OCP\IL10N;
15
use OCP\Settings\ISettings;
16
use OCP\AppFramework\Http\TemplateResponse;
17
use OCP\AppFramework\Http\JSONResponse;
18
use OCP\AppFramework\ApiController;
19
use OCP\IRequest;
20
use OCA\Passman\Service\SettingsService;
21
22
class SettingsController extends ApiController {
23
	private $userId;
24
	private $settings;
25
26
	public function __construct(
27
		$AppName,
28
		IRequest $request,
29
		$userId,
30
		SettingsService $settings,
31
		IL10N $l) {
32
		parent::__construct($AppName, $request);
33
		$this->settings = $settings;
34
		$this->l = $l;
35
		$this->userId = $userId;
36
	}
37
38
	/**
39
	 * @return TemplateResponse
40
	 */
41 1
	public function getForm() {
42 1
		return new TemplateResponse('passman', 'part.admin');
43
	}
44
45
	/**
46
	 * @return string the section ID, e.g. 'sharing'
47
	 */
48
	public function getSection() {
49
		return 'additional';
50
	}
51
52
	/**
53
	 * @return int whether the form should be rather on the top or bottom of
54
	 * the admin section. The forms are arranged in ascending order of the
55
	 * priority values. It is required to return a value between 0 and 100.
56
	 *
57
	 * E.g.: 70
58
	 */
59 1
	public function getPriority() {
60 1
		return 0;
61
	}
62
63
	/**
64
	 * Get all settings
65
	 *
66
	 * @NoAdminRequired
67
	 * @NoCSRFRequired
68
	 */
69 1
	public function getSettings() {
70 1
		$settings = $this->settings->getAppSettings();
71 1
		return new JSONResponse($settings);
72
	}
73
74
	/**
75
	 * Save a user setting
76
	 *
77
	 * @NoAdminRequired
78
	 * @NoCSRFRequired
79
	 */
80 1
	public function saveUserSetting($key, $value) {
81 1
		$this->settings->setUserSetting($key, $value);
82 1
		return new JSONResponse('OK');
83
	}
84
85
86
	/**
87
	 * Save a app setting
88
	 *
89
	 * @NoCSRFRequired
90
	 */
91 1
	public function saveAdminSetting($key, $value) {
92 1
		$this->settings->setAppSetting($key, $value);
93 1
		return new JSONResponse('OK');
94
	}
95
96
}