mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-09-22 13:39:35 +00:00
Minor group validation changes
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import slugify from "@sindresorhus/slugify";
|
||||
import { z } from "zod";
|
||||
|
||||
import { GroupsSchema, OrgMembershipRole, UsersSchema } from "@app/db/schemas";
|
||||
@@ -13,8 +14,15 @@ export const registerGroupRouter = async (server: FastifyZodProvider) => {
|
||||
body: z.object({
|
||||
organizationId: z.string().trim(),
|
||||
name: z.string().trim().min(1),
|
||||
slug: z.string().trim().min(1),
|
||||
role: z.string().trim().min(1).default(OrgMembershipRole.NoAccess) // TODO: add describe
|
||||
slug: z
|
||||
.string()
|
||||
.min(5)
|
||||
.max(36)
|
||||
.refine((v) => slugify(v) === v, {
|
||||
message: "Slug must be a valid slug"
|
||||
})
|
||||
.optional(),
|
||||
role: z.string().trim().min(1).default(OrgMembershipRole.NoAccess)
|
||||
}),
|
||||
response: {
|
||||
200: GroupsSchema
|
||||
@@ -45,7 +53,13 @@ export const registerGroupRouter = async (server: FastifyZodProvider) => {
|
||||
body: z
|
||||
.object({
|
||||
name: z.string().trim().min(1),
|
||||
slug: z.string().trim().min(1),
|
||||
slug: z
|
||||
.string()
|
||||
.min(5)
|
||||
.max(36)
|
||||
.refine((v) => slugify(v) === v, {
|
||||
message: "Slug must be a valid slug"
|
||||
}),
|
||||
role: z.string().trim().min(1)
|
||||
})
|
||||
.partial(),
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
import { ForbiddenError } from "@casl/ability";
|
||||
import slugify from "@sindresorhus/slugify";
|
||||
|
||||
import { OrgMembershipRole, TOrgRoles } from "@app/db/schemas";
|
||||
import { isAtLeastAsPrivileged } from "@app/lib/casl";
|
||||
import { BadRequestError, ForbiddenRequestError } from "@app/lib/errors";
|
||||
import { alphaNumericNanoId } from "@app/lib/nanoid";
|
||||
|
||||
import { TOrgDALFactory } from "../../../services/org/org-dal";
|
||||
import { TUserDALFactory } from "../../../services/user/user-dal";
|
||||
@@ -21,11 +23,10 @@ import {
|
||||
import { TUserGroupMembershipDALFactory } from "./user-group-membership-dal";
|
||||
|
||||
type TGroupServiceFactoryDep = {
|
||||
// TODO: Pick
|
||||
userDAL: TUserDALFactory;
|
||||
groupDAL: TGroupDALFactory;
|
||||
orgDAL: TOrgDALFactory;
|
||||
userGroupMembershipDAL: TUserGroupMembershipDALFactory;
|
||||
userDAL: Pick<TUserDALFactory, "findOne">;
|
||||
groupDAL: Pick<TGroupDALFactory, "create" | "findOne" | "update" | "delete" | "findAllGroupMembers">;
|
||||
orgDAL: Pick<TOrgDALFactory, "findMembership">;
|
||||
userGroupMembershipDAL: Pick<TUserGroupMembershipDALFactory, "findOne" | "create" | "delete">;
|
||||
permissionService: Pick<TPermissionServiceFactory, "getOrgPermission" | "getOrgPermissionByRole">;
|
||||
licenseService: Pick<TLicenseServiceFactory, "getPlan">;
|
||||
};
|
||||
@@ -69,7 +70,7 @@ export const groupServiceFactory = ({
|
||||
|
||||
const group = await groupDAL.create({
|
||||
name,
|
||||
slug, // TODO: slugify
|
||||
slug: slug || slugify(`${name}-${alphaNumericNanoId(4)}`),
|
||||
orgId,
|
||||
role: isCustomRole ? OrgMembershipRole.Custom : role,
|
||||
roleId: customRole?.id
|
||||
@@ -122,7 +123,7 @@ export const groupServiceFactory = ({
|
||||
},
|
||||
{
|
||||
name,
|
||||
slug, // TODO: slugify
|
||||
slug: slug ? slugify(slug) : undefined,
|
||||
...(role
|
||||
? {
|
||||
role: customRole ? OrgMembershipRole.Custom : role,
|
||||
|
||||
@@ -2,7 +2,7 @@ import { TOrgPermission } from "@app/lib/types";
|
||||
|
||||
export type TCreateGroupDTO = {
|
||||
name: string;
|
||||
slug: string;
|
||||
slug?: string;
|
||||
role: string;
|
||||
} & TOrgPermission;
|
||||
|
||||
|
||||
@@ -22,12 +22,12 @@ import {
|
||||
} from "./group-project-types";
|
||||
|
||||
type TGroupProjectServiceFactoryDep = {
|
||||
groupProjectDAL: TGroupProjectDALFactory;
|
||||
groupProjectDAL: Pick<TGroupProjectDALFactory, "findOne" | "transaction" | "create" | "delete" | "findByProjectId">;
|
||||
groupProjectMembershipRoleDAL: Pick<
|
||||
TGroupProjectMembershipRoleDALFactory,
|
||||
"create" | "transaction" | "insertMany" | "delete"
|
||||
>;
|
||||
projectDAL: TProjectDALFactory;
|
||||
projectDAL: Pick<TProjectDALFactory, "findById">;
|
||||
projectRoleDAL: Pick<TProjectRoleDALFactory, "find">;
|
||||
groupDAL: Pick<TGroupDALFactory, "findOne">;
|
||||
permissionService: Pick<TPermissionServiceFactory, "getProjectPermission" | "getProjectPermissionByRole">;
|
||||
|
||||
Reference in New Issue
Block a user