Skip to content

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

hide sections from default templates

x032205686ff733c48c
diff --git a/frontend/src/pages/organization/SettingsPage/components/ProjectTemplatesTab/components/EditProjectTemplateSection/components/EditProjectTemplate.tsx b/frontend/src/pages/organization/SettingsPage/components/ProjectTemplatesTab/components/EditProjectTemplateSection/components/EditProjectTemplate.tsx
index 2aa71e8c53..35f1a2006e 100644
--- a/frontend/src/pages/organization/SettingsPage/components/ProjectTemplatesTab/components/EditProjectTemplateSection/components/EditProjectTemplate.tsx
+++ b/frontend/src/pages/organization/SettingsPage/components/ProjectTemplatesTab/components/EditProjectTemplateSection/components/EditProjectTemplate.tsx
@@ -104,18 +104,13 @@ export const EditProjectTemplate = ({ isInfisicalTemplate, projectTemplate, onBa
isInfisicalTemplate={isInfisicalTemplate}
projectTemplate={projectTemplate}
/>
- <ProjectTemplateUsersSection
- isInfisicalTemplate={isInfisicalTemplate}
- projectTemplate={projectTemplate}
- />
- <ProjectTemplateGroupsSection
- isInfisicalTemplate={isInfisicalTemplate}
- projectTemplate={projectTemplate}
- />
- <ProjectTemplateIdentitiesSection
- isInfisicalTemplate={isInfisicalTemplate}
- projectTemplate={projectTemplate}
- />
+ {!isInfisicalTemplate && (
+ <>
+ <ProjectTemplateUsersSection projectTemplate={projectTemplate} />
+ <ProjectTemplateGroupsSection projectTemplate={projectTemplate} />
+ <ProjectTemplateIdentitiesSection projectTemplate={projectTemplate} />
+ </>
+ )}
<ProjectTemplateDetailsModal
isOpen={popUp.editDetails.isOpen}
onOpenChange={(isOpen) => handlePopUpToggle("editDetails", isOpen)}
diff --git a/frontend/src/pages/organization/SettingsPage/components/ProjectTemplatesTab/components/EditProjectTemplateSection/components/ProjectTemplateGroupsSection.tsx b/frontend/src/pages/organization/SettingsPage/components/ProjectTemplatesTab/components/EditProjectTemplateSection/components/ProjectTemplateGroupsSection.tsx
index 3dfc242913..6061e94fcb 100644
--- a/frontend/src/pages/organization/SettingsPage/components/ProjectTemplatesTab/components/EditProjectTemplateSection/components/ProjectTemplateGroupsSection.tsx
+++ b/frontend/src/pages/organization/SettingsPage/components/ProjectTemplatesTab/components/EditProjectTemplateSection/components/ProjectTemplateGroupsSection.tsx
@@ -33,7 +33,6 @@ import {
type Props = {
projectTemplate: TProjectTemplate;
- isInfisicalTemplate: boolean;
};
const formSchema = z.object({
@@ -68,7 +67,7 @@ const addGroupFormSchema = z.object({
type TAddGroupForm = z.infer<typeof addGroupFormSchema>;
-export const ProjectTemplateGroupsSection = ({ projectTemplate, isInfisicalTemplate }: Props) => {
+export const ProjectTemplateGroupsSection = ({ projectTemplate }: Props) => {
const { currentOrg } = useOrganization();
const orgId = currentOrg?.id || "";
const [isAddGroupModalOpen, setIsAddGroupModalOpen] = useState(false);
@@ -138,15 +137,6 @@ export const ProjectTemplateGroupsSection = ({ projectTemplate, isInfisicalTempl
}));
}, [orgGroups, currentGroups]);
- const getRoleNames = (roleSlugs: string[]) => {
- return roleSlugs
- .map((slug) => {
- const role = availableRoles.find((r) => r.slug === slug);
- return role?.name || slug;
- })
- .join(", ");
- };
-
const getGroupName = (groupSlug: string) => {
const group = orgGroups?.find((g) => g.slug.toLowerCase() === groupSlug.toLowerCase());
return group?.name || groupSlug;
@@ -196,52 +186,49 @@ export const ProjectTemplateGroupsSection = ({ projectTemplate, isInfisicalTempl
<div>
<h2 className="text-lg font-medium">Project Groups</h2>
<p className="text-sm text-mineshaft-400">
- {isInfisicalTemplate
- ? "Groups that will be automatically added to projects created from this template"
- : "Add groups that will be automatically added to projects created from this template"}
+ Add groups that will be automatically added to projects created from this template
</p>
</div>
- {!isInfisicalTemplate && (
- <OrgPermissionCan
- I={OrgPermissionActions.Edit}
- a={OrgPermissionSubjects.ProjectTemplates}
- >
- {(isAllowed) => (
- <div className="flex gap-3">
- {isAllowed && isDirty && (
- <>
- <Button
- onClick={handleDiscard}
- colorSchema="secondary"
- variant="plain"
- type="button"
- >
- Discard
- </Button>
- <Button
- type="submit"
- colorSchema="primary"
- variant="solid"
- leftIcon={<FontAwesomeIcon icon={faSave} />}
- >
- Save
- </Button>
- </>
- )}
- <Button
- onClick={() => setIsAddGroupModalOpen(true)}
- colorSchema="primary"
- variant="outline_bg"
- leftIcon={<FontAwesomeIcon icon={faPlus} />}
- isDisabled={!isAllowed || availableOrgGroups.length === 0}
- type="button"
- >
- Add Group
- </Button>
- </div>
- )}
- </OrgPermissionCan>
- )}
+
+ <OrgPermissionCan
+ I={OrgPermissionActions.Edit}
+ a={OrgPermissionSubjects.ProjectTemplates}
+ >
+ {(isAllowed) => (
+ <div className="flex gap-3">
+ {isAllowed && isDirty && (
+ <>
+ <Button
+ onClick={handleDiscard}
+ colorSchema="secondary"
+ variant="plain"
+ type="button"
+ >
+ Discard
+ </Button>
+ <Button
+ type="submit"
+ colorSchema="primary"
+ variant="solid"
+ leftIcon={<FontAwesomeIcon icon={faSave} />}
+ >
+ Save
+ </Button>
+ </>
+ )}
+ <Button
+ onClick={() => setIsAddGroupModalOpen(true)}
+ colorSchema="primary"
+ variant="outline_bg"
+ leftIcon={<FontAwesomeIcon icon={faPlus} />}
+ isDisabled={!isAllowed || availableOrgGroups.length === 0}
+ type="button"
+ >
+ Add Group
+ </Button>
+ </div>
+ )}
+ </OrgPermissionCan>
</div>
{errors.groups && <span className="my-4 text-sm text-red">{errors.groups.message}</span>}
<TableContainer>
@@ -250,7 +237,7 @@ export const ProjectTemplateGroupsSection = ({ projectTemplate, isInfisicalTempl
<Tr>
<Th>Group</Th>
<Th>Roles</Th>
- {!isInfisicalTemplate && <Th className="w-16" />}
+ <Th className="w-16" />
</Tr>
</THead>
<TBody>
@@ -269,93 +256,79 @@ export const ProjectTemplateGroupsSection = ({ projectTemplate, isInfisicalTempl
/>
</Td>
<Td>
- {isInfisicalTemplate ? (
- <Controller
- control={control}
- name={`groups.${pos}.roles`}
- render={({ field }) => (
- <span className="text-sm">{getRoleNames(field.value)}</span>
- )}
- />
- ) : (
- <OrgPermissionCan
- I={OrgPermissionActions.Edit}
- a={OrgPermissionSubjects.ProjectTemplates}
- >
- {(isAllowed) => (
- <Controller
- control={control}
- name={`groups.${pos}.roles`}
- render={({ field, fieldState: { error } }) => {
- // Include orphaned roles
- const availableRoleSlugs = new Set(
- availableRoles.map((r) => r.slug)
- );
- const orphanedRoles = field.value
- .filter((slug) => !availableRoleSlugs.has(slug))
- .map((slug) => ({ slug, name: slug }));
- const allOptions = [...availableRoles, ...orphanedRoles];
+ <OrgPermissionCan
+ I={OrgPermissionActions.Edit}
+ a={OrgPermissionSubjects.ProjectTemplates}
+ >
+ {(isAllowed) => (
+ <Controller
+ control={control}
+ name={`groups.${pos}.roles`}
+ render={({ field, fieldState: { error } }) => {
+ // Include orphaned roles
+ const availableRoleSlugs = new Set(availableRoles.map((r) => r.slug));
+ const orphanedRoles = field.value
+ .filter((slug) => !availableRoleSlugs.has(slug))
+ .map((slug) => ({ slug, name: slug }));
+ const allOptions = [...availableRoles, ...orphanedRoles];
- const selectedValues = allOptions.filter((role) =>
- field.value.includes(role.slug)
- );
+ const selectedValues = allOptions.filter((role) =>
+ field.value.includes(role.slug)
+ );
- return (
- <FormControl
- isError={Boolean(error?.message)}
- errorText={error?.message}
- className="mb-0"
- >
- <FilterableSelect
- isMulti
- isDisabled={!isAllowed}
- options={allOptions}
- value={selectedValues}
- onChange={(selected) => {
- field.onChange(
- (selected as { slug: string; name: string }[]).map(
- (s) => s.slug
- )
- );
- }}
- getOptionValue={(option) => option.slug}
- getOptionLabel={(option) => option.name}
- placeholder="Select roles..."
- menuPosition="fixed"
- />
- </FormControl>
- );
- }}
- />
- )}
- </OrgPermissionCan>
- )}
+ return (
+ <FormControl
+ isError={Boolean(error?.message)}
+ errorText={error?.message}
+ className="mb-0"
+ >
+ <FilterableSelect
+ isMulti
+ isDisabled={!isAllowed}
+ options={allOptions}
+ value={selectedValues}
+ onChange={(selected) => {
+ field.onChange(
+ (selected as { slug: string; name: string }[]).map(
+ (s) => s.slug
+ )
+ );
+ }}
+ getOptionValue={(option) => option.slug}
+ getOptionLabel={(option) => option.name}
+ placeholder="Select roles..."
+ menuPosition="fixed"
+ />
+ </FormControl>
+ );
+ }}
+ />
+ )}
+ </OrgPermissionCan>
+ </Td>
+ <Td>
+ <OrgPermissionCan
+ I={OrgPermissionActions.Edit}
+ a={OrgPermissionSubjects.ProjectTemplates}
+ >
+ {(isAllowed) => (
+ <IconButton
+ onClick={() => remove(pos)}
+ colorSchema="danger"
+ variant="plain"
+ ariaLabel="Remove group"
+ isDisabled={!isAllowed}
+ >
+ <FontAwesomeIcon icon={faTrash} />
+ </IconButton>
+ )}
+ </OrgPermissionCan>
</Td>
- {!isInfisicalTemplate && (
- <Td>
- <OrgPermissionCan
- I={OrgPermissionActions.Edit}
- a={OrgPermissionSubjects.ProjectTemplates}
- >
- {(isAllowed) => (
- <IconButton
- onClick={() => remove(pos)}
- colorSchema="danger"
- variant="plain"
- ariaLabel="Remove group"
- isDisabled={!isAllowed}
- >
- <FontAwesomeIcon icon={faTrash} />
- </IconButton>
- )}
- </OrgPermissionCan>
- </Td>
- )}
</Tr>
))
) : (
<Tr>
- <Td colSpan={isInfisicalTemplate ? 2 : 3}>
+ <Td colSpan={3}>
<EmptyState title="No groups assigned to this template" icon={faUsers} />
</Td>
</Tr>
diff --git a/frontend/src/pages/organization/SettingsPage/components/ProjectTemplatesTab/components/EditProjectTemplateSection/components/ProjectTemplateIdentitiesSection.tsx b/frontend/src/pages/organization/SettingsPage/components/ProjectTemplatesTab/components/EditProjectTemplateSection/components/ProjectTemplateIdentitiesSection.tsx
index a3866452aa..8651f30fc3 100644
--- a/frontend/src/pages/organization/SettingsPage/components/ProjectTemplatesTab/components/EditProjectTemplateSection/components/ProjectTemplateIdentitiesSection.tsx
+++ b/frontend/src/pages/organization/SettingsPage/components/ProjectTemplatesTab/components/EditProjectTemplateSection/components/ProjectTemplateIdentitiesSection.tsx
@@ -39,7 +39,6 @@ import {
type Props = {
projectTemplate: TProjectTemplate;
- isInfisicalTemplate: boolean;
};
const formSchema = z.object({
@@ -95,10 +94,7 @@ enum AddIdentityType {
AssignExisting
}
-export const ProjectTemplateIdentitiesSection = ({
- projectTemplate,
- isInfisicalTemplate
-}: Props) => {
+export const ProjectTemplateIdentitiesSection = ({ projectTemplate }: Props) => {
const [isAddIdentityModalOpen, setIsAddIdentityModalOpen] = useState(false);
const [addMachineIdentityType, setAddMachineIdentityType] = useState<AddIdentityType>(
@@ -197,15 +193,6 @@ export const ProjectTemplateIdentitiesSection = ({
}));
}, [orgIdentities, currentIdentities]);
- const getRoleNames = (roleSlugs: string[]) => {
- return roleSlugs
- .map((slug) => {
- const role = availableRoles.find((r) => r.slug === slug);
- return role?.name || slug;
- })
- .join(", ");
- };
-
const getIdentityName = (identityId: string) => {
const identity = orgIdentities.find((i) => i.id === identityId);
return identity?.name || identityId;
@@ -302,52 +289,50 @@ export const ProjectTemplateIdentitiesSection = ({
<div>
<h2 className="text-lg font-medium">Project Machine Identities</h2>
<p className="text-sm text-mineshaft-400">
- {isInfisicalTemplate
- ? "Machine identities that will be automatically added to projects created from this template"
- : "Add machine identities that will be automatically added to projects created from this template"}
+ Add machine identities that will be automatically added to projects created from this
+ template
</p>
</div>
- {!isInfisicalTemplate && (
- <OrgPermissionCan
- I={OrgPermissionActions.Edit}
- a={OrgPermissionSubjects.ProjectTemplates}
- >
- {(isAllowed) => (
- <div className="flex gap-3">
- {isAllowed && isDirty && (
- <>
- <Button
- onClick={handleDiscard}
- colorSchema="secondary"
- variant="plain"
- type="button"
- >
- Discard
- </Button>
- <Button
- type="submit"
- colorSchema="primary"
- variant="solid"
- leftIcon={<FontAwesomeIcon icon={faSave} />}
- >
- Save
- </Button>
- </>
- )}
- <Button
- onClick={() => setIsAddIdentityModalOpen(true)}
- colorSchema="primary"
- variant="outline_bg"
- leftIcon={<FontAwesomeIcon icon={faPlus} />}
- isDisabled={!isAllowed}
- type="button"
- >
- Add Machine Identity
- </Button>
- </div>
- )}
- </OrgPermissionCan>
- )}
+
+ <OrgPermissionCan
+ I={OrgPermissionActions.Edit}
+ a={OrgPermissionSubjects.ProjectTemplates}
+ >
+ {(isAllowed) => (
+ <div className="flex gap-3">
+ {isAllowed && isDirty && (
+ <>
+ <Button
+ onClick={handleDiscard}
+ colorSchema="secondary"
+ variant="plain"
+ type="button"
+ >
+ Discard
+ </Button>
+ <Button
+ type="submit"
+ colorSchema="primary"
+ variant="solid"
+ leftIcon={<FontAwesomeIcon icon={faSave} />}
+ >
+ Save
+ </Button>
+ </>
+ )}
+ <Button
+ onClick={() => setIsAddIdentityModalOpen(true)}
+ colorSchema="primary"
+ variant="outline_bg"
+ leftIcon={<FontAwesomeIcon icon={faPlus} />}
+ isDisabled={!isAllowed}
+ type="button"
+ >
+ Add Machine Identity
+ </Button>
+ </div>
+ )}
+ </OrgPermissionCan>
</div>
{errors.identities && (
<span className="my-4 text-sm text-red">{errors.identities.message}</span>
@@ -362,7 +347,7 @@ export const ProjectTemplateIdentitiesSection = ({
<Th>Identity</Th>
<Th>Roles</Th>
<Th>Managed by</Th>
- {!isInfisicalTemplate && <Th className="w-16" />}
+ <Th className="w-16" />
</Tr>
</THead>
<TBody>
@@ -375,65 +360,59 @@ export const ProjectTemplateIdentitiesSection = ({
</p>
</Td>
<Td>
- {isInfisicalTemplate ? (
- <span className="text-sm">{getRoleNames(item.roles)}</span>
- ) : (
- <OrgPermissionCan
- I={OrgPermissionActions.Edit}
- a={OrgPermissionSubjects.ProjectTemplates}
- >
- {(isAllowed) => (
- <Controller
- control={control}
- name={
- item.type === "org"
- ? `identities.${item.index}.roles`
- : `projectManagedIdentities.${item.index}.roles`
- }
- render={({ field, fieldState: { error } }) => {
- // Include orphaned roles
- const availableRoleSlugs = new Set(
- availableRoles.map((r) => r.slug)
- );
- const orphanedRoles = field.value
- .filter((slug) => !availableRoleSlugs.has(slug))
- .map((slug) => ({ slug, name: slug }));
- const allOptions = [...availableRoles, ...orphanedRoles];
-
- const selectedValues = allOptions.filter((role) =>
- field.value.includes(role.slug)
- );
-
- return (
- <FormControl
- isError={Boolean(error?.message)}
- errorText={error?.message}
- className="mb-0"
- >
- <FilterableSelect
- isMulti
- isDisabled={!isAllowed}
- options={allOptions}
- value={selectedValues}
- onChange={(selected) => {
- field.onChange(
- (selected as { slug: string; name: string }[]).map(
- (s) => s.slug
- )
- );
- }}
- getOptionValue={(option) => option.slug}
- getOptionLabel={(option) => option.name}
- placeholder="Select roles..."
- menuPosition="fixed"
- />
- </FormControl>
- );
- }}
- />
- )}
- </OrgPermissionCan>
- )}
+ <OrgPermissionCan
+ I={OrgPermissionActions.Edit}
+ a={OrgPermissionSubjects.ProjectTemplates}
+ >
+ {(isAllowed) => (
+ <Controller
+ control={control}
+ name={
+ item.type === "org"
+ ? `identities.${item.index}.roles`
+ : `projectManagedIdentities.${item.index}.roles`
+ }
+ render={({ field, fieldState: { error } }) => {
+ // Include orphaned roles
+ const availableRoleSlugs = new Set(availableRoles.map((r) => r.slug));
+ const orphanedRoles = field.value
+ .filter((slug) => !availableRoleSlugs.has(slug))
+ .map((slug) => ({ slug, name: slug }));
+ const allOptions = [...availableRoles, ...orphanedRoles];
+
+ const selectedValues = allOptions.filter((role) =>
+ field.value.includes(role.slug)
+ );
+
+ return (
+ <FormControl
+ isError={Boolean(error?.message)}
+ errorText={error?.message}
+ className="mb-0"
+ >
+ <FilterableSelect
+ isMulti
+ isDisabled={!isAllowed}
+ options={allOptions}
+ value={selectedValues}
+ onChange={(selected) => {
+ field.onChange(
+ (selected as { slug: string; name: string }[]).map(
+ (s) => s.slug
+ )
+ );
+ }}
+ getOptionValue={(option) => option.slug}
+ getOptionLabel={(option) => option.name}
+ placeholder="Select roles..."
+ menuPosition="fixed"
+ />
+ </FormControl>
+ );
+ }}
+ />
+ )}
+ </OrgPermissionCan>
</Td>
<Td>
<Badge variant={item.type === "project" ? "project" : "org"}>
@@ -450,37 +429,35 @@ export const ProjectTemplateIdentitiesSection = ({
)}
</Badge>
</Td>
- {!isInfisicalTemplate && (
- <Td>
- <OrgPermissionCan
- I={OrgPermissionActions.Edit}
- a={OrgPermissionSubjects.ProjectTemplates}
- >
- {(isAllowed) => (
- <IconButton
- onClick={() => {
- if (item.type === "org") {
- removeIdentity(item.index);
- } else {
- removeProjectManagedIdentity(item.index);
- }
- }}
- colorSchema="danger"
- variant="plain"
- ariaLabel="Remove identity"
- isDisabled={!isAllowed}
- >
- <FontAwesomeIcon icon={faTrash} />
- </IconButton>
- )}
- </OrgPermissionCan>
- </Td>
- )}
+ <Td>
+ <OrgPermissionCan
+ I={OrgPermissionActions.Edit}
+ a={OrgPermissionSubjects.ProjectTemplates}
+ >
+ {(isAllowed) => (
+ <IconButton
+ onClick={() => {
+ if (item.type === "org") {
+ removeIdentity(item.index);
+ } else {
+ removeProjectManagedIdentity(item.index);
+ }
+ }}
+ colorSchema="danger"
+ variant="plain"
+ ariaLabel="Remove identity"
+ isDisabled={!isAllowed}
+ >
+ <FontAwesomeIcon icon={faTrash} />
+ </IconButton>
+ )}
+ </OrgPermissionCan>
+ </Td>
</Tr>
))
) : (
<Tr>
- <Td colSpan={isInfisicalTemplate ? 3 : 4}>
+ <Td colSpan={4}>
<EmptyState
title="No machine identities assigned to this template"
icon={faServer}
diff --git a/frontend/src/pages/organization/SettingsPage/components/ProjectTemplatesTab/components/EditProjectTemplateSection/components/ProjectTemplateUsersSection.tsx b/frontend/src/pages/organization/SettingsPage/components/ProjectTemplatesTab/components/EditProjectTemplateSection/components/ProjectTemplateUsersSection.tsx
index b8446e1975..f1822645ba 100644
--- a/frontend/src/pages/organization/SettingsPage/components/ProjectTemplatesTab/components/EditProjectTemplateSection/components/ProjectTemplateUsersSection.tsx
+++ b/frontend/src/pages/organization/SettingsPage/components/ProjectTemplatesTab/components/EditProjectTemplateSection/components/ProjectTemplateUsersSection.tsx
@@ -33,7 +33,6 @@ import { useGetOrgUsers } from "@app/hooks/api/users";
type Props = {
projectTemplate: TProjectTemplate;
- isInfisicalTemplate: boolean;
};
const formSchema = z.object({
@@ -68,7 +67,7 @@ const addUserFormSchema = z.object({
type TAddUserForm = z.infer<typeof addUserFormSchema>;
-export const ProjectTemplateUsersSection = ({ projectTemplate, isInfisicalTemplate }: Props) => {
+export const ProjectTemplateUsersSection = ({ projectTemplate }: Props) => {
const { currentOrg } = useOrganization();
const orgId = currentOrg?.id || "";
const [isAddUserModalOpen, setIsAddUserModalOpen] = useState(false);
@@ -144,15 +143,6 @@ export const ProjectTemplateUsersSection = ({ projectTemplate, isInfisicalTempla
}));
}, [orgUsers, currentUsers]);
- const getRoleNames = (roleSlugs: string[]) => {
- return roleSlugs
- .map((slug) => {
- const role = availableRoles.find((r) => r.slug === slug);
- return role?.name || slug;
- })
- .join(", ");
- };
-
// Add user modal form
const {
control: addUserControl,
@@ -197,52 +187,49 @@ export const ProjectTemplateUsersSection = ({ projectTemplate, isInfisicalTempla
<div>
<h2 className="text-lg font-medium">Project Members</h2>
<p className="text-sm text-mineshaft-400">
- {isInfisicalTemplate
- ? "Users that will be automatically added to projects created from this template"
- : "Add users who will be automatically added to projects created from this template"}
+ Add users who will be automatically added to projects created from this template
</p>
</div>
- {!isInfisicalTemplate && (
- <OrgPermissionCan
- I={OrgPermissionActions.Edit}
- a={OrgPermissionSubjects.ProjectTemplates}
- >
- {(isAllowed) => (
- <div className="flex gap-3">
- {isAllowed && isDirty && (
- <>
- <Button
- onClick={handleDiscard}
- colorSchema="secondary"
- variant="plain"
- type="button"
- >
- Discard
- </Button>
- <Button
- type="submit"
- colorSchema="primary"
- variant="solid"
- leftIcon={<FontAwesomeIcon icon={faSave} />}
- >
- Save
- </Button>
- </>
- )}
- <Button
- onClick={() => setIsAddUserModalOpen(true)}
- colorSchema="primary"
- variant="outline_bg"
- leftIcon={<FontAwesomeIcon icon={faPlus} />}
- isDisabled={!isAllowed || availableOrgUsers.length === 0}
- type="button"
- >
- Add User
- </Button>
- </div>
- )}
- </OrgPermissionCan>
- )}
+
+ <OrgPermissionCan
+ I={OrgPermissionActions.Edit}
+ a={OrgPermissionSubjects.ProjectTemplates}
+ >
+ {(isAllowed) => (
+ <div className="flex gap-3">
+ {isAllowed && isDirty && (
+ <>
+ <Button
+ onClick={handleDiscard}
+ colorSchema="secondary"
+ variant="plain"
+ type="button"
+ >
+ Discard
+ </Button>
+ <Button
+ type="submit"
+ colorSchema="primary"
+ variant="solid"
+ leftIcon={<FontAwesomeIcon icon={faSave} />}
+ >
+ Save
+ </Button>
+ </>
+ )}
+ <Button
+ onClick={() => setIsAddUserModalOpen(true)}
+ colorSchema="primary"
+ variant="outline_bg"
+ leftIcon={<FontAwesomeIcon icon={faPlus} />}
+ isDisabled={!isAllowed || availableOrgUsers.length === 0}
+ type="button"
+ >
+ Add User
+ </Button>
+ </div>
+ )}
+ </OrgPermissionCan>
</div>
{errors.users && <span className="my-4 text-sm text-red">{errors.users.message}</span>}
<TableContainer>
@@ -251,7 +238,7 @@ export const ProjectTemplateUsersSection = ({ projectTemplate, isInfisicalTempla
<Tr>
<Th>Username</Th>
<Th>Roles</Th>
- {!isInfisicalTemplate && <Th className="w-16" />}
+ <Th className="w-16" />
</Tr>
</THead>
<TBody>
@@ -270,93 +257,79 @@ export const ProjectTemplateUsersSection = ({ projectTemplate, isInfisicalTempla
/>
</Td>
<Td>
- {isInfisicalTemplate ? (
- <Controller
- control={control}
- name={`users.${pos}.roles`}
- render={({ field }) => (
- <span className="text-sm">{getRoleNames(field.value)}</span>
- )}
- />
- ) : (
- <OrgPermissionCan
- I={OrgPermissionActions.Edit}
- a={OrgPermissionSubjects.ProjectTemplates}
- >
- {(isAllowed) => (
- <Controller
- control={control}
- name={`users.${pos}.roles`}
- render={({ field, fieldState: { error } }) => {
- // Include orphaned roles
- const availableRoleSlugs = new Set(
- availableRoles.map((r) => r.slug)
- );
- const orphanedRoles = field.value
- .filter((slug) => !availableRoleSlugs.has(slug))
- .map((slug) => ({ slug, name: slug }));
- const allOptions = [...availableRoles, ...orphanedRoles];
+ <OrgPermissionCan
+ I={OrgPermissionActions.Edit}
+ a={OrgPermissionSubjects.ProjectTemplates}
+ >
+ {(isAllowed) => (
+ <Controller
+ control={control}
+ name={`users.${pos}.roles`}
+ render={({ field, fieldState: { error } }) => {
+ // Include orphaned roles
+ const availableRoleSlugs = new Set(availableRoles.map((r) => r.slug));
+ const orphanedRoles = field.value
+ .filter((slug) => !availableRoleSlugs.has(slug))
+ .map((slug) => ({ slug, name: slug }));
+ const allOptions = [...availableRoles, ...orphanedRoles];
- const selectedValues = allOptions.filter((role) =>
- field.value.includes(role.slug)
- );
+ const selectedValues = allOptions.filter((role) =>
+ field.value.includes(role.slug)
+ );
- return (
- <FormControl
- isError={Boolean(error?.message)}
- errorText={error?.message}
- className="mb-0"
- >
- <FilterableSelect
- isMulti
- isDisabled={!isAllowed}
- options={allOptions}
- value={selectedValues}
- onChange={(selected) => {
- field.onChange(
- (selected as { slug: string; name: string }[]).map(
- (s) => s.slug
- )
- );
- }}
- getOptionValue={(option) => option.slug}
- getOptionLabel={(option) => option.name}
- placeholder="Select roles..."
- menuPosition="fixed"
- />
- </FormControl>
- );
- }}
- />
- )}
- </OrgPermissionCan>
- )}
+ return (
+ <FormControl
+ isError={Boolean(error?.message)}
+ errorText={error?.message}
+ className="mb-0"
+ >
+ <FilterableSelect
+ isMulti
+ isDisabled={!isAllowed}
+ options={allOptions}
+ value={selectedValues}
+ onChange={(selected) => {
+ field.onChange(
+ (selected as { slug: string; name: string }[]).map(
+ (s) => s.slug
+ )
+ );
+ }}
+ getOptionValue={(option) => option.slug}
+ getOptionLabel={(option) => option.name}
+ placeholder="Select roles..."
+ menuPosition="fixed"
+ />
+ </FormControl>
+ );
+ }}
+ />
+ )}
+ </OrgPermissionCan>
+ </Td>
+ <Td>
+ <OrgPermissionCan
+ I={OrgPermissionActions.Edit}
+ a={OrgPermissionSubjects.ProjectTemplates}
+ >
+ {(isAllowed) => (
+ <IconButton
+ onClick={() => remove(pos)}
+ colorSchema="danger"
+ variant="plain"
+ ariaLabel="Remove user"
+ isDisabled={!isAllowed}
+ >
+ <FontAwesomeIcon icon={faTrash} />
+ </IconButton>
+ )}
+ </OrgPermissionCan>
</Td>
- {!isInfisicalTemplate && (
- <Td>
- <OrgPermissionCan
- I={OrgPermissionActions.Edit}
- a={OrgPermissionSubjects.ProjectTemplates}
- >
- {(isAllowed) => (
- <IconButton
- onClick={() => remove(pos)}
- colorSchema="danger"
- variant="plain"
- ariaLabel="Remove user"
- isDisabled={!isAllowed}
- >
- <FontAwesomeIcon icon={faTrash} />
- </IconButton>
- )}
- </OrgPermissionCan>
- </Td>
- )}
</Tr>
))
) : (
<Tr>
- <Td colSpan={isInfisicalTemplate ? 2 : 3}>
+ <Td colSpan={3}>
<EmptyState title="No users assigned to this template" icon={faUsers} />
</Td>
</Tr>