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
5 changes: 3 additions & 2 deletions apps/files_sharing/lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,13 @@ public function __construct(array $urlParams = []) {
$server->getRootFolder()
);
});
$container->registerService('ExternalSharesController', function (SimpleContainer $c) {
$container->registerService('ExternalSharesController', function (SimpleContainer $c) use ($server) {
return new ExternalSharesController(
$c->query('AppName'),
$c->query('Request'),
$c->query('ExternalManager'),
$c->query('HttpClientService')
$c->query('HttpClientService'),
$server->getEventDispatcher()
);
});

Expand Down
33 changes: 32 additions & 1 deletion apps/files_sharing/lib/Controllers/ExternalSharesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
use OCP\AppFramework\Http\JSONResponse;
use OCP\Http\Client\IClientService;
use OCP\AppFramework\Http\DataResponse;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\GenericEvent;

/**
* Class ExternalSharesController
Expand All @@ -42,20 +44,29 @@ class ExternalSharesController extends Controller {
private $externalManager;
/** @var IClientService */
private $clientService;
/**
* @var \Symfony\Component\EventDispatcher\EventDispatcherInterface
*/
private $dispatcher;

/**
* ExternalSharesController constructor.
*
* @param string $appName
* @param IRequest $request
* @param \OCA\Files_Sharing\External\Manager $externalManager
* @param IClientService $clientService
* @param EventDispatcherInterface $eventDispatcher
*/
public function __construct($appName,
IRequest $request,
\OCA\Files_Sharing\External\Manager $externalManager,
IClientService $clientService) {
IClientService $clientService,
EventDispatcherInterface $eventDispatcher) {
parent::__construct($appName, $request);
$this->externalManager = $externalManager;
$this->clientService = $clientService;
$this->dispatcher = $eventDispatcher;
}

/**
Expand All @@ -76,6 +87,16 @@ public function index() {
* @return JSONResponse
*/
public function create($id) {
$shareInfo = $this->externalManager->getShare($id);
$event = new GenericEvent(null,
[
'shareAcceptedFrom' => $shareInfo['owner'],
'sharedAcceptedBy' => $shareInfo['user'],
'sharedItem' => $shareInfo['name'],
'remoteUrl' => $shareInfo['remote']
]
);
$this->dispatcher->dispatch('remoteshare.accepted', $event);
$this->externalManager->acceptShare($id);
return new JSONResponse();
}
Expand All @@ -88,6 +109,16 @@ public function create($id) {
* @return JSONResponse
*/
public function destroy($id) {
$shareInfo = $this->externalManager->getShare($id);
$event = new GenericEvent(null,
[
'shareAcceptedFrom' => $shareInfo['owner'],
'sharedAcceptedBy' => $shareInfo['user'],
'sharedItem' => $shareInfo['name'],
'remoteUrl' => $shareInfo['remote']
]
);
$this->dispatcher->dispatch('remoteshare.declined', $event);
$this->externalManager->declineShare($id);
return new JSONResponse();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@
use OCP\AppFramework\Http\JSONResponse;
use OCP\Http\Client\IClientService;
use OCP\IRequest;
use Symfony\Component\EventDispatcher\GenericEvent;

/**
* Class ExternalShareControllerTest
* @group DB
*
* @package OCA\Files_Sharing\Controllers
*/
Expand Down Expand Up @@ -60,7 +62,8 @@ public function getExternalShareController() {
'files_sharing',
$this->request,
$this->externalManager,
$this->clientService
$this->clientService,
\OC::$server->getEventDispatcher()
);
}

Expand All @@ -79,7 +82,15 @@ public function testCreate() {
->method('acceptShare')
->with(4);

$called = array();
\OC::$server->getEventDispatcher()->addListener('remoteshare.accepted', function ($event) use (&$called) {
$called[] = 'remoteshare.accepted';
array_push($called, $event);
});
$this->assertEquals(new JSONResponse(), $this->getExternalShareController()->create(4));

$this->assertSame('remoteshare.accepted', $called[0]);
$this->assertTrue($called[1] instanceof GenericEvent);
}

public function testDestroy() {
Expand All @@ -88,7 +99,16 @@ public function testDestroy() {
->method('declineShare')
->with(4);

$called = array();
\OC::$server->getEventDispatcher()->addListener('remoteshare.declined', function ($event) use (&$called) {
$called[] = 'remoteshare.declined';
array_push($called, $event);
});

$this->assertEquals(new JSONResponse(), $this->getExternalShareController()->destroy(4));

$this->assertSame('remoteshare.declined', $called[0]);
$this->assertTrue($called[1] instanceof GenericEvent);
}

public function testRemoteWithValidHttps() {
Expand Down