@@ -3,13 +3,13 @@ const fs = require('fs');
3
3
const batchflow = require ( 'batchflow' ) ;
4
4
const logger = require ( '../logger' ) . access ;
5
5
const error = require ( '../lib/error' ) ;
6
+ const utils = require ( '../lib/utils' ) ;
6
7
const accessListModel = require ( '../models/access_list' ) ;
7
8
const accessListAuthModel = require ( '../models/access_list_auth' ) ;
8
9
const accessListClientModel = require ( '../models/access_list_client' ) ;
9
10
const proxyHostModel = require ( '../models/proxy_host' ) ;
10
11
const internalAuditLog = require ( './audit-log' ) ;
11
12
const internalNginx = require ( './nginx' ) ;
12
- const utils = require ( '../lib/utils' ) ;
13
13
14
14
function omissions ( ) {
15
15
return [ 'is_deleted' ] ;
@@ -27,13 +27,13 @@ const internalAccessList = {
27
27
. then ( ( /*access_data*/ ) => {
28
28
return accessListModel
29
29
. query ( )
30
- . omit ( omissions ( ) )
31
30
. insertAndFetch ( {
32
31
name : data . name ,
33
32
satisfy_any : data . satisfy_any ,
34
33
pass_auth : data . pass_auth ,
35
34
owner_user_id : access . token . getUserId ( 1 )
36
- } ) ;
35
+ } )
36
+ . then ( utils . omitRow ( omissions ( ) ) ) ;
37
37
} )
38
38
. then ( ( row ) => {
39
39
data . id = row . id ;
@@ -256,35 +256,31 @@ const internalAccessList = {
256
256
. joinRaw ( 'LEFT JOIN `proxy_host` ON `proxy_host`.`access_list_id` = `access_list`.`id` AND `proxy_host`.`is_deleted` = 0' )
257
257
. where ( 'access_list.is_deleted' , 0 )
258
258
. 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]]]' )
261
260
. first ( ) ;
262
261
263
262
if ( access_data . permission_visibility !== 'all' ) {
264
263
query . andWhere ( 'access_list.owner_user_id' , access . token . getUserId ( 1 ) ) ;
265
264
}
266
265
267
- // Custom omissions
268
- if ( typeof data . omit !== 'undefined' && data . omit !== null ) {
269
- query . omit ( data . omit ) ;
270
- }
271
-
272
266
if ( typeof data . expand !== 'undefined' && data . expand !== null ) {
273
- query . eager ( '[' + data . expand . join ( ', ' ) + ']' ) ;
267
+ query . withGraphFetched ( '[' + data . expand . join ( ', ' ) + ']' ) ;
274
268
}
275
269
276
- return query ;
270
+ return query . then ( utils . omitRow ( omissions ( ) ) ) ;
277
271
} )
278
272
. 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 ) {
286
274
throw new error . ItemNotFoundError ( data . id ) ;
287
275
}
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 ;
288
284
} ) ;
289
285
} ,
290
286
@@ -381,8 +377,7 @@ const internalAccessList = {
381
377
. joinRaw ( 'LEFT JOIN `proxy_host` ON `proxy_host`.`access_list_id` = `access_list`.`id` AND `proxy_host`.`is_deleted` = 0' )
382
378
. where ( 'access_list.is_deleted' , 0 )
383
379
. groupBy ( 'access_list.id' )
384
- . omit ( [ 'access_list.is_deleted' ] )
385
- . allowEager ( '[owner,items,clients]' )
380
+ . allowGraph ( '[owner,items,clients]' )
386
381
. orderBy ( 'access_list.name' , 'ASC' ) ;
387
382
388
383
if ( access_data . permission_visibility !== 'all' ) {
@@ -397,10 +392,10 @@ const internalAccessList = {
397
392
}
398
393
399
394
if ( typeof expand !== 'undefined' && expand !== null ) {
400
- query . eager ( '[' + expand . join ( ', ' ) + ']' ) ;
395
+ query . withGraphFetched ( '[' + expand . join ( ', ' ) + ']' ) ;
401
396
}
402
397
403
- return query ;
398
+ return query . then ( utils . omitRows ( omissions ( ) ) ) ;
404
399
} )
405
400
. then ( ( rows ) => {
406
401
if ( rows ) {
0 commit comments