Skip to content

Commit 4fc8fdd

Browse files
schiessleMorrisJobke
authored andcommitted
add hide file list option
1 parent bc8fe82 commit 4fc8fdd

File tree

8 files changed

+108
-33
lines changed

8 files changed

+108
-33
lines changed

apps/files/templates/list.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@
3737
<h2><?php p($l->t('No entries found in this folder')); ?></h2>
3838
<p></p>
3939
</div>
40-
41-
<table id="filestable" data-allow-public-upload="<?php p($_['publicUploadEnabled'])?>" data-preview-x="32" data-preview-y="32">
40+
<table id="filestable" data-allow-public-upload="<?php p($_['publicUploadEnabled'])?>" data-preview-x="32" data-preview-y="32">
4241
<thead>
4342
<tr>
4443
<th id='headerName' class="hidden column-name">
@@ -72,7 +71,7 @@
7271
</tbody>
7372
<tfoot>
7473
</tfoot>
75-
</table>
74+
</table>
7675
<input type="hidden" name="dir" id="dir" value="" />
7776
<div class="hiddenuploadfield">
7877
<input type="file" id="file_upload_start" class="hiddenuploadfield" name="files[]"

apps/files_sharing/js/public.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,11 @@ OCA.Sharing.PublicApp = {
238238
$(this).select();
239239
});
240240

241+
$(document).on('click', '.content-wrapper-upload', function (e) {
242+
//e.preventDefault();
243+
$('#file_upload_start').focus().trigger('click');
244+
});
245+
241246
$('.save-form').submit(function (event) {
242247
event.preventDefault();
243248

@@ -302,7 +307,7 @@ OCA.Sharing.PublicApp = {
302307
$('#save-button-confirm')
303308
.removeClass("icon-loading-small")
304309
.addClass("icon-confirm");
305-
310+
306311
}
307312
else {
308313
$('#save-button-confirm')
@@ -314,7 +319,7 @@ OCA.Sharing.PublicApp = {
314319

315320
toggleLoading();
316321
var location = window.location.protocol + '//' + window.location.host + OC.webroot;
317-
322+
318323
if(remote.substr(-1) !== '/') {
319324
remote += '/'
320325
};

apps/files_sharing/lib/API/Share20OCS.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,7 @@ public function updateShare($id) {
602602

603603
if ($newPermissions !== null &&
604604
$newPermissions !== \OCP\Constants::PERMISSION_READ &&
605+
$newPermissions !== (\OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE) &&
605606
$newPermissions !== (\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE)) {
606607
$share->getNode()->unlock(ILockingProvider::LOCK_SHARED);
607608
return new \OC_OCS_Result(null, 400, $this->l->t('Can\'t change permissions for public share links'));

apps/files_sharing/lib/Controllers/ShareController.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
use OCP\IUserManager;
5050
use OCP\ISession;
5151
use OCP\IPreview;
52-
use OCA\Files_Sharing\Helper;
5352
use OCP\Util;
5453
use OCA\Files_Sharing\Activity;
5554
use \OCP\Files\NotFoundException;
@@ -314,6 +313,7 @@ public function showShare($token, $path = '') {
314313
$shareTmpl['fileSize'] = \OCP\Util::humanFileSize($share->getNode()->getSize());
315314

316315
// Show file list
316+
$hideFileList = false;
317317
if ($share->getNode() instanceof \OCP\Files\Folder) {
318318
$shareTmpl['dir'] = $rootFolder->getRelativePath($path->getPath());
319319

@@ -329,12 +329,14 @@ public function showShare($token, $path = '') {
329329

330330
$uploadLimit = Util::uploadLimit();
331331
$maxUploadFilesize = min($freeSpace, $uploadLimit);
332+
$hideFileList = $share->getPermissions() & \OCP\Constants::PERMISSION_READ ? false : true;
332333

333334
$folder = new Template('files', 'list', '');
334335
$folder->assign('dir', $rootFolder->getRelativePath($path->getPath()));
335336
$folder->assign('dirToken', $token);
336337
$folder->assign('permissions', \OCP\Constants::PERMISSION_READ);
337338
$folder->assign('isPublic', true);
339+
$folder->assign('hideFileList', $hideFileList);
338340
$folder->assign('publicUploadEnabled', 'no');
339341
$folder->assign('uploadMaxFilesize', $maxUploadFilesize);
340342
$folder->assign('uploadMaxHumanFilesize', OCP\Util::humanFileSize($maxUploadFilesize));
@@ -345,6 +347,8 @@ public function showShare($token, $path = '') {
345347
$shareTmpl['folder'] = $folder->fetchPage();
346348
}
347349

350+
$shareTmpl['hideFileList'] = $hideFileList;
351+
$shareTmpl['shareOwner'] = $this->userManager->get($share->getShareOwner())->getDisplayName();
348352
$shareTmpl['downloadURL'] = $this->urlGenerator->linkToRouteAbsolute('files_sharing.sharecontroller.downloadShare', array('token' => $token));
349353
$shareTmpl['maxSizeAnimateGif'] = $this->config->getSystemValue('max_filesize_animated_gifs_public_sharing', 10);
350354
$shareTmpl['previewEnabled'] = $this->config->getSystemValue('enable_previews', true);

apps/files_sharing/templates/public.php

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -66,26 +66,28 @@
6666
<div class="header-right">
6767
<span id="details">
6868
<?php
69-
if ($_['server2serversharing']) {
70-
?>
71-
<span id="save" data-protected="<?php p($_['protected']) ?>"
72-
data-owner-display-name="<?php p($_['displayName']) ?>" data-owner="<?php p($_['owner']) ?>" data-name="<?php p($_['filename']) ?>">
73-
<button id="save-button"><?php p($l->t('Add to your ownCloud')) ?></button>
74-
<form class="save-form hidden" action="#">
75-
<input type="text" id="remote_address" placeholder="example.com/owncloud"/>
76-
<button id="save-button-confirm" class="icon-confirm svg" disabled></button>
77-
</form>
78-
</span>
69+
if (!isset($_['hideFileList']) || (isset($_['hideFileList']) && $_['hideFileList'] === false)) {
70+
if ($_['server2serversharing']) {
71+
?>
72+
<span id="save" data-protected="<?php p($_['protected']) ?>"
73+
data-owner-display-name="<?php p($_['displayName']) ?>" data-owner="<?php p($_['owner']) ?>" data-name="<?php p($_['filename']) ?>">
74+
<button id="save-button"><?php p($l->t('Add to your ownCloud')) ?></button>
75+
<form class="save-form hidden" action="#">
76+
<input type="text" id="remote_address" placeholder="example.com/owncloud"/>
77+
<button id="save-button-confirm" class="icon-confirm svg" disabled></button>
78+
</form>
79+
</span>
80+
<?php } ?>
81+
<a href="<?php p($_['downloadURL']); ?>" id="download" class="button">
82+
<img class="svg" alt="" src="<?php print_unescaped(image_path("core", "actions/download.svg")); ?>"/>
83+
<span id="download-text"><?php p($l->t('Download'))?></span>
84+
</a>
7985
<?php } ?>
80-
<a href="<?php p($_['downloadURL']); ?>" id="download" class="button">
81-
<img class="svg" alt="" src="<?php print_unescaped(image_path("core", "actions/download.svg")); ?>"/>
82-
<span id="download-text"><?php p($l->t('Download'))?></span>
83-
</a>
8486
</span>
8587
</div>
86-
</div></header>
87-
<div id="content-wrapper">
88-
<div id="content">
88+
</div></header>
89+
<div id="content-wrapper" <?php if(isset($_['hideFileList']) && $_['hideFileList'] === true){ print_unescaped(" class=\"content-wrapper-upload\"");} ?>>
90+
<?php if (!isset($_['hideFileList']) || (isset($_['hideFileList']) && $_['hideFileList'] === false)) { ?>
8991
<div id="preview">
9092
<?php if (isset($_['folder'])): ?>
9193
<?php print_unescaped($_['folder']); ?>
@@ -112,7 +114,21 @@
112114
</div>
113115
<?php endif; ?>
114116
</div>
117+
<?php } else { ?>
118+
<div id="emptycontent" class="">
119+
<div class="icon-upload"></div>
120+
<h2>Upload files to <?php print_unescaped($_['shareOwner']); ?></h2>
121+
<a href="#" class="inlineblock button">Select</a>
122+
</div>
123+
<?php } ?>
124+
</div>
125+
<?php if (!isset($_['hideFileList']) || (isset($_['hideFileList']) && $_['hideFileList'] === true)): ?>
126+
<input type="hidden" name="dir" id="dir" value="" />
127+
<div class="hiddenuploadfield">
128+
<input type="file" id="file_upload_start" class="hiddenuploadfield" name="files[]"
129+
data-url="<?php print_unescaped(OCP\Util::linkTo('files', 'ajax/upload.php')); ?>" />
115130
</div>
131+
<?php endif; ?>
116132
<footer>
117133
<p class="info">
118134
<?php print_unescaped($theme->getLongFooter()); ?>

core/js/sharedialoglinkshareview.js

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,14 @@
3030
' <input type="checkbox" value="1" name="allowPublicUpload" id="sharingDialogAllowPublicUpload-{{cid}}" class="checkbox publicUploadCheckbox" {{{publicUploadChecked}}} />' +
3131
'<label for="sharingDialogAllowPublicUpload-{{cid}}">{{publicUploadLabel}}</label>' +
3232
'</div>' +
33-
' {{/if}}' +
33+
'{{#if hideFileList}}' +
34+
'<div id="hideFileListWrapper">' +
35+
' <span class="icon-loading-small hidden"></span>' +
36+
' <input type="checkbox" value="1" name="hideFileList" id="sharingDialogHideFileList-{{cid}}" class="checkbox hideFileListCheckbox" {{{hideFileListChecked}}} />' +
37+
'<label for="sharingDialogHideFileList-{{cid}}">{{hideFileListLabel}}</label>' +
38+
'</div>' +
39+
'{{/if}}' +
40+
' {{/if}}' +
3441
' {{#if showPasswordCheckBox}}' +
3542
'<input type="checkbox" name="showPassword" id="showPassword-{{cid}}" class="checkbox showPasswordCheckbox" {{#if isPasswordSet}}checked="checked"{{/if}} value="1" />' +
3643
'<label for="showPassword-{{cid}}">{{enablePasswordLabel}}</label>' +
@@ -74,7 +81,8 @@
7481
'keyup input.linkPassText': 'onPasswordKeyUp',
7582
'click .linkCheckbox': 'onLinkCheckBoxChange',
7683
'click .linkText': 'onLinkTextClick',
77-
'change .publicUploadCheckbox': 'onAllowPublicUploadChange',
84+
'change .publicUploadCheckbox': 'onAllowPublicUploadChange',
85+
'change .hideFileListCheckbox': 'onHideFileListChange',
7886
'click .showPasswordCheckbox': 'onShowPasswordClick'
7987
},
8088

@@ -93,6 +101,10 @@
93101
view.render();
94102
});
95103

104+
this.model.on('change:hideFileListStatus', function() {
105+
view.render();
106+
});
107+
96108
this.model.on('change:linkShare', function() {
97109
view.render();
98110
});
@@ -110,6 +122,7 @@
110122
'onPasswordKeyUp',
111123
'onLinkTextClick',
112124
'onShowPasswordClick',
125+
'onHideFileListChange',
113126
'onAllowPublicUploadChange'
114127
);
115128
},
@@ -208,7 +221,21 @@
208221
this.model.saveLinkShare({
209222
permissions: permissions
210223
});
211-
},
224+
},
225+
226+
onHideFileListChange: function () {
227+
var $checkbox = this.$('.hideFileListCheckbox');
228+
$checkbox.siblings('.icon-loading-small').removeClass('hidden').addClass('inlineblock');
229+
230+
var permissions = OC.PERMISSION_UPDATE | OC.PERMISSION_CREATE | OC.PERMISSION_READ;
231+
if ($checkbox.is(':checked')) {
232+
permissions = OC.PERMISSION_UPDATE | OC.PERMISSION_CREATE;
233+
}
234+
235+
this.model.saveLinkShare({
236+
permissions: permissions
237+
});
238+
},
212239

213240
render: function() {
214241
var linkShareTemplate = this.template();
@@ -237,6 +264,13 @@
237264
publicUploadChecked = 'checked="checked"';
238265
}
239266

267+
var hideFileList = publicUploadChecked;
268+
269+
var hideFileListChecked = '';
270+
if(this.model.isHideFileListSet()) {
271+
hideFileListChecked = 'checked="checked"';
272+
}
273+
240274
var isLinkShare = this.model.get('linkShare').isLinkShare;
241275
var isPasswordSet = !!this.model.get('linkShare').password;
242276
var showPasswordCheckBox = isLinkShare
@@ -246,6 +280,7 @@
246280
this.$el.html(linkShareTemplate({
247281
cid: this.cid,
248282
shareAllowed: true,
283+
hideFileList: hideFileList,
249284
isLinkShare: isLinkShare,
250285
shareLinkURL: this.model.get('linkShare').link,
251286
linkShareLabel: t('core', 'Share link'),
@@ -257,7 +292,9 @@
257292
showPasswordCheckBox: showPasswordCheckBox,
258293
publicUpload: publicUpload && isLinkShare,
259294
publicUploadChecked: publicUploadChecked,
260-
publicUploadLabel: t('core', 'Allow editing'),
295+
hideFileListChecked: hideFileListChecked,
296+
publicUploadLabel: t('core', 'Allow editing'),
297+
hideFileListLabel: t('core', 'Hide file listing'),
261298
mailPublicNotificationEnabled: isLinkShare && this.configModel.isMailPublicNotificationEnabled(),
262299
mailPrivatePlaceholder: t('core', 'Email link to person'),
263300
mailButtonText: t('core', 'Send')

core/js/shareitemmodel.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,13 @@
272272
return this.get('allowPublicUploadStatus');
273273
},
274274

275+
/**
276+
* @returns {boolean}
277+
*/
278+
isHideFileListSet: function() {
279+
return this.get('hideFileListStatus');
280+
},
281+
275282
/**
276283
* @returns {boolean}
277284
*/
@@ -685,6 +692,16 @@
685692
});
686693
}
687694

695+
var hideFileListStatus = false;
696+
if(!_.isUndefined(data.shares)) {
697+
$.each(data.shares, function (key, value) {
698+
if (value.share_type === OC.Share.SHARE_TYPE_LINK) {
699+
hideFileListStatus = (value.permissions & OC.PERMISSION_READ) ? false : true;
700+
return true;
701+
}
702+
});
703+
}
704+
688705
/** @type {OC.Share.Types.ShareInfo[]} **/
689706
var shares = _.map(data.shares, function(share) {
690707
// properly parse some values because sometimes the server
@@ -757,7 +774,8 @@
757774
shares: shares,
758775
linkShare: linkShare,
759776
permissions: permissions,
760-
allowPublicUploadStatus: allowPublicUploadStatus
777+
allowPublicUploadStatus: allowPublicUploadStatus,
778+
hideFileListStatus: hideFileListStatus
761779
};
762780
},
763781

lib/private/Share20/Manager.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -239,11 +239,6 @@ protected function generalCreateChecks(\OCP\Share\IShare $share) {
239239
throw new GenericShareException($message_t, $message_t, 404);
240240
}
241241

242-
// Check that read permissions are always set
243-
if (($share->getPermissions() & \OCP\Constants::PERMISSION_READ) === 0) {
244-
throw new \InvalidArgumentException('Shares need at least read permissions');
245-
}
246-
247242
if ($share->getNode() instanceof \OCP\Files\File) {
248243
if ($share->getPermissions() & \OCP\Constants::PERMISSION_DELETE) {
249244
$message_t = $this->l->t('Files can\'t be shared with delete permissions');

0 commit comments

Comments
 (0)