Skip to content

Commit ba3c608

Browse files
authored
Merge pull request #6590 from nextcloud/dav-create-activities-for-publishing
Create activities for (un)publishing calendar events
2 parents 4fc8984 + effde61 commit ba3c608

File tree

5 files changed

+57
-0
lines changed

5 files changed

+57
-0
lines changed

apps/dav/lib/AppInfo/Application.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,15 @@ public function registerHooks() {
178178
);
179179
});
180180

181+
$dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::publishCalendar', function(GenericEvent $event) {
182+
/** @var Backend $backend */
183+
$backend = $this->getContainer()->query(Backend::class);
184+
$backend->onCalendarPublication(
185+
$event->getArgument('calendarData'),
186+
$event->getArgument('public')
187+
);
188+
});
189+
181190
$listener = function(GenericEvent $event, $eventName) {
182191
/** @var Backend $backend */
183192
$backend = $this->getContainer()->query(Backend::class);

apps/dav/lib/CalDAV/Activity/Backend.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,16 @@ public function onCalendarDelete(array $calendarData, array $shares) {
9292
$this->triggerCalendarActivity(Calendar::SUBJECT_DELETE, $calendarData, $shares);
9393
}
9494

95+
/**
96+
* Creates activities when a calendar was (un)published
97+
*
98+
* @param array $calendarData
99+
* @param bool $publishStatus
100+
*/
101+
public function onCalendarPublication(array $calendarData, $publishStatus) {
102+
$this->triggerCalendarActivity($publishStatus ? Calendar::SUBJECT_PUBLISH : Calendar::SUBJECT_UNPUBLISH, $calendarData);
103+
}
104+
95105
/**
96106
* Creates activities for all related users when a calendar was touched
97107
*

apps/dav/lib/CalDAV/Activity/Provider/Calendar.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ class Calendar extends Base {
3636
const SUBJECT_ADD = 'calendar_add';
3737
const SUBJECT_UPDATE = 'calendar_update';
3838
const SUBJECT_DELETE = 'calendar_delete';
39+
const SUBJECT_PUBLISH = 'calendar_publish';
40+
const SUBJECT_UNPUBLISH = 'calendar_unpublish';
3941
const SUBJECT_SHARE_USER = 'calendar_user_share';
4042
const SUBJECT_SHARE_GROUP = 'calendar_group_share';
4143
const SUBJECT_UNSHARE_USER = 'calendar_user_unshare';
@@ -105,6 +107,11 @@ public function parse($language, IEvent $event, IEvent $previousEvent = null) {
105107
} else if ($event->getSubject() === self::SUBJECT_UPDATE . '_self') {
106108
$subject = $this->l->t('You updated calendar {calendar}');
107109

110+
} else if ($event->getSubject() === self::SUBJECT_PUBLISH . '_self') {
111+
$subject = $this->l->t('You shared calendar {calendar} as public link');
112+
} else if ($event->getSubject() === self::SUBJECT_UNPUBLISH . '_self') {
113+
$subject = $this->l->t('You removed public link for calendar {calendar}');
114+
108115
} else if ($event->getSubject() === self::SUBJECT_SHARE_USER) {
109116
$subject = $this->l->t('{actor} shared calendar {calendar} with you');
110117
} else if ($event->getSubject() === self::SUBJECT_SHARE_USER . '_you') {
@@ -215,6 +222,8 @@ protected function getParameters(IEvent $event) {
215222
case self::SUBJECT_DELETE . '_self':
216223
case self::SUBJECT_UPDATE:
217224
case self::SUBJECT_UPDATE . '_self':
225+
case self::SUBJECT_PUBLISH . '_self':
226+
case self::SUBJECT_UNPUBLISH . '_self':
218227
case self::SUBJECT_SHARE_USER:
219228
case self::SUBJECT_UNSHARE_USER:
220229
case self::SUBJECT_UNSHARE_USER . '_self':

apps/dav/lib/CalDAV/CalDavBackend.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2151,6 +2151,16 @@ public function getShares($resourceId) {
21512151
* @return string|null
21522152
*/
21532153
public function setPublishStatus($value, $calendar) {
2154+
2155+
$calendarId = $calendar->getResourceId();
2156+
$this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::publishCalendar', new GenericEvent(
2157+
'\OCA\DAV\CalDAV\CalDavBackend::updateShares',
2158+
[
2159+
'calendarId' => $calendarId,
2160+
'calendarData' => $this->getCalendarById($calendarId),
2161+
'public' => $value,
2162+
]));
2163+
21542164
$query = $this->db->getQueryBuilder();
21552165
if ($value) {
21562166
$publicUri = $this->random->generate(16, ISecureRandom::CHAR_HUMAN_READABLE);

apps/dav/tests/unit/CalDAV/Activity/BackendTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ public function dataCallTriggerCalendarActivity() {
7979
['onCalendarAdd', [['data']], Calendar::SUBJECT_ADD, [['data'], [], []]],
8080
['onCalendarUpdate', [['data'], ['shares'], ['changed-properties']], Calendar::SUBJECT_UPDATE, [['data'], ['shares'], ['changed-properties']]],
8181
['onCalendarDelete', [['data'], ['shares']], Calendar::SUBJECT_DELETE, [['data'], ['shares'], []]],
82+
['onCalendarPublication', [['data'], true], Calendar::SUBJECT_PUBLISH, [['data'], [], []]],
8283
];
8384
}
8485

@@ -163,6 +164,24 @@ public function dataTriggerCalendarActivity() {
163164
'uri' => 'this-uri',
164165
'{DAV:}displayname' => 'Name of calendar',
165166
], ['shares'], [], 'test2', 'test2', ['user1'], ['user1', 'admin']],
167+
168+
// Publish calendar
169+
[Calendar::SUBJECT_PUBLISH, [], [], [], '', '', null, []],
170+
[Calendar::SUBJECT_PUBLISH, [
171+
'principaluri' => 'principal/user/admin',
172+
'id' => 42,
173+
'uri' => 'this-uri',
174+
'{DAV:}displayname' => 'Name of calendar',
175+
], ['shares'], [], '', 'admin', [], ['admin']],
176+
177+
// Unpublish calendar
178+
[Calendar::SUBJECT_UNPUBLISH, [], [], [], '', '', null, []],
179+
[Calendar::SUBJECT_UNPUBLISH, [
180+
'principaluri' => 'principal/user/admin',
181+
'id' => 42,
182+
'uri' => 'this-uri',
183+
'{DAV:}displayname' => 'Name of calendar',
184+
], ['shares'], [], '', 'admin', [], ['admin']],
166185
];
167186
}
168187

0 commit comments

Comments
 (0)