From 3b4ae2d0a0025ae08b0b30e9b1f7ca9af882c0d9 Mon Sep 17 00:00:00 2001 From: Tyler Brock Date: Mon, 16 May 2016 14:41:25 -0700 Subject: [PATCH] Write old ACL format in _acl in addition to new format (#1810) --- spec/MongoTransform.spec.js | 15 +++++++++++++++ src/Adapters/Storage/Mongo/MongoTransform.js | 12 +++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/spec/MongoTransform.spec.js b/spec/MongoTransform.spec.js index 755187dd..905b7647 100644 --- a/spec/MongoTransform.spec.js +++ b/spec/MongoTransform.spec.js @@ -233,6 +233,21 @@ describe('transform schema key changes', () => { done(); }); + it('writes the old ACL format in addition to rperm and wperm', (done) => { + var input = { + ACL: { + "*": { "read": true }, + "Kevin": { "write": true } + } + }; + + var output = transform.parseObjectToMongoObjectForCreate(dummySchema, null, input); + expect(typeof output._acl).toEqual('object'); + expect(output._acl["Kevin"].w).toBeTruthy(); + expect(output._acl["Kevin"].r).toBeUndefined(); + done(); + }) + it('untransforms from _rperm and _wperm to ACL', (done) => { var input = { _rperm: ["*"], diff --git a/src/Adapters/Storage/Mongo/MongoTransform.js b/src/Adapters/Storage/Mongo/MongoTransform.js index d445e7ce..0cf09dbb 100644 --- a/src/Adapters/Storage/Mongo/MongoTransform.js +++ b/src/Adapters/Storage/Mongo/MongoTransform.js @@ -348,7 +348,7 @@ function transformUpdate(schema, className, restUpdate) { var mongoUpdate = {}; var acl = transformACL(restUpdate); - if (acl._rperm || acl._wperm) { + if (acl._rperm || acl._wperm || acl._acl) { mongoUpdate['$set'] = {}; if (acl._rperm) { mongoUpdate['$set']['_rperm'] = acl._rperm; @@ -356,6 +356,9 @@ function transformUpdate(schema, className, restUpdate) { if (acl._wperm) { mongoUpdate['$set']['_wperm'] = acl._wperm; } + if (acl._acl) { + mongoUpdate['$set']['_acl'] = acl._acl; + } } for (var restKey in restUpdate) { @@ -404,16 +407,23 @@ function transformACL(restObject) { var acl = restObject['ACL']; var rperm = []; var wperm = []; + var _acl = {}; // old format + for (var entry in acl) { if (acl[entry].read) { rperm.push(entry); + _acl[entry] = _acl[entry] || {}; + _acl[entry]['r'] = true; } if (acl[entry].write) { wperm.push(entry); + _acl[entry] = _acl[entry] || {}; + _acl[entry]['w'] = true; } } output._rperm = rperm; output._wperm = wperm; + output._acl = _acl; delete restObject.ACL; return output; }