aboutsummaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
Diffstat (limited to 'apps')
-rw-r--r--apps/dav/lib/CalDAV/Activity.php17
-rw-r--r--apps/dav/lib/CalDAV/CalDavBackend.php90
2 files changed, 100 insertions, 7 deletions
diff --git a/apps/dav/lib/CalDAV/Activity.php b/apps/dav/lib/CalDAV/Activity.php
index d42e9704a88..b551a5f9309 100644
--- a/apps/dav/lib/CalDAV/Activity.php
+++ b/apps/dav/lib/CalDAV/Activity.php
@@ -38,6 +38,8 @@ class Activity implements IExtension {
const SUBJECT_ADD = 'calendar_add';
const SUBJECT_UPDATE = 'calendar_update';
const SUBJECT_DELETE = 'calendar_delete';
+ const SUBJECT_SHARE_USER = 'calendar_user_share';
+ const SUBJECT_SHARE_GROUP = 'calendar_group_share';
const SUBJECT_UNSHARE_USER = 'calendar_user_unshare';
const SUBJECT_UNSHARE_GROUP = 'calendar_group_unshare';
@@ -143,6 +145,12 @@ class Activity implements IExtension {
return (string) $l->t('%1$s updated calendar %2$s', $params);
case self::SUBJECT_UPDATE . '_self':
return (string) $l->t('You updated calendar %2$s', $params);
+ case self::SUBJECT_SHARE_USER:
+ return (string) $l->t('%1$s shared calendar %2$s with you', $params);
+ case self::SUBJECT_SHARE_USER . '_you':
+ return (string) $l->t('You shared calendar %2$s with %1$s', $params);
+ case self::SUBJECT_SHARE_USER . '_by':
+ return (string) $l->t('%3$s shared calendar %2$s with %1$s', $params);
case self::SUBJECT_UNSHARE_USER:
return (string) $l->t('%1$s unshared calendar %2$s from you', $params);
case self::SUBJECT_UNSHARE_USER . '_you':
@@ -151,6 +159,10 @@ class Activity implements IExtension {
return (string) $l->t('%3$s unshared calendar %2$s from %1$s', $params);
case self::SUBJECT_UNSHARE_USER . '_self':
return (string) $l->t('%1$s unshared calendar %2$s from themselves', $params);
+ case self::SUBJECT_SHARE_GROUP . '_you':
+ return (string) $l->t('You shared calendar %2$s with group %1$s', $params);
+ case self::SUBJECT_SHARE_GROUP . '_by':
+ return (string) $l->t('%3$s shared calendar %2$s with group %1$s', $params);
case self::SUBJECT_UNSHARE_GROUP . '_you':
return (string) $l->t('You unshared calendar %2$s from group %1$s', $params);
case self::SUBJECT_UNSHARE_GROUP . '_by':
@@ -180,6 +192,8 @@ class Activity implements IExtension {
case self::SUBJECT_DELETE . '_self':
case self::SUBJECT_UPDATE:
case self::SUBJECT_UPDATE . '_self':
+ case self::SUBJECT_SHARE_USER:
+ case self::SUBJECT_SHARE_USER . '_you':
case self::SUBJECT_UNSHARE_USER:
case self::SUBJECT_UNSHARE_USER . '_you':
case self::SUBJECT_UNSHARE_USER . '_self':
@@ -187,17 +201,20 @@ class Activity implements IExtension {
0 => 'username',
//1 => 'calendar',
];
+ case self::SUBJECT_SHARE_USER . '_by':
case self::SUBJECT_UNSHARE_USER . '_by':
return [
0 => 'username',
//1 => 'calendar',
2 => 'username',
];
+ case self::SUBJECT_SHARE_GROUP . '_you':
case self::SUBJECT_UNSHARE_GROUP . '_you':
return [
//0 => 'group',
//1 => 'calendar',
];
+ case self::SUBJECT_SHARE_GROUP . '_by':
case self::SUBJECT_UNSHARE_GROUP . '_by':
return [
//0 => 'group',
diff --git a/apps/dav/lib/CalDAV/CalDavBackend.php b/apps/dav/lib/CalDAV/CalDavBackend.php
index 3e1f720cd01..2d2a5062a0c 100644
--- a/apps/dav/lib/CalDAV/CalDavBackend.php
+++ b/apps/dav/lib/CalDAV/CalDavBackend.php
@@ -1792,7 +1792,7 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
$userSession = \OC::$server->getUserSession();
$calendarId = $calendar->getResourceId();
- //$shares = $this->sharingBackend->getShares($calendarId);
+ $shares = $this->sharingBackend->getShares($calendarId);
$properties = $this->getCalendarById($calendarId);
$principal = explode('/', $properties['principaluri']);
@@ -1820,7 +1820,13 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
$principal = explode('/', $parts[1]);
if ($principal[1] === 'users') {
- $this->triggerActivityUnshareUser($principal[2], $event, $properties);
+ $this->triggerActivityUnshareUser(
+ $principal[2],
+ $event,
+ $properties,
+ Activity::SUBJECT_UNSHARE_USER,
+ Activity::SUBJECT_DELETE . '_self'
+ );
if ($owner !== $principal[2]) {
$parameters = [
@@ -1846,7 +1852,7 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
$aM->publish($event);
}
} else if ($principal[1] === 'groups') {
- $this->triggerActivityUnshareGroup($principal[2], $event, $properties);
+ $this->triggerActivityUnshareGroup($principal[2], $event, $properties, Activity::SUBJECT_UNSHARE_USER);
$parameters = [
$principal[2],
@@ -1869,9 +1875,79 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
$aM->publish($event);
}
}
+
+ foreach ($add as $share) {
+ if ($this->isAlreadyShared($share['href'], $shares)) {
+ continue;
+ }
+
+ // principal:principals/users/test
+ $parts = explode(':', $share['href'], 2);
+ if ($parts[0] !== 'principal') {
+ continue;
+ }
+ $principal = explode('/', $parts[1]);
+
+ if ($principal[1] === 'users') {
+ $this->triggerActivityUnshareUser($principal[2], $event, $properties, Activity::SUBJECT_SHARE_USER);
+
+ if ($owner !== $principal[2]) {
+ $parameters = [
+ $principal[2],
+ $properties['{DAV:}displayname'],
+ ];
+
+ if ($owner === $event->getAuthor()) {
+ $subject = Activity::SUBJECT_SHARE_USER . '_you';
+ } else {
+ $event->setAffectedUser($event->getAuthor())
+ ->setSubject(Activity::SUBJECT_SHARE_USER . '_you', $parameters);
+ $aM->publish($event);
+
+ $subject = Activity::SUBJECT_SHARE_USER . '_by';
+ $parameters[] = $event->getAuthor();
+ }
+
+ $event->setAffectedUser($owner)
+ ->setSubject($subject, $parameters);
+ $aM->publish($event);
+ }
+ } else if ($principal[1] === 'groups') {
+ $this->triggerActivityUnshareGroup($principal[2], $event, $properties, Activity::SUBJECT_SHARE_USER);
+
+ $parameters = [
+ $principal[2],
+ $properties['{DAV:}displayname'],
+ ];
+
+ if ($owner === $event->getAuthor()) {
+ $subject = Activity::SUBJECT_SHARE_GROUP . '_you';
+ } else {
+ $event->setAffectedUser($event->getAuthor())
+ ->setSubject(Activity::SUBJECT_SHARE_GROUP . '_you', $parameters);
+ $aM->publish($event);
+
+ $subject = Activity::SUBJECT_SHARE_GROUP . '_by';
+ $parameters[] = $event->getAuthor();
+ }
+
+ $event->setAffectedUser($owner)
+ ->setSubject($subject, $parameters);
+ $aM->publish($event);
+ }
+ }
+ }
+
+ protected function isAlreadyShared($principal, $shares) {
+ foreach ($shares as $share) {
+ if ($principal === $share['href']) {
+ return true;
+ }
+ }
+ return false;
}
- protected function triggerActivityUnshareGroup($gid, IEvent $event, array $properties) {
+ protected function triggerActivityUnshareGroup($gid, IEvent $event, array $properties, $subject) {
$gM = \OC::$server->getGroupManager();
$group = $gM->get($gid);
@@ -1879,18 +1955,18 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
foreach ($group->getUsers() as $user) {
// Exclude current user
if ($user->getUID() !== $event->getAuthor()) {
- $this->triggerActivityUnshareUser($user->getUID(), $event, $properties);
+ $this->triggerActivityUnshareUser($user->getUID(), $event, $properties, $subject);
}
}
}
}
- protected function triggerActivityUnshareUser($user, IEvent $event, array $properties) {
+ protected function triggerActivityUnshareUser($user, IEvent $event, array $properties, $subject, $subjectSelf = '') {
$aM = \OC::$server->getActivityManager();
$event->setAffectedUser($user)
->setSubject(
- $user === $event->getAuthor() ? Activity::SUBJECT_DELETE . '_self' : Activity::SUBJECT_UNSHARE_USER,
+ $user === $event->getAuthor() && $subjectSelf ? $subjectSelf : $subject,
[
$event->getAuthor(),
$properties['{DAV:}displayname'],