Completed
Push — master ( 732696...257f5a )
by Sander
10s
created

SettingsController::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 15

Duplication

Lines 16
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 15
nc 1
nop 5
dl 16
loc 16
ccs 0
cts 9
cp 0
crap 2
rs 9.4285
c 1
b 0
f 0
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 View Code Duplication
	public function __construct(
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
27
		$AppName,
28
		IRequest $request,
29
		$userId,
30
		SettingsService $settings,
31
		IL10N $l) {
32
		parent::__construct(
33
			$AppName,
34
			$request,
35
			'GET, POST, DELETE, PUT, PATCH, OPTIONS',
36
			'Authorization, Content-Type, Accept',
37
			86400);
38
		$this->settings = $settings;
39
		$this->l = $l;
40
		$this->userId = $userId;
41
	}
42
43
	/**
44
	 * @return TemplateResponse
45
	 */
46 1
	public function getForm() {
47 1
		return new TemplateResponse('passman', 'part.admin');
48
	}
49
50
	/**
51
	 * @return string the section ID, e.g. 'sharing'
52
	 */
53 1
	public function getSection() {
54 1
		return 'additional';
55
	}
56
57
	/**
58
	 * @return int whether the form should be rather on the top or bottom of
59
	 * the admin section. The forms are arranged in ascending order of the
60
	 * priority values. It is required to return a value between 0 and 100.
61
	 *
62
	 * E.g.: 70
63
	 */
64 1
	public function getPriority() {
65 1
		return 0;
66
	}
67
68
	/**
69
	 * Get all settings
70
	 *
71
	 * @NoAdminRequired
72
	 * @NoCSRFRequired
73
	 */
74 1
	public function getSettings() {
75 1
		$settings = $this->settings->getAppSettings();
76 1
		return new JSONResponse($settings);
77
	}
78
79
	/**
80
	 * Save a user setting
81
	 *
82
	 * @NoAdminRequired
83
	 * @NoCSRFRequired
84
	 */
85 1
	public function saveUserSetting($key, $value) {
86 1
		$this->settings->setUserSetting($key, $value);
87 1
		return new JSONResponse('OK');
88
	}
89
90
91
	/**
92
	 * Save a app setting
93
	 *
94
	 * @NoCSRFRequired
95
	 */
96 1
	public function saveAdminSetting($key, $value) {
97 1
		$this->settings->setAppSetting($key, $value);
98 1
		return new JSONResponse('OK');
99
	}
100
101
}