-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
[stable22] Fix duplicate event email notifications #35021
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,7 @@ | |
| * @author Christoph Wurst <[email protected]> | ||
| * @author Georg Ehrke <[email protected]> | ||
| * @author Roeland Jago Douma <[email protected]> | ||
| * @author Richard Steinmetz <[email protected]> | ||
| * | ||
| * @license GNU AGPL version 3 or any later version | ||
| * | ||
|
|
@@ -42,10 +43,12 @@ interface INotificationProvider { | |
| * | ||
| * @param VEvent $vevent | ||
| * @param string $calendarDisplayName | ||
| * @param string[] $principalEmailAddresses All email addresses associated to the principal owning the calendar object | ||
| * @param IUser[] $users | ||
| * @return void | ||
| */ | ||
| public function send(VEvent $vevent, | ||
| string $calendarDisplayName, | ||
| array $principalEmailAddresses, | ||
| array $users = []): void; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,7 @@ | |
| * @author Georg Ehrke <[email protected]> | ||
| * @author Joas Schilling <[email protected]> | ||
| * @author Roeland Jago Douma <[email protected]> | ||
| * @author Richard Steinmetz <[email protected]> | ||
| * | ||
| * @license GNU AGPL version 3 or any later version | ||
| * | ||
|
|
@@ -89,11 +90,13 @@ public function __construct(ILogger $logger, | |
| * | ||
| * @param VEvent $vevent | ||
| * @param string $calendarDisplayName | ||
| * @param string[] $principalEmailAddresses | ||
| * @param IUser[] $users | ||
| * @return void | ||
| */ | ||
| abstract public function send(VEvent $vevent, | ||
| string $calendarDisplayName, | ||
| array $principalEmailAddresses, | ||
| array $users = []): void; | ||
|
|
||
| /** | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,7 @@ | |
| * @author Georg Ehrke <[email protected]> | ||
| * @author Roeland Jago Douma <[email protected]> | ||
| * @author Thomas Citharel <[email protected]> | ||
| * @author Richard Steinmetz <[email protected]> | ||
| * | ||
| * @license GNU AGPL version 3 or any later version | ||
| * | ||
|
|
@@ -81,11 +82,13 @@ public function __construct(IConfig $config, | |
| * | ||
| * @param VEvent $vevent | ||
| * @param string $calendarDisplayName | ||
| * @param string[] $principalEmailAddresses | ||
| * @param IUser[] $users | ||
| * @throws \Exception | ||
| */ | ||
| public function send(VEvent $vevent, | ||
| string $calendarDisplayName = null, | ||
| string $calendarDisplayName, | ||
| array $principalEmailAddresses, | ||
| array $users = []):void { | ||
| if ($this->config->getAppValue('dav', 'sendEventRemindersPush', 'no') !== 'yes') { | ||
| return; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,7 @@ | |
| * @author Joas Schilling <[email protected]> | ||
| * @author Roeland Jago Douma <[email protected]> | ||
| * @author Thomas Citharel <[email protected]> | ||
| * @author Richard Steinmetz <[email protected]> | ||
| * | ||
| * @license GNU AGPL version 3 or any later version | ||
| * | ||
|
|
@@ -32,6 +33,7 @@ | |
|
|
||
| use DateTimeImmutable; | ||
| use OCA\DAV\CalDAV\CalDavBackend; | ||
| use OCA\DAV\Connector\Sabre\Principal; | ||
| use OCP\AppFramework\Utility\ITimeFactory; | ||
| use OCP\IGroup; | ||
| use OCP\IGroupManager; | ||
|
|
@@ -66,6 +68,9 @@ class ReminderService { | |
| /** @var ITimeFactory */ | ||
| private $timeFactory; | ||
|
|
||
| /** @var Principal */ | ||
| private $principalConnector; | ||
|
|
||
| public const REMINDER_TYPE_EMAIL = 'EMAIL'; | ||
| public const REMINDER_TYPE_DISPLAY = 'DISPLAY'; | ||
| public const REMINDER_TYPE_AUDIO = 'AUDIO'; | ||
|
|
@@ -90,19 +95,22 @@ class ReminderService { | |
| * @param IGroupManager $groupManager | ||
| * @param CalDavBackend $caldavBackend | ||
| * @param ITimeFactory $timeFactory | ||
| * @param Principal $principalConnector | ||
| */ | ||
| public function __construct(Backend $backend, | ||
| NotificationProviderManager $notificationProviderManager, | ||
| IUserManager $userManager, | ||
| IGroupManager $groupManager, | ||
| CalDavBackend $caldavBackend, | ||
| ITimeFactory $timeFactory) { | ||
| ITimeFactory $timeFactory, | ||
| Principal $principalConnector) { | ||
| $this->backend = $backend; | ||
| $this->notificationProviderManager = $notificationProviderManager; | ||
| $this->userManager = $userManager; | ||
| $this->groupManager = $groupManager; | ||
| $this->caldavBackend = $caldavBackend; | ||
| $this->timeFactory = $timeFactory; | ||
| $this->principalConnector = $principalConnector; | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -151,8 +159,14 @@ public function processReminders():void { | |
| $users[] = $user; | ||
| } | ||
|
|
||
| $userPrincipalEmailAddresses = []; | ||
| $userPrincipal = $this->principalConnector->getPrincipalByPath($reminder['principaluri']); | ||
| if ($userPrincipal) { | ||
| $userPrincipalEmailAddresses = $this->principalConnector->getEmailAddressesOfPrincipal($userPrincipal); | ||
| } | ||
|
|
||
| $notificationProvider = $this->notificationProviderManager->getProvider($reminder['type']); | ||
| $notificationProvider->send($vevent, $reminder['displayname'], $users); | ||
| $notificationProvider->send($vevent, $reminder['displayname'], $userPrincipalEmailAddresses, $users); | ||
|
|
||
| $this->deleteOrProcessNext($reminder, $vevent); | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,7 @@ | |
| * @author Joas Schilling <[email protected]> | ||
| * @author Roeland Jago Douma <[email protected]> | ||
| * @author Thomas Citharel <[email protected]> | ||
| * @author Richard Steinmetz <[email protected]> | ||
| * | ||
| * @license GNU AGPL version 3 or any later version | ||
| * | ||
|
|
@@ -45,6 +46,7 @@ | |
| use Sabre\VObject\Component\VCalendar; | ||
| use Sabre\VObject\Component\VEvent; | ||
| use Sabre\VObject\DateTimeParser; | ||
| use Sabre\VObject\Document; | ||
| use Sabre\VObject\FreeBusyGenerator; | ||
| use Sabre\VObject\ITip; | ||
| use Sabre\VObject\Parameter; | ||
|
|
@@ -153,6 +155,14 @@ public function calendarObjectChange(RequestInterface $request, ResponseInterfac | |
| * @inheritDoc | ||
| */ | ||
| public function scheduleLocalDelivery(ITip\Message $iTipMessage):void { | ||
| /** @var Component|null $vevent */ | ||
| $vevent = $iTipMessage->message->VEVENT ?? null; | ||
|
|
||
| // Strip VALARMs from incoming VEVENT | ||
| if ($vevent && isset($vevent->VALARM)) { | ||
| $vevent->remove('VALARM'); | ||
| } | ||
|
|
||
| parent::scheduleLocalDelivery($iTipMessage); | ||
|
|
||
| // We only care when the message was successfully delivered locally | ||
|
|
@@ -189,18 +199,10 @@ public function scheduleLocalDelivery(ITip\Message $iTipMessage):void { | |
| return; | ||
| } | ||
|
|
||
| if (!isset($iTipMessage->message)) { | ||
| if (!$vevent) { | ||
| return; | ||
| } | ||
|
|
||
| $vcalendar = $iTipMessage->message; | ||
| if (!isset($vcalendar->VEVENT)) { | ||
| return; | ||
| } | ||
|
|
||
| /** @var Component $vevent */ | ||
| $vevent = $vcalendar->VEVENT; | ||
|
|
||
| // We don't support autoresponses for recurrencing events for now | ||
| if (isset($vevent->RRULE) || isset($vevent->RDATE)) { | ||
| return; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -81,6 +81,7 @@ protected function setUp(): void { | |
|
|
||
| public function testSendWithoutAttendees():void { | ||
| [$user1, $user2, $user3, , $user5] = $users = $this->getUsers(); | ||
| $principalEmailAddresses = [$user1->getEmailAddress()]; | ||
|
|
||
| $enL10N = $this->createMock(IL10N::class); | ||
| $enL10N->method('t') | ||
|
|
@@ -186,11 +187,12 @@ public function testSendWithoutAttendees():void { | |
| $this->setupURLGeneratorMock(2); | ||
|
|
||
| $vcalendar = $this->getNoAttendeeVCalendar(); | ||
| $this->provider->send($vcalendar->VEVENT, $this->calendarDisplayName, $users); | ||
| $this->provider->send($vcalendar->VEVENT, $this->calendarDisplayName, $principalEmailAddresses, $users); | ||
| } | ||
|
|
||
| public function testSendWithAttendees(): void { | ||
| public function testSendWithAttendeesWhenOwnerIsOrganizer(): void { | ||
| [$user1, $user2, $user3, , $user5] = $users = $this->getUsers(); | ||
| $principalEmailAddresses = [$user1->getEmailAddress()]; | ||
|
|
||
| $enL10N = $this->createMock(IL10N::class); | ||
| $enL10N->method('t') | ||
|
|
@@ -282,7 +284,81 @@ public function testSendWithAttendees(): void { | |
| $this->setupURLGeneratorMock(2); | ||
|
|
||
| $vcalendar = $this->getAttendeeVCalendar(); | ||
| $this->provider->send($vcalendar->VEVENT, $this->calendarDisplayName, $users); | ||
| $this->provider->send($vcalendar->VEVENT, $this->calendarDisplayName, $principalEmailAddresses, $users); | ||
| } | ||
|
|
||
| public function testSendWithAttendeesWhenOwnerIsAttendee(): void { | ||
| [$user1, $user2, $user3] = $this->getUsers(); | ||
| $users = [$user2, $user3]; | ||
| $principalEmailAddresses = [$user2->getEmailAddress()]; | ||
|
|
||
| $deL10N = $this->createMock(IL10N::class); | ||
| $deL10N->method('t') | ||
| ->willReturnArgument(0); | ||
| $deL10N->method('l') | ||
| ->willReturnArgument(0); | ||
|
|
||
| $this->l10nFactory | ||
| ->method('getUserLanguage') | ||
| ->willReturnMap([ | ||
| [$user2, 'de'], | ||
| [$user3, 'de'], | ||
| ]); | ||
|
|
||
| $this->l10nFactory | ||
| ->method('findGenericLanguage') | ||
| ->willReturn('en'); | ||
|
|
||
| $this->l10nFactory | ||
| ->method('languageExists') | ||
| ->willReturnMap([ | ||
| ['dav', 'de', true], | ||
| ]); | ||
|
|
||
| $this->l10nFactory | ||
| ->method('get') | ||
| ->willReturnMap([ | ||
| ['dav', 'de', null, $deL10N], | ||
| ]); | ||
|
|
||
| $template1 = $this->getTemplateMock(); | ||
| $message12 = $this->getMessageMock('[email protected]', $template1); | ||
| $message13 = $this->getMessageMock('[email protected]', $template1); | ||
|
|
||
| $this->mailer->expects(self::once()) | ||
| ->method('createEMailTemplate') | ||
| ->with('dav.calendarReminder') | ||
| ->willReturnOnConsecutiveCalls( | ||
| $template1, | ||
| ); | ||
| $this->mailer->expects($this->atLeastOnce()) | ||
| ->method('validateMailAddress') | ||
| ->willReturnMap([ | ||
| ['[email protected]', true], | ||
| ['[email protected]', true], | ||
| ['[email protected]', true], | ||
| ['[email protected]', true], | ||
| ['[email protected]', true], | ||
| ['[email protected]', true], | ||
| ['invalid', false], | ||
| ]); | ||
| $this->mailer->expects($this->exactly(2)) | ||
| ->method('createMessage') | ||
| ->with() | ||
| ->willReturnOnConsecutiveCalls( | ||
| $message12, | ||
| $message13, | ||
| ); | ||
| $this->mailer->expects($this->exactly(2)) | ||
| ->method('send') | ||
| ->withConsecutive( | ||
| [$message12], | ||
| [$message13], | ||
| )->willReturn([]); | ||
| $this->setupURLGeneratorMock(1); | ||
|
|
||
| $vcalendar = $this->getAttendeeVCalendar(); | ||
| $this->provider->send($vcalendar->VEVENT, $this->calendarDisplayName, $principalEmailAddresses, $users); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -392,6 +468,14 @@ private function getAttendeeVCalendar():VCalendar { | |
| 'DESCRIPTION' => 'DESCRIPTION 456', | ||
| ]); | ||
|
|
||
| $vcalendar->VEVENT->add( | ||
| 'ORGANIZER', | ||
| 'mailto:[email protected]', | ||
| [ | ||
| 'LANG' => 'en' | ||
| ] | ||
| ); | ||
|
|
||
| $vcalendar->VEVENT->add( | ||
| 'ATTENDEE', | ||
| 'mailto:[email protected]', | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.