2019-09-25 16:19:42 +00:00
|
|
|
/* eslint-disable */
|
2015-07-30 22:07:41 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2015
|
|
|
|
*
|
|
|
|
* This file is licensed under the Affero General Public License version 3
|
|
|
|
* or later.
|
|
|
|
*
|
|
|
|
* See the COPYING-README file.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
(function() {
|
2019-09-25 16:19:42 +00:00
|
|
|
if (!OC.Share) {
|
|
|
|
OC.Share = {}
|
|
|
|
OC.Share.Types = {}
|
2015-07-30 22:07:41 +00:00
|
|
|
}
|
|
|
|
|
2015-09-03 13:53:17 +00:00
|
|
|
/**
|
|
|
|
* @typedef {object} OC.Share.Types.LinkShareInfo
|
|
|
|
* @property {string} token
|
2018-10-22 09:06:53 +00:00
|
|
|
* @property {bool} hideDownload
|
2015-09-03 13:53:17 +00:00
|
|
|
* @property {string|null} password
|
2018-10-15 15:09:46 +00:00
|
|
|
* @property {bool} sendPasswordByTalk
|
2015-09-12 15:02:03 +00:00
|
|
|
* @property {number} permissions
|
2015-09-04 13:31:45 +00:00
|
|
|
* @property {Date} expiration
|
|
|
|
* @property {number} stime share time
|
2015-09-03 13:53:17 +00:00
|
|
|
*/
|
|
|
|
|
2015-07-30 22:07:41 +00:00
|
|
|
/**
|
|
|
|
* @typedef {object} OC.Share.Types.Reshare
|
|
|
|
* @property {string} uid_owner
|
|
|
|
* @property {number} share_type
|
|
|
|
* @property {string} share_with
|
|
|
|
* @property {string} displayname_owner
|
|
|
|
* @property {number} permissions
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @typedef {object} OC.Share.Types.ShareInfo
|
|
|
|
* @property {number} share_type
|
|
|
|
* @property {number} permissions
|
|
|
|
* @property {number} file_source optional
|
|
|
|
* @property {number} item_source
|
|
|
|
* @property {string} token
|
|
|
|
* @property {string} share_with
|
|
|
|
* @property {string} share_with_displayname
|
2017-06-06 11:21:42 +00:00
|
|
|
* @property {string} share_with_avatar
|
2015-09-23 10:14:09 +00:00
|
|
|
* @property {string} mail_send
|
2015-07-30 22:07:41 +00:00
|
|
|
* @property {Date} expiration optional?
|
|
|
|
* @property {number} stime optional?
|
2016-02-10 15:00:55 +00:00
|
|
|
* @property {string} uid_owner
|
2017-04-10 15:07:45 +00:00
|
|
|
* @property {string} displayname_owner
|
2015-07-30 22:07:41 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @typedef {object} OC.Share.Types.ShareItemInfo
|
|
|
|
* @property {OC.Share.Types.Reshare} reshare
|
|
|
|
* @property {OC.Share.Types.ShareInfo[]} shares
|
2015-09-03 13:53:17 +00:00
|
|
|
* @property {OC.Share.Types.LinkShareInfo|undefined} linkShare
|
2015-07-30 22:07:41 +00:00
|
|
|
*/
|
|
|
|
|
2015-09-23 10:14:09 +00:00
|
|
|
/**
|
|
|
|
* These properties are sometimes returned by the server as strings instead
|
|
|
|
* of integers, so we need to convert them accordingly...
|
|
|
|
*/
|
|
|
|
var SHARE_RESPONSE_INT_PROPS = [
|
|
|
|
'id', 'file_parent', 'mail_send', 'file_source', 'item_source', 'permissions',
|
2015-09-24 10:21:19 +00:00
|
|
|
'storage', 'share_type', 'parent', 'stime'
|
2019-09-25 16:19:42 +00:00
|
|
|
]
|
2015-09-23 10:14:09 +00:00
|
|
|
|
2015-07-30 22:07:41 +00:00
|
|
|
/**
|
|
|
|
* @class OCA.Share.ShareItemModel
|
|
|
|
* @classdesc
|
|
|
|
*
|
|
|
|
* Represents the GUI of the share dialogue
|
|
|
|
*
|
2015-08-11 12:10:25 +00:00
|
|
|
* // FIXME: use OC Share API once #17143 is done
|
2015-09-14 10:48:01 +00:00
|
|
|
*
|
|
|
|
* // TODO: this really should be a collection of share item models instead,
|
|
|
|
* where the link share is one of them
|
2015-07-30 22:07:41 +00:00
|
|
|
*/
|
2015-08-10 20:23:52 +00:00
|
|
|
var ShareItemModel = OC.Backbone.Model.extend({
|
2016-01-22 16:30:18 +00:00
|
|
|
/**
|
2018-10-24 14:24:16 +00:00
|
|
|
* share id of the link share, if applicable
|
2016-01-22 16:30:18 +00:00
|
|
|
*/
|
|
|
|
_linkShareId: null,
|
|
|
|
|
2015-08-13 00:38:14 +00:00
|
|
|
initialize: function(attributes, options) {
|
2019-09-25 16:19:42 +00:00
|
|
|
if (!_.isUndefined(options.configModel)) {
|
|
|
|
this.configModel = options.configModel
|
2015-08-13 00:38:14 +00:00
|
|
|
}
|
2019-09-25 16:19:42 +00:00
|
|
|
if (!_.isUndefined(options.fileInfoModel)) {
|
2015-09-03 13:53:17 +00:00
|
|
|
/** @type {OC.Files.FileInfo} **/
|
2019-09-25 16:19:42 +00:00
|
|
|
this.fileInfoModel = options.fileInfoModel
|
2015-09-03 13:53:17 +00:00
|
|
|
}
|
2015-09-05 00:02:55 +00:00
|
|
|
|
2019-09-25 16:19:42 +00:00
|
|
|
_.bindAll(this, 'addShare')
|
2015-07-30 22:07:41 +00:00
|
|
|
},
|
|
|
|
|
2015-08-11 21:14:44 +00:00
|
|
|
defaults: {
|
2015-08-24 21:37:04 +00:00
|
|
|
allowPublicUploadStatus: false,
|
2015-09-03 13:53:17 +00:00
|
|
|
permissions: 0,
|
2018-10-29 12:58:14 +00:00
|
|
|
linkShares: []
|
2015-08-11 21:14:44 +00:00
|
|
|
},
|
|
|
|
|
2015-09-14 10:48:01 +00:00
|
|
|
/**
|
|
|
|
* Saves the current link share information.
|
|
|
|
*
|
2017-04-24 20:05:34 +00:00
|
|
|
* This will trigger an ajax call and, if successful, refetch the model
|
|
|
|
* afterwards. Callbacks "success", "error" and "complete" can be given
|
|
|
|
* in the options object; "success" is called after a successful save
|
|
|
|
* once the model is refetch, "error" is called after a failed save, and
|
|
|
|
* "complete" is called both after a successful save and after a failed
|
|
|
|
* save. Note that "complete" is called before "success" and "error" are
|
|
|
|
* called (unlike in jQuery, in which it is called after them); this
|
|
|
|
* ensures that "complete" is called even if refetching the model fails.
|
2015-09-14 10:48:01 +00:00
|
|
|
*
|
|
|
|
* TODO: this should be a separate model
|
|
|
|
*/
|
|
|
|
saveLinkShare: function(attributes, options) {
|
2019-09-25 16:19:42 +00:00
|
|
|
options = options || {}
|
|
|
|
attributes = _.extend({}, attributes)
|
2015-09-12 15:02:03 +00:00
|
|
|
|
2019-09-25 16:19:42 +00:00
|
|
|
var shareId = null
|
|
|
|
var call
|
2015-10-22 15:32:40 +00:00
|
|
|
|
2016-01-22 16:30:18 +00:00
|
|
|
// oh yeah...
|
|
|
|
if (attributes.expiration) {
|
2019-09-25 16:19:42 +00:00
|
|
|
attributes.expireDate = attributes.expiration
|
|
|
|
delete attributes.expiration
|
2016-01-22 16:30:18 +00:00
|
|
|
}
|
2015-09-14 10:48:01 +00:00
|
|
|
|
2019-09-25 16:19:42 +00:00
|
|
|
var linkShares = this.get('linkShares')
|
|
|
|
var shareIndex = _.findIndex(linkShares, function(share) { return share.id === attributes.cid })
|
2018-10-29 12:58:14 +00:00
|
|
|
|
|
|
|
if (linkShares.length > 0 && shareIndex !== -1) {
|
2019-09-25 16:19:42 +00:00
|
|
|
shareId = linkShares[shareIndex].id
|
2015-09-12 12:21:14 +00:00
|
|
|
|
2016-01-22 16:30:18 +00:00
|
|
|
// note: update can only update a single value at a time
|
2019-09-25 16:19:42 +00:00
|
|
|
call = this.updateShare(shareId, attributes, options)
|
2016-01-22 16:30:18 +00:00
|
|
|
} else {
|
|
|
|
attributes = _.defaults(attributes, {
|
2018-10-22 09:06:53 +00:00
|
|
|
hideDownload: false,
|
2016-01-22 16:30:18 +00:00
|
|
|
password: '',
|
|
|
|
passwordChanged: false,
|
2018-10-15 15:09:46 +00:00
|
|
|
sendPasswordByTalk: false,
|
2016-01-22 16:30:18 +00:00
|
|
|
permissions: OC.PERMISSION_READ,
|
|
|
|
expireDate: this.configModel.getDefaultExpirationDateString(),
|
|
|
|
shareType: OC.Share.SHARE_TYPE_LINK
|
2019-09-25 16:19:42 +00:00
|
|
|
})
|
2015-09-12 12:21:14 +00:00
|
|
|
|
2019-09-25 16:19:42 +00:00
|
|
|
call = this.addShare(attributes, options)
|
2015-09-13 23:01:02 +00:00
|
|
|
}
|
|
|
|
|
2019-09-25 16:19:42 +00:00
|
|
|
return call
|
2015-09-14 10:48:01 +00:00
|
|
|
},
|
|
|
|
|
2015-09-14 15:47:47 +00:00
|
|
|
addShare: function(attributes, options) {
|
2019-09-25 16:19:42 +00:00
|
|
|
var shareType = attributes.shareType
|
|
|
|
attributes = _.extend({}, attributes)
|
2015-09-05 00:02:55 +00:00
|
|
|
|
2017-12-01 10:35:01 +00:00
|
|
|
// get default permissions
|
2019-09-25 16:19:42 +00:00
|
|
|
var defaultPermissions = OC.getCapabilities()['files_sharing']['default_permissions'] || OC.PERMISSION_ALL
|
|
|
|
var possiblePermissions = OC.PERMISSION_READ
|
2017-12-01 10:35:01 +00:00
|
|
|
|
2016-04-18 15:15:20 +00:00
|
|
|
if (this.updatePermissionPossible()) {
|
2019-09-25 16:19:42 +00:00
|
|
|
possiblePermissions = possiblePermissions | OC.PERMISSION_UPDATE
|
2016-04-18 15:15:20 +00:00
|
|
|
}
|
|
|
|
if (this.createPermissionPossible()) {
|
2019-09-25 16:19:42 +00:00
|
|
|
possiblePermissions = possiblePermissions | OC.PERMISSION_CREATE
|
2016-04-18 15:15:20 +00:00
|
|
|
}
|
|
|
|
if (this.deletePermissionPossible()) {
|
2019-09-25 16:19:42 +00:00
|
|
|
possiblePermissions = possiblePermissions | OC.PERMISSION_DELETE
|
2016-04-18 15:15:20 +00:00
|
|
|
}
|
|
|
|
if (this.configModel.get('isResharingAllowed') && (this.sharePermissionPossible())) {
|
2019-09-25 16:19:42 +00:00
|
|
|
possiblePermissions = possiblePermissions | OC.PERMISSION_SHARE
|
2015-09-05 00:02:55 +00:00
|
|
|
}
|
|
|
|
|
2019-09-25 16:19:42 +00:00
|
|
|
attributes.permissions = defaultPermissions & possiblePermissions
|
2016-01-22 16:30:18 +00:00
|
|
|
if (_.isUndefined(attributes.path)) {
|
2019-09-25 16:19:42 +00:00
|
|
|
attributes.path = this.fileInfoModel.getFullPath()
|
2016-01-22 16:30:18 +00:00
|
|
|
}
|
2015-09-05 00:02:55 +00:00
|
|
|
|
2017-04-24 20:07:08 +00:00
|
|
|
return this._addOrUpdateShare({
|
2016-01-22 16:30:18 +00:00
|
|
|
type: 'POST',
|
|
|
|
url: this._getUrl('shares'),
|
|
|
|
data: attributes,
|
|
|
|
dataType: 'json'
|
2019-09-25 16:19:42 +00:00
|
|
|
}, options)
|
2015-09-14 00:29:22 +00:00
|
|
|
},
|
|
|
|
|
2016-01-28 16:07:51 +00:00
|
|
|
updateShare: function(shareId, attrs, options) {
|
2017-04-24 20:07:08 +00:00
|
|
|
return this._addOrUpdateShare({
|
2016-01-22 16:30:18 +00:00
|
|
|
type: 'PUT',
|
|
|
|
url: this._getUrl('shares/' + encodeURIComponent(shareId)),
|
|
|
|
data: attrs,
|
|
|
|
dataType: 'json'
|
2019-09-25 16:19:42 +00:00
|
|
|
}, options)
|
2017-04-24 20:07:08 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_addOrUpdateShare: function(ajaxSettings, options) {
|
2019-09-25 16:19:42 +00:00
|
|
|
var self = this
|
|
|
|
options = options || {}
|
2017-04-24 20:07:08 +00:00
|
|
|
|
|
|
|
return $.ajax(
|
|
|
|
ajaxSettings
|
|
|
|
).always(function() {
|
2017-04-24 19:18:29 +00:00
|
|
|
if (_.isFunction(options.complete)) {
|
2019-09-25 16:19:42 +00:00
|
|
|
options.complete(self)
|
2017-04-24 19:18:29 +00:00
|
|
|
}
|
2016-01-22 16:30:18 +00:00
|
|
|
}).done(function() {
|
2017-04-24 20:07:08 +00:00
|
|
|
self.fetch().done(function() {
|
|
|
|
if (_.isFunction(options.success)) {
|
2019-09-25 16:19:42 +00:00
|
|
|
options.success(self)
|
2016-01-28 16:07:51 +00:00
|
|
|
}
|
2019-09-25 16:19:42 +00:00
|
|
|
})
|
2016-01-28 16:07:51 +00:00
|
|
|
}).fail(function(xhr) {
|
2019-09-25 16:19:42 +00:00
|
|
|
var msg = t('core', 'Error')
|
|
|
|
var result = xhr.responseJSON
|
2017-04-24 20:07:08 +00:00
|
|
|
if (result && result.ocs && result.ocs.meta) {
|
2019-09-25 16:19:42 +00:00
|
|
|
msg = result.ocs.meta.message
|
2016-01-28 16:07:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (_.isFunction(options.error)) {
|
2019-09-25 16:19:42 +00:00
|
|
|
options.error(self, msg)
|
2016-01-28 16:07:51 +00:00
|
|
|
} else {
|
2019-09-25 16:19:42 +00:00
|
|
|
OC.dialogs.alert(msg, t('core', 'Error while sharing'))
|
2016-01-28 16:07:51 +00:00
|
|
|
}
|
2019-09-25 16:19:42 +00:00
|
|
|
})
|
2016-01-22 16:30:18 +00:00
|
|
|
},
|
2015-09-13 23:24:21 +00:00
|
|
|
|
2016-01-22 16:30:18 +00:00
|
|
|
/**
|
|
|
|
* Deletes the share with the given id
|
|
|
|
*
|
|
|
|
* @param {int} shareId share id
|
2019-09-25 16:19:42 +00:00
|
|
|
* @returns {jQuery}
|
2016-01-22 16:30:18 +00:00
|
|
|
*/
|
2016-01-28 16:07:51 +00:00
|
|
|
removeShare: function(shareId, options) {
|
2019-09-25 16:19:42 +00:00
|
|
|
var self = this
|
|
|
|
options = options || {}
|
2016-01-22 16:30:18 +00:00
|
|
|
return $.ajax({
|
|
|
|
type: 'DELETE',
|
2019-09-25 16:19:42 +00:00
|
|
|
url: this._getUrl('shares/' + encodeURIComponent(shareId))
|
2016-01-22 16:30:18 +00:00
|
|
|
}).done(function() {
|
2016-01-28 16:07:51 +00:00
|
|
|
self.fetch({
|
|
|
|
success: function() {
|
|
|
|
if (_.isFunction(options.success)) {
|
2019-09-25 16:19:42 +00:00
|
|
|
options.success(self)
|
2016-01-28 16:07:51 +00:00
|
|
|
}
|
|
|
|
}
|
2019-09-25 16:19:42 +00:00
|
|
|
})
|
2016-01-28 16:07:51 +00:00
|
|
|
}).fail(function(xhr) {
|
2019-09-25 16:19:42 +00:00
|
|
|
var msg = t('core', 'Error')
|
|
|
|
var result = xhr.responseJSON
|
2016-01-28 16:07:51 +00:00
|
|
|
if (result.ocs && result.ocs.meta) {
|
2019-09-25 16:19:42 +00:00
|
|
|
msg = result.ocs.meta.message
|
2016-01-28 16:07:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (_.isFunction(options.error)) {
|
2019-09-25 16:19:42 +00:00
|
|
|
options.error(self, msg)
|
2016-01-28 16:07:51 +00:00
|
|
|
} else {
|
2019-09-25 16:19:42 +00:00
|
|
|
OC.dialogs.alert(msg, t('core', 'Error removing share'))
|
2016-01-28 16:07:51 +00:00
|
|
|
}
|
2019-09-25 16:19:42 +00:00
|
|
|
})
|
2015-09-13 23:24:21 +00:00
|
|
|
},
|
|
|
|
|
2015-08-11 21:14:44 +00:00
|
|
|
/**
|
2015-08-13 00:38:14 +00:00
|
|
|
* @returns {boolean}
|
2015-08-11 21:14:44 +00:00
|
|
|
*/
|
2015-08-13 00:38:14 +00:00
|
|
|
isPublicUploadAllowed: function() {
|
2019-09-25 16:19:42 +00:00
|
|
|
return this.get('allowPublicUploadStatus')
|
2015-08-13 00:38:14 +00:00
|
|
|
},
|
|
|
|
|
2017-01-24 12:24:46 +00:00
|
|
|
isPublicEditingAllowed: function() {
|
2019-09-25 16:19:42 +00:00
|
|
|
return this.get('allowPublicEditingStatus')
|
2017-01-24 12:24:46 +00:00
|
|
|
},
|
|
|
|
|
2016-06-07 10:28:02 +00:00
|
|
|
/**
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
|
|
|
isHideFileListSet: function() {
|
2019-09-25 16:19:42 +00:00
|
|
|
return this.get('hideFileListStatus')
|
2016-06-07 10:28:02 +00:00
|
|
|
},
|
|
|
|
|
2015-08-13 00:38:14 +00:00
|
|
|
/**
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
|
|
|
isFolder: function() {
|
2019-09-25 16:19:42 +00:00
|
|
|
return this.get('itemType') === 'folder'
|
2015-08-13 00:38:14 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
|
|
|
isFile: function() {
|
2019-09-25 16:19:42 +00:00
|
|
|
return this.get('itemType') === 'file'
|
2015-08-11 21:14:44 +00:00
|
|
|
},
|
|
|
|
|
2015-08-11 12:10:25 +00:00
|
|
|
/**
|
|
|
|
* whether this item has reshare information
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
2015-07-30 22:07:41 +00:00
|
|
|
hasReshare: function() {
|
2019-09-25 16:19:42 +00:00
|
|
|
var reshare = this.get('reshare')
|
|
|
|
return _.isObject(reshare) && !_.isUndefined(reshare.uid_owner)
|
2015-07-30 22:07:41 +00:00
|
|
|
},
|
|
|
|
|
2015-08-11 20:36:28 +00:00
|
|
|
/**
|
2015-09-14 15:20:51 +00:00
|
|
|
* whether this item has user share information
|
2015-08-11 20:36:28 +00:00
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
2015-09-14 15:20:51 +00:00
|
|
|
hasUserShares: function() {
|
2019-09-25 16:19:42 +00:00
|
|
|
return this.getSharesWithCurrentItem().length > 0
|
2015-09-14 15:20:51 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2018-10-29 12:58:14 +00:00
|
|
|
* Returns whether this item has link shares
|
2015-09-14 15:20:51 +00:00
|
|
|
*
|
2019-09-25 16:19:42 +00:00
|
|
|
* @returns {bool} true if a link share exists, false otherwise
|
2015-09-14 15:20:51 +00:00
|
|
|
*/
|
2018-10-29 12:58:14 +00:00
|
|
|
hasLinkShares: function() {
|
2019-09-25 16:19:42 +00:00
|
|
|
var linkShares = this.get('linkShares')
|
2018-10-29 12:58:14 +00:00
|
|
|
if (linkShares && linkShares.length > 0) {
|
2019-09-25 16:19:42 +00:00
|
|
|
return true
|
2015-09-14 15:20:51 +00:00
|
|
|
}
|
2019-09-25 16:19:42 +00:00
|
|
|
return false
|
2015-08-11 20:36:28 +00:00
|
|
|
},
|
|
|
|
|
2015-08-11 12:10:25 +00:00
|
|
|
/**
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
2015-07-30 22:07:41 +00:00
|
|
|
getReshareOwner: function() {
|
2019-09-25 16:19:42 +00:00
|
|
|
return this.get('reshare').uid_owner
|
2015-07-30 22:07:41 +00:00
|
|
|
},
|
|
|
|
|
2015-08-11 12:10:25 +00:00
|
|
|
/**
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
2015-07-30 22:07:41 +00:00
|
|
|
getReshareOwnerDisplayname: function() {
|
2019-09-25 16:19:42 +00:00
|
|
|
return this.get('reshare').displayname_owner
|
2015-07-30 22:07:41 +00:00
|
|
|
},
|
|
|
|
|
2018-07-20 09:22:24 +00:00
|
|
|
/**
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
|
|
|
getReshareNote: function() {
|
2019-09-25 16:19:42 +00:00
|
|
|
return this.get('reshare').note
|
2018-07-20 09:22:24 +00:00
|
|
|
},
|
|
|
|
|
2015-08-11 12:10:25 +00:00
|
|
|
/**
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
2015-07-30 22:07:41 +00:00
|
|
|
getReshareWith: function() {
|
2019-09-25 16:19:42 +00:00
|
|
|
return this.get('reshare').share_with
|
2015-07-30 22:07:41 +00:00
|
|
|
},
|
|
|
|
|
2016-11-30 19:56:10 +00:00
|
|
|
/**
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
|
|
|
getReshareWithDisplayName: function() {
|
2019-09-25 16:19:42 +00:00
|
|
|
var reshare = this.get('reshare')
|
|
|
|
return reshare.share_with_displayname || reshare.share_with
|
2016-11-30 19:56:10 +00:00
|
|
|
},
|
|
|
|
|
2015-08-11 12:10:25 +00:00
|
|
|
/**
|
|
|
|
* @returns {number}
|
|
|
|
*/
|
2015-07-30 22:07:41 +00:00
|
|
|
getReshareType: function() {
|
2019-09-25 16:19:42 +00:00
|
|
|
return this.get('reshare').share_type
|
2015-07-30 22:07:41 +00:00
|
|
|
},
|
|
|
|
|
2017-03-29 14:50:23 +00:00
|
|
|
getExpireDate: function(shareIndex) {
|
2019-09-25 16:19:42 +00:00
|
|
|
return this._shareExpireDate(shareIndex)
|
2017-03-29 14:50:23 +00:00
|
|
|
},
|
|
|
|
|
2018-07-18 15:42:30 +00:00
|
|
|
getNote: function(shareIndex) {
|
2019-09-25 16:19:42 +00:00
|
|
|
return this._shareNote(shareIndex)
|
2018-07-18 15:42:30 +00:00
|
|
|
},
|
|
|
|
|
2015-09-23 10:44:25 +00:00
|
|
|
/**
|
|
|
|
* Returns all share entries that only apply to the current item
|
|
|
|
* (file/folder)
|
|
|
|
*
|
2019-09-25 16:19:42 +00:00
|
|
|
* @returns {Array.<OC.Share.Types.ShareInfo>}
|
2015-09-23 10:44:25 +00:00
|
|
|
*/
|
|
|
|
getSharesWithCurrentItem: function() {
|
2019-09-25 16:19:42 +00:00
|
|
|
var shares = this.get('shares') || []
|
|
|
|
var fileId = this.fileInfoModel.get('id')
|
2015-09-23 10:44:25 +00:00
|
|
|
return _.filter(shares, function(share) {
|
2019-09-25 16:19:42 +00:00
|
|
|
return share.item_source === fileId
|
|
|
|
})
|
2015-09-23 10:44:25 +00:00
|
|
|
},
|
|
|
|
|
2015-09-01 10:43:04 +00:00
|
|
|
/**
|
|
|
|
* @param shareIndex
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
|
|
|
getShareWith: function(shareIndex) {
|
|
|
|
/** @type OC.Share.Types.ShareInfo **/
|
2019-09-25 16:19:42 +00:00
|
|
|
var share = this.get('shares')[shareIndex]
|
|
|
|
if (!_.isObject(share)) {
|
|
|
|
throw 'Unknown Share'
|
2015-09-01 10:43:04 +00:00
|
|
|
}
|
2019-09-25 16:19:42 +00:00
|
|
|
return share.share_with
|
2015-09-01 10:43:04 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param shareIndex
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
|
|
|
getShareWithDisplayName: function(shareIndex) {
|
|
|
|
/** @type OC.Share.Types.ShareInfo **/
|
2019-09-25 16:19:42 +00:00
|
|
|
var share = this.get('shares')[shareIndex]
|
|
|
|
if (!_.isObject(share)) {
|
|
|
|
throw 'Unknown Share'
|
2015-09-01 10:43:04 +00:00
|
|
|
}
|
2019-09-25 16:19:42 +00:00
|
|
|
return share.share_with_displayname
|
2015-09-01 10:43:04 +00:00
|
|
|
},
|
|
|
|
|
2017-06-06 11:21:42 +00:00
|
|
|
/**
|
|
|
|
* @param shareIndex
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
|
|
|
getShareWithAvatar: function(shareIndex) {
|
|
|
|
/** @type OC.Share.Types.ShareInfo **/
|
2019-09-25 16:19:42 +00:00
|
|
|
var share = this.get('shares')[shareIndex]
|
|
|
|
if (!_.isObject(share)) {
|
|
|
|
throw 'Unknown Share'
|
2017-06-06 11:21:42 +00:00
|
|
|
}
|
2019-09-25 16:19:42 +00:00
|
|
|
return share.share_with_avatar
|
2017-06-06 11:21:42 +00:00
|
|
|
},
|
|
|
|
|
2017-04-10 15:07:45 +00:00
|
|
|
/**
|
|
|
|
* @param shareIndex
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
|
|
|
getSharedBy: function(shareIndex) {
|
|
|
|
/** @type OC.Share.Types.ShareInfo **/
|
2019-09-25 16:19:42 +00:00
|
|
|
var share = this.get('shares')[shareIndex]
|
|
|
|
if (!_.isObject(share)) {
|
|
|
|
throw 'Unknown Share'
|
2017-04-10 15:07:45 +00:00
|
|
|
}
|
2019-09-25 16:19:42 +00:00
|
|
|
return share.uid_owner
|
2017-04-10 15:07:45 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param shareIndex
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
|
|
|
getSharedByDisplayName: function(shareIndex) {
|
|
|
|
/** @type OC.Share.Types.ShareInfo **/
|
2019-09-25 16:19:42 +00:00
|
|
|
var share = this.get('shares')[shareIndex]
|
|
|
|
if (!_.isObject(share)) {
|
|
|
|
throw 'Unknown Share'
|
2017-04-10 15:07:45 +00:00
|
|
|
}
|
2019-09-25 16:19:42 +00:00
|
|
|
return share.displayname_owner
|
2017-04-10 15:07:45 +00:00
|
|
|
},
|
|
|
|
|
2018-10-30 13:22:33 +00:00
|
|
|
/**
|
|
|
|
* @param shareIndex
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
|
|
|
getFileOwnerUid: function(shareIndex) {
|
|
|
|
/** @type OC.Share.Types.ShareInfo **/
|
2019-09-25 16:19:42 +00:00
|
|
|
var share = this.get('shares')[shareIndex]
|
|
|
|
if (!_.isObject(share)) {
|
|
|
|
throw 'Unknown Share'
|
2018-10-30 13:22:33 +00:00
|
|
|
}
|
2019-09-25 16:19:42 +00:00
|
|
|
return share.uid_file_owner
|
2018-10-30 13:22:33 +00:00
|
|
|
},
|
|
|
|
|
2016-11-29 11:51:37 +00:00
|
|
|
/**
|
|
|
|
* returns the array index of a sharee for a provided shareId
|
|
|
|
*
|
|
|
|
* @param shareId
|
|
|
|
* @returns {number}
|
|
|
|
*/
|
|
|
|
findShareWithIndex: function(shareId) {
|
2019-09-25 16:19:42 +00:00
|
|
|
var shares = this.get('shares')
|
|
|
|
if (!_.isArray(shares)) {
|
|
|
|
throw 'Unknown Share'
|
|
|
|
}
|
|
|
|
for (var i = 0; i < shares.length; i++) {
|
|
|
|
var shareWith = shares[i]
|
|
|
|
if (shareWith.id === shareId) {
|
|
|
|
return i
|
2016-11-29 11:51:37 +00:00
|
|
|
}
|
|
|
|
}
|
2019-09-25 16:19:42 +00:00
|
|
|
throw 'Unknown Sharee'
|
2016-11-29 11:51:37 +00:00
|
|
|
},
|
|
|
|
|
2015-09-01 10:43:04 +00:00
|
|
|
getShareType: function(shareIndex) {
|
|
|
|
/** @type OC.Share.Types.ShareInfo **/
|
2019-09-25 16:19:42 +00:00
|
|
|
var share = this.get('shares')[shareIndex]
|
|
|
|
if (!_.isObject(share)) {
|
|
|
|
throw 'Unknown Share'
|
2015-09-01 10:43:04 +00:00
|
|
|
}
|
2019-09-25 16:19:42 +00:00
|
|
|
return share.share_type
|
2015-09-01 10:43:04 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* whether a share from shares has the requested permission
|
|
|
|
*
|
|
|
|
* @param {number} shareIndex
|
|
|
|
* @param {number} permission
|
|
|
|
* @returns {boolean}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
_shareHasPermission: function(shareIndex, permission) {
|
|
|
|
/** @type OC.Share.Types.ShareInfo **/
|
2019-09-25 16:19:42 +00:00
|
|
|
var share = this.get('shares')[shareIndex]
|
|
|
|
if (!_.isObject(share)) {
|
|
|
|
throw 'Unknown Share'
|
2015-09-01 10:43:04 +00:00
|
|
|
}
|
2019-09-25 16:19:42 +00:00
|
|
|
return (share.permissions & permission) === permission
|
2015-09-01 10:43:04 +00:00
|
|
|
},
|
|
|
|
|
2017-03-29 14:50:23 +00:00
|
|
|
_shareExpireDate: function(shareIndex) {
|
2019-09-25 16:19:42 +00:00
|
|
|
var share = this.get('shares')[shareIndex]
|
|
|
|
if (!_.isObject(share)) {
|
|
|
|
throw 'Unknown Share'
|
2017-03-29 14:50:23 +00:00
|
|
|
}
|
2019-09-25 16:19:42 +00:00
|
|
|
var date2 = share.expiration
|
|
|
|
return date2
|
2017-03-29 14:50:23 +00:00
|
|
|
},
|
|
|
|
|
2018-07-18 15:42:30 +00:00
|
|
|
_shareNote: function(shareIndex) {
|
2019-09-25 16:19:42 +00:00
|
|
|
var share = this.get('shares')[shareIndex]
|
|
|
|
if (!_.isObject(share)) {
|
|
|
|
throw 'Unknown Share'
|
2018-07-18 15:42:30 +00:00
|
|
|
}
|
2019-09-25 16:19:42 +00:00
|
|
|
return share.note
|
2018-07-18 15:42:30 +00:00
|
|
|
},
|
|
|
|
|
2017-03-09 12:56:27 +00:00
|
|
|
/**
|
2019-09-25 16:19:42 +00:00
|
|
|
* @returns {int}
|
2017-03-09 12:56:27 +00:00
|
|
|
*/
|
|
|
|
getPermissions: function() {
|
2019-09-25 16:19:42 +00:00
|
|
|
return this.get('permissions')
|
2017-03-09 12:56:27 +00:00
|
|
|
},
|
|
|
|
|
2015-08-11 21:14:44 +00:00
|
|
|
/**
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
2015-09-01 10:43:04 +00:00
|
|
|
sharePermissionPossible: function() {
|
2019-09-25 16:19:42 +00:00
|
|
|
return (this.get('permissions') & OC.PERMISSION_SHARE) === OC.PERMISSION_SHARE
|
2015-08-13 00:38:14 +00:00
|
|
|
},
|
|
|
|
|
2015-09-01 10:43:04 +00:00
|
|
|
/**
|
|
|
|
* @param {number} shareIndex
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
|
|
|
hasSharePermission: function(shareIndex) {
|
2019-09-25 16:19:42 +00:00
|
|
|
return this._shareHasPermission(shareIndex, OC.PERMISSION_SHARE)
|
2015-09-01 10:43:04 +00:00
|
|
|
},
|
|
|
|
|
2015-08-13 00:38:14 +00:00
|
|
|
/**
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
2015-09-01 10:43:04 +00:00
|
|
|
createPermissionPossible: function() {
|
2019-09-25 16:19:42 +00:00
|
|
|
return (this.get('permissions') & OC.PERMISSION_CREATE) === OC.PERMISSION_CREATE
|
2015-08-11 21:14:44 +00:00
|
|
|
},
|
|
|
|
|
2015-09-01 10:43:04 +00:00
|
|
|
/**
|
|
|
|
* @param {number} shareIndex
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
|
|
|
hasCreatePermission: function(shareIndex) {
|
2019-09-25 16:19:42 +00:00
|
|
|
return this._shareHasPermission(shareIndex, OC.PERMISSION_CREATE)
|
2015-09-01 10:43:04 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
|
|
|
updatePermissionPossible: function() {
|
2019-09-25 16:19:42 +00:00
|
|
|
return (this.get('permissions') & OC.PERMISSION_UPDATE) === OC.PERMISSION_UPDATE
|
2015-09-01 10:43:04 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {number} shareIndex
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
|
|
|
hasUpdatePermission: function(shareIndex) {
|
2019-09-25 16:19:42 +00:00
|
|
|
return this._shareHasPermission(shareIndex, OC.PERMISSION_UPDATE)
|
2015-09-01 10:43:04 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
|
|
|
deletePermissionPossible: function() {
|
2019-09-25 16:19:42 +00:00
|
|
|
return (this.get('permissions') & OC.PERMISSION_DELETE) === OC.PERMISSION_DELETE
|
2015-09-01 10:43:04 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {number} shareIndex
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
|
|
|
hasDeletePermission: function(shareIndex) {
|
2019-09-25 16:19:42 +00:00
|
|
|
return this._shareHasPermission(shareIndex, OC.PERMISSION_DELETE)
|
2015-09-01 10:43:04 +00:00
|
|
|
},
|
|
|
|
|
2017-03-29 09:58:04 +00:00
|
|
|
hasReadPermission: function(shareIndex) {
|
2019-09-25 16:19:42 +00:00
|
|
|
return this._shareHasPermission(shareIndex, OC.PERMISSION_READ)
|
2017-03-29 09:58:04 +00:00
|
|
|
},
|
|
|
|
|
2015-09-01 10:43:04 +00:00
|
|
|
/**
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
|
|
|
editPermissionPossible: function() {
|
2019-09-25 16:19:42 +00:00
|
|
|
return this.createPermissionPossible()
|
2015-09-01 10:43:04 +00:00
|
|
|
|| this.updatePermissionPossible()
|
2019-09-25 16:19:42 +00:00
|
|
|
|| this.deletePermissionPossible()
|
2015-09-01 10:43:04 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2018-02-15 20:10:39 +00:00
|
|
|
* @returns {string}
|
|
|
|
* The state that the 'can edit' permission checkbox should have.
|
|
|
|
* Possible values:
|
|
|
|
* - empty string: no permission
|
|
|
|
* - 'checked': all applicable permissions
|
|
|
|
* - 'indeterminate': some but not all permissions
|
|
|
|
*/
|
|
|
|
editPermissionState: function(shareIndex) {
|
2019-09-25 16:19:42 +00:00
|
|
|
var hcp = this.hasCreatePermission(shareIndex)
|
|
|
|
var hup = this.hasUpdatePermission(shareIndex)
|
|
|
|
var hdp = this.hasDeletePermission(shareIndex)
|
2018-10-31 10:23:23 +00:00
|
|
|
if (this.isFile()) {
|
|
|
|
if (hcp || hup || hdp) {
|
2019-09-25 16:19:42 +00:00
|
|
|
return 'checked'
|
2018-10-31 10:23:23 +00:00
|
|
|
}
|
2019-09-25 16:19:42 +00:00
|
|
|
return ''
|
2018-10-31 10:23:23 +00:00
|
|
|
}
|
2018-02-15 20:10:39 +00:00
|
|
|
if (!hcp && !hup && !hdp) {
|
2019-09-25 16:19:42 +00:00
|
|
|
return ''
|
2018-02-15 20:10:39 +00:00
|
|
|
}
|
2019-09-25 16:19:42 +00:00
|
|
|
if ((this.createPermissionPossible() && !hcp)
|
2018-02-15 20:10:39 +00:00
|
|
|
|| (this.updatePermissionPossible() && !hup)
|
2019-09-25 16:19:42 +00:00
|
|
|
|| (this.deletePermissionPossible() && !hdp)) {
|
|
|
|
return 'indeterminate'
|
2018-02-15 20:10:39 +00:00
|
|
|
}
|
2019-09-25 16:19:42 +00:00
|
|
|
return 'checked'
|
2015-09-01 10:43:04 +00:00
|
|
|
},
|
|
|
|
|
2017-03-09 12:56:27 +00:00
|
|
|
/**
|
|
|
|
* @returns {int}
|
|
|
|
*/
|
2018-10-29 12:58:14 +00:00
|
|
|
linkSharePermissions: function(shareId) {
|
2019-09-25 16:19:42 +00:00
|
|
|
var linkShares = this.get('linkShares')
|
|
|
|
var shareIndex = _.findIndex(linkShares, function(share) { return share.id === shareId })
|
2018-10-29 12:58:14 +00:00
|
|
|
|
|
|
|
if (!this.hasLinkShares()) {
|
2019-09-25 16:19:42 +00:00
|
|
|
return -1
|
2018-10-29 12:58:14 +00:00
|
|
|
} else if (linkShares.length > 0 && shareIndex !== -1) {
|
2019-09-25 16:19:42 +00:00
|
|
|
return linkShares[shareIndex].permissions
|
2017-03-09 12:56:27 +00:00
|
|
|
}
|
2019-09-25 16:19:42 +00:00
|
|
|
return -1
|
2017-03-09 12:56:27 +00:00
|
|
|
},
|
|
|
|
|
2016-01-22 16:30:18 +00:00
|
|
|
_getUrl: function(base, params) {
|
2019-09-25 16:19:42 +00:00
|
|
|
params = _.extend({ format: 'json' }, params || {})
|
|
|
|
return OC.linkToOCS('apps/files_sharing/api/v1', 2) + base + '?' + OC.buildQueryString(params)
|
2016-01-22 16:30:18 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_fetchShares: function() {
|
2019-09-25 16:19:42 +00:00
|
|
|
var path = this.fileInfoModel.getFullPath()
|
2016-01-22 16:30:18 +00:00
|
|
|
return $.ajax({
|
|
|
|
type: 'GET',
|
2019-09-25 16:19:42 +00:00
|
|
|
url: this._getUrl('shares', { path: path, reshares: true })
|
|
|
|
})
|
2016-01-22 16:30:18 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_fetchReshare: function() {
|
|
|
|
// only fetch original share once
|
|
|
|
if (!this._reshareFetched) {
|
2019-09-25 16:19:42 +00:00
|
|
|
var path = this.fileInfoModel.getFullPath()
|
|
|
|
this._reshareFetched = true
|
2016-01-22 16:30:18 +00:00
|
|
|
return $.ajax({
|
|
|
|
type: 'GET',
|
2019-09-25 16:19:42 +00:00
|
|
|
url: this._getUrl('shares', { path: path, shared_with_me: true })
|
|
|
|
})
|
2016-01-22 16:30:18 +00:00
|
|
|
} else {
|
|
|
|
return $.Deferred().resolve([{
|
|
|
|
ocs: {
|
|
|
|
data: [this.get('reshare')]
|
|
|
|
}
|
2019-09-25 16:19:42 +00:00
|
|
|
}])
|
2016-01-22 16:30:18 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-07-13 13:46:02 +00:00
|
|
|
/**
|
|
|
|
* Group reshares into a single super share element.
|
|
|
|
* Does this by finding the most precise share and
|
|
|
|
* combines the permissions to be the most permissive.
|
|
|
|
*
|
|
|
|
* @param {Array} reshares
|
2019-09-25 16:19:42 +00:00
|
|
|
* @returns {Object} reshare
|
2016-07-13 13:46:02 +00:00
|
|
|
*/
|
|
|
|
_groupReshares: function(reshares) {
|
|
|
|
if (!reshares || !reshares.length) {
|
2019-09-25 16:19:42 +00:00
|
|
|
return false
|
2016-07-13 13:46:02 +00:00
|
|
|
}
|
|
|
|
|
2019-09-25 16:19:42 +00:00
|
|
|
var superShare = reshares.shift()
|
|
|
|
var combinedPermissions = superShare.permissions
|
2016-07-13 13:46:02 +00:00
|
|
|
_.each(reshares, function(reshare) {
|
|
|
|
// use share have higher priority than group share
|
|
|
|
if (reshare.share_type === OC.Share.SHARE_TYPE_USER && superShare.share_type === OC.Share.SHARE_TYPE_GROUP) {
|
2019-09-25 16:19:42 +00:00
|
|
|
superShare = reshare
|
2016-07-13 13:46:02 +00:00
|
|
|
}
|
2019-09-25 16:19:42 +00:00
|
|
|
combinedPermissions |= reshare.permissions
|
|
|
|
})
|
2016-07-13 13:46:02 +00:00
|
|
|
|
2019-09-25 16:19:42 +00:00
|
|
|
superShare.permissions = combinedPermissions
|
|
|
|
return superShare
|
2016-07-13 13:46:02 +00:00
|
|
|
},
|
|
|
|
|
2016-12-02 12:14:25 +00:00
|
|
|
fetch: function(options) {
|
2019-09-25 16:19:42 +00:00
|
|
|
var model = this
|
|
|
|
this.trigger('request', this)
|
2016-01-22 16:30:18 +00:00
|
|
|
|
|
|
|
var deferred = $.when(
|
|
|
|
this._fetchShares(),
|
|
|
|
this._fetchReshare()
|
2019-09-25 16:19:42 +00:00
|
|
|
)
|
2016-01-22 16:30:18 +00:00
|
|
|
deferred.done(function(data1, data2) {
|
2019-09-25 16:19:42 +00:00
|
|
|
model.trigger('sync', 'GET', this)
|
|
|
|
var sharesMap = {}
|
2016-01-22 16:30:18 +00:00
|
|
|
_.each(data1[0].ocs.data, function(shareItem) {
|
2019-09-25 16:19:42 +00:00
|
|
|
sharesMap[shareItem.id] = shareItem
|
|
|
|
})
|
2016-01-22 16:30:18 +00:00
|
|
|
|
2019-09-25 16:19:42 +00:00
|
|
|
var reshare = false
|
2016-01-22 16:30:18 +00:00
|
|
|
if (data2[0].ocs.data.length) {
|
2019-09-25 16:19:42 +00:00
|
|
|
reshare = model._groupReshares(data2[0].ocs.data)
|
2016-01-22 16:30:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
model.set(model.parse({
|
|
|
|
shares: sharesMap,
|
|
|
|
reshare: reshare
|
2019-09-25 16:19:42 +00:00
|
|
|
}))
|
2016-12-02 12:14:25 +00:00
|
|
|
|
2019-09-25 16:19:42 +00:00
|
|
|
if (!_.isUndefined(options) && _.isFunction(options.success)) {
|
|
|
|
options.success()
|
2016-12-02 12:14:25 +00:00
|
|
|
}
|
2019-09-25 16:19:42 +00:00
|
|
|
})
|
2016-01-22 16:30:18 +00:00
|
|
|
|
2019-09-25 16:19:42 +00:00
|
|
|
return deferred
|
2015-08-11 12:10:25 +00:00
|
|
|
},
|
|
|
|
|
2015-09-14 15:20:51 +00:00
|
|
|
/**
|
|
|
|
* Updates OC.Share.itemShares and OC.Share.statuses.
|
|
|
|
*
|
|
|
|
* This is required in case the user navigates away and comes back,
|
|
|
|
* the share statuses from the old arrays are still used to fill in the icons
|
|
|
|
* in the file list.
|
|
|
|
*/
|
|
|
|
_legacyFillCurrentShares: function(shares) {
|
2019-09-25 16:19:42 +00:00
|
|
|
var fileId = this.fileInfoModel.get('id')
|
2015-09-14 15:20:51 +00:00
|
|
|
if (!shares || !shares.length) {
|
2019-09-25 16:19:42 +00:00
|
|
|
delete OC.Share.statuses[fileId]
|
|
|
|
OC.Share.currentShares = {}
|
|
|
|
OC.Share.itemShares = []
|
|
|
|
return
|
2015-09-14 15:20:51 +00:00
|
|
|
}
|
|
|
|
|
2019-09-25 16:19:42 +00:00
|
|
|
var currentShareStatus = OC.Share.statuses[fileId]
|
2015-09-14 15:20:51 +00:00
|
|
|
if (!currentShareStatus) {
|
2019-09-25 16:19:42 +00:00
|
|
|
currentShareStatus = { link: false }
|
|
|
|
OC.Share.statuses[fileId] = currentShareStatus
|
2015-09-14 15:20:51 +00:00
|
|
|
}
|
2019-09-25 16:19:42 +00:00
|
|
|
currentShareStatus.link = false
|
2015-09-14 15:20:51 +00:00
|
|
|
|
2019-09-25 16:19:42 +00:00
|
|
|
OC.Share.currentShares = {}
|
|
|
|
OC.Share.itemShares = []
|
2015-09-02 14:47:25 +00:00
|
|
|
_.each(shares,
|
|
|
|
/**
|
|
|
|
* @param {OC.Share.Types.ShareInfo} share
|
|
|
|
*/
|
|
|
|
function(share) {
|
2015-09-14 15:20:51 +00:00
|
|
|
if (share.share_type === OC.Share.SHARE_TYPE_LINK) {
|
2019-09-25 16:19:42 +00:00
|
|
|
OC.Share.itemShares[share.share_type] = true
|
|
|
|
currentShareStatus.link = true
|
2015-09-14 15:20:51 +00:00
|
|
|
} else {
|
|
|
|
if (!OC.Share.itemShares[share.share_type]) {
|
2019-09-25 16:19:42 +00:00
|
|
|
OC.Share.itemShares[share.share_type] = []
|
2015-09-14 15:20:51 +00:00
|
|
|
}
|
2019-09-25 16:19:42 +00:00
|
|
|
OC.Share.itemShares[share.share_type].push(share.share_with)
|
2015-09-02 14:47:25 +00:00
|
|
|
}
|
|
|
|
}
|
2019-09-25 16:19:42 +00:00
|
|
|
)
|
2015-09-02 14:47:25 +00:00
|
|
|
},
|
|
|
|
|
2015-08-11 12:10:25 +00:00
|
|
|
parse: function(data) {
|
2019-09-25 16:19:42 +00:00
|
|
|
if (data === false) {
|
|
|
|
console.warn('no data was returned')
|
|
|
|
this.trigger('fetchError')
|
|
|
|
return {}
|
2015-07-30 22:07:41 +00:00
|
|
|
}
|
2015-08-11 21:14:44 +00:00
|
|
|
|
2019-09-25 16:19:42 +00:00
|
|
|
var permissions = this.fileInfoModel.get('permissions')
|
|
|
|
if (!_.isUndefined(data.reshare) && !_.isUndefined(data.reshare.permissions) && data.reshare.uid_owner !== OC.currentUser) {
|
|
|
|
permissions = permissions & data.reshare.permissions
|
2015-08-11 21:14:44 +00:00
|
|
|
}
|
|
|
|
|
2019-09-25 16:19:42 +00:00
|
|
|
var allowPublicUploadStatus = false
|
|
|
|
if (!_.isUndefined(data.shares)) {
|
|
|
|
$.each(data.shares, function(key, value) {
|
2015-08-11 21:14:44 +00:00
|
|
|
if (value.share_type === OC.Share.SHARE_TYPE_LINK) {
|
2019-09-25 16:19:42 +00:00
|
|
|
allowPublicUploadStatus = !!((value.permissions & OC.PERMISSION_CREATE))
|
|
|
|
return true
|
2015-08-11 21:14:44 +00:00
|
|
|
}
|
2019-09-25 16:19:42 +00:00
|
|
|
})
|
2015-08-11 21:14:44 +00:00
|
|
|
}
|
|
|
|
|
2019-09-25 16:19:42 +00:00
|
|
|
var allowPublicEditingStatus = true
|
|
|
|
if (!_.isUndefined(data.shares)) {
|
|
|
|
$.each(data.shares, function(key, value) {
|
2017-01-24 12:24:46 +00:00
|
|
|
if (value.share_type === OC.Share.SHARE_TYPE_LINK) {
|
2019-09-25 16:19:42 +00:00
|
|
|
allowPublicEditingStatus = !!((value.permissions & OC.PERMISSION_UPDATE))
|
|
|
|
return true
|
2017-01-24 12:24:46 +00:00
|
|
|
}
|
2019-09-25 16:19:42 +00:00
|
|
|
})
|
2017-01-24 12:24:46 +00:00
|
|
|
}
|
|
|
|
|
2019-09-25 16:19:42 +00:00
|
|
|
var hideFileListStatus = false
|
|
|
|
if (!_.isUndefined(data.shares)) {
|
|
|
|
$.each(data.shares, function(key, value) {
|
2016-06-07 10:28:02 +00:00
|
|
|
if (value.share_type === OC.Share.SHARE_TYPE_LINK) {
|
2019-09-25 16:19:42 +00:00
|
|
|
hideFileListStatus = !((value.permissions & OC.PERMISSION_READ))
|
|
|
|
return true
|
2016-06-07 10:28:02 +00:00
|
|
|
}
|
2019-09-25 16:19:42 +00:00
|
|
|
})
|
2016-06-07 10:28:02 +00:00
|
|
|
}
|
|
|
|
|
2015-09-03 13:53:17 +00:00
|
|
|
/** @type {OC.Share.Types.ShareInfo[]} **/
|
2015-09-23 10:14:09 +00:00
|
|
|
var shares = _.map(data.shares, function(share) {
|
|
|
|
// properly parse some values because sometimes the server
|
|
|
|
// returns integers as string...
|
2019-09-25 16:19:42 +00:00
|
|
|
var i
|
2015-09-23 10:14:09 +00:00
|
|
|
for (i = 0; i < SHARE_RESPONSE_INT_PROPS.length; i++) {
|
2019-09-25 16:19:42 +00:00
|
|
|
var prop = SHARE_RESPONSE_INT_PROPS[i]
|
2015-09-23 10:14:09 +00:00
|
|
|
if (!_.isUndefined(share[prop])) {
|
2019-09-25 16:19:42 +00:00
|
|
|
share[prop] = parseInt(share[prop], 10)
|
2015-09-23 10:14:09 +00:00
|
|
|
}
|
|
|
|
}
|
2019-09-25 16:19:42 +00:00
|
|
|
return share
|
|
|
|
})
|
2015-09-23 10:14:09 +00:00
|
|
|
|
2019-09-25 16:19:42 +00:00
|
|
|
this._legacyFillCurrentShares(shares)
|
2015-09-02 14:47:25 +00:00
|
|
|
|
2019-09-25 16:19:42 +00:00
|
|
|
var linkShares = []
|
2015-09-03 13:53:17 +00:00
|
|
|
// filter out the share by link
|
|
|
|
shares = _.reject(shares,
|
|
|
|
/**
|
|
|
|
* @param {OC.Share.Types.ShareInfo} share
|
|
|
|
*/
|
|
|
|
function(share) {
|
2019-09-25 16:19:42 +00:00
|
|
|
var isShareLink
|
|
|
|
= share.share_type === OC.Share.SHARE_TYPE_LINK
|
|
|
|
&& (share.file_source === this.get('itemSource')
|
|
|
|
|| share.item_source === this.get('itemSource'))
|
2015-09-03 13:53:17 +00:00
|
|
|
|
|
|
|
if (isShareLink) {
|
2018-10-29 12:58:14 +00:00
|
|
|
/**
|
2016-02-10 15:00:55 +00:00
|
|
|
* Ignore reshared link shares for now
|
|
|
|
* FIXME: Find a way to display properly
|
|
|
|
*/
|
|
|
|
if (share.uid_owner !== OC.currentUser) {
|
2019-09-25 16:19:42 +00:00
|
|
|
return
|
2016-02-10 15:00:55 +00:00
|
|
|
}
|
|
|
|
|
2019-09-25 16:19:42 +00:00
|
|
|
var link = window.location.protocol + '//' + window.location.host
|
2015-09-03 13:53:17 +00:00
|
|
|
if (!share.token) {
|
|
|
|
// pre-token link
|
2019-09-25 16:19:42 +00:00
|
|
|
var fullPath = this.fileInfoModel.get('path') + '/'
|
|
|
|
+ this.fileInfoModel.get('name')
|
|
|
|
var location = '/' + OC.currentUser + '/files' + fullPath
|
|
|
|
var type = this.fileInfoModel.isDirectory() ? 'folder' : 'file'
|
|
|
|
link += OC.linkTo('', 'public.php') + '?service=files&'
|
|
|
|
+ type + '=' + encodeURIComponent(location)
|
2015-09-03 13:53:17 +00:00
|
|
|
} else {
|
2019-09-25 16:19:42 +00:00
|
|
|
link += OC.generateUrl('/s/') + share.token
|
2015-09-03 13:53:17 +00:00
|
|
|
}
|
2018-10-29 12:58:14 +00:00
|
|
|
linkShares.push(_.extend({}, share, {
|
2018-10-22 09:06:53 +00:00
|
|
|
// hide_download is returned as an int, so force it
|
|
|
|
// to a boolean
|
|
|
|
hideDownload: !!share.hide_download,
|
2018-10-15 15:09:46 +00:00
|
|
|
password: share.share_with,
|
|
|
|
sendPasswordByTalk: share.send_password_by_talk
|
2019-09-25 16:19:42 +00:00
|
|
|
}))
|
2015-09-03 13:53:17 +00:00
|
|
|
|
2019-09-25 16:19:42 +00:00
|
|
|
return share
|
2015-09-03 13:53:17 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
this
|
2019-09-25 16:19:42 +00:00
|
|
|
)
|
2015-09-03 13:53:17 +00:00
|
|
|
|
2015-08-24 21:37:04 +00:00
|
|
|
return {
|
2015-08-10 20:23:52 +00:00
|
|
|
reshare: data.reshare,
|
2015-09-02 14:47:25 +00:00
|
|
|
shares: shares,
|
2018-10-29 12:58:14 +00:00
|
|
|
linkShares: linkShares,
|
2015-08-11 21:14:44 +00:00
|
|
|
permissions: permissions,
|
2016-06-07 10:28:02 +00:00
|
|
|
allowPublicUploadStatus: allowPublicUploadStatus,
|
2017-01-24 12:24:46 +00:00
|
|
|
allowPublicEditingStatus: allowPublicEditingStatus,
|
2016-06-07 10:28:02 +00:00
|
|
|
hideFileListStatus: hideFileListStatus
|
2019-09-25 16:19:42 +00:00
|
|
|
}
|
2015-09-15 13:47:45 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Parses a string to an valid integer (unix timestamp)
|
|
|
|
* @param time
|
|
|
|
* @returns {*}
|
|
|
|
* @internal Only used to work around a bug in the backend
|
|
|
|
*/
|
|
|
|
_parseTime: function(time) {
|
|
|
|
if (_.isString(time)) {
|
|
|
|
// skip empty strings and hex values
|
|
|
|
if (time === '' || (time.length > 1 && time[0] === '0' && time[1] === 'x')) {
|
2019-09-25 16:19:42 +00:00
|
|
|
return null
|
2015-09-15 13:47:45 +00:00
|
|
|
}
|
2019-09-25 16:19:42 +00:00
|
|
|
time = parseInt(time, 10)
|
|
|
|
if (isNaN(time)) {
|
|
|
|
time = null
|
2015-09-15 13:47:45 +00:00
|
|
|
}
|
|
|
|
}
|
2019-09-25 16:19:42 +00:00
|
|
|
return time
|
2016-08-17 10:25:58 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a list of share types from the existing shares.
|
|
|
|
*
|
2019-09-25 16:19:42 +00:00
|
|
|
* @returns {Array.<int>} array of share types
|
2016-08-17 10:25:58 +00:00
|
|
|
*/
|
|
|
|
getShareTypes: function() {
|
2019-09-25 16:19:42 +00:00
|
|
|
var result
|
|
|
|
result = _.pluck(this.getSharesWithCurrentItem(), 'share_type')
|
2018-10-29 12:58:14 +00:00
|
|
|
if (this.hasLinkShares()) {
|
2019-09-25 16:19:42 +00:00
|
|
|
result.push(OC.Share.SHARE_TYPE_LINK)
|
2016-08-17 10:25:58 +00:00
|
|
|
}
|
2019-09-25 16:19:42 +00:00
|
|
|
return _.uniq(result)
|
2015-07-30 22:07:41 +00:00
|
|
|
}
|
2019-09-25 16:19:42 +00:00
|
|
|
})
|
2015-07-30 22:07:41 +00:00
|
|
|
|
2019-09-25 16:19:42 +00:00
|
|
|
OC.Share.ShareItemModel = ShareItemModel
|
|
|
|
})()
|