Skip to content

Commit

Permalink
Merge pull request #11844 from nextcloud/multiple-link-shares
Browse files Browse the repository at this point in the history
allow to create multiple link shares via share api
  • Loading branch information
MorrisJobke authored Nov 1, 2018
2 parents 35e3d40 + 876d6ec commit f28691c
Show file tree
Hide file tree
Showing 26 changed files with 893 additions and 500 deletions.
56 changes: 27 additions & 29 deletions apps/files_sharing/css/sharetabview.scss
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
top: 0px;
}
.shareWithConfirm,
.clipboardButton,
.linkPass .icon-loading-small {
position: absolute;
right: 2px;
Expand All @@ -74,21 +73,17 @@
.datepicker {
margin-left: 35px;
}
.clipboardButton {
position: relative;
top: initial;
right: initial;
padding: 0;
}
.share-add {
input.share-note-delete {
display: none;
border: none;
background-color: transparent;
width: 44px !important;
padding: 0;
flex: 0 0 44px;
margin-left: auto;
&.hidden {
display: none;
}
}
}
// note
Expand Down Expand Up @@ -123,6 +118,11 @@
margin-bottom: 10px;
}
}

/* Border above last entry '+ Add another share' to separate it from current link settings */
.new-share {
border-top: 1px solid var(--color-border);
}
}
.linkPass .icon-loading-small {
margin-right: 0px;
Expand Down Expand Up @@ -182,7 +182,7 @@
.avatar {
width: 32px;
height: 32px;
background-color: var(--color-background-darker);
background-color: var(--color-primary);
}
}
.unshare img {
Expand All @@ -194,31 +194,29 @@
display: flex;
align-items: center;
white-space: nowrap;
// can edit label
> .shareOption > label {
padding: 13px;
padding-right: 0;
}
// more menu
> .share-menu {
position: relative;

// icons
> .icon:not(.hidden),
.share-menu > .icon:not(.hidden) {
padding: 14px;
height: 44px;
width: 44px;
opacity: .5;
display: block;
.icon-more {
padding: 14px;
height: 44px;
width: 44px;
opacity: .5;
display: block;
cursor: pointer;
}
cursor: pointer;

&:hover,
&:focus,
&:active {
.icon-more {
opacity: .7;;
}
opacity: .7;;
}
}

// more menu
> .share-menu {
position: relative;
display: block;
}
}
.username {
padding: 0 8px;
Expand Down Expand Up @@ -269,4 +267,4 @@

.resharerInfoView.subView {
position: relative;
}
}
14 changes: 7 additions & 7 deletions apps/files_sharing/js/share.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,15 +193,15 @@
var $tr = fileList.findFileEl(fileInfoModel.get('name'));

// We count email shares as link share
var hasLinkShare = shareModel.hasLinkShare();
var hasLinkShares = shareModel.hasLinkShares();
shareModel.get('shares').forEach(function (share) {
if (share.share_type === OC.Share.SHARE_TYPE_EMAIL) {
hasLinkShare = true;
hasLinkShares = true;
}
});

OCA.Sharing.Util._updateFileListDataAttributes(fileList, $tr, shareModel);
if (!OCA.Sharing.Util._updateFileActionIcon($tr, shareModel.hasUserShares(), hasLinkShare)) {
if (!OCA.Sharing.Util._updateFileActionIcon($tr, shareModel.hasUserShares(), hasLinkShares)) {
// remove icon, if applicable
OC.Share.markFileAsShared($tr, false, false);
}
Expand Down Expand Up @@ -249,15 +249,15 @@
*
* @param $tr file element of the file to update
* @param {boolean} hasUserShares true if a user share exists
* @param {boolean} hasLinkShare true if a link share exists
* @param {boolean} hasLinkShares true if a link share exists
*
* @return {boolean} true if the icon was set, false otherwise
*/
_updateFileActionIcon: function($tr, hasUserShares, hasLinkShare) {
_updateFileActionIcon: function($tr, hasUserShares, hasLinkShares) {
// if the statuses are loaded already, use them for the icon
// (needed when scrolling to the next page)
if (hasUserShares || hasLinkShare || $tr.attr('data-share-recipient-data') || $tr.attr('data-share-owner')) {
OC.Share.markFileAsShared($tr, true, hasLinkShare);
if (hasUserShares || hasLinkShares || $tr.attr('data-share-recipient-data') || $tr.attr('data-share-owner')) {
OC.Share.markFileAsShared($tr, true, hasLinkShares);
return true;
}
return false;
Expand Down
43 changes: 28 additions & 15 deletions apps/files_sharing/lib/Controller/ShareAPIController.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ protected function formatShare(\OCP\Share\IShare $share, Node $recipientNode = n
'token' => null,
'uid_file_owner' => $share->getShareOwner(),
'note' => $share->getNote(),
'label' => $share->getLabel(),
'displayname_file_owner' => $shareOwner !== null ? $shareOwner->getDisplayName() : $share->getShareOwner(),
];

Expand Down Expand Up @@ -354,15 +355,17 @@ public function deleteShare(string $id): DataResponse {
* @param string $shareWith
* @param string $publicUpload
* @param string $password
* @param bool $sendPasswordByTalk
* @param string $sendPasswordByTalk
* @param string $expireDate
* @param string $label
*
* @return DataResponse
* @throws OCSNotFoundException
* @throws OCSForbiddenException
* @throws NotFoundException
* @throws OCSBadRequestException
* @throws OCSException
*
* @throws OCSForbiddenException
* @throws OCSNotFoundException
* @throws \OCP\Files\InvalidPathException
* @suppress PhanUndeclaredClassMethod
*/
public function createShare(
Expand All @@ -373,7 +376,8 @@ public function createShare(
string $publicUpload = 'false',
string $password = '',
string $sendPasswordByTalk = null,
string $expireDate = ''
string $expireDate = '',
string $label = ''
): DataResponse {
$share = $this->shareManager->newShare();

Expand Down Expand Up @@ -447,15 +451,6 @@ public function createShare(
throw new OCSNotFoundException($this->l->t('Public link sharing is disabled by the administrator'));
}

/*
* For now we only allow 1 link share.
* Return the existing link share if this is a duplicate
*/
$existingShares = $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_LINK, $path, false, 1, 0);
if (!empty($existingShares)) {
return new DataResponse($this->formatShare($existingShares[0]));
}

if ($publicUpload === 'true') {
// Check if public upload is allowed
if (!$this->shareManager->shareApiLinkAllowPublicUpload()) {
Expand All @@ -482,6 +477,10 @@ public function createShare(
$share->setPassword($password);
}

if (!empty($label)) {
$share->setLabel($label);
}

//Expire date
if ($expireDate !== '') {
try {
Expand Down Expand Up @@ -746,6 +745,7 @@ public function getShares(
* @param string $publicUpload
* @param string $expireDate
* @param string $note
* @param string $label
* @param string $hideDownload
* @return DataResponse
* @throws LockedException
Expand All @@ -762,6 +762,7 @@ public function updateShare(
string $publicUpload = null,
string $expireDate = null,
string $note = null,
string $label = null,
string $hideDownload = null
): DataResponse {
try {
Expand All @@ -776,7 +777,15 @@ public function updateShare(
throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist'));
}

if ($permissions === null && $password === null && $sendPasswordByTalk === null && $publicUpload === null && $expireDate === null && $note === null && $hideDownload === null) {
if ($permissions === null &&
$password === null &&
$sendPasswordByTalk === null &&
$publicUpload === null &&
$expireDate === null &&
$note === null &&
$label === null &&
$hideDownload === null
) {
throw new OCSBadRequestException($this->l->t('Wrong or no update parameter given'));
}

Expand Down Expand Up @@ -860,6 +869,10 @@ public function updateShare(
$share->setPassword($password);
}

if ($label !== null) {
$share->setLabel($label);
}

} else {
if ($permissions !== null) {
$permissions = (int)$permissions;
Expand Down
Loading

0 comments on commit f28691c

Please sign in to comment.