From 9fcb0b78f26b1cebd769250b5b72dcf835c90919 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Mon, 12 Oct 2020 16:05:02 +0200 Subject: [PATCH 01/15] Add option to configure notification level per board MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- appinfo/routes.php | 2 + css/icons.scss | 1 + img/notifications-dark.svg | 4 ++ lib/Db/Board.php | 3 ++ lib/Service/BoardService.php | 17 +++++++ lib/Service/ConfigService.php | 20 ++++++-- .../navigation/AppNavigationBoard.vue | 51 +++++++++++++++---- 7 files changed, 85 insertions(+), 13 deletions(-) create mode 100644 img/notifications-dark.svg diff --git a/appinfo/routes.php b/appinfo/routes.php index 4b273c464..1aa5890c8 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -127,6 +127,8 @@ return [ 'ocs' => [ ['name' => 'Config#get', 'url' => '/api/v1.0/config', 'verb' => 'GET'], ['name' => 'Config#setValue', 'url' => '/api/v1.0/config/{key}', 'verb' => 'POST'], + ['name' => 'Config#setBoardValue', 'url' => '/api/v1.0/config/board/{id}/{key}', 'verb' => 'POST'], + ['name' => 'comments_api#list', 'url' => '/api/v1.0/cards/{cardId}/comments', 'verb' => 'GET'], ['name' => 'comments_api#create', 'url' => '/api/v1.0/cards/{cardId}/comments', 'verb' => 'POST'], diff --git a/css/icons.scss b/css/icons.scss index 3c9af26cf..7d1ed1034 100644 --- a/css/icons.scss +++ b/css/icons.scss @@ -9,6 +9,7 @@ @include icon-black-white('filter_set', 'deck', 1); @include icon-black-white('attach', 'deck', 1); @include icon-black-white('reply', 'deck', 1); +@include icon-black-white('notifications-dark', 'deck', 1); .icon-toggle-compact-collapsed { @include icon-color('toggle-view-expand', 'deck', $color-black); diff --git a/img/notifications-dark.svg b/img/notifications-dark.svg new file mode 100644 index 000000000..1bc88f4c3 --- /dev/null +++ b/img/notifications-dark.svg @@ -0,0 +1,4 @@ + + + + diff --git a/lib/Db/Board.php b/lib/Db/Board.php index 28129b2b2..eb5ec1d07 100644 --- a/lib/Db/Board.php +++ b/lib/Db/Board.php @@ -37,6 +37,8 @@ class Board extends RelationalEntity { protected $deletedAt = 0; protected $lastModified = 0; + protected $settings = []; + public function __construct() { $this->addType('id', 'integer'); $this->addType('shared', 'integer'); @@ -49,6 +51,7 @@ class Board extends RelationalEntity { $this->addRelation('users'); $this->addRelation('permissions'); $this->addRelation('stacks'); + $this->addRelation('settings'); $this->addResolvable('owner'); $this->shared = -1; } diff --git a/lib/Service/BoardService.php b/lib/Service/BoardService.php index 516ca158a..93071e929 100644 --- a/lib/Service/BoardService.php +++ b/lib/Service/BoardService.php @@ -26,6 +26,7 @@ namespace OCA\Deck\Service; use OCA\Deck\Activity\ActivityManager; use OCA\Deck\Activity\ChangeSet; +use OCA\Deck\AppInfo\Application; use OCA\Deck\Db\Acl; use OCA\Deck\Db\AclMapper; use OCA\Deck\Db\AssignedUsersMapper; @@ -37,6 +38,7 @@ use OCA\Deck\Db\StackMapper; use OCA\Deck\NoPermissionException; use OCA\Deck\Notification\NotificationHelper; use OCP\AppFramework\Db\DoesNotExistException; +use OCP\IConfig; use OCP\IGroupManager; use OCP\IL10N; use OCA\Deck\Db\Board; @@ -52,6 +54,8 @@ class BoardService { private $stackMapper; private $labelMapper; private $aclMapper; + /** @var IConfig */ + private $config; private $l10n; private $permissionService; private $notificationHelper; @@ -66,9 +70,11 @@ class BoardService { private $boardsCache = null; + public function __construct( BoardMapper $boardMapper, StackMapper $stackMapper, + IConfig $config, IL10N $l10n, LabelMapper $labelMapper, AclMapper $aclMapper, @@ -85,6 +91,7 @@ class BoardService { $this->boardMapper = $boardMapper; $this->stackMapper = $stackMapper; $this->labelMapper = $labelMapper; + $this->config = $config; $this->aclMapper = $aclMapper; $this->l10n = $l10n; $this->permissionService = $permissionService; @@ -151,6 +158,7 @@ class BoardService { 'PERMISSION_MANAGE' => $permissions[Acl::PERMISSION_MANAGE] ?? false, 'PERMISSION_SHARE' => $permissions[Acl::PERMISSION_SHARE] ?? false ]); + $this->enrichWithBoardSettings($item); $result[$item->getId()] = $item; } $this->boardsCache = $result; @@ -190,6 +198,7 @@ class BoardService { 'PERMISSION_SHARE' => $permissions[Acl::PERMISSION_SHARE] ?? false ]); $this->enrichWithUsers($board); + $this->enrichWithBoardSettings($board); $this->boardsCache[$board->getId()] = $board; return $board; } @@ -476,6 +485,14 @@ class BoardService { return [$edit, $share, $manage]; } + public function enrichWithBoardSettings(Board $board) { + $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), + ]; + $board->setSettings($settings); + } + /** * @param $boardId * @param $type diff --git a/lib/Service/ConfigService.php b/lib/Service/ConfigService.php index baf1e4b8f..d370cdcad 100644 --- a/lib/Service/ConfigService.php +++ b/lib/Service/ConfigService.php @@ -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; } diff --git a/src/components/navigation/AppNavigationBoard.vue b/src/components/navigation/AppNavigationBoard.vue index fa03da162..5bf6bfefb 100644 --- a/src/components/navigation/AppNavigationBoard.vue +++ b/src/components/navigation/AppNavigationBoard.vue @@ -34,39 +34,65 @@ style="opacity: 0.5" />
@@ -82,7 +108,7 @@