mirror of
https://github.com/fosrl/pangolin.git
synced 2026-06-17 21:01:53 +00:00
@@ -327,27 +327,6 @@ export async function listSites(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
let accessibleSites;
|
|
||||||
if (req.user) {
|
|
||||||
accessibleSites = await db
|
|
||||||
.select({
|
|
||||||
siteId: sql<number>`COALESCE(${userSites.siteId}, ${roleSites.siteId})`
|
|
||||||
})
|
|
||||||
.from(userSites)
|
|
||||||
.fullJoin(roleSites, eq(userSites.siteId, roleSites.siteId))
|
|
||||||
.where(
|
|
||||||
or(
|
|
||||||
eq(userSites.userId, req.user!.userId),
|
|
||||||
inArray(roleSites.roleId, req.userOrgRoleIds!)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
accessibleSites = await db
|
|
||||||
.select({ siteId: sites.siteId })
|
|
||||||
.from(sites)
|
|
||||||
.where(eq(sites.orgId, orgId));
|
|
||||||
}
|
|
||||||
|
|
||||||
const isLabelFeatureEnabled = await isLicensedOrSubscribed(
|
const isLabelFeatureEnabled = await isLicensedOrSubscribed(
|
||||||
orgId,
|
orgId,
|
||||||
tierMatrix.labels
|
tierMatrix.labels
|
||||||
@@ -364,14 +343,38 @@ export async function listSites(
|
|||||||
labels: labelFilter
|
labels: labelFilter
|
||||||
} = parsedQuery.data;
|
} = parsedQuery.data;
|
||||||
|
|
||||||
const accessibleSiteIds = accessibleSites.map((site) => site.siteId);
|
const conditions = [eq(sites.orgId, orgId)];
|
||||||
|
|
||||||
const conditions = [
|
if (req.user) {
|
||||||
and(
|
const userAccessConditions = [
|
||||||
inArray(sites.siteId, accessibleSiteIds),
|
inArray(
|
||||||
eq(sites.orgId, orgId)
|
sites.siteId,
|
||||||
)
|
db
|
||||||
];
|
.select({ siteId: userSites.siteId })
|
||||||
|
.from(userSites)
|
||||||
|
.where(eq(userSites.userId, req.user.userId))
|
||||||
|
)
|
||||||
|
];
|
||||||
|
|
||||||
|
const roleIds = req.userOrgRoleIds ?? [];
|
||||||
|
if (roleIds.length > 0) {
|
||||||
|
userAccessConditions.push(
|
||||||
|
inArray(
|
||||||
|
sites.siteId,
|
||||||
|
db
|
||||||
|
.select({ siteId: roleSites.siteId })
|
||||||
|
.from(roleSites)
|
||||||
|
.where(inArray(roleSites.roleId, roleIds))
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
conditions.push(
|
||||||
|
userAccessConditions.length === 1
|
||||||
|
? userAccessConditions[0]
|
||||||
|
: or(...userAccessConditions)!
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if (typeof online !== "undefined") {
|
if (typeof online !== "undefined") {
|
||||||
conditions.push(eq(sites.online, online));
|
conditions.push(eq(sites.online, online));
|
||||||
@@ -418,17 +421,15 @@ export async function listSites(
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
conditions.push(or(...queryList));
|
conditions.push(or(...queryList)!);
|
||||||
}
|
}
|
||||||
|
|
||||||
const baseQuery = querySitesBase().where(and(...conditions));
|
const baseQuery = querySitesBase().where(and(...conditions));
|
||||||
|
|
||||||
// we need to add `as` so that drizzle filters the result as a subquery
|
const countQuery = db
|
||||||
const countQuery = db.$count(
|
.select({ count: sql<number>`count(*)` })
|
||||||
querySitesBase()
|
.from(sites)
|
||||||
.where(and(...conditions))
|
.where(and(...conditions));
|
||||||
.as("filtered_sites")
|
|
||||||
);
|
|
||||||
|
|
||||||
const siteListQuery = baseQuery
|
const siteListQuery = baseQuery
|
||||||
.limit(pageSize)
|
.limit(pageSize)
|
||||||
@@ -441,11 +442,13 @@ export async function listSites(
|
|||||||
: asc(sites.name)
|
: asc(sites.name)
|
||||||
);
|
);
|
||||||
|
|
||||||
const [totalCount, rows] = await Promise.all([
|
const [countRows, rows] = await Promise.all([
|
||||||
countQuery,
|
countQuery,
|
||||||
siteListQuery
|
siteListQuery
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
const totalCount = Number(countRows[0]?.count ?? 0);
|
||||||
|
|
||||||
// Get latest version asynchronously without blocking the response
|
// Get latest version asynchronously without blocking the response
|
||||||
const latestNewtVersionPromise = getLatestNewtVersion();
|
const latestNewtVersionPromise = getLatestNewtVersion();
|
||||||
|
|
||||||
|
|||||||
@@ -764,7 +764,7 @@ export default function Page() {
|
|||||||
ssh: "SSH",
|
ssh: "SSH",
|
||||||
rdp: "RDP",
|
rdp: "RDP",
|
||||||
vnc: "VNC",
|
vnc: "VNC",
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const typeOptions: OptionSelectOption<NewResourceType>[] =
|
const typeOptions: OptionSelectOption<NewResourceType>[] =
|
||||||
|
|||||||
Reference in New Issue
Block a user