Write old ACL format in _acl in addition to new format (#1810)
This commit is contained in:
@@ -233,6 +233,21 @@ describe('transform schema key changes', () => {
|
|||||||
done();
|
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) => {
|
it('untransforms from _rperm and _wperm to ACL', (done) => {
|
||||||
var input = {
|
var input = {
|
||||||
_rperm: ["*"],
|
_rperm: ["*"],
|
||||||
|
|||||||
@@ -348,7 +348,7 @@ function transformUpdate(schema, className, restUpdate) {
|
|||||||
|
|
||||||
var mongoUpdate = {};
|
var mongoUpdate = {};
|
||||||
var acl = transformACL(restUpdate);
|
var acl = transformACL(restUpdate);
|
||||||
if (acl._rperm || acl._wperm) {
|
if (acl._rperm || acl._wperm || acl._acl) {
|
||||||
mongoUpdate['$set'] = {};
|
mongoUpdate['$set'] = {};
|
||||||
if (acl._rperm) {
|
if (acl._rperm) {
|
||||||
mongoUpdate['$set']['_rperm'] = acl._rperm;
|
mongoUpdate['$set']['_rperm'] = acl._rperm;
|
||||||
@@ -356,6 +356,9 @@ function transformUpdate(schema, className, restUpdate) {
|
|||||||
if (acl._wperm) {
|
if (acl._wperm) {
|
||||||
mongoUpdate['$set']['_wperm'] = acl._wperm;
|
mongoUpdate['$set']['_wperm'] = acl._wperm;
|
||||||
}
|
}
|
||||||
|
if (acl._acl) {
|
||||||
|
mongoUpdate['$set']['_acl'] = acl._acl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var restKey in restUpdate) {
|
for (var restKey in restUpdate) {
|
||||||
@@ -404,16 +407,23 @@ function transformACL(restObject) {
|
|||||||
var acl = restObject['ACL'];
|
var acl = restObject['ACL'];
|
||||||
var rperm = [];
|
var rperm = [];
|
||||||
var wperm = [];
|
var wperm = [];
|
||||||
|
var _acl = {}; // old format
|
||||||
|
|
||||||
for (var entry in acl) {
|
for (var entry in acl) {
|
||||||
if (acl[entry].read) {
|
if (acl[entry].read) {
|
||||||
rperm.push(entry);
|
rperm.push(entry);
|
||||||
|
_acl[entry] = _acl[entry] || {};
|
||||||
|
_acl[entry]['r'] = true;
|
||||||
}
|
}
|
||||||
if (acl[entry].write) {
|
if (acl[entry].write) {
|
||||||
wperm.push(entry);
|
wperm.push(entry);
|
||||||
|
_acl[entry] = _acl[entry] || {};
|
||||||
|
_acl[entry]['w'] = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
output._rperm = rperm;
|
output._rperm = rperm;
|
||||||
output._wperm = wperm;
|
output._wperm = wperm;
|
||||||
|
output._acl = _acl;
|
||||||
delete restObject.ACL;
|
delete restObject.ACL;
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user