feat: allow global settings as fallback when user has not defined any

This commit is contained in:
2024-08-09 21:36:02 +02:00
parent 2d10b81650
commit 6b53ccb88e
10 changed files with 193 additions and 35 deletions

View File

@ -14,6 +14,7 @@ use OCP\AppFramework\Http;
use OCP\AppFramework\Http\JSONResponse;
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
use OCP\AppFramework\Http\Attribute\NoCSRFRequired;
use OCP\AppFramework\Http\Attribute\AuthorizedAdminSetting;
class SettingsController extends Controller {
@ -33,6 +34,17 @@ class SettingsController extends Controller {
return $this->makeJSONResponse(fn () => $this->appSettings->getAll($this->userId));
}
#[AuthorizedAdminSetting]
public function setGlobal(string $folderVariant, string $buttonVariant): JSONResponse {
$this->appSettings->setGlobal($folderVariant, $buttonVariant);
return $this->makeJSONResponse(fn () => $this->appSettings->getGlobal());
}
#[NoCSRFRequired]
public function getGlobal(): JSONResponse {
return $this->makeJSONResponse(fn () => $this->appSettings->getGlobal());
}
protected function makeJSONResponse(Closure $closure): JSONResponse {
try {
return new JSONResponse($closure(), HTTP::STATUS_OK);