@@ -7,7 +7,6 @@ var mongodb = require('mongodb');
7
7
var Parse = require ( 'parse/node' ) . Parse ;
8
8
9
9
var Schema = require ( './../Schema' ) ;
10
- var transform = require ( './../transform' ) ;
11
10
const deepcopy = require ( 'deepcopy' ) ;
12
11
13
12
// options can contain:
@@ -122,7 +121,7 @@ DatabaseController.prototype.validateObject = function(className, object, query,
122
121
// Filters out any data that shouldn't be on this REST-formatted object.
123
122
DatabaseController . prototype . untransformObject = function (
124
123
schema , isMaster , aclGroup , className , mongoObject ) {
125
- var object = transform . untransformObject ( schema , className , mongoObject ) ;
124
+ var object = this . adapter . transform . untransformObject ( schema , className , mongoObject ) ;
126
125
127
126
if ( className !== '_User' ) {
128
127
return object ;
@@ -168,17 +167,11 @@ DatabaseController.prototype.update = function(className, query, update, options
168
167
. then ( ( ) => this . handleRelationUpdates ( className , query . objectId , update ) )
169
168
. then ( ( ) => this . adaptiveCollection ( className ) )
170
169
. then ( collection => {
171
- var mongoWhere = transform . transformWhere ( schema , className , query ) ;
170
+ var mongoWhere = this . adapter . transform . transformWhere ( schema , className , query ) ;
172
171
if ( options . acl ) {
173
- var writePerms = [
174
- { _wperm : { '$exists' : false } }
175
- ] ;
176
- for ( var entry of options . acl ) {
177
- writePerms . push ( { _wperm : { '$in' : [ entry ] } } ) ;
178
- }
179
- mongoWhere = { '$and' : [ mongoWhere , { '$or' : writePerms } ] } ;
172
+ mongoWhere = this . adapter . transform . addWriteACL ( mongoWhere , options . acl ) ;
180
173
}
181
- mongoUpdate = transform . transformUpdate ( schema , className , update ) ;
174
+ mongoUpdate = this . adapter . transform . transformUpdate ( schema , className , update ) ;
182
175
return collection . findOneAndUpdate ( mongoWhere , mongoUpdate ) ;
183
176
} )
184
177
. then ( result => {
@@ -305,16 +298,9 @@ DatabaseController.prototype.destroy = function(className, query, options = {})
305
298
} )
306
299
. then ( ( ) => this . adaptiveCollection ( className ) )
307
300
. then ( collection => {
308
- let mongoWhere = transform . transformWhere ( schema , className , query ) ;
309
-
301
+ let mongoWhere = this . adapter . transform . transformWhere ( schema , className , query , options ) ;
310
302
if ( options . acl ) {
311
- var writePerms = [
312
- { _wperm : { '$exists' : false } }
313
- ] ;
314
- for ( var entry of options . acl ) {
315
- writePerms . push ( { _wperm : { '$in' : [ entry ] } } ) ;
316
- }
317
- mongoWhere = { '$and' : [ mongoWhere , { '$or' : writePerms } ] } ;
303
+ mongoWhere = this . adapter . transform . addWriteACL ( mongoWhere , options . acl ) ;
318
304
}
319
305
return collection . deleteMany ( mongoWhere ) ;
320
306
} )
@@ -350,7 +336,7 @@ DatabaseController.prototype.create = function(className, object, options) {
350
336
. then ( ( ) => this . handleRelationUpdates ( className , null , object ) )
351
337
. then ( ( ) => this . adaptiveCollection ( className ) )
352
338
. then ( coll => {
353
- var mongoObject = transform . transformCreate ( schema , className , object ) ;
339
+ var mongoObject = this . adapter . transform . transformCreate ( schema , className , object ) ;
354
340
return coll . insertOne ( mongoObject ) ;
355
341
} )
356
342
. then ( result => {
@@ -552,7 +538,7 @@ DatabaseController.prototype.find = function(className, query, options = {}) {
552
538
if ( options . sort ) {
553
539
mongoOptions . sort = { } ;
554
540
for ( let key in options . sort ) {
555
- let mongoKey = transform . transformKey ( schema , className , key ) ;
541
+ let mongoKey = this . adapter . transform . transformKey ( schema , className , key ) ;
556
542
mongoOptions . sort [ mongoKey ] = options . sort [ key ] ;
557
543
}
558
544
}
@@ -569,16 +555,9 @@ DatabaseController.prototype.find = function(className, query, options = {}) {
569
555
. then ( ( ) => this . reduceInRelation ( className , query , schema ) )
570
556
. then ( ( ) => this . adaptiveCollection ( className ) )
571
557
. then ( collection => {
572
- let mongoWhere = transform . transformWhere ( schema , className , query ) ;
558
+ let mongoWhere = this . adapter . transform . transformWhere ( schema , className , query ) ;
573
559
if ( ! isMaster ) {
574
- let orParts = [
575
- { "_rperm" : { "$exists" : false } } ,
576
- { "_rperm" : { "$in" : [ "*" ] } }
577
- ] ;
578
- for ( let acl of aclGroup ) {
579
- orParts . push ( { "_rperm" : { "$in" : [ acl ] } } ) ;
580
- }
581
- mongoWhere = { '$and' : [ mongoWhere , { '$or' : orParts } ] } ;
560
+ mongoWhere = this . adapter . transform . addReadACL ( mongoWhere , aclGroup ) ;
582
561
}
583
562
if ( options . count ) {
584
563
delete mongoOptions . limit ;
0 commit comments