mirror of
https://github.com/fosrl/pangolin.git
synced 2026-05-20 15:55:31 +00:00
✨ policies table
This commit is contained in:
@@ -170,6 +170,7 @@
|
|||||||
"resourcePoliciesDescription": "Create and manage authentication policies to control access to your resources",
|
"resourcePoliciesDescription": "Create and manage authentication policies to control access to your resources",
|
||||||
"resourcePoliciesSearch": "Search policies...",
|
"resourcePoliciesSearch": "Search policies...",
|
||||||
"resourcePoliciesAdd": "Add Policy",
|
"resourcePoliciesAdd": "Add Policy",
|
||||||
|
"resourcePoliciesDefaultBadgeText": "Default policy",
|
||||||
"authentication": "Authentication",
|
"authentication": "Authentication",
|
||||||
"protected": "Protected",
|
"protected": "Protected",
|
||||||
"notProtected": "Not Protected",
|
"notProtected": "Not Protected",
|
||||||
|
|||||||
@@ -11,32 +11,17 @@
|
|||||||
* This file is not licensed under the AGPLv3.
|
* This file is not licensed under the AGPLv3.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Request, Response, NextFunction } from "express";
|
import { db, resourcePolicies, roleResources, userResources } from "@server/db";
|
||||||
import { z } from "zod";
|
|
||||||
import {
|
|
||||||
db,
|
|
||||||
resourceHeaderAuth,
|
|
||||||
resourceHeaderAuthExtendedCompatibility,
|
|
||||||
resourcePolicies
|
|
||||||
} from "@server/db";
|
|
||||||
import {
|
|
||||||
resources,
|
|
||||||
userResources,
|
|
||||||
roleResources,
|
|
||||||
resourcePassword,
|
|
||||||
resourcePincode,
|
|
||||||
targets,
|
|
||||||
targetHealthCheck
|
|
||||||
} from "@server/db";
|
|
||||||
import response from "@server/lib/response";
|
import response from "@server/lib/response";
|
||||||
import HttpCode from "@server/types/HttpCode";
|
|
||||||
import createHttpError from "http-errors";
|
|
||||||
import { sql, eq, or, inArray, and, count, ilike, asc } from "drizzle-orm";
|
|
||||||
import logger from "@server/logger";
|
import logger from "@server/logger";
|
||||||
import { fromZodError } from "zod-validation-error";
|
|
||||||
import { OpenAPITags, registry } from "@server/openApi";
|
import { OpenAPITags, registry } from "@server/openApi";
|
||||||
import type { PaginatedResponse } from "@server/types/Pagination";
|
|
||||||
import type { ListResourcePoliciesResponse } from "@server/routers/resource/types";
|
import type { ListResourcePoliciesResponse } from "@server/routers/resource/types";
|
||||||
|
import HttpCode from "@server/types/HttpCode";
|
||||||
|
import { and, asc, eq, inArray, like, or, sql } from "drizzle-orm";
|
||||||
|
import { NextFunction, Request, Response } from "express";
|
||||||
|
import createHttpError from "http-errors";
|
||||||
|
import { z } from "zod";
|
||||||
|
import { fromZodError } from "zod-validation-error";
|
||||||
|
|
||||||
const listResourcePoliciesParamsSchema = z.strictObject({
|
const listResourcePoliciesParamsSchema = z.strictObject({
|
||||||
orgId: z.string()
|
orgId: z.string()
|
||||||
@@ -66,7 +51,8 @@ function queryResourcePoliciesBase() {
|
|||||||
resourcePolicyId: resourcePolicies.resourcePolicyId,
|
resourcePolicyId: resourcePolicies.resourcePolicyId,
|
||||||
name: resourcePolicies.name,
|
name: resourcePolicies.name,
|
||||||
niceId: resourcePolicies.niceId,
|
niceId: resourcePolicies.niceId,
|
||||||
orgId: resourcePolicies.orgId
|
orgId: resourcePolicies.orgId,
|
||||||
|
isDefault: resourcePolicies.isDefault
|
||||||
})
|
})
|
||||||
.from(resourcePolicies);
|
.from(resourcePolicies);
|
||||||
}
|
}
|
||||||
@@ -180,8 +166,14 @@ export async function listResourcePolicies(
|
|||||||
if (query) {
|
if (query) {
|
||||||
conditions.push(
|
conditions.push(
|
||||||
or(
|
or(
|
||||||
ilike(resourcePolicies.name, "%" + query + "%"),
|
like(
|
||||||
ilike(resourcePolicies.niceId, "%" + query + "%")
|
sql`LOWER(${resourcePolicies.name})`,
|
||||||
|
"%" + query.toLowerCase() + "%"
|
||||||
|
),
|
||||||
|
like(
|
||||||
|
sql`LOWER(${resourcePolicies.niceId})`,
|
||||||
|
"%" + query.toLowerCase() + "%"
|
||||||
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,9 @@ export type GetMaintenanceInfoResponse = {
|
|||||||
|
|
||||||
export type ListResourcePoliciesResponse = PaginatedResponse<{
|
export type ListResourcePoliciesResponse = PaginatedResponse<{
|
||||||
policies: Array<
|
policies: Array<
|
||||||
Pick<ResourcePolicy, "resourcePolicyId" | "niceId" | "name" | "orgId">
|
Pick<
|
||||||
|
ResourcePolicy,
|
||||||
|
"resourcePolicyId" | "niceId" | "name" | "orgId" | "isDefault"
|
||||||
|
>
|
||||||
>;
|
>;
|
||||||
}>;
|
}>;
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import { MoreHorizontal, ArrowRight } from "lucide-react";
|
|||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { ControlledDataTable } from "./ui/controlled-data-table";
|
import { ControlledDataTable } from "./ui/controlled-data-table";
|
||||||
import { useDebouncedCallback } from "use-debounce";
|
import { useDebouncedCallback } from "use-debounce";
|
||||||
|
import { Badge } from "./ui/badge";
|
||||||
|
|
||||||
type ResourcePolicyRow = ListResourcePoliciesResponse["policies"][number];
|
type ResourcePolicyRow = ListResourcePoliciesResponse["policies"][number];
|
||||||
|
|
||||||
@@ -70,7 +71,25 @@ export function ResourcePoliciesTable({
|
|||||||
accessorKey: "name",
|
accessorKey: "name",
|
||||||
enableHiding: false,
|
enableHiding: false,
|
||||||
friendlyName: t("name"),
|
friendlyName: t("name"),
|
||||||
header: () => <span className="p-3">{t("name")}</span>
|
header: () => <span className="p-3">{t("name")}</span>,
|
||||||
|
cell({ row }) {
|
||||||
|
const r = row.original;
|
||||||
|
return (
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<span>{r.name}</span>
|
||||||
|
{r.isDefault && (
|
||||||
|
<>
|
||||||
|
<Badge
|
||||||
|
variant="outlinePrimary"
|
||||||
|
className="flex items-center gap-1"
|
||||||
|
>
|
||||||
|
{t("resourcePoliciesDefaultBadgeText")}
|
||||||
|
</Badge>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: "niceId",
|
id: "niceId",
|
||||||
|
|||||||
Reference in New Issue
Block a user