Skip to content

Commit e266666

Browse files
authored
Merge pull request #20188 from nextcloud/bug/19662/add-default-title-for-event-in-invitatios
Add default titles for titleless events in invitations
2 parents 50ad706 + 058ffa3 commit e266666

2 files changed

Lines changed: 53 additions & 6 deletions

File tree

apps/dav/lib/CalDAV/Schedule/IMipPlugin.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
use OCP\Mail\IEMailTemplate;
4444
use OCP\Mail\IMailer;
4545
use OCP\Security\ISecureRandom;
46+
use OCP\Util;
4647
use Sabre\CalDAV\Schedule\IMipPlugin as SabreIMipPlugin;
4748
use Sabre\VObject\Component\VCalendar;
4849
use Sabre\VObject\Component\VEvent;
@@ -246,7 +247,7 @@ public function schedule(Message $iTipMessage) {
246247
'meeting_url' => (string)$meetingUrl ?: $defaultVal,
247248
];
248249

249-
$fromEMail = \OCP\Util::getDefaultEmailAddress('invitations-noreply');
250+
$fromEMail = Util::getDefaultEmailAddress('invitations-noreply');
250251
$fromName = $l10n->t('%1$s via %2$s', [$senderName, $this->defaults->getName()]);
251252

252253
$message = $this->mailer->createMessage()
@@ -257,6 +258,8 @@ public function schedule(Message $iTipMessage) {
257258
$template = $this->mailer->createEMailTemplate('dav.calendarInvite.' . $method, $data);
258259
$template->addHeader();
259260

261+
$summary = ((string) $summary !== '') ? (string) $summary : $l10n->t('Untitled event');
262+
260263
$this->addSubjectAndHeading($template, $l10n, $method, $summary,
261264
$meetingAttendeeName, $meetingInviteeName);
262265
$this->addBulletList($template, $l10n, $meetingWhen, $meetingLocation,

apps/dav/tests/unit/CalDAV/Schedule/IMipPluginTest.php

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,40 @@
4646
use OCP\Mail\IMailer;
4747
use OCP\Mail\IMessage;
4848
use OCP\Security\ISecureRandom;
49+
use PHPUnit\Framework\MockObject\MockObject;
4950
use Sabre\VObject\Component\VCalendar;
5051
use Sabre\VObject\ITip\Message;
5152
use Test\TestCase;
5253

5354
class IMipPluginTest extends TestCase {
5455

56+
/** @var IMessage|MockObject */
57+
private $mailMessage;
58+
59+
/** @var IMailer|MockObject */
60+
private $mailer;
61+
62+
/** @var IEMailTemplate|MockObject */
63+
private $emailTemplate;
64+
65+
/** @var IAttachment|MockObject */
66+
private $emailAttachment;
67+
68+
/** @var ITimeFactory|MockObject */
69+
private $timeFactory;
70+
71+
/** @var IConfig|MockObject */
72+
private $config;
73+
74+
/** @var IUserManager|MockObject */
75+
private $userManager;
76+
77+
/** @var IQueryBuilder|MockObject */
78+
private $queryBuilder;
79+
80+
/** @var IMipPlugin */
81+
private $plugin;
82+
5583
protected function setUp(): void {
5684
$this->mailMessage = $this->createMock(IMessage::class);
5785
$this->mailMessage->method('setFrom')->willReturn($this->mailMessage);
@@ -67,6 +95,7 @@ protected function setUp(): void {
6795
$this->emailAttachment = $this->createMock(IAttachment::class);
6896
$this->mailer->method('createAttachment')->willReturn($this->emailAttachment);
6997

98+
/** @var ILogger|MockObject $logger */
7099
$logger = $this->getMockBuilder(ILogger::class)->disableOriginalConstructor()->getMock();
71100

72101
$this->timeFactory = $this->getMockBuilder(ITimeFactory::class)->disableOriginalConstructor()->getMock();
@@ -156,7 +185,7 @@ public function testDeliveryWithNoCommonName() {
156185
/**
157186
* @dataProvider dataNoMessageSendForPastEvents
158187
*/
159-
public function testNoMessageSendForPastEvents($veventParams, $expectsMail) {
188+
public function testNoMessageSendForPastEvents(array $veventParams, bool $expectsMail) {
160189

161190
$this->config
162191
->method('getAppValue')
@@ -194,7 +223,7 @@ public function dataNoMessageSendForPastEvents() {
194223
/**
195224
* @dataProvider dataIncludeResponseButtons
196225
*/
197-
public function testIncludeResponseButtons( $config_setting, $recipient, $has_buttons ) {
226+
public function testIncludeResponseButtons(string $config_setting, string $recipient, bool $has_buttons ) {
198227
$message = $this->_testMessage([],$recipient);
199228

200229
$this->_expectSend($recipient, true, $has_buttons);
@@ -220,7 +249,22 @@ public function dataIncludeResponseButtons() {
220249
];
221250
}
222251

223-
private function _testMessage($attrs = [], $recipient = '[email protected]' ) {
252+
public function testMessageSendWhenEventWithoutName() {
253+
$this->config
254+
->method('getAppValue')
255+
->with('dav', 'invitation_link_recipients', 'yes')
256+
->willReturn('yes');
257+
258+
$message = $this->_testMessage(['SUMMARY' => '']);
259+
$this->_expectSend('[email protected]', true, true,'Invitation: Untitled event');
260+
$this->emailTemplate->expects($this->once())
261+
->method('addHeading')
262+
->with('Mr. Wizard invited you to »Untitled event«');
263+
$this->plugin->schedule($message);
264+
$this->assertEquals('1.1', $message->getScheduleStatus());
265+
}
266+
267+
private function _testMessage(array $attrs = [], string $recipient = '[email protected]' ) {
224268
$message = new Message();
225269
$message->method = 'REQUEST';
226270
$message->message = new VCalendar();
@@ -239,7 +283,7 @@ private function _testMessage($attrs = [], $recipient = '[email protected]' ) {
239283
}
240284

241285

242-
private function _expectSend( $recipient = '[email protected]', $expectSend = true, $expectButtons = true ) {
286+
private function _expectSend(string $recipient = '[email protected]', bool $expectSend = true, bool $expectButtons = true, string $subject = 'Invitation: Fellowship meeting') {
243287

244288
// if the event is in the past, we skip out
245289
if (!$expectSend) {
@@ -251,7 +295,7 @@ private function _expectSend( $recipient = '[email protected]', $expectSend = true,
251295

252296
$this->emailTemplate->expects($this->once())
253297
->method('setSubject')
254-
->with('Invitation: Fellowship meeting');
298+
->with($subject);
255299
$this->mailMessage->expects($this->once())
256300
->method('setTo')
257301
->with([$recipient => null]);

0 commit comments

Comments
 (0)