ConfigService cleanup

Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Julius Härtl
2020-11-06 14:51:26 +01:00
parent b18ebe83b6
commit ba384d9b72
3 changed files with 22 additions and 5 deletions

View File

@@ -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 {

View File

@@ -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);
}

View File

@@ -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);