always load access list details for proxy host

This commit is contained in:
Kyle Klaus 2020-05-11 08:49:25 -07:00
parent 64922f07ff
commit c895a852fb
4 changed files with 29 additions and 13 deletions

View file

@ -71,7 +71,7 @@ const internalAccessList = {
// re-fetch with expansions // re-fetch with expansions
return internalAccessList.get(access, { return internalAccessList.get(access, {
id: data.id, id: data.id,
expand: ['owner', 'items', 'clients', 'proxy_hosts.access_list.clients'] expand: ['owner', 'items', 'clients', 'proxy_hosts']
}, true /* <- skip masking */); }, true /* <- skip masking */);
}) })
.then((row) => { .then((row) => {
@ -216,10 +216,11 @@ const internalAccessList = {
// re-fetch with expansions // re-fetch with expansions
return internalAccessList.get(access, { return internalAccessList.get(access, {
id: data.id, id: data.id,
expand: ['owner', 'items', 'clients', 'proxy_hosts.access_list.clients'] expand: ['owner', 'items', 'clients', 'proxy_hosts']
}, true /* <- skip masking */); }, true /* <- skip masking */);
}) })
.then((row) => { .then((row) => {
console.log(row);
return internalAccessList.build(row) return internalAccessList.build(row)
.then(() => { .then(() => {
if (row.proxy_host_count) { if (row.proxy_host_count) {
@ -254,7 +255,7 @@ const internalAccessList = {
.joinRaw('LEFT JOIN `proxy_host` ON `proxy_host`.`access_list_id` = `access_list`.`id` AND `proxy_host`.`is_deleted` = 0') .joinRaw('LEFT JOIN `proxy_host` ON `proxy_host`.`access_list_id` = `access_list`.`id` AND `proxy_host`.`is_deleted` = 0')
.where('access_list.is_deleted', 0) .where('access_list.is_deleted', 0)
.andWhere('access_list.id', data.id) .andWhere('access_list.id', data.id)
.allowEager('[owner,items,clients,proxy_hosts,proxy_hosts.access_list.clients]') .allowEager('[owner, items, clients, proxy_hosts]')
.omit(['access_list.is_deleted']) .omit(['access_list.is_deleted'])
.first(); .first();

View file

@ -73,7 +73,7 @@ const internalProxyHost = {
// re-fetch with cert // re-fetch with cert
return internalProxyHost.get(access, { return internalProxyHost.get(access, {
id: row.id, id: row.id,
expand: ['certificate', 'owner', 'access_list.clients'] expand: ['certificate', 'owner']
}); });
}) })
.then((row) => { .then((row) => {
@ -186,7 +186,7 @@ const internalProxyHost = {
.then(() => { .then(() => {
return internalProxyHost.get(access, { return internalProxyHost.get(access, {
id: data.id, id: data.id,
expand: ['owner', 'certificate', 'access_list.clients'] expand: ['owner', 'certificate']
}) })
.then((row) => { .then((row) => {
// Configure nginx // Configure nginx
@ -219,7 +219,6 @@ const internalProxyHost = {
.query() .query()
.where('is_deleted', 0) .where('is_deleted', 0)
.andWhere('id', data.id) .andWhere('id', data.id)
.allowEager('[owner,access_list,access_list.clients,certificate]')
.first(); .first();
if (access_data.permission_visibility !== 'all') { if (access_data.permission_visibility !== 'all') {
@ -304,7 +303,7 @@ const internalProxyHost = {
.then(() => { .then(() => {
return internalProxyHost.get(access, { return internalProxyHost.get(access, {
id: data.id, id: data.id,
expand: ['certificate', 'owner', 'access_list'] expand: ['certificate', 'owner']
}); });
}) })
.then((row) => { .then((row) => {
@ -406,7 +405,7 @@ const internalProxyHost = {
.where('is_deleted', 0) .where('is_deleted', 0)
.groupBy('id') .groupBy('id')
.omit(['is_deleted']) .omit(['is_deleted'])
.allowEager('[owner,access_list,certificate]') .allowGraph('[owner,certificate]')
.orderBy('domain_names', 'ASC'); .orderBy('domain_names', 'ASC');
if (access_data.permission_visibility !== 'all') { if (access_data.permission_visibility !== 'all') {

View file

@ -6,6 +6,7 @@ const Model = require('objection').Model;
const User = require('./user'); const User = require('./user');
const AccessList = require('./access_list'); const AccessList = require('./access_list');
const Certificate = require('./certificate'); const Certificate = require('./certificate');
const ProxyHostQueryBuilder = require('../query/proxy_host');
Model.knex(db); Model.knex(db);
@ -36,6 +37,10 @@ class ProxyHost extends Model {
} }
} }
static get QueryBuilder() {
return ProxyHostQueryBuilder;
}
static get name () { static get name () {
return 'ProxyHost'; return 'ProxyHost';
} }

View file

@ -0,0 +1,11 @@
const QueryBuilder = require('objection').QueryBuilder;
class ProxyHostQueryBuilder extends QueryBuilder {
execute () {
this.allowGraph('[access_list.[items, clients]]');
this.withGraphFetched('[access_list.[items, clients]]');
return super.execute();
}
}
module.exports = ProxyHostQueryBuilder;