diff --git a/src/api/services/permissions.ts b/src/api/services/permissions.ts index fa45bfe5d..fa600a726 100644 --- a/src/api/services/permissions.ts +++ b/src/api/services/permissions.ts @@ -1,6 +1,7 @@ import { IncidentCommander } from "../axios"; import { resolvePostGrestRequestWithPagination } from "../resolve"; import { PermissionsSummary, PermissionTable } from "../types/permissions"; +import { AVATAR_INFO } from "@flanksource-ui/constants"; export type FetchPermissionsInput = { componentId?: string; @@ -68,11 +69,11 @@ export function fetchPermissions( } ) { const queryParam = composeQueryParamForFetchPermissions(input); - const selectFields = ["*"]; + const selectFields = `*,created_by(${AVATAR_INFO})`; const { pageSize, pageIndex } = pagination; - const url = `/permissions_summary?${queryParam}&select=${selectFields.join(",")}&deleted_at=is.null&limit=${pageSize}&offset=${pageIndex * pageSize}`; + const url = `/permissions_summary?${queryParam}&select=${selectFields}&deleted_at=is.null&limit=${pageSize}&offset=${pageIndex * pageSize}`; return resolvePostGrestRequestWithPagination( IncidentCommander.get(url, { headers: { diff --git a/src/api/types/permissions.ts b/src/api/types/permissions.ts index 03ed79ccf..d12cabee3 100644 --- a/src/api/types/permissions.ts +++ b/src/api/types/permissions.ts @@ -32,8 +32,6 @@ export type PermissionTable = { updated_at: string; until?: string; source?: string; - tags?: Record; - agents?: string[]; // Resources object?: PermissionGlobalObject; @@ -68,9 +66,7 @@ export type PermissionsSummary = PermissionTable & { group: any; subject: string; person: User; - createdBy: User; - tags: Record | null; - agents: string[] | null; + created_by?: User; // These represent global objects object: PermissionGlobalObject; @@ -78,7 +74,8 @@ export type PermissionsSummary = PermissionTable & { // These represent object selectors per type object_selector?: PermissionObjectSelector; - // These are objects that are specifically chosen + // These are objects that are specifically chosen (from the dropdown). + // We store their ID. config_object: Pick; playbook_object: Pick; connection_object: Pick; diff --git a/src/components/Permissions/ManagePermissions/Forms/PermissionForm.tsx b/src/components/Permissions/ManagePermissions/Forms/PermissionForm.tsx index 7d19512d0..bd4cdf4b5 100644 --- a/src/components/Permissions/ManagePermissions/Forms/PermissionForm.tsx +++ b/src/components/Permissions/ManagePermissions/Forms/PermissionForm.tsx @@ -18,7 +18,6 @@ import { Button } from "@flanksource-ui/ui/Buttons/Button"; import { Modal } from "@flanksource-ui/ui/Modal"; import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"; import { AxiosError } from "axios"; -import clsx from "clsx"; import { Form, Formik, useFormikContext } from "formik"; import { useMemo } from "react"; import { FaSpinner } from "react-icons/fa"; @@ -78,22 +77,45 @@ function PermissionFormContent({ return (
- - {isResourceIdProvided && isReadOnly ? ( -
- - + {isReadOnly && ( +
+

+ Read-Only Mode: This resource is managed by Kubernetes CRD and + cannot be edited from the UI. +

- ) : ( - )} - - - + +
+ +
+ +
+ {isResourceIdProvided && isReadOnly ? ( +
+ + +
+ ) : ( + + )} +
+ +
+ +
+ +
+ +
+ +
+ +
); } @@ -247,41 +269,36 @@ export default function PermissionForm({ id={permissionData?.id} resourceType={"permissions"} source={permissionData?.source} - className="flex items-center bg-gray-100 px-5 py-4" + className="flex items-center justify-between bg-gray-100 px-5 py-4" > - -
- {permissionData?.id && ( +
+ {permissionData?.id && permissionData.source === "UI" && ( + - )} -
+ + )} +
+ +
); } @@ -166,9 +123,6 @@ const permissionsTableColumns: MRT_ColumnDef[] = [ {permissionObjectList.find((o) => o.value === object)?.label} - {rlsBadges.length > 0 && ( -
{rlsBadges}
- )} ); } @@ -216,10 +170,6 @@ const permissionsTableColumns: MRT_ColumnDef[] = [ )} - - {rlsBadges.length > 0 && ( -
{rlsBadges}
- )} ); } @@ -280,7 +230,7 @@ const permissionsTableColumns: MRT_ColumnDef[] = [ header: "Created By", size: 40, Cell: ({ row }) => { - const createdBy = row.original.createdBy; + const createdBy = row.original.created_by; const source = row.original.source; if (source?.toLowerCase() === "KubernetesCRD".toLowerCase()) { @@ -288,6 +238,10 @@ const permissionsTableColumns: MRT_ColumnDef[] = [ return ; } + if (!createdBy) { + return null; + } + return ; } }