Merge pull request #2521 from akhilmhdh/fix/create-identity

feat: added a default empty array for create-identity
This commit is contained in:
Scott Wilson
2024-10-02 07:40:25 -07:00
committed by GitHub
2 changed files with 17 additions and 3 deletions
+13 -2
View File
@@ -23,8 +23,19 @@ export const conditionsMatcher = buildMongoQueryMatcher({ $glob }, { glob });
/** /**
* Extracts and formats permissions from a CASL Ability object or a raw permission set. * Extracts and formats permissions from a CASL Ability object or a raw permission set.
*/ */
const extractPermissions = (ability: MongoAbility) => const extractPermissions = (ability: MongoAbility) => {
ability.rules.map((permission) => `${permission.action as string}_${permission.subject as string}`); const permissions: string[] = [];
ability.rules.forEach((permission) => {
if (typeof permission.action === "string") {
permissions.push(`${permission.action}_${permission.subject as string}`);
} else {
permission.action.forEach((permissionAction) => {
permissions.push(`${permissionAction}_${permission.subject as string}`);
});
}
});
return permissions;
};
/** /**
* Compares two sets of permissions to determine if the first set is at least as privileged as the second set. * Compares two sets of permissions to determine if the first set is at least as privileged as the second set.
@@ -36,6 +36,7 @@ const schema = z
value: z.string().trim().min(1) value: z.string().trim().min(1)
}) })
.array() .array()
.default([])
.optional() .optional()
}) })
.required(); .required();
@@ -88,6 +89,7 @@ export const IdentityModal = ({ popUp, handlePopUpToggle }: Props) => {
identityId: string; identityId: string;
name: string; name: string;
role: string; role: string;
metadata?: { key: string; value: string }[];
customRole: { customRole: {
name: string; name: string;
slug: string; slug: string;
@@ -99,7 +101,8 @@ export const IdentityModal = ({ popUp, handlePopUpToggle }: Props) => {
if (identity) { if (identity) {
reset({ reset({
name: identity.name, name: identity.name,
role: identity?.customRole?.slug ?? identity.role role: identity?.customRole?.slug ?? identity.role,
metadata: identity.metadata
}); });
} else { } else {
reset({ reset({