Skip to content

Commit 0773523

Browse files
steven-supersolidflovilmart
authored andcommitted
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
1 parent f6312a1 commit 0773523

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

spec/MongoTransform.spec.js

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -221,18 +221,37 @@ describe('parseObjectToMongoObjectForCreate', () => {
221221
done();
222222
});
223223

224-
it('writes the old ACL format in addition to rperm and wperm', (done) => {
224+
it('writes the old ACL format in addition to rperm and wperm on create', (done) => {
225225
var input = {
226226
_rperm: ['*'],
227227
_wperm: ['Kevin'],
228228
};
229229

230230
var output = transform.parseObjectToMongoObjectForCreate(null, input, { fields: {} });
231231
expect(typeof output._acl).toEqual('object');
232-
expect(output._acl["Kevin"].w).toBeTruthy();
233-
expect(output._acl["Kevin"].r).toBeUndefined();
232+
expect(output._acl['Kevin'].w).toBeTruthy();
233+
expect(output._acl['Kevin'].r).toBeUndefined();
234+
expect(output._rperm).toEqual(input._rperm);
235+
expect(output._wperm).toEqual(input._wperm);
234236
done();
235-
})
237+
});
238+
239+
it('writes the old ACL format in addition to rperm and wperm on update', (done) => {
240+
var input = {
241+
_rperm: ['*'],
242+
_wperm: ['Kevin']
243+
};
244+
245+
var output = transform.transformUpdate(null, input, { fields: {} });
246+
var set = output.$set;
247+
expect(typeof set).toEqual('object');
248+
expect(typeof set._acl).toEqual('object');
249+
expect(set._acl['Kevin'].w).toBeTruthy();
250+
expect(set._acl['Kevin'].r).toBeUndefined();
251+
expect(set._rperm).toEqual(input._rperm);
252+
expect(set._wperm).toEqual(input._wperm);
253+
done();
254+
});
236255

237256
it('untransforms from _rperm and _wperm to ACL', (done) => {
238257
var input = {

src/Adapters/Storage/Mongo/MongoTransform.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,8 +330,8 @@ const parseObjectToMongoObjectForCreate = (className, restCreate, schema) => {
330330
// Main exposed method to help update old objects.
331331
const transformUpdate = (className, restUpdate, parseFormatSchema) => {
332332
let mongoUpdate = {};
333-
let acl = addLegacyACL(restUpdate)._acl;
334-
if (acl) {
333+
let acl = addLegacyACL(restUpdate);
334+
if (acl._rperm || acl._wperm || acl._acl) {
335335
mongoUpdate.$set = {};
336336
if (acl._rperm) {
337337
mongoUpdate.$set._rperm = acl._rperm;

0 commit comments

Comments
 (0)