1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Nextcloud - namespace OCA\Nextnote |
4
|
|
|
* |
5
|
|
|
* @copyright Copyright (c) 2016, Sander Brand ([email protected]) |
6
|
|
|
* @copyright Copyright (c) 2016, Marcos Zuriaga Miguel ([email protected]) |
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 OCA\NextNote\Controller; |
25
|
|
|
|
26
|
|
|
use OCP\IL10N; |
27
|
|
|
use OCP\Settings\ISettings; |
28
|
|
|
use OCP\AppFramework\Http\TemplateResponse; |
29
|
|
|
use OCP\AppFramework\Http\JSONResponse; |
30
|
|
|
use OCP\AppFramework\ApiController; |
31
|
|
|
use OCP\IRequest; |
32
|
|
|
use OCA\NextNote\Service\SettingsService; |
33
|
|
|
|
34
|
|
|
class SettingsController extends ApiController { |
35
|
|
|
private $userId; |
36
|
|
|
private $settings; |
37
|
|
|
|
38
|
|
|
public function __construct( |
39
|
|
|
$AppName, |
40
|
|
|
IRequest $request, |
41
|
|
|
$userId, |
42
|
|
|
SettingsService $settings, |
43
|
|
|
IL10N $l) { |
44
|
|
|
parent::__construct( |
45
|
|
|
$AppName, |
46
|
|
|
$request, |
47
|
|
|
'GET, POST, DELETE, PUT, PATCH, OPTIONS', |
48
|
|
|
'Authorization, Content-Type, Accept', |
49
|
|
|
86400); |
50
|
|
|
$this->settings = $settings; |
51
|
|
|
$this->l = $l; |
52
|
|
|
$this->userId = $userId; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Get all settings |
58
|
|
|
* |
59
|
|
|
* @NoAdminRequired |
60
|
|
|
* @NoCSRFRequired |
61
|
|
|
*/ |
62
|
|
|
public function getSettings() { |
63
|
|
|
$settings = $this->settings->getAppSettings(); |
64
|
|
|
return new JSONResponse($settings); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Save a user setting |
69
|
|
|
* |
70
|
|
|
* @NoAdminRequired |
71
|
|
|
* @NoCSRFRequired |
72
|
|
|
*/ |
73
|
|
|
public function saveUserSetting($key, $value) { |
74
|
|
|
$this->settings->setUserSetting($key, $value); |
75
|
|
|
return new JSONResponse('OK'); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Save a app setting |
81
|
|
|
* |
82
|
|
|
* @NoCSRFRequired |
83
|
|
|
*/ |
84
|
|
|
public function saveAdminSetting($field, $value) { |
85
|
|
|
$this->settings->setAppSetting($field, $value); |
86
|
|
|
return new JSONResponse('OK'); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
} |