From a7d4fd55d9a53a32d2f8555cc9310852a33b3d09 Mon Sep 17 00:00:00 2001 From: Jamie Curnow Date: Wed, 10 Sep 2025 22:39:00 +1000 Subject: [PATCH] Fix proxy hosts routes throwing errors --- backend/internal/proxy-host.js | 59 ++++++++++++++++------------------ backend/lib/access.js | 10 +++--- backend/nodemon.json | 2 +- 3 files changed, 35 insertions(+), 36 deletions(-) diff --git a/backend/internal/proxy-host.js b/backend/internal/proxy-host.js index 1c51d801..2fb4d164 100644 --- a/backend/internal/proxy-host.js +++ b/backend/internal/proxy-host.js @@ -420,41 +420,38 @@ const internalProxyHost = { * @param {String} [search_query] * @returns {Promise} */ - getAll: (access, expand, search_query) => { - return access - .can("proxy_hosts:list") - .then((access_data) => { - const query = proxyHostModel - .query() - .where("is_deleted", 0) - .groupBy("id") - .allowGraph("[owner,access_list,certificate]") - .orderBy(castJsonIfNeed("domain_names"), "ASC"); + getAll: async (access, expand, searchQuery) => { + const accessData = await access.can("proxy_hosts:list"); - if (access_data.permission_visibility !== "all") { - query.andWhere("owner_user_id", access.token.getUserId(1)); - } + const query = proxyHostModel + .query() + .where("is_deleted", 0) + .groupBy("id") + .allowGraph("[owner,access_list,certificate]") + .orderBy(castJsonIfNeed("domain_names"), "ASC"); - // Query is used for searching - if (typeof search_query === "string" && search_query.length > 0) { - query.where(function () { - this.where(castJsonIfNeed("domain_names"), "like", `%${search_query}%`); - }); - } + if (accessData.permission_visibility !== "all") { + query.andWhere("owner_user_id", access.token.getUserId(1)); + } - if (typeof expand !== "undefined" && expand !== null) { - query.withGraphFetched(`[${expand.join(", ")}]`); - } - - return query.then(utils.omitRows(omissions())); - }) - .then((rows) => { - if (typeof expand !== "undefined" && expand !== null && expand.indexOf("certificate") !== -1) { - return internalHost.cleanAllRowsCertificateMeta(rows); - } - - return rows; + // Query is used for searching + if (typeof searchQuery === "string" && searchQuery.length > 0) { + query.where(function () { + this.where(castJsonIfNeed("domain_names"), "like", `%${searchQuery}%`); }); + } + + if (typeof expand !== "undefined" && expand !== null) { + query.withGraphFetched(`[${expand.join(", ")}]`); + } + + const rows = await query.then(utils.omitRows(omissions())); + + if (typeof expand !== "undefined" && expand !== null && expand.indexOf("certificate") !== -1) { + return internalHost.cleanAllRowsCertificateMeta(rows); + } + + return rows; }, /** diff --git a/backend/lib/access.js b/backend/lib/access.js index 783c416f..133a24f5 100644 --- a/backend/lib/access.js +++ b/backend/lib/access.js @@ -107,7 +107,6 @@ export default function (tokenString) { } const tokenUserId = tokenData.attrs.id ? tokenData.attrs.id : 0; - let query; if (typeof objectCache[objectType] !== "undefined") { objects = objectCache[objectType]; @@ -120,12 +119,16 @@ export default function (tokenString) { // Proxy Hosts case "proxy_hosts": { - query = proxyHostModel.query().select("id").andWhere("is_deleted", 0); + const query = proxyHostModel + .query() + .select("id") + .andWhere("is_deleted", 0); + if (permissions.visibility === "user") { query.andWhere("owner_user_id", tokenUserId); } - const rows = await query(); + const rows = await query; objects = []; _.forEach(rows, (ruleRow) => { result.push(ruleRow.id); @@ -141,7 +144,6 @@ export default function (tokenString) { objectCache[objectType] = objects; } } - return objects; }; diff --git a/backend/nodemon.json b/backend/nodemon.json index 3d6d1342..90223a21 100644 --- a/backend/nodemon.json +++ b/backend/nodemon.json @@ -3,5 +3,5 @@ "ignore": [ "data" ], - "ext": "js json ejs" + "ext": "js json ejs cjs" }