@@ -7,7 +7,6 @@ var mongodb = require('mongodb');
77var Parse = require ( 'parse/node' ) . Parse ;
88
99var Schema = require ( './../Schema' ) ;
10- var transform = require ( './../transform' ) ;
1110const deepcopy = require ( 'deepcopy' ) ;
1211
1312// options can contain:
@@ -122,7 +121,7 @@ DatabaseController.prototype.validateObject = function(className, object, query,
122121// Filters out any data that shouldn't be on this REST-formatted object.
123122DatabaseController . prototype . untransformObject = function (
124123 schema , isMaster , aclGroup , className , mongoObject ) {
125- var object = transform . untransformObject ( schema , className , mongoObject ) ;
124+ var object = this . adapter . transform . untransformObject ( schema , className , mongoObject ) ;
126125
127126 if ( className !== '_User' ) {
128127 return object ;
@@ -168,17 +167,11 @@ DatabaseController.prototype.update = function(className, query, update, options
168167 . then ( ( ) => this . handleRelationUpdates ( className , query . objectId , update ) )
169168 . then ( ( ) => this . adaptiveCollection ( className ) )
170169 . then ( collection => {
171- var mongoWhere = transform . transformWhere ( schema , className , query ) ;
170+ var mongoWhere = this . adapter . transform . transformWhere ( schema , className , query ) ;
172171 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 ) ;
180173 }
181- mongoUpdate = transform . transformUpdate ( schema , className , update ) ;
174+ mongoUpdate = this . adapter . transform . transformUpdate ( schema , className , update ) ;
182175 return collection . findOneAndUpdate ( mongoWhere , mongoUpdate ) ;
183176 } )
184177 . then ( result => {
@@ -305,16 +298,9 @@ DatabaseController.prototype.destroy = function(className, query, options = {})
305298 } )
306299 . then ( ( ) => this . adaptiveCollection ( className ) )
307300 . then ( collection => {
308- let mongoWhere = transform . transformWhere ( schema , className , query ) ;
309-
301+ let mongoWhere = this . adapter . transform . transformWhere ( schema , className , query , options ) ;
310302 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 ) ;
318304 }
319305 return collection . deleteMany ( mongoWhere ) ;
320306 } )
@@ -350,7 +336,7 @@ DatabaseController.prototype.create = function(className, object, options) {
350336 . then ( ( ) => this . handleRelationUpdates ( className , null , object ) )
351337 . then ( ( ) => this . adaptiveCollection ( className ) )
352338 . then ( coll => {
353- var mongoObject = transform . transformCreate ( schema , className , object ) ;
339+ var mongoObject = this . adapter . transform . transformCreate ( schema , className , object ) ;
354340 return coll . insertOne ( mongoObject ) ;
355341 } )
356342 . then ( result => {
@@ -609,7 +595,7 @@ DatabaseController.prototype.find = function(className, query, options = {}) {
609595 if ( options . sort ) {
610596 mongoOptions . sort = { } ;
611597 for ( let key in options . sort ) {
612- let mongoKey = transform . transformKey ( schema , className , key ) ;
598+ let mongoKey = this . adapter . transform . transformKey ( schema , className , key ) ;
613599 mongoOptions . sort [ mongoKey ] = options . sort [ key ] ;
614600 }
615601 }
@@ -626,16 +612,9 @@ DatabaseController.prototype.find = function(className, query, options = {}) {
626612 . then ( ( ) => this . reduceInRelation ( className , query , schema ) )
627613 . then ( ( ) => this . adaptiveCollection ( className ) )
628614 . then ( collection => {
629- let mongoWhere = transform . transformWhere ( schema , className , query ) ;
615+ let mongoWhere = this . adapter . transform . transformWhere ( schema , className , query ) ;
630616 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 ) ;
639618 }
640619 if ( options . count ) {
641620 delete mongoOptions . limit ;
0 commit comments