Merge pull request #5823 from nextcloud/improve-error-handling

Improve error handling for accepting federated shares
This commit is contained in:
Morris Jobke 2017-07-21 22:54:14 +02:00 committed by GitHub
commit 50fc5a1e25
3 changed files with 22 additions and 13 deletions

View File

@ -194,12 +194,12 @@ class RequestHandlerController extends OCSController {
$declineAction = $notification->createAction(); $declineAction = $notification->createAction();
$declineAction->setLabel('decline') $declineAction->setLabel('decline')
->setLink($urlGenerator->getAbsoluteURL($urlGenerator->linkTo('', 'ocs/v1.php/apps/files_sharing/api/v1/remote_shares/pending/' . $shareId)), 'DELETE'); ->setLink($urlGenerator->getAbsoluteURL($urlGenerator->linkTo('', 'ocs/v2.php/apps/files_sharing/api/v1/remote_shares/pending/' . $shareId)), 'DELETE');
$notification->addAction($declineAction); $notification->addAction($declineAction);
$acceptAction = $notification->createAction(); $acceptAction = $notification->createAction();
$acceptAction->setLabel('accept') $acceptAction->setLabel('accept')
->setLink($urlGenerator->getAbsoluteURL($urlGenerator->linkTo('', 'ocs/v1.php/apps/files_sharing/api/v1/remote_shares/pending/' . $shareId)), 'POST'); ->setLink($urlGenerator->getAbsoluteURL($urlGenerator->linkTo('', 'ocs/v2.php/apps/files_sharing/api/v1/remote_shares/pending/' . $shareId)), 'POST');
$notification->addAction($acceptAction); $notification->addAction($acceptAction);
$notificationManager->notify($notification); $notificationManager->notify($notification);

View File

@ -29,6 +29,7 @@ use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\OCS\OCSForbiddenException; use OCP\AppFramework\OCS\OCSForbiddenException;
use OCP\AppFramework\OCS\OCSNotFoundException; use OCP\AppFramework\OCS\OCSNotFoundException;
use OCP\AppFramework\OCSController; use OCP\AppFramework\OCSController;
use OCP\ILogger;
use OCP\IRequest; use OCP\IRequest;
class RemoteController extends OCSController { class RemoteController extends OCSController {
@ -36,6 +37,9 @@ class RemoteController extends OCSController {
/** @var Manager */ /** @var Manager */
private $externalManager; private $externalManager;
/** @var ILogger */
private $logger;
/** /**
* @NoAdminRequired * @NoAdminRequired
* *
@ -47,10 +51,12 @@ class RemoteController extends OCSController {
*/ */
public function __construct($appName, public function __construct($appName,
IRequest $request, IRequest $request,
Manager $externalManager) { Manager $externalManager,
ILogger $logger) {
parent::__construct($appName, $request); parent::__construct($appName, $request);
$this->externalManager = $externalManager; $this->externalManager = $externalManager;
$this->logger = $logger;
} }
/** /**
@ -78,8 +84,8 @@ class RemoteController extends OCSController {
return new DataResponse(); return new DataResponse();
} }
// Make sure the user has no notification for something that does not exist anymore. $this->logger->error('Could not accept federated share with id: ' . $id,
$this->externalManager->processNotification($id); ['app' => 'files_sharing']);
throw new OCSNotFoundException('wrong share ID, share doesn\'t exist.'); throw new OCSNotFoundException('wrong share ID, share doesn\'t exist.');
} }

View File

@ -197,6 +197,7 @@ class Manager {
public function acceptShare($id) { public function acceptShare($id) {
$share = $this->getShare($id); $share = $this->getShare($id);
$result = false;
if ($share) { if ($share) {
\OC_Util::setupFS($this->uid); \OC_Util::setupFS($this->uid);
@ -211,16 +212,18 @@ class Manager {
`mountpoint` = ?, `mountpoint` = ?,
`mountpoint_hash` = ? `mountpoint_hash` = ?
WHERE `id` = ? AND `user` = ?'); WHERE `id` = ? AND `user` = ?');
$acceptShare->execute(array(1, $mountPoint, $hash, $id, $this->uid)); $updated = $acceptShare->execute(array(1, $mountPoint, $hash, $id, $this->uid));
if ($updated === true) {
$this->sendFeedbackToRemote($share['remote'], $share['share_token'], $share['remote_id'], 'accept'); $this->sendFeedbackToRemote($share['remote'], $share['share_token'], $share['remote_id'], 'accept');
\OC_Hook::emit('OCP\Share', 'federated_share_added', ['server' => $share['remote']]); \OC_Hook::emit('OCP\Share', 'federated_share_added', ['server' => $share['remote']]);
$result = true;
$this->processNotification($id); }
return true;
} }
return false; // Make sure the user has no notification for something that does not exist anymore.
$this->processNotification($id);
return $result;
} }
/** /**