|
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( |
|
|
|
|
|
|
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
|
|
|
} |
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.