41 lines
1.2 KiB
PHP
41 lines
1.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace OCA\NuqloudMasterCalendar\Controller;
|
|
|
|
use OCA\NuqloudMasterCalendar\AppInfo\Application;
|
|
use OCA\NuqloudMasterCalendar\Calendar\SourceCalendarService;
|
|
use OCP\AppFramework\Controller;
|
|
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
|
|
use OCP\AppFramework\Http\DataResponse;
|
|
use OCP\IConfig;
|
|
use OCP\IL10N;
|
|
use OCP\IRequest;
|
|
use OCP\IUserSession;
|
|
|
|
class SettingsController extends Controller {
|
|
public function __construct(
|
|
IRequest $request,
|
|
private IConfig $config,
|
|
private IUserSession $userSession,
|
|
private IL10N $l,
|
|
) {
|
|
parent::__construct(Application::APP_ID, $request);
|
|
}
|
|
|
|
#[NoAdminRequired]
|
|
public function save(string $mode): DataResponse {
|
|
if (!in_array($mode, [SourceCalendarService::MODE_ALL, SourceCalendarService::MODE_EDITABLE], true)) {
|
|
return new DataResponse(['message' => $this->l->t('Invalid source mode.')], 400);
|
|
}
|
|
$user = $this->userSession->getUser();
|
|
if ($user === null) {
|
|
return new DataResponse(['message' => $this->l->t('Authentication required.')], 401);
|
|
}
|
|
|
|
$this->config->setUserValue($user->getUID(), Application::APP_ID, 'source_mode', $mode);
|
|
return new DataResponse(['mode' => $mode]);
|
|
}
|
|
}
|