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 18, 2022
1 parent b0fbccc commit b44fb78
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 7 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 @@ -43,6 +43,7 @@ class CalDAVSettings implements IDelegatedSettings {
'sendInvitations' => 'yes',
'generateBirthdayCalendar' => 'yes',
'sendEventReminders' => 'yes',
'sendEventRemindersToSharedGroupMembers' => 'yes',
'sendEventRemindersPush' => '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'),
sendEventRemindersToSharedGroupMembers: loadState(
'dav',
'sendEventRemindersToSharedGroupMembers'
),
sendEventRemindersPush: loadState('dav', 'sendEventRemindersPush'),
}
},
Expand Down
29 changes: 28 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 class="indented">
<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 class="indented">
<input id="caldavSendEventRemindersPush"
v-model="sendEventRemindersPush"
type="checkbox"
Expand All @@ -70,6 +84,12 @@
</div>
</template>

<style lang="scss" scoped>
.indented {
padding-left: 28px;
}
</style>

<script>
import axios from '@nextcloud/axios'
import { generateUrl } from '@nextcloud/router'
Expand Down Expand Up @@ -115,6 +135,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
8 changes: 7 additions & 1 deletion apps/dav/tests/unit/CalDAV/Reminder/ReminderServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
use OCA\DAV\CalDAV\Reminder\NotificationProviderManager;
use OCA\DAV\CalDAV\Reminder\ReminderService;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\IConfig;
use OCP\IGroupManager;
use OCP\IUser;
use OCP\IUserManager;
Expand Down Expand Up @@ -63,6 +64,9 @@ class ReminderServiceTest extends TestCase {
/** @var ITimeFactory|\PHPUnit\Framework\MockObject\MockObject */
private $timeFactory;

/** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
private $config;

/** @var ReminderService */
private $reminderService;

Expand Down Expand Up @@ -194,6 +198,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 +207,8 @@ protected function setUp(): void {
$this->userManager,
$this->groupManager,
$this->caldavBackend,
$this->timeFactory);
$this->timeFactory,
$this->config);
}

public function testOnCalendarObjectDelete():void {
Expand Down
4 changes: 2 additions & 2 deletions dist/dav-settings-admin-caldav.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/dav-settings-admin-caldav.js.map

Large diffs are not rendered by default.

0 comments on commit b44fb78

Please sign in to comment.