2016-11-29 17:47:43 +03:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com>
|
|
|
|
*
|
2017-11-06 17:56:42 +03:00
|
|
|
* @author Joas Schilling <coding@schilljs.com>
|
2019-12-03 21:57:53 +03:00
|
|
|
* @author Julius Härtl <jus@bitgrid.net>
|
|
|
|
* @author Morris Jobke <hey@morrisjobke.de>
|
2020-03-31 11:49:10 +03:00
|
|
|
* @author Thomas Citharel <nextcloud@tcit.fr>
|
2017-11-06 17:56:42 +03:00
|
|
|
*
|
2016-11-29 17:47:43 +03:00
|
|
|
* @license GNU AGPL version 3 or any later version
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
2019-12-03 21:57:53 +03:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2016-11-29 17:47:43 +03:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace OCA\DAV\CalDAV\Activity\Provider;
|
|
|
|
|
|
|
|
use OCP\Activity\IEvent;
|
|
|
|
use OCP\Activity\IEventMerger;
|
|
|
|
use OCP\Activity\IManager;
|
2018-01-24 15:54:49 +03:00
|
|
|
use OCP\IGroupManager;
|
2016-11-29 17:47:43 +03:00
|
|
|
use OCP\IL10N;
|
|
|
|
use OCP\IURLGenerator;
|
|
|
|
use OCP\IUserManager;
|
2016-12-01 13:35:23 +03:00
|
|
|
use OCP\L10N\IFactory;
|
2016-11-29 17:47:43 +03:00
|
|
|
|
2016-11-30 13:38:49 +03:00
|
|
|
class Calendar extends Base {
|
2020-04-10 17:54:27 +03:00
|
|
|
public const SUBJECT_ADD = 'calendar_add';
|
|
|
|
public const SUBJECT_UPDATE = 'calendar_update';
|
|
|
|
public const SUBJECT_DELETE = 'calendar_delete';
|
|
|
|
public const SUBJECT_PUBLISH = 'calendar_publish';
|
|
|
|
public const SUBJECT_UNPUBLISH = 'calendar_unpublish';
|
|
|
|
public const SUBJECT_SHARE_USER = 'calendar_user_share';
|
|
|
|
public const SUBJECT_SHARE_GROUP = 'calendar_group_share';
|
|
|
|
public const SUBJECT_UNSHARE_USER = 'calendar_user_unshare';
|
|
|
|
public const SUBJECT_UNSHARE_GROUP = 'calendar_group_unshare';
|
2016-11-29 17:47:43 +03:00
|
|
|
|
2016-12-01 13:35:23 +03:00
|
|
|
/** @var IFactory */
|
|
|
|
protected $languageFactory;
|
|
|
|
|
2016-11-29 17:47:43 +03:00
|
|
|
/** @var IL10N */
|
|
|
|
protected $l;
|
|
|
|
|
|
|
|
/** @var IURLGenerator */
|
|
|
|
protected $url;
|
|
|
|
|
|
|
|
/** @var IManager */
|
|
|
|
protected $activityManager;
|
|
|
|
|
|
|
|
/** @var IEventMerger */
|
|
|
|
protected $eventMerger;
|
|
|
|
|
|
|
|
/**
|
2016-12-01 13:35:23 +03:00
|
|
|
* @param IFactory $languageFactory
|
2016-11-29 17:47:43 +03:00
|
|
|
* @param IURLGenerator $url
|
|
|
|
* @param IManager $activityManager
|
|
|
|
* @param IUserManager $userManager
|
2018-01-24 15:54:49 +03:00
|
|
|
* @param IGroupManager $groupManager
|
2016-11-29 17:47:43 +03:00
|
|
|
* @param IEventMerger $eventMerger
|
|
|
|
*/
|
2018-01-24 15:54:49 +03:00
|
|
|
public function __construct(IFactory $languageFactory, IURLGenerator $url, IManager $activityManager, IUserManager $userManager, IGroupManager $groupManager, IEventMerger $eventMerger) {
|
|
|
|
parent::__construct($userManager, $groupManager);
|
2016-12-01 13:35:23 +03:00
|
|
|
$this->languageFactory = $languageFactory;
|
2016-11-29 17:47:43 +03:00
|
|
|
$this->url = $url;
|
|
|
|
$this->activityManager = $activityManager;
|
|
|
|
$this->eventMerger = $eventMerger;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-12-01 13:35:23 +03:00
|
|
|
* @param string $language
|
2016-11-29 17:47:43 +03:00
|
|
|
* @param IEvent $event
|
|
|
|
* @param IEvent|null $previousEvent
|
|
|
|
* @return IEvent
|
|
|
|
* @throws \InvalidArgumentException
|
|
|
|
* @since 11.0.0
|
|
|
|
*/
|
2016-12-01 13:35:23 +03:00
|
|
|
public function parse($language, IEvent $event, IEvent $previousEvent = null) {
|
2016-11-29 17:56:22 +03:00
|
|
|
if ($event->getApp() !== 'dav' || $event->getType() !== 'calendar') {
|
2016-11-29 17:47:43 +03:00
|
|
|
throw new \InvalidArgumentException();
|
|
|
|
}
|
|
|
|
|
2016-12-01 13:35:23 +03:00
|
|
|
$this->l = $this->languageFactory->get('dav', $language);
|
|
|
|
|
2017-06-20 14:48:51 +03:00
|
|
|
if ($this->activityManager->getRequirePNG()) {
|
|
|
|
$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'places/calendar-dark.png')));
|
|
|
|
} else {
|
2018-07-24 19:47:54 +03:00
|
|
|
$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'places/calendar.svg')));
|
2017-06-20 14:48:51 +03:00
|
|
|
}
|
2016-11-29 17:56:22 +03:00
|
|
|
|
2016-11-29 17:47:43 +03:00
|
|
|
if ($event->getSubject() === self::SUBJECT_ADD) {
|
|
|
|
$subject = $this->l->t('{actor} created calendar {calendar}');
|
2020-04-10 11:35:09 +03:00
|
|
|
} elseif ($event->getSubject() === self::SUBJECT_ADD . '_self') {
|
2016-11-29 17:47:43 +03:00
|
|
|
$subject = $this->l->t('You created calendar {calendar}');
|
2020-04-10 11:35:09 +03:00
|
|
|
} elseif ($event->getSubject() === self::SUBJECT_DELETE) {
|
2016-11-29 17:47:43 +03:00
|
|
|
$subject = $this->l->t('{actor} deleted calendar {calendar}');
|
2020-04-10 11:35:09 +03:00
|
|
|
} elseif ($event->getSubject() === self::SUBJECT_DELETE . '_self') {
|
2016-11-29 17:47:43 +03:00
|
|
|
$subject = $this->l->t('You deleted calendar {calendar}');
|
2020-04-10 11:35:09 +03:00
|
|
|
} elseif ($event->getSubject() === self::SUBJECT_UPDATE) {
|
2016-11-29 17:47:43 +03:00
|
|
|
$subject = $this->l->t('{actor} updated calendar {calendar}');
|
2020-04-10 11:35:09 +03:00
|
|
|
} elseif ($event->getSubject() === self::SUBJECT_UPDATE . '_self') {
|
2016-11-29 17:47:43 +03:00
|
|
|
$subject = $this->l->t('You updated calendar {calendar}');
|
2020-04-10 11:35:09 +03:00
|
|
|
} elseif ($event->getSubject() === self::SUBJECT_PUBLISH . '_self') {
|
2017-12-11 17:48:31 +03:00
|
|
|
$subject = $this->l->t('You shared calendar {calendar} as public link');
|
2020-04-10 11:35:09 +03:00
|
|
|
} elseif ($event->getSubject() === self::SUBJECT_UNPUBLISH . '_self') {
|
2017-12-11 17:48:31 +03:00
|
|
|
$subject = $this->l->t('You removed public link for calendar {calendar}');
|
2020-04-10 11:35:09 +03:00
|
|
|
} elseif ($event->getSubject() === self::SUBJECT_SHARE_USER) {
|
2016-11-29 17:47:43 +03:00
|
|
|
$subject = $this->l->t('{actor} shared calendar {calendar} with you');
|
2020-04-10 11:35:09 +03:00
|
|
|
} elseif ($event->getSubject() === self::SUBJECT_SHARE_USER . '_you') {
|
2016-11-29 17:47:43 +03:00
|
|
|
$subject = $this->l->t('You shared calendar {calendar} with {user}');
|
2020-04-10 11:35:09 +03:00
|
|
|
} elseif ($event->getSubject() === self::SUBJECT_SHARE_USER . '_by') {
|
2016-11-29 17:47:43 +03:00
|
|
|
$subject = $this->l->t('{actor} shared calendar {calendar} with {user}');
|
2020-04-10 11:35:09 +03:00
|
|
|
} elseif ($event->getSubject() === self::SUBJECT_UNSHARE_USER) {
|
2016-11-29 17:47:43 +03:00
|
|
|
$subject = $this->l->t('{actor} unshared calendar {calendar} from you');
|
2020-04-10 11:35:09 +03:00
|
|
|
} elseif ($event->getSubject() === self::SUBJECT_UNSHARE_USER . '_you') {
|
2016-11-29 17:47:43 +03:00
|
|
|
$subject = $this->l->t('You unshared calendar {calendar} from {user}');
|
2020-04-10 11:35:09 +03:00
|
|
|
} elseif ($event->getSubject() === self::SUBJECT_UNSHARE_USER . '_by') {
|
2016-11-29 17:47:43 +03:00
|
|
|
$subject = $this->l->t('{actor} unshared calendar {calendar} from {user}');
|
2020-04-10 11:35:09 +03:00
|
|
|
} elseif ($event->getSubject() === self::SUBJECT_UNSHARE_USER . '_self') {
|
2016-11-29 17:47:43 +03:00
|
|
|
$subject = $this->l->t('{actor} unshared calendar {calendar} from themselves');
|
2020-04-10 11:35:09 +03:00
|
|
|
} elseif ($event->getSubject() === self::SUBJECT_SHARE_GROUP . '_you') {
|
2016-11-29 17:47:43 +03:00
|
|
|
$subject = $this->l->t('You shared calendar {calendar} with group {group}');
|
2020-04-10 11:35:09 +03:00
|
|
|
} elseif ($event->getSubject() === self::SUBJECT_SHARE_GROUP . '_by') {
|
2016-11-29 17:47:43 +03:00
|
|
|
$subject = $this->l->t('{actor} shared calendar {calendar} with group {group}');
|
2020-04-10 11:35:09 +03:00
|
|
|
} elseif ($event->getSubject() === self::SUBJECT_UNSHARE_GROUP . '_you') {
|
2016-11-29 17:47:43 +03:00
|
|
|
$subject = $this->l->t('You unshared calendar {calendar} from group {group}');
|
2020-04-10 11:35:09 +03:00
|
|
|
} elseif ($event->getSubject() === self::SUBJECT_UNSHARE_GROUP . '_by') {
|
2016-11-29 17:47:43 +03:00
|
|
|
$subject = $this->l->t('{actor} unshared calendar {calendar} from group {group}');
|
|
|
|
} else {
|
|
|
|
throw new \InvalidArgumentException();
|
|
|
|
}
|
|
|
|
|
|
|
|
$parsedParameters = $this->getParameters($event);
|
|
|
|
$this->setSubjects($event, $subject, $parsedParameters);
|
|
|
|
|
|
|
|
$event = $this->eventMerger->mergeEvents('calendar', $event, $previousEvent);
|
|
|
|
|
|
|
|
if ($event->getChildEvent() === null) {
|
|
|
|
if (isset($parsedParameters['user'])) {
|
|
|
|
// Couldn't group by calendar, maybe we can group by users
|
|
|
|
$event = $this->eventMerger->mergeEvents('user', $event, $previousEvent);
|
2020-04-10 11:35:09 +03:00
|
|
|
} elseif (isset($parsedParameters['group'])) {
|
2016-11-29 17:47:43 +03:00
|
|
|
// Couldn't group by calendar, maybe we can group by groups
|
|
|
|
$event = $this->eventMerger->mergeEvents('group', $event, $previousEvent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $event;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param IEvent $event
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
protected function getParameters(IEvent $event) {
|
|
|
|
$subject = $event->getSubject();
|
|
|
|
$parameters = $event->getSubjectParameters();
|
|
|
|
|
2017-10-16 19:31:43 +03:00
|
|
|
// Nextcloud 13+
|
|
|
|
if (isset($parameters['calendar'])) {
|
|
|
|
switch ($subject) {
|
|
|
|
case self::SUBJECT_ADD:
|
|
|
|
case self::SUBJECT_ADD . '_self':
|
|
|
|
case self::SUBJECT_DELETE:
|
|
|
|
case self::SUBJECT_DELETE . '_self':
|
|
|
|
case self::SUBJECT_UPDATE:
|
|
|
|
case self::SUBJECT_UPDATE . '_self':
|
2018-07-02 14:57:48 +03:00
|
|
|
case self::SUBJECT_PUBLISH . '_self':
|
|
|
|
case self::SUBJECT_UNPUBLISH . '_self':
|
2017-10-16 19:31:43 +03:00
|
|
|
case self::SUBJECT_SHARE_USER:
|
|
|
|
case self::SUBJECT_UNSHARE_USER:
|
|
|
|
case self::SUBJECT_UNSHARE_USER . '_self':
|
|
|
|
return [
|
|
|
|
'actor' => $this->generateUserParameter($parameters['actor']),
|
|
|
|
'calendar' => $this->generateCalendarParameter($parameters['calendar'], $this->l),
|
|
|
|
];
|
|
|
|
case self::SUBJECT_SHARE_USER . '_you':
|
|
|
|
case self::SUBJECT_UNSHARE_USER . '_you':
|
|
|
|
return [
|
|
|
|
'calendar' => $this->generateCalendarParameter($parameters['calendar'], $this->l),
|
|
|
|
'user' => $this->generateUserParameter($parameters['user']),
|
|
|
|
];
|
|
|
|
case self::SUBJECT_SHARE_USER . '_by':
|
|
|
|
case self::SUBJECT_UNSHARE_USER . '_by':
|
|
|
|
return [
|
|
|
|
'actor' => $this->generateUserParameter($parameters['actor']),
|
|
|
|
'calendar' => $this->generateCalendarParameter($parameters['calendar'], $this->l),
|
|
|
|
'user' => $this->generateUserParameter($parameters['user']),
|
|
|
|
];
|
|
|
|
case self::SUBJECT_SHARE_GROUP . '_you':
|
|
|
|
case self::SUBJECT_UNSHARE_GROUP . '_you':
|
|
|
|
return [
|
|
|
|
'calendar' => $this->generateCalendarParameter($parameters['calendar'], $this->l),
|
|
|
|
'group' => $this->generateGroupParameter($parameters['group']),
|
|
|
|
];
|
|
|
|
case self::SUBJECT_SHARE_GROUP . '_by':
|
|
|
|
case self::SUBJECT_UNSHARE_GROUP . '_by':
|
|
|
|
return [
|
|
|
|
'actor' => $this->generateUserParameter($parameters['actor']),
|
|
|
|
'calendar' => $this->generateCalendarParameter($parameters['calendar'], $this->l),
|
|
|
|
'group' => $this->generateGroupParameter($parameters['group']),
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-23 13:35:55 +03:00
|
|
|
// Legacy - Do NOT Remove unless necessary
|
|
|
|
// Removing this will break parsing of activities that were created on
|
|
|
|
// Nextcloud 12, so we should keep this as long as it's acceptable.
|
|
|
|
// Otherwise if people upgrade over multiple releases in a short period,
|
|
|
|
// they will get the dead entries in their stream.
|
2016-11-29 17:47:43 +03:00
|
|
|
switch ($subject) {
|
|
|
|
case self::SUBJECT_ADD:
|
|
|
|
case self::SUBJECT_ADD . '_self':
|
|
|
|
case self::SUBJECT_DELETE:
|
|
|
|
case self::SUBJECT_DELETE . '_self':
|
|
|
|
case self::SUBJECT_UPDATE:
|
|
|
|
case self::SUBJECT_UPDATE . '_self':
|
2017-09-20 18:33:51 +03:00
|
|
|
case self::SUBJECT_PUBLISH . '_self':
|
|
|
|
case self::SUBJECT_UNPUBLISH . '_self':
|
2016-11-29 17:47:43 +03:00
|
|
|
case self::SUBJECT_SHARE_USER:
|
|
|
|
case self::SUBJECT_UNSHARE_USER:
|
|
|
|
case self::SUBJECT_UNSHARE_USER . '_self':
|
|
|
|
return [
|
|
|
|
'actor' => $this->generateUserParameter($parameters[0]),
|
2017-10-16 19:31:43 +03:00
|
|
|
'calendar' => $this->generateLegacyCalendarParameter((int)$event->getObjectId(), $parameters[1]),
|
2016-11-29 17:47:43 +03:00
|
|
|
];
|
|
|
|
case self::SUBJECT_SHARE_USER . '_you':
|
|
|
|
case self::SUBJECT_UNSHARE_USER . '_you':
|
|
|
|
return [
|
|
|
|
'user' => $this->generateUserParameter($parameters[0]),
|
2017-10-16 19:31:43 +03:00
|
|
|
'calendar' => $this->generateLegacyCalendarParameter((int)$event->getObjectId(), $parameters[1]),
|
2016-11-29 17:47:43 +03:00
|
|
|
];
|
|
|
|
case self::SUBJECT_SHARE_USER . '_by':
|
|
|
|
case self::SUBJECT_UNSHARE_USER . '_by':
|
|
|
|
return [
|
|
|
|
'user' => $this->generateUserParameter($parameters[0]),
|
2017-10-16 19:31:43 +03:00
|
|
|
'calendar' => $this->generateLegacyCalendarParameter((int)$event->getObjectId(), $parameters[1]),
|
2016-11-29 17:47:43 +03:00
|
|
|
'actor' => $this->generateUserParameter($parameters[2]),
|
|
|
|
];
|
|
|
|
case self::SUBJECT_SHARE_GROUP . '_you':
|
|
|
|
case self::SUBJECT_UNSHARE_GROUP . '_you':
|
|
|
|
return [
|
|
|
|
'group' => $this->generateGroupParameter($parameters[0]),
|
2017-10-16 19:31:43 +03:00
|
|
|
'calendar' => $this->generateLegacyCalendarParameter((int)$event->getObjectId(), $parameters[1]),
|
2016-11-29 17:47:43 +03:00
|
|
|
];
|
|
|
|
case self::SUBJECT_SHARE_GROUP . '_by':
|
|
|
|
case self::SUBJECT_UNSHARE_GROUP . '_by':
|
|
|
|
return [
|
|
|
|
'group' => $this->generateGroupParameter($parameters[0]),
|
2017-10-16 19:31:43 +03:00
|
|
|
'calendar' => $this->generateLegacyCalendarParameter((int)$event->getObjectId(), $parameters[1]),
|
2016-11-29 17:47:43 +03:00
|
|
|
'actor' => $this->generateUserParameter($parameters[2]),
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
throw new \InvalidArgumentException();
|
|
|
|
}
|
|
|
|
}
|