Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

commit missing file and update group assume member modal

Scott Wilson3abe8573cd30
diff --git a/backend/src/services/role/role-service.ts b/backend/src/services/role/role-service.ts
index 4b1a7768d4..48c7f0c3a3 100644
--- a/backend/src/services/role/role-service.ts
+++ b/backend/src/services/role/role-service.ts
@@ -317,8 +317,7 @@ export const roleServiceFactory = ({
);
if (!userDetails)
throw new NotFoundError({ message: `User with ID ${assumedPrivilegeDetails.actorId} not found` });
- assumedPrivilegeDetails.actorName =
- `${userDetails?.firstName ?? ""} ${userDetails?.lastName ?? ""}`.trim();
+ assumedPrivilegeDetails.actorName = `${userDetails?.firstName ?? ""} ${userDetails?.lastName ?? ""}`.trim();
assumedPrivilegeDetails.actorEmail = userDetails?.email || "";
}
diff --git a/frontend/src/components/assume-privileges/AssumePrivilegesModal.tsx b/frontend/src/components/assume-privileges/AssumePrivilegesModal.tsx
new file mode 100644
index 0000000000..a75258d613
--- /dev/null
+++ b/frontend/src/components/assume-privileges/AssumePrivilegesModal.tsx
@@ -0,0 +1,116 @@
+import { useEffect, useState } from "react";
+
+import { createNotification } from "@app/components/notifications";
+import {
+ Button,
+ Dialog,
+ DialogClose,
+ DialogContent,
+ DialogDescription,
+ DialogFooter,
+ DialogHeader,
+ DialogTitle,
+ Field,
+ FieldContent,
+ FieldLabel,
+ Input
+} from "@app/components/v3";
+import { useOrganization, useProject } from "@app/context";
+import { getProjectHomePage } from "@app/helpers/project";
+import { useAssumeProjectPrivileges } from "@app/hooks/api";
+import { ActorType } from "@app/hooks/api/auditLogs/enums";
+
+const CONFIRM_KEY = "assume";
+
+type Props = {
+ isOpen: boolean;
+ onOpenChange: (isOpen: boolean) => void;
+ actorType: ActorType;
+ actorId?: string;
+};
+
+export const AssumePrivilegesModal = ({ isOpen, onOpenChange, actorType, actorId }: Props) => {
+ const { currentOrg } = useOrganization();
+ const { currentProject } = useProject();
+ const assumePrivileges = useAssumeProjectPrivileges();
+ const [inputData, setInputData] = useState("");
+
+ useEffect(() => {
+ setInputData("");
+ }, [isOpen]);
+
+ const isUser = actorType === ActorType.USER;
+ const noun = isUser ? "user" : "machine identity";
+ const isConfirmed = inputData === CONFIRM_KEY;
+
+ const handleConfirm = () => {
+ if (!isConfirmed || !actorId || !currentOrg?.id || !currentProject?.id) return;
+
+ assumePrivileges.mutate(
+ {
+ actorId,
+ actorType,
+ projectId: currentProject.id
+ },
+ {
+ onSuccess: () => {
+ createNotification({
+ type: "success",
+ text: `${isUser ? "User" : "Machine identity"} privilege assumption has started`
+ });
+
+ const url = getProjectHomePage(currentProject.type, currentProject.environments);
+ window.location.assign(
+ url.replace("$orgId", currentOrg.id).replace("$projectId", currentProject.id)
+ );
+ }
+ }
+ );
+ };
+
+ return (
+ <Dialog open={isOpen} onOpenChange={onOpenChange}>
+ <DialogContent className="max-w-xl">
+ <DialogHeader>
+ <DialogTitle>Do you want to assume privileges of this {noun}?</DialogTitle>
+ <DialogDescription>
+ This will set your privileges to those of the {noun} for the next hour.
+ </DialogDescription>
+ </DialogHeader>
+ <form
+ onSubmit={(e) => {
+ e.preventDefault();
+ handleConfirm();
+ }}
+ >
+ <Field>
+ <FieldLabel>
+ Type <span className="font-bold">{CONFIRM_KEY}</span> to perform this action
+ </FieldLabel>
+ <FieldContent>
+ <Input
+ value={inputData}
+ onChange={(e) => setInputData(e.target.value)}
+ placeholder={`Type ${CONFIRM_KEY} here`}
+ autoComplete="off"
+ />
+ </FieldContent>
+ </Field>
+ </form>
+ <DialogFooter>
+ <DialogClose asChild>
+ <Button variant="ghost">Cancel</Button>
+ </DialogClose>
+ <Button
+ variant="project"
+ onClick={handleConfirm}
+ isPending={assumePrivileges.isPending}
+ isDisabled={!isConfirmed || assumePrivileges.isPending}
+ >
+ Confirm
+ </Button>
+ </DialogFooter>
+ </DialogContent>
+ </Dialog>
+ );
+};
diff --git a/frontend/src/components/assume-privileges/index.ts b/frontend/src/components/assume-privileges/index.ts
new file mode 100644
index 0000000000..f9a43ba879
--- /dev/null
+++ b/frontend/src/components/assume-privileges/index.ts
@@ -0,0 +1 @@
+export * from "./AssumePrivilegesModal";
diff --git a/frontend/src/pages/project/GroupDetailsByIDPage/components/GroupMembersSection/GroupMembersTable.tsx b/frontend/src/pages/project/GroupDetailsByIDPage/components/GroupMembersSection/GroupMembersTable.tsx
index c7f8be1f71..0ad9c47b2a 100644
--- a/frontend/src/pages/project/GroupDetailsByIDPage/components/GroupMembersSection/GroupMembersTable.tsx
+++ b/frontend/src/pages/project/GroupDetailsByIDPage/components/GroupMembersSection/GroupMembersTable.tsx
@@ -3,8 +3,8 @@ import { useNavigate, useSearch } from "@tanstack/react-router";
import { ChevronDownIcon, FilterIcon, HardDriveIcon, UserIcon } from "lucide-react";
import { twMerge } from "tailwind-merge";
-import { createNotification } from "@app/components/notifications";
-import { ConfirmActionModal, Lottie } from "@app/components/v2";
+import { AssumePrivilegesModal } from "@app/components/assume-privileges";
+import { Lottie } from "@app/components/v2";
import {
DropdownMenu,
DropdownMenuCheckboxItem,
@@ -24,15 +24,12 @@ import {
TableHeader,
TableRow
} from "@app/components/v3";
-import { useOrganization, useProject } from "@app/context";
-import { getProjectHomePage } from "@app/helpers/project";
import {
getUserTablePreference,
PreferenceKey,
setUserTablePreference
} from "@app/helpers/userTablePreferences";
import { usePagination, usePopUp, useResetPageHelper } from "@app/hooks";
-import { useAssumeProjectPrivileges } from "@app/hooks/api";
import { ActorType } from "@app/hooks/api/auditLogs/enums";
import { OrderByDirection } from "@app/hooks/api/generic/types";
import { useListGroupMembers } from "@app/hooks/api/groups/queries";
@@ -91,9 +88,6 @@ export const GroupMembersTable = ({ groupMembership }: Props) => {
setUserTablePreference("projectGroupMembersTable", PreferenceKey.PerPage, newPerPage);
};
- const { currentOrg } = useOrganization();
- const { currentProject } = useProject();
-
const { data: groupMemberships, isPending } = useListGroupMembers({
id: groupMembership.group.id,
groupSlug: groupMembership.group.slug,
@@ -115,38 +109,6 @@ export const GroupMembersTable = ({ groupMembership }: Props) => {
setPage
});
- const assumePrivileges = useAssumeProjectPrivileges();
-
- const handleAssumePrivileges = async () => {
- const { actorId, actorType } = popUp?.assumePrivileges?.data as {
- actorId: string;
- actorType: ActorType;
- };
- assumePrivileges.mutate(
- {
- actorId,
- actorType,
- projectId: currentProject.id
- },
- {
- onSuccess: () => {
- createNotification({
- type: "success",
- text:
- actorType === ActorType.IDENTITY
- ? "Machine identity privilege assumption has started"
- : "User privilege assumption has started"
- });
-
- const url = getProjectHomePage(currentProject.type, currentProject.environments);
- window.location.assign(
- url.replace("$orgId", currentOrg.id).replace("$projectId", currentProject.id)
- );
- }
- }
- );
- };
-
const filterOptions = [
{
icon: <UserIcon size={16} />,
@@ -278,14 +240,11 @@ export const GroupMembersTable = ({ groupMembership }: Props) => {
onChangePerPage={handlePerPageChange}
/>
)}
- <ConfirmActionModal
+ <AssumePrivilegesModal
isOpen={popUp.assumePrivileges.isOpen}
- confirmKey="assume"
- title={`Do you want to assume privileges of this ${popUp.assumePrivileges?.data?.actorType === ActorType.IDENTITY ? "machine identity" : "user"}?`}
- subTitle={`This will set your privileges to those of the ${popUp.assumePrivileges?.data?.actorType === ActorType.IDENTITY ? "machine identity" : "user"} for the next hour.`}
- onChange={(isOpen) => handlePopUpToggle("assumePrivileges", isOpen)}
- onConfirmed={handleAssumePrivileges}
- buttonText="Confirm"
+ onOpenChange={(isOpen) => handlePopUpToggle("assumePrivileges", isOpen)}
+ actorType={(popUp.assumePrivileges.data as { actorType: ActorType })?.actorType}
+ actorId={(popUp.assumePrivileges.data as { actorId: string })?.actorId}
/>
</>
);