Skip to content

Commit

Permalink
improve reshare rendering part and move permission calculation to model
Browse files Browse the repository at this point in the history
  • Loading branch information
blizzz committed Aug 11, 2015
1 parent 727ae9e commit 9b7ab23
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 39 deletions.
7 changes: 4 additions & 3 deletions core/js/share.js
Original file line number Diff line number Diff line change
Expand Up @@ -382,18 +382,19 @@ OC.Share = _.extend(OC.Share, {
});
},
showDropDown:function(itemType, itemSource, appendTo, link, possiblePermissions, filename) {
var attributes = {itemType: itemType, itemSource: itemSource};
var attributes = {itemType: itemType, itemSource: itemSource, possiblePermissions: possiblePermissions};
var itemModel = new OC.Share.ShareItemModel(attributes);
var dialogView = new OC.Share.ShareDialogView({
id: 'dropdown',
model: itemModel,
className: 'drop shareDropDown',
attributes: {
'data-item-source-name': filename
'data-item-source-name': filename,
'data-item-type': itemType,
'data-item-soruce': itemSource
}
});
dialogView.setShowLink(link);
dialogView.setPossiblePermissions(possiblePermissions);
var $dialog = dialogView.render().$el;
$dialog.appendTo(appendTo);
$dialog.slideDown(OC.menuSpeed, function() {
Expand Down
62 changes: 27 additions & 35 deletions core/js/sharedialogview.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,6 @@
/** @type {boolean} **/
_showLink: true,

/** @type {unknown} **/
_possiblePermissions: null,

/** @type {string} **/
tagName: 'div',

Expand All @@ -91,7 +88,6 @@
var baseTemplate = this._getTemplate('base', TEMPLATE_BASE);

this.$el.html(baseTemplate({

shareLabel: t('core', 'Share'),
resharerInfo: this._renderResharerInfo(),
sharePlaceholder: this._renderSharePlaceholderPart(),
Expand All @@ -112,41 +108,37 @@
this._showLink = (typeof showLink === 'boolean') ? showLink : true;
},

setPossiblePermissions: function(permissions) {
//TODO: maybe move to model? Whatever this is.
this._possiblePermissions = permissions;
},

_renderResharerInfo: function() {
var resharerInfo = '';
if ( this.model.hasReshare()
&& this.model.getReshareOwner() !== OC.currentUser)
if ( !this.model.hasReshare()
|| !this.model.getReshareOwner() !== OC.currentUser)
{
var reshareTemplate = this._getReshareTemplate();
var sharedByText = '';
if (this.model.getReshareType() === OC.Share.SHARE_TYPE_GROUP) {
sharedByText = t(
'core',
'Shared with you and the group {group} by {owner}',
{
group: this.model.getReshareWith(),
owner: this.model.getReshareOwnerDisplayname()
}
);
} else {
sharedByText = t(
'core',
'Shared with you by {owner}',
{ owner: this.model.getReshareOwnerDisplayname() }
);
}


resharerInfo = reshareTemplate({
avatarEnabled: oc_config.enable_avatars === true,
sharedByText: sharedByText
});
return '';
}

var reshareTemplate = this._getReshareTemplate();
var sharedByText = '';
if (this.model.getReshareType() === OC.Share.SHARE_TYPE_GROUP) {
sharedByText = t(
'core',
'Shared with you and the group {group} by {owner}',
{
group: this.model.getReshareWith(),
owner: this.model.getReshareOwnerDisplayname()
}
);
} else {
sharedByText = t(
'core',
'Shared with you by {owner}',
{ owner: this.model.getReshareOwnerDisplayname() }
);
}

return reshareTemplate({
avatarEnabled: oc_config.enable_avatars === true,
sharedByText: sharedByText
});
},

_renderRemoteShareInfoPart: function() {
Expand Down
57 changes: 56 additions & 1 deletion core/js/shareitemmodel.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,22 @@
this.fetch();
},

defaults: {
allowPublicUploadStatus: false
},

/**
* @returns {boolean|jQuery}
*/
isPublicUploadEnabled: function() {
// FIXME: this really needs a better place
var publicUploadEnabled = $('#filestable').data('allow-public-upload');
if (_.isUndefined(publicUploadEnabled)) {
publicUploadEnabled = 'no';
}
return publicUploadEnabled;
},

/**
* whether this item has reshare information
* @returns {boolean}
Expand Down Expand Up @@ -101,6 +117,26 @@
return this.get('reshare').share_type;
},

/**
* @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() {
return (this.getPermissions & OC.PERMISSION_SHARE) === OC.PERMISSION_SHARE;
},

fetch: function() {
var model = this;
OC.Share.loadItem(this.get('itemType'), this.get('itemSource'), function(data) {
Expand All @@ -114,10 +150,29 @@
trigger('fetchError');
return {};
}

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;
}
});
}

var attributes = {
reshare: data.reshare,
shares: data.shares
shares: data.shares,
permissions: permissions,
allowPublicUploadStatus: allowPublicUploadStatus
};

return attributes;
}
});
Expand Down

0 comments on commit 9b7ab23

Please sign in to comment.