@@ -3,13 +3,13 @@ const fs = require('fs');
33const batchflow = require ( 'batchflow' ) ;
44const logger = require ( '../logger' ) . access ;
55const error = require ( '../lib/error' ) ;
6+ const utils = require ( '../lib/utils' ) ;
67const accessListModel = require ( '../models/access_list' ) ;
78const accessListAuthModel = require ( '../models/access_list_auth' ) ;
89const accessListClientModel = require ( '../models/access_list_client' ) ;
910const proxyHostModel = require ( '../models/proxy_host' ) ;
1011const internalAuditLog = require ( './audit-log' ) ;
1112const internalNginx = require ( './nginx' ) ;
12- const utils = require ( '../lib/utils' ) ;
1313
1414function omissions ( ) {
1515 return [ 'is_deleted' ] ;
@@ -27,13 +27,13 @@ const internalAccessList = {
2727 . then ( ( /*access_data*/ ) => {
2828 return accessListModel
2929 . query ( )
30- . omit ( omissions ( ) )
3130 . insertAndFetch ( {
3231 name : data . name ,
3332 satisfy_any : data . satisfy_any ,
3433 pass_auth : data . pass_auth ,
3534 owner_user_id : access . token . getUserId ( 1 )
36- } ) ;
35+ } )
36+ . then ( utils . omitRow ( omissions ( ) ) ) ;
3737 } )
3838 . then ( ( row ) => {
3939 data . id = row . id ;
@@ -256,35 +256,31 @@ const internalAccessList = {
256256 . joinRaw ( 'LEFT JOIN `proxy_host` ON `proxy_host`.`access_list_id` = `access_list`.`id` AND `proxy_host`.`is_deleted` = 0' )
257257 . where ( 'access_list.is_deleted' , 0 )
258258 . andWhere ( 'access_list.id' , data . id )
259- . allowEager ( '[owner,items,clients,proxy_hosts.[certificate,access_list.[clients,items]]]' )
260- . omit ( [ 'access_list.is_deleted' ] )
259+ . allowGraph ( '[owner,items,clients,proxy_hosts.[certificate,access_list.[clients,items]]]' )
261260 . first ( ) ;
262261
263262 if ( access_data . permission_visibility !== 'all' ) {
264263 query . andWhere ( 'access_list.owner_user_id' , access . token . getUserId ( 1 ) ) ;
265264 }
266265
267- // Custom omissions
268- if ( typeof data . omit !== 'undefined' && data . omit !== null ) {
269- query . omit ( data . omit ) ;
270- }
271-
272266 if ( typeof data . expand !== 'undefined' && data . expand !== null ) {
273- query . eager ( '[' + data . expand . join ( ', ' ) + ']' ) ;
267+ query . withGraphFetched ( '[' + data . expand . join ( ', ' ) + ']' ) ;
274268 }
275269
276- return query ;
270+ return query . then ( utils . omitRow ( omissions ( ) ) ) ;
277271 } )
278272 . then ( ( row ) => {
279- if ( row ) {
280- if ( ! skip_masking && typeof row . items !== 'undefined' && row . items ) {
281- row = internalAccessList . maskItems ( row ) ;
282- }
283-
284- return _ . omit ( row , omissions ( ) ) ;
285- } else {
273+ if ( ! row ) {
286274 throw new error . ItemNotFoundError ( data . id ) ;
287275 }
276+ if ( ! skip_masking && typeof row . items !== 'undefined' && row . items ) {
277+ row = internalAccessList . maskItems ( row ) ;
278+ }
279+ // Custom omissions
280+ if ( typeof data . omit !== 'undefined' && data . omit !== null ) {
281+ row = _ . omit ( row , data . omit ) ;
282+ }
283+ return row ;
288284 } ) ;
289285 } ,
290286
@@ -381,8 +377,7 @@ const internalAccessList = {
381377 . joinRaw ( 'LEFT JOIN `proxy_host` ON `proxy_host`.`access_list_id` = `access_list`.`id` AND `proxy_host`.`is_deleted` = 0' )
382378 . where ( 'access_list.is_deleted' , 0 )
383379 . groupBy ( 'access_list.id' )
384- . omit ( [ 'access_list.is_deleted' ] )
385- . allowEager ( '[owner,items,clients]' )
380+ . allowGraph ( '[owner,items,clients]' )
386381 . orderBy ( 'access_list.name' , 'ASC' ) ;
387382
388383 if ( access_data . permission_visibility !== 'all' ) {
@@ -397,10 +392,10 @@ const internalAccessList = {
397392 }
398393
399394 if ( typeof expand !== 'undefined' && expand !== null ) {
400- query . eager ( '[' + expand . join ( ', ' ) + ']' ) ;
395+ query . withGraphFetched ( '[' + expand . join ( ', ' ) + ']' ) ;
401396 }
402397
403- return query ;
398+ return query . then ( utils . omitRows ( omissions ( ) ) ) ;
404399 } )
405400 . then ( ( rows ) => {
406401 if ( rows ) {
0 commit comments