migrate therinaldos.com data
Build & Deploy to DigitalOcean Space / build (push) Failing after 2m38s

This commit is contained in:
2024-05-05 15:50:45 -04:00
commit ef1ff240d4
23182 changed files with 3801898 additions and 0 deletions
@@ -0,0 +1,661 @@
<?php
/**
* @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com>
*
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
* @author Joas Schilling <coding@schilljs.com>
* @author Roeland Jago Douma <roeland@famdouma.nl>
* @author Thomas Citharel <nextcloud@tcit.fr>
*
* @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
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\DAV\CalDAV\Activity;
use OCA\DAV\CalDAV\Activity\Provider\Calendar;
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;
use OCP\IUserManager;
use OCP\IUserSession;
use Sabre\VObject\Reader;
/**
* Class Backend
*
* @package OCA\DAV\CalDAV\Activity
*/
class Backend {
/** @var IActivityManager */
protected $activityManager;
/** @var IGroupManager */
protected $groupManager;
/** @var IUserSession */
protected $userSession;
/** @var IAppManager */
protected $appManager;
/** @var IUserManager */
protected $userManager;
public function __construct(IActivityManager $activityManager, IGroupManager $groupManager, IUserSession $userSession, IAppManager $appManager, IUserManager $userManager) {
$this->activityManager = $activityManager;
$this->groupManager = $groupManager;
$this->userSession = $userSession;
$this->appManager = $appManager;
$this->userManager = $userManager;
}
/**
* Creates activities when a calendar was creates
*
* @param array $calendarData
*/
public function onCalendarAdd(array $calendarData) {
$this->triggerCalendarActivity(Calendar::SUBJECT_ADD, $calendarData);
}
/**
* Creates activities when a calendar was updated
*
* @param array $calendarData
* @param array $shares
* @param array $properties
*/
public function onCalendarUpdate(array $calendarData, array $shares, array $properties) {
$this->triggerCalendarActivity(Calendar::SUBJECT_UPDATE, $calendarData, $shares, $properties);
}
/**
* Creates activities when a calendar was moved to trash
*
* @param array $calendarData
* @param array $shares
*/
public function onCalendarMovedToTrash(array $calendarData, array $shares): void {
$this->triggerCalendarActivity(Calendar::SUBJECT_MOVE_TO_TRASH, $calendarData, $shares);
}
/**
* Creates activities when a calendar was restored
*
* @param array $calendarData
* @param array $shares
*/
public function onCalendarRestored(array $calendarData, array $shares): void {
$this->triggerCalendarActivity(Calendar::SUBJECT_RESTORE, $calendarData, $shares);
}
/**
* Creates activities when a calendar was deleted
*
* @param array $calendarData
* @param array $shares
*/
public function onCalendarDelete(array $calendarData, array $shares): void {
$this->triggerCalendarActivity(Calendar::SUBJECT_DELETE, $calendarData, $shares);
}
/**
* Creates activities when a calendar was (un)published
*
* @param array $calendarData
* @param bool $publishStatus
*/
public function onCalendarPublication(array $calendarData, bool $publishStatus): void {
$this->triggerCalendarActivity($publishStatus ? Calendar::SUBJECT_PUBLISH : Calendar::SUBJECT_UNPUBLISH, $calendarData);
}
/**
* Creates activities for all related users when a calendar was touched
*
* @param string $action
* @param array $calendarData
* @param array $shares
* @param array $changedProperties
*/
protected function triggerCalendarActivity($action, array $calendarData, array $shares = [], array $changedProperties = []) {
if (!isset($calendarData['principaluri'])) {
return;
}
$principal = explode('/', $calendarData['principaluri']);
$owner = array_pop($principal);
$currentUser = $this->userSession->getUser();
if ($currentUser instanceof IUser) {
$currentUser = $currentUser->getUID();
} else {
$currentUser = $owner;
}
$event = $this->activityManager->generateEvent();
$event->setApp('dav')
->setObject('calendar', (int) $calendarData['id'])
->setType('calendar')
->setAuthor($currentUser);
$changedVisibleInformation = array_intersect([
'{DAV:}displayname',
'{http://apple.com/ns/ical/}calendar-color'
], array_keys($changedProperties));
if (empty($shares) || ($action === Calendar::SUBJECT_UPDATE && empty($changedVisibleInformation))) {
$users = [$owner];
} else {
$users = $this->getUsersForShares($shares);
$users[] = $owner;
}
foreach ($users as $user) {
if ($action === Calendar::SUBJECT_DELETE && !$this->userManager->userExists($user)) {
// Avoid creating calendar_delete activities for deleted users
continue;
}
$event->setAffectedUser($user)
->setSubject(
$user === $currentUser ? $action . '_self' : $action,
[
'actor' => $currentUser,
'calendar' => [
'id' => (int) $calendarData['id'],
'uri' => $calendarData['uri'],
'name' => $calendarData['{DAV:}displayname'],
],
]
);
$this->activityManager->publish($event);
}
}
/**
* Creates activities for all related users when a calendar was (un-)shared
*
* @param array $calendarData
* @param array $shares
* @param array $add
* @param array $remove
*/
public function onCalendarUpdateShares(array $calendarData, array $shares, array $add, array $remove) {
$principal = explode('/', $calendarData['principaluri']);
$owner = $principal[2];
$currentUser = $this->userSession->getUser();
if ($currentUser instanceof IUser) {
$currentUser = $currentUser->getUID();
} else {
$currentUser = $owner;
}
$event = $this->activityManager->generateEvent();
$event->setApp('dav')
->setObject('calendar', (int) $calendarData['id'])
->setType('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->triggerActivityUser(
$principal[2],
$event,
$calendarData,
Calendar::SUBJECT_UNSHARE_USER,
Calendar::SUBJECT_DELETE . '_self'
);
if ($owner !== $principal[2]) {
$parameters = [
'actor' => $event->getAuthor(),
'calendar' => [
'id' => (int) $calendarData['id'],
'uri' => $calendarData['uri'],
'name' => $calendarData['{DAV:}displayname'],
],
'user' => $principal[2],
];
if ($owner === $event->getAuthor()) {
$subject = Calendar::SUBJECT_UNSHARE_USER . '_you';
} elseif ($principal[2] === $event->getAuthor()) {
$subject = Calendar::SUBJECT_UNSHARE_USER . '_self';
} else {
$event->setAffectedUser($event->getAuthor())
->setSubject(Calendar::SUBJECT_UNSHARE_USER . '_you', $parameters);
$this->activityManager->publish($event);
$subject = Calendar::SUBJECT_UNSHARE_USER . '_by';
}
$event->setAffectedUser($owner)
->setSubject($subject, $parameters);
$this->activityManager->publish($event);
}
} elseif ($principal[1] === 'groups') {
$this->triggerActivityGroup($principal[2], $event, $calendarData, Calendar::SUBJECT_UNSHARE_USER);
$parameters = [
'actor' => $event->getAuthor(),
'calendar' => [
'id' => (int) $calendarData['id'],
'uri' => $calendarData['uri'],
'name' => $calendarData['{DAV:}displayname'],
],
'group' => $principal[2],
];
if ($owner === $event->getAuthor()) {
$subject = Calendar::SUBJECT_UNSHARE_GROUP . '_you';
} else {
$event->setAffectedUser($event->getAuthor())
->setSubject(Calendar::SUBJECT_UNSHARE_GROUP . '_you', $parameters);
$this->activityManager->publish($event);
$subject = Calendar::SUBJECT_UNSHARE_GROUP . '_by';
}
$event->setAffectedUser($owner)
->setSubject($subject, $parameters);
$this->activityManager->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->triggerActivityUser($principal[2], $event, $calendarData, Calendar::SUBJECT_SHARE_USER);
if ($owner !== $principal[2]) {
$parameters = [
'actor' => $event->getAuthor(),
'calendar' => [
'id' => (int) $calendarData['id'],
'uri' => $calendarData['uri'],
'name' => $calendarData['{DAV:}displayname'],
],
'user' => $principal[2],
];
if ($owner === $event->getAuthor()) {
$subject = Calendar::SUBJECT_SHARE_USER . '_you';
} else {
$event->setAffectedUser($event->getAuthor())
->setSubject(Calendar::SUBJECT_SHARE_USER . '_you', $parameters);
$this->activityManager->publish($event);
$subject = Calendar::SUBJECT_SHARE_USER . '_by';
}
$event->setAffectedUser($owner)
->setSubject($subject, $parameters);
$this->activityManager->publish($event);
}
} elseif ($principal[1] === 'groups') {
$this->triggerActivityGroup($principal[2], $event, $calendarData, Calendar::SUBJECT_SHARE_USER);
$parameters = [
'actor' => $event->getAuthor(),
'calendar' => [
'id' => (int) $calendarData['id'],
'uri' => $calendarData['uri'],
'name' => $calendarData['{DAV:}displayname'],
],
'group' => $principal[2],
];
if ($owner === $event->getAuthor()) {
$subject = Calendar::SUBJECT_SHARE_GROUP . '_you';
} else {
$event->setAffectedUser($event->getAuthor())
->setSubject(Calendar::SUBJECT_SHARE_GROUP . '_you', $parameters);
$this->activityManager->publish($event);
$subject = Calendar::SUBJECT_SHARE_GROUP . '_by';
}
$event->setAffectedUser($owner)
->setSubject($subject, $parameters);
$this->activityManager->publish($event);
}
}
}
/**
* Checks if a calendar is already shared with a principal
*
* @param string $principal
* @param array[] $shares
* @return bool
*/
protected function isAlreadyShared($principal, $shares) {
foreach ($shares as $share) {
if ($principal === $share['href']) {
return true;
}
}
return false;
}
/**
* Creates the given activity for all members of the given group
*
* @param string $gid
* @param IEvent $event
* @param array $properties
* @param string $subject
*/
protected function triggerActivityGroup($gid, IEvent $event, array $properties, $subject) {
$group = $this->groupManager->get($gid);
if ($group instanceof IGroup) {
foreach ($group->getUsers() as $user) {
// Exclude current user
if ($user->getUID() !== $event->getAuthor()) {
$this->triggerActivityUser($user->getUID(), $event, $properties, $subject);
}
}
}
}
/**
* Creates the given activity for the given user
*
* @param string $user
* @param IEvent $event
* @param array $properties
* @param string $subject
* @param string $subjectSelf
*/
protected function triggerActivityUser($user, IEvent $event, array $properties, $subject, $subjectSelf = '') {
$event->setAffectedUser($user)
->setSubject(
$user === $event->getAuthor() && $subjectSelf ? $subjectSelf : $subject,
[
'actor' => $event->getAuthor(),
'calendar' => [
'id' => (int) $properties['id'],
'uri' => $properties['uri'],
'name' => $properties['{DAV:}displayname'],
],
]
);
$this->activityManager->publish($event);
}
/**
* Creates activities when a calendar object was created/updated/deleted
*
* @param string $action
* @param array $calendarData
* @param array $shares
* @param array $objectData
*/
public function onTouchCalendarObject($action, array $calendarData, array $shares, array $objectData) {
if (!isset($calendarData['principaluri'])) {
return;
}
$principal = explode('/', $calendarData['principaluri']);
$owner = array_pop($principal);
$currentUser = $this->userSession->getUser();
if ($currentUser instanceof IUser) {
$currentUser = $currentUser->getUID();
} else {
$currentUser = $owner;
}
$classification = $objectData['classification'] ?? CalDavBackend::CLASSIFICATION_PUBLIC;
$object = $this->getObjectNameAndType($objectData);
if (!$object) {
return;
}
$action = $action . '_' . $object['type'];
if ($object['type'] === 'todo' && str_starts_with($action, Event::SUBJECT_OBJECT_UPDATE) && $object['status'] === 'COMPLETED') {
$action .= '_completed';
} elseif ($object['type'] === 'todo' && str_starts_with($action, Event::SUBJECT_OBJECT_UPDATE) && $object['status'] === 'NEEDS-ACTION') {
$action .= '_needs_action';
}
$event = $this->activityManager->generateEvent();
$event->setApp('dav')
->setObject('calendar', (int) $calendarData['id'])
->setType($object['type'] === 'event' ? 'calendar_event' : 'calendar_todo')
->setAuthor($currentUser);
$users = $this->getUsersForShares($shares);
$users[] = $owner;
// 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' && !str_contains($action, Event::SUBJECT_OBJECT_DELETE) && $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,
$params
);
$this->activityManager->publish($event);
}
}
/**
* Creates activities when a calendar object was moved
*/
public function onMovedCalendarObject(array $sourceCalendarData, array $targetCalendarData, array $sourceShares, array $targetShares, array $objectData): void {
if (!isset($targetCalendarData['principaluri'])) {
return;
}
$sourcePrincipal = explode('/', $sourceCalendarData['principaluri']);
$sourceOwner = array_pop($sourcePrincipal);
$targetPrincipal = explode('/', $targetCalendarData['principaluri']);
$targetOwner = array_pop($targetPrincipal);
if ($sourceOwner !== $targetOwner) {
$this->onTouchCalendarObject(
Event::SUBJECT_OBJECT_DELETE,
$sourceCalendarData,
$sourceShares,
$objectData
);
$this->onTouchCalendarObject(
Event::SUBJECT_OBJECT_ADD,
$targetCalendarData,
$targetShares,
$objectData
);
return;
}
$currentUser = $this->userSession->getUser();
if ($currentUser instanceof IUser) {
$currentUser = $currentUser->getUID();
} else {
$currentUser = $targetOwner;
}
$classification = $objectData['classification'] ?? CalDavBackend::CLASSIFICATION_PUBLIC;
$object = $this->getObjectNameAndType($objectData);
if (!$object) {
return;
}
$event = $this->activityManager->generateEvent();
$event->setApp('dav')
->setObject('calendar', (int) $targetCalendarData['id'])
->setType($object['type'] === 'event' ? 'calendar_event' : 'calendar_todo')
->setAuthor($currentUser);
$users = $this->getUsersForShares(array_intersect($sourceShares, $targetShares));
$users[] = $targetOwner;
// 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 !== $targetOwner) {
// Private events are only shown to the owner
continue;
}
$params = [
'actor' => $event->getAuthor(),
'sourceCalendar' => [
'id' => (int) $sourceCalendarData['id'],
'uri' => $sourceCalendarData['uri'],
'name' => $sourceCalendarData['{DAV:}displayname'],
],
'targetCalendar' => [
'id' => (int) $targetCalendarData['id'],
'uri' => $targetCalendarData['uri'],
'name' => $targetCalendarData['{DAV:}displayname'],
],
'object' => [
'id' => $object['id'],
'name' => $classification === CalDavBackend::CLASSIFICATION_CONFIDENTIAL && $user !== $targetOwner ? 'Busy' : $object['name'],
'classified' => $classification === CalDavBackend::CLASSIFICATION_CONFIDENTIAL && $user !== $targetOwner,
],
];
if ($object['type'] === 'event' && $this->appManager->isEnabledForUser('calendar')) {
$params['object']['link']['object_uri'] = $objectData['uri'];
$params['object']['link']['calendar_uri'] = $targetCalendarData['uri'];
$params['object']['link']['owner'] = $targetOwner;
}
$event->setAffectedUser($user)
->setSubject(
$user === $currentUser ? Event::SUBJECT_OBJECT_MOVE . '_' . $object['type'] . '_self' : Event::SUBJECT_OBJECT_MOVE . '_' . $object['type'],
$params
);
$this->activityManager->publish($event);
}
}
/**
* @param array $objectData
* @return string[]|false
*/
protected function getObjectNameAndType(array $objectData) {
$vObject = Reader::read($objectData['calendardata']);
$component = $componentType = null;
foreach ($vObject->getComponents() as $component) {
if (in_array($component->name, ['VEVENT', 'VTODO'])) {
$componentType = $component->name;
break;
}
}
if (!$componentType) {
// Calendar objects must have a VEVENT or VTODO component
return false;
}
if ($componentType === 'VEVENT') {
return ['id' => (string) $component->UID, 'name' => (string) $component->SUMMARY, 'type' => 'event'];
}
return ['id' => (string) $component->UID, 'name' => (string) $component->SUMMARY, 'type' => 'todo', 'status' => (string) $component->STATUS];
}
/**
* Get all users that have access to a given calendar
*
* @param array $shares
* @return string[]
*/
protected function getUsersForShares(array $shares) {
$users = $groups = [];
foreach ($shares as $share) {
$principal = explode('/', $share['{http://owncloud.org/ns}principal']);
if ($principal[1] === 'users') {
$users[] = $principal[2];
} elseif ($principal[1] === 'groups') {
$groups[] = $principal[2];
}
}
if (!empty($groups)) {
foreach ($groups as $gid) {
$group = $this->groupManager->get($gid);
if ($group instanceof IGroup) {
foreach ($group->getUsers() as $user) {
$users[] = $user->getUID();
}
}
}
}
return array_unique($users);
}
}
@@ -0,0 +1,93 @@
<?php
/**
* @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com>
*
* @author Joas Schilling <coding@schilljs.com>
* @author John Molakvoæ <skjnldsv@protonmail.com>
*
* @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
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\DAV\CalDAV\Activity\Filter;
use OCP\Activity\IFilter;
use OCP\IL10N;
use OCP\IURLGenerator;
class Calendar implements IFilter {
/** @var IL10N */
protected $l;
/** @var IURLGenerator */
protected $url;
public function __construct(IL10N $l, IURLGenerator $url) {
$this->l = $l;
$this->url = $url;
}
/**
* @return string Lowercase a-z and underscore only identifier
* @since 11.0.0
*/
public function getIdentifier() {
return 'calendar';
}
/**
* @return string A translated string
* @since 11.0.0
*/
public function getName() {
return $this->l->t('Calendar');
}
/**
* @return int whether the filter should be rather on the top or bottom of
* the admin section. The filters are arranged in ascending order of the
* priority values. It is required to return a value between 0 and 100.
* @since 11.0.0
*/
public function getPriority() {
return 40;
}
/**
* @return string Full URL to an icon, empty string when none is given
* @since 11.0.0
*/
public function getIcon() {
return $this->url->getAbsoluteURL($this->url->imagePath('core', 'places/calendar.svg'));
}
/**
* @param string[] $types
* @return string[] An array of allowed apps from which activities should be displayed
* @since 11.0.0
*/
public function filterTypes(array $types) {
return array_intersect(['calendar', 'calendar_event'], $types);
}
/**
* @return string[] An array of allowed apps from which activities should be displayed
* @since 11.0.0
*/
public function allowedApps() {
return [];
}
}
@@ -0,0 +1,92 @@
<?php
/**
* @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com>
*
* @author Joas Schilling <coding@schilljs.com>
*
* @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
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\DAV\CalDAV\Activity\Filter;
use OCP\Activity\IFilter;
use OCP\IL10N;
use OCP\IURLGenerator;
class Todo implements IFilter {
/** @var IL10N */
protected $l;
/** @var IURLGenerator */
protected $url;
public function __construct(IL10N $l, IURLGenerator $url) {
$this->l = $l;
$this->url = $url;
}
/**
* @return string Lowercase a-z and underscore only identifier
* @since 11.0.0
*/
public function getIdentifier() {
return 'calendar_todo';
}
/**
* @return string A translated string
* @since 11.0.0
*/
public function getName() {
return $this->l->t('To-dos');
}
/**
* @return int whether the filter should be rather on the top or bottom of
* the admin section. The filters are arranged in ascending order of the
* priority values. It is required to return a value between 0 and 100.
* @since 11.0.0
*/
public function getPriority() {
return 40;
}
/**
* @return string Full URL to an icon, empty string when none is given
* @since 11.0.0
*/
public function getIcon() {
return $this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/checkmark.svg'));
}
/**
* @param string[] $types
* @return string[] An array of allowed apps from which activities should be displayed
* @since 11.0.0
*/
public function filterTypes(array $types) {
return array_intersect(['calendar_todo'], $types);
}
/**
* @return string[] An array of allowed apps from which activities should be displayed
* @since 11.0.0
*/
public function allowedApps() {
return [];
}
}
@@ -0,0 +1,133 @@
<?php
/**
* @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
*
* 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
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\DAV\CalDAV\Activity\Provider;
use OCA\DAV\CalDAV\CalDavBackend;
use OCP\Activity\IEvent;
use OCP\Activity\IProvider;
use OCP\IGroup;
use OCP\IGroupManager;
use OCP\IL10N;
use OCP\IURLGenerator;
use OCP\IUserManager;
abstract class Base implements IProvider {
/** @var IUserManager */
protected $userManager;
/** @var IGroupManager */
protected $groupManager;
/** @var string[] */
protected $groupDisplayNames = [];
/** @var IURLGenerator */
protected $url;
/**
* @param IUserManager $userManager
* @param IGroupManager $groupManager
* @param IURLGenerator $urlGenerator
*/
public function __construct(IUserManager $userManager, IGroupManager $groupManager, IURLGenerator $urlGenerator) {
$this->userManager = $userManager;
$this->groupManager = $groupManager;
$this->url = $urlGenerator;
}
protected function setSubjects(IEvent $event, string $subject, array $parameters): void {
$event->setRichSubject($subject, $parameters);
}
/**
* @param array $data
* @param IL10N $l
* @return array
*/
protected function generateCalendarParameter($data, IL10N $l) {
if ($data['uri'] === CalDavBackend::PERSONAL_CALENDAR_URI &&
$data['name'] === CalDavBackend::PERSONAL_CALENDAR_NAME) {
return [
'type' => 'calendar',
'id' => $data['id'],
'name' => $l->t('Personal'),
];
}
return [
'type' => 'calendar',
'id' => $data['id'],
'name' => $data['name'],
];
}
/**
* @param int $id
* @param string $name
* @return array
*/
protected function generateLegacyCalendarParameter($id, $name) {
return [
'type' => 'calendar',
'id' => $id,
'name' => $name,
];
}
protected function generateUserParameter(string $uid): array {
return [
'type' => 'user',
'id' => $uid,
'name' => $this->userManager->getDisplayName($uid) ?? $uid,
];
}
/**
* @param string $gid
* @return array
*/
protected function generateGroupParameter($gid) {
if (!isset($this->groupDisplayNames[$gid])) {
$this->groupDisplayNames[$gid] = $this->getGroupDisplayName($gid);
}
return [
'type' => 'user-group',
'id' => $gid,
'name' => $this->groupDisplayNames[$gid],
];
}
/**
* @param string $gid
* @return string
*/
protected function getGroupDisplayName($gid) {
$group = $this->groupManager->get($gid);
if ($group instanceof IGroup) {
return $group->getDisplayName();
}
return $gid;
}
}
@@ -0,0 +1,277 @@
<?php
/**
* @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com>
*
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
* @author Joas Schilling <coding@schilljs.com>
* @author Julius Härtl <jus@bitgrid.net>
* @author Morris Jobke <hey@morrisjobke.de>
* @author Thomas Citharel <nextcloud@tcit.fr>
*
* @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
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\DAV\CalDAV\Activity\Provider;
use OCP\Activity\IEvent;
use OCP\Activity\IEventMerger;
use OCP\Activity\IManager;
use OCP\IGroupManager;
use OCP\IL10N;
use OCP\IURLGenerator;
use OCP\IUserManager;
use OCP\L10N\IFactory;
class Calendar extends Base {
public const SUBJECT_ADD = 'calendar_add';
public const SUBJECT_UPDATE = 'calendar_update';
public const SUBJECT_MOVE_TO_TRASH = 'calendar_move_to_trash';
public const SUBJECT_RESTORE = 'calendar_restore';
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';
/** @var IFactory */
protected $languageFactory;
/** @var IL10N */
protected $l;
/** @var IManager */
protected $activityManager;
/** @var IEventMerger */
protected $eventMerger;
/**
* @param IFactory $languageFactory
* @param IURLGenerator $url
* @param IManager $activityManager
* @param IUserManager $userManager
* @param IGroupManager $groupManager
* @param IEventMerger $eventMerger
*/
public function __construct(IFactory $languageFactory, IURLGenerator $url, IManager $activityManager, IUserManager $userManager, IGroupManager $groupManager, IEventMerger $eventMerger) {
parent::__construct($userManager, $groupManager, $url);
$this->languageFactory = $languageFactory;
$this->activityManager = $activityManager;
$this->eventMerger = $eventMerger;
}
/**
* @param string $language
* @param IEvent $event
* @param IEvent|null $previousEvent
* @return IEvent
* @throws \InvalidArgumentException
* @since 11.0.0
*/
public function parse($language, IEvent $event, IEvent $previousEvent = null) {
if ($event->getApp() !== 'dav' || $event->getType() !== 'calendar') {
throw new \InvalidArgumentException();
}
$this->l = $this->languageFactory->get('dav', $language);
if ($this->activityManager->getRequirePNG()) {
$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'places/calendar-dark.png')));
} else {
$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'places/calendar.svg')));
}
if ($event->getSubject() === self::SUBJECT_ADD) {
$subject = $this->l->t('{actor} created calendar {calendar}');
} elseif ($event->getSubject() === self::SUBJECT_ADD . '_self') {
$subject = $this->l->t('You created calendar {calendar}');
} elseif ($event->getSubject() === self::SUBJECT_DELETE) {
$subject = $this->l->t('{actor} deleted calendar {calendar}');
} elseif ($event->getSubject() === self::SUBJECT_DELETE . '_self') {
$subject = $this->l->t('You deleted calendar {calendar}');
} elseif ($event->getSubject() === self::SUBJECT_UPDATE) {
$subject = $this->l->t('{actor} updated calendar {calendar}');
} elseif ($event->getSubject() === self::SUBJECT_UPDATE . '_self') {
$subject = $this->l->t('You updated calendar {calendar}');
} elseif ($event->getSubject() === self::SUBJECT_MOVE_TO_TRASH) {
$subject = $this->l->t('{actor} deleted calendar {calendar}');
} elseif ($event->getSubject() === self::SUBJECT_MOVE_TO_TRASH . '_self') {
$subject = $this->l->t('You deleted calendar {calendar}');
} elseif ($event->getSubject() === self::SUBJECT_RESTORE) {
$subject = $this->l->t('{actor} restored calendar {calendar}');
} elseif ($event->getSubject() === self::SUBJECT_RESTORE . '_self') {
$subject = $this->l->t('You restored calendar {calendar}');
} elseif ($event->getSubject() === self::SUBJECT_PUBLISH . '_self') {
$subject = $this->l->t('You shared calendar {calendar} as public link');
} elseif ($event->getSubject() === self::SUBJECT_UNPUBLISH . '_self') {
$subject = $this->l->t('You removed public link for calendar {calendar}');
} elseif ($event->getSubject() === self::SUBJECT_SHARE_USER) {
$subject = $this->l->t('{actor} shared calendar {calendar} with you');
} elseif ($event->getSubject() === self::SUBJECT_SHARE_USER . '_you') {
$subject = $this->l->t('You shared calendar {calendar} with {user}');
} elseif ($event->getSubject() === self::SUBJECT_SHARE_USER . '_by') {
$subject = $this->l->t('{actor} shared calendar {calendar} with {user}');
} elseif ($event->getSubject() === self::SUBJECT_UNSHARE_USER) {
$subject = $this->l->t('{actor} unshared calendar {calendar} from you');
} elseif ($event->getSubject() === self::SUBJECT_UNSHARE_USER . '_you') {
$subject = $this->l->t('You unshared calendar {calendar} from {user}');
} elseif ($event->getSubject() === self::SUBJECT_UNSHARE_USER . '_by') {
$subject = $this->l->t('{actor} unshared calendar {calendar} from {user}');
} elseif ($event->getSubject() === self::SUBJECT_UNSHARE_USER . '_self') {
$subject = $this->l->t('{actor} unshared calendar {calendar} from themselves');
} elseif ($event->getSubject() === self::SUBJECT_SHARE_GROUP . '_you') {
$subject = $this->l->t('You shared calendar {calendar} with group {group}');
} elseif ($event->getSubject() === self::SUBJECT_SHARE_GROUP . '_by') {
$subject = $this->l->t('{actor} shared calendar {calendar} with group {group}');
} elseif ($event->getSubject() === self::SUBJECT_UNSHARE_GROUP . '_you') {
$subject = $this->l->t('You unshared calendar {calendar} from group {group}');
} elseif ($event->getSubject() === self::SUBJECT_UNSHARE_GROUP . '_by') {
$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);
} elseif (isset($parsedParameters['group'])) {
// 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();
// 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':
case self::SUBJECT_MOVE_TO_TRASH:
case self::SUBJECT_MOVE_TO_TRASH . '_self':
case self::SUBJECT_RESTORE:
case self::SUBJECT_RESTORE . '_self':
case self::SUBJECT_PUBLISH . '_self':
case self::SUBJECT_UNPUBLISH . '_self':
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']),
];
}
}
// 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.
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':
case self::SUBJECT_PUBLISH . '_self':
case self::SUBJECT_UNPUBLISH . '_self':
case self::SUBJECT_SHARE_USER:
case self::SUBJECT_UNSHARE_USER:
case self::SUBJECT_UNSHARE_USER . '_self':
return [
'actor' => $this->generateUserParameter($parameters[0]),
'calendar' => $this->generateLegacyCalendarParameter($event->getObjectId(), $parameters[1]),
];
case self::SUBJECT_SHARE_USER . '_you':
case self::SUBJECT_UNSHARE_USER . '_you':
return [
'user' => $this->generateUserParameter($parameters[0]),
'calendar' => $this->generateLegacyCalendarParameter($event->getObjectId(), $parameters[1]),
];
case self::SUBJECT_SHARE_USER . '_by':
case self::SUBJECT_UNSHARE_USER . '_by':
return [
'user' => $this->generateUserParameter($parameters[0]),
'calendar' => $this->generateLegacyCalendarParameter($event->getObjectId(), $parameters[1]),
'actor' => $this->generateUserParameter($parameters[2]),
];
case self::SUBJECT_SHARE_GROUP . '_you':
case self::SUBJECT_UNSHARE_GROUP . '_you':
return [
'group' => $this->generateGroupParameter($parameters[0]),
'calendar' => $this->generateLegacyCalendarParameter($event->getObjectId(), $parameters[1]),
];
case self::SUBJECT_SHARE_GROUP . '_by':
case self::SUBJECT_UNSHARE_GROUP . '_by':
return [
'group' => $this->generateGroupParameter($parameters[0]),
'calendar' => $this->generateLegacyCalendarParameter($event->getObjectId(), $parameters[1]),
'actor' => $this->generateUserParameter($parameters[2]),
];
}
throw new \InvalidArgumentException();
}
}
@@ -0,0 +1,257 @@
<?php
/**
* @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com>
*
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
* @author Joas Schilling <coding@schilljs.com>
* @author Julius Härtl <jus@bitgrid.net>
* @author Morris Jobke <hey@morrisjobke.de>
* @author Thomas Citharel <nextcloud@tcit.fr>
*
* @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
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
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;
use OCP\IUserManager;
use OCP\L10N\IFactory;
class Event extends Base {
public const SUBJECT_OBJECT_ADD = 'object_add';
public const SUBJECT_OBJECT_UPDATE = 'object_update';
public const SUBJECT_OBJECT_MOVE = 'object_move';
public const SUBJECT_OBJECT_MOVE_TO_TRASH = 'object_move_to_trash';
public const SUBJECT_OBJECT_RESTORE = 'object_restore';
public const SUBJECT_OBJECT_DELETE = 'object_delete';
/** @var IFactory */
protected $languageFactory;
/** @var IL10N */
protected $l;
/** @var IManager */
protected $activityManager;
/** @var IEventMerger */
protected $eventMerger;
/** @var IAppManager */
protected $appManager;
/**
* @param IFactory $languageFactory
* @param IURLGenerator $url
* @param IManager $activityManager
* @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, IAppManager $appManager) {
parent::__construct($userManager, $groupManager, $url);
$this->languageFactory = $languageFactory;
$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' => trim($eventData['name']) !== '' ? $eventData['name'] : $this->l->t('Untitled event'),
];
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($this->url->getWebroot() . '/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;
}
/**
* @param string $language
* @param IEvent $event
* @param IEvent|null $previousEvent
* @return IEvent
* @throws \InvalidArgumentException
* @since 11.0.0
*/
public function parse($language, IEvent $event, IEvent $previousEvent = null) {
if ($event->getApp() !== 'dav' || $event->getType() !== 'calendar_event') {
throw new \InvalidArgumentException();
}
$this->l = $this->languageFactory->get('dav', $language);
if ($this->activityManager->getRequirePNG()) {
$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'places/calendar-dark.png')));
} else {
$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'places/calendar.svg')));
}
if ($event->getSubject() === self::SUBJECT_OBJECT_ADD . '_event') {
$subject = $this->l->t('{actor} created event {event} in calendar {calendar}');
} elseif ($event->getSubject() === self::SUBJECT_OBJECT_ADD . '_event_self') {
$subject = $this->l->t('You created event {event} in calendar {calendar}');
} elseif ($event->getSubject() === self::SUBJECT_OBJECT_DELETE . '_event') {
$subject = $this->l->t('{actor} deleted event {event} from calendar {calendar}');
} elseif ($event->getSubject() === self::SUBJECT_OBJECT_DELETE . '_event_self') {
$subject = $this->l->t('You deleted event {event} from calendar {calendar}');
} elseif ($event->getSubject() === self::SUBJECT_OBJECT_UPDATE . '_event') {
$subject = $this->l->t('{actor} updated event {event} in calendar {calendar}');
} elseif ($event->getSubject() === self::SUBJECT_OBJECT_UPDATE . '_event_self') {
$subject = $this->l->t('You updated event {event} in calendar {calendar}');
} elseif ($event->getSubject() === self::SUBJECT_OBJECT_MOVE . '_event') {
$subject = $this->l->t('{actor} moved event {event} from calendar {sourceCalendar} to calendar {targetCalendar}');
} elseif ($event->getSubject() === self::SUBJECT_OBJECT_MOVE . '_event_self') {
$subject = $this->l->t('You moved event {event} from calendar {sourceCalendar} to calendar {targetCalendar}');
} elseif ($event->getSubject() === self::SUBJECT_OBJECT_MOVE_TO_TRASH . '_event') {
$subject = $this->l->t('{actor} deleted event {event} from calendar {calendar}');
} elseif ($event->getSubject() === self::SUBJECT_OBJECT_MOVE_TO_TRASH . '_event_self') {
$subject = $this->l->t('You deleted event {event} from calendar {calendar}');
} elseif ($event->getSubject() === self::SUBJECT_OBJECT_RESTORE . '_event') {
$subject = $this->l->t('{actor} restored event {event} of calendar {calendar}');
} elseif ($event->getSubject() === self::SUBJECT_OBJECT_RESTORE . '_event_self') {
$subject = $this->l->t('You restored event {event} of calendar {calendar}');
} else {
throw new \InvalidArgumentException();
}
$parsedParameters = $this->getParameters($event);
$this->setSubjects($event, $subject, $parsedParameters);
$event = $this->eventMerger->mergeEvents('event', $event, $previousEvent);
return $event;
}
/**
* @param IEvent $event
* @return array
*/
protected function getParameters(IEvent $event) {
$subject = $event->getSubject();
$parameters = $event->getSubjectParameters();
// Nextcloud 13+
if (isset($parameters['calendar'])) {
switch ($subject) {
case self::SUBJECT_OBJECT_ADD . '_event':
case self::SUBJECT_OBJECT_DELETE . '_event':
case self::SUBJECT_OBJECT_UPDATE . '_event':
case self::SUBJECT_OBJECT_MOVE_TO_TRASH . '_event':
case self::SUBJECT_OBJECT_RESTORE . '_event':
return [
'actor' => $this->generateUserParameter($parameters['actor']),
'calendar' => $this->generateCalendarParameter($parameters['calendar'], $this->l),
'event' => $this->generateClassifiedObjectParameter($parameters['object']),
];
case self::SUBJECT_OBJECT_ADD . '_event_self':
case self::SUBJECT_OBJECT_DELETE . '_event_self':
case self::SUBJECT_OBJECT_UPDATE . '_event_self':
case self::SUBJECT_OBJECT_MOVE_TO_TRASH . '_event_self':
case self::SUBJECT_OBJECT_RESTORE . '_event_self':
return [
'calendar' => $this->generateCalendarParameter($parameters['calendar'], $this->l),
'event' => $this->generateClassifiedObjectParameter($parameters['object']),
];
}
}
if (isset($parameters['sourceCalendar']) && isset($parameters['targetCalendar'])) {
switch ($subject) {
case self::SUBJECT_OBJECT_MOVE . '_event':
return [
'actor' => $this->generateUserParameter($parameters['actor']),
'sourceCalendar' => $this->generateCalendarParameter($parameters['sourceCalendar'], $this->l),
'targetCalendar' => $this->generateCalendarParameter($parameters['targetCalendar'], $this->l),
'event' => $this->generateClassifiedObjectParameter($parameters['object']),
];
case self::SUBJECT_OBJECT_MOVE . '_event_self':
return [
'sourceCalendar' => $this->generateCalendarParameter($parameters['sourceCalendar'], $this->l),
'targetCalendar' => $this->generateCalendarParameter($parameters['targetCalendar'], $this->l),
'event' => $this->generateClassifiedObjectParameter($parameters['object']),
];
}
}
// 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.
switch ($subject) {
case self::SUBJECT_OBJECT_ADD . '_event':
case self::SUBJECT_OBJECT_DELETE . '_event':
case self::SUBJECT_OBJECT_UPDATE . '_event':
return [
'actor' => $this->generateUserParameter($parameters[0]),
'calendar' => $this->generateLegacyCalendarParameter($event->getObjectId(), $parameters[1]),
'event' => $this->generateObjectParameter($parameters[2]),
];
case self::SUBJECT_OBJECT_ADD . '_event_self':
case self::SUBJECT_OBJECT_DELETE . '_event_self':
case self::SUBJECT_OBJECT_UPDATE . '_event_self':
return [
'calendar' => $this->generateLegacyCalendarParameter($event->getObjectId(), $parameters[1]),
'event' => $this->generateObjectParameter($parameters[2]),
];
}
throw new \InvalidArgumentException();
}
private function generateClassifiedObjectParameter(array $eventData) {
$parameter = $this->generateObjectParameter($eventData);
if (!empty($eventData['classified'])) {
$parameter['name'] = $this->l->t('Busy');
}
return $parameter;
}
}
@@ -0,0 +1,168 @@
<?php
/**
* @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com>
*
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
* @author Joas Schilling <coding@schilljs.com>
* @author Morris Jobke <hey@morrisjobke.de>
*
* @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
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\DAV\CalDAV\Activity\Provider;
use OCP\Activity\IEvent;
class Todo extends Event {
/**
* @param string $language
* @param IEvent $event
* @param IEvent|null $previousEvent
* @return IEvent
* @throws \InvalidArgumentException
* @since 11.0.0
*/
public function parse($language, IEvent $event, IEvent $previousEvent = null) {
if ($event->getApp() !== 'dav' || $event->getType() !== 'calendar_todo') {
throw new \InvalidArgumentException();
}
$this->l = $this->languageFactory->get('dav', $language);
if ($this->activityManager->getRequirePNG()) {
$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/checkmark.png')));
} else {
$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/checkmark.svg')));
}
if ($event->getSubject() === self::SUBJECT_OBJECT_ADD . '_todo') {
$subject = $this->l->t('{actor} created to-do {todo} in list {calendar}');
} elseif ($event->getSubject() === self::SUBJECT_OBJECT_ADD . '_todo_self') {
$subject = $this->l->t('You created to-do {todo} in list {calendar}');
} elseif ($event->getSubject() === self::SUBJECT_OBJECT_DELETE . '_todo') {
$subject = $this->l->t('{actor} deleted to-do {todo} from list {calendar}');
} elseif ($event->getSubject() === self::SUBJECT_OBJECT_DELETE . '_todo_self') {
$subject = $this->l->t('You deleted to-do {todo} from list {calendar}');
} elseif ($event->getSubject() === self::SUBJECT_OBJECT_UPDATE . '_todo') {
$subject = $this->l->t('{actor} updated to-do {todo} in list {calendar}');
} elseif ($event->getSubject() === self::SUBJECT_OBJECT_UPDATE . '_todo_self') {
$subject = $this->l->t('You updated to-do {todo} in list {calendar}');
} elseif ($event->getSubject() === self::SUBJECT_OBJECT_UPDATE . '_todo_completed') {
$subject = $this->l->t('{actor} solved to-do {todo} in list {calendar}');
} elseif ($event->getSubject() === self::SUBJECT_OBJECT_UPDATE . '_todo_completed_self') {
$subject = $this->l->t('You solved to-do {todo} in list {calendar}');
} elseif ($event->getSubject() === self::SUBJECT_OBJECT_UPDATE . '_todo_needs_action') {
$subject = $this->l->t('{actor} reopened to-do {todo} in list {calendar}');
} elseif ($event->getSubject() === self::SUBJECT_OBJECT_UPDATE . '_todo_needs_action_self') {
$subject = $this->l->t('You reopened to-do {todo} in list {calendar}');
} elseif ($event->getSubject() === self::SUBJECT_OBJECT_MOVE . '_todo') {
$subject = $this->l->t('{actor} moved to-do {todo} from list {sourceCalendar} to list {targetCalendar}');
} elseif ($event->getSubject() === self::SUBJECT_OBJECT_MOVE . '_todo_self') {
$subject = $this->l->t('You moved to-do {todo} from list {sourceCalendar} to list {targetCalendar}');
} else {
throw new \InvalidArgumentException();
}
$parsedParameters = $this->getParameters($event);
$this->setSubjects($event, $subject, $parsedParameters);
$event = $this->eventMerger->mergeEvents('todo', $event, $previousEvent);
return $event;
}
/**
* @param IEvent $event
* @return array
*/
protected function getParameters(IEvent $event) {
$subject = $event->getSubject();
$parameters = $event->getSubjectParameters();
// Nextcloud 13+
if (isset($parameters['calendar'])) {
switch ($subject) {
case self::SUBJECT_OBJECT_ADD . '_todo':
case self::SUBJECT_OBJECT_DELETE . '_todo':
case self::SUBJECT_OBJECT_UPDATE . '_todo':
case self::SUBJECT_OBJECT_UPDATE . '_todo_completed':
case self::SUBJECT_OBJECT_UPDATE . '_todo_needs_action':
return [
'actor' => $this->generateUserParameter($parameters['actor']),
'calendar' => $this->generateCalendarParameter($parameters['calendar'], $this->l),
'todo' => $this->generateObjectParameter($parameters['object']),
];
case self::SUBJECT_OBJECT_ADD . '_todo_self':
case self::SUBJECT_OBJECT_DELETE . '_todo_self':
case self::SUBJECT_OBJECT_UPDATE . '_todo_self':
case self::SUBJECT_OBJECT_UPDATE . '_todo_completed_self':
case self::SUBJECT_OBJECT_UPDATE . '_todo_needs_action_self':
return [
'calendar' => $this->generateCalendarParameter($parameters['calendar'], $this->l),
'todo' => $this->generateObjectParameter($parameters['object']),
];
}
}
if (isset($parameters['sourceCalendar']) && isset($parameters['targetCalendar'])) {
switch ($subject) {
case self::SUBJECT_OBJECT_MOVE . '_todo':
return [
'actor' => $this->generateUserParameter($parameters['actor']),
'sourceCalendar' => $this->generateCalendarParameter($parameters['sourceCalendar'], $this->l),
'targetCalendar' => $this->generateCalendarParameter($parameters['targetCalendar'], $this->l),
'todo' => $this->generateObjectParameter($parameters['object']),
];
case self::SUBJECT_OBJECT_MOVE . '_todo_self':
return [
'sourceCalendar' => $this->generateCalendarParameter($parameters['sourceCalendar'], $this->l),
'targetCalendar' => $this->generateCalendarParameter($parameters['targetCalendar'], $this->l),
'todo' => $this->generateObjectParameter($parameters['object']),
];
}
}
// 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.
switch ($subject) {
case self::SUBJECT_OBJECT_ADD . '_todo':
case self::SUBJECT_OBJECT_DELETE . '_todo':
case self::SUBJECT_OBJECT_UPDATE . '_todo':
case self::SUBJECT_OBJECT_UPDATE . '_todo_completed':
case self::SUBJECT_OBJECT_UPDATE . '_todo_needs_action':
return [
'actor' => $this->generateUserParameter($parameters[0]),
'calendar' => $this->generateLegacyCalendarParameter($event->getObjectId(), $parameters[1]),
'todo' => $this->generateObjectParameter($parameters[2]),
];
case self::SUBJECT_OBJECT_ADD . '_todo_self':
case self::SUBJECT_OBJECT_DELETE . '_todo_self':
case self::SUBJECT_OBJECT_UPDATE . '_todo_self':
case self::SUBJECT_OBJECT_UPDATE . '_todo_completed_self':
case self::SUBJECT_OBJECT_UPDATE . '_todo_needs_action_self':
return [
'calendar' => $this->generateLegacyCalendarParameter($event->getObjectId(), $parameters[1]),
'todo' => $this->generateObjectParameter($parameters[2]),
];
}
throw new \InvalidArgumentException();
}
}
@@ -0,0 +1,50 @@
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2020 Robin Appelman <robin@icewind.nl>
*
* @author Joas Schilling <coding@schilljs.com>
* @author Robin Appelman <robin@icewind.nl>
*
* @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
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\DAV\CalDAV\Activity\Setting;
use OCP\Activity\ActivitySettings;
use OCP\IL10N;
abstract class CalDAVSetting extends ActivitySettings {
/** @var IL10N */
protected $l;
/**
* @param IL10N $l
*/
public function __construct(IL10N $l) {
$this->l = $l;
}
public function getGroupIdentifier() {
return 'calendar';
}
public function getGroupName() {
return $this->l->t('Calendar, contacts and tasks');
}
}
@@ -0,0 +1,84 @@
<?php
/**
* @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com>
*
* @author Joas Schilling <coding@schilljs.com>
* @author Robin Appelman <robin@icewind.nl>
*
* @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
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\DAV\CalDAV\Activity\Setting;
class Calendar extends CalDAVSetting {
/**
* @return string Lowercase a-z and underscore only identifier
* @since 11.0.0
*/
public function getIdentifier() {
return 'calendar';
}
/**
* @return string A translated string
* @since 11.0.0
*/
public function getName() {
return $this->l->t('A <strong>calendar</strong> was modified');
}
/**
* @return int whether the filter should be rather on the top or bottom of
* the admin section. The filters are arranged in ascending order of the
* priority values. It is required to return a value between 0 and 100.
* @since 11.0.0
*/
public function getPriority() {
return 50;
}
/**
* @return bool True when the option can be changed for the stream
* @since 11.0.0
*/
public function canChangeStream() {
return true;
}
/**
* @return bool True when the option can be changed for the stream
* @since 11.0.0
*/
public function isDefaultEnabledStream() {
return true;
}
/**
* @return bool True when the option can be changed for the mail
* @since 11.0.0
*/
public function canChangeMail() {
return true;
}
/**
* @return bool True when the option can be changed for the stream
* @since 11.0.0
*/
public function isDefaultEnabledMail() {
return false;
}
}
@@ -0,0 +1,84 @@
<?php
/**
* @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com>
*
* @author Joas Schilling <coding@schilljs.com>
* @author Robin Appelman <robin@icewind.nl>
*
* @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
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\DAV\CalDAV\Activity\Setting;
class Event extends CalDAVSetting {
/**
* @return string Lowercase a-z and underscore only identifier
* @since 11.0.0
*/
public function getIdentifier() {
return 'calendar_event';
}
/**
* @return string A translated string
* @since 11.0.0
*/
public function getName() {
return $this->l->t('A calendar <strong>event</strong> was modified');
}
/**
* @return int whether the filter should be rather on the top or bottom of
* the admin section. The filters are arranged in ascending order of the
* priority values. It is required to return a value between 0 and 100.
* @since 11.0.0
*/
public function getPriority() {
return 50;
}
/**
* @return bool True when the option can be changed for the stream
* @since 11.0.0
*/
public function canChangeStream() {
return true;
}
/**
* @return bool True when the option can be changed for the stream
* @since 11.0.0
*/
public function isDefaultEnabledStream() {
return true;
}
/**
* @return bool True when the option can be changed for the mail
* @since 11.0.0
*/
public function canChangeMail() {
return true;
}
/**
* @return bool True when the option can be changed for the stream
* @since 11.0.0
*/
public function isDefaultEnabledMail() {
return false;
}
}
@@ -0,0 +1,85 @@
<?php
/**
* @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com>
*
* @author Joas Schilling <coding@schilljs.com>
* @author Robin Appelman <robin@icewind.nl>
*
* @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
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\DAV\CalDAV\Activity\Setting;
class Todo extends CalDAVSetting {
/**
* @return string Lowercase a-z and underscore only identifier
* @since 11.0.0
*/
public function getIdentifier() {
return 'calendar_todo';
}
/**
* @return string A translated string
* @since 11.0.0
*/
public function getName() {
return $this->l->t('A calendar <strong>to-do</strong> was modified');
}
/**
* @return int whether the filter should be rather on the top or bottom of
* the admin section. The filters are arranged in ascending order of the
* priority values. It is required to return a value between 0 and 100.
* @since 11.0.0
*/
public function getPriority() {
return 50;
}
/**
* @return bool True when the option can be changed for the stream
* @since 11.0.0
*/
public function canChangeStream() {
return true;
}
/**
* @return bool True when the option can be changed for the stream
* @since 11.0.0
*/
public function isDefaultEnabledStream() {
return true;
}
/**
* @return bool True when the option can be changed for the mail
* @since 11.0.0
*/
public function canChangeMail() {
return true;
}
/**
* @return bool True when the option can be changed for the stream
* @since 11.0.0
*/
public function isDefaultEnabledMail() {
return false;
}
}