diff options
Diffstat (limited to 'apps/files_sharing/lib/Activity/Providers')
6 files changed, 115 insertions, 230 deletions
diff --git a/apps/files_sharing/lib/Activity/Providers/Base.php b/apps/files_sharing/lib/Activity/Providers/Base.php index 843a0c447f1..7428af382fc 100644 --- a/apps/files_sharing/lib/Activity/Providers/Base.php +++ b/apps/files_sharing/lib/Activity/Providers/Base.php @@ -1,78 +1,39 @@ <?php + /** - * @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com> - * - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @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/>. - * + * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ - namespace OCA\Files_Sharing\Activity\Providers; +use OCP\Activity\Exceptions\UnknownActivityException; use OCP\Activity\IEvent; +use OCP\Activity\IEventMerger; use OCP\Activity\IManager; use OCP\Activity\IProvider; use OCP\Contacts\IManager as IContactsManager; use OCP\Federation\ICloudIdManager; use OCP\IL10N; use OCP\IURLGenerator; -use OCP\IUser; use OCP\IUserManager; use OCP\L10N\IFactory; abstract class Base implements IProvider { - - /** @var IFactory */ - protected $languageFactory; - /** @var IL10N */ protected $l; - /** @var IURLGenerator */ - protected $url; - - /** @var IManager */ - protected $activityManager; - - /** @var IUserManager */ - protected $userManager; - - /** @var IContactsManager */ - protected $contactsManager; - - /** @var ICloudIdManager */ - protected $cloudIdManager; - /** @var array */ protected $displayNames = []; - public function __construct(IFactory $languageFactory, - IURLGenerator $url, - IManager $activityManager, - IUserManager $userManager, - ICloudIdManager $cloudIdManager, - IContactsManager $contactsManager) { - $this->languageFactory = $languageFactory; - $this->url = $url; - $this->activityManager = $activityManager; - $this->userManager = $userManager; - $this->cloudIdManager = $cloudIdManager; - $this->contactsManager = $contactsManager; + public function __construct( + protected IFactory $languageFactory, + protected IURLGenerator $url, + protected IManager $activityManager, + protected IUserManager $userManager, + protected ICloudIdManager $cloudIdManager, + protected IContactsManager $contactsManager, + protected IEventMerger $eventMerger, + ) { } /** @@ -80,12 +41,12 @@ abstract class Base implements IProvider { * @param IEvent $event * @param IEvent|null $previousEvent * @return IEvent - * @throws \InvalidArgumentException + * @throws UnknownActivityException * @since 11.0.0 */ - public function parse($language, IEvent $event, IEvent $previousEvent = null) { + public function parse($language, IEvent $event, ?IEvent $previousEvent = null) { if ($event->getApp() !== 'files_sharing') { - throw new \InvalidArgumentException(); + throw new UnknownActivityException(); } $this->l = $this->languageFactory->get('files_sharing', $language); @@ -98,7 +59,7 @@ abstract class Base implements IProvider { } } - return $this->parseLongVersion($event); + return $this->parseLongVersion($event, $previousEvent); } /** @@ -111,31 +72,18 @@ abstract class Base implements IProvider { /** * @param IEvent $event + * @param IEvent|null $previousEvent * @return IEvent * @throws \InvalidArgumentException * @since 11.0.0 */ - abstract protected function parseLongVersion(IEvent $event); + abstract protected function parseLongVersion(IEvent $event, ?IEvent $previousEvent = null); /** - * @param IEvent $event - * @param string $subject - * @param array $parameters * @throws \InvalidArgumentException */ - protected function setSubjects(IEvent $event, $subject, array $parameters) { - $placeholders = $replacements = []; - foreach ($parameters as $placeholder => $parameter) { - $placeholders[] = '{' . $placeholder . '}'; - if ($parameter['type'] === 'file') { - $replacements[] = $parameter['path']; - } else { - $replacements[] = $parameter['name']; - } - } - - $event->setParsedSubject(str_replace($placeholders, $replacements, $subject)) - ->setRichSubject($subject, $parameters); + protected function setSubjects(IEvent $event, string $subject, array $parameters): void { + $event->setRichSubject($subject, $parameters); } /** @@ -144,14 +92,13 @@ abstract class Base implements IProvider { * @return array * @throws \InvalidArgumentException */ - protected function getFile($parameter, IEvent $event = null) { + protected function getFile($parameter, ?IEvent $event = null) { if (is_array($parameter)) { $path = reset($parameter); - $id = (string) key($parameter); + $id = (string)key($parameter); } elseif ($event !== null) { - // Legacy from before ownCloud 8.2 $path = $parameter; - $id = $event->getObjectId(); + $id = (string)$event->getObjectId(); } else { throw new \InvalidArgumentException('Could not generate file parameter'); } @@ -167,16 +114,18 @@ abstract class Base implements IProvider { /** * @param string $uid + * @param string $overwriteDisplayName - overwrite display name, only if user is not local + * * @return array */ - protected function getUser($uid) { + protected function getUser(string $uid, string $overwriteDisplayName = '') { // First try local user - $user = $this->userManager->get($uid); - if ($user instanceof IUser) { + $displayName = $this->userManager->getDisplayName($uid); + if ($displayName !== null) { return [ 'type' => 'user', - 'id' => $user->getUID(), - 'name' => $user->getDisplayName(), + 'id' => $uid, + 'name' => $displayName, ]; } @@ -186,7 +135,7 @@ abstract class Base implements IProvider { return [ 'type' => 'user', 'id' => $cloudId->getUser(), - 'name' => $this->getDisplayNameFromAddressBook($cloudId->getDisplayId()), + 'name' => (($overwriteDisplayName !== '') ? $overwriteDisplayName : $this->getDisplayNameFromAddressBook($cloudId->getDisplayId())), 'server' => $cloudId->getRemote(), ]; } @@ -195,7 +144,7 @@ abstract class Base implements IProvider { return [ 'type' => 'user', 'id' => $uid, - 'name' => $uid, + 'name' => (($overwriteDisplayName !== '') ? $overwriteDisplayName : $uid), ]; } @@ -204,7 +153,12 @@ abstract class Base implements IProvider { return $this->displayNames[$search]; } - $addressBookContacts = $this->contactsManager->search($search, ['CLOUD']); + $addressBookContacts = $this->contactsManager->search($search, ['CLOUD'], [ + 'limit' => 1, + 'enumeration' => false, + 'fullmatch' => false, + 'strict_search' => true, + ]); foreach ($addressBookContacts as $contact) { if (isset($contact['isLocalSystemBook'])) { continue; diff --git a/apps/files_sharing/lib/Activity/Providers/Downloads.php b/apps/files_sharing/lib/Activity/Providers/Downloads.php index be019bdcd65..bddf2d30f73 100644 --- a/apps/files_sharing/lib/Activity/Providers/Downloads.php +++ b/apps/files_sharing/lib/Activity/Providers/Downloads.php @@ -1,27 +1,9 @@ <?php + /** - * @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com> - * - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @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/>. - * + * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ - namespace OCA\Files_Sharing\Activity\Providers; use OCP\Activity\IEvent; @@ -42,11 +24,11 @@ class Downloads extends Base { public function parseShortVersion(IEvent $event) { $parsedParameters = $this->getParsedParameters($event); - if ($event->getSubject() === self::SUBJECT_PUBLIC_SHARED_FILE_DOWNLOADED || - $event->getSubject() === self::SUBJECT_PUBLIC_SHARED_FOLDER_DOWNLOADED) { + if ($event->getSubject() === self::SUBJECT_PUBLIC_SHARED_FILE_DOWNLOADED + || $event->getSubject() === self::SUBJECT_PUBLIC_SHARED_FOLDER_DOWNLOADED) { $subject = $this->l->t('Downloaded via public link'); - } elseif ($event->getSubject() === self::SUBJECT_SHARED_FILE_BY_EMAIL_DOWNLOADED || - $event->getSubject() === self::SUBJECT_SHARED_FOLDER_BY_EMAIL_DOWNLOADED) { + } elseif ($event->getSubject() === self::SUBJECT_SHARED_FILE_BY_EMAIL_DOWNLOADED + || $event->getSubject() === self::SUBJECT_SHARED_FOLDER_BY_EMAIL_DOWNLOADED) { $subject = $this->l->t('Downloaded by {email}'); } else { throw new \InvalidArgumentException(); @@ -64,19 +46,28 @@ class Downloads extends Base { /** * @param IEvent $event + * @param IEvent|null $previousEvent * @return IEvent * @throws \InvalidArgumentException * @since 11.0.0 */ - public function parseLongVersion(IEvent $event) { + public function parseLongVersion(IEvent $event, ?IEvent $previousEvent = null) { $parsedParameters = $this->getParsedParameters($event); - if ($event->getSubject() === self::SUBJECT_PUBLIC_SHARED_FILE_DOWNLOADED || - $event->getSubject() === self::SUBJECT_PUBLIC_SHARED_FOLDER_DOWNLOADED) { - $subject = $this->l->t('{file} downloaded via public link'); - } elseif ($event->getSubject() === self::SUBJECT_SHARED_FILE_BY_EMAIL_DOWNLOADED || - $event->getSubject() === self::SUBJECT_SHARED_FOLDER_BY_EMAIL_DOWNLOADED) { + if ($event->getSubject() === self::SUBJECT_PUBLIC_SHARED_FILE_DOWNLOADED + || $event->getSubject() === self::SUBJECT_PUBLIC_SHARED_FOLDER_DOWNLOADED) { + if (!isset($parsedParameters['remote-address-hash']['type'])) { + $subject = $this->l->t('{file} downloaded via public link'); + $this->setSubjects($event, $subject, $parsedParameters); + } else { + $subject = $this->l->t('{file} downloaded via public link'); + $this->setSubjects($event, $subject, $parsedParameters); + $event = $this->eventMerger->mergeEvents('file', $event, $previousEvent); + } + } elseif ($event->getSubject() === self::SUBJECT_SHARED_FILE_BY_EMAIL_DOWNLOADED + || $event->getSubject() === self::SUBJECT_SHARED_FOLDER_BY_EMAIL_DOWNLOADED) { $subject = $this->l->t('{email} downloaded {file}'); + $this->setSubjects($event, $subject, $parsedParameters); } else { throw new \InvalidArgumentException(); } @@ -86,7 +77,6 @@ class Downloads extends Base { } else { $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/download.svg'))); } - $this->setSubjects($event, $subject, $parsedParameters); return $event; } @@ -103,6 +93,17 @@ class Downloads extends Base { switch ($subject) { case self::SUBJECT_PUBLIC_SHARED_FILE_DOWNLOADED: case self::SUBJECT_PUBLIC_SHARED_FOLDER_DOWNLOADED: + if (isset($parameters[1])) { + return [ + 'file' => $this->getFile($parameters[0], $event), + 'remote-address-hash' => [ + 'type' => 'highlight', + 'id' => $parameters[1], + 'name' => $parameters[1], + 'link' => '', + ], + ]; + } return [ 'file' => $this->getFile($parameters[0], $event), ]; diff --git a/apps/files_sharing/lib/Activity/Providers/Groups.php b/apps/files_sharing/lib/Activity/Providers/Groups.php index 53336057e37..d0086c05ced 100644 --- a/apps/files_sharing/lib/Activity/Providers/Groups.php +++ b/apps/files_sharing/lib/Activity/Providers/Groups.php @@ -1,31 +1,13 @@ <?php + /** - * @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com> - * - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @author Joas Schilling <coding@schilljs.com> - * @author John Molakvoæ (skjnldsv) <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/>. - * + * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ - namespace OCA\Files_Sharing\Activity\Providers; use OCP\Activity\IEvent; +use OCP\Activity\IEventMerger; use OCP\Activity\IManager; use OCP\Contacts\IManager as IContactsManager; use OCP\Federation\ICloudIdManager; @@ -44,21 +26,20 @@ class Groups extends Base { public const SUBJECT_EXPIRED_GROUP = 'expired_group'; - /** @var IGroupManager */ - protected $groupManager; - /** @var string[] */ protected $groupDisplayNames = []; - public function __construct(IFactory $languageFactory, - IURLGenerator $url, - IManager $activityManager, - IUserManager $userManager, - ICloudIdManager $cloudIdManager, - IContactsManager $contactsManager, - IGroupManager $groupManager) { - parent::__construct($languageFactory, $url, $activityManager, $userManager, $cloudIdManager, $contactsManager); - $this->groupManager = $groupManager; + public function __construct( + IFactory $languageFactory, + IURLGenerator $url, + IManager $activityManager, + IUserManager $userManager, + ICloudIdManager $cloudIdManager, + IContactsManager $contactsManager, + IEventMerger $eventMerger, + protected IGroupManager $groupManager, + ) { + parent::__construct($languageFactory, $url, $activityManager, $userManager, $cloudIdManager, $contactsManager, $eventMerger); } /** @@ -96,11 +77,12 @@ class Groups extends Base { /** * @param IEvent $event + * @param IEvent|null $previousEvent * @return IEvent * @throws \InvalidArgumentException * @since 11.0.0 */ - public function parseLongVersion(IEvent $event) { + public function parseLongVersion(IEvent $event, ?IEvent $previousEvent = null) { $parsedParameters = $this->getParsedParameters($event); if ($event->getSubject() === self::SUBJECT_SHARED_GROUP_SELF) { diff --git a/apps/files_sharing/lib/Activity/Providers/PublicLinks.php b/apps/files_sharing/lib/Activity/Providers/PublicLinks.php index 2742ded4007..15ffaf2cdb0 100644 --- a/apps/files_sharing/lib/Activity/Providers/PublicLinks.php +++ b/apps/files_sharing/lib/Activity/Providers/PublicLinks.php @@ -1,27 +1,9 @@ <?php + /** - * @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com> - * - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @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/>. - * + * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ - namespace OCA\Files_Sharing\Activity\Providers; use OCP\Activity\IEvent; @@ -71,11 +53,12 @@ class PublicLinks extends Base { /** * @param IEvent $event + * @param IEvent|null $previousEvent * @return IEvent * @throws \InvalidArgumentException * @since 11.0.0 */ - public function parseLongVersion(IEvent $event) { + public function parseLongVersion(IEvent $event, ?IEvent $previousEvent = null) { $parsedParameters = $this->getParsedParameters($event); if ($event->getSubject() === self::SUBJECT_SHARED_LINK_SELF) { diff --git a/apps/files_sharing/lib/Activity/Providers/RemoteShares.php b/apps/files_sharing/lib/Activity/Providers/RemoteShares.php index f2217f423ef..750d0747b62 100644 --- a/apps/files_sharing/lib/Activity/Providers/RemoteShares.php +++ b/apps/files_sharing/lib/Activity/Providers/RemoteShares.php @@ -1,31 +1,13 @@ <?php + /** - * @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com> - * - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @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/>. - * + * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ - namespace OCA\Files_Sharing\Activity\Providers; use OCP\Activity\IEvent; +use OCP\Activity\IEventMerger; use OCP\Activity\IManager; use OCP\Contacts\IManager as IContactsManager; use OCP\Federation\ICloudIdManager; @@ -40,13 +22,13 @@ class RemoteShares extends Base { public const SUBJECT_REMOTE_SHARE_UNSHARED = 'remote_share_unshared'; public function __construct(IFactory $languageFactory, - IURLGenerator $url, - IManager $activityManager, - IUserManager $userManager, - IContactsManager $contactsManager, - ICloudIdManager $cloudIdManager - ) { - parent::__construct($languageFactory, $url, $activityManager, $userManager, $cloudIdManager, $contactsManager); + IURLGenerator $url, + IManager $activityManager, + IUserManager $userManager, + ICloudIdManager $cloudIdManager, + IContactsManager $contactsManager, + IEventMerger $eventMerger) { + parent::__construct($languageFactory, $url, $activityManager, $userManager, $cloudIdManager, $contactsManager, $eventMerger); } /** @@ -78,11 +60,12 @@ class RemoteShares extends Base { /** * @param IEvent $event + * @param IEvent|null $previousEvent * @return IEvent * @throws \InvalidArgumentException * @since 11.0.0 */ - public function parseLongVersion(IEvent $event) { + public function parseLongVersion(IEvent $event, ?IEvent $previousEvent = null) { $parsedParameters = $this->getParsedParameters($event); if ($event->getSubject() === self::SUBJECT_REMOTE_SHARE_RECEIVED) { @@ -114,13 +97,14 @@ class RemoteShares extends Base { switch ($subject) { case self::SUBJECT_REMOTE_SHARE_RECEIVED: case self::SUBJECT_REMOTE_SHARE_UNSHARED: + $displayName = (count($parameters) > 2) ? $parameters[2] : ''; return [ 'file' => [ 'type' => 'pending-federated-share', 'id' => $parameters[1], 'name' => $parameters[1], ], - 'user' => $this->getUser($parameters[0]), + 'user' => $this->getUser($parameters[0], $displayName) ]; case self::SUBJECT_REMOTE_SHARE_ACCEPTED: case self::SUBJECT_REMOTE_SHARE_DECLINED: diff --git a/apps/files_sharing/lib/Activity/Providers/Users.php b/apps/files_sharing/lib/Activity/Providers/Users.php index 828befc471b..5c833ffae93 100644 --- a/apps/files_sharing/lib/Activity/Providers/Users.php +++ b/apps/files_sharing/lib/Activity/Providers/Users.php @@ -1,29 +1,9 @@ <?php + /** - * @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com> - * - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @author Joas Schilling <coding@schilljs.com> - * @author John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com> - * @author Kevin Ndung'u <kevgathuku@gmail.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/>. - * + * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ - namespace OCA\Files_Sharing\Activity\Providers; use OCP\Activity\IEvent; @@ -87,11 +67,12 @@ class Users extends Base { /** * @param IEvent $event + * @param IEvent|null $previousEvent * @return IEvent * @throws \InvalidArgumentException * @since 11.0.0 */ - public function parseLongVersion(IEvent $event) { + public function parseLongVersion(IEvent $event, ?IEvent $previousEvent = null) { $parsedParameters = $this->getParsedParameters($event); if ($event->getSubject() === self::SUBJECT_SHARED_USER_SELF) { |