mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-09-22 13:39:35 +00:00
Merge pull request #1599 from Infisical/daniel/improve-create-project
Fix: Remove required org slug from create project route
This commit is contained in:
@@ -150,8 +150,7 @@ export const registerProjectRouter = async (server: FastifyZodProvider) => {
|
|||||||
message: "Slug must be a valid slug"
|
message: "Slug must be a valid slug"
|
||||||
})
|
})
|
||||||
.optional()
|
.optional()
|
||||||
.describe(PROJECTS.CREATE.slug),
|
.describe(PROJECTS.CREATE.slug)
|
||||||
organizationSlug: z.string().trim().describe(PROJECTS.CREATE.organizationSlug)
|
|
||||||
}),
|
}),
|
||||||
response: {
|
response: {
|
||||||
200: z.object({
|
200: z.object({
|
||||||
@@ -166,7 +165,6 @@ export const registerProjectRouter = async (server: FastifyZodProvider) => {
|
|||||||
actor: req.permission.type,
|
actor: req.permission.type,
|
||||||
actorOrgId: req.permission.orgId,
|
actorOrgId: req.permission.orgId,
|
||||||
actorAuthMethod: req.permission.authMethod,
|
actorAuthMethod: req.permission.authMethod,
|
||||||
orgSlug: req.body.organizationSlug,
|
|
||||||
workspaceName: req.body.projectName,
|
workspaceName: req.body.projectName,
|
||||||
slug: req.body.slug
|
slug: req.body.slug
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -92,7 +92,6 @@ export const projectServiceFactory = ({
|
|||||||
* Create workspace. Make user the admin
|
* Create workspace. Make user the admin
|
||||||
* */
|
* */
|
||||||
const createProject = async ({
|
const createProject = async ({
|
||||||
orgSlug,
|
|
||||||
actor,
|
actor,
|
||||||
actorId,
|
actorId,
|
||||||
actorOrgId,
|
actorOrgId,
|
||||||
@@ -100,13 +99,7 @@ export const projectServiceFactory = ({
|
|||||||
workspaceName,
|
workspaceName,
|
||||||
slug: projectSlug
|
slug: projectSlug
|
||||||
}: TCreateProjectDTO) => {
|
}: TCreateProjectDTO) => {
|
||||||
if (!orgSlug) {
|
const organization = await orgDAL.findOne({ id: actorOrgId });
|
||||||
throw new BadRequestError({
|
|
||||||
message: "Must provide organization slug to create project"
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
const organization = await orgDAL.findOne({ slug: orgSlug });
|
|
||||||
|
|
||||||
const { permission, membership: orgMembership } = await permissionService.getOrgPermission(
|
const { permission, membership: orgMembership } = await permissionService.getOrgPermission(
|
||||||
actor,
|
actor,
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ export type TCreateProjectDTO = {
|
|||||||
actorAuthMethod: ActorAuthMethod;
|
actorAuthMethod: ActorAuthMethod;
|
||||||
actorId: string;
|
actorId: string;
|
||||||
actorOrgId?: string;
|
actorOrgId?: string;
|
||||||
orgSlug: string;
|
|
||||||
workspaceName: string;
|
workspaceName: string;
|
||||||
slug?: string;
|
slug?: string;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -196,10 +196,8 @@ export default function UserInfoStep({
|
|||||||
|
|
||||||
const userOrgs = await fetchOrganizations();
|
const userOrgs = await fetchOrganizations();
|
||||||
|
|
||||||
const orgSlug = userOrgs[0]?.slug;
|
|
||||||
const orgId = userOrgs[0]?.id;
|
const orgId = userOrgs[0]?.id;
|
||||||
const project = await ProjectService.initProject({
|
const project = await ProjectService.initProject({
|
||||||
organizationSlug: orgSlug,
|
|
||||||
projectName: "Example Project"
|
projectName: "Example Project"
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -77,18 +77,11 @@ const secretsToBeAdded = [
|
|||||||
* @param {String} obj.projectName - name of new project
|
* @param {String} obj.projectName - name of new project
|
||||||
* @returns {Project} project - new project
|
* @returns {Project} project - new project
|
||||||
*/
|
*/
|
||||||
const initProjectHelper = async ({
|
const initProjectHelper = async ({ projectName }: { projectName: string }) => {
|
||||||
organizationSlug,
|
|
||||||
projectName
|
|
||||||
}: {
|
|
||||||
organizationSlug: string;
|
|
||||||
projectName: string;
|
|
||||||
}) => {
|
|
||||||
// create new project
|
// create new project
|
||||||
const {
|
const {
|
||||||
data: { project }
|
data: { project }
|
||||||
} = await createWorkspace({
|
} = await createWorkspace({
|
||||||
organizationSlug,
|
|
||||||
projectName
|
projectName
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -199,19 +199,17 @@ export const useGetWorkspaceIntegrations = (workspaceId: string) =>
|
|||||||
});
|
});
|
||||||
|
|
||||||
export const createWorkspace = ({
|
export const createWorkspace = ({
|
||||||
organizationSlug,
|
|
||||||
projectName
|
projectName
|
||||||
}: CreateWorkspaceDTO): Promise<{ data: { project: Workspace } }> => {
|
}: CreateWorkspaceDTO): Promise<{ data: { project: Workspace } }> => {
|
||||||
return apiRequest.post("/api/v2/workspace", { projectName, organizationSlug });
|
return apiRequest.post("/api/v2/workspace", { projectName });
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useCreateWorkspace = () => {
|
export const useCreateWorkspace = () => {
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
return useMutation<{ data: { project: Workspace } }, {}, CreateWorkspaceDTO>({
|
return useMutation<{ data: { project: Workspace } }, {}, CreateWorkspaceDTO>({
|
||||||
mutationFn: async ({ organizationSlug, projectName }) =>
|
mutationFn: async ({ projectName }) =>
|
||||||
createWorkspace({
|
createWorkspace({
|
||||||
organizationSlug,
|
|
||||||
projectName
|
projectName
|
||||||
}),
|
}),
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
@@ -325,7 +323,13 @@ export const useDeleteUserFromWorkspace = () => {
|
|||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationFn: async ({ usernames, workspaceId }: { workspaceId: string; usernames: string[] }) => {
|
mutationFn: async ({
|
||||||
|
usernames,
|
||||||
|
workspaceId
|
||||||
|
}: {
|
||||||
|
workspaceId: string;
|
||||||
|
usernames: string[];
|
||||||
|
}) => {
|
||||||
const {
|
const {
|
||||||
data: { deletedMembership }
|
data: { deletedMembership }
|
||||||
} = await apiRequest.delete(`/api/v2/workspace/${workspaceId}/memberships`, {
|
} = await apiRequest.delete(`/api/v2/workspace/${workspaceId}/memberships`, {
|
||||||
@@ -391,11 +395,7 @@ export const useAddIdentityToWorkspace = () => {
|
|||||||
export const useUpdateIdentityWorkspaceRole = () => {
|
export const useUpdateIdentityWorkspaceRole = () => {
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationFn: async ({
|
mutationFn: async ({ identityId, workspaceId, roles }: TUpdateWorkspaceIdentityRoleDTO) => {
|
||||||
identityId,
|
|
||||||
workspaceId,
|
|
||||||
roles
|
|
||||||
}:TUpdateWorkspaceIdentityRoleDTO)=> {
|
|
||||||
const {
|
const {
|
||||||
data: { identityMembership }
|
data: { identityMembership }
|
||||||
} = await apiRequest.patch(
|
} = await apiRequest.patch(
|
||||||
|
|||||||
@@ -45,7 +45,6 @@ export type TGetUpgradeProjectStatusDTO = {
|
|||||||
// mutation dto
|
// mutation dto
|
||||||
export type CreateWorkspaceDTO = {
|
export type CreateWorkspaceDTO = {
|
||||||
projectName: string;
|
projectName: string;
|
||||||
organizationSlug: string;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export type RenameWorkspaceDTO = { workspaceID: string; newWorkspaceName: string };
|
export type RenameWorkspaceDTO = { workspaceID: string; newWorkspaceName: string };
|
||||||
@@ -82,16 +81,16 @@ export type TUpdateWorkspaceUserRoleDTO = {
|
|||||||
workspaceId: string;
|
workspaceId: string;
|
||||||
roles: (
|
roles: (
|
||||||
| {
|
| {
|
||||||
role: string;
|
role: string;
|
||||||
isTemporary?: false;
|
isTemporary?: false;
|
||||||
}
|
}
|
||||||
| {
|
| {
|
||||||
role: string;
|
role: string;
|
||||||
isTemporary: true;
|
isTemporary: true;
|
||||||
temporaryMode: ProjectUserMembershipTemporaryMode;
|
temporaryMode: ProjectUserMembershipTemporaryMode;
|
||||||
temporaryRange: string;
|
temporaryRange: string;
|
||||||
temporaryAccessStartTime: string;
|
temporaryAccessStartTime: string;
|
||||||
}
|
}
|
||||||
)[];
|
)[];
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -100,15 +99,15 @@ export type TUpdateWorkspaceIdentityRoleDTO = {
|
|||||||
workspaceId: string;
|
workspaceId: string;
|
||||||
roles: (
|
roles: (
|
||||||
| {
|
| {
|
||||||
role: string;
|
role: string;
|
||||||
isTemporary?: false;
|
isTemporary?: false;
|
||||||
}
|
}
|
||||||
| {
|
| {
|
||||||
role: string;
|
role: string;
|
||||||
isTemporary: true;
|
isTemporary: true;
|
||||||
temporaryMode: ProjectUserMembershipTemporaryMode;
|
temporaryMode: ProjectUserMembershipTemporaryMode;
|
||||||
temporaryRange: string;
|
temporaryRange: string;
|
||||||
temporaryAccessStartTime: string;
|
temporaryAccessStartTime: string;
|
||||||
}
|
}
|
||||||
)[];
|
)[];
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -236,7 +236,6 @@ export const AppLayout = ({ children }: LayoutProps) => {
|
|||||||
project: { id: newProjectId }
|
project: { id: newProjectId }
|
||||||
}
|
}
|
||||||
} = await createWs.mutateAsync({
|
} = await createWs.mutateAsync({
|
||||||
organizationSlug: currentOrg.slug,
|
|
||||||
projectName: name
|
projectName: name
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -512,7 +512,6 @@ const OrganizationPage = withPermission(
|
|||||||
project: { id: newProjectId }
|
project: { id: newProjectId }
|
||||||
}
|
}
|
||||||
} = await createWs.mutateAsync({
|
} = await createWs.mutateAsync({
|
||||||
organizationSlug: currentOrg.slug,
|
|
||||||
projectName: name
|
projectName: name
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -9,15 +9,8 @@ class ProjectService {
|
|||||||
* @param {String} obj.projectName - name of new project
|
* @param {String} obj.projectName - name of new project
|
||||||
* @returns {Project} project - new project
|
* @returns {Project} project - new project
|
||||||
*/
|
*/
|
||||||
static async initProject({
|
static async initProject({ projectName }: { projectName: string }) {
|
||||||
organizationSlug,
|
|
||||||
projectName
|
|
||||||
}: {
|
|
||||||
organizationSlug: string;
|
|
||||||
projectName: string;
|
|
||||||
}) {
|
|
||||||
return initProjectHelper({
|
return initProjectHelper({
|
||||||
organizationSlug,
|
|
||||||
projectName
|
projectName
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -189,14 +189,12 @@ export const UserInfoSSOStep = ({
|
|||||||
|
|
||||||
const userOrgs = await fetchOrganizations();
|
const userOrgs = await fetchOrganizations();
|
||||||
const orgId = userOrgs[0]?.id;
|
const orgId = userOrgs[0]?.id;
|
||||||
const orgSlug = userOrgs[0]?.slug;
|
|
||||||
|
|
||||||
await selectOrganization({
|
await selectOrganization({
|
||||||
organizationId: orgId
|
organizationId: orgId
|
||||||
});
|
});
|
||||||
|
|
||||||
const project = await ProjectService.initProject({
|
const project = await ProjectService.initProject({
|
||||||
organizationSlug: orgSlug,
|
|
||||||
projectName: "Example Project"
|
projectName: "Example Project"
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user