Ensure _acl is updated when _rperm and _wperm updated (#2701)
* Ensure _acl is updated when _rperm and _wperm updated * alternative solution * Only try to apply $set for permission updates
This commit is contained in:
committed by
Florent Vilmart
parent
f6312a1b98
commit
0773523bc2
@@ -221,7 +221,7 @@ describe('parseObjectToMongoObjectForCreate', () => {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('writes the old ACL format in addition to rperm and wperm', (done) => {
|
it('writes the old ACL format in addition to rperm and wperm on create', (done) => {
|
||||||
var input = {
|
var input = {
|
||||||
_rperm: ['*'],
|
_rperm: ['*'],
|
||||||
_wperm: ['Kevin'],
|
_wperm: ['Kevin'],
|
||||||
@@ -229,10 +229,29 @@ describe('parseObjectToMongoObjectForCreate', () => {
|
|||||||
|
|
||||||
var output = transform.parseObjectToMongoObjectForCreate(null, input, { fields: {} });
|
var output = transform.parseObjectToMongoObjectForCreate(null, input, { fields: {} });
|
||||||
expect(typeof output._acl).toEqual('object');
|
expect(typeof output._acl).toEqual('object');
|
||||||
expect(output._acl["Kevin"].w).toBeTruthy();
|
expect(output._acl['Kevin'].w).toBeTruthy();
|
||||||
expect(output._acl["Kevin"].r).toBeUndefined();
|
expect(output._acl['Kevin'].r).toBeUndefined();
|
||||||
|
expect(output._rperm).toEqual(input._rperm);
|
||||||
|
expect(output._wperm).toEqual(input._wperm);
|
||||||
done();
|
done();
|
||||||
})
|
});
|
||||||
|
|
||||||
|
it('writes the old ACL format in addition to rperm and wperm on update', (done) => {
|
||||||
|
var input = {
|
||||||
|
_rperm: ['*'],
|
||||||
|
_wperm: ['Kevin']
|
||||||
|
};
|
||||||
|
|
||||||
|
var output = transform.transformUpdate(null, input, { fields: {} });
|
||||||
|
var set = output.$set;
|
||||||
|
expect(typeof set).toEqual('object');
|
||||||
|
expect(typeof set._acl).toEqual('object');
|
||||||
|
expect(set._acl['Kevin'].w).toBeTruthy();
|
||||||
|
expect(set._acl['Kevin'].r).toBeUndefined();
|
||||||
|
expect(set._rperm).toEqual(input._rperm);
|
||||||
|
expect(set._wperm).toEqual(input._wperm);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
it('untransforms from _rperm and _wperm to ACL', (done) => {
|
it('untransforms from _rperm and _wperm to ACL', (done) => {
|
||||||
var input = {
|
var input = {
|
||||||
|
|||||||
@@ -330,8 +330,8 @@ const parseObjectToMongoObjectForCreate = (className, restCreate, schema) => {
|
|||||||
// Main exposed method to help update old objects.
|
// Main exposed method to help update old objects.
|
||||||
const transformUpdate = (className, restUpdate, parseFormatSchema) => {
|
const transformUpdate = (className, restUpdate, parseFormatSchema) => {
|
||||||
let mongoUpdate = {};
|
let mongoUpdate = {};
|
||||||
let acl = addLegacyACL(restUpdate)._acl;
|
let acl = addLegacyACL(restUpdate);
|
||||||
if (acl) {
|
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;
|
||||||
|
|||||||
Reference in New Issue
Block a user