config = $config; $this->userSession = $userSession; } /** * @NoAdminRequired * * @throws Exception */ public function getSettings(): JSONResponse { $user = $this->userSession->getUser(); if (!$user instanceof IUser) { throw new Exception("Not logged in"); } return new JSONResponse([ 'enabled' => $this->config->getUserValue($user->getUID(), Application::APP_ID, 'enabled', 'true') === 'true', ]); } /** * @NoAdminRequired * * @throws Exception */ public function setSetting(string $key, string $value): JSONResponse { $user = $this->userSession->getUser(); if (!$user instanceof IUser) { throw new Exception("Not logged in"); } $availableSettings = ['enabled']; if (!in_array($key, $availableSettings)) { return new JSONResponse([ 'message' => 'parameter does not exist', ], Http::STATUS_UNPROCESSABLE_ENTITY); } $this->config->setUserValue($user->getUID(), Application::APP_ID, $key, $value); return new JSONResponse([ 'key' => $key, 'value' => $value, ]); } }