Skip to content

Commit

Permalink
Ensure the ACL is always part of the payload when using select
Browse files Browse the repository at this point in the history
  • Loading branch information
flovilmart committed Aug 15, 2018
1 parent 2765f33 commit 0ce99f1
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
32 changes: 32 additions & 0 deletions spec/ParseObject.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1762,6 +1762,38 @@ describe('Parse.Object testing', () => {
})
});

it('should include ACLs with select', (done) => {
const score = new Parse.Object("GameScore");
const player = new Parse.Object("Player");
score.set({
"score": 1234
});
const acl = new Parse.ACL();
acl.setPublicReadAccess(true);
acl.setPublicWriteAccess(false);

score.save().then(() => {
player.set("gameScore", score);
player.set("other", "value");
player.setACL(acl);
return player.save();
}).then(() => {
const query = new Parse.Query("Player");
query.include("gameScore");
query.select("gameScore");
return query.find();
}).then((res) => {
const obj = res[0];
const gameScore = obj.get("gameScore");
const other = obj.get("other");
expect(other).toBeUndefined();
expect(gameScore).not.toBeUndefined();
expect(gameScore.get("score")).toBe(1234);
expect(obj.getACL().getPublicReadAccess()).toBe(true);
expect(obj.getACL().getPublicWriteAccess()).toBe(false);
}).then(done).catch(done.fail);
});

it ('Update object field should store exactly same sent object', async (done) => {
let object = new TestObject();

Expand Down
7 changes: 6 additions & 1 deletion src/Adapters/Storage/Mongo/MongoStorageAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,12 @@ export class MongoStorageAdapter implements StorageAdapter {
const mongoWhere = transformWhere(className, query, schema);
const mongoSort = _.mapKeys(sort, (value, fieldName) => transformKey(className, fieldName, schema));
const mongoKeys = _.reduce(keys, (memo, key) => {
memo[transformKey(className, key, schema)] = 1;
if (key === 'ACL') {
memo['_rperm'] = 1;
memo['_wperm'] = 1;
} else {
memo[transformKey(className, key, schema)] = 1;
}
return memo;
}, {});

Expand Down
2 changes: 1 addition & 1 deletion src/RestQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var SchemaController = require('./Controllers/SchemaController');
var Parse = require('parse/node').Parse;
const triggers = require('./triggers');

const AlwaysSelectedKeys = ['objectId', 'createdAt', 'updatedAt'];
const AlwaysSelectedKeys = ['objectId', 'createdAt', 'updatedAt', 'ACL'];
// restOptions can include:
// skip
// limit
Expand Down

0 comments on commit 0ce99f1

Please sign in to comment.