Skip to content

Commit 3b4ae2d

Browse files
TylerBrockdrew-gross
authored andcommitted
Write old ACL format in _acl in addition to new format (#1810)
1 parent 1854928 commit 3b4ae2d

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

spec/MongoTransform.spec.js

+15
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,21 @@ describe('transform schema key changes', () => {
233233
done();
234234
});
235235

236+
it('writes the old ACL format in addition to rperm and wperm', (done) => {
237+
var input = {
238+
ACL: {
239+
"*": { "read": true },
240+
"Kevin": { "write": true }
241+
}
242+
};
243+
244+
var output = transform.parseObjectToMongoObjectForCreate(dummySchema, null, input);
245+
expect(typeof output._acl).toEqual('object');
246+
expect(output._acl["Kevin"].w).toBeTruthy();
247+
expect(output._acl["Kevin"].r).toBeUndefined();
248+
done();
249+
})
250+
236251
it('untransforms from _rperm and _wperm to ACL', (done) => {
237252
var input = {
238253
_rperm: ["*"],

src/Adapters/Storage/Mongo/MongoTransform.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -348,14 +348,17 @@ function transformUpdate(schema, className, restUpdate) {
348348

349349
var mongoUpdate = {};
350350
var acl = transformACL(restUpdate);
351-
if (acl._rperm || acl._wperm) {
351+
if (acl._rperm || acl._wperm || acl._acl) {
352352
mongoUpdate['$set'] = {};
353353
if (acl._rperm) {
354354
mongoUpdate['$set']['_rperm'] = acl._rperm;
355355
}
356356
if (acl._wperm) {
357357
mongoUpdate['$set']['_wperm'] = acl._wperm;
358358
}
359+
if (acl._acl) {
360+
mongoUpdate['$set']['_acl'] = acl._acl;
361+
}
359362
}
360363

361364
for (var restKey in restUpdate) {
@@ -404,16 +407,23 @@ function transformACL(restObject) {
404407
var acl = restObject['ACL'];
405408
var rperm = [];
406409
var wperm = [];
410+
var _acl = {}; // old format
411+
407412
for (var entry in acl) {
408413
if (acl[entry].read) {
409414
rperm.push(entry);
415+
_acl[entry] = _acl[entry] || {};
416+
_acl[entry]['r'] = true;
410417
}
411418
if (acl[entry].write) {
412419
wperm.push(entry);
420+
_acl[entry] = _acl[entry] || {};
421+
_acl[entry]['w'] = true;
413422
}
414423
}
415424
output._rperm = rperm;
416425
output._wperm = wperm;
426+
output._acl = _acl;
417427
delete restObject.ACL;
418428
return output;
419429
}

0 commit comments

Comments
 (0)