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() {
|
|
|
|
if(!OC.Share) {
|
|
|
|
OC.Share = {};
|
|
|
|
OC.Share.Types = {};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @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
|
|
|
|
* @property {string} share_mail_send
|
|
|
|
* @property {bool} collection //TODO: verify
|
|
|
|
* @property {Date} expiration optional?
|
|
|
|
* @property {number} stime optional?
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @typedef {object} OC.Share.Types.ShareItemInfo
|
|
|
|
* @property {OC.Share.Types.Reshare} reshare
|
|
|
|
* @property {OC.Share.Types.ShareInfo[]} shares
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @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-07-30 22:07:41 +00:00
|
|
|
*/
|
2015-08-10 20:23:52 +00:00
|
|
|
var ShareItemModel = OC.Backbone.Model.extend({
|
2015-08-13 00:38:14 +00:00
|
|
|
initialize: function(attributes, options) {
|
|
|
|
if(!_.isUndefined(options.configModel)) {
|
|
|
|
this.configModel = options.configModel;
|
|
|
|
}
|
2015-08-11 12:10:25 +00:00
|
|
|
this.fetch();
|
2015-07-30 22:07:41 +00:00
|
|
|
},
|
|
|
|
|
2015-08-11 21:14:44 +00:00
|
|
|
defaults: {
|
|
|
|
allowPublicUploadStatus: false
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
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() {
|
|
|
|
return this.get('allowPublicUploadStatus');
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
|
|
|
isFolder: function() {
|
|
|
|
return this.get('itemType') === 'folder';
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
|
|
|
isFile: function() {
|
|
|
|
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() {
|
2015-08-21 13:00:15 +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
|
|
|
/**
|
|
|
|
* whether this item has reshare information
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
|
|
|
hasShares: function() {
|
|
|
|
return _.isObject(this.get('shares'));
|
|
|
|
},
|
|
|
|
|
2015-08-11 12:10:25 +00:00
|
|
|
/**
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
2015-07-30 22:07:41 +00:00
|
|
|
getReshareOwner: function() {
|
2015-08-10 20:23:52 +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() {
|
2015-08-18 22:04:16 +00:00
|
|
|
return 'foo';
|
2015-08-10 20:23:52 +00:00
|
|
|
return this.get('reshare').displayname_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
|
|
|
getReshareWith: function() {
|
2015-08-10 20:23:52 +00:00
|
|
|
return this.get('reshare').share_with;
|
2015-07-30 22:07:41 +00:00
|
|
|
},
|
|
|
|
|
2015-08-11 12:10:25 +00:00
|
|
|
/**
|
|
|
|
* @returns {number}
|
|
|
|
*/
|
2015-07-30 22:07:41 +00:00
|
|
|
getReshareType: function() {
|
2015-08-10 20:23:52 +00:00
|
|
|
return this.get('reshare').share_type;
|
2015-07-30 22:07:41 +00:00
|
|
|
},
|
|
|
|
|
2015-08-11 21:14:44 +00:00
|
|
|
/**
|
|
|
|
* @returns {number}
|
|
|
|
*/
|
|
|
|
getPermissions: function() {
|
|
|
|
var permissions = this.get('permissions');
|
|
|
|
if(_.isUndefined(permissions)) {
|
|
|
|
// model was not properly initialized
|
|
|
|
console.warn('Sharing error: undefined permissions');
|
|
|
|
permissions = 0;
|
|
|
|
}
|
|
|
|
return permissions;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
|
|
|
hasSharePermission: function() {
|
2015-08-13 00:38:14 +00:00
|
|
|
return (this.getPermissions() & OC.PERMISSION_SHARE) === OC.PERMISSION_SHARE;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
|
|
|
hasCreatePermission: function() {
|
|
|
|
return (this.getPermissions() & OC.PERMISSION_CREATE) === OC.PERMISSION_CREATE;
|
2015-08-11 21:14:44 +00:00
|
|
|
},
|
|
|
|
|
2015-08-11 12:10:25 +00:00
|
|
|
fetch: function() {
|
2015-08-11 20:36:28 +00:00
|
|
|
var model = this;
|
|
|
|
OC.Share.loadItem(this.get('itemType'), this.get('itemSource'), function(data) {
|
|
|
|
model.set(model.parse(data));
|
|
|
|
});
|
2015-08-11 12:10:25 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
parse: function(data) {
|
2015-07-30 22:07:41 +00:00
|
|
|
if(data === false) {
|
|
|
|
console.warn('no data was returned');
|
2015-08-11 20:36:28 +00:00
|
|
|
trigger('fetchError');
|
2015-08-11 12:10:25 +00:00
|
|
|
return {};
|
2015-07-30 22:07:41 +00:00
|
|
|
}
|
2015-08-11 21:14:44 +00:00
|
|
|
|
|
|
|
var permissions = this.get('possiblePermissions');
|
|
|
|
if(!_.isUndefined(data.reshare) && !_.isUndefined(data.reshare.permissions)) {
|
|
|
|
permissions = permissions & data.reshare.permissions;
|
|
|
|
}
|
|
|
|
|
|
|
|
var allowPublicUploadStatus = false;
|
|
|
|
if(!_.isUndefined(data.shares)) {
|
|
|
|
$.each(data.shares, function (key, value) {
|
|
|
|
if (value.share_type === OC.Share.SHARE_TYPE_LINK) {
|
|
|
|
allowPublicUploadStatus = (value.permissions & OC.PERMISSION_CREATE) ? true : false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-08-10 20:23:52 +00:00
|
|
|
var attributes = {
|
|
|
|
reshare: data.reshare,
|
2015-08-11 21:14:44 +00:00
|
|
|
shares: data.shares,
|
|
|
|
permissions: permissions,
|
|
|
|
allowPublicUploadStatus: allowPublicUploadStatus
|
2015-08-10 20:23:52 +00:00
|
|
|
};
|
2015-08-11 21:14:44 +00:00
|
|
|
|
2015-08-11 12:10:25 +00:00
|
|
|
return attributes;
|
2015-07-30 22:07:41 +00:00
|
|
|
}
|
2015-08-10 20:23:52 +00:00
|
|
|
});
|
2015-07-30 22:07:41 +00:00
|
|
|
|
|
|
|
OC.Share.ShareItemModel = ShareItemModel;
|
|
|
|
})();
|