summaryrefslogtreecommitdiffstats
path: root/core/js/shareitemmodel.js
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2018-11-01 22:36:09 +0100
committerGitHub <noreply@github.com>2018-11-01 22:36:09 +0100
commitf28691c26edb5b6f01330946445316d25d175fcb (patch)
tree77bc0b87e611677611750cd668be7e106a8b84a5 /core/js/shareitemmodel.js
parent35e3d40e803653e2fdfcd775eefc2d8a9a183d80 (diff)
parent876d6ec8e6b1e38215659fd606b7d7022bdb8460 (diff)
downloadnextcloud-server-f28691c26edb5b6f01330946445316d25d175fcb.tar.gz
nextcloud-server-f28691c26edb5b6f01330946445316d25d175fcb.zip
Merge pull request #11844 from nextcloud/multiple-link-shares
allow to create multiple link shares via share api
Diffstat (limited to 'core/js/shareitemmodel.js')
-rw-r--r--core/js/shareitemmodel.js59
1 files changed, 25 insertions, 34 deletions
diff --git a/core/js/shareitemmodel.js b/core/js/shareitemmodel.js
index 84715ec87c1..1bbdb2448ab 100644
--- a/core/js/shareitemmodel.js
+++ b/core/js/shareitemmodel.js
@@ -16,11 +16,9 @@
/**
* @typedef {object} OC.Share.Types.LinkShareInfo
- * @property {bool} isLinkShare
* @property {string} token
* @property {bool} hideDownload
* @property {string|null} password
- * @property {string} link
* @property {number} permissions
* @property {Date} expiration
* @property {number} stime share time
@@ -100,7 +98,7 @@
defaults: {
allowPublicUploadStatus: false,
permissions: 0,
- linkShare: {}
+ linkShares: []
},
/**
@@ -130,8 +128,11 @@
delete attributes.expiration;
}
- if (this.get('linkShare') && this.get('linkShare').isLinkShare) {
- shareId = this.get('linkShare').id;
+ var linkShares = this.get('linkShares');
+ var shareIndex = _.findIndex(linkShares, function(share) {return share.id === attributes.cid})
+
+ if (linkShares.length > 0 && shareIndex !== -1) {
+ shareId = linkShares[shareIndex].id;
// note: update can only update a single value at a time
call = this.updateShare(shareId, attributes, options);
@@ -151,12 +152,6 @@
return call;
},
- removeLinkShare: function() {
- if (this.get('linkShare')) {
- return this.removeShare(this.get('linkShare').id);
- }
- },
-
addShare: function(attributes, options) {
var shareType = attributes.shareType;
attributes = _.extend({}, attributes);
@@ -316,13 +311,13 @@
},
/**
- * Returns whether this item has a link share
+ * Returns whether this item has link shares
*
* @return {bool} true if a link share exists, false otherwise
*/
- hasLinkShare: function() {
- var linkShare = this.get('linkShare');
- if (linkShare && linkShare.isLinkShare) {
+ hasLinkShares: function() {
+ var linkShares = this.get('linkShares');
+ if (linkShares && linkShares.length > 0) {
return true;
}
return false;
@@ -636,12 +631,16 @@
/**
* @returns {int}
*/
- linkSharePermissions: function() {
- if (!this.hasLinkShare()) {
+ linkSharePermissions: function(shareId) {
+ var linkShares = this.get('linkShares');
+ var shareIndex = _.findIndex(linkShares, function(share) {return share.id === shareId})
+
+ if (!this.hasLinkShares()) {
return -1;
- } else {
- return this.get('linkShare').permissions;
+ } else if (linkShares.length > 0 && shareIndex !== -1) {
+ return linkShares[shareIndex].permissions;
}
+ return -1;
},
_getUrl: function(base, params) {
@@ -837,7 +836,7 @@
this._legacyFillCurrentShares(shares);
- var linkShare = { isLinkShare: false };
+ var linkShares = [];
// filter out the share by link
shares = _.reject(shares,
/**
@@ -850,7 +849,7 @@
|| share.item_source === this.get('itemSource'));
if (isShareLink) {
- /*
+ /**
* Ignore reshared link shares for now
* FIXME: Find a way to display properly
*/
@@ -870,20 +869,12 @@
} else {
link += OC.generateUrl('/s/') + share.token;
}
- linkShare = {
- isLinkShare: true,
- id: share.id,
- token: share.token,
+ linkShares.push(_.extend({}, share, {
// hide_download is returned as an int, so force it
// to a boolean
hideDownload: !!share.hide_download,
- password: share.share_with,
- link: link,
- permissions: share.permissions,
- // currently expiration is only effective for link shares.
- expiration: share.expiration,
- stime: share.stime
- };
+ password: share.share_with
+ }));
return share;
}
@@ -894,7 +885,7 @@
return {
reshare: data.reshare,
shares: shares,
- linkShare: linkShare,
+ linkShares: linkShares,
permissions: permissions,
allowPublicUploadStatus: allowPublicUploadStatus,
allowPublicEditingStatus: allowPublicEditingStatus,
@@ -930,7 +921,7 @@
getShareTypes: function() {
var result;
result = _.pluck(this.getSharesWithCurrentItem(), 'share_type');
- if (this.hasLinkShare()) {
+ if (this.hasLinkShares()) {
result.push(OC.Share.SHARE_TYPE_LINK);
}
return _.uniq(result);