diff options
author | Björn Schießle <bjoern@schiessle.org> | 2016-07-18 16:10:21 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-07-18 16:10:21 +0200 |
commit | f7d26e4aa523d684be6feda2b7a091b2c1548965 (patch) | |
tree | d65349059417395284b298f559399f54d5c2213f /apps/files_sharing | |
parent | b23d3c64187e2ecc3bce8ddd8bdba103568ac3e7 (diff) | |
parent | 773250be24599d93a40851d17991bab7d0861d53 (diff) | |
download | nextcloud-server-f7d26e4aa523d684be6feda2b7a091b2c1548965.tar.gz nextcloud-server-f7d26e4aa523d684be6feda2b7a091b2c1548965.zip |
Merge pull request #414 from nextcloud/files_sharing_event_dispatcher
Files sharing event dispatcher
Diffstat (limited to 'apps/files_sharing')
-rw-r--r-- | apps/files_sharing/lib/AppInfo/Application.php | 3 | ||||
-rw-r--r-- | apps/files_sharing/lib/Controllers/ShareController.php | 57 | ||||
-rw-r--r-- | apps/files_sharing/templates/public.php | 20 | ||||
-rw-r--r-- | apps/files_sharing/tests/Controllers/ShareControllerTest.php | 11 |
4 files changed, 55 insertions, 36 deletions
diff --git a/apps/files_sharing/lib/AppInfo/Application.php b/apps/files_sharing/lib/AppInfo/Application.php index 5ed8d886e2e..b91b0f3ef6e 100644 --- a/apps/files_sharing/lib/AppInfo/Application.php +++ b/apps/files_sharing/lib/AppInfo/Application.php @@ -59,7 +59,8 @@ class Application extends App { $server->getSession(), $server->getPreviewManager(), $server->getRootFolder(), - $federatedSharingApp->getFederatedShareProvider() + $federatedSharingApp->getFederatedShareProvider(), + $server->getEventDispatcher() ); }); $container->registerService('ExternalSharesController', function (SimpleContainer $c) { diff --git a/apps/files_sharing/lib/Controllers/ShareController.php b/apps/files_sharing/lib/Controllers/ShareController.php index 11359e5f2f2..7a955f6f960 100644 --- a/apps/files_sharing/lib/Controllers/ShareController.php +++ b/apps/files_sharing/lib/Controllers/ShareController.php @@ -31,11 +31,9 @@ namespace OCA\Files_Sharing\Controllers; -use OC; use OC_Files; use OC_Util; use OCA\FederatedFileSharing\FederatedShareProvider; -use OCP; use OCP\Template; use OCP\Share; use OCP\AppFramework\Controller; @@ -54,6 +52,7 @@ use OCA\Files_Sharing\Activity; use \OCP\Files\NotFoundException; use OCP\Files\IRootFolder; use OCP\Share\Exceptions\ShareNotFound; +use Symfony\Component\EventDispatcher\EventDispatcherInterface; /** * Class ShareController @@ -70,9 +69,9 @@ class ShareController extends Controller { protected $userManager; /** @var ILogger */ protected $logger; - /** @var OCP\Activity\IManager */ + /** @var \OCP\Activity\IManager */ protected $activityManager; - /** @var OCP\Share\IManager */ + /** @var \OCP\Share\IManager */ protected $shareManager; /** @var ISession */ protected $session; @@ -82,6 +81,8 @@ class ShareController extends Controller { protected $rootFolder; /** @var FederatedShareProvider */ protected $federatedShareProvider; + /** @var EventDispatcherInterface */ + protected $eventDispatcher; /** * @param string $appName @@ -90,12 +91,13 @@ class ShareController extends Controller { * @param IURLGenerator $urlGenerator * @param IUserManager $userManager * @param ILogger $logger - * @param OCP\Activity\IManager $activityManager + * @param \OCP\Activity\IManager $activityManager * @param \OCP\Share\IManager $shareManager * @param ISession $session * @param IPreview $previewManager * @param IRootFolder $rootFolder * @param FederatedShareProvider $federatedShareProvider + * @param EventDispatcherInterface $eventDispatcher */ public function __construct($appName, IRequest $request, @@ -108,7 +110,8 @@ class ShareController extends Controller { ISession $session, IPreview $previewManager, IRootFolder $rootFolder, - FederatedShareProvider $federatedShareProvider) { + FederatedShareProvider $federatedShareProvider, + EventDispatcherInterface $eventDispatcher) { parent::__construct($appName, $request); $this->config = $config; @@ -121,6 +124,7 @@ class ShareController extends Controller { $this->previewManager = $previewManager; $this->rootFolder = $rootFolder; $this->federatedShareProvider = $federatedShareProvider; + $this->eventDispatcher = $eventDispatcher; } /** @@ -147,7 +151,7 @@ class ShareController extends Controller { * Authenticates against password-protected shares * @param string $token * @param string $password - * @return RedirectResponse|TemplateResponse + * @return RedirectResponse|TemplateResponse|NotFoundResponse */ public function authenticate($token, $password = '') { @@ -203,8 +207,8 @@ class ShareController extends Controller { * otherwise token * @param int $errorCode * @param string $errorMessage - * @throws OC\HintException - * @throws OC\ServerNotAvailableException + * @throws \OC\HintException + * @throws \OC\ServerNotAvailableException */ protected function emitAccessShareHook($share, $errorCode = 200, $errorMessage = '') { $itemType = $itemSource = $uidOwner = ''; @@ -250,7 +254,7 @@ class ShareController extends Controller { * * @param string $token * @param string $path - * @return TemplateResponse|RedirectResponse + * @return TemplateResponse|RedirectResponse|NotFoundResponse * @throws NotFoundException * @throws \Exception */ @@ -337,7 +341,7 @@ class ShareController extends Controller { $folder->assign('hideFileList', $hideFileList); $folder->assign('publicUploadEnabled', 'no'); $folder->assign('uploadMaxFilesize', $maxUploadFilesize); - $folder->assign('uploadMaxHumanFilesize', OCP\Util::humanFileSize($maxUploadFilesize)); + $folder->assign('uploadMaxHumanFilesize', \OCP\Util::humanFileSize($maxUploadFilesize)); $folder->assign('freeSpace', $freeSpace); $folder->assign('uploadLimit', $uploadLimit); // PHP upload limit $folder->assign('usedSpacePercent', 0); @@ -353,7 +357,32 @@ class ShareController extends Controller { $shareTmpl['previewMaxX'] = $this->config->getSystemValue('preview_max_x', 1024); $shareTmpl['previewMaxY'] = $this->config->getSystemValue('preview_max_y', 1024); - $csp = new OCP\AppFramework\Http\ContentSecurityPolicy(); + // Load files we need + \OCP\Util::addScript('files', 'file-upload'); + \OCP\Util::addStyle('files_sharing', 'public'); + \OCP\Util::addStyle('files_sharing', 'mobile'); + \OCP\Util::addScript('files_sharing', 'public'); + \OCP\Util::addScript('files', 'fileactions'); + \OCP\Util::addScript('files', 'fileactionsmenu'); + \OCP\Util::addScript('files', 'jquery.fileupload'); + \OCP\Util::addScript('files_sharing', 'files_drop'); + + if (isset($shareTmpl['folder'])) { + // JS required for folders + \OCP\Util::addStyle('files', 'files'); + \OCP\Util::addStyle('files', 'upload'); + \OCP\Util::addScript('files', 'filesummary'); + \OCP\Util::addScript('files', 'breadcrumb'); + \OCP\Util::addScript('files', 'fileinfomodel'); + \OCP\Util::addScript('files', 'newfilemenu'); + \OCP\Util::addScript('files', 'files'); + \OCP\Util::addScript('files', 'filelist'); + \OCP\Util::addScript('files', 'keyboardshortcuts'); + } + + $this->eventDispatcher->dispatch('OCA\Files_Sharing::loadAdditionalScripts'); + + $csp = new \OCP\AppFramework\Http\ContentSecurityPolicy(); $csp->addAllowedFrameDomain('\'self\''); $response = new TemplateResponse($this->appName, 'public', $shareTmpl, 'base'); $response->setContentSecurityPolicy($csp); @@ -371,7 +400,7 @@ class ShareController extends Controller { * @param string $files * @param string $path * @param string $downloadStartSecret - * @return void|OCP\AppFramework\Http\Response + * @return void|\OCP\AppFramework\Http\Response * @throws NotFoundException */ public function downloadShare($token, $files = null, $path = '', $downloadStartSecret = '') { @@ -380,7 +409,7 @@ class ShareController extends Controller { $share = $this->shareManager->getShareByToken($token); if(!($share->getPermissions() & \OCP\Constants::PERMISSION_READ)) { - return new OCP\AppFramework\Http\DataResponse('Share is read-only'); + return new \OCP\AppFramework\Http\DataResponse('Share is read-only'); } // Share is password protected - check whether the user is permitted to access the share diff --git a/apps/files_sharing/templates/public.php b/apps/files_sharing/templates/public.php index 8a906f02a7e..f587b5109d4 100644 --- a/apps/files_sharing/templates/public.php +++ b/apps/files_sharing/templates/public.php @@ -1,26 +1,6 @@ <?php /** @var $l OC_L10N */ /** @var $_ array */ - -OCP\Util::addScript('files', 'file-upload'); -OCP\Util::addStyle('files_sharing', 'public'); -OCP\Util::addStyle('files_sharing', 'mobile'); -OCP\Util::addScript('files_sharing', 'public'); -OCP\Util::addScript('files', 'fileactions'); -OCP\Util::addScript('files', 'fileactionsmenu'); -OCP\Util::addScript('files', 'jquery.fileupload'); -OCP\Util::addScript('files_sharing', 'files_drop'); - -// JS required for folders -OCP\Util::addStyle('files', 'files'); -OCP\Util::addStyle('files', 'upload'); -OCP\Util::addScript('files', 'filesummary'); -OCP\Util::addScript('files', 'breadcrumb'); -OCP\Util::addScript('files', 'fileinfomodel'); -OCP\Util::addScript('files', 'newfilemenu'); -OCP\Util::addScript('files', 'files'); -OCP\Util::addScript('files', 'filelist'); -OCP\Util::addscript('files', 'keyboardshortcuts'); ?> <?php if ($_['previewSupported']): /* This enables preview images for links (e.g. on Facebook, Google+, ...)*/?> diff --git a/apps/files_sharing/tests/Controllers/ShareControllerTest.php b/apps/files_sharing/tests/Controllers/ShareControllerTest.php index 343d5c58d69..5b856198742 100644 --- a/apps/files_sharing/tests/Controllers/ShareControllerTest.php +++ b/apps/files_sharing/tests/Controllers/ShareControllerTest.php @@ -41,6 +41,7 @@ use OCP\ISession; use OCP\IUserManager; use OCP\Security\ISecureRandom; use OCP\IURLGenerator; +use Symfony\Component\EventDispatcher\EventDispatcherInterface; /** * @group DB @@ -72,6 +73,8 @@ class ShareControllerTest extends \Test\TestCase { private $userManager; /** @var FederatedShareProvider | \PHPUnit_Framework_MockObject_MockObject */ private $federatedShareProvider; + /** @var EventDispatcherInterface | \PHPUnit_Framework_MockObject_MockObject */ + private $eventDispatcher; protected function setUp() { parent::setUp(); @@ -89,6 +92,7 @@ class ShareControllerTest extends \Test\TestCase { ->method('isOutgoingServer2serverShareEnabled')->willReturn(true); $this->federatedShareProvider->expects($this->any()) ->method('isIncomingServer2serverShareEnabled')->willReturn(true); + $this->eventDispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcherInterface')->getMock(); $this->shareController = new \OCA\Files_Sharing\Controllers\ShareController( $this->appName, @@ -102,7 +106,8 @@ class ShareControllerTest extends \Test\TestCase { $this->session, $this->previewManager, $this->getMockBuilder('\OCP\Files\IRootFolder')->getMock(), - $this->federatedShareProvider + $this->federatedShareProvider, + $this->eventDispatcher ); @@ -353,6 +358,10 @@ class ShareControllerTest extends \Test\TestCase { $this->userManager->method('get')->with('ownerUID')->willReturn($owner); + $this->eventDispatcher->expects($this->once()) + ->method('dispatch') + ->with('OCA\Files_Sharing::loadAdditionalScripts'); + $response = $this->shareController->showShare('token'); $sharedTmplParams = array( 'displayName' => 'ownerDisplay', |