Skip to content

Commit d14d451

Browse files
drew-grossflovilmart
authored andcommitted
Move acl adding into parse server (#1601)
* Move writeACL knowledge out of mongoAdapter * Remove write ACL from mongo adapter * Remove readACL from Mongo Transform
1 parent d33dd68 commit d14d451

File tree

3 files changed

+25
-22
lines changed

3 files changed

+25
-22
lines changed

src/Adapters/Storage/Mongo/MongoStorageAdapter.js

+2-7
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,8 @@ export class MongoStorageAdapter {
163163
// If no objects match, reject with OBJECT_NOT_FOUND. If objects are found and deleted, resolve with undefined.
164164
// If there is some other error, reject with INTERNAL_SERVER_ERROR.
165165

166-
// Currently accepts the acl, schemaController, validate
167-
// for lecacy reasons, Parse Server should later integrate acl into the query. Database adapters
168-
// shouldn't know about acl.
169-
deleteObjectsByQuery(className, query, acl, schemaController, validate) {
166+
// Currently accepts the schemaController, and validate for lecacy reasons
167+
deleteObjectsByQuery(className, query, schemaController, validate) {
170168
return this.adaptiveCollection(className)
171169
.then(collection => {
172170
let mongoWhere = transform.transformWhere(
@@ -175,9 +173,6 @@ export class MongoStorageAdapter {
175173
query,
176174
{ validate }
177175
);
178-
if (acl) {
179-
mongoWhere = transform.addWriteACL(mongoWhere, acl);
180-
}
181176
return collection.deleteMany(mongoWhere)
182177
})
183178
.then(({ result }) => {

src/Adapters/Storage/Mongo/MongoTransform.js

-10
Original file line numberDiff line numberDiff line change
@@ -916,14 +916,6 @@ function transformNotInQuery(notInQueryObject, className, results) {
916916
}
917917
}
918918

919-
function addWriteACL(mongoWhere, acl) {
920-
return {'$and': [mongoWhere, {"_wperm" : { "$in" : [null, ...acl]}}]};
921-
}
922-
923-
function addReadACL(mongoWhere, acl) {
924-
return {'$and': [mongoWhere, {"_rperm" : { "$in" : [null, "*", ...acl]}}]};
925-
}
926-
927919
var DateCoder = {
928920
JSONToDatabase(json) {
929921
return new Date(json.iso);
@@ -1021,7 +1013,5 @@ module.exports = {
10211013
transformDontSelect,
10221014
transformInQuery,
10231015
transformNotInQuery,
1024-
addReadACL,
1025-
addWriteACL,
10261016
untransformObject
10271017
};

src/Controllers/DatabaseController.js

+23-5
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,28 @@
22
// Parse database.
33

44
import intersect from 'intersect';
5+
import _ from 'lodash';
56

67
var mongodb = require('mongodb');
78
var Parse = require('parse/node').Parse;
89

910
var SchemaController = require('../Controllers/SchemaController');
1011
const deepcopy = require('deepcopy');
1112

13+
function addWriteACL(query, acl) {
14+
let newQuery = _.cloneDeep(query);
15+
//Can't be any existing '_wperm' query, we don't allow client queries on that, no need to $and
16+
newQuery._wperm = { "$in" : [null, ...acl]};
17+
return newQuery;
18+
}
19+
20+
function addReadACL(query, acl) {
21+
let newQuery = _.cloneDeep(query);
22+
//Can't be any existing '_rperm' query, we don't allow client queries on that, no need to $and
23+
newQuery._rperm = { "$in" : [null, "*", ...acl]};
24+
return newQuery;
25+
}
26+
1227
function DatabaseController(adapter, { skipValidation } = {}) {
1328
this.adapter = adapter;
1429

@@ -161,10 +176,10 @@ DatabaseController.prototype.update = function(className, query, update, {
161176
if (!query) {
162177
return Promise.resolve();
163178
}
164-
var mongoWhere = this.transform.transformWhere(schema, className, query, {validate: !this.skipValidation});
165179
if (acl) {
166-
mongoWhere = this.transform.addWriteACL(mongoWhere, acl);
180+
query = addWriteACL(query, acl);
167181
}
182+
var mongoWhere = this.transform.transformWhere(schema, className, query, {validate: !this.skipValidation});
168183
mongoUpdate = this.transform.transformUpdate(schema, className, update, {validate: !this.skipValidation});
169184
if (many) {
170185
return collection.updateMany(mongoWhere, mongoUpdate);
@@ -299,7 +314,10 @@ DatabaseController.prototype.destroy = function(className, query, { acl } = {})
299314
}
300315
}
301316
// delete by query
302-
return this.adapter.deleteObjectsByQuery(className, query, acl, schemaController, !this.skipValidation)
317+
if (acl) {
318+
query = addWriteACL(query, acl);
319+
}
320+
return this.adapter.deleteObjectsByQuery(className, query, schemaController, !this.skipValidation)
303321
.catch(error => {
304322
// When deleting sessions while changing passwords, don't throw an error if they don't have any sessions.
305323
if (className === "_Session" && error.code === Parse.Error.OBJECT_NOT_FOUND) {
@@ -613,10 +631,10 @@ DatabaseController.prototype.find = function(className, query, {
613631
return Promise.resolve([]);
614632
}
615633
}
616-
let mongoWhere = this.transform.transformWhere(schema, className, query);
617634
if (!isMaster) {
618-
mongoWhere = this.transform.addReadACL(mongoWhere, aclGroup);
635+
query = addReadACL(query, aclGroup);
619636
}
637+
let mongoWhere = this.transform.transformWhere(schema, className, query);
620638
if (count) {
621639
delete mongoOptions.limit;
622640
return collection.count(mongoWhere, mongoOptions);

0 commit comments

Comments
 (0)