summaryrefslogtreecommitdiffstats
path: root/apps/dav/lib
diff options
context:
space:
mode:
authorRoeland Jago Douma <rullzer@users.noreply.github.com>2020-04-30 09:10:56 +0200
committerGitHub <noreply@github.com>2020-04-30 09:10:56 +0200
commita1f3293c06648f6b3c36353edb4a04794fabbba9 (patch)
tree4fef57e3ba9a76f35219302704b6881b43a9b67b /apps/dav/lib
parenta1c1b354fcb79153a78a658b758acd514089c9e1 (diff)
parentdeb2ea9cead3dbf428877faed5136fe73198b6c7 (diff)
downloadnextcloud-server-a1f3293c06648f6b3c36353edb4a04794fabbba9.tar.gz
nextcloud-server-a1f3293c06648f6b3c36353edb4a04794fabbba9.zip
Merge pull request #19039 from nextcloud/dav-activity-provide-links-to-calendar
Provide links to calendar in event creation/update activities
Diffstat (limited to 'apps/dav/lib')
-rw-r--r--apps/dav/lib/CalDAV/Activity/Backend.php61
-rw-r--r--apps/dav/lib/CalDAV/Activity/Provider/Base.php25
-rw-r--r--apps/dav/lib/CalDAV/Activity/Provider/Calendar.php6
-rw-r--r--apps/dav/lib/CalDAV/Activity/Provider/Event.php52
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 d4bdd02b1c6..16f581db872 100644
--- a/apps/dav/lib/CalDAV/Activity/Backend.php
+++ b/apps/dav/lib/CalDAV/Activity/Backend.php
@@ -31,6 +31,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;
@@ -53,15 +54,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;
}
/**
@@ -436,29 +436,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);
}
}
@@ -497,11 +508,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 ab9a905d937..7e762b4c088 100644
--- a/apps/dav/lib/CalDAV/Activity/Provider/Calendar.php
+++ b/apps/dav/lib/CalDAV/Activity/Provider/Calendar.php
@@ -53,9 +53,6 @@ class Calendar extends Base {
/** @var IL10N */
protected $l;
- /** @var IURLGenerator */
- protected $url;
-
/** @var IManager */
protected $activityManager;
@@ -71,9 +68,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 5a698b98be6..4aa2c8c0b0e 100644
--- a/apps/dav/lib/CalDAV/Activity/Provider/Event.php
+++ b/apps/dav/lib/CalDAV/Activity/Provider/Event.php
@@ -5,6 +5,7 @@
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
* @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
*
@@ -25,9 +26,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;
@@ -45,15 +48,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
@@ -61,13 +64,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;
}
/**