diff options
author | Thomas Citharel <tcit@tcit.fr> | 2020-01-21 10:32:48 +0100 |
---|---|---|
committer | Thomas Citharel <tcit@tcit.fr> | 2020-04-26 11:11:50 +0200 |
commit | deb2ea9cead3dbf428877faed5136fe73198b6c7 (patch) | |
tree | 603142da0bedb9d90cae4a23592be498db78822c /apps/dav/lib | |
parent | 0eeb6606796260bc3e0da3f2e6deb3a7cc522c3c (diff) | |
download | nextcloud-server-deb2ea9cead3dbf428877faed5136fe73198b6c7.tar.gz nextcloud-server-deb2ea9cead3dbf428877faed5136fe73198b6c7.zip |
Provide links to calendar in event creation/update activities
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
Diffstat (limited to 'apps/dav/lib')
-rw-r--r-- | apps/dav/lib/CalDAV/Activity/Backend.php | 61 | ||||
-rw-r--r-- | apps/dav/lib/CalDAV/Activity/Provider/Base.php | 25 | ||||
-rw-r--r-- | apps/dav/lib/CalDAV/Activity/Provider/Calendar.php | 6 | ||||
-rw-r--r-- | apps/dav/lib/CalDAV/Activity/Provider/Event.php | 52 |
4 files changed, 91 insertions, 53 deletions
diff --git a/apps/dav/lib/CalDAV/Activity/Backend.php b/apps/dav/lib/CalDAV/Activity/Backend.php index 4ca5ad17aeb..8daa9d2409f 100644 --- a/apps/dav/lib/CalDAV/Activity/Backend.php +++ b/apps/dav/lib/CalDAV/Activity/Backend.php @@ -30,6 +30,7 @@ use OCA\DAV\CalDAV\Activity\Provider\Event; use OCA\DAV\CalDAV\CalDavBackend; use OCP\Activity\IEvent; use OCP\Activity\IManager as IActivityManager; +use OCP\App\IAppManager; use OCP\IGroup; use OCP\IGroupManager; use OCP\IUser; @@ -52,15 +53,14 @@ class Backend { /** @var IUserSession */ protected $userSession; - /** - * @param IActivityManager $activityManager - * @param IGroupManager $groupManager - * @param IUserSession $userSession - */ - public function __construct(IActivityManager $activityManager, IGroupManager $groupManager, IUserSession $userSession) { + /** @var IAppManager */ + protected $appManager; + + public function __construct(IActivityManager $activityManager, IGroupManager $groupManager, IUserSession $userSession, IAppManager $appManager) { $this->activityManager = $activityManager; $this->groupManager = $groupManager; $this->userSession = $userSession; + $this->appManager = $appManager; } /** @@ -435,29 +435,40 @@ class Backend { $users = $this->getUsersForShares($shares); $users[] = $owner; - foreach ($users as $user) { + // Users for share can return the owner itself if the calendar is published + foreach (array_unique($users) as $user) { if ($classification === CalDavBackend::CLASSIFICATION_PRIVATE && $user !== $owner) { // Private events are only shown to the owner continue; } + $params = [ + 'actor' => $event->getAuthor(), + 'calendar' => [ + 'id' => (int) $calendarData['id'], + 'uri' => $calendarData['uri'], + 'name' => $calendarData['{DAV:}displayname'], + ], + 'object' => [ + 'id' => $object['id'], + 'name' => $classification === CalDavBackend::CLASSIFICATION_CONFIDENTIAL && $user !== $owner ? 'Busy' : $object['name'], + 'classified' => $classification === CalDavBackend::CLASSIFICATION_CONFIDENTIAL && $user !== $owner, + ], + ]; + + if ($object['type'] === 'event' && strpos($action, Event::SUBJECT_OBJECT_DELETE) === false && $this->appManager->isEnabledForUser('calendar')) { + $params['object']['link']['object_uri'] = $objectData['uri']; + $params['object']['link']['calendar_uri'] = $calendarData['uri']; + $params['object']['link']['owner'] = $owner; + } + + $event->setAffectedUser($user) ->setSubject( $user === $currentUser ? $action . '_self' : $action, - [ - 'actor' => $event->getAuthor(), - 'calendar' => [ - 'id' => (int) $calendarData['id'], - 'uri' => $calendarData['uri'], - 'name' => $calendarData['{DAV:}displayname'], - ], - 'object' => [ - 'id' => $object['id'], - 'name' => $classification === CalDavBackend::CLASSIFICATION_CONFIDENTIAL && $user !== $owner ? 'Busy' : $object['name'], - 'classified' => $classification === CalDavBackend::CLASSIFICATION_CONFIDENTIAL && $user !== $owner, - ], - ] + $params ); + $this->activityManager->publish($event); } } @@ -496,11 +507,11 @@ class Backend { protected function getUsersForShares(array $shares) { $users = $groups = []; foreach ($shares as $share) { - $prinical = explode('/', $share['{http://owncloud.org/ns}principal']); - if ($prinical[1] === 'users') { - $users[] = $prinical[2]; - } elseif ($prinical[1] === 'groups') { - $groups[] = $prinical[2]; + $principal = explode('/', $share['{http://owncloud.org/ns}principal']); + if ($principal[1] === 'users') { + $users[] = $principal[2]; + } elseif ($principal[1] === 'groups') { + $groups[] = $principal[2]; } } diff --git a/apps/dav/lib/CalDAV/Activity/Provider/Base.php b/apps/dav/lib/CalDAV/Activity/Provider/Base.php index 00ad1aec594..bc6e7a6cca0 100644 --- a/apps/dav/lib/CalDAV/Activity/Provider/Base.php +++ b/apps/dav/lib/CalDAV/Activity/Provider/Base.php @@ -3,6 +3,7 @@ * @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com> * * @author Joas Schilling <coding@schilljs.com> + * @author Thomas Citharel <nextcloud@tcit.fr> * * @license GNU AGPL version 3 or any later version * @@ -29,6 +30,7 @@ use OCP\Activity\IProvider; use OCP\IGroup; use OCP\IGroupManager; use OCP\IL10N; +use OCP\IURLGenerator; use OCP\IUser; use OCP\IUserManager; @@ -46,13 +48,18 @@ abstract class Base implements IProvider { /** @var string[] */ protected $groupDisplayNames = []; + /** @var IURLGenerator */ + protected $url; + /** * @param IUserManager $userManager * @param IGroupManager $groupManager + * @param IURLGenerator $urlGenerator */ - public function __construct(IUserManager $userManager, IGroupManager $groupManager) { + public function __construct(IUserManager $userManager, IGroupManager $groupManager, IURLGenerator $urlGenerator) { $this->userManager = $userManager; $this->groupManager = $groupManager; + $this->url = $urlGenerator; } /** @@ -72,22 +79,6 @@ abstract class Base implements IProvider { } /** - * @param array $eventData - * @return array - */ - protected function generateObjectParameter($eventData) { - if (!is_array($eventData) || !isset($eventData['id']) || !isset($eventData['name'])) { - throw new \InvalidArgumentException(); - } - - return [ - 'type' => 'calendar-event', - 'id' => $eventData['id'], - 'name' => $eventData['name'], - ]; - } - - /** * @param array $data * @param IL10N $l * @return array diff --git a/apps/dav/lib/CalDAV/Activity/Provider/Calendar.php b/apps/dav/lib/CalDAV/Activity/Provider/Calendar.php index ee0d6144c92..61f100733a3 100644 --- a/apps/dav/lib/CalDAV/Activity/Provider/Calendar.php +++ b/apps/dav/lib/CalDAV/Activity/Provider/Calendar.php @@ -52,9 +52,6 @@ class Calendar extends Base { /** @var IL10N */ protected $l; - /** @var IURLGenerator */ - protected $url; - /** @var IManager */ protected $activityManager; @@ -70,9 +67,8 @@ class Calendar extends Base { * @param IEventMerger $eventMerger */ public function __construct(IFactory $languageFactory, IURLGenerator $url, IManager $activityManager, IUserManager $userManager, IGroupManager $groupManager, IEventMerger $eventMerger) { - parent::__construct($userManager, $groupManager); + parent::__construct($userManager, $groupManager, $url); $this->languageFactory = $languageFactory; - $this->url = $url; $this->activityManager = $activityManager; $this->eventMerger = $eventMerger; } diff --git a/apps/dav/lib/CalDAV/Activity/Provider/Event.php b/apps/dav/lib/CalDAV/Activity/Provider/Event.php index 9ca0727fab7..8e04543379d 100644 --- a/apps/dav/lib/CalDAV/Activity/Provider/Event.php +++ b/apps/dav/lib/CalDAV/Activity/Provider/Event.php @@ -4,6 +4,7 @@ * * @author Joas Schilling <coding@schilljs.com> * @author Julius Härtl <jus@bitgrid.net> + * @author Thomas Citharel <nextcloud@tcit.fr> * * @license GNU AGPL version 3 or any later version * @@ -24,9 +25,11 @@ namespace OCA\DAV\CalDAV\Activity\Provider; +use OC_App; use OCP\Activity\IEvent; use OCP\Activity\IEventMerger; use OCP\Activity\IManager; +use OCP\App\IAppManager; use OCP\IGroupManager; use OCP\IL10N; use OCP\IURLGenerator; @@ -44,15 +47,15 @@ class Event extends Base { /** @var IL10N */ protected $l; - /** @var IURLGenerator */ - protected $url; - /** @var IManager */ protected $activityManager; /** @var IEventMerger */ protected $eventMerger; + /** @var IAppManager */ + protected $appManager; + /** * @param IFactory $languageFactory * @param IURLGenerator $url @@ -60,13 +63,50 @@ class Event extends Base { * @param IUserManager $userManager * @param IGroupManager $groupManager * @param IEventMerger $eventMerger + * @param IAppManager $appManager */ - public function __construct(IFactory $languageFactory, IURLGenerator $url, IManager $activityManager, IUserManager $userManager, IGroupManager $groupManager, IEventMerger $eventMerger) { - parent::__construct($userManager, $groupManager); + public function __construct(IFactory $languageFactory, IURLGenerator $url, IManager $activityManager, IUserManager $userManager, IGroupManager $groupManager, IEventMerger $eventMerger, IAppManager $appManager) { + parent::__construct($userManager, $groupManager, $url); $this->languageFactory = $languageFactory; - $this->url = $url; $this->activityManager = $activityManager; $this->eventMerger = $eventMerger; + $this->appManager = $appManager; + } + + /** + * @param array $eventData + * @return array + */ + protected function generateObjectParameter(array $eventData) { + if (!isset($eventData['id']) || !isset($eventData['name'])) { + throw new \InvalidArgumentException(); + } + + $params = [ + 'type' => 'calendar-event', + 'id' => $eventData['id'], + 'name' => $eventData['name'], + + ]; + if (isset($eventData['link']) && is_array($eventData['link']) && $this->appManager->isEnabledForUser('calendar')) { + try { + // The calendar app needs to be manually loaded for the routes to be loaded + OC_App::loadApp('calendar'); + $linkData = $eventData['link']; + $objectId = base64_encode('/remote.php/dav/calendars/' . $linkData['owner'] . '/' . $linkData['calendar_uri'] . '/' . $linkData['object_uri']); + $link = [ + 'view' => 'dayGridMonth', + 'timeRange' => 'now', + 'mode' => 'sidebar', + 'objectId' => $objectId, + 'recurrenceId' => 'next' + ]; + $params['link'] = $this->url->linkToRouteAbsolute('calendar.view.indexview.timerange.edit', $link); + } catch (\Exception $error) { + // Do nothing + } + } + return $params; } /** |