diff --git a/core/js/shareitemmodel.js b/core/js/shareitemmodel.js index 3ed10afd14..d883497433 100644 --- a/core/js/shareitemmodel.js +++ b/core/js/shareitemmodel.js @@ -50,7 +50,7 @@ * @property {string} token * @property {string} share_with * @property {string} share_with_displayname - * @property {string} share_mail_send + * @property {string} mail_send * @property {OC.Share.Types.Collection|undefined} collection * @property {Date} expiration optional? * @property {number} stime optional? @@ -63,6 +63,15 @@ * @property {OC.Share.Types.LinkShareInfo|undefined} linkShare */ + /** + * These properties are sometimes returned by the server as strings instead + * of integers, so we need to convert them accordingly... + */ + var SHARE_RESPONSE_INT_PROPS = [ + 'id', 'file_parent', 'mail_send', 'file_source', 'item_source', 'permissions', + 'storage', 'share_type', 'parent', 'stime', 'expiration' + ]; + /** * @class OCA.Share.ShareItemModel * @classdesc @@ -462,7 +471,7 @@ if(!_.isObject(share)) { throw "Unknown Share"; } - return share.share_mail_send === '1'; + return share.mail_send === 1; }, /** @@ -673,7 +682,19 @@ } /** @type {OC.Share.Types.ShareInfo[]} **/ - var shares = _.toArray(data.shares); + var shares = _.map(data.shares, function(share) { + // properly parse some values because sometimes the server + // returns integers as string... + var i; + for (i = 0; i < SHARE_RESPONSE_INT_PROPS.length; i++) { + var prop = SHARE_RESPONSE_INT_PROPS[i]; + if (!_.isUndefined(share[prop])) { + share[prop] = parseInt(share[prop], 10); + } + } + return share; + }); + this._legacyFillCurrentShares(shares); var linkShare = { isLinkShare: false }; diff --git a/core/js/tests/specs/shareitemmodelSpec.js b/core/js/tests/specs/shareitemmodelSpec.js index c1d820052e..07a6fbdc23 100644 --- a/core/js/tests/specs/shareitemmodelSpec.js +++ b/core/js/tests/specs/shareitemmodelSpec.js @@ -249,10 +249,7 @@ describe('OC.Share.ShareItemModel', function() { it('allows owner to share their own share when they are also the recipient', function() { OC.currentUser = 'user1'; loadItemStub.yields({ - reshare: { - permissions: OC.PERMISSION_READ, - uid_owner: 'user1' - }, + reshare: {}, shares: [] }); @@ -261,6 +258,51 @@ describe('OC.Share.ShareItemModel', function() { // sharing still allowed expect(model.get('permissions') & OC.PERMISSION_SHARE).toEqual(OC.PERMISSION_SHARE); }); + it('properly parses integer values when the server is in the mood of returning ints as string', function() { + loadItemStub.yields({ + reshare: {}, + shares: [{ + displayname_owner: 'root', + expiration: '1403900000', + file_source: '123', + file_target: '/folder', + id: '20', + item_source: '123', + item_type: 'file', + mail_send: '0', + parent: '999', + path: '/folder', + permissions: '' + OC.PERMISSION_READ, + share_type: '' + OC.Share.SHARE_TYPE_USER, + share_with: 'user1', + stime: '1403884258', + storage: '1', + token: 'tehtoken', + uid_owner: 'root' + }] + }); + + model.fetch(); + + var shares = model.get('shares'); + expect(shares.length).toEqual(1); + + var share = shares[0]; + expect(share.id).toEqual(20); + expect(share.file_source).toEqual(123); + expect(share.file_target).toEqual('/folder'); + expect(share.item_source).toEqual(123); + expect(share.item_type).toEqual('file'); + expect(share.displayname_owner).toEqual('root'); + expect(share.mail_send).toEqual(0); + expect(share.parent).toEqual(999); + expect(share.path).toEqual('/folder'); + expect(share.permissions).toEqual(OC.PERMISSION_READ); + expect(share.share_type).toEqual(OC.Share.SHARE_TYPE_USER); + expect(share.share_with).toEqual('user1'); + expect(share.stime).toEqual(1403884258); + expect(share.expiration).toEqual(1403900000); + }); }); describe('Util', function() {