Group incoming shares for resharing in JS
This commit is contained in:
parent
2ab799f674
commit
bee0a8f32a
|
@ -598,6 +598,33 @@
|
|||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 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
|
||||
* @return {Object} reshare
|
||||
*/
|
||||
_groupReshares: function(reshares) {
|
||||
if (!reshares || !reshares.length) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var superShare = reshares.shift();
|
||||
var combinedPermissions = superShare.permissions;
|
||||
_.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) {
|
||||
superShare = reshare;
|
||||
}
|
||||
combinedPermissions |= reshare.permissions;
|
||||
});
|
||||
|
||||
superShare.permissions = combinedPermissions;
|
||||
return superShare;
|
||||
},
|
||||
|
||||
fetch: function() {
|
||||
var model = this;
|
||||
this.trigger('request', this);
|
||||
|
@ -615,7 +642,7 @@
|
|||
|
||||
var reshare = false;
|
||||
if (data2[0].ocs.data.length) {
|
||||
reshare = data2[0].ocs.data[0];
|
||||
reshare = model._groupReshares(data2[0].ocs.data);
|
||||
}
|
||||
|
||||
model.set(model.parse({
|
||||
|
|
|
@ -181,6 +181,48 @@ describe('OC.Share.ShareItemModel', function() {
|
|||
|
||||
// TODO: check more attributes
|
||||
});
|
||||
it('groups reshare info into a single item', function() {
|
||||
/* jshint camelcase: false */
|
||||
fetchReshareDeferred.resolve(makeOcsResponse([
|
||||
{
|
||||
id: '1',
|
||||
share_type: OC.Share.SHARE_TYPE_USER,
|
||||
uid_owner: 'owner',
|
||||
displayname_owner: 'Owner',
|
||||
share_with: 'root',
|
||||
permissions: 1
|
||||
},
|
||||
{
|
||||
id: '2',
|
||||
share_type: OC.Share.SHARE_TYPE_GROUP,
|
||||
uid_owner: 'owner',
|
||||
displayname_owner: 'Owner',
|
||||
share_with: 'group1',
|
||||
permissions: 15
|
||||
},
|
||||
{
|
||||
id: '3',
|
||||
share_type: OC.Share.SHARE_TYPE_GROUP,
|
||||
uid_owner: 'owner',
|
||||
displayname_owner: 'Owner',
|
||||
share_with: 'group1',
|
||||
permissions: 17
|
||||
}
|
||||
]));
|
||||
fetchSharesDeferred.resolve(makeOcsResponse([]));
|
||||
|
||||
OC.currentUser = 'root';
|
||||
|
||||
model.fetch();
|
||||
|
||||
var reshare = model.get('reshare');
|
||||
// max permissions
|
||||
expect(reshare.permissions).toEqual(31);
|
||||
// user share has higher priority
|
||||
expect(reshare.share_type).toEqual(OC.Share.SHARE_TYPE_USER);
|
||||
expect(reshare.share_with).toEqual('root');
|
||||
expect(reshare.id).toEqual('1');
|
||||
});
|
||||
it('does not parse link share when for a different file', function() {
|
||||
/* jshint camelcase: false */
|
||||
fetchReshareDeferred.resolve(makeOcsResponse([]));
|
||||
|
|
Loading…
Reference in New Issue