mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-15 12:38:36 +00:00
feat(groups): unique names
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { ForbiddenError } from "@casl/ability";
|
||||
import ms from "ms";
|
||||
|
||||
import { ActionProjectType, ProjectMembershipRole, SecretKeyEncoding } from "@app/db/schemas";
|
||||
import { ActionProjectType, ProjectMembershipRole, SecretKeyEncoding, TGroups } from "@app/db/schemas";
|
||||
import { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service";
|
||||
import { ProjectPermissionActions, ProjectPermissionSub } from "@app/ee/services/permission/project-permission";
|
||||
import { isAtLeastAsPrivileged } from "@app/lib/casl";
|
||||
@@ -9,6 +9,7 @@ import { decryptAsymmetric, encryptAsymmetric } from "@app/lib/crypto";
|
||||
import { infisicalSymmetricDecrypt } from "@app/lib/crypto/encryption";
|
||||
import { BadRequestError, ForbiddenRequestError, NotFoundError } from "@app/lib/errors";
|
||||
import { groupBy } from "@app/lib/fn";
|
||||
import { isUuidV4 } from "@app/lib/validator";
|
||||
|
||||
import { TGroupDALFactory } from "../../ee/services/group/group-dal";
|
||||
import { TUserGroupMembershipDALFactory } from "../../ee/services/group/user-group-membership-dal";
|
||||
@@ -62,7 +63,7 @@ export const groupProjectServiceFactory = ({
|
||||
actorAuthMethod,
|
||||
roles,
|
||||
projectId,
|
||||
groupId
|
||||
groupIdOrName
|
||||
}: TCreateProjectGroupDTO) => {
|
||||
const project = await projectDAL.findById(projectId);
|
||||
|
||||
@@ -79,13 +80,23 @@ export const groupProjectServiceFactory = ({
|
||||
});
|
||||
ForbiddenError.from(permission).throwUnlessCan(ProjectPermissionActions.Create, ProjectPermissionSub.Groups);
|
||||
|
||||
const group = await groupDAL.findOne({ orgId: actorOrgId, id: groupId });
|
||||
if (!group) throw new NotFoundError({ message: `Failed to find group with ID ${groupId}` });
|
||||
const isUuid = isUuidV4(groupIdOrName);
|
||||
|
||||
let group: TGroups | null = null;
|
||||
// id can only be a uuid, name can be anything
|
||||
if (isUuid) {
|
||||
group = await groupDAL.findOne({ orgId: actorOrgId, id: groupIdOrName });
|
||||
}
|
||||
if (!group) {
|
||||
group = await groupDAL.findOne({ orgId: actorOrgId, name: groupIdOrName });
|
||||
}
|
||||
|
||||
if (!group) throw new NotFoundError({ message: `Failed to find group with ID or name ${groupIdOrName}` });
|
||||
|
||||
const existingGroup = await groupProjectDAL.findOne({ groupId: group.id, projectId: project.id });
|
||||
if (existingGroup)
|
||||
throw new BadRequestError({
|
||||
message: `Group with ID ${groupId} already exists in project with id ${project.id}`
|
||||
message: `Group with ID ${group.id} already exists in project with id ${project.id}`
|
||||
});
|
||||
|
||||
for await (const { role: requestedRoleChange } of roles) {
|
||||
|
||||
Reference in New Issue
Block a user