Skip to content

Commit 3d4e4c0

Browse files
committed
chore: add object for permission resource
fix: fix failing tests
1 parent d4d9622 commit 3d4e4c0

File tree

5 files changed

+53
-3
lines changed

5 files changed

+53
-3
lines changed

src/api/types/permissions.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export type PermissionTable = {
99
description: string;
1010
action: string;
1111
deny?: boolean;
12+
object?: string;
1213
component_id?: string;
1314
config_id?: string;
1415
canary_id?: string;

src/components/Permissions/ManagePermissions/Forms/FormikPermissionSelectResourceFields.tsx

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,34 @@ import FormikCanaryDropdown from "@flanksource-ui/components/Forms/Formik/Formik
22
import FormikConnectionField from "@flanksource-ui/components/Forms/Formik/FormikConnectionField";
33
import FormikPlaybooksDropdown from "@flanksource-ui/components/Forms/Formik/FormikPlaybooksDropdown";
44
import FormikResourceSelectorDropdown from "@flanksource-ui/components/Forms/Formik/FormikResourceSelectorDropdown";
5+
import FormikSelectDropdown from "@flanksource-ui/components/Forms/Formik/FormikSelectDropdown";
56
import { Switch } from "@flanksource-ui/ui/FormControls/Switch";
67
import { useFormikContext } from "formik";
78
import { useState } from "react";
89

10+
export const permissionObjectList = [
11+
{ label: "Canaries", value: "canaries" },
12+
{ label: "Catalog", value: "catalog" },
13+
{ label: "Incident", value: "incident" },
14+
{ label: "People", value: "people" },
15+
{ label: "Topology", value: "topology" },
16+
{ label: "Playbooks", value: "playbooks" },
17+
{ label: "Connection", value: "connection" },
18+
{ label: "Connection Detail", value: "connection-detail" },
19+
{ label: "Agent Push", value: "agent-push" },
20+
{ label: "Kubernetes Proxy", value: "kubernetes-proxy" },
21+
{ label: "Notification", value: "notification" },
22+
{ label: "RBAC", value: "rbac" },
23+
{ label: "Logs", value: "logs" },
24+
{ label: "Agent", value: "agent" },
25+
{ label: "Artifact", value: "artifact" }
26+
];
27+
928
export default function FormikPermissionSelectResourceFields() {
1029
const { setFieldValue } = useFormikContext<Record<string, any>>();
1130

1231
const [switchOption, setSwitchOption] = useState<
13-
"Component" | "Catalog" | "Canary" | "Playbook" | "Connection"
32+
"Component" | "Catalog" | "Canary" | "Playbook" | "Connection" | "Object"
1433
>("Catalog");
1534

1635
return (
@@ -19,13 +38,20 @@ export default function FormikPermissionSelectResourceFields() {
1938
<div>
2039
<div className="flex w-full flex-row">
2140
<Switch
22-
options={["Catalog", "Component", "Connection", "Playbook"]}
41+
options={[
42+
"Catalog",
43+
"Component",
44+
"Connection",
45+
"Playbook",
46+
"Object"
47+
]}
2348
className="w-auto"
2449
itemsClassName=""
2550
defaultValue="Go Template"
2651
value={switchOption}
2752
onChange={(v) => {
2853
setSwitchOption(v);
54+
setFieldValue("object", undefined);
2955
setFieldValue("config_id", undefined);
3056
setFieldValue("check_id", undefined);
3157
setFieldValue("canary_id", undefined);
@@ -62,6 +88,14 @@ export default function FormikPermissionSelectResourceFields() {
6288
{switchOption === "Connection" && (
6389
<FormikConnectionField required name="connection_id" />
6490
)}
91+
92+
{switchOption === "Object" && (
93+
<FormikSelectDropdown
94+
required
95+
name="object"
96+
options={permissionObjectList}
97+
/>
98+
)}
6599
</div>
66100
</div>
67101
);

src/components/Permissions/ManagePermissions/Forms/PermissionForm.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ export default function PermissionForm({
4646
data?.canary_id ||
4747
data?.canary_id ||
4848
data?.playbook_id ||
49-
data?.connection_id
49+
data?.connection_id ||
50+
data?.object
5051
);
5152
}, [data]);
5253

@@ -111,6 +112,7 @@ export default function PermissionForm({
111112
canary_id: data?.canary_id,
112113
playbook_id: data?.playbook_id,
113114
deny: data?.deny ?? false,
115+
object: data?.object,
114116
description: data?.description,
115117
connection_id: data?.connection_id,
116118
created_at: data?.created_at,

src/components/Permissions/ManagePermissions/Forms/PermissionResource.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import ConnectionLink from "@flanksource-ui/components/Connections/ConnectionLin
33
import { PlaybookSpecLabel } from "@flanksource-ui/components/Playbooks/Settings/PlaybookSpecIcon";
44
import { TopologyLink } from "@flanksource-ui/components/Topology/TopologyLink";
55
import { useFormikContext } from "formik";
6+
import { permissionObjectList } from "./FormikPermissionSelectResourceFields";
67

78
export default function PermissionResource() {
89
const { values } = useFormikContext<Record<string, string>>();
@@ -11,6 +12,12 @@ export default function PermissionResource() {
1112
const playbookId = values.playbook_id;
1213
const configId = values.config_id;
1314
const connectionId = values.connection_id;
15+
const object = values.object;
16+
17+
if (object) {
18+
// eslint-disable-next-line react/jsx-no-useless-fragment
19+
return <>{permissionObjectList.find((o) => o.value === object)?.label}</>;
20+
}
1421

1522
return (
1623
<div className="flex flex-row items-center">

src/components/Permissions/PermissionsTable.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import ConfigLink from "../Configs/ConfigLink/ConfigLink";
99
import ConnectionIcon from "../Connections/ConnectionIcon";
1010
import PlaybookSpecIcon from "../Playbooks/Settings/PlaybookSpecIcon";
1111
import { TopologyLink } from "../Topology/TopologyLink";
12+
import { permissionObjectList } from "./ManagePermissions/Forms/FormikPermissionSelectResourceFields";
1213
import { permissionsActionsList } from "./PermissionsView";
1314

1415
const permissionsTableColumns: MRT_ColumnDef<PermissionAPIResponse>[] = [
@@ -23,6 +24,11 @@ const permissionsTableColumns: MRT_ColumnDef<PermissionAPIResponse>[] = [
2324
const playbook = row.original.playbook;
2425
const component = row.original.component;
2526
const connection = row.original.connection;
27+
const object = row.original.object;
28+
29+
if (object) {
30+
return permissionObjectList.find((o) => o.value === object)?.label;
31+
}
2632

2733
return (
2834
<div className="flex flex-col">

0 commit comments

Comments
 (0)