fix: set per-user instead of globally
This commit is contained in:
parent
ea9a60558f
commit
2d10b81650
@ -16,20 +16,21 @@ use OCP\AppFramework\Http\Attribute\NoAdminRequired;
|
|||||||
use OCP\AppFramework\Http\Attribute\NoCSRFRequired;
|
use OCP\AppFramework\Http\Attribute\NoCSRFRequired;
|
||||||
|
|
||||||
class SettingsController extends Controller {
|
class SettingsController extends Controller {
|
||||||
public function __construct($appName, IRequest $request, private AppSettings $appSettings) {
|
|
||||||
|
public function __construct($appName, IRequest $request, private AppSettings $appSettings, private $userId) {
|
||||||
parent::__construct($appName, $request);
|
parent::__construct($appName, $request);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[NoAdminRequired]
|
#[NoAdminRequired]
|
||||||
#[NoCSRFRequired]
|
#[NoCSRFRequired]
|
||||||
public function get(): JSONResponse {
|
public function get(): JSONResponse {
|
||||||
return $this->makeJSONResponse(fn () => $this->appSettings->getAll());
|
return $this->makeJSONResponse(fn () => $this->appSettings->getAll($this->userId));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[NoAdminRequired]
|
#[NoAdminRequired]
|
||||||
public function set(string $folderVariant, string $buttonVariant): JSONResponse {
|
public function set(string $folderVariant, string $buttonVariant): JSONResponse {
|
||||||
$this->appSettings->set($folderVariant, $buttonVariant);
|
$this->appSettings->set($this->userId, $folderVariant, $buttonVariant);
|
||||||
return $this->makeJSONResponse(fn () => $this->appSettings->getAll());
|
return $this->makeJSONResponse(fn () => $this->appSettings->getAll($this->userId));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function makeJSONResponse(Closure $closure): JSONResponse {
|
protected function makeJSONResponse(Closure $closure): JSONResponse {
|
||||||
|
@ -12,23 +12,23 @@ class AppSettings {
|
|||||||
public function __construct(private IConfig $config) {
|
public function __construct(private IConfig $config) {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getStringSetting(string $key, string $default = ''): string {
|
public function getStringSetting($userId, string $key, string $default = ''): string {
|
||||||
return $this->config->getAppValue(AppConstants::APP_ID, $key) ?: $default;
|
return $this->config->getUserValue(AppConstants::APP_ID, $userId, $key) ?: $default;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setStringSetting(string $key, string $value): void {
|
public function setStringSetting($userId, string $key, string $value): void {
|
||||||
$this->config->setAppValue(AppConstants::APP_ID, $key, $value);
|
$this->config->setUserValue(AppConstants::APP_ID, $userId, $key, $value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getAll(): array {
|
public function getAll($userId): array {
|
||||||
return [
|
return [
|
||||||
AppSettings::FOLDER_VARIANT => $this->getStringSetting(AppSettings::FOLDER_VARIANT, 'pride'),
|
AppSettings::FOLDER_VARIANT => $this->getStringSetting($userId, AppSettings::FOLDER_VARIANT, 'pride'),
|
||||||
AppSettings::BUTTON_VARIANT => $this->getStringSetting(AppSettings::BUTTON_VARIANT, 'trans'),
|
AppSettings::BUTTON_VARIANT => $this->getStringSetting($userId, AppSettings::BUTTON_VARIANT, 'trans'),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function set($folder, $button): void {
|
public function set($userId, $folder, $button): void {
|
||||||
$this->setStringSetting(AppSettings::FOLDER_VARIANT, $folder);
|
$this->setStringSetting($userId, AppSettings::FOLDER_VARIANT, $folder);
|
||||||
$this->setStringSetting(AppSettings::BUTTON_VARIANT, $button);
|
$this->setStringSetting($userId, AppSettings::BUTTON_VARIANT, $button);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user