|
2 | 2 | // Parse database.
|
3 | 3 |
|
4 | 4 | import intersect from 'intersect';
|
| 5 | +import _ from 'lodash'; |
5 | 6 |
|
6 | 7 | var mongodb = require('mongodb');
|
7 | 8 | var Parse = require('parse/node').Parse;
|
8 | 9 |
|
9 | 10 | var SchemaController = require('../Controllers/SchemaController');
|
10 | 11 | const deepcopy = require('deepcopy');
|
11 | 12 |
|
| 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 | + |
12 | 27 | function DatabaseController(adapter, { skipValidation } = {}) {
|
13 | 28 | this.adapter = adapter;
|
14 | 29 |
|
@@ -161,10 +176,10 @@ DatabaseController.prototype.update = function(className, query, update, {
|
161 | 176 | if (!query) {
|
162 | 177 | return Promise.resolve();
|
163 | 178 | }
|
164 |
| - var mongoWhere = this.transform.transformWhere(schema, className, query, {validate: !this.skipValidation}); |
165 | 179 | if (acl) {
|
166 |
| - mongoWhere = this.transform.addWriteACL(mongoWhere, acl); |
| 180 | + query = addWriteACL(query, acl); |
167 | 181 | }
|
| 182 | + var mongoWhere = this.transform.transformWhere(schema, className, query, {validate: !this.skipValidation}); |
168 | 183 | mongoUpdate = this.transform.transformUpdate(schema, className, update, {validate: !this.skipValidation});
|
169 | 184 | if (many) {
|
170 | 185 | return collection.updateMany(mongoWhere, mongoUpdate);
|
@@ -299,7 +314,10 @@ DatabaseController.prototype.destroy = function(className, query, { acl } = {})
|
299 | 314 | }
|
300 | 315 | }
|
301 | 316 | // 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) |
303 | 321 | .catch(error => {
|
304 | 322 | // When deleting sessions while changing passwords, don't throw an error if they don't have any sessions.
|
305 | 323 | if (className === "_Session" && error.code === Parse.Error.OBJECT_NOT_FOUND) {
|
@@ -613,10 +631,10 @@ DatabaseController.prototype.find = function(className, query, {
|
613 | 631 | return Promise.resolve([]);
|
614 | 632 | }
|
615 | 633 | }
|
616 |
| - let mongoWhere = this.transform.transformWhere(schema, className, query); |
617 | 634 | if (!isMaster) {
|
618 |
| - mongoWhere = this.transform.addReadACL(mongoWhere, aclGroup); |
| 635 | + query = addReadACL(query, aclGroup); |
619 | 636 | }
|
| 637 | + let mongoWhere = this.transform.transformWhere(schema, className, query); |
620 | 638 | if (count) {
|
621 | 639 | delete mongoOptions.limit;
|
622 | 640 | return collection.count(mongoWhere, mongoOptions);
|
|
0 commit comments