summaryrefslogtreecommitdiffstats
path: root/apps/files_sharing
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files_sharing')
-rw-r--r--apps/files_sharing/composer/composer/autoload_classmap.php2
-rw-r--r--apps/files_sharing/composer/composer/autoload_static.php2
-rw-r--r--apps/files_sharing/css/public.scss8
-rw-r--r--apps/files_sharing/lib/Controller/ShareController.php16
-rw-r--r--apps/files_sharing/lib/Template/ExternalShareMenuAction.php68
-rw-r--r--apps/files_sharing/lib/Template/LinkMenuAction.php54
-rw-r--r--apps/files_sharing/templates/public.php129
-rw-r--r--apps/files_sharing/tests/Controller/ShareControllerTest.php34
8 files changed, 208 insertions, 105 deletions
diff --git a/apps/files_sharing/composer/composer/autoload_classmap.php b/apps/files_sharing/composer/composer/autoload_classmap.php
index a68db3421b6..0388c7990ec 100644
--- a/apps/files_sharing/composer/composer/autoload_classmap.php
+++ b/apps/files_sharing/composer/composer/autoload_classmap.php
@@ -53,5 +53,7 @@ return array(
'OCA\\Files_Sharing\\ShareBackend\\Folder' => $baseDir . '/../lib/ShareBackend/Folder.php',
'OCA\\Files_Sharing\\SharedMount' => $baseDir . '/../lib/SharedMount.php',
'OCA\\Files_Sharing\\SharedStorage' => $baseDir . '/../lib/SharedStorage.php',
+ 'OCA\\Files_Sharing\\Template\\ExternalShareMenuAction' => $baseDir . '/../lib/Template/ExternalShareMenuAction.php',
+ 'OCA\\Files_Sharing\\Template\\LinkMenuAction' => $baseDir . '/../lib/Template/LinkMenuAction.php',
'OCA\\Files_Sharing\\Updater' => $baseDir . '/../lib/Updater.php',
);
diff --git a/apps/files_sharing/composer/composer/autoload_static.php b/apps/files_sharing/composer/composer/autoload_static.php
index 328d6aca01d..dd75dbaa18a 100644
--- a/apps/files_sharing/composer/composer/autoload_static.php
+++ b/apps/files_sharing/composer/composer/autoload_static.php
@@ -68,6 +68,8 @@ class ComposerStaticInitFiles_Sharing
'OCA\\Files_Sharing\\ShareBackend\\Folder' => __DIR__ . '/..' . '/../lib/ShareBackend/Folder.php',
'OCA\\Files_Sharing\\SharedMount' => __DIR__ . '/..' . '/../lib/SharedMount.php',
'OCA\\Files_Sharing\\SharedStorage' => __DIR__ . '/..' . '/../lib/SharedStorage.php',
+ 'OCA\\Files_Sharing\\Template\\ExternalShareMenuAction' => __DIR__ . '/..' . '/../lib/Template/ExternalShareMenuAction.php',
+ 'OCA\\Files_Sharing\\Template\\LinkMenuAction' => __DIR__ . '/..' . '/../lib/Template/LinkMenuAction.php',
'OCA\\Files_Sharing\\Updater' => __DIR__ . '/..' . '/../lib/Updater.php',
);
diff --git a/apps/files_sharing/css/public.scss b/apps/files_sharing/css/public.scss
index 5edc3f7eb90..1e9dec87fad 100644
--- a/apps/files_sharing/css/public.scss
+++ b/apps/files_sharing/css/public.scss
@@ -3,14 +3,6 @@
min-height: calc(100vh - 160px);
}
-#header .menutoggle {
- padding: 14px;
- padding-right: 40px;
- background-position: right 15px center;
- color: $color-primary-text;
- cursor: pointer;
-}
-
/* force layout to make sure the content element's height matches its contents' height */
.ie #content {
display: inline-block;
diff --git a/apps/files_sharing/lib/Controller/ShareController.php b/apps/files_sharing/lib/Controller/ShareController.php
index 795d069c1b8..1f8864fc5f3 100644
--- a/apps/files_sharing/lib/Controller/ShareController.php
+++ b/apps/files_sharing/lib/Controller/ShareController.php
@@ -38,6 +38,10 @@ namespace OCA\Files_Sharing\Controller;
use OC_Files;
use OC_Util;
use OCA\FederatedFileSharing\FederatedShareProvider;
+use OCA\Files_Sharing\Template\ExternalShareMenuAction;
+use OCA\Files_Sharing\Template\LinkMenuAction;
+use OCP\AppFramework\Http\Template\SimpleMenuAction;
+use OCP\AppFramework\Http\Template\PublicTemplateResponse;
use OCP\Defaults;
use OCP\IL10N;
use OCP\Template;
@@ -435,7 +439,17 @@ class ShareController extends Controller {
$csp = new \OCP\AppFramework\Http\ContentSecurityPolicy();
$csp->addAllowedFrameDomain('\'self\'');
- $response = new TemplateResponse($this->appName, 'public', $shareTmpl, 'base');
+
+ $response = new PublicTemplateResponse($this->appName, 'public', $shareTmpl);
+ $response->setHeaderTitle($shareTmpl['filename']);
+ $response->setHeaderDetails($this->l10n->t('shared by %s', [$shareTmpl['displayName']]));
+ $response->setHeaderActions([
+ new SimpleMenuAction('download', $this->l10n->t('Download'), 'icon-download-white', $shareTmpl['downloadURL'], 0),
+ new SimpleMenuAction('download', $this->l10n->t('Download'), 'icon-download', $shareTmpl['downloadURL'], 10, $shareTmpl['fileSize']),
+ new LinkMenuAction($this->l10n->t('Direct link'), 'icon-public', $shareTmpl['previewURL']),
+ new ExternalShareMenuAction($this->l10n->t('Add to your Nextcloud'), 'icon-external', $shareTmpl['owner'], $shareTmpl['displayName'], $shareTmpl['filename']),
+ ]);
+
$response->setContentSecurityPolicy($csp);
$this->emitAccessShareHook($share);
diff --git a/apps/files_sharing/lib/Template/ExternalShareMenuAction.php b/apps/files_sharing/lib/Template/ExternalShareMenuAction.php
new file mode 100644
index 00000000000..f548a3bc6f1
--- /dev/null
+++ b/apps/files_sharing/lib/Template/ExternalShareMenuAction.php
@@ -0,0 +1,68 @@
+<?php
+/**
+ * @copyright Copyright (c) 2018 Julius Härtl <jus@bitgrid.net>
+ *
+ * @author Julius Härtl <jus@bitgrid.net>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCA\Files_Sharing\Template;
+
+use OCP\AppFramework\Http\Template\SimpleMenuAction;
+use OCP\Util;
+
+class ExternalShareMenuAction extends SimpleMenuAction {
+
+ /** @var string */
+ private $owner;
+
+ /** @var string */
+ private $displayname;
+
+ /** @var string */
+ private $shareName;
+
+ /**
+ * ExternalShareMenuAction constructor.
+ *
+ * @param string $label
+ * @param string $icon
+ * @param string $owner
+ * @param string $displayname
+ * @param string $shareName
+ */
+ public function __construct(string $label, string $icon, string $owner, string $displayname, string $shareName) {
+ parent::__construct('save', $label, $icon);
+ $this->owner = $owner;
+ $this->displayname = $displayname;
+ $this->shareName = $shareName;
+ }
+
+ public function render(): string {
+ return '<li>' .
+ '<a id="save" data-protected="false" data-owner-display-name="' . Util::sanitizeHTML($this->displayname) . '" data-owner="' . Util::sanitizeHTML($this->owner) . '" data-name="' . Util::sanitizeHTML($this->shareName) . '">' .
+ '<span class="icon ' . Util::sanitizeHTML($this->getIcon()) . '"></span>' .
+ '<span id="save-button">' . Util::sanitizeHTML($this->getLabel()) . '</span>' .
+ '<form class="save-form hidden" action="#">' .
+ '<input type="text" id="remote_address" placeholder="user@yourNextcloud.org">' .
+ '<button id="save-button-confirm" class="icon-confirm svg" disabled=""></button>' .
+ '</form>' .
+ '</a>' .
+ '</li>';
+ }
+} \ No newline at end of file
diff --git a/apps/files_sharing/lib/Template/LinkMenuAction.php b/apps/files_sharing/lib/Template/LinkMenuAction.php
new file mode 100644
index 00000000000..2fdf83e7026
--- /dev/null
+++ b/apps/files_sharing/lib/Template/LinkMenuAction.php
@@ -0,0 +1,54 @@
+<?php
+/**
+ * @copyright Copyright (c) 2018 Julius Härtl <jus@bitgrid.net>
+ *
+ * @author Julius Härtl <jus@bitgrid.net>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCA\Files_Sharing\Template;
+
+use OCP\AppFramework\Http\Template\SimpleMenuAction;
+use OCP\Util;
+
+class LinkMenuAction extends SimpleMenuAction {
+
+ /**
+ * LinkMenuAction constructor.
+ *
+ * @param string $label
+ * @param string $icon
+ * @param string $link
+ */
+ public function __construct(string $label, string $icon, string $link) {
+ parent::__construct('directLink-container', $label, $icon, $link);
+ }
+
+ /**
+ * @return string
+ */
+ public function render(): string {
+ return '<li>' .
+ '<a id="directLink-container">' .
+ '<span class="icon ' . Util::sanitizeHTML($this->getIcon()) . '"></span>' .
+ '<label for="directLink">' . Util::sanitizeHTML($this->getLabel()) . '</label>' .
+ '<input id="directLink" type="text" readonly="" value="' . Util::sanitizeHTML($this->getLink()) . '">' .
+ '</a>' .
+ '</li>';
+ }
+} \ No newline at end of file
diff --git a/apps/files_sharing/templates/public.php b/apps/files_sharing/templates/public.php
index 3c2bbe5fb59..698febd4c17 100644
--- a/apps/files_sharing/templates/public.php
+++ b/apps/files_sharing/templates/public.php
@@ -7,10 +7,6 @@
<link rel="image_src" href="<?php p($_['previewImage']); ?>" />
<?php endif; ?>
-<div id="notification-container">
- <div id="notification" style="display: none;"></div>
-</div>
-
<input type="hidden" id="sharingUserId" value="<?php p($_['owner']) ?>">
<input type="hidden" id="filesApp" name="filesApp" value="1">
<input type="hidden" id="isPublic" name="isPublic" value="1">
@@ -33,61 +29,9 @@ $maxUploadFilesize = min($upload_max_filesize, $post_max_size);
<input type="hidden" name="filesize" value="<?php p($_['nonHumanFileSize']); ?>" id="filesize">
<?php endif; ?>
<input type="hidden" name="maxSizeAnimateGif" value="<?php p($_['maxSizeAnimateGif']); ?>" id="maxSizeAnimateGif">
-
-
-<header><div id="header" class="<?php p((isset($_['folder']) ? 'share-folder' : 'share-file')) ?>">
- <div class="header-left">
- <span id="nextcloud">
- <div class="logo logo-icon svg"></div>
- <h1 class="header-appname">
- <?php p($_['filename']); ?>
- </h1>
- <div class="header-shared-by">
- <?php echo p($l->t('shared by %s', [$_['displayName']])); ?>
- </div>
- </span>
- </div>
-
- <div class="header-right">
- <?php if (!isset($_['hideFileList']) || (isset($_['hideFileList']) && $_['hideFileList'] === false)) { ?>
- <a id="share-menutoggle" class="menutoggle icon-more-white"><span class="share-menutoggle-text"><?php p($l->t('Download')) ?></span></a>
- <div id="share-menu" class="popovermenu menu">
- <ul>
- <li>
- <a href="<?php p($_['downloadURL']); ?>" id="download">
- <span class="icon icon-download"></span>
- <?php p($l->t('Download'))?>&nbsp;<span class="download-size">(<?php p($_['fileSize']) ?>)</span>
- </a>
- </li>
- <li>
- <a id="directLink-container">
- <span class="icon icon-public"></span>
- <label for="directLink"><?php p($l->t('Direct link')) ?></label>
- <input id="directLink" type="text" readonly value="<?php p($_['previewURL']); ?>">
- </a>
- </li>
- <?php if ($_['server2serversharing']) { ?>
- <li>
- <a id="save" data-protected="<?php p($_['protected']) ?>"
- data-owner-display-name="<?php p($_['displayName']) ?>" data-owner="<?php p($_['owner']) ?>" data-name="<?php p($_['filename']) ?>">
- <span class="icon icon-external"></span>
- <span id="save-button"><?php p($l->t('Add to your Nextcloud')) ?></span>
- <form class="save-form hidden" action="#">
- <input type="text" id="remote_address" placeholder="user@yourNextcloud.org"/>
- <button id="save-button-confirm" class="icon-confirm svg" disabled></button>
- </form>
- </a>
- </li>
- <?php } ?>
- </ul>
- </div>
- <?php } ?>
- </div>
- </div></header>
-<div id="content-wrapper">
- <?php if (!isset($_['hideFileList']) || (isset($_['hideFileList']) && $_['hideFileList'] === false)) { ?>
+<?php if (!isset($_['hideFileList']) || (isset($_['hideFileList']) && $_['hideFileList'] === false)) { ?>
<div id="content">
- <div id="preview">
+ <div id="preview">
<?php if (isset($_['folder'])): ?>
<?php print_unescaped($_['folder']); ?>
<?php else: ?>
@@ -102,46 +46,47 @@ $maxUploadFilesize = min($upload_max_filesize, $post_max_size);
<div id="imgframe"></div>
<?php endif; ?>
<?php if ($_['previewURL'] === $_['downloadURL']): ?>
- <div class="directDownload">
- <a href="<?php p($_['downloadURL']); ?>" id="downloadFile" class="button">
- <span class="icon icon-download"></span>
- <?php p($l->t('Download %s', array($_['filename'])))?> (<?php p($_['fileSize']) ?>)
- </a>
- </div>
+ <div class="directDownload">
+ <a href="<?php p($_['downloadURL']); ?>" id="downloadFile" class="button">
+ <span class="icon icon-download"></span>
+ <?php p($l->t('Download %s', array($_['filename'])))?> (<?php p($_['fileSize']) ?>)
+ </a>
+ </div>
<?php endif; ?>
<?php endif; ?>
</div>
+ </div>
+<?php } else { ?>
+ <input type="hidden" id="upload-only-interface" value="1"/>
+ <div id="public-upload">
+ <div id="emptycontent" class="<?php if (!empty($_['disclaimer'])) { ?>has-disclaimer<?php } ?>">
+ <div id="displayavatar"><div class="avatardiv"></div></div>
+ <h2><?php p($l->t('Upload files to %s', [$_['shareOwner']])) ?></h2>
+ <p><span class="icon-folder"></span> <?php p($_['filename']) ?></p>
+ <?php if (!empty($_['disclaimer'])) { ?>
+ <p class="disclaimer"><?php p($_['disclaimer']); ?></p>
+ <?php } ?>
+ <input type="file" name="files[]" class="hidden" multiple>
+
+ <a href="#" class="button icon-upload"><?php p($l->t('Select or drop files')) ?></a>
+ <div id="drop-upload-progress-indicator" style="padding-top: 25px;" class="hidden"><?php p($l->t('Uploading files…')) ?></div>
+ <div id="drop-upload-done-indicator" style="padding-top: 25px;" class="hidden"><?php p($l->t('Uploaded files:')) ?></div>
+ <ul>
+ </ul>
</div>
- <?php } else { ?>
- <input type="hidden" id="upload-only-interface" value="1"/>
- <div id="public-upload">
- <div id="emptycontent" class="<?php if (!empty($_['disclaimer'])) { ?>has-disclaimer<?php } ?>">
- <div id="displayavatar"><div class="avatardiv"></div></div>
- <h2><?php p($l->t('Upload files to %s', [$_['shareOwner']])) ?></h2>
- <p><span class="icon-folder"></span> <?php p($_['filename']) ?></p>
- <?php if (!empty($_['disclaimer'])) { ?>
- <p class="disclaimer"><?php p($_['disclaimer']); ?></p>
- <?php } ?>
- <input type="file" name="files[]" class="hidden" multiple>
+ </div>
+<?php } ?>
- <a href="#" class="button icon-upload"><?php p($l->t('Select or drop files')) ?></a>
- <div id="drop-upload-progress-indicator" style="padding-top: 25px;" class="hidden"><?php p($l->t('Uploading files…')) ?></div>
- <div id="drop-upload-done-indicator" style="padding-top: 25px;" class="hidden"><?php p($l->t('Uploaded files:')) ?></div>
- <ul>
- </ul>
- </div>
- </div>
- <?php } ?>
<?php if (!isset($_['hideFileList']) || (isset($_['hideFileList']) && $_['hideFileList'] !== true)): ?>
<input type="hidden" name="dir" id="dir" value="" />
<div class="hiddenuploadfield">
- <input type="file" id="file_upload_start" class="hiddenuploadfield" name="files[]"
- data-url="<?php p(OCP\Util::linkTo('files', 'ajax/upload.php')); ?>" />
+ <input type="file" id="file_upload_start" class="hiddenuploadfield" name="files[]"
+ data-url="<?php p(OCP\Util::linkTo('files', 'ajax/upload.php')); ?>" />
</div>
- <?php endif; ?>
- <footer>
- <p class="info">
- <?php print_unescaped($theme->getLongFooter()); ?>
- </p>
- </footer>
-</div>
+<?php endif; ?>
+
+<footer>
+ <p class="info">
+ <?php print_unescaped($theme->getLongFooter()); ?>
+ </p>
+</footer>
diff --git a/apps/files_sharing/tests/Controller/ShareControllerTest.php b/apps/files_sharing/tests/Controller/ShareControllerTest.php
index 6062ff89065..6dc577a354c 100644
--- a/apps/files_sharing/tests/Controller/ShareControllerTest.php
+++ b/apps/files_sharing/tests/Controller/ShareControllerTest.php
@@ -34,7 +34,11 @@ namespace OCA\Files_Sharing\Tests\Controllers;
use OC\Files\Filesystem;
use OCA\FederatedFileSharing\FederatedShareProvider;
use OCA\Files_Sharing\Controller\ShareController;
+use OCA\Files_Sharing\Template\ExternalShareMenuAction;
+use OCA\Files_Sharing\Template\LinkMenuAction;
use OCP\AppFramework\Http\DataResponse;
+use OCP\AppFramework\Http\Template\PublicTemplateResponse;
+use OCP\AppFramework\Http\Template\SimpleMenuAction;
use OCP\IConfig;
use OCP\IL10N;
use OCP\ILogger;
@@ -84,6 +88,8 @@ class ShareControllerTest extends \Test\TestCase {
private $federatedShareProvider;
/** @var EventDispatcherInterface | \PHPUnit_Framework_MockObject_MockObject */
private $eventDispatcher;
+ /** @var IL10N */
+ private $l10n;
protected function setUp() {
parent::setUp();
@@ -102,6 +108,7 @@ class ShareControllerTest extends \Test\TestCase {
$this->federatedShareProvider->expects($this->any())
->method('isIncomingServer2serverShareEnabled')->willReturn(true);
$this->eventDispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcherInterface')->getMock();
+ $this->l10n = $this->createMock(IL10N::class);
$this->shareController = new \OCA\Files_Sharing\Controller\ShareController(
$this->appName,
@@ -117,7 +124,7 @@ class ShareControllerTest extends \Test\TestCase {
$this->getMockBuilder('\OCP\Files\IRootFolder')->getMock(),
$this->federatedShareProvider,
$this->eventDispatcher,
- $this->getMockBuilder(IL10N::class)->getMock(),
+ $this->l10n,
$this->getMockBuilder('\OCP\Defaults')->getMock()
);
@@ -348,6 +355,11 @@ class ShareControllerTest extends \Test\TestCase {
$this->session->method('exists')->with('public_link_authenticated')->willReturn(true);
$this->session->method('get')->with('public_link_authenticated')->willReturn('42');
+ $this->urlGenerator->expects($this->at(0))
+ ->method('linkToRouteAbsolute')
+ ->with('files_sharing.sharecontroller.downloadShare', ['token' => 'token'])
+ ->willReturn('downloadURL');
+
$this->previewManager->method('isMimeSupported')->with('text/plain')->willReturn(true);
$this->config->method('getSystemValue')
@@ -379,6 +391,12 @@ class ShareControllerTest extends \Test\TestCase {
->method('dispatch')
->with('OCA\Files_Sharing::loadAdditionalScripts');
+ $this->l10n->expects($this->any())
+ ->method('t')
+ ->will($this->returnCallback(function($text, $parameters) {
+ return vsprintf($text, $parameters);
+ }));
+
$response = $this->shareController->showShare('token');
$sharedTmplParams = array(
'displayName' => 'ownerDisplay',
@@ -391,7 +409,7 @@ class ShareControllerTest extends \Test\TestCase {
'server2serversharing' => true,
'protected' => 'true',
'dir' => '',
- 'downloadURL' => null,
+ 'downloadURL' => 'downloadURL',
'fileSize' => '33 B',
'nonHumanFileSize' => 33,
'maxSizeAnimateGif' => 10,
@@ -404,13 +422,21 @@ class ShareControllerTest extends \Test\TestCase {
'disclaimer' => 'My disclaimer text',
'shareUrl' => null,
'previewImage' => null,
- 'previewURL' => null,
+ 'previewURL' => 'downloadURL',
);
$csp = new \OCP\AppFramework\Http\ContentSecurityPolicy();
$csp->addAllowedFrameDomain('\'self\'');
- $expectedResponse = new TemplateResponse($this->appName, 'public', $sharedTmplParams, 'base');
+ $expectedResponse = new PublicTemplateResponse($this->appName, 'public', $sharedTmplParams);
$expectedResponse->setContentSecurityPolicy($csp);
+ $expectedResponse->setHeaderTitle($sharedTmplParams['filename']);
+ $expectedResponse->setHeaderDetails('shared by ' . $sharedTmplParams['displayName']);
+ $expectedResponse->setHeaderActions([
+ new SimpleMenuAction('download', $this->l10n->t('Download'), 'icon-download-white', $sharedTmplParams['downloadURL'], 0),
+ new SimpleMenuAction('download', $this->l10n->t('Download'), 'icon-download', $sharedTmplParams['downloadURL'], 10, $sharedTmplParams['fileSize']),
+ new LinkMenuAction($this->l10n->t('Direct link'), 'icon-public', $sharedTmplParams['previewURL']),
+ new ExternalShareMenuAction($this->l10n->t('Add to your Nextcloud'), 'icon-external', $sharedTmplParams['owner'], $sharedTmplParams['displayName'], $sharedTmplParams['filename']),
+ ]);
$this->assertEquals($expectedResponse, $response);
}