@@ -5,7 +5,6 @@ var mongodb = require('mongodb');
5
5
var Parse = require ( 'parse/node' ) . Parse ;
6
6
7
7
var Schema = require ( './../Schema' ) ;
8
- var transform = require ( './../transform' ) ;
9
8
const deepcopy = require ( 'deepcopy' ) ;
10
9
11
10
// options can contain:
@@ -115,7 +114,7 @@ DatabaseController.prototype.validateObject = function(className, object, query,
115
114
// Filters out any data that shouldn't be on this REST-formatted object.
116
115
DatabaseController . prototype . untransformObject = function (
117
116
schema , isMaster , aclGroup , className , mongoObject ) {
118
- var object = transform . untransformObject ( schema , className , mongoObject ) ;
117
+ var object = this . adapter . transform . untransformObject ( schema , className , mongoObject ) ;
119
118
120
119
if ( className !== '_User' ) {
121
120
return object ;
@@ -161,17 +160,11 @@ DatabaseController.prototype.update = function(className, query, update, options
161
160
. then ( ( ) => this . handleRelationUpdates ( className , query . objectId , update ) )
162
161
. then ( ( ) => this . adaptiveCollection ( className ) )
163
162
. then ( collection => {
164
- var mongoWhere = transform . transformWhere ( schema , className , query ) ;
163
+ var mongoWhere = this . adapter . transform . transformWhere ( schema , className , query ) ;
165
164
if ( options . acl ) {
166
- var writePerms = [
167
- { _wperm : { '$exists' : false } }
168
- ] ;
169
- for ( var entry of options . acl ) {
170
- writePerms . push ( { _wperm : { '$in' : [ entry ] } } ) ;
171
- }
172
- mongoWhere = { '$and' : [ mongoWhere , { '$or' : writePerms } ] } ;
165
+ mongoWhere = this . adapter . transform . addWriteACL ( mongoWhere , options . acl ) ;
173
166
}
174
- mongoUpdate = transform . transformUpdate ( schema , className , update ) ;
167
+ mongoUpdate = this . adapter . transform . transformUpdate ( schema , className , update ) ;
175
168
return collection . findOneAndUpdate ( mongoWhere , mongoUpdate ) ;
176
169
} )
177
170
. then ( result => {
@@ -298,16 +291,9 @@ DatabaseController.prototype.destroy = function(className, query, options = {})
298
291
} )
299
292
. then ( ( ) => this . adaptiveCollection ( className ) )
300
293
. then ( collection => {
301
- let mongoWhere = transform . transformWhere ( schema , className , query ) ;
302
-
294
+ let mongoWhere = this . adapter . transform . transformWhere ( schema , className , query , options ) ;
303
295
if ( options . acl ) {
304
- var writePerms = [
305
- { _wperm : { '$exists' : false } }
306
- ] ;
307
- for ( var entry of options . acl ) {
308
- writePerms . push ( { _wperm : { '$in' : [ entry ] } } ) ;
309
- }
310
- mongoWhere = { '$and' : [ mongoWhere , { '$or' : writePerms } ] } ;
296
+ mongoWhere = this . adapter . transform . addWriteACL ( mongoWhere , options . acl ) ;
311
297
}
312
298
return collection . deleteMany ( mongoWhere ) ;
313
299
} )
@@ -343,7 +329,7 @@ DatabaseController.prototype.create = function(className, object, options) {
343
329
. then ( ( ) => this . handleRelationUpdates ( className , null , object ) )
344
330
. then ( ( ) => this . adaptiveCollection ( className ) )
345
331
. then ( coll => {
346
- var mongoObject = transform . transformCreate ( schema , className , object ) ;
332
+ var mongoObject = this . adapter . transform . transformCreate ( schema , className , object ) ;
347
333
return coll . insertOne ( mongoObject ) ;
348
334
} )
349
335
. then ( result => {
@@ -537,7 +523,7 @@ DatabaseController.prototype.find = function(className, query, options = {}) {
537
523
if ( options . sort ) {
538
524
mongoOptions . sort = { } ;
539
525
for ( var key in options . sort ) {
540
- var mongoKey = transform . transformKey ( schema , className , key ) ;
526
+ var mongoKey = this . adapter . transform . transformKey ( schema , className , key ) ;
541
527
mongoOptions . sort [ mongoKey ] = options . sort [ key ] ;
542
528
}
543
529
}
@@ -558,16 +544,9 @@ DatabaseController.prototype.find = function(className, query, options = {}) {
558
544
} ) . then ( ( ) => {
559
545
return this . adaptiveCollection ( className ) ;
560
546
} ) . then ( collection => {
561
- var mongoWhere = transform . transformWhere ( schema , className , query ) ;
547
+ var mongoWhere = this . adapter . transform . transformWhere ( schema , className , query ) ;
562
548
if ( ! isMaster ) {
563
- var orParts = [
564
- { "_rperm" : { "$exists" : false } } ,
565
- { "_rperm" : { "$in" : [ "*" ] } }
566
- ] ;
567
- for ( var acl of aclGroup ) {
568
- orParts . push ( { "_rperm" : { "$in" : [ acl ] } } ) ;
569
- }
570
- mongoWhere = { '$and' : [ mongoWhere , { '$or' : orParts } ] } ;
549
+ mongoWhere = this . adapter . transform . addReadACL ( mongoWhere , aclGroup ) ;
571
550
}
572
551
if ( options . count ) {
573
552
delete mongoOptions . limit ;
0 commit comments