Skip to content

Commit bf9fdb4

Browse files
authored
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
1 parent af45b4d commit bf9fdb4

File tree

5 files changed

+53
-6
lines changed

5 files changed

+53
-6
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
#### Improvements:
77
* Adds Pipeline Operator to Aggregate Router
88

9-
#### Dependency updates
9+
#### Bug Fixes:
10+
* Fixes issue that prevented ACL's from being used with `select` (see [#571](https://github.com/parse-community/Parse-SDK-JS/issues/571))
11+
12+
#### Dependency updates:
1013
* [@parse/simple-mailgun-adapter@1.1.0](https://www.npmjs.com/package/@parse/simple-mailgun-adapter)
1114

1215
### 2.8.4

spec/ParseObject.spec.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1762,6 +1762,38 @@ describe('Parse.Object testing', () => {
17621762
})
17631763
});
17641764

1765+
it('should include ACLs with select', (done) => {
1766+
const score = new Parse.Object("GameScore");
1767+
const player = new Parse.Object("Player");
1768+
score.set({
1769+
"score": 1234
1770+
});
1771+
const acl = new Parse.ACL();
1772+
acl.setPublicReadAccess(true);
1773+
acl.setPublicWriteAccess(false);
1774+
1775+
score.save().then(() => {
1776+
player.set("gameScore", score);
1777+
player.set("other", "value");
1778+
player.setACL(acl);
1779+
return player.save();
1780+
}).then(() => {
1781+
const query = new Parse.Query("Player");
1782+
query.include("gameScore");
1783+
query.select("gameScore");
1784+
return query.find();
1785+
}).then((res) => {
1786+
const obj = res[0];
1787+
const gameScore = obj.get("gameScore");
1788+
const other = obj.get("other");
1789+
expect(other).toBeUndefined();
1790+
expect(gameScore).not.toBeUndefined();
1791+
expect(gameScore.get("score")).toBe(1234);
1792+
expect(obj.getACL().getPublicReadAccess()).toBe(true);
1793+
expect(obj.getACL().getPublicWriteAccess()).toBe(false);
1794+
}).then(done).catch(done.fail);
1795+
});
1796+
17651797
it ('Update object field should store exactly same sent object', async (done) => {
17661798
let object = new TestObject();
17671799

src/Adapters/Storage/Mongo/MongoStorageAdapter.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,12 @@ export class MongoStorageAdapter implements StorageAdapter {
470470
const mongoWhere = transformWhere(className, query, schema);
471471
const mongoSort = _.mapKeys(sort, (value, fieldName) => transformKey(className, fieldName, schema));
472472
const mongoKeys = _.reduce(keys, (memo, key) => {
473-
memo[transformKey(className, key, schema)] = 1;
473+
if (key === 'ACL') {
474+
memo['_rperm'] = 1;
475+
memo['_wperm'] = 1;
476+
} else {
477+
memo[transformKey(className, key, schema)] = 1;
478+
}
474479
return memo;
475480
}, {});
476481

src/Adapters/Storage/Postgres/PostgresStorageAdapter.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1437,9 +1437,16 @@ export class PostgresStorageAdapter implements StorageAdapter {
14371437
let columns = '*';
14381438
if (keys) {
14391439
// Exclude empty keys
1440-
keys = keys.filter((key) => {
1441-
return key.length > 0;
1442-
});
1440+
// Replace ACL by it's keys
1441+
keys = keys.reduce((memo, key) => {
1442+
if (key === 'ACL') {
1443+
memo.push('_rperm');
1444+
memo.push('_wperm');
1445+
} else if (key.length > 0) {
1446+
memo.push(key);
1447+
}
1448+
return memo;
1449+
}, []);
14431450
columns = keys.map((key, index) => {
14441451
if (key === '$score') {
14451452
return `ts_rank_cd(to_tsvector($${2}, $${3}:name), to_tsquery($${4}, $${5}), 32) as score`;

src/RestQuery.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ var SchemaController = require('./Controllers/SchemaController');
55
var Parse = require('parse/node').Parse;
66
const triggers = require('./triggers');
77

8-
const AlwaysSelectedKeys = ['objectId', 'createdAt', 'updatedAt'];
8+
const AlwaysSelectedKeys = ['objectId', 'createdAt', 'updatedAt', 'ACL'];
99
// restOptions can include:
1010
// skip
1111
// limit

0 commit comments

Comments
 (0)