diff --git a/lib/DAV/CalendarPlugin.php b/lib/DAV/CalendarPlugin.php index 76da1929a..c3f8834d7 100644 --- a/lib/DAV/CalendarPlugin.php +++ b/lib/DAV/CalendarPlugin.php @@ -33,11 +33,14 @@ class CalendarPlugin implements ICalendarProvider { /** @var DeckCalendarBackend */ private $backend; + /** @var ConfigService */ + private $configService; /** @var bool */ private $calendarIntegrationEnabled; public function __construct(DeckCalendarBackend $backend, ConfigService $configService) { $this->backend = $backend; + $this->configService = $configService; $this->calendarIntegrationEnabled = $configService->get('calendar'); } @@ -50,9 +53,12 @@ class CalendarPlugin implements ICalendarProvider { return []; } + $configService = $this->configService; return array_map(function (Board $board) use ($principalUri) { return new Calendar($principalUri, 'board-' . $board->getId(), $board, $this->backend); - }, $this->backend->getBoards()); + }, array_filter($this->backend->getBoards(), function ($board) use ($configService) { + return $configService->isCalendarEnabled($board->getId()); + })); } public function hasCalendarInCalendarHome(string $principalUri, string $calendarUri): bool { diff --git a/lib/Service/BoardService.php b/lib/Service/BoardService.php index 93071e929..cdc348119 100644 --- a/lib/Service/BoardService.php +++ b/lib/Service/BoardService.php @@ -486,9 +486,10 @@ class BoardService { } public function enrichWithBoardSettings(Board $board) { + $globalCalendarConfig = (bool)$this->config->getUserValue($this->userId, Application::APP_ID, 'calendar', true); $settings = [ 'notify-due' => $this->config->getUserValue($this->userId, Application::APP_ID, 'board:' . $board->getId() . ':notify-due', ConfigService::SETTING_BOARD_NOTIFICATION_DUE_ASSIGNED), - 'calendar' => $this->config->getUserValue($this->userId, Application::APP_ID, 'board:' . $board->getId() . ':calendar', true), + 'calendar' => $this->config->getUserValue($this->userId, Application::APP_ID, 'board:' . $board->getId() . ':calendar', $globalCalendarConfig), ]; $board->setSettings($settings); } diff --git a/lib/Service/ConfigService.php b/lib/Service/ConfigService.php index d370cdcad..d917740a2 100644 --- a/lib/Service/ConfigService.php +++ b/lib/Service/ConfigService.php @@ -55,7 +55,7 @@ class ConfigService { public function getAll(): array { $data = [ - 'calendar' => $this->get('calendar') + 'calendar' => $this->isCalendarEnabled() ]; if ($this->groupManager->isAdmin($this->userId)) { $data['groupLimit'] = $this->get('groupLimit'); @@ -65,7 +65,8 @@ class ConfigService { public function get($key) { $result = null; - switch ($key) { + [$scope, $id] = explode(':', $key, 2); + switch ($scope) { case 'groupLimit': if (!$this->groupManager->isAdmin($this->userId)) { throw new NoPermissionException('You must be admin to get the group limit'); @@ -79,6 +80,15 @@ class ConfigService { return $result; } + public function isCalendarEnabled(int $boardId = null): bool { + $defaultState = (bool)$this->config->getUserValue($this->userId, Application::APP_ID, 'calendar', true); + if ($boardId === null) { + return $defaultState; + } + + return (bool)$this->config->getUserValue($this->userId, Application::APP_ID, 'board:' . $boardId . ':calendar', $defaultState); + } + public function set($key, $value) { $result = null; [$scope, $id] = explode(':', $key, 2); @@ -95,7 +105,7 @@ class ConfigService { break; case 'board': [$boardId, $boardConfigKey] = explode(':', $key); - if (!in_array($value, [self::SETTING_BOARD_NOTIFICATION_DUE_ALL, self::SETTING_BOARD_NOTIFICATION_DUE_ASSIGNED, self::SETTING_BOARD_NOTIFICATION_DUE_OFF], true)) { + if ($boardConfigKey === 'notify-due' && !in_array($value, [self::SETTING_BOARD_NOTIFICATION_DUE_ALL, self::SETTING_BOARD_NOTIFICATION_DUE_ASSIGNED, self::SETTING_BOARD_NOTIFICATION_DUE_OFF], true)) { throw new BadRequestException('Board notification option must be one of: off, assigned, all'); } $this->config->setUserValue($this->userId, Application::APP_ID, $key, $value);