Only offer on/off setting when a board is not shared

Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Julius Härtl
2020-11-06 13:04:23 +01:00
parent 40cfed4240
commit 6b4d4d9ffc
2 changed files with 61 additions and 9 deletions

View File

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

View File

@@ -65,13 +65,28 @@
{{ t('deck', 'Archive board') }}
</ActionButton>
<ActionButton :icon="!showDueSettings ? 'icon-notifications-dark' : 'icon-view-previous' " @click="showDueSettings=!showDueSettings">
<!-- Due date reminder settings -->
<ActionButton v-if="showDueSettings"
:icon="updateDueSetting ? 'icon-loading-small' : 'icon-view-previous'"
:disabled="updateDueSetting"
@click="showDueSettings=false">
{{ t('deck', 'Due date reminders') }}
</ActionButton>
<ActionButton v-else-if="board.acl.length > 0"
:title="t('deck', 'Due date reminders')"
:icon="dueDateReminderIcon"
@click="showDueSettings=true">
{{ dueDateReminderText }}
</ActionButton>
<ActionButton v-else :icon="board.settings['notify-due'] === 'off' ? 'icon-sound' : 'icon-sound-off'" @click="board.settings['notify-due'] === 'off' ? updateSetting('notify-due', 'all') : updateSetting('notify-due', 'off')">
{{ board.settings['notify-due'] === 'off' ? t('deck', 'Turn on due date reminders') : t('deck', 'Turn off due date reminders') }}
</ActionButton>
<ActionButton v-if="showDueSettings"
name="notification"
icon="icon-sound"
:disabled="updateDueSetting"
:class="{ 'forced-active': board.settings['notify-due'] === 'all' }"
@click="updateSetting('notify-due', 'all')">
{{ t('deck', 'All cards') }}
@@ -79,6 +94,7 @@
<ActionButton v-if="showDueSettings"
name="notification"
icon="icon-user"
:disabled="updateDueSetting"
:class="{ 'forced-active': board.settings['notify-due'] === 'assigned' }"
@click="updateSetting('notify-due', 'assigned')">
{{ t('deck', 'Assigned cards') }}
@@ -86,6 +102,7 @@
<ActionButton v-if="showDueSettings"
name="notification"
icon="icon-sound-off"
:disabled="updateDueSetting"
:class="{ 'forced-active': board.settings['notify-due'] === 'off' }"
@click="updateSetting('notify-due', 'off')">
{{ 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: [