@@ -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 {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user