Dismiss transferownership notification cancels transfer

Fixes #18271

Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
This commit is contained in:
Roeland Jago Douma 2019-12-11 12:58:44 +01:00
parent 97deaf85b9
commit 3f21b7b70a
No known key found for this signature in database
GPG Key ID: F941078878347C0C
1 changed files with 49 additions and 2 deletions

View File

@ -27,27 +27,47 @@ declare(strict_types=1);
namespace OCA\Files\Notification;
use OCA\Files\Db\TransferOwnershipMapper;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\IURLGenerator;
use OCP\L10N\IFactory;
use OCP\Notification\IAction;
use OCP\Notification\IDismissableNotifier;
use OCP\Notification\IManager;
use OCP\Notification\INotification;
use OCP\Notification\INotifier;
class Notifier implements INotifier {
class Notifier implements INotifier, IDismissableNotifier {
/** @var IFactory */
protected $l10nFactory;
/** @var IURLGenerator */
protected $urlGenerator;
/** @var TransferOwnershipMapper */
private $mapper;
/** @var IManager */
private $notificationManager;
/** @var ITimeFactory */
private $timeFactory;
/**
* @param IFactory $l10nFactory
* @param IURLGenerator $urlGenerator
*/
public function __construct(IFactory $l10nFactory, IURLGenerator $urlGenerator) {
public function __construct(IFactory $l10nFactory,
IURLGenerator $urlGenerator,
TransferOwnershipMapper $mapper,
IManager $notificationManager,
ITimeFactory $timeFactory) {
$this->l10nFactory = $l10nFactory;
$this->urlGenerator = $urlGenerator;
$this->mapper = $mapper;
$this->notificationManager = $notificationManager;
$this->timeFactory = $timeFactory;
}
public function getID(): string {
@ -247,4 +267,31 @@ class Notifier implements INotifier {
return $notification;
}
public function dismissNotification(INotification $notification): void {
if ($notification->getApp() !== 'files') {
throw new \InvalidArgumentException('Unhandled app');
}
// TODO: This should all be moved to a service that also the transferownershipContoller uses.
try {
$transferOwnership = $this->mapper->getById((int)$notification->getObjectId());
} catch (DoesNotExistException $e) {
return;
}
$notification = $this->notificationManager->createNotification();
$notification->setUser($transferOwnership->getSourceUser())
->setApp('files')
->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);
}
}