Skip to content

Commit

Permalink
E-Mail-Reminder to all attendees is sent only by organizer of the rem…
Browse files Browse the repository at this point in the history
…inder/event
  • Loading branch information
christlang committed May 8, 2021
1 parent 461a975 commit 010114b
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 11 deletions.
4 changes: 3 additions & 1 deletion apps/dav/lib/CalDAV/Reminder/INotificationProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,11 @@ interface INotificationProvider {
* @param VEvent $vevent
* @param string $calendarDisplayName
* @param IUser[] $users
* @param IUser $userOfReminder
* @return void
*/
public function send(VEvent $vevent,
string $calendarDisplayName,
array $users = []): void;
array $users = [],
IUser $userOfReminder = null): void;
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,13 @@ public function __construct(ILogger $logger,
* @param VEvent $vevent
* @param string $calendarDisplayName
* @param IUser[] $users
* @param IUser $userOfReminder
* @return void
*/
abstract public function send(VEvent $vevent,
string $calendarDisplayName,
array $users = []): void;
array $users = [],
IUser $userOfReminder = null): void;

/**
* @return string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
use OCP\IL10N;
use OCP\ILogger;
use OCP\IURLGenerator;
use OCP\IUser;
use OCP\L10N\IFactory as L10NFactory;
use OCP\Mail\IEMailTemplate;
use OCP\Mail\IMailer;
Expand Down Expand Up @@ -80,15 +81,24 @@ public function __construct(IConfig $config,
* @param VEvent $vevent
* @param string $calendarDisplayName
* @param array $users
* @param IUser $userOfReminder
* @throws \Exception
*/
public function send(VEvent $vevent,
string $calendarDisplayName,
array $users = []):void {
array $users = [],
IUser $userOfReminder = null):void {
$fallbackLanguage = $this->getFallbackLanguage();

$emailAddressesOfSharees = $this->getEMailAddressesOfAllUsersWithWriteAccessToCalendar($users);
$emailAddressesOfAttendees = $this->getAllEMailAddressesFromEvent($vevent);

$organizer = $this->getOrganizerEMailAndNameFromEvent($vevent);

$emailAddressesOfAttendees = [];

if ($userOfReminder && strcasecmp($userOfReminder->getEMailAddress(), key($organizer)) == 0) {
$emailAddressesOfAttendees = $this->getAllEMailAddressesFromEvent($vevent);
}

// Quote from php.net:
// If the input arrays have the same string keys, then the later value for that key will overwrite the previous one.
Expand All @@ -99,7 +109,6 @@ public function send(VEvent $vevent,
);

$sortedByLanguage = $this->sortEMailAddressesByLanguage($emailAddresses, $fallbackLanguage);
$organizer = $this->getOrganizerEMailAndNameFromEvent($vevent);

foreach ($sortedByLanguage as $lang => $emailAddresses) {
if (!$this->hasL10NForLang($lang)) {
Expand Down Expand Up @@ -196,7 +205,7 @@ private function getOrganizerEMailAndNameFromEvent(VEvent $vevent):?array {
}

$organizer = $vevent->ORGANIZER;
if (strcasecmp($organizer->getValue(), 'mailto:') !== 0) {
if (!str_starts_with($organizer->getValue(), 'mailto:')) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,13 @@ public function __construct(IConfig $config,
* @param VEvent $vevent
* @param string $calendarDisplayName
* @param IUser[] $users
* @param IUser $userOfReminder
* @throws \Exception
*/
public function send(VEvent $vevent,
string $calendarDisplayName = null,
array $users = []):void {
array $users = [],
IUser $userOfReminder = null):void {
if ($this->config->getAppValue('dav', 'sendEventRemindersPush', 'no') !== 'yes') {
return;
}
Expand Down
8 changes: 4 additions & 4 deletions apps/dav/lib/CalDAV/Reminder/ReminderService.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,13 @@ public function processReminders():void {
}

$users = $this->getAllUsersWithWriteAccessToCalendar($reminder['calendar_id']);
$user = $this->getUserFromPrincipalURI($reminder['principaluri']);
if ($user) {
$users[] = $user;
$userOfReminder = $this->getUserFromPrincipalURI($reminder['principaluri']);
if ($userOfReminder) {
$users[] = $userOfReminder;
}

$notificationProvider = $this->notificationProviderManager->getProvider($reminder['type']);
$notificationProvider->send($vevent, $reminder['displayname'], $users);
$notificationProvider->send($vevent, $reminder['displayname'], $users, $userOfReminder);

$this->deleteOrProcessNext($reminder, $vevent);
}
Expand Down

0 comments on commit 010114b

Please sign in to comment.