Merge pull request #6590 from nextcloud/dav-create-activities-for-publishing
Create activities for (un)publishing calendar events
This commit is contained in:
commit
ba3c608a00
5 changed files with 57 additions and 0 deletions
|
@ -178,6 +178,15 @@ class Application extends App {
|
|||
);
|
||||
});
|
||||
|
||||
$dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::publishCalendar', function(GenericEvent $event) {
|
||||
/** @var Backend $backend */
|
||||
$backend = $this->getContainer()->query(Backend::class);
|
||||
$backend->onCalendarPublication(
|
||||
$event->getArgument('calendarData'),
|
||||
$event->getArgument('public')
|
||||
);
|
||||
});
|
||||
|
||||
$listener = function(GenericEvent $event, $eventName) {
|
||||
/** @var Backend $backend */
|
||||
$backend = $this->getContainer()->query(Backend::class);
|
||||
|
|
|
@ -92,6 +92,16 @@ class Backend {
|
|||
$this->triggerCalendarActivity(Calendar::SUBJECT_DELETE, $calendarData, $shares);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates activities when a calendar was (un)published
|
||||
*
|
||||
* @param array $calendarData
|
||||
* @param bool $publishStatus
|
||||
*/
|
||||
public function onCalendarPublication(array $calendarData, $publishStatus) {
|
||||
$this->triggerCalendarActivity($publishStatus ? Calendar::SUBJECT_PUBLISH : Calendar::SUBJECT_UNPUBLISH, $calendarData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates activities for all related users when a calendar was touched
|
||||
*
|
||||
|
|
|
@ -36,6 +36,8 @@ class Calendar extends Base {
|
|||
const SUBJECT_ADD = 'calendar_add';
|
||||
const SUBJECT_UPDATE = 'calendar_update';
|
||||
const SUBJECT_DELETE = 'calendar_delete';
|
||||
const SUBJECT_PUBLISH = 'calendar_publish';
|
||||
const SUBJECT_UNPUBLISH = 'calendar_unpublish';
|
||||
const SUBJECT_SHARE_USER = 'calendar_user_share';
|
||||
const SUBJECT_SHARE_GROUP = 'calendar_group_share';
|
||||
const SUBJECT_UNSHARE_USER = 'calendar_user_unshare';
|
||||
|
@ -105,6 +107,11 @@ class Calendar extends Base {
|
|||
} else if ($event->getSubject() === self::SUBJECT_UPDATE . '_self') {
|
||||
$subject = $this->l->t('You updated calendar {calendar}');
|
||||
|
||||
} else if ($event->getSubject() === self::SUBJECT_PUBLISH . '_self') {
|
||||
$subject = $this->l->t('You shared calendar {calendar} as public link');
|
||||
} else if ($event->getSubject() === self::SUBJECT_UNPUBLISH . '_self') {
|
||||
$subject = $this->l->t('You removed public link for calendar {calendar}');
|
||||
|
||||
} else if ($event->getSubject() === self::SUBJECT_SHARE_USER) {
|
||||
$subject = $this->l->t('{actor} shared calendar {calendar} with you');
|
||||
} else if ($event->getSubject() === self::SUBJECT_SHARE_USER . '_you') {
|
||||
|
@ -215,6 +222,8 @@ class Calendar extends Base {
|
|||
case self::SUBJECT_DELETE . '_self':
|
||||
case self::SUBJECT_UPDATE:
|
||||
case self::SUBJECT_UPDATE . '_self':
|
||||
case self::SUBJECT_PUBLISH . '_self':
|
||||
case self::SUBJECT_UNPUBLISH . '_self':
|
||||
case self::SUBJECT_SHARE_USER:
|
||||
case self::SUBJECT_UNSHARE_USER:
|
||||
case self::SUBJECT_UNSHARE_USER . '_self':
|
||||
|
|
|
@ -2151,6 +2151,16 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
|
|||
* @return string|null
|
||||
*/
|
||||
public function setPublishStatus($value, $calendar) {
|
||||
|
||||
$calendarId = $calendar->getResourceId();
|
||||
$this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::publishCalendar', new GenericEvent(
|
||||
'\OCA\DAV\CalDAV\CalDavBackend::updateShares',
|
||||
[
|
||||
'calendarId' => $calendarId,
|
||||
'calendarData' => $this->getCalendarById($calendarId),
|
||||
'public' => $value,
|
||||
]));
|
||||
|
||||
$query = $this->db->getQueryBuilder();
|
||||
if ($value) {
|
||||
$publicUri = $this->random->generate(16, ISecureRandom::CHAR_HUMAN_READABLE);
|
||||
|
|
|
@ -79,6 +79,7 @@ class BackendTest extends TestCase {
|
|||
['onCalendarAdd', [['data']], Calendar::SUBJECT_ADD, [['data'], [], []]],
|
||||
['onCalendarUpdate', [['data'], ['shares'], ['changed-properties']], Calendar::SUBJECT_UPDATE, [['data'], ['shares'], ['changed-properties']]],
|
||||
['onCalendarDelete', [['data'], ['shares']], Calendar::SUBJECT_DELETE, [['data'], ['shares'], []]],
|
||||
['onCalendarPublication', [['data'], true], Calendar::SUBJECT_PUBLISH, [['data'], [], []]],
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -163,6 +164,24 @@ class BackendTest extends TestCase {
|
|||
'uri' => 'this-uri',
|
||||
'{DAV:}displayname' => 'Name of calendar',
|
||||
], ['shares'], [], 'test2', 'test2', ['user1'], ['user1', 'admin']],
|
||||
|
||||
// Publish calendar
|
||||
[Calendar::SUBJECT_PUBLISH, [], [], [], '', '', null, []],
|
||||
[Calendar::SUBJECT_PUBLISH, [
|
||||
'principaluri' => 'principal/user/admin',
|
||||
'id' => 42,
|
||||
'uri' => 'this-uri',
|
||||
'{DAV:}displayname' => 'Name of calendar',
|
||||
], ['shares'], [], '', 'admin', [], ['admin']],
|
||||
|
||||
// Unpublish calendar
|
||||
[Calendar::SUBJECT_UNPUBLISH, [], [], [], '', '', null, []],
|
||||
[Calendar::SUBJECT_UNPUBLISH, [
|
||||
'principaluri' => 'principal/user/admin',
|
||||
'id' => 42,
|
||||
'uri' => 'this-uri',
|
||||
'{DAV:}displayname' => 'Name of calendar',
|
||||
], ['shares'], [], '', 'admin', [], ['admin']],
|
||||
];
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue