Skip to content

Commit 558b36d

Browse files
committed
Add default titles for titleless events in invitations
Closes #19662 Signed-off-by: Thomas Citharel <[email protected]>
1 parent 62403d0 commit 558b36d

2 files changed

Lines changed: 53 additions & 7 deletions

File tree

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

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

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

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

260+
$summary = ((string) $summary !== '') ? (string) $summary : $l10n->t('Event without name');
261+
259262
$this->addSubjectAndHeading($template, $l10n, $method, $summary,
260263
$meetingAttendeeName, $meetingInviteeName);
261264
$this->addBulletList($template, $l10n, $meetingWhen, $meetingLocation,

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

Lines changed: 49 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828

2929
namespace OCA\DAV\Tests\unit\CalDAV\Schedule;
3030

31-
use OC\Mail\Mailer;
3231
use OCA\DAV\CalDAV\Schedule\IMipPlugin;
3332
use OCP\AppFramework\Utility\ITimeFactory;
3433
use OCP\DB\QueryBuilder\IQueryBuilder;
@@ -46,12 +45,40 @@
4645
use OCP\Mail\IMailer;
4746
use OCP\Mail\IMessage;
4847
use OCP\Security\ISecureRandom;
48+
use PHPUnit\Framework\MockObject\MockObject;
4949
use Sabre\VObject\Component\VCalendar;
5050
use Sabre\VObject\ITip\Message;
5151
use Test\TestCase;
5252

5353
class IMipPluginTest extends TestCase {
5454

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

97+
/** @var ILogger|MockObject $logger */
7098
$logger = $this->getMockBuilder(ILogger::class)->disableOriginalConstructor()->getMock();
7199

72100
$this->timeFactory = $this->getMockBuilder(ITimeFactory::class)->disableOriginalConstructor()->getMock();
@@ -156,7 +184,7 @@ public function testDeliveryWithNoCommonName() {
156184
/**
157185
* @dataProvider dataNoMessageSendForPastEvents
158186
*/
159-
public function testNoMessageSendForPastEvents($veventParams, $expectsMail) {
187+
public function testNoMessageSendForPastEvents(array $veventParams, bool $expectsMail) {
160188

161189
$this->config
162190
->method('getAppValue')
@@ -194,7 +222,7 @@ public function dataNoMessageSendForPastEvents() {
194222
/**
195223
* @dataProvider dataIncludeResponseButtons
196224
*/
197-
public function testIncludeResponseButtons( $config_setting, $recipient, $has_buttons ) {
225+
public function testIncludeResponseButtons(string $config_setting, string $recipient, bool $has_buttons ) {
198226
$message = $this->_testMessage([],$recipient);
199227

200228
$this->_expectSend($recipient, true, $has_buttons);
@@ -220,7 +248,22 @@ public function dataIncludeResponseButtons() {
220248
];
221249
}
222250

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

241284

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

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

252295
$this->emailTemplate->expects($this->once())
253296
->method('setSubject')
254-
->with('Invitation: Fellowship meeting');
297+
->with($subject);
255298
$this->mailMessage->expects($this->once())
256299
->method('setTo')
257300
->with([$recipient => null]);

0 commit comments

Comments
 (0)