Skip to content

Ensure _acl is updated when _rperm and _wperm updated #2701

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 17, 2016
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
27 changes: 23 additions & 4 deletions spec/MongoTransform.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,18 +221,37 @@ describe('parseObjectToMongoObjectForCreate', () => {
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 = {
_rperm: ['*'],
_wperm: ['Kevin'],
};

var output = transform.parseObjectToMongoObjectForCreate(null, input, { fields: {} });
expect(typeof output._acl).toEqual('object');
expect(output._acl["Kevin"].w).toBeTruthy();
expect(output._acl["Kevin"].r).toBeUndefined();
expect(output._acl['Kevin'].w).toBeTruthy();
expect(output._acl['Kevin'].r).toBeUndefined();
expect(output._rperm).toEqual(input._rperm);
expect(output._wperm).toEqual(input._wperm);
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) => {
var input = {
Expand Down
4 changes: 2 additions & 2 deletions src/Adapters/Storage/Mongo/MongoTransform.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,8 @@ const parseObjectToMongoObjectForCreate = (className, restCreate, schema) => {
// Main exposed method to help update old objects.
const transformUpdate = (className, restUpdate, parseFormatSchema) => {
let mongoUpdate = {};
let acl = addLegacyACL(restUpdate)._acl;
if (acl) {
let acl = addLegacyACL(restUpdate);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

._acl is not the full acl but just the legacy part, so none of the properties below exist as we are trying to reference acl._acl._acl for example.
$set._rperm and _wperm are provided via transformKeyValueForUpdate on line 340 so all that needs to be added here is the legacy property _acl

Copy link
Contributor

@flovilmart flovilmart Sep 12, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

@steven-supersolid steven-supersolid Sep 12, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you are suggesting not changing line 333 then none of the if clauses will execute on lines 336, 339, 342

The object returned by addLegacyACL has the format:

{
 _acl: {
   id: w,
   id: r},
 _rperm: [],
 _wperm: []
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the whole thing as a no-op in the end and now it's breaking all the tests...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I thought it was an intermittent test failure.
The tests were failing when restUpdate contained non-acl updates, e.g. { _failed_login_count: { __op: 'Increment', amount: 1 } }.
I've restored the original code for line 334 which fixes the issue.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good now!

if (acl._rperm || acl._wperm || acl._acl) {
mongoUpdate.$set = {};
if (acl._rperm) {
mongoUpdate.$set._rperm = acl._rperm;
Expand Down