From 194c4b717e4f43b8033da8afc397a1368b3b1812 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 8 Jan 2019 17:46:07 +0100 Subject: [PATCH] Correctly handle the classification of events in the activity stream Signed-off-by: Joas Schilling --- apps/dav/lib/CalDAV/Activity/Backend.php | 10 +++++++++- apps/dav/lib/CalDAV/Activity/Provider/Event.php | 13 +++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/apps/dav/lib/CalDAV/Activity/Backend.php b/apps/dav/lib/CalDAV/Activity/Backend.php index 9f929dc195..89802c2d6f 100644 --- a/apps/dav/lib/CalDAV/Activity/Backend.php +++ b/apps/dav/lib/CalDAV/Activity/Backend.php @@ -27,6 +27,7 @@ namespace OCA\DAV\CalDAV\Activity; use OCA\DAV\CalDAV\Activity\Provider\Calendar; use OCA\DAV\CalDAV\Activity\Provider\Event; +use OCA\DAV\CalDAV\CalDavBackend; use OCP\Activity\IEvent; use OCP\Activity\IManager as IActivityManager; use OCP\IGroup; @@ -415,6 +416,7 @@ class Backend { $currentUser = $owner; } + $classification = isset($objectData['classification']) ? $objectData['classification'] : CalDavBackend::CLASSIFICATION_PUBLIC; $object = $this->getObjectNameAndType($objectData); $action = $action . '_' . $object['type']; @@ -434,6 +436,11 @@ class Backend { $users[] = $owner; foreach ($users as $user) { + if ($classification === CalDavBackend::CLASSIFICATION_PRIVATE && $user !== $owner) { + // Private events are only shown to the owner + continue; + } + $event->setAffectedUser($user) ->setSubject( $user === $currentUser ? $action . '_self' : $action, @@ -446,7 +453,8 @@ class Backend { ], 'object' => [ 'id' => $object['id'], - 'name' => $object['name'], + 'name' => $classification === CalDavBackend::CLASSIFICATION_CONFIDENTIAL && $user !== $owner ? 'Busy' : $object['name'], + 'classified' => $classification === CalDavBackend::CLASSIFICATION_CONFIDENTIAL && $user !== $owner, ], ] ); diff --git a/apps/dav/lib/CalDAV/Activity/Provider/Event.php b/apps/dav/lib/CalDAV/Activity/Provider/Event.php index f13cb0c266..67b45b3563 100644 --- a/apps/dav/lib/CalDAV/Activity/Provider/Event.php +++ b/apps/dav/lib/CalDAV/Activity/Provider/Event.php @@ -23,6 +23,7 @@ namespace OCA\DAV\CalDAV\Activity\Provider; +use OCA\DAV\CalDAV\CalDavBackend; use OCP\Activity\IEvent; use OCP\Activity\IEventMerger; use OCP\Activity\IManager; @@ -131,14 +132,14 @@ class Event extends Base { return [ 'actor' => $this->generateUserParameter($parameters['actor']), 'calendar' => $this->generateCalendarParameter($parameters['calendar'], $this->l), - 'event' => $this->generateObjectParameter($parameters['object']), + 'event' => $this->generateClassifiedObjectParameter($parameters['object']), ]; case self::SUBJECT_OBJECT_ADD . '_event_self': case self::SUBJECT_OBJECT_DELETE . '_event_self': case self::SUBJECT_OBJECT_UPDATE . '_event_self': return [ 'calendar' => $this->generateCalendarParameter($parameters['calendar'], $this->l), - 'event' => $this->generateObjectParameter($parameters['object']), + 'event' => $this->generateClassifiedObjectParameter($parameters['object']), ]; } } @@ -168,4 +169,12 @@ class Event extends Base { throw new \InvalidArgumentException(); } + + private function generateClassifiedObjectParameter(array $eventData) { + $parameter = $this->generateObjectParameter($eventData); + if ($eventData['classified']) { + $parameter['name'] = $this->l->t('Busy'); + } + return $parameter; + } }