Add option to configure notification level per board

Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Julius Härtl
2020-10-12 16:05:02 +02:00
parent 297e060013
commit 9fcb0b78f2
7 changed files with 85 additions and 13 deletions

View File

@@ -27,12 +27,18 @@ declare(strict_types=1);
namespace OCA\Deck\Service;
use OCA\Deck\AppInfo\Application;
use OCA\Deck\BadRequestException;
use OCA\Deck\NoPermissionException;
use OCP\IConfig;
use OCP\IGroup;
use OCP\IGroupManager;
class ConfigService {
public const SETTING_BOARD_NOTIFICATION_DUE_OFF = 'off';
public const SETTING_BOARD_NOTIFICATION_DUE_ASSIGNED = 'assigned';
public const SETTING_BOARD_NOTIFICATION_DUE_ALL = 'all';
public const SETTING_BOARD_NOTIFICATION_DUE_DEFAULT = self::SETTING_BOARD_NOTIFICATION_DUE_ASSIGNED;
private $config;
private $userId;
private $groupManager;
@@ -52,9 +58,7 @@ class ConfigService {
'calendar' => $this->get('calendar')
];
if ($this->groupManager->isAdmin($this->userId)) {
$data = [
'groupLimit' => $this->get('groupLimit'),
];
$data['groupLimit'] = $this->get('groupLimit');
}
return $data;
}
@@ -77,7 +81,8 @@ class ConfigService {
public function set($key, $value) {
$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 set the group limit');
@@ -88,6 +93,13 @@ class ConfigService {
$this->config->setUserValue($this->userId, Application::APP_ID, 'calendar', (int)$value);
$result = $value;
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)) {
throw new BadRequestException('Board notification option must be one of: off, assigned, all');
}
$this->config->setUserValue($this->userId, Application::APP_ID, $key, $value);
$result = $value;
}
return $result;
}