Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 26 additions & 29 deletions lib/Service/ConfigService.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
use OCA\Deck\AppInfo\Application;
use OCA\Deck\BadRequestException;
use OCA\Deck\NoPermissionException;
use OCP\IConfig;
use OCP\Config\IUserConfig;
use OCP\IAppConfig;
use OCP\IGroup;
use OCP\IGroupManager;
use OCP\IUserSession;
Expand All @@ -24,16 +25,12 @@ class ConfigService {
public const SETTING_BOARD_NOTIFICATION_DUE_ALL = 'all';
public const SETTING_BOARD_NOTIFICATION_DUE_DEFAULT = self::SETTING_BOARD_NOTIFICATION_DUE_ASSIGNED;

private IConfig $config;
private ?string $userId = null;
private IGroupManager $groupManager;

public function __construct(
IConfig $config,
IGroupManager $groupManager,
private IAppConfig $appConfig,
private IUserConfig $userConfig,
private IGroupManager $groupManager,
private ?string $userId = null
) {
$this->groupManager = $groupManager;
$this->config = $config;
}

public function getUserId(): ?string {
Expand Down Expand Up @@ -80,17 +77,17 @@ public function get(string $key) {
if ($this->getUserId() === null) {
return false;
}
return (bool)$this->config->getUserValue($this->getUserId(), Application::APP_ID, 'calendar', true);
return $this->userConfig->getValueBool($this->getUserId(), Application::APP_ID, 'calendar', true);
case 'cardDetailsInModal':
if ($this->getUserId() === null) {
return false;
}
return (bool)$this->config->getUserValue($this->getUserId(), Application::APP_ID, 'cardDetailsInModal', true);
return $this->userConfig->getValueBool($this->getUserId(), Application::APP_ID, 'cardDetailsInModal', true);
case 'cardIdBadge':
if ($this->getUserId() === null) {
return false;
}
return (bool)$this->config->getUserValue($this->getUserId(), Application::APP_ID, 'cardIdBadge', false);
return $this->userConfig->getValueBool($this->getUserId(), Application::APP_ID, 'cardIdBadge', false);
}
return false;
}
Expand All @@ -101,13 +98,13 @@ public function isCalendarEnabled(?int $boardId = null): bool {
return false;
}

$appConfigState = $this->config->getAppValue(Application::APP_ID, 'calendar', 'yes') === 'yes';
$defaultState = (bool)$this->config->getUserValue($userId, Application::APP_ID, 'calendar', $appConfigState);
$appConfigState = $this->appConfig->getValueString(Application::APP_ID, 'calendar', 'yes') === 'yes';
$defaultState = $this->userConfig->getValueBool($userId, Application::APP_ID, 'calendar', $appConfigState);
if ($boardId === null) {
return $defaultState;
}

return (bool)$this->config->getUserValue($userId, Application::APP_ID, 'board:' . $boardId . ':calendar', $defaultState);
return $this->userConfig->getValueBool($userId, Application::APP_ID, 'board:' . $boardId . ':calendar', $defaultState);
}

public function isCardDetailsInModal(?int $boardId = null): bool {
Expand All @@ -116,26 +113,26 @@ public function isCardDetailsInModal(?int $boardId = null): bool {
return false;
}

$defaultState = (bool)$this->config->getUserValue($userId, Application::APP_ID, 'cardDetailsInModal', true);
$defaultState = $this->userConfig->getValueBool($userId, Application::APP_ID, 'cardDetailsInModal', true);
if ($boardId === null) {
return $defaultState;
}

return (bool)$this->config->getUserValue($userId, Application::APP_ID, 'board:' . $boardId . ':cardDetailsInModal', $defaultState);
return $this->userConfig->getValueBool($userId, Application::APP_ID, 'board:' . $boardId . ':cardDetailsInModal', $defaultState);
}

public function isCardIdBadgeEnabled(): bool {
$userId = $this->getUserId();
if ($userId === null) {
return false;
}
$appConfigState = $this->config->getAppValue(Application::APP_ID, 'cardIdBadge', 'yes') === 'no';
$defaultState = (bool)$this->config->getUserValue($userId, Application::APP_ID, 'cardIdBadge', $appConfigState);
$appConfigState = $this->appConfig->getValueString(Application::APP_ID, 'cardIdBadge', 'yes') === 'no';
$defaultState = $this->userConfig->getValueBool($userId, Application::APP_ID, 'cardIdBadge', $appConfigState);

return (bool)$this->config->getUserValue($userId, Application::APP_ID, 'cardIdBadge', $defaultState);
return $this->userConfig->getValueBool($userId, Application::APP_ID, 'cardIdBadge', $defaultState);
}

public function set($key, $value) {
public function set(string $key, $value) {
$userId = $this->getUserId();
if ($userId === null) {
throw new NoPermissionException('Must be logged in to set user config');
Expand All @@ -151,23 +148,23 @@ public function set($key, $value) {
$result = $this->setGroupLimit($value);
break;
case 'calendar':
$this->config->setUserValue($userId, Application::APP_ID, 'calendar', (string)$value);
$this->userConfig->setValueString($userId, Application::APP_ID, 'calendar', (string)$value);
$result = $value;
break;
case 'cardDetailsInModal':
$this->config->setUserValue($userId, Application::APP_ID, 'cardDetailsInModal', (string)$value);
$this->userConfig->setValueString($userId, Application::APP_ID, 'cardDetailsInModal', (string)$value);
$result = $value;
break;
case 'cardIdBadge':
$this->config->setUserValue($userId, Application::APP_ID, 'cardIdBadge', (string)$value);
$this->userConfig->setValueString($userId, Application::APP_ID, 'cardIdBadge', (string)$value);
$result = $value;
break;
case 'board':
[$boardId, $boardConfigKey] = explode(':', $key);
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($userId, Application::APP_ID, $key, (string)$value);
$this->userConfig->setValueString($userId, Application::APP_ID, $key, (string)$value);
$result = $value;
}
return $result;
Expand All @@ -182,12 +179,12 @@ private function setGroupLimit(array $value): array {
$groups[] = $group['id'];
}
$data = implode(',', $groups);
$this->config->setAppValue(Application::APP_ID, 'groupLimit', $data);
$this->appConfig->setValueString(Application::APP_ID, 'groupLimit', $data);
return $groups;
}

private function getGroupLimitList(): array {
$value = $this->config->getAppValue(Application::APP_ID, 'groupLimit', '');
$value = $this->appConfig->getValueString(Application::APP_ID, 'groupLimit', '');
$groups = explode(',', $value);
if ($value === '') {
return [];
Expand Down Expand Up @@ -217,14 +214,14 @@ public function getAttachmentFolder(?string $userId = null): string {
throw new NoPermissionException('Must be logged in get the attachment folder');
}

return $this->config->getUserValue($userId ?? $this->getUserId(), 'deck', 'attachment_folder', '/Deck');
return $this->userConfig->getValueString($userId ?? $this->getUserId(), 'deck', 'attachment_folder', '/Deck');
}

public function setAttachmentFolder(?string $userId, string $path): void {
if ($userId === null && $this->getUserId() === null) {
throw new NoPermissionException('Must be logged in get the attachment folder');
}

$this->config->setUserValue($userId ?? $this->getUserId(), 'deck', 'attachment_folder', $path);
$this->userConfig->setValueString($userId ?? $this->getUserId(), 'deck', 'attachment_folder', $path);
}
}
Loading