mirror of
https://github.com/Infisical/infisical.git
synced 2026-01-10 07:58:15 -05:00
Merge pull request #4918 from Infisical/fix/identity-dup-memb
fix: resolved duplicate membership in identity
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user