@@ -33,11 +33,14 @@ class CalendarPlugin implements ICalendarProvider {
|
|||||||
|
|
||||||
/** @var DeckCalendarBackend */
|
/** @var DeckCalendarBackend */
|
||||||
private $backend;
|
private $backend;
|
||||||
|
/** @var ConfigService */
|
||||||
|
private $configService;
|
||||||
/** @var bool */
|
/** @var bool */
|
||||||
private $calendarIntegrationEnabled;
|
private $calendarIntegrationEnabled;
|
||||||
|
|
||||||
public function __construct(DeckCalendarBackend $backend, ConfigService $configService) {
|
public function __construct(DeckCalendarBackend $backend, ConfigService $configService) {
|
||||||
$this->backend = $backend;
|
$this->backend = $backend;
|
||||||
|
$this->configService = $configService;
|
||||||
$this->calendarIntegrationEnabled = $configService->get('calendar');
|
$this->calendarIntegrationEnabled = $configService->get('calendar');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,9 +53,12 @@ class CalendarPlugin implements ICalendarProvider {
|
|||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$configService = $this->configService;
|
||||||
return array_map(function (Board $board) use ($principalUri) {
|
return array_map(function (Board $board) use ($principalUri) {
|
||||||
return new Calendar($principalUri, 'board-' . $board->getId(), $board, $this->backend);
|
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 {
|
public function hasCalendarInCalendarHome(string $principalUri, string $calendarUri): bool {
|
||||||
|
|||||||
@@ -486,9 +486,10 @@ class BoardService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function enrichWithBoardSettings(Board $board) {
|
public function enrichWithBoardSettings(Board $board) {
|
||||||
|
$globalCalendarConfig = (bool)$this->config->getUserValue($this->userId, Application::APP_ID, 'calendar', true);
|
||||||
$settings = [
|
$settings = [
|
||||||
'notify-due' => $this->config->getUserValue($this->userId, Application::APP_ID, 'board:' . $board->getId() . ':notify-due', ConfigService::SETTING_BOARD_NOTIFICATION_DUE_ASSIGNED),
|
'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);
|
$board->setSettings($settings);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ class ConfigService {
|
|||||||
|
|
||||||
public function getAll(): array {
|
public function getAll(): array {
|
||||||
$data = [
|
$data = [
|
||||||
'calendar' => $this->get('calendar')
|
'calendar' => $this->isCalendarEnabled()
|
||||||
];
|
];
|
||||||
if ($this->groupManager->isAdmin($this->userId)) {
|
if ($this->groupManager->isAdmin($this->userId)) {
|
||||||
$data['groupLimit'] = $this->get('groupLimit');
|
$data['groupLimit'] = $this->get('groupLimit');
|
||||||
@@ -65,7 +65,8 @@ class ConfigService {
|
|||||||
|
|
||||||
public function get($key) {
|
public function get($key) {
|
||||||
$result = null;
|
$result = null;
|
||||||
switch ($key) {
|
[$scope, $id] = explode(':', $key, 2);
|
||||||
|
switch ($scope) {
|
||||||
case 'groupLimit':
|
case 'groupLimit':
|
||||||
if (!$this->groupManager->isAdmin($this->userId)) {
|
if (!$this->groupManager->isAdmin($this->userId)) {
|
||||||
throw new NoPermissionException('You must be admin to get the group limit');
|
throw new NoPermissionException('You must be admin to get the group limit');
|
||||||
@@ -79,6 +80,15 @@ class ConfigService {
|
|||||||
return $result;
|
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) {
|
public function set($key, $value) {
|
||||||
$result = null;
|
$result = null;
|
||||||
[$scope, $id] = explode(':', $key, 2);
|
[$scope, $id] = explode(':', $key, 2);
|
||||||
@@ -95,7 +105,7 @@ class ConfigService {
|
|||||||
break;
|
break;
|
||||||
case 'board':
|
case 'board':
|
||||||
[$boardId, $boardConfigKey] = explode(':', $key);
|
[$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');
|
throw new BadRequestException('Board notification option must be one of: off, assigned, all');
|
||||||
}
|
}
|
||||||
$this->config->setUserValue($this->userId, Application::APP_ID, $key, $value);
|
$this->config->setUserValue($this->userId, Application::APP_ID, $key, $value);
|
||||||
|
|||||||
Reference in New Issue
Block a user