diff options
author | Joas Schilling <coding@schilljs.com> | 2016-10-07 12:29:22 +0200 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2016-11-03 12:07:57 +0100 |
commit | 83d51afab1eabfdad50c6408aa6a030d8727227c (patch) | |
tree | 26ba325cf4772552a7ee5cb54229ca59a27d7640 | |
parent | 90578327d57856e26f3a81813c5fdcb3db99617b (diff) | |
download | nextcloud-server-83d51afab1eabfdad50c6408aa6a030d8727227c.tar.gz nextcloud-server-83d51afab1eabfdad50c6408aa6a030d8727227c.zip |
Unshare user activities
Signed-off-by: Joas Schilling <coding@schilljs.com>
-rw-r--r-- | apps/dav/lib/CalDAV/Activity.php | 12 | ||||
-rw-r--r-- | apps/dav/lib/CalDAV/CalDavBackend.php | 72 |
2 files changed, 80 insertions, 4 deletions
diff --git a/apps/dav/lib/CalDAV/Activity.php b/apps/dav/lib/CalDAV/Activity.php index 2f27a5bf071..fbdc7b054d7 100644 --- a/apps/dav/lib/CalDAV/Activity.php +++ b/apps/dav/lib/CalDAV/Activity.php @@ -22,8 +22,6 @@ namespace OCA\DAV\CalDAV; use OCP\Activity\IExtension; -use OCP\Activity\IManager; -use OCP\IL10N; use OCP\IURLGenerator; use OCP\L10N\IFactory; @@ -40,6 +38,7 @@ class Activity implements IExtension { const SUBJECT_ADD = 'calendar_add'; const SUBJECT_UPDATE = 'calendar_update'; const SUBJECT_DELETE = 'calendar_delete'; + const SUBJECT_UNSHARE_USER = 'calendar_user_unshare'; /** * Subject keys for translation of the subjections @@ -143,6 +142,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_UNSHARE_USER: + return (string) $l->t('%1$s unshared calendar %2$s from you', $params); + case self::SUBJECT_UNSHARE_USER . '_you': + return (string) $l->t('You unshared calendar %2$s from %1$s', $params); + case self::SUBJECT_UNSHARE_USER . '_by': + return (string) $l->t('%1$s unshared calendar %2$s from themselves', $params); } return false; @@ -165,6 +170,9 @@ class Activity implements IExtension { case self::SUBJECT_ADD: case self::SUBJECT_DELETE: case self::SUBJECT_UPDATE: + case self::SUBJECT_UNSHARE_USER: + case self::SUBJECT_UNSHARE_USER . '_you': + case self::SUBJECT_UNSHARE_USER . '_by': return [ 0 => 'username', //1 => 'calendar', diff --git a/apps/dav/lib/CalDAV/CalDavBackend.php b/apps/dav/lib/CalDAV/CalDavBackend.php index 40488a2c752..25cb3ce484d 100644 --- a/apps/dav/lib/CalDAV/CalDavBackend.php +++ b/apps/dav/lib/CalDAV/CalDavBackend.php @@ -26,6 +26,7 @@ namespace OCA\DAV\CalDAV; use OCA\DAV\DAV\Sharing\IShareable; +use OCP\Activity\IEvent; use OCP\DB\QueryBuilder\IQueryBuilder; use OCA\DAV\Connector\Sabre\Principal; use OCA\DAV\DAV\Sharing\Backend; @@ -1658,6 +1659,9 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription * @param array $remove */ public function updateShares($shareable, $add, $remove) { + /** @var Calendar $shareable */ + $this->triggerActivitySharing($shareable, $add, $remove); + $this->sharingBackend->updateShares($shareable, $add, $remove); } @@ -1742,8 +1746,8 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription return; } - $principaluri = explode('/', $properties['principaluri']); - $owner = array_pop($principaluri); + $principal = explode('/', $properties['principaluri']); + $owner = $principal[2]; $currentUser = $userSession->getUser(); if ($currentUser instanceof IUser) { @@ -1783,6 +1787,70 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription } } + protected function triggerActivitySharing(Calendar $calendar, array $add, array $remove) { + $aM = \OC::$server->getActivityManager(); + $userSession = \OC::$server->getUserSession(); + + $calendarId = $calendar->getResourceId(); + //$shares = $this->sharingBackend->getShares($calendarId); + + $properties = $this->getCalendarById($calendarId); + $principal = explode('/', $properties['principaluri']); + $owner = $principal[2]; + + $currentUser = $userSession->getUser(); + if ($currentUser instanceof IUser) { + $currentUser = $currentUser->getUID(); + } else { + $currentUser = $owner; + } + + $event = $aM->generateEvent(); + $event->setApp('dav') + ->setObject(Activity::CALENDAR, $calendarId) + ->setType(Activity::CALENDAR) + ->setAuthor($currentUser); + + foreach ($remove as $principal) { + // principal:principals/users/test + $parts = explode(':', $principal, 2); + if ($parts[0] !== 'principal') { + continue; + } + $principal = explode('/', $parts[1]); + + if ($principal[1] === 'users') { + $this->triggerActivityUnshareUser($principal[2], $event, $properties); + + if ($owner !== $principal[2]) { + $event->setAffectedUser($owner) + ->setSubject( + $owner === $event->getAuthor() ? Activity::SUBJECT_UNSHARE_USER . '_you' : Activity::SUBJECT_UNSHARE_USER . '_by', + [ + $principal[2], + $properties['{DAV:}displayname'], + ] + ); + $aM->publish($event); + } + } + } + } + + protected function triggerActivityUnshareUser($user, IEvent $event, array $properties) { + $aM = \OC::$server->getActivityManager(); + + $event->setAffectedUser($user) + ->setSubject( + $user === $event->getAuthor() ? Activity::SUBJECT_DELETE . '_self' : Activity::SUBJECT_UNSHARE_USER, + [ + $event->getAuthor(), + $properties['{DAV:}displayname'], + ] + ); + $aM->publish($event); + } + /** * Get all users that have access to a given calendar * |