summaryrefslogtreecommitdiffstats
path: root/core/js
diff options
context:
space:
mode:
authorVincent Petry <pvince81@owncloud.com>2015-09-23 12:14:09 +0200
committerVincent Petry <pvince81@owncloud.com>2015-09-23 12:16:47 +0200
commit6ea27e2b035f996a121723bfb845fd47b4ebce23 (patch)
tree7ef01918a180d6c9f2ced8cbb83fc6167250f271 /core/js
parentee649d58c5f82ee209ddc1812c1a896da53de707 (diff)
downloadnextcloud-server-6ea27e2b035f996a121723bfb845fd47b4ebce23.tar.gz
nextcloud-server-6ea27e2b035f996a121723bfb845fd47b4ebce23.zip
Fix parsing int attributes from share.php response
Sometimes the attributes returned by share.php are integers but packaged as strings. This fix makes sure that such attributes are parsed as integers
Diffstat (limited to 'core/js')
-rw-r--r--core/js/shareitemmodel.js27
-rw-r--r--core/js/tests/specs/shareitemmodelSpec.js50
2 files changed, 70 insertions, 7 deletions
diff --git a/core/js/shareitemmodel.js b/core/js/shareitemmodel.js
index 3ed10afd149..d883497433f 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?
@@ -64,6 +64,15 @@
*/
/**
+ * 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 c1d820052e2..07a6fbdc23f 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() {