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 Mar 15, 2022
1 parent 04a4562 commit d4f7dff
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 4 deletions.
16 changes: 14 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 @@ -66,6 +67,9 @@ class ReminderService {
/** @var ITimeFactory */
private $timeFactory;

/** @var IConfig */
private $config;

public const REMINDER_TYPE_EMAIL = 'EMAIL';
public const REMINDER_TYPE_DISPLAY = 'DISPLAY';
public const REMINDER_TYPE_AUDIO = 'AUDIO';
Expand All @@ -90,19 +94,22 @@ class ReminderService {
* @param IGroupManager $groupManager
* @param CalDavBackend $caldavBackend
* @param ITimeFactory $timeFactory
* @param IConfig $config
*/
public function __construct(Backend $backend,
NotificationProviderManager $notificationProviderManager,
IUserManager $userManager,
IGroupManager $groupManager,
CalDavBackend $caldavBackend,
ITimeFactory $timeFactory) {
ITimeFactory $timeFactory,
IConfig $config) {
$this->backend = $backend;
$this->notificationProviderManager = $notificationProviderManager;
$this->userManager = $userManager;
$this->groupManager = $groupManager;
$this->caldavBackend = $caldavBackend;
$this->timeFactory = $timeFactory;
$this->config = $config;
}

/**
Expand Down Expand Up @@ -145,7 +152,12 @@ public function processReminders():void {
continue;
}

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

$user = $this->getUserFromPrincipalURI($reminder['principaluri']);
if ($user) {
$users[] = $user;
Expand Down
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',
'sendEventRemindersToSharedGroupMembers' => 'yes',
];

/**
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'),
sendEventRemindersToSharedGroupMembers: loadState(
'dav',
'sendEventRemindersToSharedGroupMembers'
),
sendEventRemindersPush: loadState('dav', 'sendEventRemindersPush'),
}
},
Expand Down
23 changes: 22 additions & 1 deletion apps/dav/src/views/CalDavSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,21 @@
{{ $t('dav', 'Notifications are sent via background jobs, so these must occur often enough.') }}
</em>
</p>
<p>
<p style="padding-left: 28px">
<input id="caldavSendEventRemindersToSharedGroupMembers"
v-model="sendEventRemindersToSharedGroupMembers"
type="checkbox"
class="checkbox"
:disabled="!sendEventReminders">
<label for="caldavSendEventRemindersToSharedGroupMembers">
{{ $t('dav', 'Send reminder notifications to calendar sharees as well') }}
</label>
<br>
<em>
{{ $t('dav', 'Reminders are always sent to organizers and attendees.' )}}
</em>
</p>
<p style="padding-left: 28px">
<input id="caldavSendEventRemindersPush"
v-model="sendEventRemindersPush"
type="checkbox"
Expand Down Expand Up @@ -115,6 +129,13 @@ export default {
sendEventReminders(value) {
OCP.AppConfig.setValue('dav', 'sendEventReminders', value ? 'yes' : 'no')
},
sendEventRemindersToSharedGroupMembers(value) {
OCP.AppConfig.setValue(
'dav',
'sendEventRemindersToSharedGroupMembers',
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 @@ -194,6 +194,7 @@ protected function setUp(): void {
$this->groupManager = $this->createMock(IGroupManager::class);
$this->caldavBackend = $this->createMock(CalDavBackend::class);
$this->timeFactory = $this->createMock(ITimeFactory::class);
$this->config = $this->createMock(IConfig::class);

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

Expand All @@ -202,7 +203,8 @@ protected function setUp(): void {
$this->userManager,
$this->groupManager,
$this->caldavBackend,
$this->timeFactory);
$this->timeFactory,
$this->config);
}

public function testOnCalendarObjectDelete():void {
Expand Down

0 comments on commit d4f7dff

Please sign in to comment.