-
Notifications
You must be signed in to change notification settings - Fork 119
Expand file tree
/
Copy pathConfigController.php
More file actions
68 lines (59 loc) · 1.83 KB
/
Copy pathConfigController.php
File metadata and controls
68 lines (59 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Forms\Controller;
use OCA\Forms\Constants;
use OCA\Forms\Service\ConfigService;
use OCP\AppFramework\ApiController;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\Attribute\FrontpageRoute;
use OCP\AppFramework\Http\Attribute\OpenAPI;
use OCP\AppFramework\Http\DataResponse;
use OCP\IConfig;
use OCP\IRequest;
use Psr\Log\LoggerInterface;
#[OpenAPI(scope: OpenAPI::SCOPE_IGNORE)]
class ConfigController extends ApiController {
public function __construct(
protected $appName,
private ConfigService $configService,
private IConfig $config,
private LoggerInterface $logger,
IRequest $request,
) {
parent::__construct($appName, $request);
}
/**
* Get the current AppConfig
* @return DataResponse
*/
#[FrontpageRoute(verb: 'GET', url: '/config')]
public function getAppConfig(): DataResponse {
return new DataResponse($this->configService->getAppConfig());
}
/**
* Update values on appConfig.
* Admin required, thus not checking separately.
*
* @param string $configKey AppConfig Key to store
* @param mixed $configValues Corresponding AppConfig Value
*
*/
#[FrontpageRoute(verb: 'PATCH', url: '/config')]
public function updateAppConfig(string $configKey, $configValue): DataResponse {
$this->logger->debug('Updating AppConfig: {configKey} => {configValue}', [
'configKey' => $configKey,
'configValue' => $configValue
]);
// Check for allowed keys
if (!in_array($configKey, Constants::CONFIG_KEYS)) {
return new DataResponse('Unknown appConfig key: ' . $configKey, Http::STATUS_BAD_REQUEST);
}
// Set on DB
$this->config->setAppValue($this->appName, $configKey, json_encode($configValue));
return new DataResponse();
}
}