mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-06 15:27:27 +00: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);
|
const scopeDatabaseFields = factory.getScopeDatabaseFields(dto.scopeData);
|
||||||
|
|
||||||
await factory.onCreateMembershipGroupGuard(dto);
|
await factory.onCreateMembershipGroupGuard(dto);
|
||||||
|
|
||||||
const customInputRoles = data.roles.filter((el) => factory.isCustomRole(el.role));
|
const customInputRoles = data.roles.filter((el) => factory.isCustomRole(el.role));
|
||||||
@@ -112,6 +113,19 @@ export const membershipGroupServiceFactory = ({
|
|||||||
const customRolesGroupBySlug = groupBy(customRoles, ({ slug }) => slug);
|
const customRolesGroupBySlug = groupBy(customRoles, ({ slug }) => slug);
|
||||||
|
|
||||||
const membership = await membershipGroupDAL.transaction(async (tx) => {
|
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(
|
const doc = await membershipGroupDAL.create(
|
||||||
{
|
{
|
||||||
scope: scopeData.scope,
|
scope: scopeData.scope,
|
||||||
|
|||||||
@@ -105,6 +105,19 @@ export const membershipIdentityServiceFactory = ({
|
|||||||
const customRolesGroupBySlug = groupBy(customRoles, ({ slug }) => slug);
|
const customRolesGroupBySlug = groupBy(customRoles, ({ slug }) => slug);
|
||||||
|
|
||||||
const membership = await membershipIdentityDAL.transaction(async (tx) => {
|
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(
|
const doc = await membershipIdentityDAL.create(
|
||||||
{
|
{
|
||||||
scope: scopeData.scope,
|
scope: scopeData.scope,
|
||||||
|
|||||||
Reference in New Issue
Block a user