Skip to content

Commit 1928e55

Browse files
committed
Fix proxy hosts routes throwing errors
1 parent d40e290 commit 1928e55

File tree

3 files changed

+34
-35
lines changed

3 files changed

+34
-35
lines changed

backend/internal/proxy-host.js

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -420,41 +420,38 @@ const internalProxyHost = {
420420
* @param {String} [search_query]
421421
* @returns {Promise}
422422
*/
423-
getAll: (access, expand, search_query) => {
424-
return access
425-
.can("proxy_hosts:list")
426-
.then((access_data) => {
427-
const query = proxyHostModel
428-
.query()
429-
.where("is_deleted", 0)
430-
.groupBy("id")
431-
.allowGraph("[owner,access_list,certificate]")
432-
.orderBy(castJsonIfNeed("domain_names"), "ASC");
423+
getAll: async (access, expand, searchQuery) => {
424+
const accessData = await access.can("proxy_hosts:list");
425+
426+
const query = proxyHostModel
427+
.query()
428+
.where("is_deleted", 0)
429+
.groupBy("id")
430+
.allowGraph("[owner,access_list,certificate]")
431+
.orderBy(castJsonIfNeed("domain_names"), "ASC");
432+
433+
if (accessData.permission_visibility !== "all") {
434+
query.andWhere("owner_user_id", access.token.getUserId(1));
435+
}
433436

434-
if (access_data.permission_visibility !== "all") {
435-
query.andWhere("owner_user_id", access.token.getUserId(1));
436-
}
437+
// Query is used for searching
438+
if (typeof searchQuery === "string" && searchQuery.length > 0) {
439+
query.where(function () {
440+
this.where(castJsonIfNeed("domain_names"), "like", `%${searchQuery}%`);
441+
});
442+
}
437443

438-
// Query is used for searching
439-
if (typeof search_query === "string" && search_query.length > 0) {
440-
query.where(function () {
441-
this.where(castJsonIfNeed("domain_names"), "like", `%${search_query}%`);
442-
});
443-
}
444+
if (typeof expand !== "undefined" && expand !== null) {
445+
query.withGraphFetched(`[${expand.join(", ")}]`);
446+
}
444447

445-
if (typeof expand !== "undefined" && expand !== null) {
446-
query.withGraphFetched(`[${expand.join(", ")}]`);
447-
}
448+
const rows = await query.then(utils.omitRows(omissions()));
448449

449-
return query.then(utils.omitRows(omissions()));
450-
})
451-
.then((rows) => {
452-
if (typeof expand !== "undefined" && expand !== null && expand.indexOf("certificate") !== -1) {
453-
return internalHost.cleanAllRowsCertificateMeta(rows);
454-
}
450+
if (typeof expand !== "undefined" && expand !== null && expand.indexOf("certificate") !== -1) {
451+
return internalHost.cleanAllRowsCertificateMeta(rows);
452+
}
455453

456-
return rows;
457-
});
454+
return rows;
458455
},
459456

460457
/**

backend/lib/access.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ export default function (tokenString) {
107107
}
108108

109109
const tokenUserId = tokenData.attrs.id ? tokenData.attrs.id : 0;
110-
let query;
111110

112111
if (typeof objectCache[objectType] !== "undefined") {
113112
objects = objectCache[objectType];
@@ -120,12 +119,16 @@ export default function (tokenString) {
120119

121120
// Proxy Hosts
122121
case "proxy_hosts": {
123-
query = proxyHostModel.query().select("id").andWhere("is_deleted", 0);
122+
const query = proxyHostModel
123+
.query()
124+
.select("id")
125+
.andWhere("is_deleted", 0);
126+
124127
if (permissions.visibility === "user") {
125128
query.andWhere("owner_user_id", tokenUserId);
126129
}
127130

128-
const rows = await query();
131+
const rows = await query;
129132
objects = [];
130133
_.forEach(rows, (ruleRow) => {
131134
result.push(ruleRow.id);
@@ -141,7 +144,6 @@ export default function (tokenString) {
141144
objectCache[objectType] = objects;
142145
}
143146
}
144-
145147
return objects;
146148
};
147149

backend/nodemon.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
"ignore": [
44
"data"
55
],
6-
"ext": "js json ejs"
6+
"ext": "js json ejs cjs"
77
}

0 commit comments

Comments
 (0)