diff options
-rw-r--r-- | apps/files_sharing/js/share.js | 17 | ||||
-rw-r--r-- | apps/files_sharing/tests/js/shareSpec.js | 78 | ||||
-rw-r--r-- | core/js/shareitemmodel.js | 14 | ||||
-rw-r--r-- | core/js/tests/specs/shareitemmodelSpec.js | 61 |
4 files changed, 163 insertions, 7 deletions
diff --git a/apps/files_sharing/js/share.js b/apps/files_sharing/js/share.js index c40ca07b76b..5cd04ece446 100644 --- a/apps/files_sharing/js/share.js +++ b/apps/files_sharing/js/share.js @@ -189,13 +189,16 @@ // remove icon, if applicable OC.Share.markFileAsShared($tr, false, false); } - var newIcon = $tr.attr('data-icon'); - // in case markFileAsShared decided to change the icon, - // we need to modify the model - // (FIXME: yes, this is hacky) - if (fileInfoModel.get('icon') !== newIcon) { - fileInfoModel.set('icon', newIcon); - } + + // FIXME: this is too convoluted. We need to get rid of the above updates + // and only ever update the model and let the events take care of rerendering + fileInfoModel.set({ + shareTypes: shareModel.getShareTypes(), + // in case markFileAsShared decided to change the icon, + // we need to modify the model + // (FIXME: yes, this is hacky) + icon: $tr.attr('data-icon') + }); }); fileList.registerTabView(shareTab); diff --git a/apps/files_sharing/tests/js/shareSpec.js b/apps/files_sharing/tests/js/shareSpec.js index 7568b06f27c..ea2f427df75 100644 --- a/apps/files_sharing/tests/js/shareSpec.js +++ b/apps/files_sharing/tests/js/shareSpec.js @@ -470,4 +470,82 @@ describe('OCA.Sharing.Util tests', function() { }); }); + describe('ShareTabView interaction', function() { + var shareTabSpy; + var fileInfoModel; + var configModel; + var shareModel; + + beforeEach(function() { + shareTabSpy = sinon.spy(OCA.Sharing, 'ShareTabView'); + + var attributes = { + itemType: 'file', + itemSource: 123, + possiblePermissions: 31, + permissions: 31 + }; + fileInfoModel = new OCA.Files.FileInfoModel(testFiles[0]); + configModel = new OC.Share.ShareConfigModel({ + enforcePasswordForPublicLink: false, + isResharingAllowed: true, + isDefaultExpireDateEnabled: false, + isDefaultExpireDateEnforced: false, + defaultExpireDate: 7 + }); + shareModel = new OC.Share.ShareItemModel(attributes, { + configModel: configModel, + fileInfoModel: fileInfoModel + }); + + /* jshint camelcase: false */ + shareModel.set({ + reshare: {}, + shares: [{ + id: 100, + item_source: 1, + permissions: 31, + share_type: OC.Share.SHARE_TYPE_USER, + share_with: 'user1', + share_with_displayname: 'User One' + }, { + id: 102, + item_source: 1, + permissions: 31, + share_type: OC.Share.SHARE_TYPE_REMOTE, + share_with: 'foo@bar.com/baz', + share_with_displayname: 'foo@bar.com/baz' + + }] + }, {parse: true}); + + fileList.destroy(); + fileList = new OCA.Files.FileList( + $('#listContainer'), { + id: 'files', + fileActions: new OCA.Files.FileActions() + } + ); + OCA.Sharing.Util.attach(fileList); + fileList.setFiles(testFiles); + }); + afterEach(function() { + shareTabSpy.restore(); + }); + + it('updates fileInfoModel when shares changed', function() { + var changeHandler = sinon.stub(); + fileInfoModel.on('change', changeHandler); + + shareTabSpy.getCall(0).thisValue.trigger('sharesChanged', shareModel); + + expect(changeHandler.calledOnce).toEqual(true); + expect(changeHandler.getCall(0).args[0].changed).toEqual({ + shareTypes: [ + OC.Share.SHARE_TYPE_USER, + OC.Share.SHARE_TYPE_REMOTE + ] + }); + }); + }); }); diff --git a/core/js/shareitemmodel.js b/core/js/shareitemmodel.js index 41f9eb5e0aa..4118a8a0188 100644 --- a/core/js/shareitemmodel.js +++ b/core/js/shareitemmodel.js @@ -841,6 +841,20 @@ } } return time; + }, + + /** + * Returns a list of share types from the existing shares. + * + * @return {Array.<int>} array of share types + */ + getShareTypes: function() { + var result; + result = _.pluck(this.getSharesWithCurrentItem(), 'share_type'); + if (this.hasLinkShare()) { + result.push(OC.Share.SHARE_TYPE_LINK); + } + return _.uniq(result); } }); diff --git a/core/js/tests/specs/shareitemmodelSpec.js b/core/js/tests/specs/shareitemmodelSpec.js index 771a9263709..3b17051508e 100644 --- a/core/js/tests/specs/shareitemmodelSpec.js +++ b/core/js/tests/specs/shareitemmodelSpec.js @@ -924,5 +924,66 @@ describe('OC.Share.ShareItemModel', function() { expect(errorStub.lastCall.args[1]).toEqual('Some error message'); }); }); + + describe('getShareTypes', function() { + + var dataProvider = [ + [ + ], + [ + OC.Share.SHARE_TYPE_USER, + OC.Share.SHARE_TYPE_USER, + ], + [ + OC.Share.SHARE_TYPE_USER, + OC.Share.SHARE_TYPE_GROUP, + OC.Share.SHARE_TYPE_LINK, + OC.Share.SHARE_TYPE_REMOTE + ], + [ + OC.Share.SHARE_TYPE_USER, + OC.Share.SHARE_TYPE_GROUP, + OC.Share.SHARE_TYPE_GROUP, + OC.Share.SHARE_TYPE_LINK, + OC.Share.SHARE_TYPE_LINK, + OC.Share.SHARE_TYPE_REMOTE, + OC.Share.SHARE_TYPE_REMOTE, + OC.Share.SHARE_TYPE_REMOTE + ], + [ + OC.Share.SHARE_TYPE_LINK, + OC.Share.SHARE_TYPE_LINK, + OC.Share.SHARE_TYPE_USER + ] + ]; + + _.each(dataProvider, function testCase(shareTypes, i) { + it('returns set of share types for case ' + i, function() { + /* jshint camelcase: false */ + fetchReshareDeferred.resolve(makeOcsResponse([])); + + var id = 100; + var shares = _.map(shareTypes, function(shareType) { + return { + id: id++, + item_source: 123, + permissions: 31, + share_type: shareType, + uid_owner: 'root' + }; + }); + + var expectedResult = _.uniq(shareTypes).sort(); + + fetchSharesDeferred.resolve(makeOcsResponse(shares)); + + OC.currentUser = 'root'; + + model.fetch(); + + expect(model.getShareTypes().sort()).toEqual(expectedResult); + }); + }); + }); }); |