mirror of
https://github.com/andwati/dokploy.git
synced 2026-11-02 18:22:16 +00:00
refactor: update API and dashboard components to replace projectId with environmentId for improved context handling and authorization checks
This commit is contained in:
@@ -103,8 +103,6 @@ export const TemplateGenerator = ({ environmentId }: Props) => {
|
|||||||
useState<TemplateInfo>(defaultTemplateInfo);
|
useState<TemplateInfo>(defaultTemplateInfo);
|
||||||
const utils = api.useUtils();
|
const utils = api.useUtils();
|
||||||
|
|
||||||
// Get environment data to extract projectId
|
|
||||||
const { data: environment } = api.environment.one.useQuery({ environmentId });
|
|
||||||
|
|
||||||
const haveAtleasOneProviderEnabled = aiSettings?.some(
|
const haveAtleasOneProviderEnabled = aiSettings?.some(
|
||||||
(ai) => ai.isEnabled === true,
|
(ai) => ai.isEnabled === true,
|
||||||
@@ -124,7 +122,7 @@ export const TemplateGenerator = ({ environmentId }: Props) => {
|
|||||||
|
|
||||||
const onSubmit = async () => {
|
const onSubmit = async () => {
|
||||||
await mutateAsync({
|
await mutateAsync({
|
||||||
projectId: environment?.projectId || "",
|
environmentId: environmentId,
|
||||||
id: templateInfo.details?.id || "",
|
id: templateInfo.details?.id || "",
|
||||||
name: templateInfo?.details?.name || "",
|
name: templateInfo?.details?.name || "",
|
||||||
description: templateInfo?.details?.shortDescription || "",
|
description: templateInfo?.details?.shortDescription || "",
|
||||||
@@ -142,7 +140,9 @@ export const TemplateGenerator = ({ environmentId }: Props) => {
|
|||||||
toast.success("Compose Created");
|
toast.success("Compose Created");
|
||||||
setOpen(false);
|
setOpen(false);
|
||||||
// Invalidate the project query to refresh the environment data
|
// Invalidate the project query to refresh the environment data
|
||||||
await utils.project.one.invalidate();
|
await utils.environment.one.invalidate({
|
||||||
|
environmentId,
|
||||||
|
});
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
toast.error("Error creating the compose");
|
toast.error("Error creating the compose");
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import {
|
|||||||
apiUpdateAi,
|
apiUpdateAi,
|
||||||
deploySuggestionSchema,
|
deploySuggestionSchema,
|
||||||
} from "@dokploy/server/db/schema/ai";
|
} from "@dokploy/server/db/schema/ai";
|
||||||
import { createDomain, createMount } from "@dokploy/server/index";
|
import { createDomain, createMount, findEnvironmentById } from "@dokploy/server/index";
|
||||||
import {
|
import {
|
||||||
deleteAiSettings,
|
deleteAiSettings,
|
||||||
getAiSettingById,
|
getAiSettingById,
|
||||||
@@ -177,10 +177,12 @@ export const aiRouter = createTRPCRouter({
|
|||||||
deploy: protectedProcedure
|
deploy: protectedProcedure
|
||||||
.input(deploySuggestionSchema)
|
.input(deploySuggestionSchema)
|
||||||
.mutation(async ({ ctx, input }) => {
|
.mutation(async ({ ctx, input }) => {
|
||||||
|
const environment = await findEnvironmentById(input.environmentId);
|
||||||
|
const project = await findProjectById(environment.projectId);
|
||||||
if (ctx.user.role === "member") {
|
if (ctx.user.role === "member") {
|
||||||
await checkServiceAccess(
|
await checkServiceAccess(
|
||||||
ctx.session.activeOrganizationId,
|
ctx.session.activeOrganizationId,
|
||||||
input.projectId,
|
environment.projectId,
|
||||||
"create",
|
"create",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -192,7 +194,7 @@ export const aiRouter = createTRPCRouter({
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const project = await findProjectById(input.projectId);
|
|
||||||
|
|
||||||
const projectName = slugify(`${project.name} ${input.id}`);
|
const projectName = slugify(`${project.name} ${input.id}`);
|
||||||
|
|
||||||
@@ -205,6 +207,7 @@ export const aiRouter = createTRPCRouter({
|
|||||||
sourceType: "raw",
|
sourceType: "raw",
|
||||||
appName: `${projectName}-${generatePassword(6)}`,
|
appName: `${projectName}-${generatePassword(6)}`,
|
||||||
isolatedDeployment: true,
|
isolatedDeployment: true,
|
||||||
|
environmentId: input.environmentId,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (input.domains && input.domains?.length > 0) {
|
if (input.domains && input.domains?.length > 0) {
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ export const deploymentRouter = createTRPCRouter({
|
|||||||
.query(async ({ input, ctx }) => {
|
.query(async ({ input, ctx }) => {
|
||||||
const application = await findApplicationById(input.applicationId);
|
const application = await findApplicationById(input.applicationId);
|
||||||
if (
|
if (
|
||||||
application.project.organizationId !== ctx.session.activeOrganizationId
|
application.environment.project.organizationId !== ctx.session.activeOrganizationId
|
||||||
) {
|
) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
@@ -43,7 +43,7 @@ export const deploymentRouter = createTRPCRouter({
|
|||||||
.input(apiFindAllByCompose)
|
.input(apiFindAllByCompose)
|
||||||
.query(async ({ input, ctx }) => {
|
.query(async ({ input, ctx }) => {
|
||||||
const compose = await findComposeById(input.composeId);
|
const compose = await findComposeById(input.composeId);
|
||||||
if (compose.project.organizationId !== ctx.session.activeOrganizationId) {
|
if (compose.environment.project.organizationId !== ctx.session.activeOrganizationId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to access this compose",
|
message: "You are not authorized to access this compose",
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ export const securityRouter = createTRPCRouter({
|
|||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
const application = await findApplicationById(input.applicationId);
|
const application = await findApplicationById(input.applicationId);
|
||||||
if (
|
if (
|
||||||
application.project.organizationId !== ctx.session.activeOrganizationId
|
application.environment.project.organizationId !== ctx.session.activeOrganizationId
|
||||||
) {
|
) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
@@ -34,7 +34,7 @@ export const securityRouter = createTRPCRouter({
|
|||||||
const security = await findSecurityById(input.securityId);
|
const security = await findSecurityById(input.securityId);
|
||||||
const application = await findApplicationById(security.applicationId);
|
const application = await findApplicationById(security.applicationId);
|
||||||
if (
|
if (
|
||||||
application.project.organizationId !== ctx.session.activeOrganizationId
|
application.environment.project.organizationId !== ctx.session.activeOrganizationId
|
||||||
) {
|
) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
@@ -49,7 +49,7 @@ export const securityRouter = createTRPCRouter({
|
|||||||
const security = await findSecurityById(input.securityId);
|
const security = await findSecurityById(input.securityId);
|
||||||
const application = await findApplicationById(security.applicationId);
|
const application = await findApplicationById(security.applicationId);
|
||||||
if (
|
if (
|
||||||
application.project.organizationId !== ctx.session.activeOrganizationId
|
application.environment.project.organizationId !== ctx.session.activeOrganizationId
|
||||||
) {
|
) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
@@ -64,7 +64,7 @@ export const securityRouter = createTRPCRouter({
|
|||||||
const security = await findSecurityById(input.securityId);
|
const security = await findSecurityById(input.securityId);
|
||||||
const application = await findApplicationById(security.applicationId);
|
const application = await findApplicationById(security.applicationId);
|
||||||
if (
|
if (
|
||||||
application.project.organizationId !== ctx.session.activeOrganizationId
|
application.environment.project.organizationId !== ctx.session.activeOrganizationId
|
||||||
) {
|
) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ export const apiUpdateAi = createSchema
|
|||||||
.omit({ organizationId: true });
|
.omit({ organizationId: true });
|
||||||
|
|
||||||
export const deploySuggestionSchema = z.object({
|
export const deploySuggestionSchema = z.object({
|
||||||
projectId: z.string().min(1),
|
environmentId: z.string().min(1),
|
||||||
id: z.string().min(1),
|
id: z.string().min(1),
|
||||||
dockerCompose: z.string().min(1),
|
dockerCompose: z.string().min(1),
|
||||||
envVariables: z.string(),
|
envVariables: z.string(),
|
||||||
|
|||||||
Reference in New Issue
Block a user