From 6b4d4d9ffc439cb7ab38ec0f65bdedf29a8bad71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Fri, 6 Nov 2020 13:04:23 +0100 Subject: [PATCH] Only offer on/off setting when a board is not shared MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- lib/Notification/NotificationHelper.php | 27 ++++++++---- .../navigation/AppNavigationBoard.vue | 43 ++++++++++++++++++- 2 files changed, 61 insertions(+), 9 deletions(-) diff --git a/lib/Notification/NotificationHelper.php b/lib/Notification/NotificationHelper.php index 07d9c0845..9715da7fc 100644 --- a/lib/Notification/NotificationHelper.php +++ b/lib/Notification/NotificationHelper.php @@ -92,16 +92,27 @@ class NotificationHelper { return; } - // TODO: Once assigning users is possible, those should be notified instead of all users of the board $boardId = $this->cardMapper->findBoardId($card->getId()); - $board = $this->getBoard($boardId); + $board = $this->getBoard($boardId, false, true); /** @var User $user */ foreach ($this->permissionService->findUsers($boardId) as $user) { $notificationSetting = $this->config->getUserValue($user->getUID(), Application::APP_ID, 'board:' . $boardId . ':notify-due', ConfigService::SETTING_BOARD_NOTIFICATION_DUE_DEFAULT); - if ( - $notificationSetting === ConfigService::SETTING_BOARD_NOTIFICATION_DUE_ALL || - ($notificationSetting === ConfigService::SETTING_BOARD_NOTIFICATION_DUE_ASSIGNED && $this->assignedUsersMapper->isUserAssigned($card->getId(), $user->getUID())) - ) { + + if ($notificationSetting === ConfigService::SETTING_BOARD_NOTIFICATION_DUE_OFF) { + continue; + } + + $shouldNotify = $notificationSetting === ConfigService::SETTING_BOARD_NOTIFICATION_DUE_ALL; + + if ($user->getUID() === $board->getOwner() && count($board->getAcl()) === 0) { + // Notify if all or assigned is configured for unshared boards + $shouldNotify = true; + } else if ($notificationSetting === ConfigService::SETTING_BOARD_NOTIFICATION_DUE_ASSIGNED && $this->assignedUsersMapper->isUserAssigned($card->getId(), $user->getUID())) { + // Notify if the user is assigned and has the assigned setting selected + $shouldNotify = true; + } + + if ($shouldNotify) { $notification = $this->notificationManager->createNotification(); $notification ->setApp('deck') @@ -187,9 +198,9 @@ class NotificationHelper { * @return Board * @throws \OCP\AppFramework\Db\DoesNotExistException */ - private function getBoard($boardId) { + private function getBoard($boardId, bool $withLabels = false, bool $withAcl = false) { if (!array_key_exists($boardId, $this->boards)) { - $this->boards[$boardId] = $this->boardMapper->find($boardId); + $this->boards[$boardId] = $this->boardMapper->find($boardId, $withLabels, $withAcl); } return $this->boards[$boardId]; } diff --git a/src/components/navigation/AppNavigationBoard.vue b/src/components/navigation/AppNavigationBoard.vue index 3c6a5458a..56589cf8a 100644 --- a/src/components/navigation/AppNavigationBoard.vue +++ b/src/components/navigation/AppNavigationBoard.vue @@ -65,13 +65,28 @@ {{ t('deck', 'Archive board') }} - + + + {{ t('deck', 'Due date reminders') }} + + {{ dueDateReminderText }} + + + {{ board.settings['notify-due'] === 'off' ? t('deck', 'Turn on due date reminders') : t('deck', 'Turn off due date reminders') }} + {{ t('deck', 'All cards') }} @@ -79,6 +94,7 @@ {{ t('deck', 'Assigned cards') }} @@ -86,6 +102,7 @@ {{ t('deck', 'No notifications') }} @@ -145,6 +162,7 @@ export default { editTitle: '', editColor: '', showDueSettings: false, + updateDueSetting: null, } }, computed: { @@ -166,6 +184,26 @@ export default { canManage() { return this.board.permissions.PERMISSION_MANAGE }, + dueDateReminderIcon() { + if (this.board.settings['notify-due'] === 'all') { + return 'icon-sound' + } else if (this.board.settings['notify-due'] === 'assigned') { + return 'icon-user' + } else if (this.board.settings['notify-due'] === 'off') { + return 'icon-sound-off' + } + return '' + }, + dueDateReminderText() { + if (this.board.settings['notify-due'] === 'all') { + return t('deck', 'All cards') + } else if (this.board.settings['notify-due'] === 'assigned') { + return t('deck', 'Only assigned cards') + } else if (this.board.settings['notify-due'] === 'off') { + return t('deck', 'No reminder') + } + return '' + }, }, watch: {}, mounted() { @@ -262,9 +300,12 @@ export default { this.$router.push(route) }, async updateSetting(key, value) { + this.updateDueSetting = value const setting = {} setting['board:' + this.board.id + ':' + key] = value await this.$store.dispatch('setConfig', setting) + this.showDueSettings = false + this.updateDueSetting = null }, }, inject: [