Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions apps/federatedfilesharing/lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

namespace OCA\FederatedFileSharing\AppInfo;

use GuzzleHttp\Exception\ServerException;
use OCA\FederatedFileSharing\AddressHandler;
use OCA\FederatedFileSharing\Command\PollIncomingShares;
use OCA\FederatedFileSharing\Controller\OcmController;
Expand All @@ -34,6 +35,7 @@
use OCA\FederatedFileSharing\Ocm\Permissions;
use OCA\FederatedFileSharing\TokenHandler;
use OCP\AppFramework\App;
use OCP\AppFramework\Http;
use OCP\Share\Events\AcceptShare;
use OCP\Share\Events\DeclineShare;

Expand Down Expand Up @@ -259,11 +261,19 @@ function (AcceptShare $event) use ($container) {
function (DeclineShare $event) use ($container) {
/** @var Notifications $notifications */
$notifications = $container->query('Notifications');
$notifications->sendDeclineShare(
$event->getRemote(),
$event->getRemoteId(),
$event->getShareToken()
);
try {
$notifications->sendDeclineShare(
$event->getRemote(),
$event->getRemoteId(),
$event->getShareToken()
);
} catch (ServerException $e) {
// ownCloud lower than 10.2 responded with Internal Server Error
// on declining non-existing share. It can't be caught outside the closure
if ($e->getCode() !== Http::STATUS_INTERNAL_SERVER_ERROR) {
throw $e;
}
}
}
);
}
Expand Down
16 changes: 16 additions & 0 deletions apps/federatedfilesharing/tests/NotificationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
use OCP\Http\Client\IResponse;
use OCP\IConfig;
use OCA\FederatedFileSharing\BackgroundJob\RetryJob;
use OCP\Share\Events\DeclineShare;

class NotificationsTest extends \Test\TestCase {

Expand Down Expand Up @@ -200,4 +201,19 @@ function ($options) {
]
);
}

public function testDeclineEvent() {
$dispatcher = \OC::$server->getEventDispatcher();
$event = $dispatcher->dispatch(
DeclineShare::class,
new DeclineShare(
[
'remote_id' => '4354353',
'remote' => 'http://localhost',
'share_token' => 'ohno'
]
)
);
$this->assertInstanceOf(DeclineShare::class, $event);
}
}