Merge pull request #4918 from Infisical/fix/identity-dup-memb

fix: resolved duplicate membership in identity
This commit is contained in:
carlosmonastyrski
2025-11-21 10:57:15 -03:00
committed by GitHub
2 changed files with 27 additions and 0 deletions

View File

@@ -93,6 +93,7 @@ export const membershipGroupServiceFactory = ({
}
const scopeDatabaseFields = factory.getScopeDatabaseFields(dto.scopeData);
await factory.onCreateMembershipGroupGuard(dto);
const customInputRoles = data.roles.filter((el) => factory.isCustomRole(el.role));
@@ -112,6 +113,19 @@ export const membershipGroupServiceFactory = ({
const customRolesGroupBySlug = groupBy(customRoles, ({ slug }) => slug);
const membership = await membershipGroupDAL.transaction(async (tx) => {
const existingMembership = await membershipGroupDAL.findOne(
{
scope: scopeData.scope,
...scopeDatabaseFields,
actorGroupId: dto.data.groupId
},
tx
);
if (existingMembership)
throw new BadRequestError({
message: "Group is already a member"
});
const doc = await membershipGroupDAL.create(
{
scope: scopeData.scope,

View File

@@ -105,6 +105,19 @@ export const membershipIdentityServiceFactory = ({
const customRolesGroupBySlug = groupBy(customRoles, ({ slug }) => slug);
const membership = await membershipIdentityDAL.transaction(async (tx) => {
const existingMembership = await membershipIdentityDAL.findOne(
{
scope: scopeData.scope,
...scopeDatabaseFields,
actorIdentityId: dto.data.identityId
},
tx
);
if (existingMembership)
throw new BadRequestError({
message: "Identity is already a member"
});
const doc = await membershipIdentityDAL.create(
{
scope: scopeData.scope,