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,177 @@
<?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/>.
*
*/
namespace OCA\Files\Activity;
use OCP\Activity\IEvent;
use OCP\Activity\IEventMerger;
use OCP\Activity\IManager;
use OCP\Activity\IProvider;
use OCP\IL10N;
use OCP\IURLGenerator;
use OCP\L10N\IFactory;
class FavoriteProvider implements IProvider {
public const SUBJECT_ADDED = 'added_favorite';
public const SUBJECT_REMOVED = 'removed_favorite';
/** @var IFactory */
protected $languageFactory;
/** @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;
}
/**
* @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() !== 'files' || $event->getType() !== 'favorite') {
throw new \InvalidArgumentException();
}
$this->l = $this->languageFactory->get('files', $language);
if ($this->activityManager->isFormattingFilteredObject()) {
try {
return $this->parseShortVersion($event);
} catch (\InvalidArgumentException $e) {
// Ignore and simply use the long version...
}
}
return $this->parseLongVersion($event, $previousEvent);
}
/**
* @param IEvent $event
* @return IEvent
* @throws \InvalidArgumentException
* @since 11.0.0
*/
public function parseShortVersion(IEvent $event) {
if ($event->getSubject() === self::SUBJECT_ADDED) {
$event->setParsedSubject($this->l->t('Added to favorites'));
if ($this->activityManager->getRequirePNG()) {
$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/starred.png')));
} else {
$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/starred.svg')));
}
} 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')));
} else {
$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/star.svg')));
}
} else {
throw new \InvalidArgumentException();
}
return $event;
}
/**
* @param IEvent $event
* @param IEvent|null $previousEvent
* @return IEvent
* @throws \InvalidArgumentException
* @since 11.0.0
*/
public function parseLongVersion(IEvent $event, IEvent $previousEvent = null) {
if ($event->getSubject() === self::SUBJECT_ADDED) {
$subject = $this->l->t('You added {file} to your favorites');
if ($this->activityManager->getRequirePNG()) {
$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/starred.png')));
} else {
$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/starred.svg')));
}
} 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')));
} else {
$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/star.svg')));
}
} else {
throw new \InvalidArgumentException();
}
$this->setSubjects($event, $subject);
$event = $this->eventMerger->mergeEvents('file', $event, $previousEvent);
return $event;
}
/**
* @param IEvent $event
* @param string $subject
*/
protected function setSubjects(IEvent $event, $subject) {
$subjectParams = $event->getSubjectParameters();
if (empty($subjectParams)) {
// Try to fall back to the old way, but this does not work for emails.
// But at least old activities still work.
$subjectParams = [
'id' => $event->getObjectId(),
'path' => $event->getObjectName(),
];
}
$parameter = [
'type' => 'file',
'id' => $subjectParams['id'],
'name' => basename($subjectParams['path']),
'path' => trim($subjectParams['path'], '/'),
'link' => $this->url->linkToRouteAbsolute('files.viewcontroller.showFile', ['fileid' => $subjectParams['id']]),
];
$event->setRichSubject($subject, ['file' => $parameter]);
}
}
@@ -0,0 +1,160 @@
<?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\Filter;
use OCA\Files\Activity\Helper;
use OCP\Activity\IFilter;
use OCP\Activity\IManager;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection;
use OCP\IL10N;
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
* @param IManager $activityManager
* @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;
}
/**
* @return string Lowercase a-z only identifier
* @since 11.0.0
*/
public function getIdentifier() {
return 'files_favorites';
}
/**
* @return string A translated string
* @since 11.0.0
*/
public function getName() {
return $this->l->t('Favorites');
}
/**
* @return int
* @since 11.0.0
*/
public function getPriority() {
return 10;
}
/**
* @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/star-dark.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([
'file_created',
'file_changed',
'file_deleted',
'file_restored',
], $types);
}
/**
* @return string[] An array of allowed apps from which activities should be displayed
* @since 11.0.0
*/
public function allowedApps() {
return ['files'];
}
/**
* @param IQueryBuilder $query
*/
public function filterFavorites(IQueryBuilder $query) {
try {
$user = $this->activityManager->getCurrentUserId();
} catch (\UnexpectedValueException $e) {
return;
}
try {
$favorites = $this->helper->getFavoriteFilePaths($user);
} catch (\RuntimeException $e) {
return;
}
$limitations = [];
if (!empty($favorites['items'])) {
$limitations[] = $query->expr()->in('file', $query->createNamedParameter($favorites['items'], IQueryBuilder::PARAM_STR_ARRAY));
}
foreach ($favorites['folders'] as $favorite) {
$limitations[] = $query->expr()->like('file', $query->createNamedParameter(
$this->db->escapeLikeParameter($favorite . '/') . '%'
));
}
if (empty($limitations)) {
return;
}
$function = $query->createFunction('
CASE
WHEN ' . $query->getColumnName('app') . ' <> ' . $query->createNamedParameter('files') . ' THEN 1
WHEN ' . $query->getColumnName('app') . ' = ' . $query->createNamedParameter('files') . '
AND (' . implode(' OR ', $limitations) . ')
THEN 1
END = 1'
);
$query->andWhere($function);
}
}
@@ -0,0 +1,100 @@
<?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\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;
}
/**
* @return string Lowercase a-z only identifier
* @since 11.0.0
*/
public function getIdentifier() {
return 'files';
}
/**
* @return string A translated string
* @since 11.0.0
*/
public function getName() {
return $this->l->t('File changes');
}
/**
* @return int
* @since 11.0.0
*/
public function getPriority() {
return 30;
}
/**
* @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/files.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([
'file_created',
'file_changed',
'file_deleted',
'file_restored',
], $types);
}
/**
* @return string[] An array of allowed apps from which activities should be displayed
* @since 11.0.0
*/
public function allowedApps() {
return ['files'];
}
}
@@ -0,0 +1,105 @@
<?php
/**
* @copyright Copyright (c) 2016, ownCloud, Inc.
*
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
* @author Joas Schilling <coding@schilljs.com>
* @author Ferdinand Thiessen <opensource@fthiessen.de>
*
* @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/>
*
*/
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 */
public const FAVORITE_LIMIT = 50;
public function __construct(
protected ITagManager $tagManager,
protected IRootFolder $rootFolder,
) {
}
/**
* Return an array with nodes marked as favorites
*
* @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 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);
} elseif (isset($favorites[self::FAVORITE_LIMIT])) {
throw new \RuntimeException('Too many favorites', 2);
}
// Can not DI because the user is not known on instantiation
$userFolder = $this->rootFolder->getUserFolder($user);
$favoriteNodes = [];
foreach ($favorites as $favorite) {
$nodes = $userFolder->getById($favorite);
if (!empty($nodes)) {
$node = array_shift($nodes);
if (!$foldersOnly || $node instanceof Folder) {
$favoriteNodes[] = $node;
}
}
}
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,
];
}
}
@@ -0,0 +1,579 @@
<?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>
* @author Roeland Jago Douma <roeland@famdouma.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\Files\Activity;
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\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 IRootFolder */
protected $rootFolder;
/** @var IEventMerger */
protected $eventMerger;
/** @var ICloudIdManager */
protected $cloudIdManager;
/** @var IContactsManager */
protected $contactsManager;
/** @var string[] cached displayNames - key is the cloud id and value the displayname */
protected $displayNames = [];
protected $fileIsEncrypted = false;
public function __construct(IFactory $languageFactory,
IURLGenerator $url,
IManager $activityManager,
IUserManager $userManager,
IRootFolder $rootFolder,
ICloudIdManager $cloudIdManager,
IContactsManager $contactsManager,
IEventMerger $eventMerger) {
$this->languageFactory = $languageFactory;
$this->url = $url;
$this->activityManager = $activityManager;
$this->userManager = $userManager;
$this->rootFolder = $rootFolder;
$this->cloudIdManager = $cloudIdManager;
$this->contactsManager = $contactsManager;
$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() !== 'files') {
throw new \InvalidArgumentException();
}
$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) {
// Ignore and simply use the long version...
}
}
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
* @since 11.0.0
*/
public function parseShortVersion(IEvent $event, IEvent $previousEvent = null) {
$parsedParameters = $this->getParameters($event);
if ($event->getSubject() === 'created_by') {
$subject = $this->l->t('Created by {user}');
$this->setIcon($event, 'add-color');
} elseif ($event->getSubject() === 'changed_by') {
$subject = $this->l->t('Changed by {user}');
$this->setIcon($event, 'change');
} elseif ($event->getSubject() === 'deleted_by') {
$subject = $this->l->t('Deleted by {user}');
$this->setIcon($event, 'delete-color');
} elseif ($event->getSubject() === 'restored_by') {
$subject = $this->l->t('Restored by {user}');
$this->setIcon($event, 'actions/history', 'core');
} elseif ($event->getSubject() === 'renamed_by') {
$subject = $this->l->t('Renamed by {user}');
$this->setIcon($event, 'change');
} elseif ($event->getSubject() === 'moved_by') {
$subject = $this->l->t('Moved by {user}');
$this->setIcon($event, 'change');
} else {
throw new \InvalidArgumentException();
}
if (!isset($parsedParameters['user'])) {
// External user via public link share
$subject = str_replace('{user}', $this->activityLang->t('"remote user"'), $subject);
}
$this->setSubjects($event, $subject, $parsedParameters);
return $this->eventMerger->mergeEvents('user', $event, $previousEvent);
}
/**
* @param IEvent $event
* @param IEvent|null $previousEvent
* @return IEvent
* @throws \InvalidArgumentException
* @since 11.0.0
*/
public function parseLongVersion(IEvent $event, IEvent $previousEvent = null) {
$this->fileIsEncrypted = false;
$parsedParameters = $this->getParameters($event);
if ($event->getSubject() === 'created_self') {
$subject = $this->l->t('You created {file}');
if ($this->fileIsEncrypted) {
$subject = $this->l->t('You created an encrypted file in {file}');
}
$this->setIcon($event, 'add-color');
} elseif ($event->getSubject() === 'created_by') {
$subject = $this->l->t('{user} created {file}');
if ($this->fileIsEncrypted) {
$subject = $this->l->t('{user} created an encrypted file in {file}');
}
$this->setIcon($event, 'add-color');
} elseif ($event->getSubject() === 'created_public') {
$subject = $this->l->t('{file} was created in a public folder');
$this->setIcon($event, 'add-color');
} elseif ($event->getSubject() === 'changed_self') {
$subject = $this->l->t('You changed {file}');
if ($this->fileIsEncrypted) {
$subject = $this->l->t('You changed an encrypted file in {file}');
}
$this->setIcon($event, 'change');
} elseif ($event->getSubject() === 'changed_by') {
$subject = $this->l->t('{user} changed {file}');
if ($this->fileIsEncrypted) {
$subject = $this->l->t('{user} changed an encrypted file in {file}');
}
$this->setIcon($event, 'change');
} elseif ($event->getSubject() === 'deleted_self') {
$subject = $this->l->t('You deleted {file}');
if ($this->fileIsEncrypted) {
$subject = $this->l->t('You deleted an encrypted file in {file}');
}
$this->setIcon($event, 'delete-color');
} elseif ($event->getSubject() === 'deleted_by') {
$subject = $this->l->t('{user} deleted {file}');
if ($this->fileIsEncrypted) {
$subject = $this->l->t('{user} deleted an encrypted file in {file}');
}
$this->setIcon($event, 'delete-color');
} elseif ($event->getSubject() === 'restored_self') {
$subject = $this->l->t('You restored {file}');
$this->setIcon($event, 'actions/history', 'core');
} elseif ($event->getSubject() === 'restored_by') {
$subject = $this->l->t('{user} restored {file}');
$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 {
if ($this->isHiddenFile($newFileName)) {
$subject = $this->l->t('You renamed {oldfile} to {newfile} (hidden)');
} else {
$subject = $this->l->t('You renamed {oldfile} to {newfile}');
}
}
$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 {
if ($this->isHiddenFile($newFileName)) {
$subject = $this->l->t('{user} renamed {oldfile} to {newfile} (hidden)');
} else {
$subject = $this->l->t('{user} renamed {oldfile} to {newfile}');
}
}
$this->setIcon($event, 'change');
} elseif ($event->getSubject() === 'moved_self') {
$subject = $this->l->t('You moved {oldfile} to {newfile}');
$this->setIcon($event, 'change');
} elseif ($event->getSubject() === 'moved_by') {
$subject = $this->l->t('{user} moved {oldfile} to {newfile}');
$this->setIcon($event, 'change');
} else {
throw new \InvalidArgumentException();
}
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);
}
$this->setSubjects($event, $subject, $parsedParameters);
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
$event = $this->eventMerger->mergeEvents('user', $event, $previousEvent);
}
return $event;
}
private function isHiddenFile(string $filename): bool {
return strlen($filename) > 0 && $filename[0] === '.';
}
protected function setSubjects(IEvent $event, string $subject, array $parameters): void {
$event->setRichSubject($subject, $parameters);
}
/**
* @param IEvent $event
* @return array
* @throws \InvalidArgumentException
*/
protected function getParameters(IEvent $event) {
$parameters = $event->getSubjectParameters();
switch ($event->getSubject()) {
case 'created_self':
case 'created_public':
case 'changed_self':
case 'deleted_self':
case 'restored_self':
return [
'file' => $this->getFile($parameters[0], $event),
];
case 'created_by':
case 'changed_by':
case 'deleted_by':
case 'restored_by':
if ($parameters[1] === '') {
// External user via public link share
return [
'file' => $this->getFile($parameters[0], $event),
];
}
return [
'file' => $this->getFile($parameters[0], $event),
'user' => $this->getUser($parameters[1]),
];
case 'renamed_self':
case 'moved_self':
return [
'newfile' => $this->getFile($parameters[0]),
'oldfile' => $this->getFile($parameters[1]),
];
case 'renamed_by':
case 'moved_by':
if ($parameters[1] === '') {
// External user via public link share
return [
'newfile' => $this->getFile($parameters[0]),
'oldfile' => $this->getFile($parameters[2]),
];
}
return [
'newfile' => $this->getFile($parameters[0]),
'user' => $this->getUser($parameters[1]),
'oldfile' => $this->getFile($parameters[2]),
];
}
return [];
}
/**
* @param array|string $parameter
* @param IEvent|null $event
* @return array
* @throws \InvalidArgumentException
*/
protected function getFile($parameter, IEvent $event = null) {
if (is_array($parameter)) {
$path = reset($parameter);
$id = (string) 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');
}
$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' => $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,
'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());
$files = $userFolder->getById($fileId);
if (empty($files)) {
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;
}
$file = array_shift($files);
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) {
// 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' => $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;
}
}
@@ -0,0 +1,92 @@
<?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\Files\Activity\Settings;
class FavoriteAction extends FileActivitySettings {
/**
* @return string Lowercase a-z and underscore only identifier
* @since 11.0.0
*/
public function getIdentifier() {
return 'favorite';
}
/**
* @return string A translated string
* @since 11.0.0
*/
public function getName() {
return $this->l->t('A file has been added to or removed from your <strong>favorites</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 5;
}
/**
* @return bool True when the option can be changed for the stream
* @since 11.0.0
*/
public function canChangeStream() {
return false;
}
/**
* @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;
}
/**
* @return bool True when the option can be changed for the stream
* @since 11.0.0
*/
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;
}
}
@@ -0,0 +1,49 @@
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2020 Robin Appelman <robin@icewind.nl>
*
* @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\Files\Activity\Settings;
use OCP\Activity\ActivitySettings;
use OCP\IL10N;
abstract class FileActivitySettings extends ActivitySettings {
/** @var IL10N */
protected $l;
/**
* @param IL10N $l
*/
public function __construct(IL10N $l) {
$this->l = $l;
}
public function getGroupIdentifier() {
return 'files';
}
public function getGroupName() {
return $this->l->t('Files');
}
}
@@ -0,0 +1,68 @@
<?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\Files\Activity\Settings;
class FileChanged extends FileActivitySettings {
/**
* @return string Lowercase a-z and underscore only identifier
* @since 11.0.0
*/
public function getIdentifier() {
return 'file_changed';
}
/**
* @return string A translated string
* @since 11.0.0
*/
public function getName() {
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.
* @since 11.0.0
*/
public function getPriority() {
return 2;
}
public function canChangeMail() {
return true;
}
public function isDefaultEnabledMail() {
return false;
}
public function canChangeNotification() {
return true;
}
public function isDefaultEnabledNotification() {
return false;
}
}
@@ -0,0 +1,92 @@
<?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\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;
}
}