Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions spec/MongoTransform.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,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: ["*"],
Expand Down
12 changes: 11 additions & 1 deletion src/Adapters/Storage/Mongo/MongoTransform.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,14 +354,17 @@ 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;
}
if (acl._wperm) {
mongoUpdate['$set']['_wperm'] = acl._wperm;
}
if (acl._acl) {
mongoUpdate['$set']['_acl'] = acl._acl;
}
}

for (var restKey in restUpdate) {
Expand Down Expand Up @@ -410,16 +413,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;
}
Expand Down