@@ -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:
@@ -121,7 +120,7 @@ DatabaseController.prototype.validateObject = function(className, object, query,
121
120
// Filters out any data that shouldn't be on this REST-formatted object.
122
121
DatabaseController . prototype . untransformObject = function (
123
122
schema , isMaster , aclGroup , className , mongoObject ) {
124
- var object = transform . untransformObject ( schema , className , mongoObject ) ;
123
+ var object = this . adapter . transform . untransformObject ( schema , className , mongoObject ) ;
125
124
126
125
if ( className !== '_User' ) {
127
126
return object ;
@@ -167,17 +166,11 @@ DatabaseController.prototype.update = function(className, query, update, options
167
166
. then ( ( ) => this . handleRelationUpdates ( className , query . objectId , update ) )
168
167
. then ( ( ) => this . adaptiveCollection ( className ) )
169
168
. then ( collection => {
170
- var mongoWhere = transform . transformWhere ( schema , className , query ) ;
169
+ var mongoWhere = this . adapter . transform . transformWhere ( schema , className , query ) ;
171
170
if ( options . acl ) {
172
- var writePerms = [
173
- { _wperm : { '$exists' : false } }
174
- ] ;
175
- for ( var entry of options . acl ) {
176
- writePerms . push ( { _wperm : { '$in' : [ entry ] } } ) ;
177
- }
178
- mongoWhere = { '$and' : [ mongoWhere , { '$or' : writePerms } ] } ;
171
+ mongoWhere = this . adapter . transform . addWriteACL ( mongoWhere , options . acl ) ;
179
172
}
180
- mongoUpdate = transform . transformUpdate ( schema , className , update ) ;
173
+ mongoUpdate = this . adapter . transform . transformUpdate ( schema , className , update ) ;
181
174
return collection . findOneAndUpdate ( mongoWhere , mongoUpdate ) ;
182
175
} )
183
176
. then ( result => {
@@ -304,16 +297,9 @@ DatabaseController.prototype.destroy = function(className, query, options = {})
304
297
} )
305
298
. then ( ( ) => this . adaptiveCollection ( className ) )
306
299
. then ( collection => {
307
- let mongoWhere = transform . transformWhere ( schema , className , query ) ;
308
-
300
+ let mongoWhere = this . adapter . transform . transformWhere ( schema , className , query , options ) ;
309
301
if ( options . acl ) {
310
- var writePerms = [
311
- { _wperm : { '$exists' : false } }
312
- ] ;
313
- for ( var entry of options . acl ) {
314
- writePerms . push ( { _wperm : { '$in' : [ entry ] } } ) ;
315
- }
316
- mongoWhere = { '$and' : [ mongoWhere , { '$or' : writePerms } ] } ;
302
+ mongoWhere = this . adapter . transform . addWriteACL ( mongoWhere , options . acl ) ;
317
303
}
318
304
return collection . deleteMany ( mongoWhere ) ;
319
305
} )
@@ -349,7 +335,7 @@ DatabaseController.prototype.create = function(className, object, options) {
349
335
. then ( ( ) => this . handleRelationUpdates ( className , null , object ) )
350
336
. then ( ( ) => this . adaptiveCollection ( className ) )
351
337
. then ( coll => {
352
- var mongoObject = transform . transformCreate ( schema , className , object ) ;
338
+ var mongoObject = this . adapter . transform . transformCreate ( schema , className , object ) ;
353
339
return coll . insertOne ( mongoObject ) ;
354
340
} )
355
341
. then ( result => {
@@ -606,7 +592,7 @@ DatabaseController.prototype.find = function(className, query, options = {}) {
606
592
if ( options . sort ) {
607
593
mongoOptions . sort = { } ;
608
594
for ( let key in options . sort ) {
609
- let mongoKey = transform . transformKey ( schema , className , key ) ;
595
+ let mongoKey = this . adapter . transform . transformKey ( schema , className , key ) ;
610
596
mongoOptions . sort [ mongoKey ] = options . sort [ key ] ;
611
597
}
612
598
}
@@ -623,16 +609,9 @@ DatabaseController.prototype.find = function(className, query, options = {}) {
623
609
. then ( ( ) => this . reduceInRelation ( className , query , schema ) )
624
610
. then ( ( ) => this . adaptiveCollection ( className ) )
625
611
. then ( collection => {
626
- let mongoWhere = transform . transformWhere ( schema , className , query ) ;
612
+ let mongoWhere = this . adapter . transform . transformWhere ( schema , className , query ) ;
627
613
if ( ! isMaster ) {
628
- let orParts = [
629
- { "_rperm" : { "$exists" : false } } ,
630
- { "_rperm" : { "$in" : [ "*" ] } }
631
- ] ;
632
- for ( let acl of aclGroup ) {
633
- orParts . push ( { "_rperm" : { "$in" : [ acl ] } } ) ;
634
- }
635
- mongoWhere = { '$and' : [ mongoWhere , { '$or' : orParts } ] } ;
614
+ mongoWhere = this . adapter . transform . addReadACL ( mongoWhere , aclGroup ) ;
636
615
}
637
616
if ( options . count ) {
638
617
delete mongoOptions . limit ;
0 commit comments