@@ -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 => {
@@ -609,7 +595,7 @@ DatabaseController.prototype.find = function(className, query, options = {}) {
609
595
if ( options . sort ) {
610
596
mongoOptions . sort = { } ;
611
597
for ( let key in options . sort ) {
612
- let mongoKey = transform . transformKey ( schema , className , key ) ;
598
+ let mongoKey = this . adapter . transform . transformKey ( schema , className , key ) ;
613
599
mongoOptions . sort [ mongoKey ] = options . sort [ key ] ;
614
600
}
615
601
}
@@ -626,16 +612,9 @@ DatabaseController.prototype.find = function(className, query, options = {}) {
626
612
. then ( ( ) => this . reduceInRelation ( className , query , schema ) )
627
613
. then ( ( ) => this . adaptiveCollection ( className ) )
628
614
. then ( collection => {
629
- let mongoWhere = transform . transformWhere ( schema , className , query ) ;
615
+ let mongoWhere = this . adapter . transform . transformWhere ( schema , className , query ) ;
630
616
if ( ! isMaster ) {
631
- let orParts = [
632
- { "_rperm" : { "$exists" : false } } ,
633
- { "_rperm" : { "$in" : [ "*" ] } }
634
- ] ;
635
- for ( let acl of aclGroup ) {
636
- orParts . push ( { "_rperm" : { "$in" : [ acl ] } } ) ;
637
- }
638
- mongoWhere = { '$and' : [ mongoWhere , { '$or' : orParts } ] } ;
617
+ mongoWhere = this . adapter . transform . addReadACL ( mongoWhere , aclGroup ) ;
639
618
}
640
619
if ( options . count ) {
641
620
delete mongoOptions . limit ;
0 commit comments