Ensure the ACL is always part of the payload when using select (#4967)

* Ensure the ACL is always part of the payload when using select

* Update changelog

* fix for PG
This commit is contained in:
Florent Vilmart
2018-08-15 09:48:32 -04:00
committed by GitHub
parent af45b4df74
commit bf9fdb41ed
5 changed files with 53 additions and 6 deletions

View File

@@ -6,7 +6,10 @@
#### Improvements:
* Adds Pipeline Operator to Aggregate Router
#### Dependency updates
#### Bug Fixes:
* Fixes issue that prevented ACL's from being used with `select` (see [#571](https://github.com/parse-community/Parse-SDK-JS/issues/571))
#### Dependency updates:
* [@parse/simple-mailgun-adapter@1.1.0](https://www.npmjs.com/package/@parse/simple-mailgun-adapter)
### 2.8.4

View File

@@ -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();

View File

@@ -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;
}, {});

View File

@@ -1437,9 +1437,16 @@ export class PostgresStorageAdapter implements StorageAdapter {
let columns = '*';
if (keys) {
// Exclude empty keys
keys = keys.filter((key) => {
return key.length > 0;
});
// Replace ACL by it's keys
keys = keys.reduce((memo, key) => {
if (key === 'ACL') {
memo.push('_rperm');
memo.push('_wperm');
} else if (key.length > 0) {
memo.push(key);
}
return memo;
}, []);
columns = keys.map((key, index) => {
if (key === '$score') {
return `ts_rank_cd(to_tsvector($${2}, $${3}:name), to_tsquery($${4}, $${5}), 32) as score`;

View File

@@ -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