diff options
author | Vincent Petry <pvince81@owncloud.com> | 2016-07-26 12:57:05 +0300 |
---|---|---|
committer | Thomas Müller <DeepDiver1975@users.noreply.github.com> | 2016-07-26 12:57:05 +0300 |
commit | 56ee571dc31acf57db0bc5361bdc49ded5c41608 (patch) | |
tree | e65f540951f62b849016b58b3b29750041c5c90d /core | |
parent | 2bf6f54366c4e2e0eb966881bea2075787a7a5d1 (diff) |
[stable9.1] Group shares with same source and target (#25534)
* Group shares with same source and target
Fixes #24575
Note that this is a very limited solution and eventually we want smarter
merging!
* Add integration tests for merging received shares
* Improved share grouping readability + fixed test
* Add repair step for unmerged shares (WIP)
* Added more tests for sharing's MountProvider
* Group incoming shares for resharing in JS
* Adjust repair version check for unmerged shares
* Fix RepairUnmergedShares to not skip valid repair cases
The repair step was a bit overeager to skip repairing so it missed the
case where a group share exists without subshares but with an
additional direct user share.
* Add integration tests for double shares with rename in between
* Make share target consistent when grouping group share with user share
In some situations, a group share is created before a user share, and
the recipient renamed the received share before the latter is created.
In this situation, the "file_target" was already modified and the second
created share must align to the already renamed share.
To achieve this, the MountProvider now groups only by "item_source"
value and sorts by share time. This makes it so that the least recent
share is selected as super-share and its "file_target" value is then
adjusted in all grouped shares.
This fixes the issue where this situation would have different
"file_target" values resulting in two shared folders appearing instead
of one.
Diffstat (limited to 'core')
-rw-r--r-- | core/js/shareitemmodel.js | 29 | ||||
-rw-r--r-- | core/js/tests/specs/shareitemmodelSpec.js | 42 |
2 files changed, 70 insertions, 1 deletions
diff --git a/core/js/shareitemmodel.js b/core/js/shareitemmodel.js index 3ced66a1a78..78763ad033a 100644 --- a/core/js/shareitemmodel.js +++ b/core/js/shareitemmodel.js @@ -591,6 +591,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); @@ -608,7 +635,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({ diff --git a/core/js/tests/specs/shareitemmodelSpec.js b/core/js/tests/specs/shareitemmodelSpec.js index 8c9560d2646..9d9001dc9e8 100644 --- a/core/js/tests/specs/shareitemmodelSpec.js +++ b/core/js/tests/specs/shareitemmodelSpec.js @@ -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([])); |