Skip to content

Commit

Permalink
Merge pull request #11569 from nextcloud/bug-11514/hide-header-action…
Browse files Browse the repository at this point in the history
…s-for-filedrops

Hides the header actions for file drops
  • Loading branch information
MorrisJobke authored Nov 7, 2018
2 parents b56cb41 + 463dfb5 commit 836ba4f
Show file tree
Hide file tree
Showing 6 changed files with 179 additions and 31 deletions.
6 changes: 6 additions & 0 deletions apps/files_sharing/css/mobile.scss
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,11 @@ table td.filename .nametext {
padding-right: 14px;
background-position: center;
}
.note {
padding: 0 20px;
}

#emptycontent {
margin-top: 10vh;
}
}
16 changes: 12 additions & 4 deletions apps/files_sharing/css/public.scss
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,10 @@ thead {
margin: 0 auto;
}

#emptycontent.has-disclaimer {
margin-top: 10vh;
#emptycontent {
&.has-note {
margin-top: 5vh;
}
}

#public-upload #emptycontent h2 {
Expand Down Expand Up @@ -152,8 +154,9 @@ thead {
margin-right: 7px;
}

.disclaimer {
margin: -20px auto 30px;
.disclaimer,
.note {
margin: 0 auto 30px;
max-width: 400px;
text-align: left;
}
Expand Down Expand Up @@ -184,6 +187,11 @@ thead {
}
}

#show-terms-dialog {
cursor: pointer;
font-weight: bold;
}

// hide the primary on public share on mobile
@media only screen and (max-width: 768px) {
#body-public {
Expand Down
16 changes: 15 additions & 1 deletion apps/files_sharing/js/public.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ OCA.Sharing.PublicApp = {
displayName: t('files', 'Delete'),
iconClass: 'icon-delete',
}
]
]
}
);
this.files = OCA.Files.Files;
Expand Down Expand Up @@ -297,10 +297,24 @@ OCA.Sharing.PublicApp = {
}
});

self._bindShowTermsAction();

// legacy
window.FileList = this.fileList;
},

/**
* Binds the click action for the "terms of service" action.
* Shows an OC info dialog on click.
*
* @private
*/
_bindShowTermsAction: function() {
$('#show-terms-dialog').on('click', function() {
OC.dialogs.info($('#disclaimerText').val(), t('files_sharing', 'Terms of service'));
});
},

_showTextPreview: function (data, previewHeight) {
var textDiv = $('<div/>').addClass('text-preview');
textDiv.text(data);
Expand Down
43 changes: 25 additions & 18 deletions apps/files_sharing/lib/Controller/ShareController.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
use OCP\Files\NotFoundException;
use OCP\Files\IRootFolder;
use OCP\Share\Exceptions\ShareNotFound;
use OCP\Util;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\GenericEvent;
use OCP\Share\IManager as ShareManager;
Expand Down Expand Up @@ -295,9 +294,12 @@ public function showShare($path = ''): TemplateResponse {
if (!$this->validateShare($share)) {
throw new NotFoundException();
}

$shareNode = $share->getNode();

// We can't get the path of a file share
try {
if ($share->getNode() instanceof \OCP\Files\File && $path !== '') {
if ($shareNode instanceof \OCP\Files\File && $path !== '') {
$this->emitAccessShareHook($share, 404, 'Share not found');
throw new NotFoundException();
}
Expand All @@ -309,34 +311,34 @@ public function showShare($path = ''): TemplateResponse {
$shareTmpl = [];
$shareTmpl['displayName'] = $this->userManager->get($share->getShareOwner())->getDisplayName();
$shareTmpl['owner'] = $share->getShareOwner();
$shareTmpl['filename'] = $share->getNode()->getName();
$shareTmpl['filename'] = $shareNode->getName();
$shareTmpl['directory_path'] = $share->getTarget();
$shareTmpl['note'] = $share->getNote();
$shareTmpl['mimetype'] = $share->getNode()->getMimetype();
$shareTmpl['previewSupported'] = $this->previewManager->isMimeSupported($share->getNode()->getMimetype());
$shareTmpl['mimetype'] = $shareNode->getMimetype();
$shareTmpl['previewSupported'] = $this->previewManager->isMimeSupported($shareNode->getMimetype());
$shareTmpl['dirToken'] = $this->getToken();
$shareTmpl['sharingToken'] = $this->getToken();
$shareTmpl['server2serversharing'] = $this->federatedShareProvider->isOutgoingServer2serverShareEnabled();
$shareTmpl['protected'] = $share->getPassword() !== null ? 'true' : 'false';
$shareTmpl['dir'] = '';
$shareTmpl['nonHumanFileSize'] = $share->getNode()->getSize();
$shareTmpl['fileSize'] = \OCP\Util::humanFileSize($share->getNode()->getSize());
$shareTmpl['nonHumanFileSize'] = $shareNode->getSize();
$shareTmpl['fileSize'] = \OCP\Util::humanFileSize($shareNode->getSize());
$shareTmpl['hideDownload'] = $share->getHideDownload();

// Show file list
$hideFileList = false;
if ($share->getNode() instanceof \OCP\Files\Folder) {
/** @var \OCP\Files\Folder $rootFolder */
$rootFolder = $share->getNode();

if ($shareNode instanceof \OCP\Files\Folder) {

$shareIsFolder = true;

try {
$folderNode = $rootFolder->get($path);
$folderNode = $shareNode->get($path);
} catch (\OCP\Files\NotFoundException $e) {
$this->emitAccessShareHook($share, 404, 'Share not found');
throw new NotFoundException();
}

$shareTmpl['dir'] = $rootFolder->getRelativePath($folderNode->getPath());
$shareTmpl['dir'] = $shareNode->getRelativePath($folderNode->getPath());

/*
* The OC_Util methods require a view. This just uses the node API
Expand All @@ -352,7 +354,7 @@ public function showShare($path = ''): TemplateResponse {
$maxUploadFilesize = $freeSpace;

$folder = new Template('files', 'list', '');
$folder->assign('dir', $rootFolder->getRelativePath($folderNode->getPath()));
$folder->assign('dir', $shareNode->getRelativePath($folderNode->getPath()));
$folder->assign('dirToken', $this->getToken());
$folder->assign('permissions', \OCP\Constants::PERMISSION_READ);
$folder->assign('isPublic', true);
Expand All @@ -365,6 +367,8 @@ public function showShare($path = ''): TemplateResponse {
$folder->assign('usedSpacePercent', 0);
$folder->assign('trash', false);
$shareTmpl['folder'] = $folder->fetchPage();
} else {
$shareIsFolder = false;
}

$shareTmpl['showgridview'] = true;
Expand All @@ -379,14 +383,14 @@ public function showShare($path = ''): TemplateResponse {
$shareTmpl['previewMaxY'] = $this->config->getSystemValue('preview_max_y', 1024);
$shareTmpl['disclaimer'] = $this->config->getAppValue('core', 'shareapi_public_link_disclaimertext', null);
$shareTmpl['previewURL'] = $shareTmpl['downloadURL'];
$ogPreview = '';

if ($shareTmpl['previewSupported']) {
$shareTmpl['previewImage'] = $this->urlGenerator->linkToRouteAbsolute( 'files_sharing.PublicPreview.getPreview',
['x' => 200, 'y' => 200, 'file' => $shareTmpl['directory_path'], 'token' => $shareTmpl['dirToken']]);
$ogPreview = $shareTmpl['previewImage'];

// We just have direct previews for image files
if ($share->getNode()->getMimePart() === 'image') {
if ($shareNode->getMimePart() === 'image') {
$shareTmpl['previewURL'] = $this->urlGenerator->linkToRouteAbsolute('files_sharing.publicpreview.directLink', ['token' => $this->getToken()]);

$ogPreview = $shareTmpl['previewURL'];
Expand All @@ -411,7 +415,6 @@ public function showShare($path = ''): TemplateResponse {
\OCP\Util::addStyle('files_sharing', 'publicView');
\OCP\Util::addScript('files_sharing', 'public');
\OCP\Util::addScript('files_sharing', 'templates');
\OCP\Util::addScript('files_sharing', 'public_note');
\OCP\Util::addScript('files', 'fileactions');
\OCP\Util::addScript('files', 'fileactionsmenu');
\OCP\Util::addScript('files', 'jquery.fileupload');
Expand Down Expand Up @@ -447,7 +450,11 @@ public function showShare($path = ''): TemplateResponse {
$response = new PublicTemplateResponse($this->appName, 'public', $shareTmpl);
$response->setHeaderTitle($shareTmpl['filename']);
$response->setHeaderDetails($this->l10n->t('shared by %s', [$shareTmpl['displayName']]));
if (!$share->getHideDownload()) {

$isNoneFileDropFolder = $shareIsFolder === false || $share->getPermissions() !== \OCP\Constants::PERMISSION_CREATE;

if ($isNoneFileDropFolder && !$share->getHideDownload()) {
\OCP\Util::addScript('files_sharing', 'public_note');
$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']),
Expand Down
24 changes: 19 additions & 5 deletions apps/files_sharing/templates/public.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<input type="hidden" name="previewSupported" value="<?php p($_['previewSupported'] ? 'true' : 'false'); ?>" id="previewSupported">
<input type="hidden" name="mimetypeIcon" value="<?php p(\OC::$server->getMimeTypeDetector()->mimeTypeIcon($_['mimetype'])); ?>" id="mimetypeIcon">
<input type="hidden" name="hideDownload" value="<?php p($_['hideDownload'] ? 'true' : 'false'); ?>" id="hideDownload">
<input type="hidden" id="disclaimerText" value="<?php p($_['disclaimer']) ?>">
<?php
$upload_max_filesize = OC::$server->getIniWrapper()->getBytes('upload_max_filesize');
$post_max_size = OC::$server->getIniWrapper()->getBytes('post_max_size');
Expand Down Expand Up @@ -82,20 +83,33 @@
<?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="emptycontent"
class="<?php if (!empty($_['note'])) { ?>has-note<?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 if (empty($_['note']) === false) { ?>
<h3><?php p($l->t('Note')); ?></h3>
<p class="note"><?php p($_['note']); ?></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>

<?php if (!empty($_['disclaimer'])) { ?>
<div>
<?php
echo $l->t('By uploading files, you agree to the %1$sterms of service%2$s.', [
'<span id="show-terms-dialog">', '</span>'
]);
?>
</div>
<?php } ?>
</div>
</div>
<?php } ?>
Expand Down
105 changes: 102 additions & 3 deletions apps/files_sharing/tests/Controller/ShareControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,29 +32,30 @@
namespace OCA\Files_Sharing\Tests\Controllers;

use OC\Files\Filesystem;
use OC\Files\Node\Folder;
use OCA\FederatedFileSharing\FederatedShareProvider;
use OCA\Files_Sharing\Controller\ShareController;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\Http\Template\ExternalShareMenuAction;
use OCP\AppFramework\Http\Template\LinkMenuAction;
use OCP\AppFramework\Http\Template\PublicTemplateResponse;
use OCP\AppFramework\Http\Template\SimpleMenuAction;
use OCP\Constants;
use OCP\Files\NotFoundException;
use OCP\Files\Storage;
use OCP\IConfig;
use OCP\IL10N;
use OCP\ILogger;
use OCP\IPreview;
use OCP\IRequest;
use OCP\IUser;
use OCP\Share\Exceptions\ShareNotFound;
use OCP\AppFramework\Http\NotFoundResponse;
use OCP\AppFramework\Http\RedirectResponse;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\ISession;
use OCP\IUserManager;
use OCP\Security\ISecureRandom;
use OCP\IURLGenerator;
use OCP\Share\IShare;
use PHPUnit\Framework\MockObject\MockObject;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;

/**
Expand Down Expand Up @@ -423,6 +424,104 @@ public function testShowShareHideDownload() {
$this->assertEquals($expectedResponse, $response);
}

/**
* Checks file drop shares:
* - there must not be any header action
* - the template param "hideFileList" should be true
*
* @test
* @return void
*/
public function testShareFileDrop() {
$this->shareController->setToken('token');

$owner = $this->getMockBuilder(IUser::class)->getMock();
$owner->method('getDisplayName')->willReturn('ownerDisplay');
$owner->method('getUID')->willReturn('ownerUID');

/* @var MockObject|Storage $storage */
$storage = $this->getMockBuilder(Storage::class)
->disableOriginalConstructor()
->getMock();

/* @var MockObject|Folder $folder */
$folder = $this->getMockBuilder(Folder::class)
->disableOriginalConstructor()
->getMock();
$folder->method('getName')->willReturn('/fileDrop');
$folder->method('isReadable')->willReturn(true);
$folder->method('isShareable')->willReturn(true);
$folder->method('getStorage')->willReturn($storage);
$folder->method('get')->with('')->willReturn($folder);
$folder->method('getSize')->willReturn(1337);

$share = \OC::$server->getShareManager()->newShare();
$share->setId(42);
$share->setPermissions(Constants::PERMISSION_CREATE)
->setShareOwner('ownerUID')
->setNode($folder)
->setTarget('/fileDrop');

$this->shareManager
->expects($this->once())
->method('getShareByToken')
->with('token')
->willReturn($share);

$this->userManager->method('get')->with('ownerUID')->willReturn($owner);

$this->l10n->expects($this->any())
->method('t')
->will($this->returnCallback(function($text, $parameters) {
return vsprintf($text, $parameters);
}));

$response = $this->shareController->showShare();
// skip the "folder" param for tests
$responseParams = $response->getParams();
unset($responseParams['folder']);
$response->setParams($responseParams);

$sharedTmplParams = array(
'displayName' => 'ownerDisplay',
'owner' => 'ownerUID',
'filename' => '/fileDrop',
'directory_path' => '/fileDrop',
'mimetype' => null,
'dirToken' => 'token',
'sharingToken' => 'token',
'server2serversharing' => true,
'protected' => 'false',
'dir' => null,
'downloadURL' => '',
'fileSize' => '1 KB',
'nonHumanFileSize' => 1337,
'maxSizeAnimateGif' => null,
'previewSupported' => null,
'previewEnabled' => null,
'previewMaxX' => null,
'previewMaxY' => null,
'hideFileList' => true,
'shareOwner' => 'ownerDisplay',
'disclaimer' => null,
'shareUrl' => '',
'previewImage' => '',
'previewURL' => '',
'note' => '',
'hideDownload' => false,
'showgridview' => true
);

$csp = new \OCP\AppFramework\Http\ContentSecurityPolicy();
$csp->addAllowedFrameDomain('\'self\'');
$expectedResponse = new PublicTemplateResponse($this->appName, 'public', $sharedTmplParams);
$expectedResponse->setContentSecurityPolicy($csp);
$expectedResponse->setHeaderTitle($sharedTmplParams['filename']);
$expectedResponse->setHeaderDetails('shared by ' . $sharedTmplParams['displayName']);

self::assertEquals($expectedResponse, $response);
}

/**
* @expectedException \OCP\Files\NotFoundException
*/
Expand Down

0 comments on commit 836ba4f

Please sign in to comment.