diff options
Diffstat (limited to 'apps/files/lib/Activity')
-rw-r--r-- | apps/files/lib/Activity/FavoriteProvider.php | 85 | ||||
-rw-r--r-- | apps/files/lib/Activity/Filter/Favorites.php | 52 | ||||
-rw-r--r-- | apps/files/lib/Activity/Filter/FileChanges.php | 39 | ||||
-rw-r--r-- | apps/files/lib/Activity/Helper.php | 93 | ||||
-rw-r--r-- | apps/files/lib/Activity/Provider.php | 505 | ||||
-rw-r--r-- | apps/files/lib/Activity/Settings/FavoriteAction.php | 57 | ||||
-rw-r--r-- | apps/files/lib/Activity/Settings/FileActivitySettings.php | 30 | ||||
-rw-r--r-- | apps/files/lib/Activity/Settings/FileChanged.php | 75 | ||||
-rw-r--r-- | apps/files/lib/Activity/Settings/FileCreated.php | 100 | ||||
-rw-r--r-- | apps/files/lib/Activity/Settings/FileDeleted.php | 100 | ||||
-rw-r--r-- | apps/files/lib/Activity/Settings/FileFavorite.php | 100 | ||||
-rw-r--r-- | apps/files/lib/Activity/Settings/FileFavoriteChanged.php | 75 | ||||
-rw-r--r-- | apps/files/lib/Activity/Settings/FileRestored.php | 100 |
13 files changed, 543 insertions, 868 deletions
diff --git a/apps/files/lib/Activity/FavoriteProvider.php b/apps/files/lib/Activity/FavoriteProvider.php index 787978babed..e56b13b902a 100644 --- a/apps/files/lib/Activity/FavoriteProvider.php +++ b/apps/files/lib/Activity/FavoriteProvider.php @@ -1,28 +1,12 @@ <?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/>. - * + * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ - namespace OCA\Files\Activity; +use OCP\Activity\Exceptions\UnknownActivityException; use OCP\Activity\IEvent; use OCP\Activity\IEventMerger; use OCP\Activity\IManager; @@ -32,36 +16,24 @@ use OCP\IURLGenerator; use OCP\L10N\IFactory; class FavoriteProvider implements IProvider { - - const SUBJECT_ADDED = 'added_favorite'; - const SUBJECT_REMOVED = 'removed_favorite'; - - /** @var IFactory */ - protected $languageFactory; + public const SUBJECT_ADDED = 'added_favorite'; + public const SUBJECT_REMOVED = 'removed_favorite'; /** @var IL10N */ protected $l; - /** @var IURLGenerator */ - protected $url; - - /** @var IManager */ - protected $activityManager; - - /** @var IEventMerger */ - protected $eventMerger; - /** * @param IFactory $languageFactory * @param IURLGenerator $url * @param IManager $activityManager * @param IEventMerger $eventMerger */ - public function __construct(IFactory $languageFactory, IURLGenerator $url, IManager $activityManager, IEventMerger $eventMerger) { - $this->languageFactory = $languageFactory; - $this->url = $url; - $this->activityManager = $activityManager; - $this->eventMerger = $eventMerger; + public function __construct( + protected IFactory $languageFactory, + protected IURLGenerator $url, + protected IManager $activityManager, + protected IEventMerger $eventMerger, + ) { } /** @@ -69,12 +41,12 @@ class FavoriteProvider 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' || $event->getType() !== 'favorite') { - throw new \InvalidArgumentException(); + throw new UnknownActivityException(); } $this->l = $this->languageFactory->get('files', $language); @@ -82,7 +54,7 @@ class FavoriteProvider implements IProvider { if ($this->activityManager->isFormattingFilteredObject()) { try { return $this->parseShortVersion($event); - } catch (\InvalidArgumentException $e) { + } catch (UnknownActivityException) { // Ignore and simply use the long version... } } @@ -93,11 +65,10 @@ class FavoriteProvider implements IProvider { /** * @param IEvent $event * @return IEvent - * @throws \InvalidArgumentException + * @throws UnknownActivityException * @since 11.0.0 */ - public function parseShortVersion(IEvent $event) { - + public function parseShortVersion(IEvent $event): IEvent { if ($event->getSubject() === self::SUBJECT_ADDED) { $event->setParsedSubject($this->l->t('Added to favorites')); if ($this->activityManager->getRequirePNG()) { @@ -105,7 +76,8 @@ class FavoriteProvider implements IProvider { } else { $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/starred.svg'))); } - } else if ($event->getSubject() === self::SUBJECT_REMOVED) { + } elseif ($event->getSubject() === self::SUBJECT_REMOVED) { + $event->setType('unfavorite'); $event->setParsedSubject($this->l->t('Removed from favorites')); if ($this->activityManager->getRequirePNG()) { $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/star.png'))); @@ -113,7 +85,7 @@ class FavoriteProvider implements IProvider { $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/star.svg'))); } } else { - throw new \InvalidArgumentException(); + throw new UnknownActivityException(); } return $event; @@ -123,11 +95,10 @@ class FavoriteProvider implements IProvider { * @param IEvent $event * @param IEvent|null $previousEvent * @return IEvent - * @throws \InvalidArgumentException + * @throws UnknownActivityException * @since 11.0.0 */ - public function parseLongVersion(IEvent $event, IEvent $previousEvent = null) { - + public function parseLongVersion(IEvent $event, ?IEvent $previousEvent = null): IEvent { if ($event->getSubject() === self::SUBJECT_ADDED) { $subject = $this->l->t('You added {file} to your favorites'); if ($this->activityManager->getRequirePNG()) { @@ -135,7 +106,8 @@ class FavoriteProvider implements IProvider { } else { $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/starred.svg'))); } - } else if ($event->getSubject() === self::SUBJECT_REMOVED) { + } elseif ($event->getSubject() === self::SUBJECT_REMOVED) { + $event->setType('unfavorite'); $subject = $this->l->t('You removed {file} from your favorites'); if ($this->activityManager->getRequirePNG()) { $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/star.png'))); @@ -143,7 +115,7 @@ class FavoriteProvider implements IProvider { $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/star.svg'))); } } else { - throw new \InvalidArgumentException(); + throw new UnknownActivityException(); } $this->setSubjects($event, $subject); @@ -167,13 +139,12 @@ class FavoriteProvider implements IProvider { } $parameter = [ 'type' => 'file', - 'id' => $subjectParams['id'], + 'id' => (string)$subjectParams['id'], 'name' => basename($subjectParams['path']), 'path' => trim($subjectParams['path'], '/'), 'link' => $this->url->linkToRouteAbsolute('files.viewcontroller.showFile', ['fileid' => $subjectParams['id']]), ]; - $event->setParsedSubject(str_replace('{file}', $parameter['path'], $subject)) - ->setRichSubject($subject, ['file' => $parameter]); + $event->setRichSubject($subject, ['file' => $parameter]); } } diff --git a/apps/files/lib/Activity/Filter/Favorites.php b/apps/files/lib/Activity/Filter/Favorites.php index 0cb03eec2b2..0159dd20b82 100644 --- a/apps/files/lib/Activity/Filter/Favorites.php +++ b/apps/files/lib/Activity/Filter/Favorites.php @@ -1,29 +1,11 @@ <?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/>. - * + * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ - namespace OCA\Files\Activity\Filter; - use OCA\Files\Activity\Helper; use OCP\Activity\IFilter; use OCP\Activity\IManager; @@ -34,21 +16,6 @@ use OCP\IURLGenerator; class Favorites implements IFilter { - /** @var IL10N */ - protected $l; - - /** @var IURLGenerator */ - protected $url; - - /** @var IManager */ - protected $activityManager; - - /** @var Helper */ - protected $helper; - - /** @var IDBConnection */ - protected $db; - /** * @param IL10N $l * @param IURLGenerator $url @@ -56,12 +23,13 @@ class Favorites implements IFilter { * @param Helper $helper * @param IDBConnection $db */ - public function __construct(IL10N $l, IURLGenerator $url, IManager $activityManager, Helper $helper, IDBConnection $db) { - $this->l = $l; - $this->url = $url; - $this->activityManager = $activityManager; - $this->helper = $helper; - $this->db = $db; + public function __construct( + protected IL10N $l, + protected IURLGenerator $url, + protected IManager $activityManager, + protected Helper $helper, + protected IDBConnection $db, + ) { } /** diff --git a/apps/files/lib/Activity/Filter/FileChanges.php b/apps/files/lib/Activity/Filter/FileChanges.php index 122dc4250f9..0ca8f6792e0 100644 --- a/apps/files/lib/Activity/Filter/FileChanges.php +++ b/apps/files/lib/Activity/Filter/FileChanges.php @@ -1,48 +1,25 @@ <?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/>. - * + * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ - namespace OCA\Files\Activity\Filter; - use OCP\Activity\IFilter; use OCP\IL10N; use OCP\IURLGenerator; class FileChanges implements IFilter { - /** @var IL10N */ - protected $l; - - /** @var IURLGenerator */ - protected $url; - /** * @param IL10N $l * @param IURLGenerator $url */ - public function __construct(IL10N $l, IURLGenerator $url) { - $this->l = $l; - $this->url = $url; + public function __construct( + protected IL10N $l, + protected IURLGenerator $url, + ) { } /** @@ -74,7 +51,7 @@ class FileChanges implements IFilter { * @since 11.0.0 */ public function getIcon() { - return $this->url->getAbsoluteURL($this->url->imagePath('core', 'places/files-dark.svg')); + return $this->url->getAbsoluteURL($this->url->imagePath('core', 'places/files.svg')); } /** diff --git a/apps/files/lib/Activity/Helper.php b/apps/files/lib/Activity/Helper.php index d03d6e8e974..9b8ad9cd442 100644 --- a/apps/files/lib/Activity/Helper.php +++ b/apps/files/lib/Activity/Helper.php @@ -1,82 +1,85 @@ <?php + /** - * @copyright Copyright (c) 2016, ownCloud, Inc. - * - * @author Joas Schilling <coding@schilljs.com> - * - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * 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, version 3, - * along with this program. If not, see <http://www.gnu.org/licenses/> - * + * SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-FileCopyrightText: 2016 ownCloud, Inc. + * SPDX-License-Identifier: AGPL-3.0-only */ - namespace OCA\Files\Activity; use OCP\Files\Folder; +use OCP\Files\IRootFolder; +use OCP\Files\Node; use OCP\ITagManager; class Helper { /** If a user has a lot of favorites the query might get too slow and long */ - const FAVORITE_LIMIT = 50; - - /** @var ITagManager */ - protected $tagManager; + public const FAVORITE_LIMIT = 50; - /** - * @param ITagManager $tagManager - */ - public function __construct(ITagManager $tagManager) { - $this->tagManager = $tagManager; + public function __construct( + protected ITagManager $tagManager, + protected IRootFolder $rootFolder, + ) { } /** - * Returns an array with the favorites + * Return an array with nodes marked as favorites * - * @param string $user - * @return array + * @param string $user User ID + * @param bool $foldersOnly Only return folders (default false) + * @return Node[] + * @psalm-return ($foldersOnly is true ? Folder[] : Node[]) * @throws \RuntimeException when too many or no favorites where found */ - public function getFavoriteFilePaths($user) { + public function getFavoriteNodes(string $user, bool $foldersOnly = false): array { $tags = $this->tagManager->load('files', [], false, $user); $favorites = $tags->getFavorites(); if (empty($favorites)) { throw new \RuntimeException('No favorites', 1); - } else if (isset($favorites[self::FAVORITE_LIMIT])) { + } elseif (isset($favorites[self::FAVORITE_LIMIT])) { throw new \RuntimeException('Too many favorites', 2); } // Can not DI because the user is not known on instantiation - $rootFolder = \OC::$server->getUserFolder($user); - $folders = $items = []; + $userFolder = $this->rootFolder->getUserFolder($user); + $favoriteNodes = []; foreach ($favorites as $favorite) { - $nodes = $rootFolder->getById($favorite); - if (!empty($nodes)) { - /** @var \OCP\Files\Node $node */ - $node = array_shift($nodes); - $path = substr($node->getPath(), strlen($user . '/files/')); - - $items[] = $path; - if ($node instanceof Folder) { - $folders[] = $path; + $node = $userFolder->getFirstNodeById($favorite); + if ($node) { + if (!$foldersOnly || $node instanceof Folder) { + $favoriteNodes[] = $node; } } } - if (empty($items)) { + if (empty($favoriteNodes)) { throw new \RuntimeException('No favorites', 1); } + return $favoriteNodes; + } + + /** + * Returns an array with the favorites + * + * @param string $user + * @return array + * @throws \RuntimeException when too many or no favorites where found + */ + public function getFavoriteFilePaths(string $user): array { + $userFolder = $this->rootFolder->getUserFolder($user); + $nodes = $this->getFavoriteNodes($user); + $folders = $items = []; + foreach ($nodes as $node) { + $path = $userFolder->getRelativePath($node->getPath()); + + $items[] = $path; + if ($node instanceof Folder) { + $folders[] = $path; + } + } + return [ 'items' => $items, 'folders' => $folders, diff --git a/apps/files/lib/Activity/Provider.php b/apps/files/lib/Activity/Provider.php index 3da1f3c1157..3ef79ac107f 100644 --- a/apps/files/lib/Activity/Provider.php +++ b/apps/files/lib/Activity/Provider.php @@ -1,77 +1,47 @@ <?php + /** - * @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com> - * - * @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/>. - * + * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ - namespace OCA\Files\Activity; +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\Files\Folder; +use OCP\Files\InvalidPathException; +use OCP\Files\IRootFolder; +use OCP\Files\Node; +use OCP\Files\NotFoundException; use OCP\IL10N; use OCP\IURLGenerator; -use OCP\IUser; use OCP\IUserManager; use OCP\L10N\IFactory; class Provider implements IProvider { - - /** @var IFactory */ - protected $languageFactory; - /** @var IL10N */ protected $l; - /** @var IL10N */ - protected $activityLang; - - /** @var IURLGenerator */ - protected $url; - - /** @var IManager */ - protected $activityManager; - /** @var IUserManager */ - protected $userManager; - - /** @var IEventMerger */ - protected $eventMerger; - - /** @var string[] cached displayNames - key is the UID and value the displayname */ + /** @var string[] cached displayNames - key is the cloud id and value the displayname */ protected $displayNames = []; - /** - * @param IFactory $languageFactory - * @param IURLGenerator $url - * @param IManager $activityManager - * @param IUserManager $userManager - * @param IEventMerger $eventMerger - */ - public function __construct(IFactory $languageFactory, IURLGenerator $url, IManager $activityManager, IUserManager $userManager, IEventMerger $eventMerger) { - $this->languageFactory = $languageFactory; - $this->url = $url; - $this->activityManager = $activityManager; - $this->userManager = $userManager; - $this->eventMerger = $eventMerger; + protected $fileIsEncrypted = false; + + public function __construct( + protected IFactory $languageFactory, + protected IURLGenerator $url, + protected IManager $activityManager, + protected IUserManager $userManager, + protected IRootFolder $rootFolder, + protected ICloudIdManager $cloudIdManager, + protected IContactsManager $contactsManager, + protected IEventMerger $eventMerger, + ) { } /** @@ -79,21 +49,20 @@ class Provider 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') { - throw new \InvalidArgumentException(); + throw new UnknownActivityException(); } $this->l = $this->languageFactory->get('files', $language); - $this->activityLang = $this->languageFactory->get('activity', $language); if ($this->activityManager->isFormattingFilteredObject()) { try { return $this->parseShortVersion($event, $previousEvent); - } catch (\InvalidArgumentException $e) { + } catch (UnknownActivityException) { // Ignore and simply use the long version... } } @@ -101,60 +70,49 @@ class Provider implements IProvider { return $this->parseLongVersion($event, $previousEvent); } + protected function setIcon(IEvent $event, string $icon, string $app = 'files') { + if ($this->activityManager->getRequirePNG()) { + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath($app, $icon . '.png'))); + } else { + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath($app, $icon . '.svg'))); + } + } + /** * @param IEvent $event * @param IEvent|null $previousEvent * @return IEvent - * @throws \InvalidArgumentException + * @throws UnknownActivityException * @since 11.0.0 */ - public function parseShortVersion(IEvent $event, IEvent $previousEvent = null) { + public function parseShortVersion(IEvent $event, ?IEvent $previousEvent = null): IEvent { $parsedParameters = $this->getParameters($event); if ($event->getSubject() === 'created_by') { $subject = $this->l->t('Created by {user}'); - if ($this->activityManager->getRequirePNG()) { - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'add-color.png'))); - } else { - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'add-color.svg'))); - } - } else if ($event->getSubject() === 'changed_by') { + $this->setIcon($event, 'add-color'); + } elseif ($event->getSubject() === 'changed_by') { $subject = $this->l->t('Changed by {user}'); - if ($this->activityManager->getRequirePNG()) { - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'change.png'))); - } else { - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'change.svg'))); - } - } else if ($event->getSubject() === 'deleted_by') { + $this->setIcon($event, 'change'); + } elseif ($event->getSubject() === 'deleted_by') { $subject = $this->l->t('Deleted by {user}'); - if ($this->activityManager->getRequirePNG()) { - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'delete-color.png'))); - } else { - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'delete-color.svg'))); - } - } else if ($event->getSubject() === 'restored_by') { + $this->setIcon($event, 'delete-color'); + } elseif ($event->getSubject() === 'restored_by') { $subject = $this->l->t('Restored by {user}'); - } else if ($event->getSubject() === 'renamed_by') { + $this->setIcon($event, 'actions/history', 'core'); + } elseif ($event->getSubject() === 'renamed_by') { $subject = $this->l->t('Renamed by {user}'); - if ($this->activityManager->getRequirePNG()) { - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'change.png'))); - } else { - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'change.svg'))); - } - } else if ($event->getSubject() === 'moved_by') { + $this->setIcon($event, 'change'); + } elseif ($event->getSubject() === 'moved_by') { $subject = $this->l->t('Moved by {user}'); - if ($this->activityManager->getRequirePNG()) { - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'change.png'))); - } else { - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'change.svg'))); - } + $this->setIcon($event, 'change'); } else { - throw new \InvalidArgumentException(); + throw new UnknownActivityException(); } if (!isset($parsedParameters['user'])) { // External user via public link share - $subject = str_replace('{user}', $this->activityLang->t('"remote user"'), $subject); + $subject = str_replace('{user}', $this->l->t('"remote account"'), $subject); } $this->setSubjects($event, $subject, $parsedParameters); @@ -166,105 +124,122 @@ class Provider implements IProvider { * @param IEvent $event * @param IEvent|null $previousEvent * @return IEvent - * @throws \InvalidArgumentException + * @throws UnknownActivityException * @since 11.0.0 */ - public function parseLongVersion(IEvent $event, IEvent $previousEvent = null) { + public function parseLongVersion(IEvent $event, ?IEvent $previousEvent = null): IEvent { + $this->fileIsEncrypted = false; $parsedParameters = $this->getParameters($event); if ($event->getSubject() === 'created_self') { $subject = $this->l->t('You created {file}'); - if ($this->activityManager->getRequirePNG()) { - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'add-color.png'))); - } else { - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'add-color.svg'))); + if ($this->fileIsEncrypted) { + $subject = $this->l->t('You created an encrypted file in {file}'); } - } else if ($event->getSubject() === 'created_by') { + $this->setIcon($event, 'add-color'); + } elseif ($event->getSubject() === 'created_by') { $subject = $this->l->t('{user} created {file}'); - if ($this->activityManager->getRequirePNG()) { - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'add-color.png'))); - } else { - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'add-color.svg'))); + if ($this->fileIsEncrypted) { + $subject = $this->l->t('{user} created an encrypted file in {file}'); } - } else if ($event->getSubject() === 'created_public') { + $this->setIcon($event, 'add-color'); + } elseif ($event->getSubject() === 'created_public') { $subject = $this->l->t('{file} was created in a public folder'); - if ($this->activityManager->getRequirePNG()) { - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'add-color.png'))); - } else { - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'add-color.svg'))); - } - } else if ($event->getSubject() === 'changed_self') { + $this->setIcon($event, 'add-color'); + } elseif ($event->getSubject() === 'changed_self') { $subject = $this->l->t('You changed {file}'); - if ($this->activityManager->getRequirePNG()) { - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'change.png'))); - } else { - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'change.svg'))); + if ($this->fileIsEncrypted) { + $subject = $this->l->t('You changed an encrypted file in {file}'); } - } else if ($event->getSubject() === 'changed_by') { + $this->setIcon($event, 'change'); + } elseif ($event->getSubject() === 'changed_by') { $subject = $this->l->t('{user} changed {file}'); - if ($this->activityManager->getRequirePNG()) { - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'change.png'))); - } else { - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'change.svg'))); + if ($this->fileIsEncrypted) { + $subject = $this->l->t('{user} changed an encrypted file in {file}'); } - } else if ($event->getSubject() === 'deleted_self') { + $this->setIcon($event, 'change'); + } elseif ($event->getSubject() === 'deleted_self') { $subject = $this->l->t('You deleted {file}'); - if ($this->activityManager->getRequirePNG()) { - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'delete-color.png'))); - } else { - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'delete-color.svg'))); + if ($this->fileIsEncrypted) { + $subject = $this->l->t('You deleted an encrypted file in {file}'); } - } else if ($event->getSubject() === 'deleted_by') { + $this->setIcon($event, 'delete-color'); + } elseif ($event->getSubject() === 'deleted_by') { $subject = $this->l->t('{user} deleted {file}'); - if ($this->activityManager->getRequirePNG()) { - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'delete-color.png'))); - } else { - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'delete-color.svg'))); + if ($this->fileIsEncrypted) { + $subject = $this->l->t('{user} deleted an encrypted file in {file}'); } - } else if ($event->getSubject() === 'restored_self') { + $this->setIcon($event, 'delete-color'); + } elseif ($event->getSubject() === 'restored_self') { $subject = $this->l->t('You restored {file}'); - } else if ($event->getSubject() === 'restored_by') { + $this->setIcon($event, 'actions/history', 'core'); + } elseif ($event->getSubject() === 'restored_by') { $subject = $this->l->t('{user} restored {file}'); - } else if ($event->getSubject() === 'renamed_self') { - $subject = $this->l->t('You renamed {oldfile} to {newfile}'); - if ($this->activityManager->getRequirePNG()) { - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'change.png'))); + $this->setIcon($event, 'actions/history', 'core'); + } elseif ($event->getSubject() === 'renamed_self') { + $oldFileName = $parsedParameters['oldfile']['name']; + $newFileName = $parsedParameters['newfile']['name']; + + if ($this->isHiddenFile($oldFileName)) { + if ($this->isHiddenFile($newFileName)) { + $subject = $this->l->t('You renamed {oldfile} (hidden) to {newfile} (hidden)'); + } else { + $subject = $this->l->t('You renamed {oldfile} (hidden) to {newfile}'); + } } else { - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'change.svg'))); + if ($this->isHiddenFile($newFileName)) { + $subject = $this->l->t('You renamed {oldfile} to {newfile} (hidden)'); + } else { + $subject = $this->l->t('You renamed {oldfile} to {newfile}'); + } } - } else if ($event->getSubject() === 'renamed_by') { - $subject = $this->l->t('{user} renamed {oldfile} to {newfile}'); - if ($this->activityManager->getRequirePNG()) { - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'change.png'))); + + $this->setIcon($event, 'change'); + } elseif ($event->getSubject() === 'renamed_by') { + $oldFileName = $parsedParameters['oldfile']['name']; + $newFileName = $parsedParameters['newfile']['name']; + + if ($this->isHiddenFile($oldFileName)) { + if ($this->isHiddenFile($newFileName)) { + $subject = $this->l->t('{user} renamed {oldfile} (hidden) to {newfile} (hidden)'); + } else { + $subject = $this->l->t('{user} renamed {oldfile} (hidden) to {newfile}'); + } } else { - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'change.svg'))); + if ($this->isHiddenFile($newFileName)) { + $subject = $this->l->t('{user} renamed {oldfile} to {newfile} (hidden)'); + } else { + $subject = $this->l->t('{user} renamed {oldfile} to {newfile}'); + } } - } else if ($event->getSubject() === 'moved_self') { + + $this->setIcon($event, 'change'); + } elseif ($event->getSubject() === 'moved_self') { $subject = $this->l->t('You moved {oldfile} to {newfile}'); - if ($this->activityManager->getRequirePNG()) { - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'change.png'))); - } else { - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'change.svg'))); - } - } else if ($event->getSubject() === 'moved_by') { + $this->setIcon($event, 'change'); + } elseif ($event->getSubject() === 'moved_by') { $subject = $this->l->t('{user} moved {oldfile} to {newfile}'); - if ($this->activityManager->getRequirePNG()) { - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'change.png'))); - } else { - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'change.svg'))); - } + $this->setIcon($event, 'change'); } else { - throw new \InvalidArgumentException(); + throw new UnknownActivityException(); + } + + if ($this->fileIsEncrypted) { + $event->setSubject($event->getSubject() . '_enc', $event->getSubjectParameters()); } if (!isset($parsedParameters['user'])) { // External user via public link share - $subject = str_replace('{user}', $this->activityLang->t('"remote user"'), $subject); + $subject = str_replace('{user}', $this->l->t('"remote account"'), $subject); } $this->setSubjects($event, $subject, $parsedParameters); - $event = $this->eventMerger->mergeEvents('file', $event, $previousEvent); + if ($event->getSubject() === 'moved_self' || $event->getSubject() === 'moved_by') { + $event = $this->eventMerger->mergeEvents('oldfile', $event, $previousEvent); + } else { + $event = $this->eventMerger->mergeEvents('file', $event, $previousEvent); + } if ($event->getChildEvent() === null) { // Couldn't group by file, maybe we can group by user @@ -274,27 +249,20 @@ class Provider implements IProvider { return $event; } - 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']; - } - } + private function isHiddenFile(string $filename): bool { + return strlen($filename) > 0 && $filename[0] === '.'; + } - $event->setParsedSubject(str_replace($placeholders, $replacements, $subject)) - ->setRichSubject($subject, $parameters); + protected function setSubjects(IEvent $event, string $subject, array $parameters): void { + $event->setRichSubject($subject, $parameters); } /** * @param IEvent $event * @return array - * @throws \InvalidArgumentException + * @throws UnknownActivityException */ - protected function getParameters(IEvent $event) { + protected function getParameters(IEvent $event): array { $parameters = $event->getSubjectParameters(); switch ($event->getSubject()) { case 'created_self': @@ -347,55 +315,212 @@ class Provider implements IProvider { * @param array|string $parameter * @param IEvent|null $event * @return array - * @throws \InvalidArgumentException + * @throws UnknownActivityException */ - protected function getFile($parameter, IEvent $event = null) { + protected function getFile($parameter, ?IEvent $event = null): array { if (is_array($parameter)) { $path = reset($parameter); - $id = (string) key($parameter); - } else if ($event !== null) { + $id = (int)key($parameter); + } elseif ($event !== null) { // Legacy from before ownCloud 8.2 $path = $parameter; $id = $event->getObjectId(); } else { - throw new \InvalidArgumentException('Could not generate file parameter'); + throw new UnknownActivityException('Could not generate file parameter'); + } + + $encryptionContainer = $this->getEndToEndEncryptionContainer($id, $path); + if ($encryptionContainer instanceof Folder) { + $this->fileIsEncrypted = true; + try { + $fullPath = rtrim($encryptionContainer->getPath(), '/'); + // Remove /user/files/... + [,,, $path] = explode('/', $fullPath, 4); + if (!$path) { + throw new InvalidPathException('Path could not be split correctly'); + } + + return [ + 'type' => 'file', + 'id' => (string)$encryptionContainer->getId(), + 'name' => $encryptionContainer->getName(), + 'path' => $path, + 'link' => $this->url->linkToRouteAbsolute('files.viewcontroller.showFile', ['fileid' => $encryptionContainer->getId()]), + ]; + } catch (\Exception $e) { + // fall back to the normal one + $this->fileIsEncrypted = false; + } } return [ 'type' => 'file', - 'id' => $id, + 'id' => (string)$id, 'name' => basename($path), 'path' => trim($path, '/'), 'link' => $this->url->linkToRouteAbsolute('files.viewcontroller.showFile', ['fileid' => $id]), ]; } + protected $fileEncrypted = []; + + /** + * Check if a file is end2end encrypted + * @param int $fileId + * @param string $path + * @return Folder|null + */ + protected function getEndToEndEncryptionContainer($fileId, $path) { + if (isset($this->fileEncrypted[$fileId])) { + return $this->fileEncrypted[$fileId]; + } + + $fileName = basename($path); + if (!preg_match('/^[0-9a-fA-F]{32}$/', $fileName)) { + $this->fileEncrypted[$fileId] = false; + return $this->fileEncrypted[$fileId]; + } + + $userFolder = $this->rootFolder->getUserFolder($this->activityManager->getCurrentUserId()); + $file = $userFolder->getFirstNodeById($fileId); + if (!$file) { + try { + // Deleted, try with parent + $file = $this->findExistingParent($userFolder, dirname($path)); + } catch (NotFoundException $e) { + return null; + } + + if (!$file instanceof Folder || !$file->isEncrypted()) { + return null; + } + + $this->fileEncrypted[$fileId] = $file; + return $file; + } + + if ($file instanceof Folder && $file->isEncrypted()) { + // If the folder is encrypted, it is the Container, + // but can be the name is just fine. + $this->fileEncrypted[$fileId] = true; + return null; + } + + $this->fileEncrypted[$fileId] = $this->getParentEndToEndEncryptionContainer($userFolder, $file); + return $this->fileEncrypted[$fileId]; + } + + /** + * @param Folder $userFolder + * @param string $path + * @return Folder + * @throws NotFoundException + */ + protected function findExistingParent(Folder $userFolder, $path) { + if ($path === '/') { + throw new NotFoundException('Reached the root'); + } + + try { + $folder = $userFolder->get(dirname($path)); + } catch (NotFoundException $e) { + return $this->findExistingParent($userFolder, dirname($path)); + } + + return $folder; + } + + /** + * Check all parents until the user's root folder if one is encrypted + * + * @param Folder $userFolder + * @param Node $file + * @return Node|null + */ + protected function getParentEndToEndEncryptionContainer(Folder $userFolder, Node $file) { + try { + $parent = $file->getParent(); + + if ($userFolder->getId() === $parent->getId()) { + return null; + } + } catch (\Exception $e) { + return null; + } + + if ($parent->isEncrypted()) { + return $parent; + } + + return $this->getParentEndToEndEncryptionContainer($userFolder, $parent); + } + /** * @param string $uid * @return array */ protected function getUser($uid) { - if (!isset($this->displayNames[$uid])) { - $this->displayNames[$uid] = $this->getDisplayName($uid); + // First try local user + $displayName = $this->userManager->getDisplayName($uid); + if ($displayName !== null) { + return [ + 'type' => 'user', + 'id' => $uid, + 'name' => $displayName, + ]; + } + + // Then a contact from the addressbook + if ($this->cloudIdManager->isValidCloudId($uid)) { + $cloudId = $this->cloudIdManager->resolveCloudId($uid); + return [ + 'type' => 'user', + 'id' => $cloudId->getUser(), + 'name' => $this->getDisplayNameFromAddressBook($cloudId->getDisplayId()), + 'server' => $cloudId->getRemote(), + ]; } + // Fallback to empty dummy data return [ 'type' => 'user', 'id' => $uid, - 'name' => $this->displayNames[$uid], + 'name' => $uid, ]; } - /** - * @param string $uid - * @return string - */ - protected function getDisplayName($uid) { - $user = $this->userManager->get($uid); - if ($user instanceof IUser) { - return $user->getDisplayName(); - } else { - return $uid; + protected function getDisplayNameFromAddressBook(string $search): string { + if (isset($this->displayNames[$search])) { + return $this->displayNames[$search]; } + + $addressBookContacts = $this->contactsManager->search($search, ['CLOUD'], [ + 'limit' => 1, + 'enumeration' => false, + 'fullmatch' => false, + 'strict_search' => true, + ]); + foreach ($addressBookContacts as $contact) { + if (isset($contact['isLocalSystemBook'])) { + continue; + } + + if (isset($contact['CLOUD'])) { + $cloudIds = $contact['CLOUD']; + if (is_string($cloudIds)) { + $cloudIds = [$cloudIds]; + } + + $lowerSearch = strtolower($search); + foreach ($cloudIds as $cloudId) { + if (strtolower($cloudId) === $lowerSearch) { + $this->displayNames[$search] = $contact['FN'] . " ($cloudId)"; + return $this->displayNames[$search]; + } + } + } + } + + return $search; } } diff --git a/apps/files/lib/Activity/Settings/FavoriteAction.php b/apps/files/lib/Activity/Settings/FavoriteAction.php index 8f798d6e5d3..73b200341ec 100644 --- a/apps/files/lib/Activity/Settings/FavoriteAction.php +++ b/apps/files/lib/Activity/Settings/FavoriteAction.php @@ -1,44 +1,12 @@ <?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/>. - * + * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ - namespace OCA\Files\Activity\Settings; - -use OCP\Activity\ISetting; -use OCP\IL10N; - -class FavoriteAction implements ISetting { - - /** @var IL10N */ - protected $l; - - /** - * @param IL10N $l - */ - public function __construct(IL10N $l) { - $this->l = $l; - } - +class FavoriteAction extends FileActivitySettings { /** * @return string Lowercase a-z and underscore only identifier * @since 11.0.0 @@ -57,8 +25,8 @@ class FavoriteAction implements ISetting { /** * @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. + * 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() { @@ -70,7 +38,7 @@ class FavoriteAction implements ISetting { * @since 11.0.0 */ public function canChangeStream() { - return true; + return false; } /** @@ -86,7 +54,7 @@ class FavoriteAction implements ISetting { * @since 11.0.0 */ public function canChangeMail() { - return true; + return false; } /** @@ -96,5 +64,12 @@ class FavoriteAction implements ISetting { public function isDefaultEnabledMail() { return false; } -} + /** + * @return bool True when the option can be changed for the notification + * @since 20.0.0 + */ + public function canChangeNotification() { + return false; + } +} diff --git a/apps/files/lib/Activity/Settings/FileActivitySettings.php b/apps/files/lib/Activity/Settings/FileActivitySettings.php new file mode 100644 index 00000000000..0ca7100832f --- /dev/null +++ b/apps/files/lib/Activity/Settings/FileActivitySettings.php @@ -0,0 +1,30 @@ +<?php + +declare(strict_types=1); + +/** + * SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ +namespace OCA\Files\Activity\Settings; + +use OCP\Activity\ActivitySettings; +use OCP\IL10N; + +abstract class FileActivitySettings extends ActivitySettings { + /** + * @param IL10N $l + */ + public function __construct( + protected IL10N $l, + ) { + } + + public function getGroupIdentifier() { + return 'files'; + } + + public function getGroupName() { + return $this->l->t('Files'); + } +} diff --git a/apps/files/lib/Activity/Settings/FileChanged.php b/apps/files/lib/Activity/Settings/FileChanged.php index f89c088e1bd..c33ed5e1eba 100644 --- a/apps/files/lib/Activity/Settings/FileChanged.php +++ b/apps/files/lib/Activity/Settings/FileChanged.php @@ -1,44 +1,12 @@ <?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/>. - * + * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ - namespace OCA\Files\Activity\Settings; - -use OCP\Activity\ISetting; -use OCP\IL10N; - -class FileChanged implements ISetting { - - /** @var IL10N */ - protected $l; - - /** - * @param IL10N $l - */ - public function __construct(IL10N $l) { - $this->l = $l; - } - +class FileChanged extends FileActivitySettings { /** * @return string Lowercase a-z and underscore only identifier * @since 11.0.0 @@ -52,49 +20,32 @@ class FileChanged implements ISetting { * @since 11.0.0 */ public function getName() { - return $this->l->t('A file or folder has been <strong>changed</strong> or <strong>renamed</strong>'); + return $this->l->t('A file or folder has been <strong>changed</strong>'); } /** * @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. + * 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 1; + return 2; } - /** - * @return bool True when the option can be changed for the stream - * @since 11.0.0 - */ - public function canChangeStream() { + public function canChangeMail() { return true; } - /** - * @return bool True when the option can be changed for the stream - * @since 11.0.0 - */ - public function isDefaultEnabledStream() { - return true; + public function isDefaultEnabledMail() { + return false; } - /** - * @return bool True when the option can be changed for the mail - * @since 11.0.0 - */ - public function canChangeMail() { + public function canChangeNotification() { return true; } - /** - * @return bool True when the option can be changed for the stream - * @since 11.0.0 - */ - public function isDefaultEnabledMail() { + public function isDefaultEnabledNotification() { return false; } } - diff --git a/apps/files/lib/Activity/Settings/FileCreated.php b/apps/files/lib/Activity/Settings/FileCreated.php deleted file mode 100644 index 945d25806a7..00000000000 --- a/apps/files/lib/Activity/Settings/FileCreated.php +++ /dev/null @@ -1,100 +0,0 @@ -<?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\Files\Activity\Settings; - - -use OCP\Activity\ISetting; -use OCP\IL10N; - -class FileCreated implements ISetting { - - /** @var IL10N */ - protected $l; - - /** - * @param IL10N $l - */ - public function __construct(IL10N $l) { - $this->l = $l; - } - - /** - * @return string Lowercase a-z and underscore only identifier - * @since 11.0.0 - */ - public function getIdentifier() { - return 'file_created'; - } - - /** - * @return string A translated string - * @since 11.0.0 - */ - public function getName() { - return $this->l->t('A new file or folder has been <strong>created</strong>'); - } - - /** - * @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 0; - } - - /** - * @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; - } -} - diff --git a/apps/files/lib/Activity/Settings/FileDeleted.php b/apps/files/lib/Activity/Settings/FileDeleted.php deleted file mode 100644 index 34ecc7cb2d7..00000000000 --- a/apps/files/lib/Activity/Settings/FileDeleted.php +++ /dev/null @@ -1,100 +0,0 @@ -<?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\Files\Activity\Settings; - - -use OCP\Activity\ISetting; -use OCP\IL10N; - -class FileDeleted implements ISetting { - - /** @var IL10N */ - protected $l; - - /** - * @param IL10N $l - */ - public function __construct(IL10N $l) { - $this->l = $l; - } - - /** - * @return string Lowercase a-z and underscore only identifier - * @since 11.0.0 - */ - public function getIdentifier() { - return 'file_deleted'; - } - - /** - * @return string A translated string - * @since 11.0.0 - */ - public function getName() { - return $this->l->t('A file or folder has been <strong>deleted</strong>'); - } - - /** - * @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 3; - } - - /** - * @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; - } -} - diff --git a/apps/files/lib/Activity/Settings/FileFavorite.php b/apps/files/lib/Activity/Settings/FileFavorite.php deleted file mode 100644 index ae0a4cae674..00000000000 --- a/apps/files/lib/Activity/Settings/FileFavorite.php +++ /dev/null @@ -1,100 +0,0 @@ -<?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\Files\Activity\Settings; - - -use OCP\Activity\ISetting; -use OCP\IL10N; - -class FileFavorite implements ISetting { - - /** @var IL10N */ - protected $l; - - /** - * @param IL10N $l - */ - public function __construct(IL10N $l) { - $this->l = $l; - } - - /** - * @return string Lowercase a-z and underscore only identifier - * @since 11.0.0 - */ - public function getIdentifier() { - return 'file_favorite'; - } - - /** - * @return string A translated string - * @since 11.0.0 - */ - public function getName() { - return $this->l->t('Limit notifications about creation and changes to your <strong>favorite files</strong> <em>(Stream only)</em>'); - } - - /** - * @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 2; - } - - /** - * @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 false; - } - - /** - * @return bool True when the option can be changed for the mail - * @since 11.0.0 - */ - public function canChangeMail() { - return false; - } - - /** - * @return bool True when the option can be changed for the stream - * @since 11.0.0 - */ - public function isDefaultEnabledMail() { - return false; - } -} - diff --git a/apps/files/lib/Activity/Settings/FileFavoriteChanged.php b/apps/files/lib/Activity/Settings/FileFavoriteChanged.php new file mode 100644 index 00000000000..5000902ed3f --- /dev/null +++ b/apps/files/lib/Activity/Settings/FileFavoriteChanged.php @@ -0,0 +1,75 @@ +<?php + +/** + * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ +namespace OCA\Files\Activity\Settings; + +class FileFavoriteChanged extends FileActivitySettings { + /** + * @return string Lowercase a-z and underscore only identifier + * @since 11.0.0 + */ + public function getIdentifier() { + return 'file_favorite_changed'; + } + + /** + * @return string A translated string + * @since 11.0.0 + */ + public function getName() { + return $this->l->t('A favorite file or folder has been <strong>changed</strong>'); + } + + /** + * @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 1; + } + + /** + * @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 false; + } + + public function canChangeNotification() { + return false; + } + + /** + * @return bool True when the option can be changed for the stream + * @since 11.0.0 + */ + public function isDefaultEnabledMail() { + return false; + } + + public function isDefaultEnabledNotification() { + return false; + } +} diff --git a/apps/files/lib/Activity/Settings/FileRestored.php b/apps/files/lib/Activity/Settings/FileRestored.php deleted file mode 100644 index 76f2cca5888..00000000000 --- a/apps/files/lib/Activity/Settings/FileRestored.php +++ /dev/null @@ -1,100 +0,0 @@ -<?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\Files\Activity\Settings; - - -use OCP\Activity\ISetting; -use OCP\IL10N; - -class FileRestored implements ISetting { - - /** @var IL10N */ - protected $l; - - /** - * @param IL10N $l - */ - public function __construct(IL10N $l) { - $this->l = $l; - } - - /** - * @return string Lowercase a-z and underscore only identifier - * @since 11.0.0 - */ - public function getIdentifier() { - return 'file_restored'; - } - - /** - * @return string A translated string - * @since 11.0.0 - */ - public function getName() { - return $this->l->t('A file or folder has been <strong>restored</strong>'); - } - - /** - * @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 4; - } - - /** - * @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; - } -} - |