mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-11-26 06:55:25 +00:00
Merge branch 'main' into feature/ldap-gateway-support
This commit is contained in:
+15
-1
@@ -2,6 +2,7 @@ import { useState } from "react";
|
||||
import { faPlus } from "@fortawesome/free-solid-svg-icons";
|
||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||
|
||||
import { UpgradePlanModal } from "@app/components/license/UpgradePlanModal";
|
||||
import { createNotification } from "@app/components/notifications";
|
||||
import { Button, DeleteActionModal } from "@app/components/v2";
|
||||
import { useProjectPermission } from "@app/context";
|
||||
@@ -9,6 +10,7 @@ import {
|
||||
ProjectPermissionActions,
|
||||
ProjectPermissionSub
|
||||
} from "@app/context/ProjectPermissionContext/types";
|
||||
import { usePopUp } from "@app/hooks";
|
||||
import {
|
||||
TCertificateProfileWithDetails,
|
||||
useDeleteCertificateProfile
|
||||
@@ -29,6 +31,7 @@ export const CertificateProfilesTab = () => {
|
||||
const [selectedProfile, setSelectedProfile] = useState<TCertificateProfileWithDetails | null>(
|
||||
null
|
||||
);
|
||||
const { popUp, handlePopUpOpen, handlePopUpToggle } = usePopUp(["upgradePlan"] as const);
|
||||
|
||||
const deleteProfile = useDeleteCertificateProfile();
|
||||
|
||||
@@ -99,7 +102,17 @@ export const CertificateProfilesTab = () => {
|
||||
onDeleteProfile={handleDeleteProfile}
|
||||
/>
|
||||
|
||||
<CreateProfileModal isOpen={isCreateModalOpen} onClose={() => setIsCreateModalOpen(false)} />
|
||||
<CreateProfileModal
|
||||
isOpen={isCreateModalOpen}
|
||||
onClose={() => setIsCreateModalOpen(false)}
|
||||
handlePopUpOpen={handlePopUpOpen}
|
||||
/>
|
||||
<UpgradePlanModal
|
||||
isOpen={popUp.upgradePlan.isOpen}
|
||||
onOpenChange={(isOpen) => handlePopUpToggle("upgradePlan", isOpen)}
|
||||
isEnterpriseFeature={popUp.upgradePlan.data?.isEnterpriseFeature}
|
||||
text="Your current plan does not include access to managing template enrollment options for ACME. To unlock this feature, please upgrade to Infisical Enterprise plan."
|
||||
/>
|
||||
|
||||
{selectedProfile && (
|
||||
<>
|
||||
@@ -109,6 +122,7 @@ export const CertificateProfilesTab = () => {
|
||||
setIsEditModalOpen(false);
|
||||
setSelectedProfile(null);
|
||||
}}
|
||||
handlePopUpOpen={handlePopUpOpen}
|
||||
profile={selectedProfile}
|
||||
mode="edit"
|
||||
/>
|
||||
|
||||
+26
-4
@@ -18,8 +18,7 @@ import {
|
||||
TextArea,
|
||||
Tooltip
|
||||
} from "@app/components/v2";
|
||||
import { envConfig } from "@app/config/env";
|
||||
import { useProject } from "@app/context";
|
||||
import { useProject, useSubscription } from "@app/context";
|
||||
import { useListCasByProjectId } from "@app/hooks/api/ca/queries";
|
||||
import {
|
||||
TCertificateProfileWithDetails,
|
||||
@@ -29,6 +28,7 @@ import {
|
||||
useUpdateCertificateProfile
|
||||
} from "@app/hooks/api/certificateProfiles";
|
||||
import { useListCertificateTemplatesV2 } from "@app/hooks/api/certificateTemplates/queries";
|
||||
import { UsePopUpState } from "@app/hooks/usePopUp";
|
||||
|
||||
const createSchema = z
|
||||
.object({
|
||||
@@ -151,12 +151,25 @@ export type FormData = z.infer<typeof createSchema>;
|
||||
interface Props {
|
||||
isOpen: boolean;
|
||||
onClose: () => void;
|
||||
handlePopUpOpen: (
|
||||
popUpName: keyof UsePopUpState<["upgradePlan"]>,
|
||||
data?: {
|
||||
isEnterpriseFeature?: boolean;
|
||||
}
|
||||
) => void;
|
||||
profile?: TCertificateProfileWithDetails;
|
||||
mode?: "create" | "edit";
|
||||
}
|
||||
|
||||
export const CreateProfileModal = ({ isOpen, onClose, profile, mode = "create" }: Props) => {
|
||||
export const CreateProfileModal = ({
|
||||
isOpen,
|
||||
onClose,
|
||||
handlePopUpOpen,
|
||||
profile,
|
||||
mode = "create"
|
||||
}: Props) => {
|
||||
const { currentProject } = useProject();
|
||||
const { subscription } = useSubscription();
|
||||
|
||||
const { data: caData } = useListCasByProjectId(currentProject?.id || "");
|
||||
const { data: templateData } = useListCertificateTemplatesV2({
|
||||
@@ -248,6 +261,15 @@ export const CreateProfileModal = ({ isOpen, onClose, profile, mode = "create" }
|
||||
}, [isEdit, profile, reset]);
|
||||
|
||||
const onFormSubmit = async (data: FormData) => {
|
||||
if (!isEdit && !subscription?.pkiAcme && data.enrollmentType === "acme") {
|
||||
reset();
|
||||
onClose();
|
||||
handlePopUpOpen("upgradePlan", {
|
||||
isEnterpriseFeature: true
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (!currentProject?.id && !isEdit) return;
|
||||
|
||||
if (isEdit) {
|
||||
@@ -467,7 +489,7 @@ export const CreateProfileModal = ({ isOpen, onClose, profile, mode = "create" }
|
||||
>
|
||||
<SelectItem value="api">API</SelectItem>
|
||||
<SelectItem value="est">EST</SelectItem>
|
||||
{envConfig.ACME_FEATURE_ENABLED && <SelectItem value="acme">ACME</SelectItem>}
|
||||
<SelectItem value="acme">ACME</SelectItem>
|
||||
</Select>
|
||||
</FormControl>
|
||||
)}
|
||||
|
||||
+7
-2
@@ -10,7 +10,7 @@ import {
|
||||
ProjectPermissionSub
|
||||
} from "@app/context/ProjectPermissionContext/types";
|
||||
import { useDeleteCertificateTemplateV2WithPolicies } from "@app/hooks/api/certificateTemplates/mutations";
|
||||
import { TCertificateTemplateV2WithPolicies } from "@app/hooks/api/certificateTemplates/types";
|
||||
import { type TCertificateTemplateV2WithPolicies } from "@app/hooks/api/certificateTemplates/types";
|
||||
|
||||
import { CreateTemplateModal } from "./CreateTemplateModal";
|
||||
import { TemplateList } from "./TemplateList";
|
||||
@@ -84,7 +84,12 @@ export const CertificateTemplatesV2Tab = () => {
|
||||
|
||||
<TemplateList onEditTemplate={handleEditTemplate} onDeleteTemplate={handleDeleteTemplate} />
|
||||
|
||||
<CreateTemplateModal isOpen={isCreateModalOpen} onClose={() => setIsCreateModalOpen(false)} />
|
||||
<CreateTemplateModal
|
||||
isOpen={isCreateModalOpen}
|
||||
onClose={() => {
|
||||
setIsCreateModalOpen(false);
|
||||
}}
|
||||
/>
|
||||
|
||||
{selectedTemplate && (
|
||||
<>
|
||||
|
||||
+157
-32
@@ -36,13 +36,18 @@ import {
|
||||
CertDurationUnit,
|
||||
CertExtendedKeyUsageType,
|
||||
CertKeyUsageType,
|
||||
CertSanInclude,
|
||||
CertSubjectAlternativeNameType,
|
||||
CertSubjectAttributeInclude,
|
||||
CertSubjectAttributeType,
|
||||
SAN_INCLUDE_OPTIONS,
|
||||
SAN_TYPE_OPTIONS,
|
||||
SUBJECT_ATTRIBUTE_INCLUDE_OPTIONS,
|
||||
SUBJECT_ATTRIBUTE_TYPE_OPTIONS
|
||||
SUBJECT_ATTRIBUTE_TYPE_OPTIONS,
|
||||
TEMPLATE_PRESET_IDS,
|
||||
type TemplatePresetId
|
||||
} from "./shared/certificate-constants";
|
||||
import { CERTIFICATE_TEMPLATE_PRESETS } from "./shared/template-presets";
|
||||
import { KeyUsagesSection, TemplateFormData, templateSchema } from "./shared";
|
||||
|
||||
export type FormData = TemplateFormData;
|
||||
@@ -91,7 +96,7 @@ const SIGNATURE_ALGORITHMS = [
|
||||
"SHA256-ECDSA",
|
||||
"SHA384-ECDSA",
|
||||
"SHA512-ECDSA"
|
||||
];
|
||||
] as const;
|
||||
|
||||
const KEY_ALGORITHMS = [
|
||||
"RSA-2048",
|
||||
@@ -100,7 +105,7 @@ const KEY_ALGORITHMS = [
|
||||
"ECDSA-P256",
|
||||
"ECDSA-P384",
|
||||
"ECDSA-P521"
|
||||
];
|
||||
] as const;
|
||||
|
||||
export const CreateTemplateModal = ({ isOpen, onClose, template, mode = "create" }: Props) => {
|
||||
const { currentProject } = useProject();
|
||||
@@ -117,7 +122,7 @@ export const CreateTemplateModal = ({ isOpen, onClose, template, mode = "create"
|
||||
subj.allowed.forEach((allowedValue) => {
|
||||
attributes.push({
|
||||
type: subj.type as CertSubjectAttributeType,
|
||||
include: "optional",
|
||||
include: CertSubjectAttributeInclude.OPTIONAL,
|
||||
value: [allowedValue]
|
||||
});
|
||||
});
|
||||
@@ -126,7 +131,7 @@ export const CreateTemplateModal = ({ isOpen, onClose, template, mode = "create"
|
||||
subj.denied.forEach((deniedValue) => {
|
||||
attributes.push({
|
||||
type: subj.type as CertSubjectAttributeType,
|
||||
include: "prohibit",
|
||||
include: CertSubjectAttributeInclude.PROHIBIT,
|
||||
value: [deniedValue]
|
||||
});
|
||||
});
|
||||
@@ -141,7 +146,7 @@ export const CreateTemplateModal = ({ isOpen, onClose, template, mode = "create"
|
||||
san.required.forEach((requiredValue) => {
|
||||
subjectAlternativeNames.push({
|
||||
type: san.type as CertSubjectAlternativeNameType,
|
||||
include: "mandatory",
|
||||
include: CertSanInclude.MANDATORY,
|
||||
value: [requiredValue]
|
||||
});
|
||||
});
|
||||
@@ -150,7 +155,7 @@ export const CreateTemplateModal = ({ isOpen, onClose, template, mode = "create"
|
||||
san.allowed.forEach((allowedValue) => {
|
||||
subjectAlternativeNames.push({
|
||||
type: san.type as CertSubjectAlternativeNameType,
|
||||
include: "optional",
|
||||
include: CertSanInclude.OPTIONAL,
|
||||
value: [allowedValue]
|
||||
});
|
||||
});
|
||||
@@ -159,7 +164,7 @@ export const CreateTemplateModal = ({ isOpen, onClose, template, mode = "create"
|
||||
san.denied.forEach((deniedValue) => {
|
||||
subjectAlternativeNames.push({
|
||||
type: san.type as CertSubjectAlternativeNameType,
|
||||
include: "prohibit",
|
||||
include: CertSanInclude.PROHIBIT,
|
||||
value: [deniedValue]
|
||||
});
|
||||
});
|
||||
@@ -219,6 +224,7 @@ export const CreateTemplateModal = ({ isOpen, onClose, template, mode = "create"
|
||||
};
|
||||
|
||||
return {
|
||||
preset: TEMPLATE_PRESET_IDS.CUSTOM,
|
||||
name: templateData.name || "",
|
||||
description: templateData.description || "",
|
||||
attributes,
|
||||
@@ -231,25 +237,30 @@ export const CreateTemplateModal = ({ isOpen, onClose, template, mode = "create"
|
||||
};
|
||||
};
|
||||
|
||||
const getDefaultValues = (): FormData => ({
|
||||
name: "",
|
||||
description: "",
|
||||
attributes: [],
|
||||
keyUsages: { requiredUsages: [], optionalUsages: [] },
|
||||
extendedKeyUsages: { requiredUsages: [], optionalUsages: [] },
|
||||
subjectAlternativeNames: [],
|
||||
validity: {
|
||||
maxDuration: { value: 365, unit: CertDurationUnit.DAYS }
|
||||
},
|
||||
signatureAlgorithm: {
|
||||
allowedAlgorithms: []
|
||||
},
|
||||
keyAlgorithm: {
|
||||
allowedKeyTypes: []
|
||||
}
|
||||
});
|
||||
const getDefaultValues = (): FormData & { preset: TemplatePresetId } => {
|
||||
return {
|
||||
preset: TEMPLATE_PRESET_IDS.CUSTOM,
|
||||
name: "",
|
||||
description: "",
|
||||
attributes: [],
|
||||
keyUsages: { requiredUsages: [], optionalUsages: [] },
|
||||
extendedKeyUsages: { requiredUsages: [], optionalUsages: [] },
|
||||
subjectAlternativeNames: [],
|
||||
validity: {
|
||||
maxDuration: { value: 365, unit: CertDurationUnit.DAYS }
|
||||
},
|
||||
signatureAlgorithm: {
|
||||
allowedAlgorithms: []
|
||||
},
|
||||
keyAlgorithm: {
|
||||
allowedKeyTypes: []
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
const { control, handleSubmit, reset, watch, setValue, formState } = useForm<FormData>({
|
||||
const { control, handleSubmit, reset, watch, setValue, formState } = useForm<
|
||||
FormData & { preset: TemplatePresetId }
|
||||
>({
|
||||
resolver: zodResolver(templateSchema),
|
||||
defaultValues: getDefaultValues(),
|
||||
mode: "onChange",
|
||||
@@ -260,7 +271,7 @@ export const CreateTemplateModal = ({ isOpen, onClose, template, mode = "create"
|
||||
useEffect(() => {
|
||||
if (isEdit && template) {
|
||||
const convertedData = convertApiToUiFormat(template);
|
||||
reset(convertedData);
|
||||
reset({ ...convertedData, preset: TEMPLATE_PRESET_IDS.CUSTOM });
|
||||
} else if (!isEdit) {
|
||||
reset(getDefaultValues());
|
||||
}
|
||||
@@ -273,6 +284,37 @@ export const CreateTemplateModal = ({ isOpen, onClose, template, mode = "create"
|
||||
requiredUsages: [],
|
||||
optionalUsages: []
|
||||
};
|
||||
const watchedPreset = watch("preset") || TEMPLATE_PRESET_IDS.CUSTOM;
|
||||
|
||||
const handlePresetChange = (presetId: TemplatePresetId) => {
|
||||
setValue("preset", presetId);
|
||||
|
||||
if (presetId === TEMPLATE_PRESET_IDS.CUSTOM) {
|
||||
return;
|
||||
}
|
||||
|
||||
const selectedPreset = CERTIFICATE_TEMPLATE_PRESETS.find((p) => p.id === presetId);
|
||||
if (selectedPreset) {
|
||||
if (selectedPreset.formData.keyUsages) {
|
||||
setValue("keyUsages", selectedPreset.formData.keyUsages);
|
||||
}
|
||||
if (selectedPreset.formData.extendedKeyUsages) {
|
||||
setValue("extendedKeyUsages", selectedPreset.formData.extendedKeyUsages);
|
||||
}
|
||||
if (selectedPreset.formData.attributes) {
|
||||
setValue("attributes", selectedPreset.formData.attributes);
|
||||
}
|
||||
if (selectedPreset.formData.subjectAlternativeNames) {
|
||||
setValue("subjectAlternativeNames", selectedPreset.formData.subjectAlternativeNames);
|
||||
}
|
||||
if (selectedPreset.formData.signatureAlgorithm) {
|
||||
setValue("signatureAlgorithm", selectedPreset.formData.signatureAlgorithm);
|
||||
}
|
||||
if (selectedPreset.formData.keyAlgorithm) {
|
||||
setValue("keyAlgorithm", selectedPreset.formData.keyAlgorithm);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const consolidateByType = <
|
||||
T extends { type: string; allowed?: string[]; required?: string[]; denied?: string[] }
|
||||
@@ -309,9 +351,17 @@ export const CreateTemplateModal = ({ isOpen, onClose, template, mode = "create"
|
||||
data.attributes?.map((attr) => {
|
||||
const result: AttributeTransform = { type: attr.type };
|
||||
|
||||
if (attr.include === "optional" && attr.value && attr.value.length > 0) {
|
||||
if (
|
||||
attr.include === CertSubjectAttributeInclude.OPTIONAL &&
|
||||
attr.value &&
|
||||
attr.value.length > 0
|
||||
) {
|
||||
result.allowed = attr.value;
|
||||
} else if (attr.include === "prohibit" && attr.value && attr.value.length > 0) {
|
||||
} else if (
|
||||
attr.include === CertSubjectAttributeInclude.PROHIBIT &&
|
||||
attr.value &&
|
||||
attr.value.length > 0
|
||||
) {
|
||||
result.denied = attr.value;
|
||||
}
|
||||
|
||||
@@ -322,11 +372,11 @@ export const CreateTemplateModal = ({ isOpen, onClose, template, mode = "create"
|
||||
data.subjectAlternativeNames?.map((san) => {
|
||||
const result: SanTransform = { type: san.type };
|
||||
|
||||
if (san.include === "mandatory" && san.value && san.value.length > 0) {
|
||||
if (san.include === CertSanInclude.MANDATORY && san.value && san.value.length > 0) {
|
||||
result.required = san.value;
|
||||
} else if (san.include === "optional" && san.value && san.value.length > 0) {
|
||||
} else if (san.include === CertSanInclude.OPTIONAL && san.value && san.value.length > 0) {
|
||||
result.allowed = san.value;
|
||||
} else if (san.include === "prohibit" && san.value && san.value.length > 0) {
|
||||
} else if (san.include === CertSanInclude.PROHIBIT && san.value && san.value.length > 0) {
|
||||
result.denied = san.value;
|
||||
}
|
||||
|
||||
@@ -464,11 +514,19 @@ export const CreateTemplateModal = ({ isOpen, onClose, template, mode = "create"
|
||||
value: ["*"]
|
||||
};
|
||||
setValue("attributes", [...watchedAttributes, newAttribute]);
|
||||
|
||||
if (watchedPreset !== TEMPLATE_PRESET_IDS.CUSTOM) {
|
||||
setValue("preset", TEMPLATE_PRESET_IDS.CUSTOM);
|
||||
}
|
||||
};
|
||||
|
||||
const removeAttribute = (index: number) => {
|
||||
const newAttributes = watchedAttributes.filter((_, i) => i !== index);
|
||||
setValue("attributes", newAttributes);
|
||||
|
||||
if (watchedPreset !== TEMPLATE_PRESET_IDS.CUSTOM) {
|
||||
setValue("preset", TEMPLATE_PRESET_IDS.CUSTOM);
|
||||
}
|
||||
};
|
||||
|
||||
const addSan = () => {
|
||||
@@ -478,11 +536,19 @@ export const CreateTemplateModal = ({ isOpen, onClose, template, mode = "create"
|
||||
value: ["*"]
|
||||
};
|
||||
setValue("subjectAlternativeNames", [...watchedSans, newSan]);
|
||||
|
||||
if (watchedPreset !== TEMPLATE_PRESET_IDS.CUSTOM) {
|
||||
setValue("preset", TEMPLATE_PRESET_IDS.CUSTOM);
|
||||
}
|
||||
};
|
||||
|
||||
const removeSan = (index: number) => {
|
||||
const newSans = watchedSans.filter((_, i) => i !== index);
|
||||
setValue("subjectAlternativeNames", newSans);
|
||||
|
||||
if (watchedPreset !== TEMPLATE_PRESET_IDS.CUSTOM) {
|
||||
setValue("preset", TEMPLATE_PRESET_IDS.CUSTOM);
|
||||
}
|
||||
};
|
||||
|
||||
const handleKeyUsagesChange = (usages: {
|
||||
@@ -493,6 +559,10 @@ export const CreateTemplateModal = ({ isOpen, onClose, template, mode = "create"
|
||||
requiredUsages: usages.requiredUsages,
|
||||
optionalUsages: usages.optionalUsages
|
||||
});
|
||||
|
||||
if (watchedPreset !== TEMPLATE_PRESET_IDS.CUSTOM) {
|
||||
setValue("preset", TEMPLATE_PRESET_IDS.CUSTOM);
|
||||
}
|
||||
};
|
||||
|
||||
const handleExtendedKeyUsagesChange = (usages: {
|
||||
@@ -503,6 +573,10 @@ export const CreateTemplateModal = ({ isOpen, onClose, template, mode = "create"
|
||||
requiredUsages: usages.requiredUsages,
|
||||
optionalUsages: usages.optionalUsages
|
||||
});
|
||||
|
||||
if (watchedPreset !== TEMPLATE_PRESET_IDS.CUSTOM) {
|
||||
setValue("preset", TEMPLATE_PRESET_IDS.CUSTOM);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
@@ -555,6 +629,33 @@ export const CreateTemplateModal = ({ isOpen, onClose, template, mode = "create"
|
||||
</FormControl>
|
||||
)}
|
||||
/>
|
||||
|
||||
<Controller
|
||||
control={control}
|
||||
name="preset"
|
||||
render={({ field, fieldState: { error } }) => (
|
||||
<FormControl
|
||||
label="Template Preset"
|
||||
isError={Boolean(error)}
|
||||
errorText={error?.message}
|
||||
>
|
||||
<Select
|
||||
value={field.value}
|
||||
onValueChange={handlePresetChange}
|
||||
className="w-full"
|
||||
position="popper"
|
||||
dropdownContainerClassName="max-w-none"
|
||||
>
|
||||
<SelectItem value={TEMPLATE_PRESET_IDS.CUSTOM}>Custom</SelectItem>
|
||||
{CERTIFICATE_TEMPLATE_PRESETS.map((preset) => (
|
||||
<SelectItem key={preset.id} value={preset.id}>
|
||||
{preset.name}
|
||||
</SelectItem>
|
||||
))}
|
||||
</Select>
|
||||
</FormControl>
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
<AccordionItem value="attributes">
|
||||
<AccordionTrigger>Subject Attributes</AccordionTrigger>
|
||||
@@ -595,6 +696,10 @@ export const CreateTemplateModal = ({ isOpen, onClose, template, mode = "create"
|
||||
type: value as CertSubjectAttributeType
|
||||
};
|
||||
setValue("attributes", newAttributes);
|
||||
|
||||
if (watchedPreset !== TEMPLATE_PRESET_IDS.CUSTOM) {
|
||||
setValue("preset", TEMPLATE_PRESET_IDS.CUSTOM);
|
||||
}
|
||||
}}
|
||||
className="w-48"
|
||||
>
|
||||
@@ -615,6 +720,10 @@ export const CreateTemplateModal = ({ isOpen, onClose, template, mode = "create"
|
||||
value as (typeof SUBJECT_ATTRIBUTE_INCLUDE_OPTIONS)[number]
|
||||
};
|
||||
setValue("attributes", newAttributes);
|
||||
|
||||
if (watchedPreset !== TEMPLATE_PRESET_IDS.CUSTOM) {
|
||||
setValue("preset", TEMPLATE_PRESET_IDS.CUSTOM);
|
||||
}
|
||||
}}
|
||||
className="w-32"
|
||||
>
|
||||
@@ -635,6 +744,10 @@ export const CreateTemplateModal = ({ isOpen, onClose, template, mode = "create"
|
||||
value: e.target.value.trim() ? [e.target.value.trim()] : []
|
||||
};
|
||||
setValue("attributes", newAttributes);
|
||||
|
||||
if (watchedPreset !== TEMPLATE_PRESET_IDS.CUSTOM) {
|
||||
setValue("preset", TEMPLATE_PRESET_IDS.CUSTOM);
|
||||
}
|
||||
}}
|
||||
className={`flex-1 ${
|
||||
attr.value && attr.value.length > 0 && attr.value[0] === ""
|
||||
@@ -701,6 +814,10 @@ export const CreateTemplateModal = ({ isOpen, onClose, template, mode = "create"
|
||||
type: value as CertSubjectAlternativeNameType
|
||||
};
|
||||
setValue("subjectAlternativeNames", newSans);
|
||||
|
||||
if (watchedPreset !== TEMPLATE_PRESET_IDS.CUSTOM) {
|
||||
setValue("preset", TEMPLATE_PRESET_IDS.CUSTOM);
|
||||
}
|
||||
}}
|
||||
className="w-36"
|
||||
>
|
||||
@@ -720,6 +837,10 @@ export const CreateTemplateModal = ({ isOpen, onClose, template, mode = "create"
|
||||
include: value as (typeof SAN_INCLUDE_OPTIONS)[number]
|
||||
};
|
||||
setValue("subjectAlternativeNames", newSans);
|
||||
|
||||
if (watchedPreset !== TEMPLATE_PRESET_IDS.CUSTOM) {
|
||||
setValue("preset", TEMPLATE_PRESET_IDS.CUSTOM);
|
||||
}
|
||||
}}
|
||||
className="w-32"
|
||||
>
|
||||
@@ -740,6 +861,10 @@ export const CreateTemplateModal = ({ isOpen, onClose, template, mode = "create"
|
||||
value: e.target.value.trim() ? [e.target.value.trim()] : []
|
||||
};
|
||||
setValue("subjectAlternativeNames", newSans);
|
||||
|
||||
if (watchedPreset !== TEMPLATE_PRESET_IDS.CUSTOM) {
|
||||
setValue("preset", TEMPLATE_PRESET_IDS.CUSTOM);
|
||||
}
|
||||
}}
|
||||
className={`flex-1 ${
|
||||
san.value && san.value.length > 0 && san.value[0] === ""
|
||||
|
||||
+37
-2
@@ -150,8 +150,19 @@ export const SUBJECT_ATTRIBUTE_TYPE_OPTIONS = Object.values(CertSubjectAttribute
|
||||
export const ATTRIBUTE_RULE_OPTIONS = Object.values(CertAttributeRule);
|
||||
export const SAN_EFFECT_OPTIONS = Object.values(CertSanEffect);
|
||||
|
||||
export const SUBJECT_ATTRIBUTE_INCLUDE_OPTIONS = ["optional", "prohibit"] as const;
|
||||
export const SAN_INCLUDE_OPTIONS = ["mandatory", "optional", "prohibit"] as const;
|
||||
export enum CertSubjectAttributeInclude {
|
||||
OPTIONAL = "optional",
|
||||
PROHIBIT = "prohibit"
|
||||
}
|
||||
|
||||
export enum CertSanInclude {
|
||||
MANDATORY = "mandatory",
|
||||
OPTIONAL = "optional",
|
||||
PROHIBIT = "prohibit"
|
||||
}
|
||||
|
||||
export const SUBJECT_ATTRIBUTE_INCLUDE_OPTIONS = Object.values(CertSubjectAttributeInclude);
|
||||
export const SAN_INCLUDE_OPTIONS = Object.values(CertSanInclude);
|
||||
|
||||
export const USAGE_STATES = {
|
||||
REQUIRED: "required",
|
||||
@@ -239,3 +250,27 @@ export const mapTemplateKeyAlgorithmToApi = (templateFormat: string): string =>
|
||||
};
|
||||
return mapping[templateFormat] || templateFormat;
|
||||
};
|
||||
|
||||
export const TEMPLATE_PRESET_IDS = {
|
||||
CUSTOM: "custom",
|
||||
TLS_SERVER: "tls-server",
|
||||
TLS_CLIENT: "tls-client",
|
||||
CODE_SIGNING: "code-signing",
|
||||
DEVICE: "device",
|
||||
USER: "user",
|
||||
EMAIL_PROTECTION: "email-protection",
|
||||
DUAL_PURPOSE_SERVER: "dual-purpose-server"
|
||||
} as const;
|
||||
|
||||
export type TemplatePresetId = (typeof TEMPLATE_PRESET_IDS)[keyof typeof TEMPLATE_PRESET_IDS];
|
||||
|
||||
export const ALGORITHM_FAMILIES = {
|
||||
ECDSA: {
|
||||
signature: ["SHA256-ECDSA", "SHA384-ECDSA", "SHA512-ECDSA"] as const,
|
||||
key: ["ECDSA-P256", "ECDSA-P384", "ECDSA-P521"] as const
|
||||
},
|
||||
RSA: {
|
||||
signature: ["SHA256-RSA", "SHA384-RSA", "SHA512-RSA"] as const,
|
||||
key: ["RSA-2048", "RSA-3072", "RSA-4096"] as const
|
||||
}
|
||||
} as const;
|
||||
|
||||
+19
-4
@@ -4,21 +4,22 @@ import {
|
||||
CertDurationUnit,
|
||||
CertExtendedKeyUsageType,
|
||||
CertKeyUsageType,
|
||||
CertSanInclude,
|
||||
CertSubjectAlternativeNameType,
|
||||
CertSubjectAttributeInclude,
|
||||
CertSubjectAttributeType,
|
||||
SAN_INCLUDE_OPTIONS,
|
||||
SUBJECT_ATTRIBUTE_INCLUDE_OPTIONS
|
||||
TEMPLATE_PRESET_IDS
|
||||
} from "./certificate-constants";
|
||||
|
||||
export const uiAttributeSchema = z.object({
|
||||
type: z.nativeEnum(CertSubjectAttributeType),
|
||||
include: z.enum(SUBJECT_ATTRIBUTE_INCLUDE_OPTIONS),
|
||||
include: z.nativeEnum(CertSubjectAttributeInclude),
|
||||
value: z.array(z.string().min(1, "Value cannot be empty"))
|
||||
});
|
||||
|
||||
export const uiSanSchema = z.object({
|
||||
type: z.nativeEnum(CertSubjectAlternativeNameType),
|
||||
include: z.enum(SAN_INCLUDE_OPTIONS),
|
||||
include: z.nativeEnum(CertSanInclude),
|
||||
value: z.array(z.string().min(1, "Value cannot be empty"))
|
||||
});
|
||||
|
||||
@@ -51,7 +52,21 @@ export const uiKeyAlgorithmSchema = z.object({
|
||||
.min(1, "At least one key type must be selected")
|
||||
});
|
||||
|
||||
export const uiPresetSchema = z
|
||||
.enum([
|
||||
TEMPLATE_PRESET_IDS.CUSTOM,
|
||||
TEMPLATE_PRESET_IDS.TLS_SERVER,
|
||||
TEMPLATE_PRESET_IDS.TLS_CLIENT,
|
||||
TEMPLATE_PRESET_IDS.CODE_SIGNING,
|
||||
TEMPLATE_PRESET_IDS.DEVICE,
|
||||
TEMPLATE_PRESET_IDS.USER,
|
||||
TEMPLATE_PRESET_IDS.EMAIL_PROTECTION,
|
||||
TEMPLATE_PRESET_IDS.DUAL_PURPOSE_SERVER
|
||||
])
|
||||
.default(TEMPLATE_PRESET_IDS.CUSTOM);
|
||||
|
||||
export const templateSchema = z.object({
|
||||
preset: uiPresetSchema,
|
||||
name: z
|
||||
.string()
|
||||
.trim()
|
||||
|
||||
+385
@@ -0,0 +1,385 @@
|
||||
import {
|
||||
ALGORITHM_FAMILIES,
|
||||
CertDurationUnit,
|
||||
CertExtendedKeyUsageType,
|
||||
CertKeyUsageType,
|
||||
CertSanInclude,
|
||||
CertSubjectAlternativeNameType,
|
||||
CertSubjectAttributeInclude,
|
||||
CertSubjectAttributeType,
|
||||
TEMPLATE_PRESET_IDS,
|
||||
type TemplatePresetId
|
||||
} from "./certificate-constants";
|
||||
import { TemplateFormData } from ".";
|
||||
|
||||
export interface CertificateTemplatePreset {
|
||||
readonly id: TemplatePresetId;
|
||||
readonly name: string;
|
||||
readonly description: string;
|
||||
readonly useCase: string;
|
||||
readonly formData: Omit<TemplateFormData, "preset">;
|
||||
}
|
||||
|
||||
export const CERTIFICATE_TEMPLATE_PRESETS: CertificateTemplatePreset[] = [
|
||||
{
|
||||
id: TEMPLATE_PRESET_IDS.TLS_SERVER,
|
||||
name: "TLS Server Certificate",
|
||||
description: "Standard TLS/SSL server certificate for HTTPS services and API endpoints.",
|
||||
useCase: "Web servers, API endpoints, HTTPS services",
|
||||
formData: {
|
||||
name: "TLS Server Certificate",
|
||||
description: "Standard TLS/SSL server certificate for HTTPS services and API endpoints.",
|
||||
keyUsages: {
|
||||
requiredUsages: [CertKeyUsageType.DIGITAL_SIGNATURE],
|
||||
optionalUsages: [CertKeyUsageType.DIGITAL_SIGNATURE, CertKeyUsageType.KEY_ENCIPHERMENT]
|
||||
},
|
||||
extendedKeyUsages: {
|
||||
requiredUsages: [CertExtendedKeyUsageType.SERVER_AUTH],
|
||||
optionalUsages: [CertExtendedKeyUsageType.SERVER_AUTH]
|
||||
},
|
||||
validity: {
|
||||
maxDuration: {
|
||||
value: 365,
|
||||
unit: CertDurationUnit.DAYS
|
||||
}
|
||||
},
|
||||
attributes: [
|
||||
{
|
||||
type: CertSubjectAttributeType.COMMON_NAME,
|
||||
include: CertSubjectAttributeInclude.OPTIONAL,
|
||||
value: ["*"]
|
||||
}
|
||||
],
|
||||
subjectAlternativeNames: [
|
||||
{
|
||||
type: CertSubjectAlternativeNameType.DNS_NAME,
|
||||
include: CertSanInclude.OPTIONAL,
|
||||
value: ["*"]
|
||||
},
|
||||
{
|
||||
type: CertSubjectAlternativeNameType.IP_ADDRESS,
|
||||
include: CertSanInclude.OPTIONAL,
|
||||
value: ["*"]
|
||||
}
|
||||
],
|
||||
signatureAlgorithm: {
|
||||
allowedAlgorithms: [...ALGORITHM_FAMILIES.ECDSA.signature]
|
||||
},
|
||||
keyAlgorithm: {
|
||||
allowedKeyTypes: [...ALGORITHM_FAMILIES.ECDSA.key]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
id: TEMPLATE_PRESET_IDS.TLS_CLIENT,
|
||||
name: "TLS Client Certificate",
|
||||
description: "Client certificate for mutual TLS authentication and API access.",
|
||||
useCase: "Client authentication, mTLS, API authentication",
|
||||
formData: {
|
||||
name: "TLS Client Certificate",
|
||||
description: "Client certificate for mutual TLS authentication and API access.",
|
||||
keyUsages: {
|
||||
requiredUsages: [CertKeyUsageType.DIGITAL_SIGNATURE],
|
||||
optionalUsages: [CertKeyUsageType.DIGITAL_SIGNATURE, CertKeyUsageType.KEY_AGREEMENT]
|
||||
},
|
||||
extendedKeyUsages: {
|
||||
requiredUsages: [CertExtendedKeyUsageType.CLIENT_AUTH],
|
||||
optionalUsages: [CertExtendedKeyUsageType.CLIENT_AUTH]
|
||||
},
|
||||
validity: {
|
||||
maxDuration: {
|
||||
value: 365,
|
||||
unit: CertDurationUnit.DAYS
|
||||
}
|
||||
},
|
||||
attributes: [
|
||||
{
|
||||
type: CertSubjectAttributeType.COMMON_NAME,
|
||||
include: CertSubjectAttributeInclude.OPTIONAL,
|
||||
value: ["*"]
|
||||
}
|
||||
],
|
||||
subjectAlternativeNames: [
|
||||
{
|
||||
type: CertSubjectAlternativeNameType.EMAIL,
|
||||
include: CertSanInclude.OPTIONAL,
|
||||
value: ["*"]
|
||||
},
|
||||
{
|
||||
type: CertSubjectAlternativeNameType.DNS_NAME,
|
||||
include: CertSanInclude.OPTIONAL,
|
||||
value: ["*"]
|
||||
}
|
||||
],
|
||||
signatureAlgorithm: {
|
||||
allowedAlgorithms: [...ALGORITHM_FAMILIES.ECDSA.signature]
|
||||
},
|
||||
keyAlgorithm: {
|
||||
allowedKeyTypes: [...ALGORITHM_FAMILIES.ECDSA.key]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
id: TEMPLATE_PRESET_IDS.CODE_SIGNING,
|
||||
name: "Code Signing Certificate",
|
||||
description:
|
||||
"Certificate for signing software, executables, and packages. Requires hardware security modules.",
|
||||
useCase: "Software signing, executable authentication, package validation",
|
||||
formData: {
|
||||
name: "Code Signing Certificate",
|
||||
description:
|
||||
"Certificate for signing software, executables, and packages. Requires hardware security modules.",
|
||||
keyUsages: {
|
||||
requiredUsages: [CertKeyUsageType.DIGITAL_SIGNATURE, CertKeyUsageType.NON_REPUDIATION],
|
||||
optionalUsages: [CertKeyUsageType.DIGITAL_SIGNATURE, CertKeyUsageType.NON_REPUDIATION]
|
||||
},
|
||||
extendedKeyUsages: {
|
||||
requiredUsages: [CertExtendedKeyUsageType.CODE_SIGNING],
|
||||
optionalUsages: [
|
||||
CertExtendedKeyUsageType.CODE_SIGNING,
|
||||
CertExtendedKeyUsageType.TIME_STAMPING
|
||||
]
|
||||
},
|
||||
validity: {
|
||||
maxDuration: {
|
||||
value: 365,
|
||||
unit: CertDurationUnit.DAYS
|
||||
}
|
||||
},
|
||||
attributes: [
|
||||
{
|
||||
type: CertSubjectAttributeType.COMMON_NAME,
|
||||
include: CertSubjectAttributeInclude.OPTIONAL,
|
||||
value: ["*"]
|
||||
}
|
||||
],
|
||||
subjectAlternativeNames: [
|
||||
{
|
||||
type: CertSubjectAlternativeNameType.EMAIL,
|
||||
include: CertSanInclude.OPTIONAL,
|
||||
value: ["*"]
|
||||
}
|
||||
],
|
||||
signatureAlgorithm: {
|
||||
allowedAlgorithms: [...ALGORITHM_FAMILIES.RSA.signature]
|
||||
},
|
||||
keyAlgorithm: {
|
||||
allowedKeyTypes: [...ALGORITHM_FAMILIES.RSA.key]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
id: TEMPLATE_PRESET_IDS.DEVICE,
|
||||
name: "Device Certificate",
|
||||
description:
|
||||
"Certificate for IoT devices and embedded systems authentication. IEEE 802.1AR compliant.",
|
||||
useCase: "Device authentication, IoT security, embedded systems",
|
||||
formData: {
|
||||
name: "Device Certificate",
|
||||
description:
|
||||
"Certificate for IoT devices and embedded systems authentication. IEEE 802.1AR compliant.",
|
||||
keyUsages: {
|
||||
requiredUsages: [CertKeyUsageType.DIGITAL_SIGNATURE],
|
||||
optionalUsages: [CertKeyUsageType.DIGITAL_SIGNATURE, CertKeyUsageType.KEY_AGREEMENT]
|
||||
},
|
||||
extendedKeyUsages: {
|
||||
requiredUsages: [CertExtendedKeyUsageType.CLIENT_AUTH],
|
||||
optionalUsages: [CertExtendedKeyUsageType.CLIENT_AUTH, CertExtendedKeyUsageType.SERVER_AUTH]
|
||||
},
|
||||
validity: {
|
||||
maxDuration: {
|
||||
value: 365,
|
||||
unit: CertDurationUnit.DAYS
|
||||
}
|
||||
},
|
||||
attributes: [
|
||||
{
|
||||
type: CertSubjectAttributeType.COMMON_NAME,
|
||||
include: CertSubjectAttributeInclude.OPTIONAL,
|
||||
value: ["*"]
|
||||
}
|
||||
],
|
||||
subjectAlternativeNames: [
|
||||
{
|
||||
type: CertSubjectAlternativeNameType.DNS_NAME,
|
||||
include: CertSanInclude.OPTIONAL,
|
||||
value: ["*"]
|
||||
},
|
||||
{
|
||||
type: CertSubjectAlternativeNameType.IP_ADDRESS,
|
||||
include: CertSanInclude.OPTIONAL,
|
||||
value: ["*"]
|
||||
}
|
||||
],
|
||||
signatureAlgorithm: {
|
||||
allowedAlgorithms: [...ALGORITHM_FAMILIES.ECDSA.signature]
|
||||
},
|
||||
keyAlgorithm: {
|
||||
allowedKeyTypes: [...ALGORITHM_FAMILIES.ECDSA.key]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
id: TEMPLATE_PRESET_IDS.USER,
|
||||
name: "User Certificate",
|
||||
description:
|
||||
"Personal certificate for user authentication and email signing. FIPS 201 PIV compliant.",
|
||||
useCase: "Personal authentication, smart cards, email protection",
|
||||
formData: {
|
||||
name: "User Certificate",
|
||||
description:
|
||||
"Personal certificate for user authentication and email signing. FIPS 201 PIV compliant.",
|
||||
keyUsages: {
|
||||
requiredUsages: [CertKeyUsageType.DIGITAL_SIGNATURE],
|
||||
optionalUsages: [
|
||||
CertKeyUsageType.DIGITAL_SIGNATURE,
|
||||
CertKeyUsageType.KEY_ENCIPHERMENT,
|
||||
CertKeyUsageType.KEY_AGREEMENT
|
||||
]
|
||||
},
|
||||
extendedKeyUsages: {
|
||||
requiredUsages: [
|
||||
CertExtendedKeyUsageType.CLIENT_AUTH,
|
||||
CertExtendedKeyUsageType.EMAIL_PROTECTION
|
||||
],
|
||||
optionalUsages: [
|
||||
CertExtendedKeyUsageType.CLIENT_AUTH,
|
||||
CertExtendedKeyUsageType.EMAIL_PROTECTION
|
||||
]
|
||||
},
|
||||
validity: {
|
||||
maxDuration: {
|
||||
value: 365,
|
||||
unit: CertDurationUnit.DAYS
|
||||
}
|
||||
},
|
||||
attributes: [
|
||||
{
|
||||
type: CertSubjectAttributeType.COMMON_NAME,
|
||||
include: CertSubjectAttributeInclude.OPTIONAL,
|
||||
value: ["*"]
|
||||
}
|
||||
],
|
||||
subjectAlternativeNames: [
|
||||
{
|
||||
type: CertSubjectAlternativeNameType.EMAIL,
|
||||
include: CertSanInclude.OPTIONAL,
|
||||
value: ["*"]
|
||||
}
|
||||
],
|
||||
signatureAlgorithm: {
|
||||
allowedAlgorithms: [...ALGORITHM_FAMILIES.ECDSA.signature]
|
||||
},
|
||||
keyAlgorithm: {
|
||||
allowedKeyTypes: [...ALGORITHM_FAMILIES.ECDSA.key]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
id: TEMPLATE_PRESET_IDS.EMAIL_PROTECTION,
|
||||
name: "Email Protection Certificate",
|
||||
description: "S/MIME certificate for email encryption and digital signing. RFC 8550 compliant.",
|
||||
useCase: "Email encryption, digital signing, secure messaging",
|
||||
formData: {
|
||||
name: "Email Protection Certificate",
|
||||
description:
|
||||
"S/MIME certificate for email encryption and digital signing. RFC 8550 compliant.",
|
||||
keyUsages: {
|
||||
requiredUsages: [CertKeyUsageType.DIGITAL_SIGNATURE],
|
||||
optionalUsages: [
|
||||
CertKeyUsageType.DIGITAL_SIGNATURE,
|
||||
CertKeyUsageType.KEY_ENCIPHERMENT,
|
||||
CertKeyUsageType.KEY_AGREEMENT
|
||||
]
|
||||
},
|
||||
extendedKeyUsages: {
|
||||
requiredUsages: [CertExtendedKeyUsageType.EMAIL_PROTECTION],
|
||||
optionalUsages: [CertExtendedKeyUsageType.EMAIL_PROTECTION]
|
||||
},
|
||||
validity: {
|
||||
maxDuration: {
|
||||
value: 365,
|
||||
unit: CertDurationUnit.DAYS
|
||||
}
|
||||
},
|
||||
attributes: [
|
||||
{
|
||||
type: CertSubjectAttributeType.COMMON_NAME,
|
||||
include: CertSubjectAttributeInclude.OPTIONAL,
|
||||
value: ["*"]
|
||||
}
|
||||
],
|
||||
subjectAlternativeNames: [
|
||||
{
|
||||
type: CertSubjectAlternativeNameType.EMAIL,
|
||||
include: CertSanInclude.OPTIONAL,
|
||||
value: ["*"]
|
||||
}
|
||||
],
|
||||
signatureAlgorithm: {
|
||||
allowedAlgorithms: [...ALGORITHM_FAMILIES.RSA.signature]
|
||||
},
|
||||
keyAlgorithm: {
|
||||
allowedKeyTypes: [...ALGORITHM_FAMILIES.RSA.key]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
id: TEMPLATE_PRESET_IDS.DUAL_PURPOSE_SERVER,
|
||||
name: "Dual-Purpose Server Certificate",
|
||||
description:
|
||||
"Certificate for services requiring both server and client authentication capabilities",
|
||||
useCase: "Microservices, service mesh, dual authentication",
|
||||
formData: {
|
||||
name: "Dual-Purpose Server Certificate",
|
||||
description:
|
||||
"Certificate for services requiring both server and client authentication capabilities",
|
||||
keyUsages: {
|
||||
requiredUsages: [CertKeyUsageType.DIGITAL_SIGNATURE],
|
||||
optionalUsages: [
|
||||
CertKeyUsageType.DIGITAL_SIGNATURE,
|
||||
CertKeyUsageType.KEY_ENCIPHERMENT,
|
||||
CertKeyUsageType.KEY_AGREEMENT
|
||||
]
|
||||
},
|
||||
extendedKeyUsages: {
|
||||
requiredUsages: [
|
||||
CertExtendedKeyUsageType.SERVER_AUTH,
|
||||
CertExtendedKeyUsageType.CLIENT_AUTH
|
||||
],
|
||||
optionalUsages: [CertExtendedKeyUsageType.SERVER_AUTH, CertExtendedKeyUsageType.CLIENT_AUTH]
|
||||
},
|
||||
validity: {
|
||||
maxDuration: {
|
||||
value: 365,
|
||||
unit: CertDurationUnit.DAYS
|
||||
}
|
||||
},
|
||||
attributes: [
|
||||
{
|
||||
type: CertSubjectAttributeType.COMMON_NAME,
|
||||
include: CertSubjectAttributeInclude.OPTIONAL,
|
||||
value: ["*"]
|
||||
}
|
||||
],
|
||||
subjectAlternativeNames: [
|
||||
{
|
||||
type: CertSubjectAlternativeNameType.DNS_NAME,
|
||||
include: CertSanInclude.OPTIONAL,
|
||||
value: ["*"]
|
||||
},
|
||||
{
|
||||
type: CertSubjectAlternativeNameType.IP_ADDRESS,
|
||||
include: CertSanInclude.OPTIONAL,
|
||||
value: ["*"]
|
||||
}
|
||||
],
|
||||
signatureAlgorithm: {
|
||||
allowedAlgorithms: [...ALGORITHM_FAMILIES.ECDSA.signature]
|
||||
},
|
||||
keyAlgorithm: {
|
||||
allowedKeyTypes: [...ALGORITHM_FAMILIES.ECDSA.key]
|
||||
}
|
||||
}
|
||||
}
|
||||
];
|
||||
+6
-3
@@ -3,6 +3,7 @@ import { Controller, useFieldArray, useForm } from "react-hook-form";
|
||||
import { faPlus, faXmark } from "@fortawesome/free-solid-svg-icons";
|
||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||
import { zodResolver } from "@hookform/resolvers/zod";
|
||||
import { useParams } from "@tanstack/react-router";
|
||||
import { z } from "zod";
|
||||
|
||||
import { createNotification } from "@app/components/notifications";
|
||||
@@ -76,7 +77,9 @@ export const IdentityAliCloudAuthForm = ({
|
||||
const { currentOrg } = useOrganization();
|
||||
const orgId = currentOrg?.id || "";
|
||||
const { subscription } = useSubscription();
|
||||
|
||||
const { projectId } = useParams({
|
||||
strict: false
|
||||
});
|
||||
const { mutateAsync: addMutateAsync } = useAddIdentityAliCloudAuth();
|
||||
const { mutateAsync: updateMutateAsync } = useUpdateIdentityAliCloudAuth();
|
||||
const [tabValue, setTabValue] = useState<IdentityFormTab>(IdentityFormTab.Configuration);
|
||||
@@ -144,7 +147,7 @@ export const IdentityAliCloudAuthForm = ({
|
||||
|
||||
if (data) {
|
||||
await updateMutateAsync({
|
||||
organizationId: orgId,
|
||||
...(projectId ? { projectId } : { organizationId: orgId }),
|
||||
allowedArns,
|
||||
identityId,
|
||||
accessTokenTTL: Number(accessTokenTTL),
|
||||
@@ -154,7 +157,7 @@ export const IdentityAliCloudAuthForm = ({
|
||||
});
|
||||
} else {
|
||||
await addMutateAsync({
|
||||
organizationId: orgId,
|
||||
...(projectId ? { projectId } : { organizationId: orgId }),
|
||||
identityId,
|
||||
allowedArns,
|
||||
accessTokenTTL: Number(accessTokenTTL),
|
||||
|
||||
+7
-6
@@ -3,6 +3,7 @@ import { Controller, useFieldArray, useForm } from "react-hook-form";
|
||||
import { faPlus, faXmark } from "@fortawesome/free-solid-svg-icons";
|
||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||
import { zodResolver } from "@hookform/resolvers/zod";
|
||||
import { useParams } from "@tanstack/react-router";
|
||||
import { z } from "zod";
|
||||
|
||||
import { createNotification } from "@app/components/notifications";
|
||||
@@ -78,7 +79,9 @@ export const IdentityAwsAuthForm = ({
|
||||
const { currentOrg } = useOrganization();
|
||||
const orgId = currentOrg?.id || "";
|
||||
const { subscription } = useSubscription();
|
||||
|
||||
const { projectId } = useParams({
|
||||
strict: false
|
||||
});
|
||||
const { mutateAsync: addMutateAsync } = useAddIdentityAwsAuth();
|
||||
const { mutateAsync: updateMutateAsync } = useUpdateIdentityAwsAuth();
|
||||
const [tabValue, setTabValue] = useState<IdentityFormTab>(IdentityFormTab.Configuration);
|
||||
@@ -154,7 +157,7 @@ export const IdentityAwsAuthForm = ({
|
||||
|
||||
if (data) {
|
||||
await updateMutateAsync({
|
||||
organizationId: orgId,
|
||||
...(projectId ? { projectId } : { organizationId: orgId }),
|
||||
stsEndpoint,
|
||||
allowedPrincipalArns,
|
||||
allowedAccountIds,
|
||||
@@ -166,7 +169,7 @@ export const IdentityAwsAuthForm = ({
|
||||
});
|
||||
} else {
|
||||
await addMutateAsync({
|
||||
organizationId: orgId,
|
||||
...(projectId ? { projectId } : { organizationId: orgId }),
|
||||
identityId,
|
||||
stsEndpoint: stsEndpoint || "",
|
||||
allowedPrincipalArns: allowedPrincipalArns || "",
|
||||
@@ -176,10 +179,8 @@ export const IdentityAwsAuthForm = ({
|
||||
accessTokenNumUsesLimit: Number(accessTokenNumUsesLimit),
|
||||
accessTokenTrustedIps
|
||||
});
|
||||
handlePopUpToggle("identityAuthMethod", false);
|
||||
}
|
||||
|
||||
handlePopUpToggle("identityAuthMethod", false);
|
||||
|
||||
createNotification({
|
||||
text: `Successfully ${isUpdate ? "updated" : "configured"} auth method`,
|
||||
type: "success"
|
||||
|
||||
+6
-3
@@ -3,6 +3,7 @@ import { Controller, useFieldArray, useForm } from "react-hook-form";
|
||||
import { faPlus, faXmark } from "@fortawesome/free-solid-svg-icons";
|
||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||
import { zodResolver } from "@hookform/resolvers/zod";
|
||||
import { useParams } from "@tanstack/react-router";
|
||||
import { z } from "zod";
|
||||
|
||||
import { createNotification } from "@app/components/notifications";
|
||||
@@ -73,7 +74,9 @@ export const IdentityAzureAuthForm = ({
|
||||
const { currentOrg } = useOrganization();
|
||||
const orgId = currentOrg?.id || "";
|
||||
const { subscription } = useSubscription();
|
||||
|
||||
const { projectId } = useParams({
|
||||
strict: false
|
||||
});
|
||||
const { mutateAsync: addMutateAsync } = useAddIdentityAzureAuth();
|
||||
const { mutateAsync: updateMutateAsync } = useUpdateIdentityAzureAuth();
|
||||
const [tabValue, setTabValue] = useState<IdentityFormTab>(IdentityFormTab.Configuration);
|
||||
@@ -150,7 +153,7 @@ export const IdentityAzureAuthForm = ({
|
||||
|
||||
if (data) {
|
||||
await updateMutateAsync({
|
||||
organizationId: orgId,
|
||||
...(projectId ? { projectId } : { organizationId: orgId }),
|
||||
identityId,
|
||||
tenantId,
|
||||
resource,
|
||||
@@ -162,7 +165,7 @@ export const IdentityAzureAuthForm = ({
|
||||
});
|
||||
} else {
|
||||
await addMutateAsync({
|
||||
organizationId: orgId,
|
||||
...(projectId ? { projectId } : { organizationId: orgId }),
|
||||
identityId,
|
||||
tenantId: tenantId || "",
|
||||
resource: resource || "",
|
||||
|
||||
+6
-4
@@ -3,6 +3,7 @@ import { Controller, useFieldArray, useForm } from "react-hook-form";
|
||||
import { faPlus, faXmark } from "@fortawesome/free-solid-svg-icons";
|
||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||
import { zodResolver } from "@hookform/resolvers/zod";
|
||||
import { useParams } from "@tanstack/react-router";
|
||||
import { z } from "zod";
|
||||
|
||||
import { createNotification } from "@app/components/notifications";
|
||||
@@ -76,7 +77,9 @@ export const IdentityGcpAuthForm = ({
|
||||
const { currentOrg } = useOrganization();
|
||||
const orgId = currentOrg?.id || "";
|
||||
const { subscription } = useSubscription();
|
||||
|
||||
const { projectId } = useParams({
|
||||
strict: false
|
||||
});
|
||||
const { mutateAsync: addMutateAsync } = useAddIdentityGcpAuth();
|
||||
const { mutateAsync: updateMutateAsync } = useUpdateIdentityGcpAuth();
|
||||
const [tabValue, setTabValue] = useState<IdentityFormTab>(IdentityFormTab.Configuration);
|
||||
@@ -160,7 +163,7 @@ export const IdentityGcpAuthForm = ({
|
||||
if (data) {
|
||||
await updateMutateAsync({
|
||||
identityId,
|
||||
organizationId: orgId,
|
||||
...(projectId ? { projectId } : { organizationId: orgId }),
|
||||
type,
|
||||
allowedServiceAccounts,
|
||||
allowedProjects,
|
||||
@@ -173,7 +176,7 @@ export const IdentityGcpAuthForm = ({
|
||||
} else {
|
||||
await addMutateAsync({
|
||||
identityId,
|
||||
organizationId: orgId,
|
||||
...(projectId ? { projectId } : { organizationId: orgId }),
|
||||
type,
|
||||
allowedServiceAccounts: allowedServiceAccounts || "",
|
||||
allowedProjects: allowedProjects || "",
|
||||
@@ -191,7 +194,6 @@ export const IdentityGcpAuthForm = ({
|
||||
text: `Successfully ${isUpdate ? "updated" : "configured"} auth method`,
|
||||
type: "success"
|
||||
});
|
||||
|
||||
reset();
|
||||
};
|
||||
|
||||
|
||||
+6
-4
@@ -4,6 +4,7 @@ import { faQuestionCircle } from "@fortawesome/free-regular-svg-icons";
|
||||
import { faPlus, faXmark } from "@fortawesome/free-solid-svg-icons";
|
||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||
import { zodResolver } from "@hookform/resolvers/zod";
|
||||
import { useParams } from "@tanstack/react-router";
|
||||
import { z } from "zod";
|
||||
|
||||
import { createNotification } from "@app/components/notifications";
|
||||
@@ -109,7 +110,9 @@ export const IdentityJwtAuthForm = ({
|
||||
const { currentOrg } = useOrganization();
|
||||
const orgId = currentOrg?.id || "";
|
||||
const { subscription } = useSubscription();
|
||||
|
||||
const { projectId } = useParams({
|
||||
strict: false
|
||||
});
|
||||
const { mutateAsync: addMutateAsync } = useAddIdentityJwtAuth();
|
||||
const { mutateAsync: updateMutateAsync } = useUpdateIdentityJwtAuth();
|
||||
const [tabValue, setTabValue] = useState<IdentityFormTab>(IdentityFormTab.Configuration);
|
||||
@@ -227,7 +230,7 @@ export const IdentityJwtAuthForm = ({
|
||||
if (data) {
|
||||
await updateMutateAsync({
|
||||
identityId,
|
||||
organizationId: orgId,
|
||||
...(projectId ? { projectId } : { organizationId: orgId }),
|
||||
configurationType,
|
||||
jwksUrl,
|
||||
jwksCaCert,
|
||||
@@ -252,7 +255,7 @@ export const IdentityJwtAuthForm = ({
|
||||
boundAudiences,
|
||||
boundClaims: Object.fromEntries(boundClaims.map((entry) => [entry.key, entry.value])),
|
||||
boundSubject,
|
||||
organizationId: orgId,
|
||||
...(projectId ? { projectId } : { organizationId: orgId }),
|
||||
accessTokenTTL: Number(accessTokenTTL),
|
||||
accessTokenMaxTTL: Number(accessTokenMaxTTL),
|
||||
accessTokenNumUsesLimit: Number(accessTokenNumUsesLimit),
|
||||
@@ -266,7 +269,6 @@ export const IdentityJwtAuthForm = ({
|
||||
text: `Successfully ${isUpdate ? "updated" : "configured"} auth method`,
|
||||
type: "success"
|
||||
});
|
||||
|
||||
reset();
|
||||
};
|
||||
|
||||
|
||||
+6
-3
@@ -4,6 +4,7 @@ import { faInfoCircle, faPlus, faXmark } from "@fortawesome/free-solid-svg-icons
|
||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||
import { zodResolver } from "@hookform/resolvers/zod";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { useParams } from "@tanstack/react-router";
|
||||
import { z } from "zod";
|
||||
|
||||
import { createNotification } from "@app/components/notifications";
|
||||
@@ -117,7 +118,9 @@ export const IdentityKubernetesAuthForm = ({
|
||||
const { currentOrg } = useOrganization();
|
||||
const orgId = currentOrg?.id || "";
|
||||
const { subscription } = useSubscription();
|
||||
|
||||
const { projectId } = useParams({
|
||||
strict: false
|
||||
});
|
||||
const { mutateAsync: addMutateAsync } = useAddIdentityKubernetesAuth();
|
||||
const { mutateAsync: updateMutateAsync } = useUpdateIdentityKubernetesAuth();
|
||||
const [tabValue, setTabValue] = useState<IdentityFormTab>(IdentityFormTab.Configuration);
|
||||
@@ -318,7 +321,7 @@ export const IdentityKubernetesAuthForm = ({
|
||||
|
||||
if (data) {
|
||||
await updateMutateAsync({
|
||||
organizationId: orgId,
|
||||
...(projectId ? { projectId } : { organizationId: orgId }),
|
||||
...(tokenReviewMode === IdentityKubernetesAuthTokenReviewMode.Api
|
||||
? {
|
||||
kubernetesHost: kubernetesHost || ""
|
||||
@@ -341,7 +344,7 @@ export const IdentityKubernetesAuthForm = ({
|
||||
});
|
||||
} else {
|
||||
await addMutateAsync({
|
||||
organizationId: orgId,
|
||||
...(projectId ? { projectId } : { organizationId: orgId }),
|
||||
identityId,
|
||||
...(tokenReviewMode === IdentityKubernetesAuthTokenReviewMode.Api
|
||||
? {
|
||||
|
||||
+5
-2
@@ -3,6 +3,7 @@ import { Controller, useFieldArray, useForm } from "react-hook-form";
|
||||
import { faPlus, faQuestionCircle, faXmark } from "@fortawesome/free-solid-svg-icons";
|
||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||
import { zodResolver } from "@hookform/resolvers/zod";
|
||||
import { useParams } from "@tanstack/react-router";
|
||||
import ms from "ms";
|
||||
import { z } from "zod";
|
||||
|
||||
@@ -168,7 +169,9 @@ export const IdentityLdapAuthForm = ({
|
||||
const { currentOrg } = useOrganization();
|
||||
const orgId = currentOrg?.id || "";
|
||||
const { subscription } = useSubscription();
|
||||
|
||||
const { projectId } = useParams({
|
||||
strict: false
|
||||
});
|
||||
const { mutateAsync: addMutateAsync } = useAddIdentityLdapAuth();
|
||||
const { mutateAsync: updateMutateAsync } = useUpdateIdentityLdapAuth();
|
||||
const [tabValue, setTabValue] = useState<IdentityFormTab>(IdentityFormTab.Configuration);
|
||||
@@ -345,7 +348,7 @@ export const IdentityLdapAuthForm = ({
|
||||
ms(`${lockoutCounterResetValue}${lockoutCounterResetUnit}`) / 1000;
|
||||
|
||||
const basePayload = {
|
||||
organizationId: orgId,
|
||||
...(projectId ? { projectId } : { organizationId: orgId }),
|
||||
identityId,
|
||||
searchFilter,
|
||||
ldapCaCertificate,
|
||||
|
||||
+6
-4
@@ -3,6 +3,7 @@ import { Controller, useFieldArray, useForm } from "react-hook-form";
|
||||
import { faPlus, faXmark } from "@fortawesome/free-solid-svg-icons";
|
||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||
import { zodResolver } from "@hookform/resolvers/zod";
|
||||
import { useParams } from "@tanstack/react-router";
|
||||
import { z } from "zod";
|
||||
|
||||
import { createNotification } from "@app/components/notifications";
|
||||
@@ -84,7 +85,9 @@ export const IdentityOciAuthForm = ({
|
||||
const { currentOrg } = useOrganization();
|
||||
const orgId = currentOrg?.id || "";
|
||||
const { subscription } = useSubscription();
|
||||
|
||||
const { projectId } = useParams({
|
||||
strict: false
|
||||
});
|
||||
const { mutateAsync: addMutateAsync } = useAddIdentityOciAuth();
|
||||
const { mutateAsync: updateMutateAsync } = useUpdateIdentityOciAuth();
|
||||
const [tabValue, setTabValue] = useState<IdentityFormTab>(IdentityFormTab.Configuration);
|
||||
@@ -156,7 +159,7 @@ export const IdentityOciAuthForm = ({
|
||||
|
||||
if (data) {
|
||||
await updateMutateAsync({
|
||||
organizationId: orgId,
|
||||
...(projectId ? { projectId } : { organizationId: orgId }),
|
||||
tenancyOcid,
|
||||
allowedUsernames,
|
||||
identityId,
|
||||
@@ -167,7 +170,7 @@ export const IdentityOciAuthForm = ({
|
||||
});
|
||||
} else {
|
||||
await addMutateAsync({
|
||||
organizationId: orgId,
|
||||
...(projectId ? { projectId } : { organizationId: orgId }),
|
||||
identityId,
|
||||
tenancyOcid,
|
||||
allowedUsernames: allowedUsernames || undefined,
|
||||
@@ -184,7 +187,6 @@ export const IdentityOciAuthForm = ({
|
||||
text: `Successfully ${isUpdate ? "updated" : "configured"} auth method`,
|
||||
type: "success"
|
||||
});
|
||||
|
||||
reset();
|
||||
};
|
||||
|
||||
|
||||
+6
-4
@@ -4,6 +4,7 @@ import { faQuestionCircle } from "@fortawesome/free-regular-svg-icons";
|
||||
import { faPlus, faXmark } from "@fortawesome/free-solid-svg-icons";
|
||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||
import { zodResolver } from "@hookform/resolvers/zod";
|
||||
import { useParams } from "@tanstack/react-router";
|
||||
import { z } from "zod";
|
||||
|
||||
import { createNotification } from "@app/components/notifications";
|
||||
@@ -96,7 +97,9 @@ export const IdentityOidcAuthForm = ({
|
||||
const { currentOrg } = useOrganization();
|
||||
const orgId = currentOrg?.id || "";
|
||||
const { subscription } = useSubscription();
|
||||
|
||||
const { projectId } = useParams({
|
||||
strict: false
|
||||
});
|
||||
const { mutateAsync: addMutateAsync } = useAddIdentityOidcAuth();
|
||||
const { mutateAsync: updateMutateAsync } = useUpdateIdentityOidcAuth();
|
||||
const [tabValue, setTabValue] = useState<IdentityFormTab>(IdentityFormTab.Configuration);
|
||||
@@ -211,7 +214,7 @@ export const IdentityOidcAuthForm = ({
|
||||
if (data) {
|
||||
await updateMutateAsync({
|
||||
identityId,
|
||||
organizationId: orgId,
|
||||
...(projectId ? { projectId } : { organizationId: orgId }),
|
||||
oidcDiscoveryUrl,
|
||||
caCert,
|
||||
boundIssuer,
|
||||
@@ -238,7 +241,7 @@ export const IdentityOidcAuthForm = ({
|
||||
? Object.fromEntries(claimMetadataMapping.map((entry) => [entry.key, entry.value]))
|
||||
: undefined,
|
||||
boundSubject,
|
||||
organizationId: orgId,
|
||||
...(projectId ? { projectId } : { organizationId: orgId }),
|
||||
accessTokenTTL: Number(accessTokenTTL),
|
||||
accessTokenMaxTTL: Number(accessTokenMaxTTL),
|
||||
accessTokenNumUsesLimit: Number(accessTokenNumUsesLimit),
|
||||
@@ -252,7 +255,6 @@ export const IdentityOidcAuthForm = ({
|
||||
text: `Successfully ${isUpdate ? "updated" : "configured"} auth method`,
|
||||
type: "success"
|
||||
});
|
||||
|
||||
reset();
|
||||
};
|
||||
|
||||
|
||||
+123
-45
@@ -1,5 +1,8 @@
|
||||
import { faLink, faPlus } from "@fortawesome/free-solid-svg-icons";
|
||||
import { useState } from "react";
|
||||
import { faPlus } from "@fortawesome/free-solid-svg-icons";
|
||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||
import { AnimatePresence, motion } from "framer-motion";
|
||||
import { LinkIcon, PlusIcon } from "lucide-react";
|
||||
|
||||
import { UpgradePlanModal } from "@app/components/license/UpgradePlanModal";
|
||||
import { createNotification } from "@app/components/notifications";
|
||||
@@ -14,17 +17,23 @@ import {
|
||||
} from "@app/context";
|
||||
import { OrgPermissionMachineIdentityAuthTemplateActions } from "@app/context/OrgPermissionContext/types";
|
||||
import { withPermission } from "@app/hoc";
|
||||
import { useDeleteIdentity } from "@app/hooks/api";
|
||||
import { useDeleteOrgIdentity } from "@app/hooks/api";
|
||||
import { useDeleteIdentityAuthTemplate } from "@app/hooks/api/identityAuthTemplates";
|
||||
import { usePopUp } from "@app/hooks/usePopUp";
|
||||
|
||||
import { IdentityAuthTemplateModal } from "./IdentityAuthTemplateModal";
|
||||
import { IdentityAuthTemplatesTable } from "./IdentityAuthTemplatesTable";
|
||||
import { IdentityLinkForm } from "./IdentityLinkForm";
|
||||
import { IdentityModal } from "./IdentityModal";
|
||||
import { IdentityTable } from "./IdentityTable";
|
||||
import { IdentityTokenAuthTokenModal } from "./IdentityTokenAuthTokenModal";
|
||||
import { MachineAuthTemplateUsagesModal } from "./MachineAuthTemplateUsagesModal";
|
||||
import { OrgIdentityLinkForm } from "./OrgIdentityLinkForm";
|
||||
import { OrgIdentityModal } from "./OrgIdentityModal";
|
||||
|
||||
enum IdentityWizardSteps {
|
||||
SelectAction = "select-action",
|
||||
LinkIdentity = "link-identity",
|
||||
OrganizationIdentity = "project-identity"
|
||||
}
|
||||
|
||||
export const IdentitySection = withPermission(
|
||||
() => {
|
||||
@@ -32,7 +41,9 @@ export const IdentitySection = withPermission(
|
||||
const { currentOrg, isSubOrganization } = useOrganization();
|
||||
const orgId = currentOrg?.id || "";
|
||||
|
||||
const { mutateAsync: deleteMutateAsync } = useDeleteIdentity();
|
||||
const [wizardStep, setWizardStep] = useState(IdentityWizardSteps.SelectAction);
|
||||
|
||||
const { mutateAsync: deleteMutateAsync } = useDeleteOrgIdentity();
|
||||
const { mutateAsync: deleteTemplateMutateAsync } = useDeleteIdentityAuthTemplate();
|
||||
const { popUp, handlePopUpOpen, handlePopUpClose, handlePopUpToggle } = usePopUp([
|
||||
"identity",
|
||||
@@ -46,7 +57,7 @@ export const IdentitySection = withPermission(
|
||||
"editTemplate",
|
||||
"deleteTemplate",
|
||||
"viewUsages",
|
||||
"linkIdentity"
|
||||
"addOptions"
|
||||
] as const);
|
||||
|
||||
const isMoreIdentitiesAllowed = subscription?.identityLimit
|
||||
@@ -58,7 +69,7 @@ export const IdentitySection = withPermission(
|
||||
const onDeleteIdentitySubmit = async (identityId: string) => {
|
||||
await deleteMutateAsync({
|
||||
identityId,
|
||||
organizationId: orgId
|
||||
orgId
|
||||
});
|
||||
|
||||
createNotification({
|
||||
@@ -91,50 +102,38 @@ export const IdentitySection = withPermission(
|
||||
<p className="text-xl font-medium text-mineshaft-100">Identities</p>
|
||||
<DocumentationLinkBadge href="https://infisical.com/docs/documentation/platform/identities/machine-identities" />
|
||||
</div>
|
||||
{isSubOrganization && (
|
||||
<div className="flex items-center">
|
||||
<OrgPermissionCan
|
||||
I={OrgPermissionIdentityActions.Create}
|
||||
a={OrgPermissionSubjects.Identity}
|
||||
>
|
||||
{(isAllowed) => (
|
||||
<Button
|
||||
variant="plain"
|
||||
colorSchema="secondary"
|
||||
leftIcon={<FontAwesomeIcon icon={faLink} />}
|
||||
variant="outline_bg"
|
||||
type="submit"
|
||||
leftIcon={<FontAwesomeIcon icon={faPlus} />}
|
||||
onClick={() => {
|
||||
handlePopUpOpen("linkIdentity");
|
||||
if (!isMoreIdentitiesAllowed && !isEnterprise) {
|
||||
handlePopUpOpen("upgradePlan", {
|
||||
description:
|
||||
"You can add more identities if you upgrade your Infisical Pro plan."
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isSubOrganization) {
|
||||
setWizardStep(IdentityWizardSteps.OrganizationIdentity);
|
||||
}
|
||||
|
||||
handlePopUpOpen("identity");
|
||||
}}
|
||||
isDisabled={!isAllowed}
|
||||
>
|
||||
Link Identity
|
||||
Create Identity
|
||||
</Button>
|
||||
)}
|
||||
</OrgPermissionCan>
|
||||
)}
|
||||
<OrgPermissionCan
|
||||
I={OrgPermissionIdentityActions.Create}
|
||||
a={OrgPermissionSubjects.Identity}
|
||||
>
|
||||
{(isAllowed) => (
|
||||
<Button
|
||||
colorSchema="secondary"
|
||||
type="submit"
|
||||
leftIcon={<FontAwesomeIcon icon={faPlus} />}
|
||||
onClick={() => {
|
||||
if (!isMoreIdentitiesAllowed && !isEnterprise) {
|
||||
handlePopUpOpen("upgradePlan", {
|
||||
text: "You have reached the maximum number of identities allowed on your current plan. Upgrade to Infisical Pro plan to add more identities."
|
||||
});
|
||||
return;
|
||||
}
|
||||
handlePopUpOpen("identity");
|
||||
}}
|
||||
isDisabled={!isAllowed}
|
||||
>
|
||||
Create Identity
|
||||
</Button>
|
||||
)}
|
||||
</OrgPermissionCan>
|
||||
</div>
|
||||
</div>
|
||||
<IdentityTable handlePopUpOpen={handlePopUpOpen} />
|
||||
</div>
|
||||
@@ -173,7 +172,6 @@ export const IdentitySection = withPermission(
|
||||
</div>
|
||||
<IdentityAuthTemplatesTable handlePopUpOpen={handlePopUpOpen} />
|
||||
</div>
|
||||
<IdentityModal popUp={popUp} handlePopUpToggle={handlePopUpToggle} />
|
||||
<IdentityAuthTemplateModal popUp={popUp} handlePopUpToggle={handlePopUpToggle} />
|
||||
<MachineAuthTemplateUsagesModal
|
||||
isOpen={popUp.viewUsages.isOpen}
|
||||
@@ -187,19 +185,99 @@ export const IdentitySection = withPermission(
|
||||
?.name || ""
|
||||
}
|
||||
/>
|
||||
<IdentityTokenAuthTokenModal popUp={popUp} handlePopUpToggle={handlePopUpToggle} />
|
||||
<Modal
|
||||
isOpen={popUp.linkIdentity.isOpen}
|
||||
onOpenChange={(isOpen) => handlePopUpToggle("linkIdentity", isOpen)}
|
||||
isOpen={popUp.identity.isOpen}
|
||||
onOpenChange={(open) => {
|
||||
handlePopUpToggle("identity", open);
|
||||
if (!open) {
|
||||
setWizardStep(IdentityWizardSteps.SelectAction);
|
||||
}
|
||||
}}
|
||||
>
|
||||
<ModalContent
|
||||
title="Assign Existing Identity"
|
||||
subTitle="Assign an existing identity from your root organization to the sub organization. The identity will continue to be managed at its original scope."
|
||||
bodyClassName="overflow-visible"
|
||||
title="Add Identity"
|
||||
subTitle={
|
||||
isSubOrganization ? "Create a new identity or assign an existing identity" : undefined
|
||||
}
|
||||
>
|
||||
<IdentityLinkForm onClose={() => handlePopUpClose("linkIdentity")} />
|
||||
<AnimatePresence mode="wait">
|
||||
{wizardStep === IdentityWizardSteps.SelectAction && (
|
||||
<motion.div
|
||||
key="select-type-step"
|
||||
transition={{ duration: 0.1 }}
|
||||
initial={{ opacity: 0, translateX: 30 }}
|
||||
animate={{ opacity: 1, translateX: 0 }}
|
||||
exit={{ opacity: 0, translateX: -30 }}
|
||||
>
|
||||
<div
|
||||
className="cursor-pointer rounded-md border border-mineshaft-600 p-4 transition-all hover:bg-mineshaft-700"
|
||||
role="button"
|
||||
tabIndex={0}
|
||||
onClick={() => setWizardStep(IdentityWizardSteps.OrganizationIdentity)}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === "Enter") {
|
||||
setWizardStep(IdentityWizardSteps.OrganizationIdentity);
|
||||
}
|
||||
}}
|
||||
>
|
||||
<div className="flex items-center gap-2">
|
||||
<PlusIcon size="1rem" />
|
||||
<div>Create New Identity</div>
|
||||
</div>
|
||||
<div className="mt-2 text-xs text-mineshaft-300">
|
||||
Create a new machine identity specifically for this sub-organization. This
|
||||
identity will be managed at the sub-organization level.
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
className="mt-4 cursor-pointer rounded-md border border-mineshaft-600 p-4 transition-all hover:bg-mineshaft-700"
|
||||
role="button"
|
||||
tabIndex={0}
|
||||
onClick={() => setWizardStep(IdentityWizardSteps.LinkIdentity)}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === "Enter") {
|
||||
setWizardStep(IdentityWizardSteps.LinkIdentity);
|
||||
}
|
||||
}}
|
||||
>
|
||||
<div className="flex items-center gap-2">
|
||||
<LinkIcon size="1rem" />
|
||||
<div>Assign Existing Identity</div>
|
||||
</div>
|
||||
<div className="mt-2 text-xs text-mineshaft-300">
|
||||
Assign an existing identity from your parent organization. The identity will
|
||||
continue to be managed at its original scope.
|
||||
</div>
|
||||
</div>
|
||||
</motion.div>
|
||||
)}
|
||||
{wizardStep === IdentityWizardSteps.OrganizationIdentity && (
|
||||
<motion.div
|
||||
key="identity-step"
|
||||
transition={{ duration: 0.1 }}
|
||||
initial={{ opacity: 0, translateX: 30 }}
|
||||
animate={{ opacity: 1, translateX: 0 }}
|
||||
exit={{ opacity: 0, translateX: -30 }}
|
||||
>
|
||||
<OrgIdentityModal popUp={popUp} handlePopUpToggle={handlePopUpToggle} />
|
||||
</motion.div>
|
||||
)}
|
||||
{wizardStep === IdentityWizardSteps.LinkIdentity && (
|
||||
<motion.div
|
||||
key="link-step"
|
||||
transition={{ duration: 0.1 }}
|
||||
initial={{ opacity: 0, translateX: 30 }}
|
||||
animate={{ opacity: 1, translateX: 0 }}
|
||||
exit={{ opacity: 0, translateX: -30 }}
|
||||
>
|
||||
<OrgIdentityLinkForm onClose={() => handlePopUpClose("identity")} />
|
||||
</motion.div>
|
||||
)}
|
||||
</AnimatePresence>
|
||||
</ModalContent>
|
||||
</Modal>
|
||||
<IdentityTokenAuthTokenModal popUp={popUp} handlePopUpToggle={handlePopUpToggle} />
|
||||
<DeleteActionModal
|
||||
isOpen={popUp.deleteIdentity.isOpen}
|
||||
title={`Are you sure you want to delete ${
|
||||
|
||||
+24
-11
@@ -2,7 +2,6 @@ import { useCallback, useState } from "react";
|
||||
import {
|
||||
faArrowDown,
|
||||
faArrowUp,
|
||||
faBuilding,
|
||||
faCheckCircle,
|
||||
faChevronRight,
|
||||
faEdit,
|
||||
@@ -46,6 +45,7 @@ import {
|
||||
Tooltip,
|
||||
Tr
|
||||
} from "@app/components/v2";
|
||||
import { Badge, OrgIcon, SubOrgIcon } from "@app/components/v3";
|
||||
import { OrgPermissionIdentityActions, OrgPermissionSubjects, useOrganization } from "@app/context";
|
||||
import {
|
||||
getUserTablePreference,
|
||||
@@ -56,8 +56,8 @@ import { usePagination, useResetPageHelper } from "@app/hooks";
|
||||
import {
|
||||
identityAuthToNameMap,
|
||||
useGetOrgRoles,
|
||||
useSearchIdentities,
|
||||
useUpdateIdentity
|
||||
useSearchOrgIdentityMemberships,
|
||||
useUpdateOrgIdentity
|
||||
} from "@app/hooks/api";
|
||||
import { OrderByDirection } from "@app/hooks/api/generic/types";
|
||||
import { OrgIdentityOrderBy } from "@app/hooks/api/organization/types";
|
||||
@@ -110,9 +110,9 @@ export const IdentityTable = ({ handlePopUpOpen }: Props) => {
|
||||
|
||||
const organizationId = currentOrg?.id || "";
|
||||
|
||||
const { mutateAsync: updateMutateAsync } = useUpdateIdentity();
|
||||
const { mutateAsync: updateMutateAsync } = useUpdateOrgIdentity();
|
||||
|
||||
const { data, isPending, isFetching } = useSearchIdentities({
|
||||
const { data, isPending, isFetching } = useSearchOrgIdentityMemberships({
|
||||
offset,
|
||||
limit,
|
||||
orderDirection,
|
||||
@@ -293,6 +293,8 @@ export const IdentityTable = ({ handlePopUpOpen }: Props) => {
|
||||
lastLoginAuthMethod,
|
||||
lastLoginTime
|
||||
}) => {
|
||||
const isSubOrgIdentity = currentOrg.id === orgId;
|
||||
|
||||
return (
|
||||
<Tr
|
||||
className="h-10 cursor-pointer transition-colors duration-100 hover:bg-mineshaft-700"
|
||||
@@ -357,10 +359,19 @@ export const IdentityTable = ({ handlePopUpOpen }: Props) => {
|
||||
</Td>
|
||||
{isSubOrganization && (
|
||||
<Td>
|
||||
<p className="truncate">
|
||||
<FontAwesomeIcon size="sm" className="mr-1.5" icon={faBuilding} />
|
||||
{currentOrg.id === orgId ? "Sub Organization" : "Root Organization"}
|
||||
</p>
|
||||
<Badge variant={isSubOrgIdentity ? "sub-org" : "org"}>
|
||||
{isSubOrgIdentity ? (
|
||||
<>
|
||||
<SubOrgIcon />
|
||||
Sub-Organization
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<OrgIcon />
|
||||
Root Organization
|
||||
</>
|
||||
)}
|
||||
</Badge>
|
||||
</Td>
|
||||
)}
|
||||
<Td>
|
||||
@@ -394,7 +405,7 @@ export const IdentityTable = ({ handlePopUpOpen }: Props) => {
|
||||
}}
|
||||
isDisabled={!isAllowed}
|
||||
>
|
||||
Edit Identity
|
||||
Edit Identity {isSubOrgIdentity ? "" : "Membership"}
|
||||
</DropdownMenuItem>
|
||||
)}
|
||||
</OrgPermissionCan>
|
||||
@@ -414,7 +425,9 @@ export const IdentityTable = ({ handlePopUpOpen }: Props) => {
|
||||
isDisabled={!isAllowed}
|
||||
icon={<FontAwesomeIcon icon={faTrash} />}
|
||||
>
|
||||
Delete Identity
|
||||
{isSubOrgIdentity
|
||||
? "Delete Identity"
|
||||
: "Remove From Sub-Organization"}
|
||||
</DropdownMenuItem>
|
||||
)}
|
||||
</OrgPermissionCan>
|
||||
|
||||
+6
-4
@@ -3,6 +3,7 @@ import { Controller, useFieldArray, useForm } from "react-hook-form";
|
||||
import { faPlus, faXmark } from "@fortawesome/free-solid-svg-icons";
|
||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||
import { zodResolver } from "@hookform/resolvers/zod";
|
||||
import { useParams } from "@tanstack/react-router";
|
||||
import { z } from "zod";
|
||||
|
||||
import { createNotification } from "@app/components/notifications";
|
||||
@@ -71,7 +72,9 @@ export const IdentityTlsCertAuthForm = ({
|
||||
const { currentOrg } = useOrganization();
|
||||
const orgId = currentOrg?.id || "";
|
||||
const { subscription } = useSubscription();
|
||||
|
||||
const { projectId } = useParams({
|
||||
strict: false
|
||||
});
|
||||
const { mutateAsync: addMutateAsync } = useAddIdentityTlsCertAuth();
|
||||
const { mutateAsync: updateMutateAsync } = useUpdateIdentityTlsCertAuth();
|
||||
const [tabValue, setTabValue] = useState<IdentityFormTab>(IdentityFormTab.Configuration);
|
||||
@@ -141,7 +144,7 @@ export const IdentityTlsCertAuthForm = ({
|
||||
|
||||
if (data) {
|
||||
await updateMutateAsync({
|
||||
organizationId: orgId,
|
||||
...(projectId ? { projectId } : { organizationId: orgId }),
|
||||
caCertificate,
|
||||
allowedCommonNames: allowedCommonNames || null,
|
||||
identityId,
|
||||
@@ -152,7 +155,7 @@ export const IdentityTlsCertAuthForm = ({
|
||||
});
|
||||
} else {
|
||||
await addMutateAsync({
|
||||
organizationId: orgId,
|
||||
...(projectId ? { projectId } : { organizationId: orgId }),
|
||||
identityId,
|
||||
caCertificate,
|
||||
allowedCommonNames: allowedCommonNames || undefined,
|
||||
@@ -169,7 +172,6 @@ export const IdentityTlsCertAuthForm = ({
|
||||
text: `Successfully ${isUpdate ? "updated" : "configured"} auth method`,
|
||||
type: "success"
|
||||
});
|
||||
|
||||
reset();
|
||||
};
|
||||
|
||||
|
||||
+6
-3
@@ -3,6 +3,7 @@ import { Controller, useFieldArray, useForm } from "react-hook-form";
|
||||
import { faPlus, faXmark } from "@fortawesome/free-solid-svg-icons";
|
||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||
import { zodResolver } from "@hookform/resolvers/zod";
|
||||
import { useParams } from "@tanstack/react-router";
|
||||
import { z } from "zod";
|
||||
|
||||
import { createNotification } from "@app/components/notifications";
|
||||
@@ -70,7 +71,9 @@ export const IdentityTokenAuthForm = ({
|
||||
const { currentOrg } = useOrganization();
|
||||
const orgId = currentOrg?.id || "";
|
||||
const { subscription } = useSubscription();
|
||||
|
||||
const { projectId } = useParams({
|
||||
strict: false
|
||||
});
|
||||
const { mutateAsync: addMutateAsync } = useAddIdentityTokenAuth();
|
||||
const { mutateAsync: updateMutateAsync } = useUpdateIdentityTokenAuth();
|
||||
const [tabValue, setTabValue] = useState<IdentityFormTab>(IdentityFormTab.Configuration);
|
||||
@@ -134,7 +137,7 @@ export const IdentityTokenAuthForm = ({
|
||||
|
||||
if (data) {
|
||||
await updateMutateAsync({
|
||||
organizationId: orgId,
|
||||
...(projectId ? { projectId } : { organizationId: orgId }),
|
||||
identityId,
|
||||
accessTokenTTL: Number(accessTokenTTL),
|
||||
accessTokenMaxTTL: Number(accessTokenMaxTTL),
|
||||
@@ -143,7 +146,7 @@ export const IdentityTokenAuthForm = ({
|
||||
});
|
||||
} else {
|
||||
await addMutateAsync({
|
||||
organizationId: orgId,
|
||||
...(projectId ? { projectId } : { organizationId: orgId }),
|
||||
identityId,
|
||||
accessTokenTTL: Number(accessTokenTTL),
|
||||
accessTokenMaxTTL: Number(accessTokenMaxTTL),
|
||||
|
||||
+6
-3
@@ -3,6 +3,7 @@ import { Controller, useFieldArray, useForm } from "react-hook-form";
|
||||
import { faPlus, faXmark } from "@fortawesome/free-solid-svg-icons";
|
||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||
import { zodResolver } from "@hookform/resolvers/zod";
|
||||
import { useParams } from "@tanstack/react-router";
|
||||
import ms from "ms";
|
||||
import { z } from "zod";
|
||||
|
||||
@@ -105,6 +106,9 @@ export const IdentityUniversalAuthForm = ({
|
||||
identityId,
|
||||
isUpdate
|
||||
}: Props) => {
|
||||
const { projectId } = useParams({
|
||||
strict: false
|
||||
});
|
||||
const { currentOrg } = useOrganization();
|
||||
const orgId = currentOrg?.id || "";
|
||||
const { subscription } = useSubscription();
|
||||
@@ -232,7 +236,7 @@ export const IdentityUniversalAuthForm = ({
|
||||
if (data) {
|
||||
// update universal auth configuration
|
||||
await updateMutateAsync({
|
||||
organizationId: orgId,
|
||||
...(projectId ? { projectId } : { organizationId: orgId }),
|
||||
identityId,
|
||||
clientSecretTrustedIps,
|
||||
accessTokenTTL: Number(accessTokenTTL),
|
||||
@@ -249,7 +253,7 @@ export const IdentityUniversalAuthForm = ({
|
||||
// create new universal auth configuration
|
||||
|
||||
await addMutateAsync({
|
||||
organizationId: orgId,
|
||||
...(projectId ? { projectId } : { organizationId: orgId }),
|
||||
identityId,
|
||||
clientSecretTrustedIps,
|
||||
accessTokenTTL: Number(accessTokenTTL),
|
||||
@@ -270,7 +274,6 @@ export const IdentityUniversalAuthForm = ({
|
||||
text: `Successfully ${isUpdate ? "updated" : "created"} auth method`,
|
||||
type: "success"
|
||||
});
|
||||
|
||||
reset();
|
||||
};
|
||||
|
||||
|
||||
+17
-4
@@ -1,13 +1,15 @@
|
||||
import { Controller, useForm } from "react-hook-form";
|
||||
import { zodResolver } from "@hookform/resolvers/zod";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { useNavigate } from "@tanstack/react-router";
|
||||
import { z } from "zod";
|
||||
|
||||
import { createNotification } from "@app/components/notifications";
|
||||
import { Button, FilterableSelect, FormControl } from "@app/components/v2";
|
||||
import { useOrganization } from "@app/context";
|
||||
import { useGetAvailableOrgIdentities, useGetOrgRoles } from "@app/hooks/api";
|
||||
import { useGetOrgRoles } from "@app/hooks/api";
|
||||
import { useCreateOrgIdentityMembership } from "@app/hooks/api/orgIdentityMembership";
|
||||
import { orgIdentityMembershipQuery } from "@app/hooks/api/orgIdentityMembership/queries";
|
||||
|
||||
const schema = z
|
||||
.object({
|
||||
@@ -22,15 +24,26 @@ type Props = {
|
||||
onClose: () => void;
|
||||
};
|
||||
|
||||
export const IdentityLinkForm = ({ onClose }: Props) => {
|
||||
export const OrgIdentityLinkForm = ({ onClose }: Props) => {
|
||||
const navigate = useNavigate();
|
||||
const { currentOrg } = useOrganization();
|
||||
const orgId = currentOrg?.id || "";
|
||||
|
||||
const { data: roles } = useGetOrgRoles(orgId);
|
||||
|
||||
// const [searchValue, setSearchValue] = useState("");
|
||||
//
|
||||
// const [debouncedSearchValue] = useDebounce(searchValue);
|
||||
|
||||
const { mutateAsync: createMutateAsync } = useCreateOrgIdentityMembership();
|
||||
const { data: rootOrgIdentities, isPending: isRootOrgLoading } = useGetAvailableOrgIdentities();
|
||||
|
||||
// TODO: name filter needs to be implemented on backend
|
||||
const { data: rootOrgIdentities, isPending: isRootOrgLoading } = useQuery({
|
||||
...orgIdentityMembershipQuery.listAvailable({
|
||||
// identityName: debouncedSearchValue
|
||||
}),
|
||||
placeholderData: (prev) => prev
|
||||
});
|
||||
|
||||
const {
|
||||
control,
|
||||
@@ -69,6 +82,7 @@ export const IdentityLinkForm = ({ onClose }: Props) => {
|
||||
value={value}
|
||||
onChange={onChange}
|
||||
placeholder="Select identity..."
|
||||
// onInputChange={setSearchValue}
|
||||
options={rootOrgIdentities}
|
||||
getOptionValue={(option) => option.id}
|
||||
getOptionLabel={(option) => option.name}
|
||||
@@ -94,7 +108,6 @@ export const IdentityLinkForm = ({ onClose }: Props) => {
|
||||
placeholder="Select role..."
|
||||
getOptionValue={(option) => option.slug}
|
||||
getOptionLabel={(option) => option.name}
|
||||
// menuPortalTarget={document.body}
|
||||
/>
|
||||
</FormControl>
|
||||
)}
|
||||
+82
-93
@@ -14,13 +14,11 @@ import {
|
||||
FormLabel,
|
||||
IconButton,
|
||||
Input,
|
||||
Modal,
|
||||
ModalContent,
|
||||
Switch
|
||||
} from "@app/components/v2";
|
||||
import { useOrganization } from "@app/context";
|
||||
import { findOrgMembershipRole } from "@app/helpers/roles";
|
||||
import { useCreateIdentity, useGetOrgRoles, useUpdateIdentity } from "@app/hooks/api";
|
||||
import { useCreateOrgIdentity, useGetOrgRoles, useUpdateOrgIdentity } from "@app/hooks/api";
|
||||
import { useAddIdentityUniversalAuth } from "@app/hooks/api/identities";
|
||||
import { UsePopUpState } from "@app/hooks/usePopUp";
|
||||
|
||||
@@ -47,7 +45,7 @@ type Props = {
|
||||
handlePopUpToggle: (popUpName: keyof UsePopUpState<["identity"]>, state?: boolean) => void;
|
||||
};
|
||||
|
||||
export const IdentityModal = ({ popUp, handlePopUpToggle }: Props) => {
|
||||
export const OrgIdentityModal = ({ popUp, handlePopUpToggle }: Props) => {
|
||||
const navigate = useNavigate();
|
||||
const { currentOrg } = useOrganization();
|
||||
const orgId = currentOrg?.id || "";
|
||||
@@ -55,8 +53,8 @@ export const IdentityModal = ({ popUp, handlePopUpToggle }: Props) => {
|
||||
const { data: roles } = useGetOrgRoles(orgId);
|
||||
const isOrgIdentity = popUp?.identity?.data ? orgId === popUp?.identity?.data?.orgId : true;
|
||||
|
||||
const { mutateAsync: createMutateAsync } = useCreateIdentity();
|
||||
const { mutateAsync: updateMutateAsync } = useUpdateIdentity();
|
||||
const { mutateAsync: createMutateAsync } = useCreateOrgIdentity();
|
||||
const { mutateAsync: updateMutateAsync } = useUpdateOrgIdentity();
|
||||
const { mutateAsync: addMutateAsync } = useAddIdentityUniversalAuth();
|
||||
|
||||
const {
|
||||
@@ -173,75 +171,66 @@ export const IdentityModal = ({ popUp, handlePopUpToggle }: Props) => {
|
||||
};
|
||||
|
||||
return (
|
||||
<Modal
|
||||
isOpen={popUp?.identity?.isOpen}
|
||||
onOpenChange={(isOpen) => {
|
||||
handlePopUpToggle("identity", isOpen);
|
||||
reset();
|
||||
}}
|
||||
>
|
||||
<ModalContent
|
||||
bodyClassName="overflow-visible"
|
||||
title={`${popUp?.identity?.data ? "Update" : "Create"} Identity`}
|
||||
>
|
||||
<form onSubmit={handleSubmit(onFormSubmit)}>
|
||||
{isOrgIdentity && (
|
||||
<Controller
|
||||
control={control}
|
||||
defaultValue=""
|
||||
name="name"
|
||||
render={({ field, fieldState: { error } }) => (
|
||||
<FormControl
|
||||
className="mb-4"
|
||||
label="Name"
|
||||
isError={Boolean(error)}
|
||||
errorText={error?.message}
|
||||
>
|
||||
<Input {...field} placeholder="Machine 1" />
|
||||
</FormControl>
|
||||
)}
|
||||
/>
|
||||
<form onSubmit={handleSubmit(onFormSubmit)}>
|
||||
{isOrgIdentity && (
|
||||
<Controller
|
||||
control={control}
|
||||
defaultValue=""
|
||||
name="name"
|
||||
render={({ field, fieldState: { error } }) => (
|
||||
<FormControl
|
||||
className="mb-4"
|
||||
label="Name"
|
||||
isError={Boolean(error)}
|
||||
errorText={error?.message}
|
||||
>
|
||||
<Input {...field} placeholder="Machine 1" />
|
||||
</FormControl>
|
||||
)}
|
||||
<Controller
|
||||
control={control}
|
||||
name="role"
|
||||
render={({ field: { onChange, value }, fieldState: { error } }) => (
|
||||
<FormControl
|
||||
label={`${popUp?.identity?.data ? "Update" : ""} Role`}
|
||||
errorText={error?.message}
|
||||
isError={Boolean(error)}
|
||||
/>
|
||||
)}
|
||||
<Controller
|
||||
control={control}
|
||||
name="role"
|
||||
render={({ field: { onChange, value }, fieldState: { error } }) => (
|
||||
<FormControl
|
||||
label={`${popUp?.identity?.data ? "Update" : ""} Role`}
|
||||
errorText={error?.message}
|
||||
isError={Boolean(error)}
|
||||
>
|
||||
<FilterableSelect
|
||||
placeholder="Select role..."
|
||||
options={roles}
|
||||
onChange={onChange}
|
||||
value={value}
|
||||
getOptionValue={(option) => option.slug}
|
||||
getOptionLabel={(option) => option.name}
|
||||
/>
|
||||
</FormControl>
|
||||
)}
|
||||
/>
|
||||
{isOrgIdentity && (
|
||||
<Controller
|
||||
control={control}
|
||||
name="hasDeleteProtection"
|
||||
render={({ field: { onChange, value }, fieldState: { error } }) => (
|
||||
<FormControl errorText={error?.message} isError={Boolean(error)}>
|
||||
<Switch
|
||||
className="mr-2 ml-0 bg-mineshaft-400/80 shadow-inner data-[state=checked]:bg-green/80"
|
||||
containerClassName="flex-row-reverse w-fit"
|
||||
id="delete-protection-enabled"
|
||||
thumbClassName="bg-mineshaft-800"
|
||||
onCheckedChange={onChange}
|
||||
isChecked={value}
|
||||
>
|
||||
<FilterableSelect
|
||||
placeholder="Select role..."
|
||||
options={roles}
|
||||
onChange={onChange}
|
||||
value={value}
|
||||
getOptionValue={(option) => option.slug}
|
||||
getOptionLabel={(option) => option.name}
|
||||
/>
|
||||
</FormControl>
|
||||
)}
|
||||
/>
|
||||
{isOrgIdentity && (
|
||||
<Controller
|
||||
control={control}
|
||||
name="hasDeleteProtection"
|
||||
render={({ field: { onChange, value }, fieldState: { error } }) => (
|
||||
<FormControl errorText={error?.message} isError={Boolean(error)}>
|
||||
<Switch
|
||||
className="mr-2 ml-0 bg-mineshaft-400/80 shadow-inner data-[state=checked]:bg-green/80"
|
||||
containerClassName="flex-row-reverse w-fit"
|
||||
id="delete-protection-enabled"
|
||||
thumbClassName="bg-mineshaft-800"
|
||||
onCheckedChange={onChange}
|
||||
isChecked={value}
|
||||
>
|
||||
<p>Delete Protection {value ? "Enabled" : "Disabled"}</p>
|
||||
</Switch>
|
||||
</FormControl>
|
||||
)}
|
||||
/>
|
||||
<p>Delete Protection {value ? "Enabled" : "Disabled"}</p>
|
||||
</Switch>
|
||||
</FormControl>
|
||||
)}
|
||||
/>
|
||||
)}
|
||||
{isOrgIdentity && (
|
||||
<>
|
||||
<div>
|
||||
<FormLabel label="Metadata" />
|
||||
</div>
|
||||
@@ -303,26 +292,26 @@ export const IdentityModal = ({ popUp, handlePopUpToggle }: Props) => {
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex items-center">
|
||||
<Button
|
||||
className="mr-4"
|
||||
size="sm"
|
||||
type="submit"
|
||||
isLoading={isSubmitting}
|
||||
isDisabled={isSubmitting}
|
||||
>
|
||||
{popUp?.identity?.data ? "Update" : "Create"}
|
||||
</Button>
|
||||
<Button
|
||||
colorSchema="secondary"
|
||||
variant="plain"
|
||||
onClick={() => handlePopUpToggle("identity", false)}
|
||||
>
|
||||
Cancel
|
||||
</Button>
|
||||
</div>
|
||||
</form>
|
||||
</ModalContent>
|
||||
</Modal>
|
||||
</>
|
||||
)}
|
||||
<div className="flex items-center">
|
||||
<Button
|
||||
className="mr-4"
|
||||
size="sm"
|
||||
type="submit"
|
||||
isLoading={isSubmitting}
|
||||
isDisabled={isSubmitting}
|
||||
>
|
||||
{popUp?.identity?.data ? "Update" : "Create"}
|
||||
</Button>
|
||||
<Button
|
||||
colorSchema="secondary"
|
||||
variant="plain"
|
||||
onClick={() => handlePopUpToggle("identity", false)}
|
||||
>
|
||||
Cancel
|
||||
</Button>
|
||||
</div>
|
||||
</form>
|
||||
);
|
||||
};
|
||||
+53
-9
@@ -7,16 +7,21 @@ import { Link, useNavigate, useParams } from "@tanstack/react-router";
|
||||
import { UpgradePlanModal } from "@app/components/license/UpgradePlanModal";
|
||||
import { createNotification } from "@app/components/notifications";
|
||||
import { OrgPermissionCan } from "@app/components/permissions";
|
||||
import { DeleteActionModal, PageHeader } from "@app/components/v2";
|
||||
import { Button, DeleteActionModal, Modal, ModalContent, PageHeader } from "@app/components/v2";
|
||||
import { ROUTE_PATHS } from "@app/const/routes";
|
||||
import { OrgPermissionIdentityActions, OrgPermissionSubjects, useOrganization } from "@app/context";
|
||||
import { useDeleteIdentity, useGetIdentityById } from "@app/hooks/api";
|
||||
import {
|
||||
OrgPermissionActions,
|
||||
OrgPermissionIdentityActions,
|
||||
OrgPermissionSubjects,
|
||||
useOrganization
|
||||
} from "@app/context";
|
||||
import { useDeleteOrgIdentity, useGetOrgIdentityMembershipById } from "@app/hooks/api";
|
||||
import { usePopUp } from "@app/hooks/usePopUp";
|
||||
import { ViewIdentityAuthModal } from "@app/pages/organization/IdentityDetailsByIDPage/components/ViewIdentityAuthModal/ViewIdentityAuthModal";
|
||||
import { OrgAccessControlTabSections } from "@app/types/org";
|
||||
|
||||
import { IdentityAuthMethodModal } from "../AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/IdentityAuthMethodModal";
|
||||
import { IdentityModal } from "../AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/IdentityModal";
|
||||
import { OrgIdentityModal } from "../AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/OrgIdentityModal";
|
||||
import {
|
||||
IdentityAuthenticationSection,
|
||||
IdentityDetailsSection,
|
||||
@@ -31,8 +36,8 @@ const Page = () => {
|
||||
const identityId = params.identityId as string;
|
||||
const { currentOrg, isSubOrganization } = useOrganization();
|
||||
const orgId = currentOrg?.id || "";
|
||||
const { data } = useGetIdentityById(identityId);
|
||||
const { mutateAsync: deleteIdentity } = useDeleteIdentity();
|
||||
const { data } = useGetOrgIdentityMembershipById(identityId);
|
||||
const { mutateAsync: deleteIdentity, isPending: isDeletingIdentity } = useDeleteOrgIdentity();
|
||||
const isAuthHidden = orgId !== data?.identity?.orgId;
|
||||
|
||||
const { popUp, handlePopUpOpen, handlePopUpClose, handlePopUpToggle } = usePopUp([
|
||||
@@ -46,7 +51,7 @@ const Page = () => {
|
||||
const onDeleteIdentitySubmit = async (id: string) => {
|
||||
await deleteIdentity({
|
||||
identityId: id,
|
||||
organizationId: orgId
|
||||
orgId
|
||||
});
|
||||
|
||||
createNotification({
|
||||
@@ -81,7 +86,36 @@ const Page = () => {
|
||||
scope={isSubOrganization ? "namespace" : "org"}
|
||||
description={`${isSubOrganization ? "Sub-" : ""}Organization Identity`}
|
||||
title={data.identity.name}
|
||||
/>
|
||||
>
|
||||
<div className="flex items-center gap-2">
|
||||
{isSubOrganization && data.identity.orgId !== currentOrg.id && (
|
||||
<OrgPermissionCan
|
||||
I={OrgPermissionActions.Delete}
|
||||
a={OrgPermissionSubjects.Identity}
|
||||
renderTooltip
|
||||
allowedLabel="Remove from sub-organization"
|
||||
>
|
||||
{(isAllowed) => (
|
||||
<Button
|
||||
colorSchema="danger"
|
||||
variant="outline_bg"
|
||||
size="xs"
|
||||
isDisabled={!isAllowed}
|
||||
isLoading={isDeletingIdentity}
|
||||
onClick={() =>
|
||||
handlePopUpOpen("deleteIdentity", {
|
||||
identityId: data.identity.id,
|
||||
name: data.identity.name
|
||||
})
|
||||
}
|
||||
>
|
||||
Unlink Identity
|
||||
</Button>
|
||||
)}
|
||||
</OrgPermissionCan>
|
||||
)}
|
||||
</div>
|
||||
</PageHeader>
|
||||
<div className="flex">
|
||||
<div className="mr-4 w-96">
|
||||
<IdentityDetailsSection
|
||||
@@ -100,7 +134,17 @@ const Page = () => {
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
<IdentityModal popUp={popUp} handlePopUpToggle={handlePopUpToggle} />
|
||||
<Modal
|
||||
isOpen={popUp?.identity?.isOpen}
|
||||
onOpenChange={(isOpen) => handlePopUpToggle("identity", isOpen)}
|
||||
>
|
||||
<ModalContent
|
||||
bodyClassName="overflow-visible"
|
||||
title={`${popUp?.identity?.data ? "Update" : "Create"} Identity`}
|
||||
>
|
||||
<OrgIdentityModal popUp={popUp} handlePopUpToggle={handlePopUpToggle} />
|
||||
</ModalContent>
|
||||
</Modal>
|
||||
<IdentityAuthMethodModal
|
||||
popUp={popUp}
|
||||
handlePopUpOpen={handlePopUpOpen}
|
||||
|
||||
+6
-2
@@ -4,7 +4,11 @@ import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||
import { OrgPermissionCan } from "@app/components/permissions";
|
||||
import { Button, Tooltip } from "@app/components/v2";
|
||||
import { OrgPermissionIdentityActions, OrgPermissionSubjects } from "@app/context";
|
||||
import { IdentityAuthMethod, identityAuthToNameMap, useGetIdentityById } from "@app/hooks/api";
|
||||
import {
|
||||
IdentityAuthMethod,
|
||||
identityAuthToNameMap,
|
||||
useGetOrgIdentityMembershipById
|
||||
} from "@app/hooks/api";
|
||||
import { UsePopUpState } from "@app/hooks/usePopUp";
|
||||
|
||||
type Props = {
|
||||
@@ -16,7 +20,7 @@ type Props = {
|
||||
};
|
||||
|
||||
export const IdentityAuthenticationSection = ({ identityId, handlePopUpOpen }: Props) => {
|
||||
const { data, refetch } = useGetIdentityById(identityId);
|
||||
const { data, refetch } = useGetOrgIdentityMembershipById(identityId);
|
||||
|
||||
return data ? (
|
||||
<div className="mt-4 rounded-lg border border-mineshaft-600 bg-mineshaft-900 p-4">
|
||||
|
||||
+3
-3
@@ -7,9 +7,9 @@ import { Button, IconButton, Tooltip } from "@app/components/v2";
|
||||
import { OrgPermissionIdentityActions, OrgPermissionSubjects } from "@app/context";
|
||||
import { useTimedReset } from "@app/hooks";
|
||||
import {
|
||||
useGetIdentityById,
|
||||
useGetIdentityUniversalAuth,
|
||||
useGetIdentityUniversalAuthClientSecrets
|
||||
useGetIdentityUniversalAuthClientSecrets,
|
||||
useGetOrgIdentityMembershipById
|
||||
} from "@app/hooks/api";
|
||||
import { UsePopUpState } from "@app/hooks/usePopUp";
|
||||
|
||||
@@ -30,7 +30,7 @@ export const IdentityClientSecrets = ({ identityId, handlePopUpOpen }: Props) =>
|
||||
initialState: "Copy Client ID to clipboard"
|
||||
});
|
||||
|
||||
const { data } = useGetIdentityById(identityId);
|
||||
const { data } = useGetOrgIdentityMembershipById(identityId);
|
||||
const { data: identityUniversalAuth } = useGetIdentityUniversalAuth(identityId);
|
||||
const { data: clientSecrets } = useGetIdentityUniversalAuthClientSecrets(identityId);
|
||||
return (
|
||||
|
||||
+2
-2
@@ -11,7 +11,7 @@ import {
|
||||
IconButton,
|
||||
Tooltip
|
||||
} from "@app/components/v2";
|
||||
import { useGetIdentityById, useGetIdentityTokensTokenAuth } from "@app/hooks/api";
|
||||
import { useGetIdentityTokensTokenAuth, useGetOrgIdentityMembershipById } from "@app/hooks/api";
|
||||
import { UsePopUpState } from "@app/hooks/usePopUp";
|
||||
|
||||
type Props = {
|
||||
@@ -23,7 +23,7 @@ type Props = {
|
||||
};
|
||||
|
||||
export const IdentityTokens = ({ identityId, handlePopUpOpen }: Props) => {
|
||||
const { data } = useGetIdentityById(identityId);
|
||||
const { data } = useGetOrgIdentityMembershipById(identityId);
|
||||
const { data: tokens } = useGetIdentityTokensTokenAuth(identityId);
|
||||
return (
|
||||
<div>
|
||||
|
||||
+4
-4
@@ -23,7 +23,7 @@ import {
|
||||
} from "@app/components/v2";
|
||||
import { OrgPermissionIdentityActions, OrgPermissionSubjects, useOrganization } from "@app/context";
|
||||
import { useTimedReset } from "@app/hooks";
|
||||
import { identityAuthToNameMap, useGetIdentityById } from "@app/hooks/api";
|
||||
import { identityAuthToNameMap, useGetOrgIdentityMembershipById } from "@app/hooks/api";
|
||||
import { UsePopUpState } from "@app/hooks/usePopUp";
|
||||
|
||||
type Props = {
|
||||
@@ -41,7 +41,7 @@ export const IdentityDetailsSection = ({ identityId, handlePopUpOpen, isOrgIdent
|
||||
});
|
||||
const { isSubOrganization } = useOrganization();
|
||||
|
||||
const { data } = useGetIdentityById(identityId);
|
||||
const { data } = useGetOrgIdentityMembershipById(identityId);
|
||||
return data ? (
|
||||
<div className="rounded-lg border border-mineshaft-600 bg-mineshaft-900 p-4">
|
||||
<div className="flex items-center justify-between border-b border-mineshaft-400 pb-4">
|
||||
@@ -86,7 +86,7 @@ export const IdentityDetailsSection = ({ identityId, handlePopUpOpen, isOrgIdent
|
||||
}}
|
||||
disabled={!isAllowed}
|
||||
>
|
||||
Edit Identity
|
||||
{isOrgIdentity ? "Edit Identity" : "Edit Identity Role"}
|
||||
</DropdownMenuItem>
|
||||
)}
|
||||
</OrgPermissionCan>
|
||||
@@ -110,7 +110,7 @@ export const IdentityDetailsSection = ({ identityId, handlePopUpOpen, isOrgIdent
|
||||
icon={<FontAwesomeIcon icon={faTrash} />}
|
||||
disabled={!isAllowed}
|
||||
>
|
||||
Delete Identity
|
||||
{!isOrgIdentity ? "Remove From Sub-Organization" : "Delete Identity"}
|
||||
</DropdownMenuItem>
|
||||
)}
|
||||
</OrgPermissionCan>
|
||||
|
||||
+2
-2
@@ -14,7 +14,7 @@ import {
|
||||
} from "@app/components/v2";
|
||||
import { useOrganization } from "@app/context";
|
||||
import {
|
||||
useAddIdentityToWorkspace,
|
||||
useCreateProjectIdentityMembership,
|
||||
useGetIdentityProjectMemberships,
|
||||
useGetProjectRoles,
|
||||
useGetUserProjects,
|
||||
@@ -45,7 +45,7 @@ type Props = {
|
||||
const Content = ({ identityId, handlePopUpToggle }: Omit<Props, "popUp">) => {
|
||||
const { currentOrg } = useOrganization();
|
||||
const { data: workspaces = [] } = useGetUserProjects();
|
||||
const { mutateAsync: addIdentityToWorkspace } = useAddIdentityToWorkspace();
|
||||
const { mutateAsync: addIdentityToWorkspace } = useCreateProjectIdentityMembership();
|
||||
|
||||
const {
|
||||
control,
|
||||
|
||||
+2
-2
@@ -9,7 +9,7 @@ import { IconButton, Td, Tooltip, Tr } from "@app/components/v2";
|
||||
import { getProjectBaseURL } from "@app/helpers/project";
|
||||
import { formatProjectRoleName } from "@app/helpers/roles";
|
||||
import { useGetUserProjects } from "@app/hooks/api";
|
||||
import { IdentityMembership } from "@app/hooks/api/identities/types";
|
||||
import { IdentityProjectMembershipV1 } from "@app/hooks/api/identities/types";
|
||||
import { UsePopUpState } from "@app/hooks/usePopUp";
|
||||
|
||||
export enum TabSections {
|
||||
@@ -20,7 +20,7 @@ export enum TabSections {
|
||||
}
|
||||
|
||||
type Props = {
|
||||
membership: IdentityMembership;
|
||||
membership: IdentityProjectMembershipV1;
|
||||
handlePopUpOpen: (
|
||||
popUpName: keyof UsePopUpState<["removeIdentityFromProject"]>,
|
||||
data?: object
|
||||
|
||||
+2
-2
@@ -3,7 +3,7 @@ import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||
|
||||
import { createNotification } from "@app/components/notifications";
|
||||
import { DeleteActionModal, IconButton } from "@app/components/v2";
|
||||
import { useDeleteIdentityFromWorkspace } from "@app/hooks/api";
|
||||
import { useDeleteProjectIdentityMembership } from "@app/hooks/api";
|
||||
import { usePopUp } from "@app/hooks/usePopUp";
|
||||
|
||||
import { IdentityAddToProjectModal } from "./IdentityAddToProjectModal";
|
||||
@@ -14,7 +14,7 @@ type Props = {
|
||||
};
|
||||
|
||||
export const IdentityProjectsSection = ({ identityId }: Props) => {
|
||||
const { mutateAsync: deleteMutateAsync } = useDeleteIdentityFromWorkspace();
|
||||
const { mutateAsync: deleteMutateAsync } = useDeleteProjectIdentityMembership();
|
||||
|
||||
const { popUp, handlePopUpOpen, handlePopUpClose, handlePopUpToggle } = usePopUp([
|
||||
"addIdentityToProject",
|
||||
|
||||
+27
-6
@@ -1,11 +1,18 @@
|
||||
import { useState } from "react";
|
||||
import { subject } from "@casl/ability";
|
||||
import { UseMutationResult } from "@tanstack/react-query";
|
||||
import { useParams } from "@tanstack/react-router";
|
||||
import ms from "ms";
|
||||
|
||||
import { createNotification } from "@app/components/notifications";
|
||||
import { OrgPermissionCan } from "@app/components/permissions";
|
||||
import { VariablePermissionCan } from "@app/components/permissions";
|
||||
import { Button } from "@app/components/v2";
|
||||
import { OrgPermissionIdentityActions, OrgPermissionSubjects } from "@app/context";
|
||||
import {
|
||||
OrgPermissionIdentityActions,
|
||||
OrgPermissionSubjects,
|
||||
ProjectPermissionIdentityActions,
|
||||
ProjectPermissionSub
|
||||
} from "@app/context";
|
||||
|
||||
import { IdentityAuthFieldDisplay } from "./IdentityAuthFieldDisplay";
|
||||
|
||||
@@ -31,7 +38,11 @@ export const LockoutFields = ({
|
||||
|
||||
const [lockedOutState, setLockedOutState] = useState(lockedOut);
|
||||
|
||||
const clearLockouts = async () => {
|
||||
const { projectId } = useParams({
|
||||
strict: false
|
||||
});
|
||||
|
||||
async function clearLockouts() {
|
||||
const deleted = await mutateAsync({ identityId });
|
||||
createNotification({
|
||||
text: `Successfully cleared ${deleted} lockout${deleted === 1 ? "" : "s"}`,
|
||||
@@ -39,13 +50,23 @@ export const LockoutFields = ({
|
||||
});
|
||||
setLockedOutState(false);
|
||||
onResetAllLockouts();
|
||||
};
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="col-span-2 mt-3 flex justify-between border-b border-mineshaft-500 pb-2">
|
||||
<span className="text-bunker-300">Lockout Options</span>
|
||||
<OrgPermissionCan I={OrgPermissionIdentityActions.Edit} a={OrgPermissionSubjects.Identity}>
|
||||
<VariablePermissionCan
|
||||
type={projectId ? "project" : "org"}
|
||||
I={projectId ? ProjectPermissionIdentityActions.Edit : OrgPermissionIdentityActions.Edit}
|
||||
a={
|
||||
projectId
|
||||
? subject(ProjectPermissionSub.Identity, {
|
||||
identityId
|
||||
})
|
||||
: OrgPermissionSubjects.Identity
|
||||
}
|
||||
>
|
||||
{(isAllowed) => (
|
||||
<Button
|
||||
isDisabled={!isAllowed || !lockedOutState || isPending}
|
||||
@@ -57,7 +78,7 @@ export const LockoutFields = ({
|
||||
Reset All Lockouts
|
||||
</Button>
|
||||
)}
|
||||
</OrgPermissionCan>
|
||||
</VariablePermissionCan>
|
||||
</div>
|
||||
<IdentityAuthFieldDisplay label="Lockout Threshold">
|
||||
{data.lockoutThreshold}
|
||||
|
||||
+55
-12
@@ -1,10 +1,12 @@
|
||||
import { useState } from "react";
|
||||
import { subject } from "@casl/ability";
|
||||
import { faBan, faEdit, faKey, faPlus } from "@fortawesome/free-solid-svg-icons";
|
||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||
import { useParams } from "@tanstack/react-router";
|
||||
import { format } from "date-fns";
|
||||
|
||||
import { createNotification } from "@app/components/notifications";
|
||||
import { OrgPermissionCan } from "@app/components/permissions";
|
||||
import { VariablePermissionCan } from "@app/components/permissions";
|
||||
import {
|
||||
Button,
|
||||
DeleteActionModal,
|
||||
@@ -20,7 +22,12 @@ import {
|
||||
Tooltip,
|
||||
Tr
|
||||
} from "@app/components/v2";
|
||||
import { OrgPermissionIdentityActions, OrgPermissionSubjects } from "@app/context";
|
||||
import {
|
||||
OrgPermissionIdentityActions,
|
||||
OrgPermissionSubjects,
|
||||
ProjectPermissionIdentityActions,
|
||||
ProjectPermissionSub
|
||||
} from "@app/context";
|
||||
import { usePopUp } from "@app/hooks";
|
||||
import { useRevokeIdentityTokenAuthToken } from "@app/hooks/api";
|
||||
import { IdentityAccessToken } from "@app/hooks/api/identities/types";
|
||||
@@ -37,6 +44,10 @@ export const IdentityTokenAuthTokensTable = ({ tokens, identityId }: Props) => {
|
||||
"revokeToken"
|
||||
] as const);
|
||||
|
||||
const { projectId } = useParams({
|
||||
strict: false
|
||||
});
|
||||
|
||||
const [page, setPage] = useState(1);
|
||||
const [perPage, setPerPage] = useState(5);
|
||||
|
||||
@@ -68,7 +79,17 @@ export const IdentityTokenAuthTokensTable = ({ tokens, identityId }: Props) => {
|
||||
<div className="col-span-2 mt-3">
|
||||
<div className="flex items-end justify-between border-b border-mineshaft-500 pb-2">
|
||||
<span className="text-bunker-300">Access Tokens</span>
|
||||
<OrgPermissionCan I={OrgPermissionIdentityActions.Edit} a={OrgPermissionSubjects.Identity}>
|
||||
<VariablePermissionCan
|
||||
type={projectId ? "project" : "org"}
|
||||
I={projectId ? ProjectPermissionIdentityActions.Edit : OrgPermissionIdentityActions.Edit}
|
||||
a={
|
||||
projectId
|
||||
? subject(ProjectPermissionSub.Identity, {
|
||||
identityId
|
||||
})
|
||||
: OrgPermissionSubjects.Identity
|
||||
}
|
||||
>
|
||||
{(isAllowed) => (
|
||||
<Button
|
||||
size="xs"
|
||||
@@ -84,7 +105,7 @@ export const IdentityTokenAuthTokensTable = ({ tokens, identityId }: Props) => {
|
||||
Add Token
|
||||
</Button>
|
||||
)}
|
||||
</OrgPermissionCan>
|
||||
</VariablePermissionCan>
|
||||
</div>
|
||||
<TableContainer className="mt-4 rounded-none border-none">
|
||||
<Table>
|
||||
@@ -132,9 +153,20 @@ export const IdentityTokenAuthTokensTable = ({ tokens, identityId }: Props) => {
|
||||
</Td>
|
||||
<Td>
|
||||
<div className="flex items-center gap-2">
|
||||
<OrgPermissionCan
|
||||
I={OrgPermissionIdentityActions.Edit}
|
||||
a={OrgPermissionSubjects.Identity}
|
||||
<VariablePermissionCan
|
||||
type={projectId ? "project" : "org"}
|
||||
I={
|
||||
projectId
|
||||
? ProjectPermissionIdentityActions.Edit
|
||||
: OrgPermissionIdentityActions.Edit
|
||||
}
|
||||
a={
|
||||
projectId
|
||||
? subject(ProjectPermissionSub.Identity, {
|
||||
identityId
|
||||
})
|
||||
: OrgPermissionSubjects.Identity
|
||||
}
|
||||
>
|
||||
{(isAllowed) => (
|
||||
<Tooltip content={isAllowed ? "Edit Token" : "Access Restricted"}>
|
||||
@@ -155,11 +187,22 @@ export const IdentityTokenAuthTokensTable = ({ tokens, identityId }: Props) => {
|
||||
</IconButton>
|
||||
</Tooltip>
|
||||
)}
|
||||
</OrgPermissionCan>
|
||||
</VariablePermissionCan>
|
||||
{!isAccessTokenRevoked && (
|
||||
<OrgPermissionCan
|
||||
I={OrgPermissionIdentityActions.Edit}
|
||||
a={OrgPermissionSubjects.Identity}
|
||||
<VariablePermissionCan
|
||||
type={projectId ? "project" : "org"}
|
||||
I={
|
||||
projectId
|
||||
? ProjectPermissionIdentityActions.Edit
|
||||
: OrgPermissionIdentityActions.Edit
|
||||
}
|
||||
a={
|
||||
projectId
|
||||
? subject(ProjectPermissionSub.Identity, {
|
||||
identityId
|
||||
})
|
||||
: OrgPermissionSubjects.Identity
|
||||
}
|
||||
>
|
||||
{(isAllowed) => (
|
||||
<Tooltip content={isAllowed ? "Revoke Token" : "Access Restricted"}>
|
||||
@@ -181,7 +224,7 @@ export const IdentityTokenAuthTokensTable = ({ tokens, identityId }: Props) => {
|
||||
</IconButton>
|
||||
</Tooltip>
|
||||
)}
|
||||
</OrgPermissionCan>
|
||||
</VariablePermissionCan>
|
||||
)}
|
||||
</div>
|
||||
</Td>
|
||||
|
||||
+40
-8
@@ -1,10 +1,12 @@
|
||||
import { useState } from "react";
|
||||
import { subject } from "@casl/ability";
|
||||
import { faKey, faPlus, faTrash } from "@fortawesome/free-solid-svg-icons";
|
||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||
import { useParams } from "@tanstack/react-router";
|
||||
import { format } from "date-fns";
|
||||
|
||||
import { createNotification } from "@app/components/notifications";
|
||||
import { OrgPermissionCan } from "@app/components/permissions";
|
||||
import { VariablePermissionCan } from "@app/components/permissions";
|
||||
import {
|
||||
Button,
|
||||
DeleteActionModal,
|
||||
@@ -20,7 +22,12 @@ import {
|
||||
Tooltip,
|
||||
Tr
|
||||
} from "@app/components/v2";
|
||||
import { OrgPermissionIdentityActions, OrgPermissionSubjects } from "@app/context";
|
||||
import {
|
||||
OrgPermissionIdentityActions,
|
||||
OrgPermissionSubjects,
|
||||
ProjectPermissionIdentityActions,
|
||||
ProjectPermissionSub
|
||||
} from "@app/context";
|
||||
import { usePopUp } from "@app/hooks";
|
||||
import { useRevokeIdentityUniversalAuthClientSecret } from "@app/hooks/api";
|
||||
import { ClientSecretData } from "@app/hooks/api/identities/types";
|
||||
@@ -37,6 +44,10 @@ export const IdentityUniversalAuthClientSecretsTable = ({ clientSecrets, identit
|
||||
"clientSecret"
|
||||
] as const);
|
||||
|
||||
const { projectId } = useParams({
|
||||
strict: false
|
||||
});
|
||||
|
||||
const [page, setPage] = useState(1);
|
||||
const [perPage, setPerPage] = useState(5);
|
||||
|
||||
@@ -60,7 +71,17 @@ export const IdentityUniversalAuthClientSecretsTable = ({ clientSecrets, identit
|
||||
<div className="col-span-2">
|
||||
<div className="flex items-end justify-between border-b border-mineshaft-500 pb-2">
|
||||
<span className="text-bunker-300">Client Secrets</span>
|
||||
<OrgPermissionCan I={OrgPermissionIdentityActions.Edit} a={OrgPermissionSubjects.Identity}>
|
||||
<VariablePermissionCan
|
||||
type={projectId ? "project" : "org"}
|
||||
I={projectId ? ProjectPermissionIdentityActions.Edit : OrgPermissionIdentityActions.Edit}
|
||||
a={
|
||||
projectId
|
||||
? subject(ProjectPermissionSub.Identity, {
|
||||
identityId
|
||||
})
|
||||
: OrgPermissionSubjects.Identity
|
||||
}
|
||||
>
|
||||
{(isAllowed) => (
|
||||
<Button
|
||||
isDisabled={!isAllowed}
|
||||
@@ -76,7 +97,7 @@ export const IdentityUniversalAuthClientSecretsTable = ({ clientSecrets, identit
|
||||
Add Client Secret
|
||||
</Button>
|
||||
)}
|
||||
</OrgPermissionCan>
|
||||
</VariablePermissionCan>
|
||||
</div>
|
||||
<TableContainer className="mt-4 rounded-none border-none">
|
||||
<Table>
|
||||
@@ -120,9 +141,20 @@ export const IdentityUniversalAuthClientSecretsTable = ({ clientSecrets, identit
|
||||
{expiresAt ? format(expiresAt, "yyyy-MM-dd") : "-"}
|
||||
</Td>
|
||||
<Td>
|
||||
<OrgPermissionCan
|
||||
I={OrgPermissionIdentityActions.Edit}
|
||||
a={OrgPermissionSubjects.Identity}
|
||||
<VariablePermissionCan
|
||||
type={projectId ? "project" : "org"}
|
||||
I={
|
||||
projectId
|
||||
? ProjectPermissionIdentityActions.Edit
|
||||
: OrgPermissionIdentityActions.Edit
|
||||
}
|
||||
a={
|
||||
projectId
|
||||
? subject(ProjectPermissionSub.Identity, {
|
||||
identityId
|
||||
})
|
||||
: OrgPermissionSubjects.Identity
|
||||
}
|
||||
>
|
||||
{(isAllowed) => (
|
||||
<Tooltip content={isAllowed ? "Delete Secret" : "Access Restricted"}>
|
||||
@@ -143,7 +175,7 @@ export const IdentityUniversalAuthClientSecretsTable = ({ clientSecrets, identit
|
||||
</IconButton>
|
||||
</Tooltip>
|
||||
)}
|
||||
</OrgPermissionCan>
|
||||
</VariablePermissionCan>
|
||||
</Td>
|
||||
</Tr>
|
||||
);
|
||||
|
||||
+1
@@ -49,6 +49,7 @@ export const ViewIdentityAliCloudAuthContent = ({
|
||||
<ViewIdentityContentWrapper
|
||||
onEdit={() => handlePopUpOpen("identityAuthMethod")}
|
||||
onDelete={onDelete}
|
||||
identityId={identityId}
|
||||
>
|
||||
<IdentityAuthFieldDisplay label="Access Token TTL (seconds)">
|
||||
{data.accessTokenTTL}
|
||||
|
||||
+11
-4
@@ -1,3 +1,5 @@
|
||||
import { useParams } from "@tanstack/react-router";
|
||||
|
||||
import { UpgradePlanModal } from "@app/components/license/UpgradePlanModal";
|
||||
import { createNotification } from "@app/components/notifications";
|
||||
import { DeleteActionModal, Modal, ModalContent } from "@app/components/v2";
|
||||
@@ -46,8 +48,7 @@ type Props = {
|
||||
|
||||
type TRevokeOptions = {
|
||||
identityId: string;
|
||||
organizationId: string;
|
||||
};
|
||||
} & ({ projectId: string } | { organizationId: string });
|
||||
|
||||
export const Content = ({
|
||||
identityId,
|
||||
@@ -61,7 +62,9 @@ export const Content = ({
|
||||
>) => {
|
||||
const { currentOrg } = useOrganization();
|
||||
const orgId = currentOrg?.id || "";
|
||||
|
||||
const { projectId } = useParams({
|
||||
strict: false
|
||||
});
|
||||
const { popUp, handlePopUpOpen, handlePopUpToggle } = usePopUp([
|
||||
"revokeAuthMethod",
|
||||
"upgradePlan",
|
||||
@@ -142,7 +145,11 @@ export const Content = ({
|
||||
const handleDeleteAuthMethod = async () => {
|
||||
await revokeMethod({
|
||||
identityId,
|
||||
organizationId: orgId
|
||||
...(projectId
|
||||
? { projectId }
|
||||
: {
|
||||
organizationId: orgId
|
||||
})
|
||||
});
|
||||
|
||||
createNotification({
|
||||
|
||||
+1
@@ -46,6 +46,7 @@ export const ViewIdentityAwsAuthContent = ({
|
||||
<ViewIdentityContentWrapper
|
||||
onEdit={() => handlePopUpOpen("identityAuthMethod")}
|
||||
onDelete={onDelete}
|
||||
identityId={identityId}
|
||||
>
|
||||
<IdentityAuthFieldDisplay label="Access Token TTL (seconds)">
|
||||
{data.accessTokenTTL}
|
||||
|
||||
+1
@@ -46,6 +46,7 @@ export const ViewIdentityAzureAuthContent = ({
|
||||
<ViewIdentityContentWrapper
|
||||
onEdit={() => handlePopUpOpen("identityAuthMethod")}
|
||||
onDelete={onDelete}
|
||||
identityId={identityId}
|
||||
>
|
||||
<IdentityAuthFieldDisplay label="Access Token TTL (seconds)">
|
||||
{data.accessTokenTTL}
|
||||
|
||||
+45
-11
@@ -1,8 +1,10 @@
|
||||
import { ReactNode } from "react";
|
||||
import { subject } from "@casl/ability";
|
||||
import { faChevronDown, faEdit, faTrash } from "@fortawesome/free-solid-svg-icons";
|
||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||
import { useParams } from "@tanstack/react-router";
|
||||
|
||||
import { OrgPermissionCan } from "@app/components/permissions";
|
||||
import { VariablePermissionCan } from "@app/components/permissions";
|
||||
import {
|
||||
Button,
|
||||
DropdownMenu,
|
||||
@@ -10,15 +12,25 @@ import {
|
||||
DropdownMenuItem,
|
||||
DropdownMenuTrigger
|
||||
} from "@app/components/v2";
|
||||
import { OrgPermissionIdentityActions, OrgPermissionSubjects } from "@app/context";
|
||||
import {
|
||||
OrgPermissionIdentityActions,
|
||||
OrgPermissionSubjects,
|
||||
ProjectPermissionIdentityActions,
|
||||
ProjectPermissionSub
|
||||
} from "@app/context";
|
||||
|
||||
type Props = {
|
||||
children: ReactNode;
|
||||
onEdit: VoidFunction;
|
||||
onDelete: VoidFunction;
|
||||
identityId: string;
|
||||
};
|
||||
|
||||
export const ViewIdentityContentWrapper = ({ children, onDelete, onEdit }: Props) => {
|
||||
export const ViewIdentityContentWrapper = ({ children, onDelete, onEdit, identityId }: Props) => {
|
||||
const { projectId } = useParams({
|
||||
strict: false
|
||||
});
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-4">
|
||||
<div>
|
||||
@@ -36,9 +48,20 @@ export const ViewIdentityContentWrapper = ({ children, onDelete, onEdit }: Props
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent className="mt-3 min-w-[120px]" align="end">
|
||||
<OrgPermissionCan
|
||||
I={OrgPermissionIdentityActions.Edit}
|
||||
a={OrgPermissionSubjects.Identity}
|
||||
<VariablePermissionCan
|
||||
type={projectId ? "project" : "org"}
|
||||
I={
|
||||
projectId
|
||||
? ProjectPermissionIdentityActions.Edit
|
||||
: OrgPermissionIdentityActions.Edit
|
||||
}
|
||||
a={
|
||||
projectId
|
||||
? subject(ProjectPermissionSub.Identity, {
|
||||
identityId
|
||||
})
|
||||
: OrgPermissionSubjects.Identity
|
||||
}
|
||||
>
|
||||
{(isAllowed) => (
|
||||
<DropdownMenuItem
|
||||
@@ -49,10 +72,21 @@ export const ViewIdentityContentWrapper = ({ children, onDelete, onEdit }: Props
|
||||
Edit
|
||||
</DropdownMenuItem>
|
||||
)}
|
||||
</OrgPermissionCan>
|
||||
<OrgPermissionCan
|
||||
I={OrgPermissionIdentityActions.Delete}
|
||||
a={OrgPermissionSubjects.Identity}
|
||||
</VariablePermissionCan>
|
||||
<VariablePermissionCan
|
||||
type={projectId ? "project" : "org"}
|
||||
I={
|
||||
projectId
|
||||
? ProjectPermissionIdentityActions.Delete
|
||||
: OrgPermissionIdentityActions.Delete
|
||||
}
|
||||
a={
|
||||
projectId
|
||||
? subject(ProjectPermissionSub.Identity, {
|
||||
identityId
|
||||
})
|
||||
: OrgPermissionSubjects.Identity
|
||||
}
|
||||
>
|
||||
{(isAllowed) => (
|
||||
<DropdownMenuItem
|
||||
@@ -63,7 +97,7 @@ export const ViewIdentityContentWrapper = ({ children, onDelete, onEdit }: Props
|
||||
Delete
|
||||
</DropdownMenuItem>
|
||||
)}
|
||||
</OrgPermissionCan>
|
||||
</VariablePermissionCan>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
</div>
|
||||
|
||||
+1
@@ -46,6 +46,7 @@ export const ViewIdentityGcpAuthContent = ({
|
||||
<ViewIdentityContentWrapper
|
||||
onEdit={() => handlePopUpOpen("identityAuthMethod")}
|
||||
onDelete={onDelete}
|
||||
identityId={identityId}
|
||||
>
|
||||
<IdentityAuthFieldDisplay label="Access Token TTL (seconds)">
|
||||
{data.accessTokenTTL}
|
||||
|
||||
+1
@@ -49,6 +49,7 @@ export const ViewIdentityJwtAuthContent = ({
|
||||
<ViewIdentityContentWrapper
|
||||
onEdit={() => handlePopUpOpen("identityAuthMethod")}
|
||||
onDelete={onDelete}
|
||||
identityId={identityId}
|
||||
>
|
||||
<IdentityAuthFieldDisplay label="Access Token TTL (seconds)">
|
||||
{data.accessTokenTTL}
|
||||
|
||||
+1
@@ -59,6 +59,7 @@ export const ViewIdentityKubernetesAuthContent = ({
|
||||
<ViewIdentityContentWrapper
|
||||
onEdit={() => handlePopUpOpen("identityAuthMethod")}
|
||||
onDelete={onDelete}
|
||||
identityId={identityId}
|
||||
>
|
||||
<IdentityAuthFieldDisplay label="Access Token TTL (seconds)">
|
||||
{data.accessTokenTTL}
|
||||
|
||||
+1
@@ -52,6 +52,7 @@ export const ViewIdentityLdapAuthContent = ({
|
||||
<ViewIdentityContentWrapper
|
||||
onEdit={() => handlePopUpOpen("identityAuthMethod")}
|
||||
onDelete={onDelete}
|
||||
identityId={identityId}
|
||||
>
|
||||
<IdentityAuthFieldDisplay label="Access Token TTL (seconds)">
|
||||
{data.accessTokenTTL}
|
||||
|
||||
+1
@@ -46,6 +46,7 @@ export const ViewIdentityOciAuthContent = ({
|
||||
<ViewIdentityContentWrapper
|
||||
onEdit={() => handlePopUpOpen("identityAuthMethod")}
|
||||
onDelete={onDelete}
|
||||
identityId={identityId}
|
||||
>
|
||||
<IdentityAuthFieldDisplay label="Access Token TTL (seconds)">
|
||||
{data.accessTokenTTL}
|
||||
|
||||
+1
@@ -48,6 +48,7 @@ export const ViewIdentityOidcAuthContent = ({
|
||||
<ViewIdentityContentWrapper
|
||||
onEdit={() => handlePopUpOpen("identityAuthMethod")}
|
||||
onDelete={onDelete}
|
||||
identityId={identityId}
|
||||
>
|
||||
<IdentityAuthFieldDisplay label="Access Token TTL (seconds)">
|
||||
{data.accessTokenTTL}
|
||||
|
||||
+1
@@ -51,6 +51,7 @@ export const ViewIdentityTlsCertAuthContent = ({
|
||||
<ViewIdentityContentWrapper
|
||||
onEdit={() => handlePopUpOpen("identityAuthMethod")}
|
||||
onDelete={onDelete}
|
||||
identityId={identityId}
|
||||
>
|
||||
<IdentityAuthFieldDisplay label="Access Token TTL (seconds)">
|
||||
{data.accessTokenTTL}
|
||||
|
||||
+1
@@ -49,6 +49,7 @@ export const ViewIdentityTokenAuthContent = ({
|
||||
<ViewIdentityContentWrapper
|
||||
onEdit={() => handlePopUpOpen("identityAuthMethod")}
|
||||
onDelete={onDelete}
|
||||
identityId={identityId}
|
||||
>
|
||||
<IdentityAuthFieldDisplay label="Access Token TTL (seconds)">
|
||||
{data.accessTokenTTL}
|
||||
|
||||
+1
@@ -66,6 +66,7 @@ export const ViewIdentityUniversalAuthContent = ({
|
||||
<ViewIdentityContentWrapper
|
||||
onEdit={() => handlePopUpOpen("identityAuthMethod")}
|
||||
onDelete={onDelete}
|
||||
identityId={identityId}
|
||||
>
|
||||
{Number(data.accessTokenPeriod) > 0 ? (
|
||||
<IdentityAuthFieldDisplay label="Access Token Period (seconds)">
|
||||
|
||||
@@ -26,10 +26,21 @@ export const ResourceTypeSelect = ({ onSelect }: Props) => {
|
||||
return [
|
||||
...resourceOptions,
|
||||
// We are temporarily showing these resources so that we can gauge interest before committing
|
||||
{ name: "OracleDB", resource: PamResourceType.OracleDB },
|
||||
{ name: "SQLite", resource: PamResourceType.SQLite },
|
||||
{ name: "Microsoft SQL Server", resource: PamResourceType.MsSQL },
|
||||
{ name: "MongoDB", resource: PamResourceType.MongoDB },
|
||||
{ name: "Cassandra", resource: PamResourceType.Cassandra },
|
||||
{ name: "CockroachDB", resource: PamResourceType.CockroachDB },
|
||||
{ name: "DynamoDB", resource: PamResourceType.DynamoDB },
|
||||
{ name: "Snowflake", resource: PamResourceType.Snowflake },
|
||||
{ name: "Elasticsearch", resource: PamResourceType.Elasticsearch },
|
||||
{ name: "Redis", resource: PamResourceType.Redis },
|
||||
{ name: "RDP", resource: PamResourceType.RDP },
|
||||
{ name: "SSH", resource: PamResourceType.SSH },
|
||||
{ name: "Kubernetes", resource: PamResourceType.Kubernetes },
|
||||
{ name: "MCP", resource: PamResourceType.MCP }
|
||||
{ name: "MCP", resource: PamResourceType.MCP },
|
||||
{ name: "Web Application", resource: PamResourceType.WebApp }
|
||||
];
|
||||
}, [resourceOptions]);
|
||||
|
||||
@@ -39,11 +50,13 @@ export const ResourceTypeSelect = ({ onSelect }: Props) => {
|
||||
|
||||
const filteredOptions = useMemo(
|
||||
() =>
|
||||
appendedResourceOptions?.filter(
|
||||
({ name, resource }) =>
|
||||
name.toLowerCase().includes(search.trim().toLowerCase()) ||
|
||||
resource.toLowerCase().includes(search.trim().toLowerCase())
|
||||
) ?? [],
|
||||
appendedResourceOptions
|
||||
?.filter(
|
||||
({ name, resource }) =>
|
||||
name.toLowerCase().includes(search.trim().toLowerCase()) ||
|
||||
resource.toLowerCase().includes(search.trim().toLowerCase())
|
||||
)
|
||||
.sort((a, b) => a.name.localeCompare(b.name)) ?? [],
|
||||
[appendedResourceOptions, search]
|
||||
);
|
||||
|
||||
@@ -67,7 +80,15 @@ export const ResourceTypeSelect = ({ onSelect }: Props) => {
|
||||
resource === PamResourceType.RDP ||
|
||||
resource === PamResourceType.SSH ||
|
||||
resource === PamResourceType.Kubernetes ||
|
||||
resource === PamResourceType.MCP
|
||||
resource === PamResourceType.MCP ||
|
||||
resource === PamResourceType.Redis ||
|
||||
resource === PamResourceType.MongoDB ||
|
||||
resource === PamResourceType.WebApp ||
|
||||
resource === PamResourceType.Cassandra ||
|
||||
resource === PamResourceType.CockroachDB ||
|
||||
resource === PamResourceType.Elasticsearch ||
|
||||
resource === PamResourceType.Snowflake ||
|
||||
resource === PamResourceType.DynamoDB
|
||||
) {
|
||||
handlePopUpOpen("upgradePlan", {
|
||||
text: "Your current plan does not include access to this resource type. To unlock this feature, please upgrade to Infisical Enterprise plan.",
|
||||
@@ -107,17 +128,16 @@ export const ResourceTypeSelect = ({ onSelect }: Props) => {
|
||||
onClick={() => handleResourceSelect(option.resource)}
|
||||
className="group relative flex h-28 cursor-pointer flex-col items-center justify-center rounded-md border border-mineshaft-600 bg-mineshaft-700 p-4 duration-200 hover:bg-mineshaft-600"
|
||||
>
|
||||
<div className="relative">
|
||||
<div className="relative my-auto">
|
||||
<img
|
||||
src={`/images/integrations/${image}`}
|
||||
style={{
|
||||
width: `${size}px`
|
||||
}}
|
||||
className="mt-auto"
|
||||
alt={`${name} logo`}
|
||||
/>
|
||||
</div>
|
||||
<div className="mt-auto max-w-xs text-center text-xs font-medium text-gray-300 duration-200 group-hover:text-gray-200">
|
||||
<div className="max-w-xs text-center text-xs font-medium text-gray-300 duration-200 group-hover:text-gray-200">
|
||||
{name}
|
||||
</div>
|
||||
</button>
|
||||
|
||||
+243
-54
@@ -1,3 +1,4 @@
|
||||
import { useState } from "react";
|
||||
import { subject } from "@casl/ability";
|
||||
import {
|
||||
faArrowDown,
|
||||
@@ -11,7 +12,8 @@ import {
|
||||
} from "@fortawesome/free-solid-svg-icons";
|
||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||
import { useNavigate } from "@tanstack/react-router";
|
||||
import { format } from "date-fns";
|
||||
import { AnimatePresence, motion } from "framer-motion";
|
||||
import { LinkIcon, PlusIcon } from "lucide-react";
|
||||
import { twMerge } from "tailwind-merge";
|
||||
|
||||
import { createNotification } from "@app/components/notifications";
|
||||
@@ -29,6 +31,8 @@ import {
|
||||
HoverCardTrigger,
|
||||
IconButton,
|
||||
Input,
|
||||
Modal,
|
||||
ModalContent,
|
||||
Pagination,
|
||||
Spinner,
|
||||
Table,
|
||||
@@ -42,8 +46,20 @@ import {
|
||||
Tooltip,
|
||||
Tr
|
||||
} from "@app/components/v2";
|
||||
import { DocumentationLinkBadge } from "@app/components/v3";
|
||||
import { ProjectPermissionActions, ProjectPermissionSub, useProject } from "@app/context";
|
||||
import { Blur } from "@app/components/v2/Blur";
|
||||
import {
|
||||
Badge,
|
||||
DocumentationLinkBadge,
|
||||
OrgIcon,
|
||||
ProjectIcon,
|
||||
SubOrgIcon
|
||||
} from "@app/components/v3";
|
||||
import {
|
||||
ProjectPermissionActions,
|
||||
ProjectPermissionSub,
|
||||
useOrganization,
|
||||
useProject
|
||||
} from "@app/context";
|
||||
import { getProjectBaseURL } from "@app/helpers/project";
|
||||
import { formatProjectRoleName } from "@app/helpers/roles";
|
||||
import {
|
||||
@@ -53,19 +69,33 @@ import {
|
||||
} from "@app/helpers/userTablePreferences";
|
||||
import { withProjectPermission } from "@app/hoc";
|
||||
import { usePagination, useResetPageHelper } from "@app/hooks";
|
||||
import { useDeleteIdentityFromWorkspace, useGetWorkspaceIdentityMemberships } from "@app/hooks/api";
|
||||
import {
|
||||
useDeleteProjectIdentity,
|
||||
useDeleteProjectIdentityMembership,
|
||||
useListProjectIdentityMemberships
|
||||
} from "@app/hooks/api";
|
||||
import { OrderByDirection } from "@app/hooks/api/generic/types";
|
||||
import { ProjectIdentityOrderBy } from "@app/hooks/api/projects/types";
|
||||
import { usePopUp } from "@app/hooks/usePopUp";
|
||||
import { ProjectIdentityModal } from "@app/pages/project/AccessControlPage/components/IdentityTab/components/ProjectIdentityModal";
|
||||
|
||||
import { IdentityModal } from "./components/IdentityModal";
|
||||
import { ProjectLinkIdentityModal } from "./components/ProjectLinkIdentityModal";
|
||||
|
||||
const MAX_ROLES_TO_BE_SHOWN_IN_TABLE = 2;
|
||||
|
||||
enum WizardSteps {
|
||||
SelectAction = "select-action",
|
||||
LinkIdentity = "link-identity",
|
||||
ProjectIdentity = "project-identity"
|
||||
}
|
||||
|
||||
export const IdentityTab = withProjectPermission(
|
||||
() => {
|
||||
const { currentProject, projectId } = useProject();
|
||||
const navigate = useNavigate();
|
||||
const { isSubOrganization, currentOrg } = useOrganization();
|
||||
|
||||
const [wizardStep, setWizardStep] = useState(WizardSteps.SelectAction);
|
||||
|
||||
const {
|
||||
offset,
|
||||
@@ -90,7 +120,7 @@ export const IdentityTab = withProjectPermission(
|
||||
setUserTablePreference("projectIdentityTable", PreferenceKey.PerPage, newPerPage);
|
||||
};
|
||||
|
||||
const { data, isPending, isFetching } = useGetWorkspaceIdentityMemberships(
|
||||
const { data, isPending, isFetching } = useListProjectIdentityMemberships(
|
||||
{
|
||||
projectId,
|
||||
offset,
|
||||
@@ -110,28 +140,41 @@ export const IdentityTab = withProjectPermission(
|
||||
setPage
|
||||
});
|
||||
|
||||
const { mutateAsync: deleteMutateAsync } = useDeleteIdentityFromWorkspace();
|
||||
const { mutateAsync: deleteMembershipMutateAsync } = useDeleteProjectIdentityMembership();
|
||||
const { mutateAsync: deleteProjectIdentity } = useDeleteProjectIdentity();
|
||||
|
||||
const { popUp, handlePopUpOpen, handlePopUpClose, handlePopUpToggle } = usePopUp([
|
||||
"identity",
|
||||
"createIdentity",
|
||||
"deleteIdentity",
|
||||
"upgradePlan"
|
||||
"upgradePlan",
|
||||
"addOptions"
|
||||
] as const);
|
||||
|
||||
const onRemoveIdentitySubmit = async (identityId: string) => {
|
||||
await deleteMutateAsync({
|
||||
identityId,
|
||||
projectId
|
||||
});
|
||||
const onRemoveIdentitySubmit = async (identityId: string, isProjectIdentity: boolean) => {
|
||||
if (isProjectIdentity) {
|
||||
await deleteProjectIdentity({
|
||||
identityId,
|
||||
projectId
|
||||
});
|
||||
|
||||
createNotification({
|
||||
text: "Successfully removed identity from project",
|
||||
type: "success"
|
||||
});
|
||||
createNotification({
|
||||
text: "Successfully deleted project identity",
|
||||
type: "success"
|
||||
});
|
||||
} else {
|
||||
await deleteMembershipMutateAsync({
|
||||
identityId,
|
||||
projectId
|
||||
});
|
||||
|
||||
createNotification({
|
||||
text: "Successfully removed identity from project",
|
||||
type: "success"
|
||||
});
|
||||
}
|
||||
|
||||
handlePopUpClose("deleteIdentity");
|
||||
};
|
||||
|
||||
const handleSort = (column: ProjectIdentityOrderBy) => {
|
||||
if (column === orderBy) {
|
||||
setOrderDirection((prev) =>
|
||||
@@ -144,6 +187,12 @@ export const IdentityTab = withProjectPermission(
|
||||
setOrderDirection(OrderByDirection.ASC);
|
||||
};
|
||||
|
||||
const noAccessIdentityCount = Math.max(
|
||||
(page * perPage > totalCount ? totalCount % perPage : perPage) -
|
||||
(data?.identityMemberships?.length || 0),
|
||||
0
|
||||
);
|
||||
|
||||
return (
|
||||
<div className="mb-6 rounded-lg border border-mineshaft-600 bg-mineshaft-900 p-4">
|
||||
<div className="mb-4 flex items-center justify-between">
|
||||
@@ -151,22 +200,23 @@ export const IdentityTab = withProjectPermission(
|
||||
<p className="text-xl font-medium text-mineshaft-100">Identities</p>
|
||||
<DocumentationLinkBadge href="https://infisical.com/docs/documentation/platform/identities/machine-identities" />
|
||||
</div>
|
||||
<ProjectPermissionCan
|
||||
I={ProjectPermissionActions.Create}
|
||||
a={ProjectPermissionSub.Identity}
|
||||
>
|
||||
{(isAllowed) => (
|
||||
<Button
|
||||
colorSchema="secondary"
|
||||
type="submit"
|
||||
leftIcon={<FontAwesomeIcon icon={faPlus} />}
|
||||
onClick={() => handlePopUpOpen("identity")}
|
||||
isDisabled={!isAllowed}
|
||||
>
|
||||
Add Identity
|
||||
</Button>
|
||||
)}
|
||||
</ProjectPermissionCan>
|
||||
<div className="flex items-center">
|
||||
<ProjectPermissionCan
|
||||
I={ProjectPermissionActions.Create}
|
||||
a={ProjectPermissionSub.Identity}
|
||||
>
|
||||
{(isAllowed) => (
|
||||
<Button
|
||||
variant="outline_bg"
|
||||
leftIcon={<FontAwesomeIcon icon={faPlus} />}
|
||||
onClick={() => handlePopUpOpen("createIdentity")}
|
||||
isDisabled={!isAllowed}
|
||||
>
|
||||
Create Identity
|
||||
</Button>
|
||||
)}
|
||||
</ProjectPermissionCan>
|
||||
</div>
|
||||
</div>
|
||||
<Input
|
||||
containerClassName="mb-4"
|
||||
@@ -202,7 +252,7 @@ export const IdentityTab = withProjectPermission(
|
||||
</div>
|
||||
</Th>
|
||||
<Th className="w-1/3">Role</Th>
|
||||
<Th>Added on</Th>
|
||||
<Th>Managed by</Th>
|
||||
<Th className="w-5">{isFetching ? <Spinner size="xs" /> : null}</Th>
|
||||
</Tr>
|
||||
</THead>
|
||||
@@ -213,9 +263,8 @@ export const IdentityTab = withProjectPermission(
|
||||
data.identityMemberships.length > 0 &&
|
||||
data.identityMemberships.map((identityMember) => {
|
||||
const {
|
||||
identity: { id, name },
|
||||
roles,
|
||||
createdAt
|
||||
identity: { id, name, projectId: identityProjectId, orgId: identityOrgId },
|
||||
roles
|
||||
} = identityMember;
|
||||
return (
|
||||
<Tr
|
||||
@@ -339,7 +388,36 @@ export const IdentityTab = withProjectPermission(
|
||||
)}
|
||||
</div>
|
||||
</Td>
|
||||
<Td>{format(new Date(createdAt), "yyyy-MM-dd")}</Td>
|
||||
<Td>
|
||||
<Badge
|
||||
variant={
|
||||
// eslint-disable-next-line no-nested-ternary
|
||||
identityProjectId
|
||||
? "project"
|
||||
: isSubOrganization && currentOrg.id === identityOrgId
|
||||
? "sub-org"
|
||||
: "org"
|
||||
}
|
||||
>
|
||||
{/* eslint-disable-next-line no-nested-ternary */}
|
||||
{identityProjectId ? (
|
||||
<>
|
||||
<ProjectIcon />
|
||||
Project
|
||||
</>
|
||||
) : isSubOrganization && currentOrg.id === identityOrgId ? (
|
||||
<>
|
||||
<SubOrgIcon />
|
||||
Sub-Organization
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<OrgIcon />
|
||||
Organization
|
||||
</>
|
||||
)}
|
||||
</Badge>
|
||||
</Td>
|
||||
<Td className="flex justify-end space-x-2">
|
||||
<Tooltip className="max-w-sm text-center" content="Options">
|
||||
<DropdownMenu>
|
||||
@@ -369,11 +447,12 @@ export const IdentityTab = withProjectPermission(
|
||||
evt.preventDefault();
|
||||
handlePopUpOpen("deleteIdentity", {
|
||||
identityId: id,
|
||||
name
|
||||
name,
|
||||
isProjectIdentity: Boolean(identityProjectId)
|
||||
});
|
||||
}}
|
||||
>
|
||||
Remove Identity From Project
|
||||
{identityProjectId ? "Delete Identity" : "Remove From Project"}
|
||||
</DropdownMenuItem>
|
||||
)}
|
||||
</ProjectPermissionCan>
|
||||
@@ -384,6 +463,20 @@ export const IdentityTab = withProjectPermission(
|
||||
</Tr>
|
||||
);
|
||||
})}
|
||||
{!isPending &&
|
||||
data &&
|
||||
data?.totalCount !== 0 &&
|
||||
Array.from(Array(noAccessIdentityCount)).map((_e, i) => (
|
||||
<Tr key={`hid-identity-${i + 1}`}>
|
||||
<Td>No Access</Td>
|
||||
<Td colSpan={3}>
|
||||
<Blur
|
||||
className="w-min"
|
||||
tooltipText="You do not have permission to read this identity."
|
||||
/>
|
||||
</Td>
|
||||
</Tr>
|
||||
))}
|
||||
</TBody>
|
||||
</Table>
|
||||
{!isPending && data && totalCount > 0 && (
|
||||
@@ -395,18 +488,113 @@ export const IdentityTab = withProjectPermission(
|
||||
onChangePerPage={handlePerPageChange}
|
||||
/>
|
||||
)}
|
||||
{!isPending && data && data?.identityMemberships.length === 0 && (
|
||||
<EmptyState
|
||||
title={
|
||||
debouncedSearch.trim().length > 0
|
||||
? "No identities match search filter"
|
||||
: "No identities have been added to this project"
|
||||
}
|
||||
icon={faServer}
|
||||
/>
|
||||
)}
|
||||
{!isPending &&
|
||||
data &&
|
||||
data?.identityMemberships.length === 0 &&
|
||||
data?.totalCount === 0 && (
|
||||
<EmptyState
|
||||
title={
|
||||
debouncedSearch.trim().length > 0
|
||||
? "No identities match search filter"
|
||||
: "No identities have been added to this project"
|
||||
}
|
||||
icon={faServer}
|
||||
/>
|
||||
)}
|
||||
</TableContainer>
|
||||
<IdentityModal popUp={popUp} handlePopUpToggle={handlePopUpToggle} />
|
||||
<Modal
|
||||
isOpen={popUp.createIdentity.isOpen}
|
||||
onOpenChange={(open) => {
|
||||
handlePopUpToggle("createIdentity", open);
|
||||
if (!open) setWizardStep(WizardSteps.SelectAction);
|
||||
}}
|
||||
>
|
||||
<ModalContent
|
||||
bodyClassName="overflow-visible"
|
||||
title="Add Project Identity"
|
||||
subTitle="Create a new identity or assign an existing identity"
|
||||
>
|
||||
<AnimatePresence mode="wait">
|
||||
{wizardStep === WizardSteps.SelectAction && (
|
||||
<motion.div
|
||||
key="select-type-step"
|
||||
transition={{ duration: 0.1 }}
|
||||
initial={{ opacity: 0, translateX: 30 }}
|
||||
animate={{ opacity: 1, translateX: 0 }}
|
||||
exit={{ opacity: 0, translateX: -30 }}
|
||||
>
|
||||
<div
|
||||
className="cursor-pointer rounded-md border border-mineshaft-600 p-4 transition-all hover:bg-mineshaft-700"
|
||||
role="button"
|
||||
tabIndex={0}
|
||||
onClick={() => setWizardStep(WizardSteps.ProjectIdentity)}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === "Enter") {
|
||||
setWizardStep(WizardSteps.ProjectIdentity);
|
||||
}
|
||||
}}
|
||||
>
|
||||
<div className="flex items-center gap-2">
|
||||
<PlusIcon size="1rem" />
|
||||
<div>Create New Identity</div>
|
||||
</div>
|
||||
<div className="mt-2 text-xs text-mineshaft-300">
|
||||
Create a new machine identity specifically for this project. This identity
|
||||
will be managed at the project-level.
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
className="mt-4 cursor-pointer rounded-md border border-mineshaft-600 p-4 transition-all hover:bg-mineshaft-700"
|
||||
role="button"
|
||||
tabIndex={0}
|
||||
onClick={() => setWizardStep(WizardSteps.LinkIdentity)}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === "Enter") {
|
||||
setWizardStep(WizardSteps.LinkIdentity);
|
||||
}
|
||||
}}
|
||||
>
|
||||
<div className="flex items-center gap-2">
|
||||
<LinkIcon size="1rem" />
|
||||
<div>Assign Existing Identity</div>
|
||||
</div>
|
||||
<div className="mt-2 text-xs text-mineshaft-300">
|
||||
Assign an existing identity from your organization. The identity will continue
|
||||
to be managed at its original scope.
|
||||
</div>
|
||||
</div>
|
||||
</motion.div>
|
||||
)}
|
||||
{wizardStep === WizardSteps.ProjectIdentity && (
|
||||
<motion.div
|
||||
key="identity-step"
|
||||
transition={{ duration: 0.1 }}
|
||||
initial={{ opacity: 0, translateX: 30 }}
|
||||
animate={{ opacity: 1, translateX: 0 }}
|
||||
exit={{ opacity: 0, translateX: -30 }}
|
||||
>
|
||||
<ProjectIdentityModal
|
||||
onClose={() => {
|
||||
handlePopUpClose("createIdentity");
|
||||
setWizardStep(WizardSteps.SelectAction);
|
||||
}}
|
||||
/>
|
||||
</motion.div>
|
||||
)}
|
||||
{wizardStep === WizardSteps.LinkIdentity && (
|
||||
<motion.div
|
||||
key="link-step"
|
||||
transition={{ duration: 0.1 }}
|
||||
initial={{ opacity: 0, translateX: 30 }}
|
||||
animate={{ opacity: 1, translateX: 0 }}
|
||||
exit={{ opacity: 0, translateX: -30 }}
|
||||
>
|
||||
<ProjectLinkIdentityModal handlePopUpToggle={handlePopUpToggle} />
|
||||
</motion.div>
|
||||
)}
|
||||
</AnimatePresence>
|
||||
</ModalContent>
|
||||
</Modal>
|
||||
<DeleteActionModal
|
||||
isOpen={popUp.deleteIdentity.isOpen}
|
||||
title={`Are you sure you want to remove ${
|
||||
@@ -416,7 +604,8 @@ export const IdentityTab = withProjectPermission(
|
||||
deleteKey="confirm"
|
||||
onDeleteApproved={() =>
|
||||
onRemoveIdentitySubmit(
|
||||
(popUp?.deleteIdentity?.data as { identityId: string })?.identityId
|
||||
popUp?.deleteIdentity?.data?.identityId,
|
||||
popUp?.deleteIdentity?.data?.isProjectIdentity
|
||||
)
|
||||
}
|
||||
/>
|
||||
|
||||
-228
@@ -1,228 +0,0 @@
|
||||
import { useMemo } from "react";
|
||||
import { Controller, useForm } from "react-hook-form";
|
||||
import { components, OptionProps } from "react-select";
|
||||
import { faCheckCircle } from "@fortawesome/free-regular-svg-icons";
|
||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||
import { zodResolver } from "@hookform/resolvers/zod";
|
||||
import { Link } from "@tanstack/react-router";
|
||||
import { z } from "zod";
|
||||
|
||||
import { createNotification } from "@app/components/notifications";
|
||||
import {
|
||||
Button,
|
||||
FilterableSelect,
|
||||
FormControl,
|
||||
Modal,
|
||||
ModalClose,
|
||||
ModalContent,
|
||||
Spinner
|
||||
} from "@app/components/v2";
|
||||
import { Badge, OrgIcon } from "@app/components/v3";
|
||||
import { useOrganization, useProject } from "@app/context";
|
||||
import {
|
||||
useAddIdentityToWorkspace,
|
||||
useGetIdentityMembershipOrgs,
|
||||
useGetProjectRoles,
|
||||
useGetWorkspaceIdentityMemberships
|
||||
} from "@app/hooks/api";
|
||||
import { UsePopUpState } from "@app/hooks/usePopUp";
|
||||
|
||||
const schema = z.object({
|
||||
identity: z.object({ name: z.string(), id: z.string(), isManagedByRootOrg: z.boolean() }),
|
||||
role: z.object({ name: z.string(), slug: z.string() })
|
||||
});
|
||||
|
||||
export type FormData = z.infer<typeof schema>;
|
||||
|
||||
type Props = {
|
||||
popUp: UsePopUpState<["identity"]>;
|
||||
handlePopUpToggle: (popUpName: keyof UsePopUpState<["identity"]>, state?: boolean) => void;
|
||||
};
|
||||
|
||||
const Option = ({
|
||||
isSelected,
|
||||
children,
|
||||
...props
|
||||
}: OptionProps<{ name: string; id: string; isManagedByRootOrg: boolean }>) => {
|
||||
return (
|
||||
<components.Option isSelected={isSelected} {...props}>
|
||||
<div className="flex flex-row items-center justify-between">
|
||||
<p className="truncate">{children}</p>
|
||||
{props.data.isManagedByRootOrg && (
|
||||
<Badge variant="org" className="ml-auto">
|
||||
<OrgIcon />
|
||||
Organization
|
||||
</Badge>
|
||||
)}
|
||||
{isSelected && (
|
||||
<FontAwesomeIcon className="ml-2 text-primary" icon={faCheckCircle} size="sm" />
|
||||
)}
|
||||
</div>
|
||||
</components.Option>
|
||||
);
|
||||
};
|
||||
|
||||
const Content = ({ popUp, handlePopUpToggle }: Props) => {
|
||||
const { currentOrg } = useOrganization();
|
||||
const { projectId } = useProject();
|
||||
|
||||
const organizationId = currentOrg?.id || "";
|
||||
|
||||
const { data: identityMembershipOrgsData, isPending: isMembershipsLoading } =
|
||||
useGetIdentityMembershipOrgs({
|
||||
organizationId,
|
||||
limit: 20000 // TODO: this is temp to preserve functionality for larger projects, will replace with combobox in separate PR
|
||||
});
|
||||
const identityMembershipOrgs = identityMembershipOrgsData?.identityMemberships;
|
||||
const { data: identityMembershipsData } = useGetWorkspaceIdentityMemberships({
|
||||
projectId,
|
||||
limit: 20000 // TODO: this is temp to preserve functionality for larger projects, will optimize in PR referenced above
|
||||
});
|
||||
const identityMemberships = identityMembershipsData?.identityMemberships;
|
||||
|
||||
const { data: roles, isPending: isRolesLoading } = useGetProjectRoles(projectId);
|
||||
|
||||
const { mutateAsync: addIdentityToWorkspaceMutateAsync } = useAddIdentityToWorkspace();
|
||||
|
||||
const filteredIdentityMembershipOrgs = useMemo(() => {
|
||||
const wsIdentityIds = new Map();
|
||||
|
||||
identityMemberships?.forEach((identityMembership) => {
|
||||
wsIdentityIds.set(identityMembership.identity.id, true);
|
||||
});
|
||||
|
||||
return (identityMembershipOrgs || []).filter(({ identity: i }) => !wsIdentityIds.has(i.id));
|
||||
}, [identityMembershipOrgs, identityMemberships]);
|
||||
|
||||
const {
|
||||
control,
|
||||
handleSubmit,
|
||||
reset,
|
||||
formState: { isSubmitting }
|
||||
} = useForm<FormData>({
|
||||
resolver: zodResolver(schema)
|
||||
});
|
||||
|
||||
const onFormSubmit = async ({ identity, role }: FormData) => {
|
||||
await addIdentityToWorkspaceMutateAsync({
|
||||
projectId,
|
||||
identityId: identity.id,
|
||||
role: role.slug || undefined
|
||||
});
|
||||
|
||||
createNotification({
|
||||
text: "Successfully added identity to project",
|
||||
type: "success"
|
||||
});
|
||||
|
||||
const nextAvailableMembership = filteredIdentityMembershipOrgs.filter(
|
||||
(membership) => membership.identity.id !== identity.id
|
||||
)[0];
|
||||
|
||||
// prevents combobox from displaying previously added identity
|
||||
reset({
|
||||
identity: {
|
||||
name: nextAvailableMembership?.identity.name,
|
||||
id: nextAvailableMembership?.identity.id
|
||||
}
|
||||
});
|
||||
handlePopUpToggle("identity", false);
|
||||
};
|
||||
|
||||
if (isMembershipsLoading || isRolesLoading)
|
||||
return (
|
||||
<div className="flex w-full items-center justify-center py-10">
|
||||
<Spinner className="text-mineshaft-400" />
|
||||
</div>
|
||||
);
|
||||
|
||||
return filteredIdentityMembershipOrgs.length ? (
|
||||
<form onSubmit={handleSubmit(onFormSubmit)}>
|
||||
<Controller
|
||||
control={control}
|
||||
name="identity"
|
||||
render={({ field: { onChange, value }, fieldState: { error } }) => (
|
||||
<FormControl label="Identity" errorText={error?.message} isError={Boolean(error)}>
|
||||
<FilterableSelect
|
||||
value={value}
|
||||
onChange={onChange}
|
||||
placeholder="Select identity..."
|
||||
options={filteredIdentityMembershipOrgs.map((membership) => ({
|
||||
...membership.identity,
|
||||
isManagedByRootOrg: membership.identity.orgId !== currentOrg.id
|
||||
}))}
|
||||
getOptionValue={(option) => option.id}
|
||||
getOptionLabel={(option) => option.name}
|
||||
components={{
|
||||
Option
|
||||
}}
|
||||
/>
|
||||
</FormControl>
|
||||
)}
|
||||
/>
|
||||
<Controller
|
||||
control={control}
|
||||
name="role"
|
||||
render={({ field: { onChange, value }, fieldState: { error } }) => (
|
||||
<FormControl
|
||||
label="Role"
|
||||
errorText={error?.message}
|
||||
isError={Boolean(error)}
|
||||
className="mt-4"
|
||||
>
|
||||
<FilterableSelect
|
||||
value={value}
|
||||
onChange={onChange}
|
||||
options={roles}
|
||||
placeholder="Select role..."
|
||||
getOptionValue={(option) => option.slug}
|
||||
getOptionLabel={(option) => option.name}
|
||||
/>
|
||||
</FormControl>
|
||||
)}
|
||||
/>
|
||||
<div className="flex items-center">
|
||||
<Button
|
||||
className="mr-4"
|
||||
size="sm"
|
||||
type="submit"
|
||||
isLoading={isSubmitting}
|
||||
isDisabled={isSubmitting}
|
||||
>
|
||||
{popUp?.identity?.data ? "Update" : "Add"}
|
||||
</Button>
|
||||
<ModalClose asChild>
|
||||
<Button colorSchema="secondary" variant="plain">
|
||||
Cancel
|
||||
</Button>
|
||||
</ModalClose>
|
||||
</div>
|
||||
</form>
|
||||
) : (
|
||||
<div className="flex flex-col space-y-4">
|
||||
<div className="text-sm">
|
||||
All identities in your organization have already been added to this project.
|
||||
</div>
|
||||
<Link to={"/organization/access-management" as const}>
|
||||
<Button isDisabled={isRolesLoading} isLoading={isRolesLoading} variant="outline_bg">
|
||||
Create a new identity
|
||||
</Button>
|
||||
</Link>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export const IdentityModal = ({ popUp, handlePopUpToggle }: Props) => {
|
||||
return (
|
||||
<Modal
|
||||
isOpen={popUp?.identity?.isOpen}
|
||||
onOpenChange={(isOpen) => {
|
||||
handlePopUpToggle("identity", isOpen);
|
||||
}}
|
||||
>
|
||||
<ModalContent title="Add Identity to Project" bodyClassName="overflow-visible">
|
||||
<Content popUp={popUp} handlePopUpToggle={handlePopUpToggle} />
|
||||
</ModalContent>
|
||||
</Modal>
|
||||
);
|
||||
};
|
||||
+292
@@ -0,0 +1,292 @@
|
||||
import { Controller, useFieldArray, useForm } from "react-hook-form";
|
||||
import { faPlus, faTrash } from "@fortawesome/free-solid-svg-icons";
|
||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||
import { zodResolver } from "@hookform/resolvers/zod";
|
||||
import { useNavigate } from "@tanstack/react-router";
|
||||
import { z } from "zod";
|
||||
|
||||
import { createNotification } from "@app/components/notifications";
|
||||
import {
|
||||
Button,
|
||||
FilterableSelect,
|
||||
FormControl,
|
||||
FormLabel,
|
||||
IconButton,
|
||||
Input,
|
||||
ModalClose,
|
||||
Switch
|
||||
} from "@app/components/v2";
|
||||
import { useProject } from "@app/context";
|
||||
import { getProjectBaseURL } from "@app/helpers/project";
|
||||
import {
|
||||
TProjectIdentity,
|
||||
useCreateProjectIdentity,
|
||||
useGetProjectRoles,
|
||||
useUpdateProjectIdentity,
|
||||
useUpdateProjectIdentityMembership
|
||||
} from "@app/hooks/api";
|
||||
import { useAddIdentityUniversalAuth } from "@app/hooks/api/identities";
|
||||
import { ProjectMembershipRole } from "@app/hooks/api/roles/types";
|
||||
|
||||
const schema = z.object({
|
||||
name: z.string().min(1, "Required"),
|
||||
hasDeleteProtection: z.boolean(),
|
||||
role: z.object({ slug: z.string(), name: z.string() }).optional(),
|
||||
metadata: z
|
||||
.object({
|
||||
key: z.string().trim().min(1),
|
||||
value: z.string().trim().min(1)
|
||||
})
|
||||
.array()
|
||||
.default([])
|
||||
.optional()
|
||||
});
|
||||
export type FormData = z.infer<typeof schema>;
|
||||
|
||||
type ContentProps = {
|
||||
onClose: () => void;
|
||||
identity?: TProjectIdentity;
|
||||
};
|
||||
|
||||
export const ProjectIdentityModal = ({ onClose, identity }: ContentProps) => {
|
||||
const navigate = useNavigate();
|
||||
|
||||
const { currentProject } = useProject();
|
||||
|
||||
const isUpdate = Boolean(identity);
|
||||
|
||||
const { data: roles } = useGetProjectRoles(currentProject.id);
|
||||
|
||||
const { mutateAsync: createMutateAsync } = useCreateProjectIdentity();
|
||||
const { mutateAsync: updateMutateAsync } = useUpdateProjectIdentity();
|
||||
const { mutateAsync: addMutateAsync } = useAddIdentityUniversalAuth();
|
||||
const { mutateAsync: updateMembershipMutateAsync } = useUpdateProjectIdentityMembership();
|
||||
|
||||
const {
|
||||
control,
|
||||
handleSubmit,
|
||||
reset,
|
||||
formState: { isSubmitting }
|
||||
} = useForm<FormData>({
|
||||
resolver: zodResolver(schema),
|
||||
defaultValues: {
|
||||
name: identity?.name ?? "",
|
||||
hasDeleteProtection: identity?.hasDeleteProtection ?? false,
|
||||
metadata: identity?.metadata ?? [],
|
||||
role: isUpdate ? undefined : { slug: ProjectMembershipRole.NoAccess, name: "No Access" }
|
||||
}
|
||||
});
|
||||
|
||||
const metadataFormFields = useFieldArray({
|
||||
control,
|
||||
name: "metadata"
|
||||
});
|
||||
|
||||
const onFormSubmit = async ({ name, role, metadata, hasDeleteProtection }: FormData) => {
|
||||
try {
|
||||
if (identity) {
|
||||
// update
|
||||
await updateMutateAsync({
|
||||
identityId: identity.id,
|
||||
name,
|
||||
hasDeleteProtection,
|
||||
projectId: currentProject.id,
|
||||
metadata
|
||||
});
|
||||
|
||||
onClose();
|
||||
} else {
|
||||
// create
|
||||
|
||||
const { id: createdId } = await createMutateAsync({
|
||||
name,
|
||||
projectId: currentProject.id,
|
||||
hasDeleteProtection,
|
||||
metadata
|
||||
});
|
||||
|
||||
if (role) {
|
||||
await updateMembershipMutateAsync({
|
||||
roles: [{ role: role.slug }],
|
||||
identityId: createdId,
|
||||
projectId: currentProject.id
|
||||
});
|
||||
}
|
||||
|
||||
await addMutateAsync({
|
||||
projectId: currentProject.id,
|
||||
identityId: createdId,
|
||||
clientSecretTrustedIps: [{ ipAddress: "0.0.0.0/0" }, { ipAddress: "::/0" }],
|
||||
accessTokenTrustedIps: [{ ipAddress: "0.0.0.0/0" }, { ipAddress: "::/0" }],
|
||||
accessTokenTTL: 2592000,
|
||||
accessTokenMaxTTL: 2592000,
|
||||
accessTokenNumUsesLimit: 0,
|
||||
accessTokenPeriod: 0,
|
||||
lockoutEnabled: true,
|
||||
lockoutThreshold: 3,
|
||||
lockoutDurationSeconds: 300,
|
||||
lockoutCounterResetSeconds: 30
|
||||
});
|
||||
|
||||
onClose();
|
||||
navigate({
|
||||
to: `${getProjectBaseURL(currentProject.type)}/identities/$identityId`,
|
||||
params: {
|
||||
identityId: createdId
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
createNotification({
|
||||
text: `Successfully ${isUpdate ? "updated" : "created"} project identity`,
|
||||
type: "success"
|
||||
});
|
||||
|
||||
reset();
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
const error = err as any;
|
||||
const text =
|
||||
error?.response?.data?.message ??
|
||||
`Failed to ${isUpdate ? "update" : "create"} project identity`;
|
||||
|
||||
createNotification({
|
||||
text,
|
||||
type: "error"
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<form onSubmit={handleSubmit(onFormSubmit)}>
|
||||
<Controller
|
||||
control={control}
|
||||
defaultValue=""
|
||||
name="name"
|
||||
render={({ field, fieldState: { error } }) => (
|
||||
<FormControl
|
||||
className="mb-4"
|
||||
label="Name"
|
||||
isError={Boolean(error)}
|
||||
errorText={error?.message}
|
||||
>
|
||||
<Input {...field} placeholder="Machine 1" />
|
||||
</FormControl>
|
||||
)}
|
||||
/>
|
||||
{!isUpdate && (
|
||||
<Controller
|
||||
control={control}
|
||||
name="role"
|
||||
render={({ field: { onChange, value }, fieldState: { error } }) => (
|
||||
<FormControl label="Role" errorText={error?.message} isError={Boolean(error)}>
|
||||
<FilterableSelect
|
||||
placeholder="Select role..."
|
||||
options={roles}
|
||||
onChange={onChange}
|
||||
value={value}
|
||||
getOptionValue={(option) => option.slug}
|
||||
getOptionLabel={(option) => option.name}
|
||||
/>
|
||||
</FormControl>
|
||||
)}
|
||||
/>
|
||||
)}
|
||||
<Controller
|
||||
control={control}
|
||||
name="hasDeleteProtection"
|
||||
render={({ field: { onChange, value }, fieldState: { error } }) => (
|
||||
<FormControl errorText={error?.message} isError={Boolean(error)}>
|
||||
<Switch
|
||||
className="mr-2 ml-0 bg-mineshaft-400/80 shadow-inner data-[state=checked]:bg-green/80"
|
||||
containerClassName="flex-row-reverse w-fit"
|
||||
id="delete-protection-enabled"
|
||||
thumbClassName="bg-mineshaft-800"
|
||||
onCheckedChange={onChange}
|
||||
isChecked={value}
|
||||
>
|
||||
<p>Delete Protection {value ? "Enabled" : "Disabled"}</p>
|
||||
</Switch>
|
||||
</FormControl>
|
||||
)}
|
||||
/>
|
||||
<div>
|
||||
<FormLabel label="Metadata" />
|
||||
</div>
|
||||
<div className="mb-3 flex flex-col space-y-2">
|
||||
{metadataFormFields.fields.map(({ id: metadataFieldId }, i) => (
|
||||
<div key={metadataFieldId} className="flex items-end space-x-2">
|
||||
<div className="grow">
|
||||
{i === 0 && <span className="text-xs text-mineshaft-400">Key</span>}
|
||||
<Controller
|
||||
control={control}
|
||||
name={`metadata.${i}.key`}
|
||||
render={({ field, fieldState: { error } }) => (
|
||||
<FormControl
|
||||
isError={Boolean(error?.message)}
|
||||
errorText={error?.message}
|
||||
className="mb-0"
|
||||
>
|
||||
<Input {...field} />
|
||||
</FormControl>
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
<div className="grow">
|
||||
{i === 0 && (
|
||||
<FormLabel label="Value" className="text-xs text-mineshaft-400" isOptional />
|
||||
)}
|
||||
<Controller
|
||||
control={control}
|
||||
name={`metadata.${i}.value`}
|
||||
render={({ field, fieldState: { error } }) => (
|
||||
<FormControl
|
||||
isError={Boolean(error?.message)}
|
||||
errorText={error?.message}
|
||||
className="mb-0"
|
||||
>
|
||||
<Input {...field} />
|
||||
</FormControl>
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
<IconButton
|
||||
ariaLabel="delete key"
|
||||
className="bottom-0.5 h-9"
|
||||
variant="outline_bg"
|
||||
onClick={() => metadataFormFields.remove(i)}
|
||||
>
|
||||
<FontAwesomeIcon icon={faTrash} />
|
||||
</IconButton>
|
||||
</div>
|
||||
))}
|
||||
<div className="mt-2 flex justify-end">
|
||||
<Button
|
||||
leftIcon={<FontAwesomeIcon icon={faPlus} />}
|
||||
size="xs"
|
||||
variant="outline_bg"
|
||||
onClick={() => metadataFormFields.append({ key: "", value: "" })}
|
||||
>
|
||||
Add Key
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex items-center">
|
||||
<Button
|
||||
className="mr-4"
|
||||
size="sm"
|
||||
type="submit"
|
||||
isLoading={isSubmitting}
|
||||
isDisabled={isSubmitting}
|
||||
>
|
||||
{isUpdate ? "Update" : "Create"}
|
||||
</Button>
|
||||
<ModalClose asChild>
|
||||
<Button colorSchema="secondary" variant="plain">
|
||||
Cancel
|
||||
</Button>
|
||||
</ModalClose>
|
||||
</div>
|
||||
</form>
|
||||
);
|
||||
};
|
||||
+172
@@ -0,0 +1,172 @@
|
||||
import { useMemo } from "react";
|
||||
import { Controller, useForm } from "react-hook-form";
|
||||
import { zodResolver } from "@hookform/resolvers/zod";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { z } from "zod";
|
||||
|
||||
import { createNotification } from "@app/components/notifications";
|
||||
import { Button, FilterableSelect, FormControl, ModalClose, Spinner } from "@app/components/v2";
|
||||
import { useProject } from "@app/context";
|
||||
import {
|
||||
projectIdentityMembershipQuery,
|
||||
useCreateProjectIdentityMembership,
|
||||
useGetProjectRoles,
|
||||
useListProjectIdentityMemberships
|
||||
} from "@app/hooks/api";
|
||||
import { UsePopUpState } from "@app/hooks/usePopUp";
|
||||
|
||||
const schema = z.object({
|
||||
identity: z.object({
|
||||
name: z.string(),
|
||||
id: z.string()
|
||||
}),
|
||||
role: z.object({ name: z.string(), slug: z.string() })
|
||||
});
|
||||
|
||||
export type FormData = z.infer<typeof schema>;
|
||||
|
||||
type Props = {
|
||||
handlePopUpToggle: (popUpName: keyof UsePopUpState<["createIdentity"]>, state?: boolean) => void;
|
||||
};
|
||||
|
||||
export const ProjectLinkIdentityModal = ({ handlePopUpToggle }: Props) => {
|
||||
const { projectId } = useProject();
|
||||
|
||||
// const [searchValue, setSearchValue] = useState("");
|
||||
|
||||
// const [debouncedSearchValue] = useDebounce(searchValue);
|
||||
|
||||
// TODO: name search needs to be implemented on the backend
|
||||
const { data: identityMembershipOrgs, isPending: isMembershipsLoading } = useQuery({
|
||||
...projectIdentityMembershipQuery.listAvailable({
|
||||
projectId
|
||||
// identityName: debouncedSearchValue
|
||||
}),
|
||||
placeholderData: (prev) => prev
|
||||
});
|
||||
|
||||
const { data: identityMembershipsData } = useListProjectIdentityMemberships({
|
||||
projectId,
|
||||
limit: 1000 // TODO: this is temp to preserve functionality for larger projects, will optimize in PR referenced above
|
||||
});
|
||||
const identityMemberships = identityMembershipsData?.identityMemberships;
|
||||
|
||||
const { data: roles, isPending: isRolesLoading } = useGetProjectRoles(projectId);
|
||||
|
||||
const { mutateAsync: createProjectIdentityMembershipMutateAsync } =
|
||||
useCreateProjectIdentityMembership();
|
||||
|
||||
const filteredIdentityMembershipOrgs = useMemo(() => {
|
||||
const wsIdentityIds = new Map();
|
||||
|
||||
identityMemberships?.forEach((identityMembership) => {
|
||||
wsIdentityIds.set(identityMembership.identity.id, true);
|
||||
});
|
||||
|
||||
return (identityMembershipOrgs || []).filter((i) => !wsIdentityIds.has(i.id));
|
||||
}, [identityMembershipOrgs, identityMemberships]);
|
||||
|
||||
const {
|
||||
control,
|
||||
handleSubmit,
|
||||
reset,
|
||||
formState: { isSubmitting }
|
||||
} = useForm<FormData>({
|
||||
resolver: zodResolver(schema)
|
||||
});
|
||||
|
||||
const onFormSubmit = async ({ identity, role }: FormData) => {
|
||||
await createProjectIdentityMembershipMutateAsync({
|
||||
projectId,
|
||||
identityId: identity.id,
|
||||
role: role.slug || undefined
|
||||
});
|
||||
|
||||
createNotification({
|
||||
text: "Successfully added identity to project",
|
||||
type: "success"
|
||||
});
|
||||
|
||||
const nextAvailableMembership = filteredIdentityMembershipOrgs.filter(
|
||||
(membership) => membership.id !== identity.id
|
||||
)[0];
|
||||
|
||||
// prevents combobox from displaying previously added identity
|
||||
reset({
|
||||
identity: {
|
||||
name: nextAvailableMembership?.name,
|
||||
id: nextAvailableMembership?.id
|
||||
}
|
||||
});
|
||||
handlePopUpToggle("createIdentity", false);
|
||||
};
|
||||
|
||||
if (isMembershipsLoading || isRolesLoading)
|
||||
return (
|
||||
<div className="flex w-full items-center justify-center py-10">
|
||||
<Spinner className="text-mineshaft-400" />
|
||||
</div>
|
||||
);
|
||||
|
||||
return (
|
||||
<form onSubmit={handleSubmit(onFormSubmit)}>
|
||||
<Controller
|
||||
control={control}
|
||||
name="identity"
|
||||
render={({ field: { onChange, value }, fieldState: { error } }) => (
|
||||
<FormControl label="Identity" errorText={error?.message} isError={Boolean(error)}>
|
||||
<FilterableSelect
|
||||
value={value}
|
||||
onChange={onChange}
|
||||
placeholder="Select identity..."
|
||||
// onInputChange={setSearchValue}
|
||||
options={filteredIdentityMembershipOrgs.map((membership) => ({
|
||||
name: membership.name,
|
||||
id: membership.id
|
||||
}))}
|
||||
getOptionValue={(option) => option.id}
|
||||
getOptionLabel={(option) => option.name}
|
||||
/>
|
||||
</FormControl>
|
||||
)}
|
||||
/>
|
||||
<Controller
|
||||
control={control}
|
||||
name="role"
|
||||
render={({ field: { onChange, value }, fieldState: { error } }) => (
|
||||
<FormControl
|
||||
label="Role"
|
||||
errorText={error?.message}
|
||||
isError={Boolean(error)}
|
||||
className="mt-4"
|
||||
>
|
||||
<FilterableSelect
|
||||
value={value}
|
||||
onChange={onChange}
|
||||
options={roles}
|
||||
placeholder="Select role..."
|
||||
getOptionValue={(option) => option.slug}
|
||||
getOptionLabel={(option) => option.name}
|
||||
/>
|
||||
</FormControl>
|
||||
)}
|
||||
/>
|
||||
<div className="flex items-center">
|
||||
<Button
|
||||
className="mr-4"
|
||||
size="sm"
|
||||
type="submit"
|
||||
isLoading={isSubmitting}
|
||||
isDisabled={isSubmitting}
|
||||
>
|
||||
Link
|
||||
</Button>
|
||||
<ModalClose asChild>
|
||||
<Button colorSchema="secondary" variant="plain">
|
||||
Cancel
|
||||
</Button>
|
||||
</ModalClose>
|
||||
</div>
|
||||
</form>
|
||||
);
|
||||
};
|
||||
+3
-2
@@ -24,7 +24,7 @@ import {
|
||||
THead,
|
||||
Tr
|
||||
} from "@app/components/v2";
|
||||
import { useProject } from "@app/context";
|
||||
import { useOrganization, useProject } from "@app/context";
|
||||
import { getProjectHomePage } from "@app/helpers/project";
|
||||
import {
|
||||
getUserTablePreference,
|
||||
@@ -86,6 +86,7 @@ export const GroupMembersTable = ({ groupMembership }: Props) => {
|
||||
setUserTablePreference("projectGroupMembersTable", PreferenceKey.PerPage, newPerPage);
|
||||
};
|
||||
|
||||
const { isSubOrganization, currentOrg } = useOrganization();
|
||||
const { currentProject } = useProject();
|
||||
|
||||
const { data: groupMemberships, isPending } = useListProjectGroupUsers({
|
||||
@@ -153,7 +154,7 @@ export const GroupMembersTable = ({ groupMembership }: Props) => {
|
||||
text: "User privilege assumption has started"
|
||||
});
|
||||
|
||||
const url = getProjectHomePage(currentProject.type, currentProject.environments);
|
||||
const url = `${getProjectHomePage(currentProject.type, currentProject.environments)}${isSubOrganization ? `?subOrganization=${currentOrg.slug}` : ""}`;
|
||||
window.location.href = url.replace("$projectId", currentProject.id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,12 +3,15 @@ import { useTranslation } from "react-i18next";
|
||||
import { subject } from "@casl/ability";
|
||||
import { faChevronLeft } from "@fortawesome/free-solid-svg-icons";
|
||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { Link, useNavigate, useParams } from "@tanstack/react-router";
|
||||
import { formatRelative } from "date-fns";
|
||||
|
||||
import { createNotification } from "@app/components/notifications";
|
||||
import { ProjectPermissionCan } from "@app/components/permissions";
|
||||
import { OrgPermissionCan, ProjectPermissionCan } from "@app/components/permissions";
|
||||
import {
|
||||
Alert,
|
||||
AlertDescription,
|
||||
Button,
|
||||
ConfirmActionModal,
|
||||
DeleteActionModal,
|
||||
@@ -17,19 +20,25 @@ import {
|
||||
Spinner
|
||||
} from "@app/components/v2";
|
||||
import {
|
||||
OrgPermissionIdentityActions,
|
||||
OrgPermissionSubjects,
|
||||
ProjectPermissionActions,
|
||||
ProjectPermissionIdentityActions,
|
||||
ProjectPermissionSub,
|
||||
useOrganization,
|
||||
useProject
|
||||
} from "@app/context";
|
||||
import { getProjectBaseURL, getProjectHomePage } from "@app/helpers/project";
|
||||
import { usePopUp } from "@app/hooks";
|
||||
import {
|
||||
useAssumeProjectPrivileges,
|
||||
useDeleteIdentityFromWorkspace,
|
||||
useGetWorkspaceIdentityMembershipDetails
|
||||
useDeleteProjectIdentityMembership,
|
||||
useGetProjectIdentityMembershipV2
|
||||
} from "@app/hooks/api";
|
||||
import { ActorType } from "@app/hooks/api/auditLogs/enums";
|
||||
import { projectIdentityQuery } from "@app/hooks/api/projectIdentity";
|
||||
import { ProjectIdentityAuthenticationSection } from "@app/pages/project/IdentityDetailsByIDPage/components/ProjectIdentityAuthSection";
|
||||
import { ProjectIdentityDetailsSection } from "@app/pages/project/IdentityDetailsByIDPage/components/ProjectIdentityDetailsSection";
|
||||
import { ProjectAccessControlTabs } from "@app/types/project";
|
||||
|
||||
import { IdentityProjectAdditionalPrivilegeSection } from "./components/IdentityProjectAdditionalPrivilegeSection";
|
||||
@@ -42,12 +51,29 @@ const Page = () => {
|
||||
select: (el) => el.identityId as string
|
||||
});
|
||||
const { currentProject, projectId } = useProject();
|
||||
const { currentOrg, isSubOrganization } = useOrganization();
|
||||
|
||||
const { data: identityMembershipDetails, isPending: isMembershipDetailsLoading } =
|
||||
useGetWorkspaceIdentityMembershipDetails(projectId, identityId);
|
||||
useGetProjectIdentityMembershipV2(projectId, identityId);
|
||||
|
||||
const { mutateAsync: deleteMutateAsync, isPending: isDeletingIdentity } =
|
||||
useDeleteIdentityFromWorkspace();
|
||||
useDeleteProjectIdentityMembership();
|
||||
|
||||
const isProjectIdentity = Boolean(identityMembershipDetails?.identity.projectId);
|
||||
const isNonScopedIdentity =
|
||||
!isProjectIdentity && currentOrg.id !== identityMembershipDetails?.identity?.orgId;
|
||||
|
||||
const {
|
||||
data: identity,
|
||||
isPending: isProjectIdentityPending,
|
||||
refetch: refetchIdentity
|
||||
} = useQuery({
|
||||
...projectIdentityQuery.getById({
|
||||
identityId: identityMembershipDetails?.identity.id as string,
|
||||
projectId: identityMembershipDetails?.identity.projectId as string
|
||||
}),
|
||||
enabled: isProjectIdentity
|
||||
});
|
||||
|
||||
const { popUp, handlePopUpOpen, handlePopUpClose, handlePopUpToggle } = usePopUp([
|
||||
"deleteIdentity",
|
||||
@@ -68,7 +94,7 @@ const Page = () => {
|
||||
type: "success",
|
||||
text: "Identity privilege assumption has started"
|
||||
});
|
||||
const url = getProjectHomePage(currentProject.type, currentProject.environments);
|
||||
const url = `${getProjectHomePage(currentProject.type, currentProject.environments)}${isSubOrganization && isNonScopedIdentity ? `?subOrganization=${currentOrg.slug}` : ""}`;
|
||||
window.location.href = url.replace("$projectId", currentProject.id);
|
||||
}
|
||||
}
|
||||
@@ -96,7 +122,7 @@ const Page = () => {
|
||||
});
|
||||
};
|
||||
|
||||
if (isMembershipDetailsLoading) {
|
||||
if (isMembershipDetailsLoading || (isProjectIdentity && isProjectIdentityPending)) {
|
||||
return (
|
||||
<div className="flex w-full items-center justify-center p-24">
|
||||
<Spinner />
|
||||
@@ -124,7 +150,8 @@ const Page = () => {
|
||||
<PageHeader
|
||||
scope={currentProject.type}
|
||||
title={identityMembershipDetails?.identity?.name}
|
||||
description={`Identity joined on ${identityMembershipDetails?.createdAt && formatRelative(new Date(identityMembershipDetails?.createdAt || ""), new Date())}`}
|
||||
description={`Identity ${isProjectIdentity ? "created" : "added"} on ${identityMembershipDetails?.createdAt && formatRelative(new Date(identityMembershipDetails?.createdAt || ""), new Date())}`}
|
||||
className={!isProjectIdentity ? "mb-4" : undefined}
|
||||
>
|
||||
<div className="flex items-center gap-2">
|
||||
<Button
|
||||
@@ -142,7 +169,9 @@ const Page = () => {
|
||||
</Button>
|
||||
<ProjectPermissionCan
|
||||
I={ProjectPermissionIdentityActions.AssumePrivileges}
|
||||
a={ProjectPermissionSub.Identity}
|
||||
a={subject(ProjectPermissionSub.Identity, {
|
||||
identityId: identityMembershipDetails?.identity.id
|
||||
})}
|
||||
renderTooltip
|
||||
allowedLabel="Assume privileges of the user"
|
||||
passThrough={false}
|
||||
@@ -158,36 +187,90 @@ const Page = () => {
|
||||
</Button>
|
||||
)}
|
||||
</ProjectPermissionCan>
|
||||
<ProjectPermissionCan
|
||||
I={ProjectPermissionActions.Delete}
|
||||
a={subject(ProjectPermissionSub.Identity, {
|
||||
identityId: identityMembershipDetails?.identity?.id
|
||||
})}
|
||||
renderTooltip
|
||||
allowedLabel="Remove from project"
|
||||
>
|
||||
{(isAllowed) => (
|
||||
<Button
|
||||
colorSchema="danger"
|
||||
variant="outline_bg"
|
||||
size="xs"
|
||||
isDisabled={!isAllowed}
|
||||
isLoading={isDeletingIdentity}
|
||||
onClick={() => handlePopUpOpen("deleteIdentity")}
|
||||
>
|
||||
Remove Identity
|
||||
</Button>
|
||||
)}
|
||||
</ProjectPermissionCan>
|
||||
{!isProjectIdentity && (
|
||||
<ProjectPermissionCan
|
||||
I={ProjectPermissionActions.Delete}
|
||||
a={subject(ProjectPermissionSub.Identity, {
|
||||
identityId: identityMembershipDetails?.identity?.id
|
||||
})}
|
||||
renderTooltip
|
||||
allowedLabel="Remove from project"
|
||||
>
|
||||
{(isAllowed) => (
|
||||
<Button
|
||||
colorSchema="danger"
|
||||
variant="outline_bg"
|
||||
size="xs"
|
||||
isDisabled={!isAllowed}
|
||||
isLoading={isDeletingIdentity}
|
||||
onClick={() => handlePopUpOpen("deleteIdentity")}
|
||||
>
|
||||
Remove Identity
|
||||
</Button>
|
||||
)}
|
||||
</ProjectPermissionCan>
|
||||
)}
|
||||
</div>
|
||||
</PageHeader>
|
||||
<IdentityRoleDetailsSection
|
||||
identityMembershipDetails={identityMembershipDetails}
|
||||
isMembershipDetailsLoading={isMembershipDetailsLoading}
|
||||
/>
|
||||
<IdentityProjectAdditionalPrivilegeSection
|
||||
identityMembershipDetails={identityMembershipDetails}
|
||||
/>
|
||||
{!isProjectIdentity && (
|
||||
<Alert hideTitle iconClassName="text-info" className="mb-4 border-info/50 bg-info/10">
|
||||
<AlertDescription>
|
||||
This identity is managed by your organization.{" "}
|
||||
<OrgPermissionCan
|
||||
I={OrgPermissionIdentityActions.Read}
|
||||
an={OrgPermissionSubjects.Identity}
|
||||
>
|
||||
{(isAllowed) =>
|
||||
isAllowed ? (
|
||||
<Link
|
||||
to="/organization/identities/$identityId"
|
||||
params={{
|
||||
identityId
|
||||
}}
|
||||
>
|
||||
<span className="cursor-pointer text-info underline underline-offset-2">
|
||||
Click here to manage identity.
|
||||
</span>
|
||||
</Link>
|
||||
) : null
|
||||
}
|
||||
</OrgPermissionCan>
|
||||
</AlertDescription>
|
||||
</Alert>
|
||||
)}
|
||||
<div className="flex gap-x-4">
|
||||
{identity ? (
|
||||
<div className="flex w-72 flex-col gap-y-4">
|
||||
<ProjectIdentityDetailsSection
|
||||
identity={identity}
|
||||
membership={identityMembershipDetails!}
|
||||
/>
|
||||
<ProjectIdentityAuthenticationSection
|
||||
identity={identity}
|
||||
refetchIdentity={() => refetchIdentity()}
|
||||
/>
|
||||
</div>
|
||||
) : (
|
||||
<div>
|
||||
<div className="flex w-72 flex-col gap-y-4">
|
||||
<ProjectIdentityDetailsSection
|
||||
identity={{ ...identityMembershipDetails?.identity, projectId: "" }}
|
||||
isOrgIdentity
|
||||
membership={identityMembershipDetails!}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
<div className="flex-1">
|
||||
<IdentityRoleDetailsSection
|
||||
identityMembershipDetails={identityMembershipDetails}
|
||||
isMembershipDetailsLoading={isMembershipDetailsLoading}
|
||||
/>
|
||||
<IdentityProjectAdditionalPrivilegeSection
|
||||
identityMembershipDetails={identityMembershipDetails}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<DeleteActionModal
|
||||
isOpen={popUp.deleteIdentity.isOpen}
|
||||
title={`Are you sure you want to remove ${identityMembershipDetails?.identity?.name} from the project?`}
|
||||
|
||||
+5
-4
@@ -26,17 +26,18 @@ import {
|
||||
ProjectPermissionActions,
|
||||
ProjectPermissionIdentityActions,
|
||||
ProjectPermissionSub,
|
||||
useProject,
|
||||
useProjectPermission
|
||||
} from "@app/context";
|
||||
import { usePopUp } from "@app/hooks";
|
||||
import { useDeleteIdentityProjectAdditionalPrivilege } from "@app/hooks/api";
|
||||
import { IdentityMembership } from "@app/hooks/api/identities/types";
|
||||
import { IdentityProjectMembershipV1 } from "@app/hooks/api/identities/types";
|
||||
import { useListIdentityProjectPrivileges } from "@app/hooks/api/identityProjectAdditionalPrivilege/queries";
|
||||
|
||||
import { IdentityProjectAdditionalPrivilegeModifySection } from "./IdentityProjectAdditionalPrivilegeModifySection";
|
||||
|
||||
type Props = {
|
||||
identityMembershipDetails: IdentityMembership;
|
||||
identityMembershipDetails: IdentityProjectMembershipV1;
|
||||
};
|
||||
|
||||
export const IdentityProjectAdditionalPrivilegeSection = ({ identityMembershipDetails }: Props) => {
|
||||
@@ -46,13 +47,13 @@ export const IdentityProjectAdditionalPrivilegeSection = ({ identityMembershipDe
|
||||
] as const);
|
||||
const { permission } = useProjectPermission();
|
||||
const identityId = identityMembershipDetails?.identity?.id;
|
||||
const projectId = identityMembershipDetails?.project?.id;
|
||||
const { projectId } = useProject();
|
||||
|
||||
const { mutateAsync: deletePrivilege } = useDeleteIdentityProjectAdditionalPrivilege();
|
||||
|
||||
const { data: identityProjectPrivileges, isPending } = useListIdentityProjectPrivileges({
|
||||
identityId: identityMembershipDetails?.identity?.id,
|
||||
projectId: identityMembershipDetails?.project?.id
|
||||
projectId
|
||||
});
|
||||
|
||||
const handlePrivilegeDelete = async () => {
|
||||
|
||||
+5
-5
@@ -26,14 +26,14 @@ import {
|
||||
import { ProjectPermissionActions, ProjectPermissionSub, useProject } from "@app/context";
|
||||
import { formatProjectRoleName } from "@app/helpers/roles";
|
||||
import { usePopUp } from "@app/hooks";
|
||||
import { useUpdateIdentityWorkspaceRole } from "@app/hooks/api";
|
||||
import { IdentityMembership } from "@app/hooks/api/identities/types";
|
||||
import { useUpdateProjectIdentityMembership } from "@app/hooks/api";
|
||||
import { IdentityProjectMembershipV1 } from "@app/hooks/api/identities/types";
|
||||
import { TProjectRole } from "@app/hooks/api/roles/types";
|
||||
|
||||
import { IdentityRoleModify } from "./IdentityRoleModify";
|
||||
|
||||
type Props = {
|
||||
identityMembershipDetails: IdentityMembership;
|
||||
identityMembershipDetails: IdentityProjectMembershipV1;
|
||||
isMembershipDetailsLoading?: boolean;
|
||||
};
|
||||
|
||||
@@ -46,12 +46,12 @@ export const IdentityRoleDetailsSection = ({
|
||||
"deleteRole",
|
||||
"modifyRole"
|
||||
] as const);
|
||||
const { mutateAsync: updateIdentityWorkspaceRole } = useUpdateIdentityWorkspaceRole();
|
||||
const { mutateAsync: updateIdentityProjectMembership } = useUpdateProjectIdentityMembership();
|
||||
|
||||
const handleRoleDelete = async () => {
|
||||
const { id } = popUp?.deleteRole?.data as TProjectRole;
|
||||
const updatedRoles = identityMembershipDetails?.roles?.filter((el) => el.id !== id);
|
||||
await updateIdentityWorkspaceRole({
|
||||
await updateIdentityProjectMembership({
|
||||
projectId: currentProject?.id || "",
|
||||
identityId: identityMembershipDetails.identity.id,
|
||||
roles: updatedRoles.map(
|
||||
|
||||
+8
-8
@@ -32,10 +32,10 @@ import {
|
||||
useProject,
|
||||
useProjectPermission
|
||||
} from "@app/context";
|
||||
import { useGetProjectRoles, useUpdateIdentityWorkspaceRole } from "@app/hooks/api";
|
||||
import { IdentityMembership } from "@app/hooks/api/identities/types";
|
||||
import { ProjectUserMembershipTemporaryMode } from "@app/hooks/api/projects/types";
|
||||
import { useGetProjectRoles, useUpdateProjectIdentityMembership } from "@app/hooks/api";
|
||||
import { IdentityProjectMembershipV1 } from "@app/hooks/api/identities/types";
|
||||
import { ProjectMembershipRole } from "@app/hooks/api/roles/types";
|
||||
import { TemporaryPermissionMode } from "@app/hooks/api/shared";
|
||||
|
||||
const roleFormSchema = z.object({
|
||||
roles: z
|
||||
@@ -58,7 +58,7 @@ const roleFormSchema = z.object({
|
||||
type TRoleForm = z.infer<typeof roleFormSchema>;
|
||||
|
||||
type Props = {
|
||||
identityProjectMembership: IdentityMembership;
|
||||
identityProjectMembership: IdentityProjectMembershipV1;
|
||||
};
|
||||
|
||||
export const IdentityRoleModify = ({ identityProjectMembership }: Props) => {
|
||||
@@ -95,10 +95,10 @@ export const IdentityRoleModify = ({ identityProjectMembership }: Props) => {
|
||||
|
||||
const formRoleField = roleForm.watch("roles");
|
||||
|
||||
const updateIdentityWorkspaceRole = useUpdateIdentityWorkspaceRole();
|
||||
const updateProjectIdentityMembership = useUpdateProjectIdentityMembership();
|
||||
|
||||
const handleRoleUpdate = async (data: TRoleForm) => {
|
||||
if (updateIdentityWorkspaceRole.isPending) return;
|
||||
if (updateProjectIdentityMembership.isPending) return;
|
||||
|
||||
const sanitizedRoles = data.roles.map((el) => {
|
||||
const { isTemporary } = el.temporaryAccess;
|
||||
@@ -108,13 +108,13 @@ export const IdentityRoleModify = ({ identityProjectMembership }: Props) => {
|
||||
return {
|
||||
role: el.slug,
|
||||
isTemporary: true as const,
|
||||
temporaryMode: ProjectUserMembershipTemporaryMode.Relative,
|
||||
temporaryMode: TemporaryPermissionMode.Relative,
|
||||
temporaryRange: el.temporaryAccess.temporaryRange,
|
||||
temporaryAccessStartTime: el.temporaryAccess.temporaryAccessStartTime
|
||||
};
|
||||
});
|
||||
|
||||
await updateIdentityWorkspaceRole.mutateAsync({
|
||||
await updateProjectIdentityMembership.mutateAsync({
|
||||
projectId,
|
||||
identityId: identityProjectMembership.identity.id,
|
||||
roles: sanitizedRoles
|
||||
|
||||
+119
@@ -0,0 +1,119 @@
|
||||
import { subject } from "@casl/ability";
|
||||
import { faPlus } from "@fortawesome/free-solid-svg-icons";
|
||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||
import { LockIcon, SettingsIcon } from "lucide-react";
|
||||
|
||||
import { UpgradePlanModal } from "@app/components/license/UpgradePlanModal";
|
||||
import { ProjectPermissionCan } from "@app/components/permissions";
|
||||
import { Button, Tooltip } from "@app/components/v2";
|
||||
import { Badge } from "@app/components/v3";
|
||||
import { ProjectPermissionIdentityActions, ProjectPermissionSub } from "@app/context";
|
||||
import { IdentityAuthMethod, identityAuthToNameMap, TProjectIdentity } from "@app/hooks/api";
|
||||
import { usePopUp } from "@app/hooks/usePopUp";
|
||||
import { IdentityAuthMethodModal } from "@app/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/IdentityAuthMethodModal";
|
||||
import { ViewIdentityAuthModal } from "@app/pages/organization/IdentityDetailsByIDPage/components/ViewIdentityAuthModal";
|
||||
|
||||
type Props = {
|
||||
identity: TProjectIdentity;
|
||||
refetchIdentity: () => void;
|
||||
};
|
||||
|
||||
export const ProjectIdentityAuthenticationSection = ({ identity, refetchIdentity }: Props) => {
|
||||
const { popUp, handlePopUpToggle, handlePopUpOpen } = usePopUp([
|
||||
"viewAuthMethod",
|
||||
"identityAuthMethod",
|
||||
"upgradePlan"
|
||||
]);
|
||||
|
||||
return (
|
||||
<div className="rounded-lg border border-mineshaft-600 bg-mineshaft-900 p-4">
|
||||
<div className="flex items-center justify-between border-b border-mineshaft-400 pb-4">
|
||||
<h3 className="text-lg font-medium text-mineshaft-100">Authentication</h3>
|
||||
</div>
|
||||
{identity.authMethods.length > 0 ? (
|
||||
<div className="flex flex-col divide-y divide-mineshaft-400/50">
|
||||
{identity.authMethods.map((authMethod) => (
|
||||
<button
|
||||
key={authMethod}
|
||||
onClick={() =>
|
||||
handlePopUpOpen("viewAuthMethod", {
|
||||
authMethod,
|
||||
lockedOut: identity.activeLockoutAuthMethods?.includes(authMethod) ?? false,
|
||||
refetchIdentity
|
||||
})
|
||||
}
|
||||
type="button"
|
||||
className="flex w-full items-center justify-between bg-mineshaft-900 px-4 py-2 text-sm hover:bg-mineshaft-700 data-[state=open]:bg-mineshaft-600"
|
||||
>
|
||||
<span>{identityAuthToNameMap[authMethod]}</span>
|
||||
<div className="flex items-center gap-2">
|
||||
{identity.activeLockoutAuthMethods?.includes(authMethod) && (
|
||||
<Tooltip content="Auth method has active lockouts">
|
||||
<Badge isSquare variant="danger">
|
||||
<LockIcon />
|
||||
</Badge>
|
||||
</Tooltip>
|
||||
)}
|
||||
<SettingsIcon className="size-4 text-neutral" />
|
||||
</div>
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
<div className="w-full space-y-2 pt-2">
|
||||
<p className="text-sm text-mineshaft-300">
|
||||
No authentication methods configured. Get started by creating a new auth method.
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
{!Object.values(IdentityAuthMethod).every((method) =>
|
||||
identity.authMethods.includes(method)
|
||||
) && (
|
||||
<ProjectPermissionCan
|
||||
I={ProjectPermissionIdentityActions.Edit}
|
||||
a={subject(ProjectPermissionSub.Identity, {
|
||||
identityId: identity.id
|
||||
})}
|
||||
>
|
||||
{(isAllowed) => (
|
||||
<Button
|
||||
isDisabled={!isAllowed}
|
||||
onClick={() => {
|
||||
handlePopUpOpen("identityAuthMethod", {
|
||||
identityId: identity.id,
|
||||
name: identity.name,
|
||||
allAuthMethods: identity.authMethods
|
||||
});
|
||||
}}
|
||||
variant="outline_bg"
|
||||
className="mt-3 w-full"
|
||||
size="xs"
|
||||
leftIcon={<FontAwesomeIcon icon={faPlus} />}
|
||||
>
|
||||
{identity.authMethods.length ? "Add" : "Create"} Auth Method
|
||||
</Button>
|
||||
)}
|
||||
</ProjectPermissionCan>
|
||||
)}
|
||||
<IdentityAuthMethodModal
|
||||
popUp={popUp}
|
||||
handlePopUpOpen={handlePopUpOpen}
|
||||
handlePopUpToggle={handlePopUpToggle}
|
||||
/>
|
||||
<UpgradePlanModal
|
||||
isOpen={popUp.upgradePlan.isOpen}
|
||||
onOpenChange={(isOpen) => handlePopUpToggle("upgradePlan", isOpen)}
|
||||
text={(popUp.upgradePlan?.data as { description: string })?.description}
|
||||
isEnterpriseFeature={popUp.upgradePlan.data?.isEnterpriseFeature}
|
||||
/>
|
||||
<ViewIdentityAuthModal
|
||||
isOpen={popUp.viewAuthMethod.isOpen}
|
||||
onOpenChange={(isOpen) => handlePopUpToggle("viewAuthMethod", isOpen)}
|
||||
authMethod={popUp.viewAuthMethod.data?.authMethod}
|
||||
lockedOut={popUp.viewAuthMethod.data?.lockedOut || false}
|
||||
identityId={identity.id}
|
||||
onResetAllLockouts={popUp.viewAuthMethod.data?.refetchIdentity}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
+249
@@ -0,0 +1,249 @@
|
||||
import { subject } from "@casl/ability";
|
||||
import {
|
||||
faCheck,
|
||||
faChevronDown,
|
||||
faCopy,
|
||||
faEdit,
|
||||
faKey,
|
||||
faTrash
|
||||
} from "@fortawesome/free-solid-svg-icons";
|
||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||
import { useNavigate } from "@tanstack/react-router";
|
||||
import { format } from "date-fns";
|
||||
import { twMerge } from "tailwind-merge";
|
||||
|
||||
import { createNotification } from "@app/components/notifications";
|
||||
import { ProjectPermissionCan } from "@app/components/permissions";
|
||||
import {
|
||||
Button,
|
||||
DeleteActionModal,
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuTrigger,
|
||||
IconButton,
|
||||
Modal,
|
||||
ModalContent,
|
||||
Tag,
|
||||
Tooltip
|
||||
} from "@app/components/v2";
|
||||
import { ProjectPermissionIdentityActions, ProjectPermissionSub, useProject } from "@app/context";
|
||||
import { getProjectBaseURL } from "@app/helpers/project";
|
||||
import { usePopUp, useTimedReset } from "@app/hooks";
|
||||
import { identityAuthToNameMap, TProjectIdentity, useDeleteProjectIdentity } from "@app/hooks/api";
|
||||
import { IdentityProjectMembershipV1 } from "@app/hooks/api/identities/types";
|
||||
import { ProjectIdentityModal } from "@app/pages/project/AccessControlPage/components/IdentityTab/components/ProjectIdentityModal";
|
||||
|
||||
type Props = {
|
||||
identity: TProjectIdentity;
|
||||
isOrgIdentity?: boolean;
|
||||
membership: IdentityProjectMembershipV1;
|
||||
};
|
||||
|
||||
export const ProjectIdentityDetailsSection = ({ identity, isOrgIdentity, membership }: Props) => {
|
||||
const [copyTextId, isCopyingId, setCopyTextId] = useTimedReset<string>({
|
||||
initialState: "Copy ID to clipboard"
|
||||
});
|
||||
|
||||
const { currentProject } = useProject();
|
||||
const { mutateAsync: deleteIdentity } = useDeleteProjectIdentity();
|
||||
const navigate = useNavigate();
|
||||
const { popUp, handlePopUpToggle, handlePopUpOpen } = usePopUp([
|
||||
"editIdentity",
|
||||
"deleteIdentity"
|
||||
] as const);
|
||||
|
||||
const handleDeleteIdentity = async () => {
|
||||
try {
|
||||
await deleteIdentity({
|
||||
identityId: identity.id,
|
||||
projectId: identity.projectId!
|
||||
});
|
||||
|
||||
navigate({
|
||||
to: `${getProjectBaseURL(currentProject.type)}/access-management`,
|
||||
search: {
|
||||
selectedTab: "identities"
|
||||
}
|
||||
});
|
||||
} catch {
|
||||
createNotification({
|
||||
type: "error",
|
||||
text: "Failed to delete project identity"
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="rounded-lg border border-mineshaft-600 bg-mineshaft-900 p-4">
|
||||
<div className="flex items-center justify-between border-b border-mineshaft-400 pb-4">
|
||||
<h3 className="text-lg font-medium text-mineshaft-100">Identity Details</h3>
|
||||
<DropdownMenu>
|
||||
{!isOrgIdentity && (
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button
|
||||
size="xs"
|
||||
rightIcon={
|
||||
<FontAwesomeIcon
|
||||
className="ml-1 transition-transform duration-200 group-data-[state=open]:rotate-180"
|
||||
icon={faChevronDown}
|
||||
/>
|
||||
}
|
||||
colorSchema="secondary"
|
||||
className="group select-none"
|
||||
>
|
||||
Options
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
)}
|
||||
<DropdownMenuContent className="mt-3 min-w-[120px]" align="end">
|
||||
<ProjectPermissionCan
|
||||
I={ProjectPermissionIdentityActions.Edit}
|
||||
a={subject(ProjectPermissionSub.Identity, {
|
||||
identityId: identity.id
|
||||
})}
|
||||
>
|
||||
{(isAllowed) => (
|
||||
<DropdownMenuItem
|
||||
className={twMerge(
|
||||
!isAllowed && "pointer-events-none cursor-not-allowed opacity-50"
|
||||
)}
|
||||
icon={<FontAwesomeIcon icon={faEdit} />}
|
||||
onClick={async () => {
|
||||
handlePopUpOpen("editIdentity");
|
||||
}}
|
||||
disabled={!isAllowed}
|
||||
>
|
||||
Edit Identity
|
||||
</DropdownMenuItem>
|
||||
)}
|
||||
</ProjectPermissionCan>
|
||||
<ProjectPermissionCan
|
||||
I={ProjectPermissionIdentityActions.Delete}
|
||||
a={subject(ProjectPermissionSub.Identity, {
|
||||
identityId: identity.id
|
||||
})}
|
||||
>
|
||||
{(isAllowed) => (
|
||||
<DropdownMenuItem
|
||||
className={twMerge(
|
||||
isAllowed
|
||||
? "hover:bg-red-500! hover:text-white!"
|
||||
: "pointer-events-none cursor-not-allowed opacity-50"
|
||||
)}
|
||||
onClick={async () => {
|
||||
handlePopUpOpen("deleteIdentity");
|
||||
}}
|
||||
icon={<FontAwesomeIcon icon={faTrash} />}
|
||||
disabled={!isAllowed}
|
||||
>
|
||||
Delete Identity
|
||||
</DropdownMenuItem>
|
||||
)}
|
||||
</ProjectPermissionCan>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
</div>
|
||||
<div className="pt-4">
|
||||
<div className="mb-4">
|
||||
<p className="text-sm font-medium text-mineshaft-300">Identity ID</p>
|
||||
<div className="group flex align-top">
|
||||
<p className="text-sm break-all text-mineshaft-300">{identity.id}</p>
|
||||
<div className="opacity-0 transition-opacity duration-300 group-hover:opacity-100">
|
||||
<Tooltip content={copyTextId}>
|
||||
<IconButton
|
||||
ariaLabel="copy icon"
|
||||
variant="plain"
|
||||
className="group relative ml-2"
|
||||
onClick={() => {
|
||||
navigator.clipboard.writeText(identity.id);
|
||||
setCopyTextId("Copied");
|
||||
}}
|
||||
>
|
||||
<FontAwesomeIcon icon={isCopyingId ? faCheck : faCopy} />
|
||||
</IconButton>
|
||||
</Tooltip>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="mb-4">
|
||||
<p className="text-sm font-medium text-mineshaft-300">Managed By</p>
|
||||
<p className="text-sm text-mineshaft-300">
|
||||
{identity.projectId ? "Project" : "Organization"}
|
||||
</p>
|
||||
</div>
|
||||
{!isOrgIdentity && (
|
||||
<>
|
||||
<div className="mb-4">
|
||||
<p className="text-sm font-medium text-mineshaft-300">Last Login Auth Method</p>
|
||||
<p className="text-sm text-mineshaft-300">
|
||||
{membership.lastLoginAuthMethod
|
||||
? identityAuthToNameMap[membership.lastLoginAuthMethod]
|
||||
: "-"}
|
||||
</p>
|
||||
</div>
|
||||
<div className="mb-4">
|
||||
<p className="text-sm font-medium text-mineshaft-300">Last Login Time</p>
|
||||
<p className="text-sm text-mineshaft-300">
|
||||
{membership.lastLoginTime ? format(membership.lastLoginTime, "PPpp") : "-"}
|
||||
</p>
|
||||
</div>
|
||||
<div className="mb-4">
|
||||
<p className="text-sm font-medium text-mineshaft-300">Delete Protection</p>
|
||||
<p className="text-sm text-mineshaft-300">
|
||||
{identity.hasDeleteProtection ? "On" : "Off"}
|
||||
</p>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
<div>
|
||||
<p className="text-sm font-medium text-mineshaft-300">Metadata</p>
|
||||
{identity?.metadata?.length ? (
|
||||
<div className="mt-1 flex flex-wrap gap-2 text-sm text-mineshaft-300">
|
||||
{identity.metadata?.map((el) => (
|
||||
<div key={el.id} className="flex items-center">
|
||||
<Tag
|
||||
size="xs"
|
||||
className="mr-0 flex items-center rounded-r-none border border-mineshaft-500"
|
||||
>
|
||||
<FontAwesomeIcon icon={faKey} size="xs" className="mr-1" />
|
||||
<div>{el.key}</div>
|
||||
</Tag>
|
||||
<Tag
|
||||
size="xs"
|
||||
className="flex items-center rounded-l-none border border-mineshaft-500 bg-mineshaft-900 pl-1"
|
||||
>
|
||||
<div className="max-w-[150px] overflow-hidden text-ellipsis whitespace-nowrap">
|
||||
{el.value}
|
||||
</div>
|
||||
</Tag>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
<p className="text-sm text-mineshaft-300">-</p>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
<Modal
|
||||
isOpen={popUp.editIdentity.isOpen}
|
||||
onOpenChange={(open) => handlePopUpToggle("editIdentity", open)}
|
||||
>
|
||||
<ModalContent bodyClassName="overflow-visible" title="Edit Project Identity">
|
||||
<ProjectIdentityModal
|
||||
identity={identity}
|
||||
onClose={() => handlePopUpToggle("editIdentity", false)}
|
||||
/>
|
||||
</ModalContent>
|
||||
</Modal>
|
||||
|
||||
<DeleteActionModal
|
||||
isOpen={popUp.deleteIdentity.isOpen}
|
||||
title={`Are you sure you want to delete ${identity.name}?`}
|
||||
onChange={(isOpen) => handlePopUpToggle("deleteIdentity", isOpen)}
|
||||
deleteKey="confirm"
|
||||
onDeleteApproved={handleDeleteIdentity}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -42,7 +42,7 @@ export const Page = () => {
|
||||
strict: false,
|
||||
select: (el) => el.membershipId as string
|
||||
});
|
||||
const { currentOrg } = useOrganization();
|
||||
const { currentOrg, isSubOrganization } = useOrganization();
|
||||
const { currentProject, projectId } = useProject();
|
||||
|
||||
const { data: membershipDetails, isPending: isMembershipDetailsLoading } =
|
||||
@@ -73,7 +73,7 @@ export const Page = () => {
|
||||
text: "User privilege assumption has started"
|
||||
});
|
||||
|
||||
const url = getProjectHomePage(currentProject.type, currentProject.environments);
|
||||
const url = `${getProjectHomePage(currentProject.type, currentProject.environments)}${isSubOrganization ? `?subOrganization=${currentOrg.slug}` : ""}`;
|
||||
window.location.href = url.replace("$projectId", currentProject.id);
|
||||
}
|
||||
}
|
||||
|
||||
+46
-26
@@ -180,7 +180,11 @@ const IdentityPolicyActionSchema = z.object({
|
||||
[ProjectPermissionIdentityActions.Edit]: z.boolean().optional(),
|
||||
[ProjectPermissionIdentityActions.Delete]: z.boolean().optional(),
|
||||
[ProjectPermissionIdentityActions.GrantPrivileges]: z.boolean().optional(),
|
||||
[ProjectPermissionIdentityActions.AssumePrivileges]: z.boolean().optional()
|
||||
[ProjectPermissionIdentityActions.AssumePrivileges]: z.boolean().optional(),
|
||||
[ProjectPermissionIdentityActions.RevokeAuth]: z.boolean().optional(),
|
||||
[ProjectPermissionIdentityActions.GetToken]: z.boolean().optional(),
|
||||
[ProjectPermissionIdentityActions.CreateToken]: z.boolean().optional(),
|
||||
[ProjectPermissionIdentityActions.DeleteToken]: z.boolean().optional()
|
||||
});
|
||||
|
||||
const GroupPolicyActionSchema = z.object({
|
||||
@@ -577,6 +581,7 @@ export const rolePermission2Form = (permissions: TProjectPermission[] = []) => {
|
||||
ProjectPermissionSub.IpAllowList,
|
||||
ProjectPermissionSub.CertificateAuthorities,
|
||||
ProjectPermissionSub.PkiAlerts,
|
||||
ProjectPermissionSub.Identity,
|
||||
ProjectPermissionSub.PkiCollections,
|
||||
ProjectPermissionSub.Tags,
|
||||
ProjectPermissionSub.SecretRotation,
|
||||
@@ -782,6 +787,41 @@ export const rolePermission2Form = (permissions: TProjectPermission[] = []) => {
|
||||
return;
|
||||
}
|
||||
|
||||
if (subject === ProjectPermissionSub.Identity) {
|
||||
const canRead = action.includes(ProjectPermissionIdentityActions.Read);
|
||||
const canCreate = action.includes(ProjectPermissionIdentityActions.Create);
|
||||
const canEdit = action.includes(ProjectPermissionIdentityActions.Edit);
|
||||
const canDelete = action.includes(ProjectPermissionIdentityActions.Delete);
|
||||
const canGrantPrivileges = action.includes(
|
||||
ProjectPermissionIdentityActions.GrantPrivileges
|
||||
);
|
||||
const canAssumePrivileges = action.includes(
|
||||
ProjectPermissionIdentityActions.AssumePrivileges
|
||||
);
|
||||
const canRevokeAuth = action.includes(ProjectPermissionIdentityActions.RevokeAuth);
|
||||
const canCreateToken = action.includes(ProjectPermissionIdentityActions.CreateToken);
|
||||
const canGetToken = action.includes(ProjectPermissionIdentityActions.GetToken);
|
||||
const canDeleteToken = action.includes(ProjectPermissionIdentityActions.DeleteToken);
|
||||
|
||||
// from above statement we are sure it won't be undefined
|
||||
formVal[subject]!.push({
|
||||
[ProjectPermissionIdentityActions.Read]: canRead,
|
||||
[ProjectPermissionIdentityActions.Create]: canCreate,
|
||||
[ProjectPermissionIdentityActions.Edit]: canEdit,
|
||||
[ProjectPermissionIdentityActions.Delete]: canDelete,
|
||||
[ProjectPermissionIdentityActions.GrantPrivileges]: canGrantPrivileges,
|
||||
[ProjectPermissionIdentityActions.AssumePrivileges]: canAssumePrivileges,
|
||||
[ProjectPermissionIdentityActions.RevokeAuth]: canRevokeAuth,
|
||||
[ProjectPermissionIdentityActions.CreateToken]: canCreateToken,
|
||||
[ProjectPermissionIdentityActions.GetToken]: canGetToken,
|
||||
[ProjectPermissionIdentityActions.DeleteToken]: canDeleteToken,
|
||||
conditions: conditions ? convertCaslConditionToFormOperator(conditions) : [],
|
||||
inverted
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// for other subjects
|
||||
const canRead = action.includes(ProjectPermissionActions.Read);
|
||||
const canEdit = action.includes(ProjectPermissionActions.Edit);
|
||||
@@ -953,30 +993,6 @@ export const rolePermission2Form = (permissions: TProjectPermission[] = []) => {
|
||||
return;
|
||||
}
|
||||
|
||||
if (subject === ProjectPermissionSub.Identity) {
|
||||
const canRead = action.includes(ProjectPermissionIdentityActions.Read);
|
||||
const canCreate = action.includes(ProjectPermissionIdentityActions.Create);
|
||||
const canEdit = action.includes(ProjectPermissionIdentityActions.Edit);
|
||||
const canDelete = action.includes(ProjectPermissionIdentityActions.Delete);
|
||||
const canGrantPrivileges = action.includes(ProjectPermissionIdentityActions.GrantPrivileges);
|
||||
const canAssumePrivileges = action.includes(
|
||||
ProjectPermissionIdentityActions.AssumePrivileges
|
||||
);
|
||||
|
||||
if (!formVal[subject]) formVal[subject] = [{ conditions: [] }];
|
||||
|
||||
// from above statement we are sure it won't be undefined
|
||||
if (canRead) formVal[subject]![0][ProjectPermissionIdentityActions.Read] = true;
|
||||
if (canCreate) formVal[subject]![0][ProjectPermissionIdentityActions.Create] = true;
|
||||
if (canEdit) formVal[subject]![0][ProjectPermissionIdentityActions.Edit] = true;
|
||||
if (canDelete) formVal[subject]![0][ProjectPermissionIdentityActions.Delete] = true;
|
||||
if (canGrantPrivileges)
|
||||
formVal[subject]![0][ProjectPermissionIdentityActions.GrantPrivileges] = true;
|
||||
if (canAssumePrivileges)
|
||||
formVal[subject]![0][ProjectPermissionIdentityActions.AssumePrivileges] = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (subject === ProjectPermissionSub.Groups) {
|
||||
const canRead = action.includes(ProjectPermissionGroupActions.Read);
|
||||
const canCreate = action.includes(ProjectPermissionGroupActions.Create);
|
||||
@@ -1453,7 +1469,11 @@ export const PROJECT_PERMISSION_OBJECT: TProjectPermissionObject = {
|
||||
{ label: "Modify", value: ProjectPermissionIdentityActions.Edit },
|
||||
{ label: "Remove", value: ProjectPermissionIdentityActions.Delete },
|
||||
{ label: "Grant Privileges", value: ProjectPermissionIdentityActions.GrantPrivileges },
|
||||
{ label: "Assume Privileges", value: ProjectPermissionIdentityActions.AssumePrivileges }
|
||||
{ label: "Assume Privileges", value: ProjectPermissionIdentityActions.AssumePrivileges },
|
||||
{ label: "Revoke Auth", value: ProjectPermissionIdentityActions.RevokeAuth },
|
||||
{ label: "Create Token", value: ProjectPermissionIdentityActions.CreateToken },
|
||||
{ label: "Get Token", value: ProjectPermissionIdentityActions.GetToken },
|
||||
{ label: "Delete Token", value: ProjectPermissionIdentityActions.DeleteToken }
|
||||
]
|
||||
},
|
||||
[ProjectPermissionSub.Groups]: {
|
||||
|
||||
@@ -13,6 +13,8 @@ import { Button, IconButton } from "@app/components/v2";
|
||||
import { useTimedReset, useToggle } from "@app/hooks";
|
||||
import { TViewSharedSecretResponse } from "@app/hooks/api/secretSharing";
|
||||
|
||||
import { SecretShareInfo } from "./SecretShareInfo";
|
||||
|
||||
type Props = {
|
||||
secret: TViewSharedSecretResponse["secret"];
|
||||
secretKey: string | null;
|
||||
@@ -71,6 +73,7 @@ export const SecretContainer = ({ secret, secretKey: key }: Props) => {
|
||||
</IconButton>
|
||||
</div>
|
||||
</div>
|
||||
<SecretShareInfo secret={secret} />
|
||||
<Button
|
||||
className="mt-4 w-full bg-mineshaft-700 py-3 text-bunker-200"
|
||||
colorSchema="primary"
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
import { faClock, faEye } from "@fortawesome/free-solid-svg-icons";
|
||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||
import { format } from "date-fns";
|
||||
|
||||
import { TViewSharedSecretResponse } from "@app/hooks/api/secretSharing";
|
||||
|
||||
type Props = {
|
||||
secret: TViewSharedSecretResponse["secret"];
|
||||
};
|
||||
|
||||
export const SecretShareInfo = ({ secret }: Props) => {
|
||||
let timeRemaining: string | null = null;
|
||||
|
||||
if (secret.expiresAt) {
|
||||
try {
|
||||
timeRemaining = format(new Date(secret.expiresAt), "yyyy-MM-dd 'at' HH:mm a");
|
||||
} catch {
|
||||
timeRemaining = null;
|
||||
}
|
||||
}
|
||||
|
||||
let viewsRemaining: number | null = null;
|
||||
|
||||
if (secret.expiresAfterViews) {
|
||||
viewsRemaining = secret.expiresAfterViews - 1;
|
||||
}
|
||||
|
||||
if (!timeRemaining && viewsRemaining === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="mt-4 flex flex-col gap-2 rounded-md border border-mineshaft-600 bg-mineshaft-700/50 p-3 text-sm text-gray-300">
|
||||
{timeRemaining && (
|
||||
<div className="flex items-center gap-2">
|
||||
<FontAwesomeIcon icon={faClock} className="text-mineshaft-400" />
|
||||
<span>Expires on {timeRemaining}</span>
|
||||
</div>
|
||||
)}
|
||||
{viewsRemaining !== null && (
|
||||
<div className="flex items-center gap-2">
|
||||
<FontAwesomeIcon icon={faEye} className="text-mineshaft-400" />
|
||||
<span>
|
||||
{viewsRemaining === 0
|
||||
? "This is the last time you can view this secret"
|
||||
: `${viewsRemaining} more view${viewsRemaining === 1 ? "" : "s"} remaining`}
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
+1
-1
@@ -39,7 +39,7 @@ const CommitItem = ({
|
||||
<div className="flex gap-2 px-4 py-3 transition-colors duration-200 hover:bg-zinc-800">
|
||||
<div className="flex min-w-0 flex-1 flex-col items-start">
|
||||
<p className="block w-full truncate text-left text-sm text-mineshaft-100">
|
||||
{commit.message}
|
||||
{commit.message || <span className="text-mineshaft-400 italic">No message</span>}
|
||||
</p>
|
||||
<p className="text-left text-xs text-mineshaft-300">
|
||||
{commit.actorMetadata?.email || commit.actorMetadata?.name || commit.actorType}{" "}
|
||||
|
||||
+2
-6
@@ -293,9 +293,6 @@ export const CommitForm: React.FC<CommitFormProps> = ({
|
||||
}
|
||||
|
||||
const handleCommit = async () => {
|
||||
if (!commitMessage.trim()) {
|
||||
return;
|
||||
}
|
||||
await onCommit(pendingChanges, commitMessage);
|
||||
clearAllPendingChanges({
|
||||
projectId,
|
||||
@@ -432,7 +429,7 @@ export const CommitForm: React.FC<CommitFormProps> = ({
|
||||
{/* Commit Message */}
|
||||
<div>
|
||||
<label className="mb-2 block text-sm font-medium text-mineshaft-200">
|
||||
Commit Message <span className="text-red-400">*</span>
|
||||
Commit Message
|
||||
</label>
|
||||
<Input
|
||||
value={commitMessage}
|
||||
@@ -440,7 +437,6 @@ export const CommitForm: React.FC<CommitFormProps> = ({
|
||||
placeholder="Describe your changes..."
|
||||
className="w-full"
|
||||
autoFocus
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
|
||||
@@ -457,7 +453,7 @@ export const CommitForm: React.FC<CommitFormProps> = ({
|
||||
<Button
|
||||
onClick={handleCommit}
|
||||
isLoading={isCommitting}
|
||||
isDisabled={isCommitting || !commitMessage.trim()}
|
||||
isDisabled={isCommitting}
|
||||
leftIcon={<FontAwesomeIcon icon={faCodeCommit} />}
|
||||
colorSchema="primary"
|
||||
variant="outline_bg"
|
||||
|
||||
Reference in New Issue
Block a user