Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoeland Jago Douma <roeland@famdouma.nl>2019-10-29 14:22:15 +0300
committerRoeland Jago Douma <roeland@famdouma.nl>2019-12-02 17:28:47 +0300
commit5274c5426818270460ce05ee0071aa9f189281e6 (patch)
tree5686820b9f0493ddc2a7005c39eee648849b9d79 /apps/files/lib
parentb99134d0a37269b263eef019d1a58317b1d943ed (diff)
Add a transfer ownership background job
This job can be initiated by a user to transfer a file/folder to a target user. The target user will have to accept the job. Once that is done the transfers is initiated in the background. Both parties get notified when the job is done. Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'apps/files/lib')
-rw-r--r--apps/files/lib/AppInfo/Application.php12
-rw-r--r--apps/files/lib/BackgroundJob/TransferOwnership.php183
-rw-r--r--apps/files/lib/Controller/TransferOwnershipController.php181
-rw-r--r--apps/files/lib/Db/TransferOwnership.php60
-rw-r--r--apps/files/lib/Db/TransferOwnershipMapper.php47
-rw-r--r--apps/files/lib/Migration/Version11301Date20191113195931.php72
-rw-r--r--apps/files/lib/Notification/Notifier.php243
-rw-r--r--apps/files/lib/Settings/PersonalSettings.php46
8 files changed, 842 insertions, 2 deletions
diff --git a/apps/files/lib/AppInfo/Application.php b/apps/files/lib/AppInfo/Application.php
index 1ffd5e96471..f4897d08e54 100644
--- a/apps/files/lib/AppInfo/Application.php
+++ b/apps/files/lib/AppInfo/Application.php
@@ -35,6 +35,7 @@ use OCA\Files\Controller\ApiController;
use OCA\Files\Controller\ViewController;
use OCA\Files\Event\LoadAdditionalScriptsEvent;
use OCA\Files\Listener\LegacyLoadAdditionalScriptsAdapter;
+use OCA\Files\Notification\Notifier;
use OCA\Files\Service\TagService;
use OCP\AppFramework\App;
use OCP\Collaboration\Resources\IManager;
@@ -42,8 +43,11 @@ use OCP\EventDispatcher\IEventDispatcher;
use OCP\IContainer;
class Application extends App {
+
+ public const APP_ID = 'files';
+
public function __construct(array $urlParams=array()) {
- parent::__construct('files', $urlParams);
+ parent::__construct(self::APP_ID, $urlParams);
$container = $this->getContainer();
$server = $container->getServer();
@@ -71,7 +75,7 @@ class Application extends App {
return new TagService(
$c->query('ServerContainer')->getUserSession(),
$c->query('ServerContainer')->getActivityManager(),
- $c->query('ServerContainer')->getTagManager()->load('files'),
+ $c->query('ServerContainer')->getTagManager()->load(self::APP_ID),
$homeFolder,
$server->getEventDispatcher()
);
@@ -93,5 +97,9 @@ class Application extends App {
/** @var IEventDispatcher $dispatcher */
$dispatcher = $container->query(IEventDispatcher::class);
$dispatcher->addServiceListener(LoadAdditionalScriptsEvent::class, LegacyLoadAdditionalScriptsAdapter::class);
+
+ /** @var \OCP\Notification\IManager $notifications */
+ $notifications = $container->query(\OCP\Notification\IManager::class);
+ $notifications->registerNotifierService(Notifier::class);
}
}
diff --git a/apps/files/lib/BackgroundJob/TransferOwnership.php b/apps/files/lib/BackgroundJob/TransferOwnership.php
new file mode 100644
index 00000000000..3e505cb19bf
--- /dev/null
+++ b/apps/files/lib/BackgroundJob/TransferOwnership.php
@@ -0,0 +1,183 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * @copyright Copyright (c) 2019, Roeland Jago Douma <roeland@famdouma.nl>
+ *
+ * @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\BackgroundJob;
+
+use OCA\Files\AppInfo\Application;
+use OCA\Files\Db\TransferOwnership as Transfer;
+use OCA\Files\Db\TransferOwnershipMapper;
+use OCA\Files\Exception\TransferOwnershipException;
+use OCA\Files\Service\OwnershipTransferService;
+use OCP\AppFramework\Utility\ITimeFactory;
+use OCP\BackgroundJob\QueuedJob;
+use OCP\Files\IRootFolder;
+use OCP\ILogger;
+use OCP\IUser;
+use OCP\IUserManager;
+use OCP\Notification\IManager as NotificationManager;
+use function ltrim;
+
+class TransferOwnership extends QueuedJob {
+
+ /** @var IUserManager $userManager */
+ private $userManager;
+
+ /** @var OwnershipTransferService */
+ private $transferService;
+
+ /** @var ILogger */
+ private $logger;
+
+ /** @var NotificationManager */
+ private $notificationManager;
+
+ /** @var TransferOwnershipMapper */
+ private $mapper;
+ /** @var IRootFolder */
+ private $rootFolder;
+
+ public function __construct(ITimeFactory $timeFactory,
+ IUserManager $userManager,
+ OwnershipTransferService $transferService,
+ ILogger $logger,
+ NotificationManager $notificationManager,
+ TransferOwnershipMapper $mapper,
+ IRootFolder $rootFolder) {
+ parent::__construct($timeFactory);
+
+ $this->userManager = $userManager;
+ $this->transferService = $transferService;
+ $this->logger = $logger;
+ $this->notificationManager = $notificationManager;
+ $this->mapper = $mapper;
+ $this->rootFolder = $rootFolder;
+ }
+
+ protected function run($argument) {
+ $id = $argument['id'];
+
+ $transfer = $this->mapper->getById($id);
+ $sourceUser = $transfer->getSourceUser();
+ $destinationUser = $transfer->getTargetUser();
+ $fileId = $transfer->getFileId();
+
+ $userFolder = $this->rootFolder->getUserFolder($sourceUser);
+ $nodes = $userFolder->getById($fileId);
+
+ if (empty($nodes)) {
+ $this->logger->alert('Could not transfer ownership: Node not found');
+ $this->failedNotication($transfer);
+ return;
+ }
+ $path = $userFolder->getRelativePath($nodes[0]->getPath());
+
+ $sourceUserObject = $this->userManager->get($sourceUser);
+ $destinationUserObject = $this->userManager->get($destinationUser);
+
+ if (!$sourceUserObject instanceof IUser) {
+ $this->logger->alert('Could not transfer ownership: Unknown source user ' . $sourceUser);
+ $this->failedNotication($transfer);
+ return;
+ }
+
+ if (!$destinationUserObject instanceof IUser) {
+ $this->logger->alert("Unknown destination user $destinationUser");
+ $this->failedNotication($transfer);
+ return;
+ }
+
+ try {
+ $this->transferService->transfer(
+ $sourceUserObject,
+ $destinationUserObject,
+ ltrim($path, '/')
+ );
+ $this->successNotification($transfer);
+ } catch (TransferOwnershipException $e) {
+ $this->logger->logException($e);
+ $this->failedNotication($transfer);
+ }
+
+ $this->mapper->delete($transfer);
+
+ }
+
+ private function failedNotication(Transfer $transfer): void {
+ // Send notification to source user
+ $notification = $this->notificationManager->createNotification();
+ $notification->setUser($transfer->getSourceUser())
+ ->setApp(Application::APP_ID)
+ ->setDateTime($this->time->getDateTime())
+ ->setSubject('transferOwnershipFailedSource', [
+ 'sourceUser' => $transfer->getSourceUser(),
+ 'targetUser' => $transfer->getTargetUser(),
+ 'nodeName' => $transfer->getNodeName(),
+ ])
+ ->setObject('transfer', (string)$transfer->getId());
+ $this->notificationManager->notify($notification);
+
+ // Send notification to source user
+ $notification = $this->notificationManager->createNotification();
+ $notification->setUser($transfer->getTargetUser())
+ ->setApp(Application::APP_ID)
+ ->setDateTime($this->time->getDateTime())
+ ->setSubject('transferOwnershipFailedTarget', [
+ 'sourceUser' => $transfer->getSourceUser(),
+ 'targetUser' => $transfer->getTargetUser(),
+ 'nodeName' => $transfer->getNodeName(),
+ ])
+ ->setObject('transfer', (string)$transfer->getId());
+ $this->notificationManager->notify($notification);
+ }
+
+ private function successNotification(Transfer $transfer): void {
+ // Send notification to source user
+ $notification = $this->notificationManager->createNotification();
+ $notification->setUser($transfer->getSourceUser())
+ ->setApp(Application::APP_ID)
+ ->setDateTime($this->time->getDateTime())
+ ->setSubject('transferOwnershipDoneSource', [
+ 'sourceUser' => $transfer->getSourceUser(),
+ 'targetUser' => $transfer->getTargetUser(),
+ 'nodeName' => $transfer->getNodeName(),
+ ])
+ ->setObject('transfer', (string)$transfer->getId());
+ $this->notificationManager->notify($notification);
+
+ // Send notification to source user
+ $notification = $this->notificationManager->createNotification();
+ $notification->setUser($transfer->getTargetUser())
+ ->setApp(Application::APP_ID)
+ ->setDateTime($this->time->getDateTime())
+ ->setSubject('transferOwnershipDoneTarget', [
+ 'sourceUser' => $transfer->getSourceUser(),
+ 'targetUser' => $transfer->getTargetUser(),
+ 'nodeName' => $transfer->getNodeName(),
+ ])
+ ->setObject('transfer', (string)$transfer->getId());
+ $this->notificationManager->notify($notification);
+ }
+}
diff --git a/apps/files/lib/Controller/TransferOwnershipController.php b/apps/files/lib/Controller/TransferOwnershipController.php
new file mode 100644
index 00000000000..b01596fc29d
--- /dev/null
+++ b/apps/files/lib/Controller/TransferOwnershipController.php
@@ -0,0 +1,181 @@
+<?php
+declare(strict_types=1);
+/**
+ * @copyright Copyright (c) 2019, Roeland Jago Douma <roeland@famdouma.nl>
+ *
+ * @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\Controller;
+
+use OCA\Files\BackgroundJob\TransferOwnership;
+use OCA\Files\Db\TransferOwnershipMapper;
+use OCP\AppFramework\Db\DoesNotExistException;
+use OCP\AppFramework\Http;
+use OCP\AppFramework\Http\DataResponse;
+use OCP\AppFramework\OCSController;
+use OCP\AppFramework\Utility\ITimeFactory;
+use OCP\BackgroundJob\IJobList;
+use OCP\Files\IRootFolder;
+use OCP\IRequest;
+use OCP\IUserManager;
+use OCP\Notification\IManager as NotificationManager;
+
+class TransferOwnershipController extends OCSController {
+
+ /** @var string */
+ private $userId;
+ /** @var NotificationManager */
+ private $notificationManager;
+ /** @var ITimeFactory */
+ private $timeFactory;
+ /** @var IJobList */
+ private $jobList;
+ /** @var TransferOwnershipMapper */
+ private $mapper;
+ /** @var IUserManager */
+ private $userManager;
+ /** @var IRootFolder */
+ private $rootFolder;
+
+ public function __construct(string $appName,
+ IRequest $request,
+ string $userId,
+ NotificationManager $notificationManager,
+ ITimeFactory $timeFactory,
+ IJobList $jobList,
+ TransferOwnershipMapper $mapper,
+ IUserManager $userManager,
+ IRootFolder $rootFolder) {
+ parent::__construct($appName, $request);
+
+ $this->userId = $userId;
+ $this->notificationManager = $notificationManager;
+ $this->timeFactory = $timeFactory;
+ $this->jobList = $jobList;
+ $this->mapper = $mapper;
+ $this->userManager = $userManager;
+ $this->rootFolder = $rootFolder;
+ }
+
+
+ /**
+ * @NoAdminRequired
+ */
+ public function transfer(string $recipient, string $path): DataResponse {
+ $recipientUser = $this->userManager->get($recipient);
+
+ if ($recipientUser === null) {
+ return new DataResponse([], Http::STATUS_BAD_REQUEST);
+ }
+
+ $userRoot = $this->rootFolder->getUserFolder($this->userId);
+
+ try {
+ $node = $userRoot->get($path);
+ } catch (\Exception $e) {
+ return new DataResponse([], Http::STATUS_BAD_REQUEST);
+ }
+
+ $transferOwnership = new \OCA\Files\Db\TransferOwnership();
+ $transferOwnership->setSourceUser($this->userId);
+ $transferOwnership->setTargetUser($recipient);
+ $transferOwnership->setFileId($node->getId());
+ $transferOwnership->setNodeName($node->getName());
+ $transferOwnership = $this->mapper->insert($transferOwnership);
+
+ $notification = $this->notificationManager->createNotification();
+ $notification->setUser($recipient)
+ ->setApp($this->appName)
+ ->setDateTime($this->timeFactory->getDateTime())
+ ->setSubject('transferownershipRequest', [
+ 'sourceUser' => $this->userId,
+ 'targetUser' => $recipient,
+ 'nodeName' => $node->getName(),
+ ])
+ ->setObject('transfer', (string)$transferOwnership->getId());
+
+ $this->notificationManager->notify($notification);
+
+ return new DataResponse([]);
+ }
+
+ /**
+ * @NoAdminRequired
+ */
+ public function accept(int $id): DataResponse {
+ try {
+ $transferOwnership = $this->mapper->getById($id);
+ } catch (DoesNotExistException $e) {
+ return new DataResponse([], Http::STATUS_NOT_FOUND);
+ }
+
+ if ($transferOwnership->getTargetUser() !== $this->userId) {
+ return new DataResponse([], Http::STATUS_FORBIDDEN);
+ }
+
+ $this->jobList->add(TransferOwnership::class, [
+ 'id' => $transferOwnership->getId(),
+ ]);
+
+ $notification = $this->notificationManager->createNotification();
+ $notification->setApp('files')
+ ->setObject('transfer', (string)$id);
+ $this->notificationManager->markProcessed($notification);
+
+ return new DataResponse([], Http::STATUS_OK);
+ }
+
+ /**
+ * @NoAdminRequired
+ */
+ public function reject(int $id): DataResponse {
+ try {
+ $transferOwnership = $this->mapper->getById($id);
+ } catch (DoesNotExistException $e) {
+ return new DataResponse([], Http::STATUS_NOT_FOUND);
+ }
+
+ if ($transferOwnership->getTargetUser() !== $this->userId) {
+ return new DataResponse([], Http::STATUS_FORBIDDEN);
+ }
+
+ $notification = $this->notificationManager->createNotification();
+ $notification->setApp('files')
+ ->setObject('transfer', (string)$id);
+ $this->notificationManager->markProcessed($notification);
+
+ $notification = $this->notificationManager->createNotification();
+ $notification->setUser($transferOwnership->getSourceUser())
+ ->setApp($this->appName)
+ ->setDateTime($this->timeFactory->getDateTime())
+ ->setSubject('transferownershipRequestDenied', [
+ 'sourceUser' => $transferOwnership->getSourceUser(),
+ 'targetUser' => $transferOwnership->getTargetUser(),
+ 'nodeName' => $transferOwnership->getNodeName()
+ ])
+ ->setObject('transfer', (string)$transferOwnership->getId());
+ $this->notificationManager->notify($notification);
+
+ $this->mapper->delete($transferOwnership);
+
+ return new DataResponse([], Http::STATUS_OK);
+ }
+
+}
diff --git a/apps/files/lib/Db/TransferOwnership.php b/apps/files/lib/Db/TransferOwnership.php
new file mode 100644
index 00000000000..34384991354
--- /dev/null
+++ b/apps/files/lib/Db/TransferOwnership.php
@@ -0,0 +1,60 @@
+<?php
+declare(strict_types=1);
+/**
+ * @copyright Copyright (c) 2019, Roeland Jago Douma <roeland@famdouma.nl>
+ *
+ * @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\Db;
+
+use OCP\AppFramework\Db\Entity;
+
+/**
+ * @method void setSourceUser(string $uid)
+ * @method string getSourceUser()
+ * @method void setTargetUser(string $uid)
+ * @method string getTargetUser()
+ * @method void setFileId(int $fileId)
+ * @method int getFileId()
+ * @method void setNodeName(string $name)
+ * @method string getNodeName()
+ */
+class TransferOwnership extends Entity {
+ /** @var string */
+ protected $sourceUser;
+
+ /** @var string */
+ protected $targetUser;
+
+ /** @var integer */
+ protected $fileId;
+
+ /** @var string */
+ protected $nodeName;
+
+ public function __construct() {
+ $this->addType('sourceUser', 'string');
+ $this->addType('targetUser', 'string');
+ $this->addType('fileId', 'integer');
+ $this->addType('nodeName', 'string');
+ }
+
+
+}
diff --git a/apps/files/lib/Db/TransferOwnershipMapper.php b/apps/files/lib/Db/TransferOwnershipMapper.php
new file mode 100644
index 00000000000..4918d4cdbf7
--- /dev/null
+++ b/apps/files/lib/Db/TransferOwnershipMapper.php
@@ -0,0 +1,47 @@
+<?php
+declare(strict_types=1);
+/**
+ * @copyright Copyright (c) 2019, Roeland Jago Douma <roeland@famdouma.nl>
+ *
+ * @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\Db;
+
+use OCP\AppFramework\Db\QBMapper;
+use OCP\IDBConnection;
+
+class TransferOwnershipMapper extends QBMapper {
+ public function __construct(IDBConnection $db) {
+ parent::__construct($db, 'user_transfer_ownership', TransferOwnership::class);
+ }
+
+ public function getById(int $id): TransferOwnership {
+ $qb = $this->db->getQueryBuilder();
+
+ $qb->select('*')
+ ->from($this->getTableName())
+ ->where(
+ $qb->expr()->eq('id', $qb->createNamedParameter($id))
+ );
+
+ return $this->findEntity($qb);
+ }
+
+}
diff --git a/apps/files/lib/Migration/Version11301Date20191113195931.php b/apps/files/lib/Migration/Version11301Date20191113195931.php
new file mode 100644
index 00000000000..d4044434c76
--- /dev/null
+++ b/apps/files/lib/Migration/Version11301Date20191113195931.php
@@ -0,0 +1,72 @@
+<?php
+declare(strict_types=1);
+/**
+ * @copyright Copyright (c) 2019, Roeland Jago Douma <roeland@famdouma.nl>
+ *
+ * @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\Migration;
+
+use Closure;
+use OCP\DB\ISchemaWrapper;
+use OCP\Migration\SimpleMigrationStep;
+use OCP\Migration\IOutput;
+
+class Version11301Date20191113195931 extends SimpleMigrationStep {
+
+ /**
+ * @param IOutput $output
+ * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
+ * @param array $options
+ * @return null|ISchemaWrapper
+ */
+ public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) {
+ /** @var ISchemaWrapper $schema */
+ $schema = $schemaClosure();
+
+ $table = $schema->createTable('user_transfer_ownership');
+ $table->addColumn('id', 'integer', [
+ 'autoincrement' => true,
+ 'notnull' => true,
+ 'length' => 4,
+ ]);
+ $table->addColumn('source_user', 'string', [
+ 'notnull' => true,
+ 'length' => 64,
+ ]);
+ $table->addColumn('target_user', 'string', [
+ 'notnull' => true,
+ 'length' => 64,
+ ]);
+ $table->addColumn('file_id', 'bigint', [
+ 'notnull' => true,
+ 'length' => 20,
+ ]);
+ $table->addColumn('node_name', 'string', [
+ 'notnull' => true,
+ 'length' => 255,
+ ]);
+ $table->setPrimaryKey(['id']);
+
+ return $schema;
+ }
+
+}
diff --git a/apps/files/lib/Notification/Notifier.php b/apps/files/lib/Notification/Notifier.php
new file mode 100644
index 00000000000..92950b8e1b1
--- /dev/null
+++ b/apps/files/lib/Notification/Notifier.php
@@ -0,0 +1,243 @@
+<?php
+declare(strict_types=1);
+/**
+ * @copyright Copyright (c) 2019, Roeland Jago Douma <roeland@famdouma.nl>
+ *
+ * @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\Notification;
+
+use OCP\IURLGenerator;
+use OCP\L10N\IFactory;
+use OCP\Notification\IAction;
+use OCP\Notification\INotification;
+use OCP\Notification\INotifier;
+
+class Notifier implements INotifier {
+
+ /** @var IFactory */
+ protected $l10nFactory;
+
+ /** @var IURLGenerator */
+ protected $urlGenerator;
+
+ /**
+ * @param IFactory $l10nFactory
+ * @param IURLGenerator $urlGenerator
+ */
+ public function __construct(IFactory $l10nFactory, IURLGenerator $urlGenerator) {
+ $this->l10nFactory = $l10nFactory;
+ $this->urlGenerator = $urlGenerator;
+ }
+
+ public function getID(): string {
+ return 'files';
+ }
+
+ public function getName(): string {
+ return $this->l10nFactory->get('files')->t('Files');
+ }
+
+ /**
+ * @param INotification $notification
+ * @param string $languageCode The code of the language that should be used to prepare the notification
+ * @return INotification
+ * @throws \InvalidArgumentException When the notification was not prepared by a notifier
+ */
+ public function prepare(INotification $notification, string $languageCode): INotification {
+ if ($notification->getApp() !== 'files') {
+ throw new \InvalidArgumentException('Unhandled app');
+ }
+
+ if ($notification->getSubject() === 'transferownershipRequest') {
+ return $this->handleTransferownershipRequest($notification, $languageCode);
+ }
+ if ($notification->getSubject() === 'transferOwnershipFailedSource') {
+ return $this->handleTransferOwnershipFailedSource($notification, $languageCode);
+ }
+ if ($notification->getSubject() === 'transferOwnershipFailedTarget') {
+ return $this->handleTransferOwnershipFailedTarget($notification, $languageCode);
+ }
+ if ($notification->getSubject() === 'transferOwnershipDoneSource') {
+ return $this->handleTransferOwnershipDoneSource($notification, $languageCode);
+ }
+ if ($notification->getSubject() === 'transferOwnershipDoneTarget') {
+ return $this->handleTransferOwnershipDoneTarget($notification, $languageCode);
+ }
+
+ throw new \InvalidArgumentException('Unhandled subject');
+ }
+
+ public function handleTransferownershipRequest(INotification $notification, string $languageCode): INotification {
+ $l = $this->l10nFactory->get('files', $languageCode);
+ $id = $notification->getObjectId();
+ $param = $notification->getSubjectParameters();
+
+ $approveAction = $notification->createAction()
+ ->setParsedLabel($l->t('Accept'))
+ ->setPrimary(true)
+ ->setLink(
+ $this->urlGenerator->getAbsoluteURL(
+ $this->urlGenerator->linkTo(
+ '',
+ 'ocs/v2.php/apps/files/api/v1/transferownership/' . $id
+ )
+ ),
+ IAction::TYPE_POST
+ );
+
+ $disapproveAction = $notification->createAction()
+ ->setParsedLabel($l->t('Decline'))
+ ->setPrimary(false)
+ ->setLink(
+ $this->urlGenerator->getAbsoluteURL(
+ $this->urlGenerator->linkTo(
+ '',
+ 'ocs/v2.php/apps/files/api/v1/transferownership/' . $id
+ )
+ ),
+ IAction::TYPE_DELETE
+ );
+
+ $notification->addParsedAction($approveAction)
+ ->addParsedAction($disapproveAction)
+ ->setRichSubject(
+ $l->t('Incomming file transfer from {user}'),
+ [
+ 'user' => [
+ 'type' => 'user',
+ 'id' => $param['sourceUser'],
+ 'name' => $param['sourceUser'],
+ ],
+ ])
+ ->setParsedSubject(str_replace('{user}', $param['sourceUser'], $l->t('Incomming file transfer from {user}')))
+ ->setRichMessage(
+ $l->t('Do you want to accept {path}?'),
+ [
+ 'path' => [
+ 'type' => 'highlight',
+ 'id' => $param['targetUser'] . '::' . $param['nodeName'],
+ 'name' => $param['nodeName'],
+ ]
+ ])
+ ->setParsedMessage(str_replace('{path}', $param['nodeName'], $l->t('Do you want to accept {path}?')));
+
+ return $notification;
+ }
+
+ public function handleTransferOwnershipFailedSource(INotification $notification, string $languageCode): INotification {
+ $l = $this->l10nFactory->get('files', $languageCode);
+ $param = $notification->getSubjectParameters();
+
+ $notification->setRichSubject($l->t('File transfer failed'))
+ ->setParsedSubject(str_replace(['{path}', '{user}'], [$param['nodeName'], $param['targetUser']], $l->t('Your transfer of {path} to {user} failed.')))
+ ->setRichMessage(
+ $l->t('Your transfer of {path} to {user} failed.'),
+ [
+ 'path' => [
+ 'type' => 'highlight',
+ 'id' => $param['targetUser'] . '::' . $param['nodeName'],
+ 'name' => $param['nodeName'],
+ ],
+ 'user' => [
+ 'type' => 'user',
+ 'id' => $param['targetUser'],
+ 'name' => $param['targetUser'],
+ ],
+ ])
+ ->setParsedMessage($l->t('File transfer failed'));
+ return $notification;
+ }
+
+ public function handleTransferOwnershipFailedTarget(INotification $notification, string $languageCode): INotification {
+ $l = $this->l10nFactory->get('files', $languageCode);
+ $param = $notification->getSubjectParameters();
+
+ $notification->setRichSubject($l->t('File transfer failed'))
+ ->setParsedSubject(str_replace(['{path}', '{user}'], [$param['nodeName'], $param['sourceUser']], $l->t('The transfer of {path} from {user} failed.')))
+ ->setRichMessage(
+ $l->t('The transfer of {path} from {user} failed.'),
+ [
+ 'path' => [
+ 'type' => 'highlight',
+ 'id' => $param['sourceUser'] . '::' . $param['nodeName'],
+ 'name' => $param['nodeName'],
+ ],
+ 'user' => [
+ 'type' => 'user',
+ 'id' => $param['sourceUser'],
+ 'name' => $param['sourceUser'],
+ ],
+ ])
+ ->setParsedMessage($l->t('File transfer failed'));
+
+ return $notification;
+ }
+
+ public function handleTransferOwnershipDoneSource(INotification $notification, string $languageCode): INotification {
+ $l = $this->l10nFactory->get('files', $languageCode);
+ $param = $notification->getSubjectParameters();
+
+ $notification->setRichSubject($l->t('File transfer done'))
+ ->setParsedSubject(str_replace(['{path}', '{user}'], [$param['nodeName'], $param['targetUser']], $l->t('Your transfer of {path} to {user} has completed.')))
+ ->setRichMessage(
+ $l->t('Your transfer of {path} to {user} has completed.'),
+ [
+ 'path' => [
+ 'type' => 'highlight',
+ 'id' => $param['targetUser'] . '::' . $param['nodeName'],
+ 'name' => $param['nodeName'],
+ ],
+ 'user' => [
+ 'type' => 'user',
+ 'id' => $param['targetUser'],
+ 'name' => $param['targetUser'],
+ ],
+ ])
+ ->setParsedMessage($l->t('File transfer done'));
+
+ return $notification;
+ }
+
+ public function handleTransferOwnershipDoneTarget(INotification $notification, string $languageCode): INotification {
+ $l = $this->l10nFactory->get('files', $languageCode);
+ $param = $notification->getSubjectParameters();
+
+ $notification->setRichSubject($l->t('File transfer done'))
+ ->setParsedSubject(str_replace(['{path}', '{user}'], [$param['nodeName'], $param['sourceUser']], $l->t('The transfer of {path} from {user} has completed.')))
+ ->setRichMessage(
+ $l->t('The transfer of {path} from {user} has completed.'),
+ [
+ 'path' => [
+ 'type' => 'highlight',
+ 'id' => $param['sourceUser'] . '::' . $param['nodeName'],
+ 'name' => $param['nodeName'],
+ ],
+ 'user' => [
+ 'type' => 'user',
+ 'id' => $param['sourceUser'],
+ 'name' => $param['sourceUser'],
+ ],
+ ])
+ ->setParsedMessage($l->t('File transfer done'));
+
+ return $notification;
+ }
+}
diff --git a/apps/files/lib/Settings/PersonalSettings.php b/apps/files/lib/Settings/PersonalSettings.php
new file mode 100644
index 00000000000..3348d394dc5
--- /dev/null
+++ b/apps/files/lib/Settings/PersonalSettings.php
@@ -0,0 +1,46 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * @copyright 2019 Christoph Wurst <christoph@winzerhof-wurst.at>
+ *
+ * @author 2019 Christoph Wurst <christoph@winzerhof-wurst.at>
+ *
+ * @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\Settings;
+
+use OCA\Files\AppInfo\Application;
+use OCP\AppFramework\Http\TemplateResponse;
+use OCP\Settings\ISettings;
+
+class PersonalSettings implements ISettings {
+
+ public function getForm(): TemplateResponse {
+ return new TemplateResponse(Application::APP_ID, 'settings-personal');
+ }
+
+ public function getSection(): string {
+ return 'sharing';
+ }
+
+ public function getPriority(): int {
+ return 90;
+ }
+
+}