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,106 @@
<?php
/**
* @copyright Copyright (c) 2016 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\Activity\Controller;
use OCA\Activity\CurrentUser;
use OCA\Activity\Data;
use OCA\Activity\GroupHelper;
use OCA\Activity\UserSettings;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\OCSController;
use OCP\IRequest;
class APIv1Controller extends OCSController {
/**
* @param string $appName
* @param IRequest $request
* @param Data $data
* @param GroupHelper $groupHelper
* @param UserSettings $userSettings
* @param CurrentUser $currentUser
*/
public function __construct($appName,
IRequest $request,
protected Data $data,
protected GroupHelper $groupHelper,
protected UserSettings $userSettings,
protected CurrentUser $currentUser) {
parent::__construct($appName, $request);
}
/**
* @NoAdminRequired
*
* @param int $start
* @param int $count
* @return DataResponse
*/
public function get($start = 0, $count = 30) {
if ($start !== 0) {
$start = $this->getSinceFromOffset($start);
}
$activities = $this->data->get(
$this->groupHelper,
$this->userSettings,
$this->currentUser->getUID(), $start, $count, 'desc', 'all'
);
$entries = [];
foreach ($activities['data'] as $entry) {
$entries[] = [
'id' => $entry['activity_id'],
'subject' => $entry['subject'],
'message' => $entry['message'],
'file' => $entry['object_name'],
'link' => $entry['link'],
'date' => date('c', $entry['timestamp']),
];
}
return new DataResponse($entries);
}
/**
* @param int $offset
* @return int
*/
protected function getSinceFromOffset($offset) {
$query = \OC::$server->getDatabaseConnection()->getQueryBuilder();
$query->select('activity_id')
->from('activity')
->where($query->expr()->eq('affecteduser', $query->createNamedParameter($this->currentUser->getUID())))
->orderBy('activity_id', 'desc')
->setFirstResult($offset - 1)
->setMaxResults(1);
$result = $query->execute();
$row = $result->fetch();
$result->closeCursor();
if ($row) {
return (int) $row['activity_id'];
}
return 0;
}
}
@@ -0,0 +1,366 @@
<?php
declare(strict_types=1);
/**
* @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/>
*
*/
namespace OCA\Activity\Controller;
use OCA\Activity\Data;
use OCA\Activity\Exception\InvalidFilterException;
use OCA\Activity\GroupHelper;
use OCA\Activity\UserSettings;
use OCA\Activity\ViewInfoCache;
use OCP\Activity\IFilter;
use OCP\Activity\IManager;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\OCSController;
use OCP\Files\FileInfo;
use OCP\Files\IMimeTypeDetector;
use OCP\IPreview;
use OCP\IRequest;
use OCP\IURLGenerator;
use OCP\IUser;
use OCP\IUserSession;
class APIv2Controller extends OCSController {
/** @var string */
protected $filter;
/** @var int */
protected $since;
/** @var int */
protected $limit;
/** @var string */
protected $sort;
/** @var string */
protected $objectType;
/** @var int */
protected $objectId;
/** @var string */
protected $user;
/** @var bool */
protected $loadPreviews;
public function __construct($appName,
IRequest $request,
protected IManager $activityManager,
protected Data $data,
protected GroupHelper $helper,
protected UserSettings $settings,
protected IURLGenerator $urlGenerator,
protected IUserSession $userSession,
protected IPreview $preview,
protected IMimeTypeDetector $mimeTypeDetector,
protected ViewInfoCache $infoCache,
) {
parent::__construct($appName, $request);
$this->activityManager = $activityManager;
}
/**
* @param string $filter
* @param int $since
* @param int $limit
* @param bool $previews
* @param string $objectType
* @param int $objectId
* @param string $sort
* @throws InvalidFilterException when the filter is invalid
* @throws \OutOfBoundsException when no user is given
*/
protected function validateParameters($filter, $since, $limit, $previews, $objectType, $objectId, $sort) {
$this->filter = \is_string($filter) ? $filter : 'all';
if ($this->filter !== $this->data->validateFilter($this->filter)) {
throw new InvalidFilterException('Invalid filter');
}
$this->since = (int) $since;
$this->limit = (int) $limit;
$this->loadPreviews = (bool) $previews;
$this->objectType = (string) $objectType;
$this->objectId = (int) $objectId;
$this->sort = \in_array($sort, ['asc', 'desc'], true) ? $sort : 'desc';
if (($this->objectType !== '' && $this->objectId === 0) || ($this->objectType === '' && $this->objectId !== 0)) {
// Only allowed together
$this->objectType = '';
$this->objectId = 0;
}
$user = $this->userSession->getUser();
if ($user instanceof IUser) {
$this->user = $user->getUID();
} else {
// No user logged in
throw new \OutOfBoundsException('Not logged in');
}
}
/**
* @NoAdminRequired
*
* @param int $since
* @param int $limit
* @param bool $previews
* @param string $object_type
* @param int $object_id
* @param string $sort
* @return DataResponse
*/
public function getDefault($since = 0, $limit = 50, $previews = false, $object_type = '', $object_id = 0, $sort = 'desc'): DataResponse {
return $this->get('all', $since, $limit, $previews, $object_type, $object_id, $sort);
}
/**
* @NoAdminRequired
*
* @param string $filter
* @param int $since
* @param int $limit
* @param bool $previews
* @param string $object_type
* @param int $object_id
* @param string $sort
* @return DataResponse
*/
public function getFilter($filter, $since = 0, $limit = 50, $previews = false, $object_type = '', $object_id = 0, $sort = 'desc'): DataResponse {
return $this->get($filter, $since, $limit, $previews, $object_type, $object_id, $sort);
}
/**
* @NoAdminRequired
*
* @return DataResponse
*/
public function listFilters(): DataResponse {
$filters = $this->activityManager->getFilters();
$filters = array_map(function (IFilter $filter) {
return [
'id' => $filter->getIdentifier(),
'name' => $filter->getName(),
'icon' => $filter->getIcon(),
'priority' => $filter->getPriority(),
];
}, $filters);
// php 5.6 has problems with usort and objects
usort($filters, static function (array $a, array $b) {
if ($a['priority'] === $b['priority']) {
return ($a['id'] > $b['id']) ? 1 : -1;
}
return $a['priority'] - $b['priority'];
});
return new DataResponse($filters);
}
/**
* @param string $filter
* @param int $since
* @param int $limit
* @param bool $previews
* @param string $filterObjectType
* @param int $filterObjectId
* @param string $sort
* @return DataResponse
*/
protected function get($filter, $since, $limit, $previews, $filterObjectType, $filterObjectId, $sort): DataResponse {
try {
$this->validateParameters($filter, $since, $limit, $previews, $filterObjectType, $filterObjectId, $sort);
} catch (InvalidFilterException $e) {
return new DataResponse([], Http::STATUS_NOT_FOUND);
} catch (\OutOfBoundsException $e) {
return new DataResponse([], Http::STATUS_FORBIDDEN);
}
$this->activityManager->setRequirePNG($this->request->isUserAgent([IRequest::USER_AGENT_CLIENT_IOS]));
try {
$response = $this->data->get(
$this->helper,
$this->settings,
$this->user,
$this->since,
$this->limit,
$this->sort,
$this->filter,
$this->objectType,
$this->objectId
);
} catch (\OutOfBoundsException $e) {
// Invalid since argument
return new DataResponse([], Http::STATUS_FORBIDDEN);
} catch (\BadMethodCallException $e) {
// No activity settings enabled
return new DataResponse([], Http::STATUS_NO_CONTENT);
}
$this->activityManager->setRequirePNG(false);
$headers = $this->generateHeaders($response['headers'], $response['has_more'], $response['data']);
if (empty($response['data']) || $this->request->getHeader('If-None-Match') === $headers['ETag']) {
return new DataResponse([], Http::STATUS_NOT_MODIFIED, $headers);
}
$preparedActivities = [];
foreach ($response['data'] as $activity) {
$activity['datetime'] = date(\DateTime::ATOM, $activity['timestamp']);
unset($activity['timestamp']);
if ($this->loadPreviews) {
$activity['previews'] = [];
if ($activity['object_type'] === 'files') {
if (!empty($activity['objects']) && \is_array($activity['objects'])) {
foreach ($activity['objects'] as $objectId => $objectName) {
if (((int) $objectId) === 0 || $objectName === '') {
// No file, no preview
continue;
}
$activity['previews'][] = $this->getPreview($activity['affecteduser'], (int) $objectId, $objectName);
}
} elseif ($activity['object_id']) {
$activity['previews'][] = $this->getPreview($activity['affecteduser'], (int) $activity['object_id'], $activity['object_name']);
}
}
}
unset($activity['affecteduser']);
$preparedActivities[] = $activity;
}
return new DataResponse($preparedActivities, Http::STATUS_OK, $headers);
}
protected function generateHeaders(array $headers, bool $hasMoreActivities, array $data): array {
if ($hasMoreActivities && isset($headers['X-Activity-Last-Given'])) {
// Set the "Link" header for the next page
$nextPageParameters = [
'since' => $headers['X-Activity-Last-Given'],
'limit' => $this->limit,
'sort' => $this->sort,
];
if ($this->objectType && $this->objectId) {
$nextPageParameters['object_type'] = $this->objectType;
$nextPageParameters['object_id'] = $this->objectId;
}
if ($this->request->getParam('format') !== null) {
$nextPageParameters['format'] = $this->request->getParam('format');
}
$nextPage = $this->request->getServerProtocol(); # http
$nextPage .= '://' . $this->request->getServerHost(); # localhost
$nextPage .= $this->request->getScriptName(); # /ocs/v2.php
$nextPage .= $this->request->getPathInfo(); # /apps/activity/api/v2/activity
$nextPage .= '?' . http_build_query($nextPageParameters);
$headers['Link'] = '<' . $nextPage . '>; rel="next"';
}
$ids = [];
foreach ($data as $activity) {
$ids[] = $activity['activity_id'];
}
$headers['ETag'] = md5(json_encode($ids));
return $headers;
}
protected function getPreview(string $owner, int $fileId, string $filePath): array {
$info = $this->infoCache->getInfoById($owner, $fileId, $filePath);
if (!$info['exists'] || $info['view'] !== '') {
return $this->getPreviewFromPath($fileId, $filePath, $info);
}
$preview = [
'link' => $this->urlGenerator->linkToRouteAbsolute('files.viewcontroller.showFile', ['fileid' => $fileId]),
'source' => '',
'mimeType' => 'application/octet-stream',
'isMimeTypeIcon' => true,
'fileId' => $fileId,
'view' => 'files',
'filename' => basename($filePath),
];
// show a preview image if the file still exists
if ($info['is_dir']) {
$preview['source'] = $this->getPreviewPathFromMimeType('dir');
$preview['mimeType'] = 'dir';
} else {
$fileInfo = $info['node'] ?? null;
if (!($fileInfo instanceof FileInfo)) {
return $this->getPreviewFromPath($fileId, $filePath, $info);
}
$preview['filePath'] = $fileInfo->getPath();
if ($this->preview->isAvailable($fileInfo)) {
$params = [
'forceIcon' => 0,
'a' => 0,
'x' => 250,
'y' => 250,
'fileId' => $fileId,
'c' => $fileInfo->getEtag(),
];
$preview['source'] = $this->urlGenerator->linkToRouteAbsolute('core.Preview.getPreviewByFileId', $params);
$preview['mimeType'] = $fileInfo->getMimetype() ?: 'application/octet-stream';
$preview['isMimeTypeIcon'] = false;
} else {
$preview['mimeType'] = $fileInfo->getMimetype() ?: 'application/octet-stream';
$preview['source'] = $this->getPreviewPathFromMimeType($preview['mimeType']);
}
}
return $preview;
}
protected function getPreviewFromPath(int $fileId, string $filePath, array $info): array {
$mimeType = $info['is_dir'] ? 'dir' : $this->mimeTypeDetector->detectPath($filePath);
return [
'link' => $this->urlGenerator->linkToRouteAbsolute('files.viewcontroller.showFile', ['fileid' => $fileId]),
'source' => $this->getPreviewPathFromMimeType($mimeType),
'mimeType' => $mimeType,
'isMimeTypeIcon' => true,
'fileId' => $fileId,
'view' => $info['view'] ?: 'files',
'filename' => basename($filePath),
];
}
protected function getPreviewPathFromMimeType(string $mimeType): string {
$mimeTypeIcon = $this->mimeTypeDetector->mimeTypeIcon($mimeType);
if (substr($mimeTypeIcon, -4) === '.png') {
$mimeTypeIcon = substr($mimeTypeIcon, 0, -4) . '.svg';
}
return $this->urlGenerator->getAbsoluteURL($mimeTypeIcon);
}
}
@@ -0,0 +1,147 @@
<?php
/**
* @copyright Copyright (c) 2016, ownCloud, Inc.
*
* @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\Activity\Controller;
use OCA\Activity\Data;
use OCA\Activity\Event\LoadAdditionalScriptsEvent;
use OCA\Viewer\Event\LoadViewer;
use OCP\Activity\IFilter;
use OCP\Activity\IManager;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Services\IInitialState;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IConfig;
use OCP\IL10N;
use OCP\IRequest;
use OCP\IURLGenerator;
class ActivitiesController extends Controller {
public function __construct(
string $appName,
IRequest $request,
private ?string $userId,
private IConfig $config,
private Data $data,
private IL10N $l10n,
private IEventDispatcher $eventDispatcher,
private IInitialState $initialState,
private IURLGenerator $urlGenerator,
private IManager $activityManager,
) {
parent::__construct($appName, $request);
}
/**
* @NoAdminRequired
* @NoCSRFRequired
*
* @param string $filter
* @return TemplateResponse
*/
public function index(): TemplateResponse {
return $this->showList('all');
}
/**
* @NoAdminRequired
* @NoCSRFRequired
*
* @param string $filter
* @return TemplateResponse
*/
public function showList(string $filter = 'all'): TemplateResponse {
$filter = $this->data->validateFilter($filter);
$event = new LoadAdditionalScriptsEvent($filter);
$this->eventDispatcher->dispatchTyped($event);
$this->eventDispatcher->dispatch(LoadAdditionalScriptsEvent::EVENT_ENTITY, $event);
// Load the viewer
if (class_exists(LoadViewer::class)) {
$this->eventDispatcher->dispatchTyped(new LoadViewer());
}
$this->initialState->provideInitialState('settings', [
'enableAvatars' => $this->config->getSystemValue('enable_avatars', true),
'personalSettingsLink' => $this->getPersonalSettingsLink(),
'rssLink' => $this->getRSSLink(),
]);
$this->initialState->provideInitialState('filter', $filter);
$this->initialState->provideInitialState('navigationList', $this->getLinkList());
\OCP\Util::addScript($this->appName, 'activity-app');
\OCP\Util::addStyle($this->appName, 'style');
return new TemplateResponse($this->appName, 'app-main');
}
/**
* Get link for personal settings
*/
protected function getPersonalSettingsLink(): string {
return $this->urlGenerator->linkToRouteAbsolute('settings.PersonalSettings.index', ['section' => 'notifications']);
}
/**
* Link to RSS feed if there is a RSS token, empty string otherwise
*/
protected function getRSSLink(): string {
$rssToken = $this->config->getUserValue($this->userId, 'activity', 'rsstoken');
if ($rssToken) {
return $this->urlGenerator->linkToRouteAbsolute('activity.Feed.show', ['token' => $rssToken]);
} else {
return '';
}
}
/**
* Get all items for the users we want to send an email to
*
* @return array Notification data (user => array of rows from the table)
*/
protected function getLinkList(): array {
$filters = $this->activityManager->getFilters();
usort($filters, static function (IFilter $a, IFilter $b) {
if ($a->getPriority() === $b->getPriority()) {
return (int) ($a->getIdentifier() > $b->getIdentifier());
}
return (int) ($a->getPriority() > $b->getPriority());
});
$entries = [];
foreach ($filters as $filter) {
$entries[] = [
'id' => $filter->getIdentifier(),
'icon' => $filter->getIcon(),
'name' => $filter->getName(),
'url' => $this->urlGenerator->linkToRoute('activity.Activities.showList', ['filter' => $filter->getIdentifier()]),
];
}
return $entries;
}
}
@@ -0,0 +1,109 @@
<?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/>
*
*/
namespace OCA\Activity\Controller;
use OCA\Activity\Data;
use OCA\Activity\GroupHelper;
use OCA\Activity\UserSettings;
use OCA\Theming\ThemingDefaults;
use OCP\Activity\IManager;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\IConfig;
use OCP\IL10N;
use OCP\IRequest;
use OCP\IURLGenerator;
use OCP\L10N\IFactory;
class FeedController extends Controller {
public const DEFAULT_PAGE_SIZE = 30;
protected IL10N $l;
public function __construct(
string $appName,
IRequest $request,
protected Data $data,
protected GroupHelper $helper,
protected UserSettings $settings,
protected IURLGenerator $urlGenerator,
protected IManager $activityManager,
protected IFactory $l10nFactory,
protected IConfig $config,
protected ThemingDefaults $themingDefaults,
) {
parent::__construct($appName, $request);
}
/**
* @PublicPage
* @NoCSRFRequired
*
* @return TemplateResponse
*/
public function show() {
try {
$user = $this->activityManager->getCurrentUserId();
$userLang = $this->config->getUserValue($user, 'core', 'lang');
// Overwrite user and language in the helper
$this->l = $this->l10nFactory->get('activity', $userLang);
$this->helper->setL10n($this->l);
$description = $this->l->t('Personal activity feed for %s', $user);
$response = $this->data->get($this->helper, $this->settings, $user, 0, self::DEFAULT_PAGE_SIZE, 'desc', 'all');
$activities = $response['data'];
} catch (\UnexpectedValueException $e) {
$this->l = $this->l10nFactory->get('activity');
$description = $this->l->t('Your feed URL is invalid');
$activities = [
[
'activity_id' => -1,
'timestamp' => time(),
'subject' => true,
'subject_prepared' => $description,
]
];
}
$title = $this->themingDefaults->getTitle();
$response = new TemplateResponse('activity', 'rss', [
'rssLang' => $this->l->getLanguageCode(),
'rssLink' => $this->urlGenerator->linkToRouteAbsolute('activity.Feed.show'),
'rssPubDate' => date('r'),
'description' => $description,
'title' => $title !== '' ? $this->l->t('Activity feed for %1$s', [$title]) : $this->l->t('Activity feed'),
'activities' => $activities,
], '');
if (stristr($this->request->getHeader('accept'), 'application/rss+xml')) {
$response->addHeader('Content-Type', 'application/rss+xml');
} else {
$response->addHeader('Content-Type', 'text/xml; charset=UTF-8');
}
return $response;
}
}
@@ -0,0 +1,218 @@
<?php
/**
* @copyright Copyright (c) 2017 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\Activity\Controller;
use OCA\Activity\Extension\Files;
use OCP\Activity\IManager as IActivityManager;
use OCP\App\IAppManager;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\OCSController;
use OCP\Files\InvalidPathException;
use OCP\Files\IRootFolder;
use OCP\Files\NotFoundException;
use OCP\IDBConnection;
use OCP\IRequest;
use OCP\IUser;
use OCP\IUserManager;
class RemoteActivityController extends OCSController {
public function __construct($appName,
IRequest $request,
protected IDBConnection $db,
protected IUserManager $userManager,
protected IAppManager $appManager,
protected IRootFolder $rootFolder,
protected IActivityManager $activityManager) {
parent::__construct($appName, $request);
}
/**
* @PublicPage
* @NoCSRFRequired
*
* @param string $token
* @param string[] $to
* @param string[] $actor
* @param string $type
* @param string $updated
* @param string[] $object
* @param string[] $target
* @param string[] $origin
* @return DataResponse
*/
public function receiveActivity($token, array $to, array $actor, $type, $updated, array $object = [], array $target = [], array $origin = []) {
$date = \DateTime::createFromFormat(\DateTime::W3C, $updated);
if ($date === false) {
return new DataResponse([], Http::STATUS_BAD_REQUEST);
}
$time = $date->getTimestamp();
if (!isset($to['type'], $to['name']) || $to['type'] !== 'Person') {
return new DataResponse([], Http::STATUS_BAD_REQUEST);
}
$user = $this->userManager->get($to['name']);
if (!$user instanceof IUser) {
return new DataResponse([], Http::STATUS_NOT_FOUND);
}
if (!isset($actor['type'], $actor['name']) || $actor['type'] !== 'Person') {
return new DataResponse([], Http::STATUS_BAD_REQUEST);
}
if ($user->getCloudId() === $actor['name']) {
return new DataResponse([], Http::STATUS_BAD_REQUEST);
}
if (!$this->appManager->isInstalled('federatedfilesharing')) {
return new DataResponse([], Http::STATUS_NOT_FOUND);
}
$query = $this->db->getQueryBuilder();
$query->select('*')
->from('share_external')
->where($query->expr()->eq('share_token', $query->createNamedParameter($token)))
->andWhere($query->expr()->eq('user', $query->createNamedParameter($user->getUID())));
$result = $query->execute();
$share = $result->fetch();
$result->closeCursor();
if (!is_array($share) || strpos($share['mountpoint'], '{{TemporaryMountPointName#') === 0) {
return new DataResponse([], Http::STATUS_NOT_FOUND);
}
$internalType = $this->translateType($type);
if ($internalType === '') {
return new DataResponse([], Http::STATUS_BAD_REQUEST);
}
$path2 = null;
if ($type === 'Move') {
if (!isset($target['type'], $target['name']) || $target['type'] !== 'Document') {
return new DataResponse([], Http::STATUS_BAD_REQUEST);
}
if (!isset($origin['type'], $origin['name']) || $origin['type'] !== 'Document') {
return new DataResponse([], Http::STATUS_BAD_REQUEST);
}
$path = $share['mountpoint'] . $target['name'];
$path2 = $share['mountpoint'] . $origin['name'];
} else {
if (!isset($object['type'], $object['name']) || $object['type'] !== 'Document') {
return new DataResponse([], Http::STATUS_BAD_REQUEST);
}
$path = $share['mountpoint'] . $object['name'];
}
$subject = $this->getSubject($type, $path, $path2);
if ($subject === '') {
return new DataResponse([], Http::STATUS_BAD_REQUEST);
}
$userFolder = $this->rootFolder->getUserFolder($user->getUID());
try {
$node = $userFolder->get($path);
$fileId = $node->getId();
} catch (NotFoundException $e) {
return new DataResponse([], Http::STATUS_NOT_FOUND);
} catch (InvalidPathException $e) {
return new DataResponse([], Http::STATUS_NOT_FOUND);
}
if ($path2 !== null) {
$secondPath = [$fileId => $path2];
if ($subject === 'moved_by') {
try {
$parent = $node->getParent();
$secondPath = [$parent->getId() => dirname($path2)];
} catch (NotFoundException $e) {
} catch (InvalidPathException $e) {
}
}
$subjectParams = [$secondPath, $actor['name'], [$fileId => $path]];
} else {
$subjectParams = [[$fileId => $path], $actor['name']];
}
$event = $this->activityManager->generateEvent();
try {
$event->setAffectedUser($user->getUID())
->setApp('files')
->setType($internalType)
->setAuthor($actor['name'])
->setObject('files', $fileId, $path)
->setSubject($subject, $subjectParams)
->setTimestamp($time);
$this->activityManager->publish($event);
} catch (\InvalidArgumentException $e) {
return new DataResponse(['activity'], Http::STATUS_BAD_REQUEST);
} catch (\BadMethodCallException $e) {
return new DataResponse(['sending'], Http::STATUS_BAD_REQUEST);
}
return new DataResponse();
}
/**
* @param null|string $path2
*/
protected function getSubject(string $type, string $path, string|null $path2) {
switch ($type) {
case 'Create':
return 'created_by';
case 'Move':
if ($path2 === null) {
return '';
}
if (basename($path) === basename($path2)) {
return 'moved_by';
}
return 'renamed_by';
case 'Update':
return 'changed_by';
case 'Delete':
return 'deleted_by';
}
return '';
}
/**
* @param string $type
* @return string
*/
protected function translateType($type) {
switch ($type) {
case 'Create':
return Files::TYPE_SHARE_CREATED;
case 'Move':
case 'Update':
return Files::TYPE_FILE_CHANGED;
case 'Delete':
return Files::TYPE_SHARE_DELETED;
}
return '';
}
}
@@ -0,0 +1,213 @@
<?php
/**
* @copyright Copyright (c) 2016, ownCloud, Inc.
*
* @author Joas Schilling <coding@schilljs.com>
* @author Lukas Reschke <lukas@statuscode.ch>
*
* @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\Activity\Controller;
use OCA\Activity\CurrentUser;
use OCA\Activity\UserSettings;
use OCP\Activity\IManager;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\DataResponse;
use OCP\IConfig;
use OCP\IL10N;
use OCP\IRequest;
use OCP\IURLGenerator;
use OCP\Security\ISecureRandom;
class SettingsController extends Controller {
protected string $user;
public function __construct(
string $appName,
IRequest $request,
protected IConfig $config,
protected ISecureRandom $random,
protected IURLGenerator $urlGenerator,
protected IManager $manager,
protected UserSettings $userSettings,
protected IL10N $l10n,
CurrentUser $currentUser) {
parent::__construct($appName, $request);
$this->user = (string) $currentUser->getUID();
}
/**
* @NoAdminRequired
*
* @param int $notify_setting_batchtime
* @param bool $notify_setting_self
* @param bool $notify_setting_selfemail
* @param bool $activity_digest
* @return DataResponse
*/
public function personal(
$notify_setting_batchtime = UserSettings::EMAIL_SEND_HOURLY,
$notify_setting_self = false,
$notify_setting_selfemail = false,
$activity_digest = false
) {
$settings = $this->manager->getSettings();
foreach ($settings as $setting) {
$this->config->setUserValue(
$this->user, 'activity',
'notify_notification_' . $setting->getIdentifier(),
(string)(int) $this->request->getParam($setting->getIdentifier() . '_notification', false)
);
if ($setting->canChangeMail()) {
$this->config->setUserValue(
$this->user, 'activity',
'notify_email_' . $setting->getIdentifier(),
(string)(int) $this->request->getParam($setting->getIdentifier() . '_email', false)
);
}
}
$email_batch_time = 3600;
if ($notify_setting_batchtime === UserSettings::EMAIL_SEND_DAILY) {
$email_batch_time = 3600 * 24;
} elseif ($notify_setting_batchtime === UserSettings::EMAIL_SEND_WEEKLY) {
$email_batch_time = 3600 * 24 * 7;
} elseif ($notify_setting_batchtime === UserSettings::EMAIL_SEND_ASAP) {
$email_batch_time = 0;
}
$this->config->setUserValue(
$this->user, 'activity',
'notify_setting_batchtime',
(string)$email_batch_time
);
$this->config->setUserValue(
$this->user, 'activity',
'notify_setting_self',
(string)(int) $notify_setting_self
);
$this->config->setUserValue(
$this->user, 'activity',
'notify_setting_selfemail',
(string)(int) $notify_setting_selfemail
);
$this->config->setUserValue(
$this->user, 'activity',
'notify_setting_activity_digest',
(string)(int) $activity_digest
);
return new DataResponse([
'data' => [
'message' => $this->l10n->t('Your settings have been updated.'),
],
]);
}
/**
* @param int $notify_setting_batchtime
* @param bool $notify_setting_self
* @param bool $notify_setting_selfemail
* @return DataResponse
*/
public function admin(
$notify_setting_batchtime = UserSettings::EMAIL_SEND_HOURLY,
$notify_setting_self = false,
$notify_setting_selfemail = false) {
$settings = $this->manager->getSettings();
foreach ($settings as $setting) {
$this->config->setAppValue(
'activity',
'notify_notification_' . $setting->getIdentifier(),
(string)(int)$this->request->getParam($setting->getIdentifier() . '_notification', false)
);
if ($setting->canChangeMail()) {
$this->config->setAppValue(
'activity',
'notify_email_' . $setting->getIdentifier(),
(string)(int) $this->request->getParam($setting->getIdentifier() . '_email', false)
);
}
}
$email_batch_time = 3600;
if ($notify_setting_batchtime === UserSettings::EMAIL_SEND_DAILY) {
$email_batch_time = 3600 * 24;
} elseif ($notify_setting_batchtime === UserSettings::EMAIL_SEND_WEEKLY) {
$email_batch_time = 3600 * 24 * 7;
} elseif ($notify_setting_batchtime === UserSettings::EMAIL_SEND_ASAP) {
$email_batch_time = 0;
}
$this->config->setAppValue(
'activity',
'notify_setting_batchtime',
(string)$email_batch_time
);
$this->config->setAppValue(
'activity',
'notify_setting_self',
(string)(int) $notify_setting_self
);
$this->config->setAppValue(
'activity',
'notify_setting_selfemail',
(string)(int) $notify_setting_selfemail
);
return new DataResponse([
'data' => [
'message' => $this->l10n->t('Settings have been updated.'),
],
]);
}
/**
* @NoAdminRequired
*
* @param bool $enable true if the feed is enabled
* @return DataResponse
*/
public function feed(bool $enable) {
$token = $tokenUrl = '';
if ($enable === true) {
$conflicts = true;
// Check for collisions
while (!empty($conflicts)) {
$token = $this->random->generate(30, ISecureRandom::CHAR_UPPER . ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_DIGITS);
$conflicts = $this->config->getUsersForUserValue('activity', 'rsstoken', $token);
}
$tokenUrl = $this->urlGenerator->linkToRouteAbsolute('activity.Feed.show', ['token' => $token]);
}
$this->config->setUserValue($this->user, 'activity', 'rsstoken', $token);
return new DataResponse([
'data' => [
'message' => $this->l10n->t('Your settings have been updated.'),
'rsslink' => trim($tokenUrl),
],
]);
}
}