|
23 | 23 |
|
24 | 24 | namespace OCA\Deck\Controller; |
25 | 25 |
|
| 26 | +use OCA\Deck\Service\ConfigService; |
26 | 27 | use OCP\AppFramework\Http\DataResponse; |
27 | 28 | use OCP\AppFramework\Http\NotFoundResponse; |
28 | | -use OCP\IConfig; |
29 | | -use OCP\IGroup; |
30 | | -use OCP\IGroupManager; |
| 29 | +use OCP\AppFramework\OCSController; |
31 | 30 | use OCP\IRequest; |
32 | | -use OCP\AppFramework\Controller; |
33 | 31 |
|
34 | | -class ConfigController extends Controller { |
35 | | - private $config; |
36 | | - private $userId; |
37 | | - private $groupManager; |
| 32 | +class ConfigController extends OCSController { |
| 33 | + private $configService; |
38 | 34 |
|
39 | 35 | public function __construct( |
40 | 36 | $AppName, |
41 | 37 | IRequest $request, |
42 | | - IConfig $config, |
43 | | - IGroupManager $groupManager, |
44 | | - $userId |
| 38 | + ConfigService $configService |
45 | 39 | ) { |
46 | 40 | parent::__construct($AppName, $request); |
47 | 41 |
|
48 | | - $this->userId = $userId; |
49 | | - $this->groupManager = $groupManager; |
50 | | - $this->config = $config; |
| 42 | + $this->configService = $configService; |
51 | 43 | } |
52 | 44 |
|
53 | 45 | /** |
54 | 46 | * @NoCSRFRequired |
| 47 | + * @NoAdminRequired |
55 | 48 | */ |
56 | | - public function get() { |
57 | | - $data = [ |
58 | | - 'groupLimit' => $this->getGroupLimit(), |
59 | | - ]; |
60 | | - return new DataResponse($data); |
| 49 | + public function get(): DataResponse { |
| 50 | + return new DataResponse($this->configService->getAll()); |
61 | 51 | } |
62 | 52 |
|
63 | 53 | /** |
64 | 54 | * @NoCSRFRequired |
| 55 | + * @NoAdminRequired |
65 | 56 | */ |
66 | | - public function setValue($key, $value) { |
67 | | - switch ($key) { |
68 | | - case 'groupLimit': |
69 | | - $result = $this->setGroupLimit($value); |
70 | | - break; |
71 | | - } |
| 57 | + public function setValue(string $key, $value) { |
| 58 | + $result = $this->configService->set($key, $value); |
72 | 59 | if ($result === null) { |
73 | 60 | return new NotFoundResponse(); |
74 | 61 | } |
75 | 62 | return new DataResponse($result); |
76 | 63 | } |
77 | | - |
78 | | - private function setGroupLimit($value) { |
79 | | - $groups = []; |
80 | | - foreach ($value as $group) { |
81 | | - $groups[] = $group['id']; |
82 | | - } |
83 | | - $data = implode(',', $groups); |
84 | | - $this->config->setAppValue($this->appName, 'groupLimit', $data); |
85 | | - return $groups; |
86 | | - } |
87 | | - |
88 | | - private function getGroupLimitList() { |
89 | | - $value = $this->config->getAppValue($this->appName, 'groupLimit', ''); |
90 | | - $groups = explode(',', $value); |
91 | | - if ($value === '') { |
92 | | - return []; |
93 | | - } |
94 | | - return $groups; |
95 | | - } |
96 | | - |
97 | | - private function getGroupLimit() { |
98 | | - $groups = $this->getGroupLimitList(); |
99 | | - $groups = array_map(function ($groupId) { |
100 | | - /** @var IGroup $groups */ |
101 | | - $group = $this->groupManager->get($groupId); |
102 | | - if ($group === null) { |
103 | | - return null; |
104 | | - } |
105 | | - return [ |
106 | | - 'id' => $group->getGID(), |
107 | | - 'displayname' => $group->getDisplayName(), |
108 | | - ]; |
109 | | - }, $groups); |
110 | | - return array_filter($groups); |
111 | | - } |
112 | 64 | } |
0 commit comments