Skip to content

Commit

Permalink
Fix nextcloud#31303: Make reminder notification behaviour selectable..
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Teichmann <daniel.teichmann@das-netzwerkteam.de>
  • Loading branch information
dzatoah committed Feb 24, 2022
1 parent c605ef1 commit 8e5d394
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 5 deletions.
2 changes: 1 addition & 1 deletion apps/dav/lib/BackgroundJob/EventReminderJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,6 @@ public function run($arg):void {
return;
}

$this->reminderService->processReminders();
$this->reminderService->processReminders($this->config);
}
}
12 changes: 10 additions & 2 deletions apps/dav/lib/CalDAV/Reminder/ReminderService.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
use DateTimeImmutable;
use OCA\DAV\CalDAV\CalDavBackend;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\IConfig;
use OCP\IGroup;
use OCP\IGroupManager;
use OCP\IUser;
Expand Down Expand Up @@ -110,8 +111,10 @@ public function __construct(Backend $backend,
*
* @throws NotificationProvider\ProviderNotAvailableException
* @throws NotificationTypeDoesNotExistException
*
* @param IConfig $config
*/
public function processReminders():void {
public function processReminders(IConfig $config):void {
$reminders = $this->backend->getRemindersToProcess();

foreach ($reminders as $reminder) {
Expand Down Expand Up @@ -141,7 +144,12 @@ public function processReminders():void {
continue;
}

$users = $this->getAllUsersWithWriteAccessToCalendar($reminder['calendar_id']);
if ($config->getAppValue('dav', 'dontSendEventRemindersToSharedGroupMembers', 'no') === 'no') {
$users = $this->getAllUsersWithWriteAccessToCalendar($reminder['calendar_id']);
} else {
$users = array();
}

$user = $this->getUserFromPrincipalURI($reminder['principaluri']);
if ($user) {
$users[] = $user;
Expand Down
2 changes: 1 addition & 1 deletion apps/dav/lib/Command/SendEventReminders.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
return 1;
}

$this->reminderService->processReminders();
$this->reminderService->processReminders($this->config);
return 0;
}
}
1 change: 1 addition & 0 deletions apps/dav/lib/Settings/CalDAVSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class CalDAVSettings implements IDelegatedSettings {
'generateBirthdayCalendar' => 'yes',
'sendEventReminders' => 'yes',
'sendEventRemindersPush' => 'no',
'dontSendEventRemindersToSharedGroupMembers' => 'no',
];

/**
Expand Down
4 changes: 4 additions & 0 deletions apps/dav/src/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ const CalDavSettingsView = new View({
'generateBirthdayCalendar'
),
sendEventReminders: loadState('dav', 'sendEventReminders'),
dontSendEventRemindersToSharedGroupMembers: loadState(
'dav',
'dontSendEventRemindersToSharedGroupMembers'
),
sendEventRemindersPush: loadState('dav', 'sendEventRemindersPush'),
}
},
Expand Down
29 changes: 29 additions & 0 deletions apps/dav/src/views/CalDavSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,28 @@
{{ $t('dav', 'Notifications are sent via background jobs, so these must occur often enough.') }}
</em>
</p>
<p>
<input id="caldavDontSendEventRemindersToSharedGroupMembers"
v-model="dontSendEventRemindersToSharedGroupMembers"
type="checkbox"
class="checkbox"
:disabled="!sendEventReminders">
<label for="caldavDontSendEventRemindersToSharedGroupMembers">
{{ $t('dav', 'Send reminder notifications not to shared group members.') }}
</label>
<br>
<!-- Can use v-html as:
- $t passes the translated string through DOMPurify.sanitize,
- replacement strings are not user-controlled. -->
<!-- eslint-disable-next-line vue/no-v-html -->
<em v-html="sendEventRemindersHelpText" />
<br>
<em>
{{ $t('dav', 'Send notifications only to the event organizer and \
attendees of an event and not to all members \
of a shared group.') }}
</em>
</p>
<p>
<input id="caldavSendEventRemindersPush"
v-model="sendEventRemindersPush"
Expand Down Expand Up @@ -115,6 +137,13 @@ export default {
sendEventReminders(value) {
OCP.AppConfig.setValue('dav', 'sendEventReminders', value ? 'yes' : 'no')
},
dontSendEventRemindersToSharedGroupMembers(value) {
OCP.AppConfig.setValue(
'dav',
'dontSendEventRemindersToSharedGroupMembers',
value ? 'yes' : 'no'
)
},
sendEventRemindersPush(value) {
OCP.AppConfig.setValue('dav', 'sendEventRemindersPush', value ? 'yes' : 'no')
},
Expand Down
4 changes: 3 additions & 1 deletion apps/dav/tests/unit/CalDAV/Reminder/ReminderServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ protected function setUp(): void {
$this->caldavBackend = $this->createMock(CalDavBackend::class);
$this->timeFactory = $this->createMock(ITimeFactory::class);

$this->config = $this->createMock(IConfig::class);

$this->caldavBackend->method('getShares')->willReturn([]);

$this->reminderService = new ReminderService($this->backend,
Expand Down Expand Up @@ -578,6 +580,6 @@ public function testProcessReminders():void {
$this->timeFactory->method('getDateTime')
->willReturn(\DateTime::createFromFormat(\DateTime::ATOM, '2016-06-08T00:00:00+00:00'));

$this->reminderService->processReminders();
$this->reminderService->processReminders($this->config);
}
}

0 comments on commit 8e5d394

Please sign in to comment.