1
0
Mirror von https://github.com/nextcloud/server.git synchronisiert 2024-08-15 02:11:48 +02:00

Fix ShareItemModel.hasUserShares to only check shares of current item

The shares array is based on what the server returns and can contain
share info for parent folders.

hasUserShares is now fixed to ignore parent folders and only checks for
shares on the current item.
Dieser Commit ist enthalten in:
Vincent Petry 2015-09-23 12:44:25 +02:00
Ursprung d54d9a573f
Commit 0db9b28f3f
2 geänderte Dateien mit 72 neuen und 2 gelöschten Zeilen

Datei anzeigen

@ -297,8 +297,7 @@
* @returns {boolean}
*/
hasUserShares: function() {
var shares = this.get('shares');
return _.isArray(shares) && shares.length > 0;
return this.getSharesWithCurrentItem().length > 0;
},
/**
@ -407,6 +406,20 @@
return this.get('reshare').share_type;
},
/**
* Returns all share entries that only apply to the current item
* (file/folder)
*
* @return {Array.<OC.Share.Types.ShareInfo>}
*/
getSharesWithCurrentItem: function() {
var shares = this.get('shares') || [];
var fileId = this.fileInfoModel.get('id');
return _.filter(shares, function(share) {
return share.item_source === fileId;
});
},
/**
* @param shareIndex
* @returns {string}

Datei anzeigen

@ -304,6 +304,63 @@ describe('OC.Share.ShareItemModel', function() {
expect(share.expiration).toEqual(1403900000);
});
});
describe('hasUserShares', function() {
it('returns false when no user shares exist', function() {
loadItemStub.yields({
reshare: {},
shares: []
});
model.fetch();
expect(model.hasUserShares()).toEqual(false);
});
it('returns true when user shares exist on the current item', function() {
loadItemStub.yields({
reshare: {},
shares: [{
id: 1,
share_type: OC.Share.SHARE_TYPE_USER,
share_with: 'user1',
item_source: '123'
}]
});
model.fetch();
expect(model.hasUserShares()).toEqual(true);
});
it('returns true when group shares exist on the current item', function() {
loadItemStub.yields({
reshare: {},
shares: [{
id: 1,
share_type: OC.Share.SHARE_TYPE_GROUP,
share_with: 'group1',
item_source: '123'
}]
});
model.fetch();
expect(model.hasUserShares()).toEqual(true);
});
it('returns false when share exist on parent item', function() {
loadItemStub.yields({
reshare: {},
shares: [{
id: 1,
share_type: OC.Share.SHARE_TYPE_GROUP,
share_with: 'group1',
item_source: '111'
}]
});
model.fetch();
expect(model.hasUserShares()).toEqual(false);
});
});
describe('Util', function() {
it('parseTime should properly parse strings', function() {