mirror of
https://github.com/Dokploy/dokploy
synced 2025-06-26 18:27:59 +00:00
feat: update references
This commit is contained in:
@@ -123,26 +123,10 @@ export const HandleProject = ({ projectId }: Props) => {
|
|||||||
<span>Update</span>
|
<span>Update</span>
|
||||||
</DropdownMenuItem>
|
</DropdownMenuItem>
|
||||||
) : (
|
) : (
|
||||||
<>
|
<Button>
|
||||||
<Button>
|
<PlusIcon className="h-4 w-4" />
|
||||||
<PlusIcon className="h-4 w-4" />
|
Create Project
|
||||||
Create Project
|
</Button>
|
||||||
</Button>
|
|
||||||
<Button
|
|
||||||
onClick={async () => {
|
|
||||||
const newUser = await authClient.admin.createUser({
|
|
||||||
name: "Test User",
|
|
||||||
email: "test4@example.com",
|
|
||||||
password: "password123",
|
|
||||||
role: "user",
|
|
||||||
});
|
|
||||||
|
|
||||||
console.log(newUser);
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Create user
|
|
||||||
</Button>
|
|
||||||
</>
|
|
||||||
)}
|
)}
|
||||||
</DialogTrigger>
|
</DialogTrigger>
|
||||||
<DialogContent className="sm:m:max-w-lg ">
|
<DialogContent className="sm:m:max-w-lg ">
|
||||||
|
|||||||
@@ -60,17 +60,18 @@ interface Props {
|
|||||||
IS_CLOUD: boolean;
|
IS_CLOUD: boolean;
|
||||||
}
|
}
|
||||||
export default function Home({ IS_CLOUD }: Props) {
|
export default function Home({ IS_CLOUD }: Props) {
|
||||||
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
|
const [isError, setIsError] = useState(false);
|
||||||
|
const [error, setError] = useState<string | null>(null);
|
||||||
const [temp, setTemp] = useState<AuthResponse>({
|
const [temp, setTemp] = useState<AuthResponse>({
|
||||||
is2FAEnabled: false,
|
is2FAEnabled: false,
|
||||||
authId: "",
|
authId: "",
|
||||||
});
|
});
|
||||||
const { mutateAsync, isLoading, error, isError } =
|
|
||||||
api.auth.login.useMutation();
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const form = useForm<Login>({
|
const form = useForm<Login>({
|
||||||
defaultValues: {
|
defaultValues: {
|
||||||
email: "",
|
email: "siumauricio@hotmail.com",
|
||||||
password: "",
|
password: "Password123",
|
||||||
},
|
},
|
||||||
resolver: zodResolver(loginSchema),
|
resolver: zodResolver(loginSchema),
|
||||||
});
|
});
|
||||||
@@ -80,6 +81,7 @@ export default function Home({ IS_CLOUD }: Props) {
|
|||||||
}, [form, form.reset, form.formState.isSubmitSuccessful]);
|
}, [form, form.reset, form.formState.isSubmitSuccessful]);
|
||||||
|
|
||||||
const onSubmit = async (values: Login) => {
|
const onSubmit = async (values: Login) => {
|
||||||
|
setIsLoading(true);
|
||||||
const { data, error } = await authClient.signIn.email({
|
const { data, error } = await authClient.signIn.email({
|
||||||
email: values.email,
|
email: values.email,
|
||||||
password: values.password,
|
password: values.password,
|
||||||
@@ -92,15 +94,17 @@ export default function Home({ IS_CLOUD }: Props) {
|
|||||||
toast.success("Successfully signed in", {
|
toast.success("Successfully signed in", {
|
||||||
duration: 2000,
|
duration: 2000,
|
||||||
});
|
});
|
||||||
// router.push("/dashboard/projects");
|
router.push("/dashboard/projects");
|
||||||
// }
|
// }
|
||||||
} else {
|
} else {
|
||||||
|
setIsError(true);
|
||||||
|
setError(error.message ?? "Error to signup");
|
||||||
toast.error("Error to sign up", {
|
toast.error("Error to sign up", {
|
||||||
description: error.message,
|
description: error.message,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(data, error);
|
setIsLoading(false);
|
||||||
// await mutateAsync({
|
// await mutateAsync({
|
||||||
// email: values.email.toLowerCase(),
|
// email: values.email.toLowerCase(),
|
||||||
// password: values.password,
|
// password: values.password,
|
||||||
@@ -136,7 +140,7 @@ export default function Home({ IS_CLOUD }: Props) {
|
|||||||
</div>
|
</div>
|
||||||
{isError && (
|
{isError && (
|
||||||
<AlertBlock type="error" className="my-2">
|
<AlertBlock type="error" className="my-2">
|
||||||
<span>{error?.message}</span>
|
<span>{error}</span>
|
||||||
</AlertBlock>
|
</AlertBlock>
|
||||||
)}
|
)}
|
||||||
<CardContent className="p-0">
|
<CardContent className="p-0">
|
||||||
|
|||||||
@@ -6,18 +6,15 @@ import {
|
|||||||
apiRemoveUser,
|
apiRemoveUser,
|
||||||
apiUpdateAdmin,
|
apiUpdateAdmin,
|
||||||
apiUpdateWebServerMonitoring,
|
apiUpdateWebServerMonitoring,
|
||||||
user,
|
|
||||||
} from "@/server/db/schema";
|
} from "@/server/db/schema";
|
||||||
import {
|
import {
|
||||||
IS_CLOUD,
|
IS_CLOUD,
|
||||||
createInvitation,
|
createInvitation,
|
||||||
findAdminById,
|
|
||||||
findUserByAuthId,
|
findUserByAuthId,
|
||||||
findUserById,
|
findUserById,
|
||||||
getUserByToken,
|
getUserByToken,
|
||||||
removeUserByAuthId,
|
removeUserById,
|
||||||
setupWebMonitoring,
|
setupWebMonitoring,
|
||||||
updateAdmin,
|
|
||||||
updateAdminById,
|
updateAdminById,
|
||||||
} from "@dokploy/server";
|
} from "@dokploy/server";
|
||||||
import { TRPCError } from "@trpc/server";
|
import { TRPCError } from "@trpc/server";
|
||||||
@@ -32,7 +29,7 @@ import {
|
|||||||
|
|
||||||
export const adminRouter = createTRPCRouter({
|
export const adminRouter = createTRPCRouter({
|
||||||
one: adminProcedure.query(async ({ ctx }) => {
|
one: adminProcedure.query(async ({ ctx }) => {
|
||||||
const { sshPrivateKey, ...rest } = await findAdminById(ctx.user.adminId);
|
const { sshPrivateKey, ...rest } = await findUserById(ctx.user.id);
|
||||||
return {
|
return {
|
||||||
haveSSH: !!sshPrivateKey,
|
haveSSH: !!sshPrivateKey,
|
||||||
...rest,
|
...rest,
|
||||||
@@ -47,15 +44,15 @@ export const adminRouter = createTRPCRouter({
|
|||||||
message: "You are not allowed to update this admin",
|
message: "You are not allowed to update this admin",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
const { authId } = await findAdminById(ctx.user.adminId);
|
const { id } = await findUserById(ctx.user.id);
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
return updateAdmin(authId, input);
|
return updateAdmin(id, input);
|
||||||
}),
|
}),
|
||||||
createUserInvitation: adminProcedure
|
createUserInvitation: adminProcedure
|
||||||
.input(apiCreateUserInvitation)
|
.input(apiCreateUserInvitation)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
try {
|
try {
|
||||||
await createInvitation(input, ctx.user.adminId);
|
await createInvitation(input, ctx.user.id);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "BAD_REQUEST",
|
code: "BAD_REQUEST",
|
||||||
@@ -69,15 +66,16 @@ export const adminRouter = createTRPCRouter({
|
|||||||
.input(apiRemoveUser)
|
.input(apiRemoveUser)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
try {
|
try {
|
||||||
const user = await findUserByAuthId(input.authId);
|
const user = await findUserById(input.id);
|
||||||
|
|
||||||
if (user.adminId !== ctx.user.adminId) {
|
if (user.id !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not allowed to delete this user",
|
message: "You are not allowed to delete this user",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return await removeUserByAuthId(input.authId);
|
|
||||||
|
return await removeUserById(input.id);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "BAD_REQUEST",
|
code: "BAD_REQUEST",
|
||||||
@@ -95,20 +93,20 @@ export const adminRouter = createTRPCRouter({
|
|||||||
.input(apiAssignPermissions)
|
.input(apiAssignPermissions)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
try {
|
try {
|
||||||
const user = await findUserById(input.userId);
|
const user = await findUserById(input.id);
|
||||||
|
|
||||||
if (user.adminId !== ctx.user.adminId) {
|
if (user.id !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not allowed to assign permissions",
|
message: "You are not allowed to assign permissions",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
await db
|
// await db
|
||||||
.update(users)
|
// .update(users)
|
||||||
.set({
|
// .set({
|
||||||
...input,
|
// ...input,
|
||||||
})
|
// })
|
||||||
.where(eq(users.userId, input.userId));
|
// .where(eq(users.userId, input.userId));
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
@@ -124,50 +122,50 @@ export const adminRouter = createTRPCRouter({
|
|||||||
message: "Feature disabled on cloud",
|
message: "Feature disabled on cloud",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
const admin = await findAdminById(ctx.user.adminId);
|
const user = await findUserById(ctx.user.ownerId);
|
||||||
if (admin.adminId !== ctx.user.adminId) {
|
if (user.id !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to setup this server",
|
message: "You are not authorized to setup this server",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
await updateAdminById(admin.adminId, {
|
// await updateAdminById(admin.adminId, {
|
||||||
metricsConfig: {
|
// metricsConfig: {
|
||||||
server: {
|
// server: {
|
||||||
type: "Dokploy",
|
// type: "Dokploy",
|
||||||
refreshRate: input.metricsConfig.server.refreshRate,
|
// refreshRate: input.metricsConfig.server.refreshRate,
|
||||||
port: input.metricsConfig.server.port,
|
// port: input.metricsConfig.server.port,
|
||||||
token: input.metricsConfig.server.token,
|
// token: input.metricsConfig.server.token,
|
||||||
cronJob: input.metricsConfig.server.cronJob,
|
// cronJob: input.metricsConfig.server.cronJob,
|
||||||
urlCallback: input.metricsConfig.server.urlCallback,
|
// urlCallback: input.metricsConfig.server.urlCallback,
|
||||||
retentionDays: input.metricsConfig.server.retentionDays,
|
// retentionDays: input.metricsConfig.server.retentionDays,
|
||||||
thresholds: {
|
// thresholds: {
|
||||||
cpu: input.metricsConfig.server.thresholds.cpu,
|
// cpu: input.metricsConfig.server.thresholds.cpu,
|
||||||
memory: input.metricsConfig.server.thresholds.memory,
|
// memory: input.metricsConfig.server.thresholds.memory,
|
||||||
},
|
// },
|
||||||
},
|
// },
|
||||||
containers: {
|
// containers: {
|
||||||
refreshRate: input.metricsConfig.containers.refreshRate,
|
// refreshRate: input.metricsConfig.containers.refreshRate,
|
||||||
services: {
|
// services: {
|
||||||
include: input.metricsConfig.containers.services.include || [],
|
// include: input.metricsConfig.containers.services.include || [],
|
||||||
exclude: input.metricsConfig.containers.services.exclude || [],
|
// exclude: input.metricsConfig.containers.services.exclude || [],
|
||||||
},
|
// },
|
||||||
},
|
// },
|
||||||
},
|
// },
|
||||||
});
|
// });
|
||||||
const currentServer = await setupWebMonitoring(admin.adminId);
|
// const currentServer = await setupWebMonitoring(admin.adminId);
|
||||||
return currentServer;
|
// return currentServer;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
getMetricsToken: protectedProcedure.query(async ({ ctx }) => {
|
getMetricsToken: protectedProcedure.query(async ({ ctx }) => {
|
||||||
const admin = await findAdminById(ctx.user.adminId);
|
const user = await findUserById(ctx.user.ownerId);
|
||||||
return {
|
return {
|
||||||
serverIp: admin.serverIp,
|
serverIp: user.serverIp,
|
||||||
enabledFeatures: admin.enablePaidFeatures,
|
enabledFeatures: user.enablePaidFeatures,
|
||||||
metricsConfig: admin?.metricsConfig,
|
metricsConfig: user?.metricsConfig,
|
||||||
};
|
};
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ export const applicationRouter = createTRPCRouter({
|
|||||||
}
|
}
|
||||||
|
|
||||||
const project = await findProjectById(input.projectId);
|
const project = await findProjectById(input.projectId);
|
||||||
if (project.adminId !== ctx.user.adminId) {
|
if (project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to access this project",
|
message: "You are not authorized to access this project",
|
||||||
@@ -106,7 +106,7 @@ export const applicationRouter = createTRPCRouter({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
const application = await findApplicationById(input.applicationId);
|
const application = await findApplicationById(input.applicationId);
|
||||||
if (application.project.adminId !== ctx.user.adminId) {
|
if (application.project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to access this application",
|
message: "You are not authorized to access this application",
|
||||||
@@ -119,7 +119,7 @@ export const applicationRouter = createTRPCRouter({
|
|||||||
.input(apiReloadApplication)
|
.input(apiReloadApplication)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
const application = await findApplicationById(input.applicationId);
|
const application = await findApplicationById(input.applicationId);
|
||||||
if (application.project.adminId !== ctx.user.adminId) {
|
if (application.project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to reload this application",
|
message: "You are not authorized to reload this application",
|
||||||
@@ -153,7 +153,7 @@ export const applicationRouter = createTRPCRouter({
|
|||||||
}
|
}
|
||||||
const application = await findApplicationById(input.applicationId);
|
const application = await findApplicationById(input.applicationId);
|
||||||
|
|
||||||
if (application.project.adminId !== ctx.user.adminId) {
|
if (application.project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to delete this application",
|
message: "You are not authorized to delete this application",
|
||||||
@@ -194,7 +194,7 @@ export const applicationRouter = createTRPCRouter({
|
|||||||
.input(apiFindOneApplication)
|
.input(apiFindOneApplication)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
const service = await findApplicationById(input.applicationId);
|
const service = await findApplicationById(input.applicationId);
|
||||||
if (service.project.adminId !== ctx.user.adminId) {
|
if (service.project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to stop this application",
|
message: "You are not authorized to stop this application",
|
||||||
@@ -214,7 +214,7 @@ export const applicationRouter = createTRPCRouter({
|
|||||||
.input(apiFindOneApplication)
|
.input(apiFindOneApplication)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
const service = await findApplicationById(input.applicationId);
|
const service = await findApplicationById(input.applicationId);
|
||||||
if (service.project.adminId !== ctx.user.adminId) {
|
if (service.project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to start this application",
|
message: "You are not authorized to start this application",
|
||||||
@@ -235,7 +235,7 @@ export const applicationRouter = createTRPCRouter({
|
|||||||
.input(apiFindOneApplication)
|
.input(apiFindOneApplication)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
const application = await findApplicationById(input.applicationId);
|
const application = await findApplicationById(input.applicationId);
|
||||||
if (application.project.adminId !== ctx.user.adminId) {
|
if (application.project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to redeploy this application",
|
message: "You are not authorized to redeploy this application",
|
||||||
@@ -268,7 +268,7 @@ export const applicationRouter = createTRPCRouter({
|
|||||||
.input(apiSaveEnvironmentVariables)
|
.input(apiSaveEnvironmentVariables)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
const application = await findApplicationById(input.applicationId);
|
const application = await findApplicationById(input.applicationId);
|
||||||
if (application.project.adminId !== ctx.user.adminId) {
|
if (application.project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to save this environment",
|
message: "You are not authorized to save this environment",
|
||||||
@@ -284,7 +284,7 @@ export const applicationRouter = createTRPCRouter({
|
|||||||
.input(apiSaveBuildType)
|
.input(apiSaveBuildType)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
const application = await findApplicationById(input.applicationId);
|
const application = await findApplicationById(input.applicationId);
|
||||||
if (application.project.adminId !== ctx.user.adminId) {
|
if (application.project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to save this build type",
|
message: "You are not authorized to save this build type",
|
||||||
@@ -305,7 +305,7 @@ export const applicationRouter = createTRPCRouter({
|
|||||||
.input(apiSaveGithubProvider)
|
.input(apiSaveGithubProvider)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
const application = await findApplicationById(input.applicationId);
|
const application = await findApplicationById(input.applicationId);
|
||||||
if (application.project.adminId !== ctx.user.adminId) {
|
if (application.project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to save this github provider",
|
message: "You are not authorized to save this github provider",
|
||||||
@@ -327,7 +327,7 @@ export const applicationRouter = createTRPCRouter({
|
|||||||
.input(apiSaveGitlabProvider)
|
.input(apiSaveGitlabProvider)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
const application = await findApplicationById(input.applicationId);
|
const application = await findApplicationById(input.applicationId);
|
||||||
if (application.project.adminId !== ctx.user.adminId) {
|
if (application.project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to save this gitlab provider",
|
message: "You are not authorized to save this gitlab provider",
|
||||||
@@ -351,7 +351,7 @@ export const applicationRouter = createTRPCRouter({
|
|||||||
.input(apiSaveBitbucketProvider)
|
.input(apiSaveBitbucketProvider)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
const application = await findApplicationById(input.applicationId);
|
const application = await findApplicationById(input.applicationId);
|
||||||
if (application.project.adminId !== ctx.user.adminId) {
|
if (application.project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to save this bitbucket provider",
|
message: "You are not authorized to save this bitbucket provider",
|
||||||
@@ -373,7 +373,7 @@ export const applicationRouter = createTRPCRouter({
|
|||||||
.input(apiSaveDockerProvider)
|
.input(apiSaveDockerProvider)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
const application = await findApplicationById(input.applicationId);
|
const application = await findApplicationById(input.applicationId);
|
||||||
if (application.project.adminId !== ctx.user.adminId) {
|
if (application.project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to save this docker provider",
|
message: "You are not authorized to save this docker provider",
|
||||||
@@ -394,7 +394,7 @@ export const applicationRouter = createTRPCRouter({
|
|||||||
.input(apiSaveGitProvider)
|
.input(apiSaveGitProvider)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
const application = await findApplicationById(input.applicationId);
|
const application = await findApplicationById(input.applicationId);
|
||||||
if (application.project.adminId !== ctx.user.adminId) {
|
if (application.project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to save this git provider",
|
message: "You are not authorized to save this git provider",
|
||||||
@@ -415,7 +415,7 @@ export const applicationRouter = createTRPCRouter({
|
|||||||
.input(apiFindOneApplication)
|
.input(apiFindOneApplication)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
const application = await findApplicationById(input.applicationId);
|
const application = await findApplicationById(input.applicationId);
|
||||||
if (application.project.adminId !== ctx.user.adminId) {
|
if (application.project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to mark this application as running",
|
message: "You are not authorized to mark this application as running",
|
||||||
@@ -427,7 +427,7 @@ export const applicationRouter = createTRPCRouter({
|
|||||||
.input(apiUpdateApplication)
|
.input(apiUpdateApplication)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
const application = await findApplicationById(input.applicationId);
|
const application = await findApplicationById(input.applicationId);
|
||||||
if (application.project.adminId !== ctx.user.adminId) {
|
if (application.project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to update this application",
|
message: "You are not authorized to update this application",
|
||||||
@@ -451,7 +451,7 @@ export const applicationRouter = createTRPCRouter({
|
|||||||
.input(apiFindOneApplication)
|
.input(apiFindOneApplication)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
const application = await findApplicationById(input.applicationId);
|
const application = await findApplicationById(input.applicationId);
|
||||||
if (application.project.adminId !== ctx.user.adminId) {
|
if (application.project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to refresh this application",
|
message: "You are not authorized to refresh this application",
|
||||||
@@ -466,7 +466,7 @@ export const applicationRouter = createTRPCRouter({
|
|||||||
.input(apiFindOneApplication)
|
.input(apiFindOneApplication)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
const application = await findApplicationById(input.applicationId);
|
const application = await findApplicationById(input.applicationId);
|
||||||
if (application.project.adminId !== ctx.user.adminId) {
|
if (application.project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to deploy this application",
|
message: "You are not authorized to deploy this application",
|
||||||
@@ -500,7 +500,7 @@ export const applicationRouter = createTRPCRouter({
|
|||||||
.input(apiFindOneApplication)
|
.input(apiFindOneApplication)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
const application = await findApplicationById(input.applicationId);
|
const application = await findApplicationById(input.applicationId);
|
||||||
if (application.project.adminId !== ctx.user.adminId) {
|
if (application.project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to clean this application",
|
message: "You are not authorized to clean this application",
|
||||||
@@ -513,7 +513,7 @@ export const applicationRouter = createTRPCRouter({
|
|||||||
.input(apiFindOneApplication)
|
.input(apiFindOneApplication)
|
||||||
.query(async ({ input, ctx }) => {
|
.query(async ({ input, ctx }) => {
|
||||||
const application = await findApplicationById(input.applicationId);
|
const application = await findApplicationById(input.applicationId);
|
||||||
if (application.project.adminId !== ctx.user.adminId) {
|
if (application.project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to read this application",
|
message: "You are not authorized to read this application",
|
||||||
@@ -548,7 +548,7 @@ export const applicationRouter = createTRPCRouter({
|
|||||||
|
|
||||||
const app = await findApplicationById(input.applicationId as string);
|
const app = await findApplicationById(input.applicationId as string);
|
||||||
|
|
||||||
if (app.project.adminId !== ctx.user.adminId) {
|
if (app.project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to deploy this application",
|
message: "You are not authorized to deploy this application",
|
||||||
@@ -590,7 +590,7 @@ export const applicationRouter = createTRPCRouter({
|
|||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
const application = await findApplicationById(input.applicationId);
|
const application = await findApplicationById(input.applicationId);
|
||||||
|
|
||||||
if (application.project.adminId !== ctx.user.adminId) {
|
if (application.project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to update this application",
|
message: "You are not authorized to update this application",
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ import {
|
|||||||
lucia,
|
lucia,
|
||||||
luciaToken,
|
luciaToken,
|
||||||
removeAdminByAuthId,
|
removeAdminByAuthId,
|
||||||
removeUserByAuthId,
|
|
||||||
sendDiscordNotification,
|
sendDiscordNotification,
|
||||||
sendEmailNotification,
|
sendEmailNotification,
|
||||||
updateAuthById,
|
updateAuthById,
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ export const bitbucketRouter = createTRPCRouter({
|
|||||||
.input(apiCreateBitbucket)
|
.input(apiCreateBitbucket)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
try {
|
try {
|
||||||
return await createBitbucket(input, ctx.user.adminId);
|
return await createBitbucket(input, ctx.user.ownerId);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "BAD_REQUEST",
|
code: "BAD_REQUEST",
|
||||||
@@ -38,7 +38,7 @@ export const bitbucketRouter = createTRPCRouter({
|
|||||||
const bitbucketProvider = await findBitbucketById(input.bitbucketId);
|
const bitbucketProvider = await findBitbucketById(input.bitbucketId);
|
||||||
if (
|
if (
|
||||||
IS_CLOUD &&
|
IS_CLOUD &&
|
||||||
bitbucketProvider.gitProvider.adminId !== ctx.user.adminId
|
bitbucketProvider.gitProvider.userId !== ctx.user.ownerId
|
||||||
) {
|
) {
|
||||||
//TODO: Remove this line when the cloud version is ready
|
//TODO: Remove this line when the cloud version is ready
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
@@ -61,7 +61,7 @@ export const bitbucketRouter = createTRPCRouter({
|
|||||||
if (IS_CLOUD) {
|
if (IS_CLOUD) {
|
||||||
// TODO: mAyBe a rEfaCtoR 🤫
|
// TODO: mAyBe a rEfaCtoR 🤫
|
||||||
result = result.filter(
|
result = result.filter(
|
||||||
(provider) => provider.gitProvider.adminId === ctx.user.adminId,
|
(provider) => provider.gitProvider.userId === ctx.user.ownerId,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
@@ -73,7 +73,7 @@ export const bitbucketRouter = createTRPCRouter({
|
|||||||
const bitbucketProvider = await findBitbucketById(input.bitbucketId);
|
const bitbucketProvider = await findBitbucketById(input.bitbucketId);
|
||||||
if (
|
if (
|
||||||
IS_CLOUD &&
|
IS_CLOUD &&
|
||||||
bitbucketProvider.gitProvider.adminId !== ctx.user.adminId
|
bitbucketProvider.gitProvider.userId !== ctx.user.ownerId
|
||||||
) {
|
) {
|
||||||
//TODO: Remove this line when the cloud version is ready
|
//TODO: Remove this line when the cloud version is ready
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
@@ -91,7 +91,7 @@ export const bitbucketRouter = createTRPCRouter({
|
|||||||
);
|
);
|
||||||
if (
|
if (
|
||||||
IS_CLOUD &&
|
IS_CLOUD &&
|
||||||
bitbucketProvider.gitProvider.adminId !== ctx.user.adminId
|
bitbucketProvider.gitProvider.userId !== ctx.user.ownerId
|
||||||
) {
|
) {
|
||||||
//TODO: Remove this line when the cloud version is ready
|
//TODO: Remove this line when the cloud version is ready
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
@@ -108,7 +108,7 @@ export const bitbucketRouter = createTRPCRouter({
|
|||||||
const bitbucketProvider = await findBitbucketById(input.bitbucketId);
|
const bitbucketProvider = await findBitbucketById(input.bitbucketId);
|
||||||
if (
|
if (
|
||||||
IS_CLOUD &&
|
IS_CLOUD &&
|
||||||
bitbucketProvider.gitProvider.adminId !== ctx.user.adminId
|
bitbucketProvider.gitProvider.userId !== ctx.user.ownerId
|
||||||
) {
|
) {
|
||||||
//TODO: Remove this line when the cloud version is ready
|
//TODO: Remove this line when the cloud version is ready
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
@@ -132,7 +132,7 @@ export const bitbucketRouter = createTRPCRouter({
|
|||||||
const bitbucketProvider = await findBitbucketById(input.bitbucketId);
|
const bitbucketProvider = await findBitbucketById(input.bitbucketId);
|
||||||
if (
|
if (
|
||||||
IS_CLOUD &&
|
IS_CLOUD &&
|
||||||
bitbucketProvider.gitProvider.adminId !== ctx.user.adminId
|
bitbucketProvider.gitProvider.userId !== ctx.user.ownerId
|
||||||
) {
|
) {
|
||||||
//TODO: Remove this line when the cloud version is ready
|
//TODO: Remove this line when the cloud version is ready
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
@@ -142,7 +142,7 @@ export const bitbucketRouter = createTRPCRouter({
|
|||||||
}
|
}
|
||||||
return await updateBitbucket(input.bitbucketId, {
|
return await updateBitbucket(input.bitbucketId, {
|
||||||
...input,
|
...input,
|
||||||
adminId: ctx.user.adminId,
|
userId: ctx.user.ownerId,
|
||||||
});
|
});
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -25,14 +25,14 @@ export const certificateRouter = createTRPCRouter({
|
|||||||
message: "Please set a server to create a certificate",
|
message: "Please set a server to create a certificate",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return await createCertificate(input, ctx.user.adminId);
|
return await createCertificate(input, ctx.user.ownerId);
|
||||||
}),
|
}),
|
||||||
|
|
||||||
one: adminProcedure
|
one: adminProcedure
|
||||||
.input(apiFindCertificate)
|
.input(apiFindCertificate)
|
||||||
.query(async ({ input, ctx }) => {
|
.query(async ({ input, ctx }) => {
|
||||||
const certificates = await findCertificateById(input.certificateId);
|
const certificates = await findCertificateById(input.certificateId);
|
||||||
if (IS_CLOUD && certificates.adminId !== ctx.user.adminId) {
|
if (IS_CLOUD && certificates.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not allowed to access this certificate",
|
message: "You are not allowed to access this certificate",
|
||||||
@@ -44,7 +44,7 @@ export const certificateRouter = createTRPCRouter({
|
|||||||
.input(apiFindCertificate)
|
.input(apiFindCertificate)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
const certificates = await findCertificateById(input.certificateId);
|
const certificates = await findCertificateById(input.certificateId);
|
||||||
if (IS_CLOUD && certificates.adminId !== ctx.user.adminId) {
|
if (IS_CLOUD && certificates.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not allowed to delete this certificate",
|
message: "You are not allowed to delete this certificate",
|
||||||
@@ -56,7 +56,7 @@ export const certificateRouter = createTRPCRouter({
|
|||||||
all: adminProcedure.query(async ({ ctx }) => {
|
all: adminProcedure.query(async ({ ctx }) => {
|
||||||
return await db.query.certificates.findMany({
|
return await db.query.certificates.findMany({
|
||||||
// TODO: Remove this line when the cloud version is ready
|
// TODO: Remove this line when the cloud version is ready
|
||||||
...(IS_CLOUD && { where: eq(certificates.adminId, ctx.user.adminId) }),
|
...(IS_CLOUD && { where: eq(certificates.userId, ctx.user.ownerId) }),
|
||||||
});
|
});
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ export const composeRouter = createTRPCRouter({
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
const project = await findProjectById(input.projectId);
|
const project = await findProjectById(input.projectId);
|
||||||
if (project.adminId !== ctx.user.adminId) {
|
if (project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to access this project",
|
message: "You are not authorized to access this project",
|
||||||
@@ -97,7 +97,7 @@ export const composeRouter = createTRPCRouter({
|
|||||||
}
|
}
|
||||||
|
|
||||||
const compose = await findComposeById(input.composeId);
|
const compose = await findComposeById(input.composeId);
|
||||||
if (compose.project.adminId !== ctx.user.adminId) {
|
if (compose.project.userId !== ctx.user.ownerId) {
|
||||||
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",
|
||||||
@@ -110,7 +110,7 @@ export const composeRouter = createTRPCRouter({
|
|||||||
.input(apiUpdateCompose)
|
.input(apiUpdateCompose)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
const compose = await findComposeById(input.composeId);
|
const compose = await findComposeById(input.composeId);
|
||||||
if (compose.project.adminId !== ctx.user.adminId) {
|
if (compose.project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to update this compose",
|
message: "You are not authorized to update this compose",
|
||||||
@@ -126,7 +126,7 @@ export const composeRouter = createTRPCRouter({
|
|||||||
}
|
}
|
||||||
const composeResult = await findComposeById(input.composeId);
|
const composeResult = await findComposeById(input.composeId);
|
||||||
|
|
||||||
if (composeResult.project.adminId !== ctx.user.adminId) {
|
if (composeResult.project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to delete this compose",
|
message: "You are not authorized to delete this compose",
|
||||||
@@ -157,7 +157,7 @@ export const composeRouter = createTRPCRouter({
|
|||||||
.input(apiFindCompose)
|
.input(apiFindCompose)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
const compose = await findComposeById(input.composeId);
|
const compose = await findComposeById(input.composeId);
|
||||||
if (compose.project.adminId !== ctx.user.adminId) {
|
if (compose.project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to clean this compose",
|
message: "You are not authorized to clean this compose",
|
||||||
@@ -170,7 +170,7 @@ export const composeRouter = createTRPCRouter({
|
|||||||
.input(apiFetchServices)
|
.input(apiFetchServices)
|
||||||
.query(async ({ input, ctx }) => {
|
.query(async ({ input, ctx }) => {
|
||||||
const compose = await findComposeById(input.composeId);
|
const compose = await findComposeById(input.composeId);
|
||||||
if (compose.project.adminId !== ctx.user.adminId) {
|
if (compose.project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to load this compose",
|
message: "You are not authorized to load this compose",
|
||||||
@@ -184,7 +184,7 @@ export const composeRouter = createTRPCRouter({
|
|||||||
try {
|
try {
|
||||||
const compose = await findComposeById(input.composeId);
|
const compose = await findComposeById(input.composeId);
|
||||||
|
|
||||||
if (compose.project.adminId !== ctx.user.adminId) {
|
if (compose.project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to fetch this compose",
|
message: "You are not authorized to fetch this compose",
|
||||||
@@ -209,7 +209,7 @@ export const composeRouter = createTRPCRouter({
|
|||||||
.input(apiRandomizeCompose)
|
.input(apiRandomizeCompose)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
const compose = await findComposeById(input.composeId);
|
const compose = await findComposeById(input.composeId);
|
||||||
if (compose.project.adminId !== ctx.user.adminId) {
|
if (compose.project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to randomize this compose",
|
message: "You are not authorized to randomize this compose",
|
||||||
@@ -221,7 +221,7 @@ export const composeRouter = createTRPCRouter({
|
|||||||
.input(apiRandomizeCompose)
|
.input(apiRandomizeCompose)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
const compose = await findComposeById(input.composeId);
|
const compose = await findComposeById(input.composeId);
|
||||||
if (compose.project.adminId !== ctx.user.adminId) {
|
if (compose.project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to randomize this compose",
|
message: "You are not authorized to randomize this compose",
|
||||||
@@ -236,7 +236,7 @@ export const composeRouter = createTRPCRouter({
|
|||||||
.input(apiFindCompose)
|
.input(apiFindCompose)
|
||||||
.query(async ({ input, ctx }) => {
|
.query(async ({ input, ctx }) => {
|
||||||
const compose = await findComposeById(input.composeId);
|
const compose = await findComposeById(input.composeId);
|
||||||
if (compose.project.adminId !== ctx.user.adminId) {
|
if (compose.project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to get this compose",
|
message: "You are not authorized to get this compose",
|
||||||
@@ -254,7 +254,7 @@ export const composeRouter = createTRPCRouter({
|
|||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
const compose = await findComposeById(input.composeId);
|
const compose = await findComposeById(input.composeId);
|
||||||
|
|
||||||
if (compose.project.adminId !== ctx.user.adminId) {
|
if (compose.project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to deploy this compose",
|
message: "You are not authorized to deploy this compose",
|
||||||
@@ -287,7 +287,7 @@ export const composeRouter = createTRPCRouter({
|
|||||||
.input(apiFindCompose)
|
.input(apiFindCompose)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
const compose = await findComposeById(input.composeId);
|
const compose = await findComposeById(input.composeId);
|
||||||
if (compose.project.adminId !== ctx.user.adminId) {
|
if (compose.project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to redeploy this compose",
|
message: "You are not authorized to redeploy this compose",
|
||||||
@@ -319,7 +319,7 @@ export const composeRouter = createTRPCRouter({
|
|||||||
.input(apiFindCompose)
|
.input(apiFindCompose)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
const compose = await findComposeById(input.composeId);
|
const compose = await findComposeById(input.composeId);
|
||||||
if (compose.project.adminId !== ctx.user.adminId) {
|
if (compose.project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to stop this compose",
|
message: "You are not authorized to stop this compose",
|
||||||
@@ -333,7 +333,7 @@ export const composeRouter = createTRPCRouter({
|
|||||||
.input(apiFindCompose)
|
.input(apiFindCompose)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
const compose = await findComposeById(input.composeId);
|
const compose = await findComposeById(input.composeId);
|
||||||
if (compose.project.adminId !== ctx.user.adminId) {
|
if (compose.project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to stop this compose",
|
message: "You are not authorized to stop this compose",
|
||||||
@@ -348,7 +348,7 @@ export const composeRouter = createTRPCRouter({
|
|||||||
.query(async ({ input, ctx }) => {
|
.query(async ({ input, ctx }) => {
|
||||||
const compose = await findComposeById(input.composeId);
|
const compose = await findComposeById(input.composeId);
|
||||||
|
|
||||||
if (compose.project.adminId !== ctx.user.adminId) {
|
if (compose.project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to get this compose",
|
message: "You are not authorized to get this compose",
|
||||||
@@ -361,7 +361,7 @@ export const composeRouter = createTRPCRouter({
|
|||||||
.input(apiFindCompose)
|
.input(apiFindCompose)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
const compose = await findComposeById(input.composeId);
|
const compose = await findComposeById(input.composeId);
|
||||||
if (compose.project.adminId !== ctx.user.adminId) {
|
if (compose.project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to refresh this compose",
|
message: "You are not authorized to refresh this compose",
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ export const deploymentRouter = createTRPCRouter({
|
|||||||
.input(apiFindAllByApplication)
|
.input(apiFindAllByApplication)
|
||||||
.query(async ({ input, ctx }) => {
|
.query(async ({ input, ctx }) => {
|
||||||
const application = await findApplicationById(input.applicationId);
|
const application = await findApplicationById(input.applicationId);
|
||||||
if (application.project.adminId !== ctx.user.adminId) {
|
if (application.project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to access this application",
|
message: "You are not authorized to access this application",
|
||||||
@@ -32,7 +32,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.adminId !== ctx.user.adminId) {
|
if (compose.project.userId !== ctx.user.ownerId) {
|
||||||
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",
|
||||||
@@ -44,7 +44,7 @@ export const deploymentRouter = createTRPCRouter({
|
|||||||
.input(apiFindAllByServer)
|
.input(apiFindAllByServer)
|
||||||
.query(async ({ input, ctx }) => {
|
.query(async ({ input, ctx }) => {
|
||||||
const server = await findServerById(input.serverId);
|
const server = await findServerById(input.serverId);
|
||||||
if (server.adminId !== ctx.user.adminId) {
|
if (server.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to access this server",
|
message: "You are not authorized to access this server",
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ export const destinationRouter = createTRPCRouter({
|
|||||||
.input(apiCreateDestination)
|
.input(apiCreateDestination)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
try {
|
try {
|
||||||
return await createDestintation(input, ctx.user.adminId);
|
return await createDestintation(input, ctx.user.ownerId);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "BAD_REQUEST",
|
code: "BAD_REQUEST",
|
||||||
@@ -84,7 +84,7 @@ export const destinationRouter = createTRPCRouter({
|
|||||||
.input(apiFindOneDestination)
|
.input(apiFindOneDestination)
|
||||||
.query(async ({ input, ctx }) => {
|
.query(async ({ input, ctx }) => {
|
||||||
const destination = await findDestinationById(input.destinationId);
|
const destination = await findDestinationById(input.destinationId);
|
||||||
if (destination.adminId !== ctx.user.adminId) {
|
if (destination.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not allowed to access this destination",
|
message: "You are not allowed to access this destination",
|
||||||
@@ -94,7 +94,7 @@ export const destinationRouter = createTRPCRouter({
|
|||||||
}),
|
}),
|
||||||
all: protectedProcedure.query(async ({ ctx }) => {
|
all: protectedProcedure.query(async ({ ctx }) => {
|
||||||
return await db.query.destinations.findMany({
|
return await db.query.destinations.findMany({
|
||||||
where: eq(destinations.adminId, ctx.user.adminId),
|
where: eq(destinations.userId, ctx.user.ownerId),
|
||||||
});
|
});
|
||||||
}),
|
}),
|
||||||
remove: adminProcedure
|
remove: adminProcedure
|
||||||
@@ -103,7 +103,7 @@ export const destinationRouter = createTRPCRouter({
|
|||||||
try {
|
try {
|
||||||
const destination = await findDestinationById(input.destinationId);
|
const destination = await findDestinationById(input.destinationId);
|
||||||
|
|
||||||
if (destination.adminId !== ctx.user.adminId) {
|
if (destination.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not allowed to delete this destination",
|
message: "You are not allowed to delete this destination",
|
||||||
@@ -111,7 +111,7 @@ export const destinationRouter = createTRPCRouter({
|
|||||||
}
|
}
|
||||||
return await removeDestinationById(
|
return await removeDestinationById(
|
||||||
input.destinationId,
|
input.destinationId,
|
||||||
ctx.user.adminId,
|
ctx.user.ownerId,
|
||||||
);
|
);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw error;
|
throw error;
|
||||||
@@ -122,7 +122,7 @@ export const destinationRouter = createTRPCRouter({
|
|||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
try {
|
try {
|
||||||
const destination = await findDestinationById(input.destinationId);
|
const destination = await findDestinationById(input.destinationId);
|
||||||
if (destination.adminId !== ctx.user.adminId) {
|
if (destination.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not allowed to update this destination",
|
message: "You are not allowed to update this destination",
|
||||||
@@ -130,7 +130,7 @@ export const destinationRouter = createTRPCRouter({
|
|||||||
}
|
}
|
||||||
return await updateDestinationById(input.destinationId, {
|
return await updateDestinationById(input.destinationId, {
|
||||||
...input,
|
...input,
|
||||||
adminId: ctx.user.adminId,
|
userId: ctx.user.ownerId,
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw error;
|
throw error;
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ export const domainRouter = createTRPCRouter({
|
|||||||
try {
|
try {
|
||||||
if (input.domainType === "compose" && input.composeId) {
|
if (input.domainType === "compose" && input.composeId) {
|
||||||
const compose = await findComposeById(input.composeId);
|
const compose = await findComposeById(input.composeId);
|
||||||
if (compose.project.adminId !== ctx.user.adminId) {
|
if (compose.project.userId !== ctx.user.ownerId) {
|
||||||
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",
|
||||||
@@ -38,7 +38,7 @@ export const domainRouter = createTRPCRouter({
|
|||||||
}
|
}
|
||||||
} else if (input.domainType === "application" && input.applicationId) {
|
} else if (input.domainType === "application" && input.applicationId) {
|
||||||
const application = await findApplicationById(input.applicationId);
|
const application = await findApplicationById(input.applicationId);
|
||||||
if (application.project.adminId !== ctx.user.adminId) {
|
if (application.project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to access this application",
|
message: "You are not authorized to access this application",
|
||||||
@@ -58,7 +58,7 @@ export const domainRouter = createTRPCRouter({
|
|||||||
.input(apiFindOneApplication)
|
.input(apiFindOneApplication)
|
||||||
.query(async ({ input, ctx }) => {
|
.query(async ({ input, ctx }) => {
|
||||||
const application = await findApplicationById(input.applicationId);
|
const application = await findApplicationById(input.applicationId);
|
||||||
if (application.project.adminId !== ctx.user.adminId) {
|
if (application.project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to access this application",
|
message: "You are not authorized to access this application",
|
||||||
@@ -70,7 +70,7 @@ export const domainRouter = createTRPCRouter({
|
|||||||
.input(apiFindCompose)
|
.input(apiFindCompose)
|
||||||
.query(async ({ input, ctx }) => {
|
.query(async ({ input, ctx }) => {
|
||||||
const compose = await findComposeById(input.composeId);
|
const compose = await findComposeById(input.composeId);
|
||||||
if (compose.project.adminId !== ctx.user.adminId) {
|
if (compose.project.userId !== ctx.user.ownerId) {
|
||||||
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",
|
||||||
@@ -83,7 +83,7 @@ export const domainRouter = createTRPCRouter({
|
|||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
return generateTraefikMeDomain(
|
return generateTraefikMeDomain(
|
||||||
input.appName,
|
input.appName,
|
||||||
ctx.user.adminId,
|
ctx.user.ownerId,
|
||||||
input.serverId,
|
input.serverId,
|
||||||
);
|
);
|
||||||
}),
|
}),
|
||||||
@@ -95,7 +95,7 @@ export const domainRouter = createTRPCRouter({
|
|||||||
|
|
||||||
if (currentDomain.applicationId) {
|
if (currentDomain.applicationId) {
|
||||||
const newApp = await findApplicationById(currentDomain.applicationId);
|
const newApp = await findApplicationById(currentDomain.applicationId);
|
||||||
if (newApp.project.adminId !== ctx.user.adminId) {
|
if (newApp.project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to access this application",
|
message: "You are not authorized to access this application",
|
||||||
@@ -103,7 +103,7 @@ export const domainRouter = createTRPCRouter({
|
|||||||
}
|
}
|
||||||
} else if (currentDomain.composeId) {
|
} else if (currentDomain.composeId) {
|
||||||
const newCompose = await findComposeById(currentDomain.composeId);
|
const newCompose = await findComposeById(currentDomain.composeId);
|
||||||
if (newCompose.project.adminId !== ctx.user.adminId) {
|
if (newCompose.project.userId !== ctx.user.ownerId) {
|
||||||
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",
|
||||||
@@ -114,7 +114,7 @@ export const domainRouter = createTRPCRouter({
|
|||||||
currentDomain.previewDeploymentId,
|
currentDomain.previewDeploymentId,
|
||||||
);
|
);
|
||||||
if (
|
if (
|
||||||
newPreviewDeployment.application.project.adminId !== ctx.user.adminId
|
newPreviewDeployment.application.project.userId !== ctx.user.ownerId
|
||||||
) {
|
) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
@@ -143,7 +143,7 @@ export const domainRouter = createTRPCRouter({
|
|||||||
const domain = await findDomainById(input.domainId);
|
const domain = await findDomainById(input.domainId);
|
||||||
if (domain.applicationId) {
|
if (domain.applicationId) {
|
||||||
const application = await findApplicationById(domain.applicationId);
|
const application = await findApplicationById(domain.applicationId);
|
||||||
if (application.project.adminId !== ctx.user.adminId) {
|
if (application.project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to access this application",
|
message: "You are not authorized to access this application",
|
||||||
@@ -151,7 +151,7 @@ export const domainRouter = createTRPCRouter({
|
|||||||
}
|
}
|
||||||
} else if (domain.composeId) {
|
} else if (domain.composeId) {
|
||||||
const compose = await findComposeById(domain.composeId);
|
const compose = await findComposeById(domain.composeId);
|
||||||
if (compose.project.adminId !== ctx.user.adminId) {
|
if (compose.project.userId !== ctx.user.ownerId) {
|
||||||
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",
|
||||||
@@ -166,7 +166,7 @@ export const domainRouter = createTRPCRouter({
|
|||||||
const domain = await findDomainById(input.domainId);
|
const domain = await findDomainById(input.domainId);
|
||||||
if (domain.applicationId) {
|
if (domain.applicationId) {
|
||||||
const application = await findApplicationById(domain.applicationId);
|
const application = await findApplicationById(domain.applicationId);
|
||||||
if (application.project.adminId !== ctx.user.adminId) {
|
if (application.project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to access this application",
|
message: "You are not authorized to access this application",
|
||||||
@@ -174,7 +174,7 @@ export const domainRouter = createTRPCRouter({
|
|||||||
}
|
}
|
||||||
} else if (domain.composeId) {
|
} else if (domain.composeId) {
|
||||||
const compose = await findComposeById(domain.composeId);
|
const compose = await findComposeById(domain.composeId);
|
||||||
if (compose.project.adminId !== ctx.user.adminId) {
|
if (compose.project.userId !== ctx.user.ownerId) {
|
||||||
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",
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ export const gitProviderRouter = createTRPCRouter({
|
|||||||
github: true,
|
github: true,
|
||||||
},
|
},
|
||||||
orderBy: desc(gitProvider.createdAt),
|
orderBy: desc(gitProvider.createdAt),
|
||||||
...(IS_CLOUD && { where: eq(gitProvider.adminId, ctx.user.adminId) }),
|
...(IS_CLOUD && { where: eq(gitProvider.userId, ctx.user.ownerId) }),
|
||||||
//TODO: Remove this line when the cloud version is ready
|
//TODO: Remove this line when the cloud version is ready
|
||||||
});
|
});
|
||||||
}),
|
}),
|
||||||
@@ -28,7 +28,7 @@ export const gitProviderRouter = createTRPCRouter({
|
|||||||
try {
|
try {
|
||||||
const gitProvider = await findGitProviderById(input.gitProviderId);
|
const gitProvider = await findGitProviderById(input.gitProviderId);
|
||||||
|
|
||||||
if (IS_CLOUD && gitProvider.adminId !== ctx.user.adminId) {
|
if (IS_CLOUD && gitProvider.userId !== ctx.user.ownerId) {
|
||||||
// TODO: Remove isCloud in the next versions of dokploy
|
// TODO: Remove isCloud in the next versions of dokploy
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ export const githubRouter = createTRPCRouter({
|
|||||||
.input(apiFindOneGithub)
|
.input(apiFindOneGithub)
|
||||||
.query(async ({ input, ctx }) => {
|
.query(async ({ input, ctx }) => {
|
||||||
const githubProvider = await findGithubById(input.githubId);
|
const githubProvider = await findGithubById(input.githubId);
|
||||||
if (IS_CLOUD && githubProvider.gitProvider.adminId !== ctx.user.adminId) {
|
if (IS_CLOUD && githubProvider.gitProvider.userId !== ctx.user.ownerId) {
|
||||||
//TODO: Remove this line when the cloud version is ready
|
//TODO: Remove this line when the cloud version is ready
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
@@ -33,7 +33,7 @@ export const githubRouter = createTRPCRouter({
|
|||||||
.input(apiFindOneGithub)
|
.input(apiFindOneGithub)
|
||||||
.query(async ({ input, ctx }) => {
|
.query(async ({ input, ctx }) => {
|
||||||
const githubProvider = await findGithubById(input.githubId);
|
const githubProvider = await findGithubById(input.githubId);
|
||||||
if (IS_CLOUD && githubProvider.gitProvider.adminId !== ctx.user.adminId) {
|
if (IS_CLOUD && githubProvider.gitProvider.userId !== ctx.user.ownerId) {
|
||||||
//TODO: Remove this line when the cloud version is ready
|
//TODO: Remove this line when the cloud version is ready
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
@@ -46,7 +46,7 @@ export const githubRouter = createTRPCRouter({
|
|||||||
.input(apiFindGithubBranches)
|
.input(apiFindGithubBranches)
|
||||||
.query(async ({ input, ctx }) => {
|
.query(async ({ input, ctx }) => {
|
||||||
const githubProvider = await findGithubById(input.githubId || "");
|
const githubProvider = await findGithubById(input.githubId || "");
|
||||||
if (IS_CLOUD && githubProvider.gitProvider.adminId !== ctx.user.adminId) {
|
if (IS_CLOUD && githubProvider.gitProvider.userId !== ctx.user.ownerId) {
|
||||||
//TODO: Remove this line when the cloud version is ready
|
//TODO: Remove this line when the cloud version is ready
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
@@ -65,7 +65,7 @@ export const githubRouter = createTRPCRouter({
|
|||||||
if (IS_CLOUD) {
|
if (IS_CLOUD) {
|
||||||
// TODO: mAyBe a rEfaCtoR 🤫
|
// TODO: mAyBe a rEfaCtoR 🤫
|
||||||
result = result.filter(
|
result = result.filter(
|
||||||
(provider) => provider.gitProvider.adminId === ctx.user.adminId,
|
(provider) => provider.gitProvider.userId === ctx.user.ownerId,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,7 +90,7 @@ export const githubRouter = createTRPCRouter({
|
|||||||
const githubProvider = await findGithubById(input.githubId);
|
const githubProvider = await findGithubById(input.githubId);
|
||||||
if (
|
if (
|
||||||
IS_CLOUD &&
|
IS_CLOUD &&
|
||||||
githubProvider.gitProvider.adminId !== ctx.user.adminId
|
githubProvider.gitProvider.userId !== ctx.user.ownerId
|
||||||
) {
|
) {
|
||||||
//TODO: Remove this line when the cloud version is ready
|
//TODO: Remove this line when the cloud version is ready
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
@@ -111,7 +111,7 @@ export const githubRouter = createTRPCRouter({
|
|||||||
.input(apiUpdateGithub)
|
.input(apiUpdateGithub)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
const githubProvider = await findGithubById(input.githubId);
|
const githubProvider = await findGithubById(input.githubId);
|
||||||
if (IS_CLOUD && githubProvider.gitProvider.adminId !== ctx.user.adminId) {
|
if (IS_CLOUD && githubProvider.gitProvider.userId !== ctx.user.ownerId) {
|
||||||
//TODO: Remove this line when the cloud version is ready
|
//TODO: Remove this line when the cloud version is ready
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
@@ -120,7 +120,7 @@ export const githubRouter = createTRPCRouter({
|
|||||||
}
|
}
|
||||||
await updateGitProvider(input.gitProviderId, {
|
await updateGitProvider(input.gitProviderId, {
|
||||||
name: input.name,
|
name: input.name,
|
||||||
adminId: ctx.user.adminId,
|
userId: ctx.user.ownerId,
|
||||||
});
|
});
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ export const gitlabRouter = createTRPCRouter({
|
|||||||
.input(apiCreateGitlab)
|
.input(apiCreateGitlab)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
try {
|
try {
|
||||||
return await createGitlab(input, ctx.user.adminId);
|
return await createGitlab(input, ctx.user.ownerId);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "BAD_REQUEST",
|
code: "BAD_REQUEST",
|
||||||
@@ -39,7 +39,7 @@ export const gitlabRouter = createTRPCRouter({
|
|||||||
.input(apiFindOneGitlab)
|
.input(apiFindOneGitlab)
|
||||||
.query(async ({ input, ctx }) => {
|
.query(async ({ input, ctx }) => {
|
||||||
const gitlabProvider = await findGitlabById(input.gitlabId);
|
const gitlabProvider = await findGitlabById(input.gitlabId);
|
||||||
if (IS_CLOUD && gitlabProvider.gitProvider.adminId !== ctx.user.adminId) {
|
if (IS_CLOUD && gitlabProvider.gitProvider.userId !== ctx.user.ownerId) {
|
||||||
//TODO: Remove this line when the cloud version is ready
|
//TODO: Remove this line when the cloud version is ready
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
@@ -58,7 +58,7 @@ export const gitlabRouter = createTRPCRouter({
|
|||||||
if (IS_CLOUD) {
|
if (IS_CLOUD) {
|
||||||
// TODO: mAyBe a rEfaCtoR 🤫
|
// TODO: mAyBe a rEfaCtoR 🤫
|
||||||
result = result.filter(
|
result = result.filter(
|
||||||
(provider) => provider.gitProvider.adminId === ctx.user.adminId,
|
(provider) => provider.gitProvider.userId === ctx.user.ownerId,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
const filtered = result
|
const filtered = result
|
||||||
@@ -78,7 +78,7 @@ export const gitlabRouter = createTRPCRouter({
|
|||||||
.input(apiFindOneGitlab)
|
.input(apiFindOneGitlab)
|
||||||
.query(async ({ input, ctx }) => {
|
.query(async ({ input, ctx }) => {
|
||||||
const gitlabProvider = await findGitlabById(input.gitlabId);
|
const gitlabProvider = await findGitlabById(input.gitlabId);
|
||||||
if (IS_CLOUD && gitlabProvider.gitProvider.adminId !== ctx.user.adminId) {
|
if (IS_CLOUD && gitlabProvider.gitProvider.userId !== ctx.user.ownerId) {
|
||||||
//TODO: Remove this line when the cloud version is ready
|
//TODO: Remove this line when the cloud version is ready
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
@@ -92,7 +92,7 @@ export const gitlabRouter = createTRPCRouter({
|
|||||||
.input(apiFindGitlabBranches)
|
.input(apiFindGitlabBranches)
|
||||||
.query(async ({ input, ctx }) => {
|
.query(async ({ input, ctx }) => {
|
||||||
const gitlabProvider = await findGitlabById(input.gitlabId || "");
|
const gitlabProvider = await findGitlabById(input.gitlabId || "");
|
||||||
if (IS_CLOUD && gitlabProvider.gitProvider.adminId !== ctx.user.adminId) {
|
if (IS_CLOUD && gitlabProvider.gitProvider.userId !== ctx.user.ownerId) {
|
||||||
//TODO: Remove this line when the cloud version is ready
|
//TODO: Remove this line when the cloud version is ready
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
@@ -108,7 +108,7 @@ export const gitlabRouter = createTRPCRouter({
|
|||||||
const gitlabProvider = await findGitlabById(input.gitlabId || "");
|
const gitlabProvider = await findGitlabById(input.gitlabId || "");
|
||||||
if (
|
if (
|
||||||
IS_CLOUD &&
|
IS_CLOUD &&
|
||||||
gitlabProvider.gitProvider.adminId !== ctx.user.adminId
|
gitlabProvider.gitProvider.userId !== ctx.user.ownerId
|
||||||
) {
|
) {
|
||||||
//TODO: Remove this line when the cloud version is ready
|
//TODO: Remove this line when the cloud version is ready
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
@@ -130,7 +130,7 @@ export const gitlabRouter = createTRPCRouter({
|
|||||||
.input(apiUpdateGitlab)
|
.input(apiUpdateGitlab)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
const gitlabProvider = await findGitlabById(input.gitlabId);
|
const gitlabProvider = await findGitlabById(input.gitlabId);
|
||||||
if (IS_CLOUD && gitlabProvider.gitProvider.adminId !== ctx.user.adminId) {
|
if (IS_CLOUD && gitlabProvider.gitProvider.userId !== ctx.user.ownerId) {
|
||||||
//TODO: Remove this line when the cloud version is ready
|
//TODO: Remove this line when the cloud version is ready
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
@@ -140,7 +140,7 @@ export const gitlabRouter = createTRPCRouter({
|
|||||||
if (input.name) {
|
if (input.name) {
|
||||||
await updateGitProvider(input.gitProviderId, {
|
await updateGitProvider(input.gitProviderId, {
|
||||||
name: input.name,
|
name: input.name,
|
||||||
adminId: ctx.user.adminId,
|
userId: ctx.user.ownerId,
|
||||||
});
|
});
|
||||||
|
|
||||||
await updateGitlab(input.gitlabId, {
|
await updateGitlab(input.gitlabId, {
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ export const mariadbRouter = createTRPCRouter({
|
|||||||
}
|
}
|
||||||
|
|
||||||
const project = await findProjectById(input.projectId);
|
const project = await findProjectById(input.projectId);
|
||||||
if (project.adminId !== ctx.user.adminId) {
|
if (project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to access this project",
|
message: "You are not authorized to access this project",
|
||||||
@@ -83,7 +83,7 @@ export const mariadbRouter = createTRPCRouter({
|
|||||||
await checkServiceAccess(ctx.user.authId, input.mariadbId, "access");
|
await checkServiceAccess(ctx.user.authId, input.mariadbId, "access");
|
||||||
}
|
}
|
||||||
const mariadb = await findMariadbById(input.mariadbId);
|
const mariadb = await findMariadbById(input.mariadbId);
|
||||||
if (mariadb.project.adminId !== ctx.user.adminId) {
|
if (mariadb.project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to access this Mariadb",
|
message: "You are not authorized to access this Mariadb",
|
||||||
@@ -96,7 +96,7 @@ export const mariadbRouter = createTRPCRouter({
|
|||||||
.input(apiFindOneMariaDB)
|
.input(apiFindOneMariaDB)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
const service = await findMariadbById(input.mariadbId);
|
const service = await findMariadbById(input.mariadbId);
|
||||||
if (service.project.adminId !== ctx.user.adminId) {
|
if (service.project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to start this Mariadb",
|
message: "You are not authorized to start this Mariadb",
|
||||||
@@ -133,7 +133,7 @@ export const mariadbRouter = createTRPCRouter({
|
|||||||
.input(apiSaveExternalPortMariaDB)
|
.input(apiSaveExternalPortMariaDB)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
const mongo = await findMariadbById(input.mariadbId);
|
const mongo = await findMariadbById(input.mariadbId);
|
||||||
if (mongo.project.adminId !== ctx.user.adminId) {
|
if (mongo.project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to save this external port",
|
message: "You are not authorized to save this external port",
|
||||||
@@ -149,7 +149,7 @@ export const mariadbRouter = createTRPCRouter({
|
|||||||
.input(apiDeployMariaDB)
|
.input(apiDeployMariaDB)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
const mariadb = await findMariadbById(input.mariadbId);
|
const mariadb = await findMariadbById(input.mariadbId);
|
||||||
if (mariadb.project.adminId !== ctx.user.adminId) {
|
if (mariadb.project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to deploy this Mariadb",
|
message: "You are not authorized to deploy this Mariadb",
|
||||||
@@ -170,7 +170,7 @@ export const mariadbRouter = createTRPCRouter({
|
|||||||
.input(apiDeployMariaDB)
|
.input(apiDeployMariaDB)
|
||||||
.subscription(async ({ input, ctx }) => {
|
.subscription(async ({ input, ctx }) => {
|
||||||
const mariadb = await findMariadbById(input.mariadbId);
|
const mariadb = await findMariadbById(input.mariadbId);
|
||||||
if (mariadb.project.adminId !== ctx.user.adminId) {
|
if (mariadb.project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to deploy this Mariadb",
|
message: "You are not authorized to deploy this Mariadb",
|
||||||
@@ -187,7 +187,7 @@ export const mariadbRouter = createTRPCRouter({
|
|||||||
.input(apiChangeMariaDBStatus)
|
.input(apiChangeMariaDBStatus)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
const mongo = await findMariadbById(input.mariadbId);
|
const mongo = await findMariadbById(input.mariadbId);
|
||||||
if (mongo.project.adminId !== ctx.user.adminId) {
|
if (mongo.project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to change this Mariadb status",
|
message: "You are not authorized to change this Mariadb status",
|
||||||
@@ -206,7 +206,7 @@ export const mariadbRouter = createTRPCRouter({
|
|||||||
}
|
}
|
||||||
|
|
||||||
const mongo = await findMariadbById(input.mariadbId);
|
const mongo = await findMariadbById(input.mariadbId);
|
||||||
if (mongo.project.adminId !== ctx.user.adminId) {
|
if (mongo.project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to delete this Mariadb",
|
message: "You are not authorized to delete this Mariadb",
|
||||||
@@ -232,7 +232,7 @@ export const mariadbRouter = createTRPCRouter({
|
|||||||
.input(apiSaveEnvironmentVariablesMariaDB)
|
.input(apiSaveEnvironmentVariablesMariaDB)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
const mariadb = await findMariadbById(input.mariadbId);
|
const mariadb = await findMariadbById(input.mariadbId);
|
||||||
if (mariadb.project.adminId !== ctx.user.adminId) {
|
if (mariadb.project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to save this environment",
|
message: "You are not authorized to save this environment",
|
||||||
@@ -255,7 +255,7 @@ export const mariadbRouter = createTRPCRouter({
|
|||||||
.input(apiResetMariadb)
|
.input(apiResetMariadb)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
const mariadb = await findMariadbById(input.mariadbId);
|
const mariadb = await findMariadbById(input.mariadbId);
|
||||||
if (mariadb.project.adminId !== ctx.user.adminId) {
|
if (mariadb.project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to reload this Mariadb",
|
message: "You are not authorized to reload this Mariadb",
|
||||||
@@ -285,7 +285,7 @@ export const mariadbRouter = createTRPCRouter({
|
|||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
const { mariadbId, ...rest } = input;
|
const { mariadbId, ...rest } = input;
|
||||||
const mariadb = await findMariadbById(mariadbId);
|
const mariadb = await findMariadbById(mariadbId);
|
||||||
if (mariadb.project.adminId !== ctx.user.adminId) {
|
if (mariadb.project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to update this Mariadb",
|
message: "You are not authorized to update this Mariadb",
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ export const mongoRouter = createTRPCRouter({
|
|||||||
}
|
}
|
||||||
|
|
||||||
const project = await findProjectById(input.projectId);
|
const project = await findProjectById(input.projectId);
|
||||||
if (project.adminId !== ctx.user.adminId) {
|
if (project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to access this project",
|
message: "You are not authorized to access this project",
|
||||||
@@ -87,7 +87,7 @@ export const mongoRouter = createTRPCRouter({
|
|||||||
}
|
}
|
||||||
|
|
||||||
const mongo = await findMongoById(input.mongoId);
|
const mongo = await findMongoById(input.mongoId);
|
||||||
if (mongo.project.adminId !== ctx.user.adminId) {
|
if (mongo.project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to access this mongo",
|
message: "You are not authorized to access this mongo",
|
||||||
@@ -101,7 +101,7 @@ export const mongoRouter = createTRPCRouter({
|
|||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
const service = await findMongoById(input.mongoId);
|
const service = await findMongoById(input.mongoId);
|
||||||
|
|
||||||
if (service.project.adminId !== ctx.user.adminId) {
|
if (service.project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to start this mongo",
|
message: "You are not authorized to start this mongo",
|
||||||
@@ -124,7 +124,7 @@ export const mongoRouter = createTRPCRouter({
|
|||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
const mongo = await findMongoById(input.mongoId);
|
const mongo = await findMongoById(input.mongoId);
|
||||||
|
|
||||||
if (mongo.project.adminId !== ctx.user.adminId) {
|
if (mongo.project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to stop this mongo",
|
message: "You are not authorized to stop this mongo",
|
||||||
@@ -146,7 +146,7 @@ export const mongoRouter = createTRPCRouter({
|
|||||||
.input(apiSaveExternalPortMongo)
|
.input(apiSaveExternalPortMongo)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
const mongo = await findMongoById(input.mongoId);
|
const mongo = await findMongoById(input.mongoId);
|
||||||
if (mongo.project.adminId !== ctx.user.adminId) {
|
if (mongo.project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to save this external port",
|
message: "You are not authorized to save this external port",
|
||||||
@@ -162,7 +162,7 @@ export const mongoRouter = createTRPCRouter({
|
|||||||
.input(apiDeployMongo)
|
.input(apiDeployMongo)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
const mongo = await findMongoById(input.mongoId);
|
const mongo = await findMongoById(input.mongoId);
|
||||||
if (mongo.project.adminId !== ctx.user.adminId) {
|
if (mongo.project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to deploy this mongo",
|
message: "You are not authorized to deploy this mongo",
|
||||||
@@ -182,7 +182,7 @@ export const mongoRouter = createTRPCRouter({
|
|||||||
.input(apiDeployMongo)
|
.input(apiDeployMongo)
|
||||||
.subscription(async ({ input, ctx }) => {
|
.subscription(async ({ input, ctx }) => {
|
||||||
const mongo = await findMongoById(input.mongoId);
|
const mongo = await findMongoById(input.mongoId);
|
||||||
if (mongo.project.adminId !== ctx.user.adminId) {
|
if (mongo.project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to deploy this mongo",
|
message: "You are not authorized to deploy this mongo",
|
||||||
@@ -199,7 +199,7 @@ export const mongoRouter = createTRPCRouter({
|
|||||||
.input(apiChangeMongoStatus)
|
.input(apiChangeMongoStatus)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
const mongo = await findMongoById(input.mongoId);
|
const mongo = await findMongoById(input.mongoId);
|
||||||
if (mongo.project.adminId !== ctx.user.adminId) {
|
if (mongo.project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to change this mongo status",
|
message: "You are not authorized to change this mongo status",
|
||||||
@@ -214,7 +214,7 @@ export const mongoRouter = createTRPCRouter({
|
|||||||
.input(apiResetMongo)
|
.input(apiResetMongo)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
const mongo = await findMongoById(input.mongoId);
|
const mongo = await findMongoById(input.mongoId);
|
||||||
if (mongo.project.adminId !== ctx.user.adminId) {
|
if (mongo.project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to reload this mongo",
|
message: "You are not authorized to reload this mongo",
|
||||||
@@ -248,7 +248,7 @@ export const mongoRouter = createTRPCRouter({
|
|||||||
|
|
||||||
const mongo = await findMongoById(input.mongoId);
|
const mongo = await findMongoById(input.mongoId);
|
||||||
|
|
||||||
if (mongo.project.adminId !== ctx.user.adminId) {
|
if (mongo.project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to delete this mongo",
|
message: "You are not authorized to delete this mongo",
|
||||||
@@ -274,7 +274,7 @@ export const mongoRouter = createTRPCRouter({
|
|||||||
.input(apiSaveEnvironmentVariablesMongo)
|
.input(apiSaveEnvironmentVariablesMongo)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
const mongo = await findMongoById(input.mongoId);
|
const mongo = await findMongoById(input.mongoId);
|
||||||
if (mongo.project.adminId !== ctx.user.adminId) {
|
if (mongo.project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to save this environment",
|
message: "You are not authorized to save this environment",
|
||||||
@@ -298,7 +298,7 @@ export const mongoRouter = createTRPCRouter({
|
|||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
const { mongoId, ...rest } = input;
|
const { mongoId, ...rest } = input;
|
||||||
const mongo = await findMongoById(mongoId);
|
const mongo = await findMongoById(mongoId);
|
||||||
if (mongo.project.adminId !== ctx.user.adminId) {
|
if (mongo.project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to update this mongo",
|
message: "You are not authorized to update this mongo",
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ export const mysqlRouter = createTRPCRouter({
|
|||||||
}
|
}
|
||||||
1;
|
1;
|
||||||
const project = await findProjectById(input.projectId);
|
const project = await findProjectById(input.projectId);
|
||||||
if (project.adminId !== ctx.user.adminId) {
|
if (project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to access this project",
|
message: "You are not authorized to access this project",
|
||||||
@@ -89,7 +89,7 @@ export const mysqlRouter = createTRPCRouter({
|
|||||||
await checkServiceAccess(ctx.user.authId, input.mysqlId, "access");
|
await checkServiceAccess(ctx.user.authId, input.mysqlId, "access");
|
||||||
}
|
}
|
||||||
const mysql = await findMySqlById(input.mysqlId);
|
const mysql = await findMySqlById(input.mysqlId);
|
||||||
if (mysql.project.adminId !== ctx.user.adminId) {
|
if (mysql.project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to access this MySQL",
|
message: "You are not authorized to access this MySQL",
|
||||||
@@ -102,7 +102,7 @@ export const mysqlRouter = createTRPCRouter({
|
|||||||
.input(apiFindOneMySql)
|
.input(apiFindOneMySql)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
const service = await findMySqlById(input.mysqlId);
|
const service = await findMySqlById(input.mysqlId);
|
||||||
if (service.project.adminId !== ctx.user.adminId) {
|
if (service.project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to start this MySQL",
|
message: "You are not authorized to start this MySQL",
|
||||||
@@ -124,7 +124,7 @@ export const mysqlRouter = createTRPCRouter({
|
|||||||
.input(apiFindOneMySql)
|
.input(apiFindOneMySql)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
const mongo = await findMySqlById(input.mysqlId);
|
const mongo = await findMySqlById(input.mysqlId);
|
||||||
if (mongo.project.adminId !== ctx.user.adminId) {
|
if (mongo.project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to stop this MySQL",
|
message: "You are not authorized to stop this MySQL",
|
||||||
@@ -145,7 +145,7 @@ export const mysqlRouter = createTRPCRouter({
|
|||||||
.input(apiSaveExternalPortMySql)
|
.input(apiSaveExternalPortMySql)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
const mongo = await findMySqlById(input.mysqlId);
|
const mongo = await findMySqlById(input.mysqlId);
|
||||||
if (mongo.project.adminId !== ctx.user.adminId) {
|
if (mongo.project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to save this external port",
|
message: "You are not authorized to save this external port",
|
||||||
@@ -161,7 +161,7 @@ export const mysqlRouter = createTRPCRouter({
|
|||||||
.input(apiDeployMySql)
|
.input(apiDeployMySql)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
const mysql = await findMySqlById(input.mysqlId);
|
const mysql = await findMySqlById(input.mysqlId);
|
||||||
if (mysql.project.adminId !== ctx.user.adminId) {
|
if (mysql.project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to deploy this MySQL",
|
message: "You are not authorized to deploy this MySQL",
|
||||||
@@ -181,7 +181,7 @@ export const mysqlRouter = createTRPCRouter({
|
|||||||
.input(apiDeployMySql)
|
.input(apiDeployMySql)
|
||||||
.subscription(async ({ input, ctx }) => {
|
.subscription(async ({ input, ctx }) => {
|
||||||
const mysql = await findMySqlById(input.mysqlId);
|
const mysql = await findMySqlById(input.mysqlId);
|
||||||
if (mysql.project.adminId !== ctx.user.adminId) {
|
if (mysql.project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to deploy this MySQL",
|
message: "You are not authorized to deploy this MySQL",
|
||||||
@@ -198,7 +198,7 @@ export const mysqlRouter = createTRPCRouter({
|
|||||||
.input(apiChangeMySqlStatus)
|
.input(apiChangeMySqlStatus)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
const mongo = await findMySqlById(input.mysqlId);
|
const mongo = await findMySqlById(input.mysqlId);
|
||||||
if (mongo.project.adminId !== ctx.user.adminId) {
|
if (mongo.project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to change this MySQL status",
|
message: "You are not authorized to change this MySQL status",
|
||||||
@@ -213,7 +213,7 @@ export const mysqlRouter = createTRPCRouter({
|
|||||||
.input(apiResetMysql)
|
.input(apiResetMysql)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
const mysql = await findMySqlById(input.mysqlId);
|
const mysql = await findMySqlById(input.mysqlId);
|
||||||
if (mysql.project.adminId !== ctx.user.adminId) {
|
if (mysql.project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to reload this MySQL",
|
message: "You are not authorized to reload this MySQL",
|
||||||
@@ -244,7 +244,7 @@ export const mysqlRouter = createTRPCRouter({
|
|||||||
await checkServiceAccess(ctx.user.authId, input.mysqlId, "delete");
|
await checkServiceAccess(ctx.user.authId, input.mysqlId, "delete");
|
||||||
}
|
}
|
||||||
const mongo = await findMySqlById(input.mysqlId);
|
const mongo = await findMySqlById(input.mysqlId);
|
||||||
if (mongo.project.adminId !== ctx.user.adminId) {
|
if (mongo.project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to delete this MySQL",
|
message: "You are not authorized to delete this MySQL",
|
||||||
@@ -270,7 +270,7 @@ export const mysqlRouter = createTRPCRouter({
|
|||||||
.input(apiSaveEnvironmentVariablesMySql)
|
.input(apiSaveEnvironmentVariablesMySql)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
const mysql = await findMySqlById(input.mysqlId);
|
const mysql = await findMySqlById(input.mysqlId);
|
||||||
if (mysql.project.adminId !== ctx.user.adminId) {
|
if (mysql.project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to save this environment",
|
message: "You are not authorized to save this environment",
|
||||||
@@ -294,7 +294,7 @@ export const mysqlRouter = createTRPCRouter({
|
|||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
const { mysqlId, ...rest } = input;
|
const { mysqlId, ...rest } = input;
|
||||||
const mysql = await findMySqlById(mysqlId);
|
const mysql = await findMySqlById(mysqlId);
|
||||||
if (mysql.project.adminId !== ctx.user.adminId) {
|
if (mysql.project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to update this MySQL",
|
message: "You are not authorized to update this MySQL",
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import {
|
|||||||
} from "@/server/api/trpc";
|
} from "@/server/api/trpc";
|
||||||
import { db } from "@/server/db";
|
import { db } from "@/server/db";
|
||||||
import {
|
import {
|
||||||
admins,
|
|
||||||
apiCreateDiscord,
|
apiCreateDiscord,
|
||||||
apiCreateEmail,
|
apiCreateEmail,
|
||||||
apiCreateGotify,
|
apiCreateGotify,
|
||||||
@@ -25,6 +24,7 @@ import {
|
|||||||
apiUpdateTelegram,
|
apiUpdateTelegram,
|
||||||
notifications,
|
notifications,
|
||||||
server,
|
server,
|
||||||
|
users_temp,
|
||||||
} from "@/server/db/schema";
|
} from "@/server/db/schema";
|
||||||
import {
|
import {
|
||||||
IS_CLOUD,
|
IS_CLOUD,
|
||||||
@@ -57,7 +57,7 @@ export const notificationRouter = createTRPCRouter({
|
|||||||
.input(apiCreateSlack)
|
.input(apiCreateSlack)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
try {
|
try {
|
||||||
return await createSlackNotification(input, ctx.user.adminId);
|
return await createSlackNotification(input, ctx.user.ownerId);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "BAD_REQUEST",
|
code: "BAD_REQUEST",
|
||||||
@@ -71,7 +71,7 @@ export const notificationRouter = createTRPCRouter({
|
|||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
try {
|
try {
|
||||||
const notification = await findNotificationById(input.notificationId);
|
const notification = await findNotificationById(input.notificationId);
|
||||||
if (IS_CLOUD && notification.adminId !== ctx.user.adminId) {
|
if (IS_CLOUD && notification.userId !== ctx.user.ownerId) {
|
||||||
// TODO: Remove isCloud in the next versions of dokploy
|
// TODO: Remove isCloud in the next versions of dokploy
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
@@ -80,7 +80,7 @@ export const notificationRouter = createTRPCRouter({
|
|||||||
}
|
}
|
||||||
return await updateSlackNotification({
|
return await updateSlackNotification({
|
||||||
...input,
|
...input,
|
||||||
adminId: ctx.user.adminId,
|
userId: ctx.user.ownerId,
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw error;
|
throw error;
|
||||||
@@ -107,7 +107,7 @@ export const notificationRouter = createTRPCRouter({
|
|||||||
.input(apiCreateTelegram)
|
.input(apiCreateTelegram)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
try {
|
try {
|
||||||
return await createTelegramNotification(input, ctx.user.adminId);
|
return await createTelegramNotification(input, ctx.user.ownerId);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "BAD_REQUEST",
|
code: "BAD_REQUEST",
|
||||||
@@ -122,7 +122,7 @@ export const notificationRouter = createTRPCRouter({
|
|||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
try {
|
try {
|
||||||
const notification = await findNotificationById(input.notificationId);
|
const notification = await findNotificationById(input.notificationId);
|
||||||
if (IS_CLOUD && notification.adminId !== ctx.user.adminId) {
|
if (IS_CLOUD && notification.userId !== ctx.user.ownerId) {
|
||||||
// TODO: Remove isCloud in the next versions of dokploy
|
// TODO: Remove isCloud in the next versions of dokploy
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
@@ -131,7 +131,7 @@ export const notificationRouter = createTRPCRouter({
|
|||||||
}
|
}
|
||||||
return await updateTelegramNotification({
|
return await updateTelegramNotification({
|
||||||
...input,
|
...input,
|
||||||
adminId: ctx.user.adminId,
|
userId: ctx.user.ownerId,
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
@@ -159,7 +159,7 @@ export const notificationRouter = createTRPCRouter({
|
|||||||
.input(apiCreateDiscord)
|
.input(apiCreateDiscord)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
try {
|
try {
|
||||||
return await createDiscordNotification(input, ctx.user.adminId);
|
return await createDiscordNotification(input, ctx.user.ownerId);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "BAD_REQUEST",
|
code: "BAD_REQUEST",
|
||||||
@@ -174,7 +174,7 @@ export const notificationRouter = createTRPCRouter({
|
|||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
try {
|
try {
|
||||||
const notification = await findNotificationById(input.notificationId);
|
const notification = await findNotificationById(input.notificationId);
|
||||||
if (IS_CLOUD && notification.adminId !== ctx.user.adminId) {
|
if (IS_CLOUD && notification.userId !== ctx.user.ownerId) {
|
||||||
// TODO: Remove isCloud in the next versions of dokploy
|
// TODO: Remove isCloud in the next versions of dokploy
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
@@ -183,7 +183,7 @@ export const notificationRouter = createTRPCRouter({
|
|||||||
}
|
}
|
||||||
return await updateDiscordNotification({
|
return await updateDiscordNotification({
|
||||||
...input,
|
...input,
|
||||||
adminId: ctx.user.adminId,
|
userId: ctx.user.ownerId,
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
@@ -220,7 +220,7 @@ export const notificationRouter = createTRPCRouter({
|
|||||||
.input(apiCreateEmail)
|
.input(apiCreateEmail)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
try {
|
try {
|
||||||
return await createEmailNotification(input, ctx.user.adminId);
|
return await createEmailNotification(input, ctx.user.ownerId);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "BAD_REQUEST",
|
code: "BAD_REQUEST",
|
||||||
@@ -234,7 +234,7 @@ export const notificationRouter = createTRPCRouter({
|
|||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
try {
|
try {
|
||||||
const notification = await findNotificationById(input.notificationId);
|
const notification = await findNotificationById(input.notificationId);
|
||||||
if (IS_CLOUD && notification.adminId !== ctx.user.adminId) {
|
if (IS_CLOUD && notification.userId !== ctx.user.ownerId) {
|
||||||
// TODO: Remove isCloud in the next versions of dokploy
|
// TODO: Remove isCloud in the next versions of dokploy
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
@@ -243,7 +243,7 @@ export const notificationRouter = createTRPCRouter({
|
|||||||
}
|
}
|
||||||
return await updateEmailNotification({
|
return await updateEmailNotification({
|
||||||
...input,
|
...input,
|
||||||
adminId: ctx.user.adminId,
|
userId: ctx.user.ownerId,
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
@@ -276,7 +276,7 @@ export const notificationRouter = createTRPCRouter({
|
|||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
try {
|
try {
|
||||||
const notification = await findNotificationById(input.notificationId);
|
const notification = await findNotificationById(input.notificationId);
|
||||||
if (IS_CLOUD && notification.adminId !== ctx.user.adminId) {
|
if (IS_CLOUD && notification.userId !== ctx.user.ownerId) {
|
||||||
// TODO: Remove isCloud in the next versions of dokploy
|
// TODO: Remove isCloud in the next versions of dokploy
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
@@ -295,7 +295,7 @@ export const notificationRouter = createTRPCRouter({
|
|||||||
.input(apiFindOneNotification)
|
.input(apiFindOneNotification)
|
||||||
.query(async ({ input, ctx }) => {
|
.query(async ({ input, ctx }) => {
|
||||||
const notification = await findNotificationById(input.notificationId);
|
const notification = await findNotificationById(input.notificationId);
|
||||||
if (IS_CLOUD && notification.adminId !== ctx.user.adminId) {
|
if (IS_CLOUD && notification.userId !== ctx.user.ownerId) {
|
||||||
// TODO: Remove isCloud in the next versions of dokploy
|
// TODO: Remove isCloud in the next versions of dokploy
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
@@ -314,7 +314,7 @@ export const notificationRouter = createTRPCRouter({
|
|||||||
gotify: true,
|
gotify: true,
|
||||||
},
|
},
|
||||||
orderBy: desc(notifications.createdAt),
|
orderBy: desc(notifications.createdAt),
|
||||||
...(IS_CLOUD && { where: eq(notifications.adminId, ctx.user.adminId) }),
|
...(IS_CLOUD && { where: eq(notifications.userId, ctx.user.ownerId) }),
|
||||||
// TODO: Remove this line when the cloud version is ready
|
// TODO: Remove this line when the cloud version is ready
|
||||||
});
|
});
|
||||||
}),
|
}),
|
||||||
@@ -332,24 +332,24 @@ export const notificationRouter = createTRPCRouter({
|
|||||||
)
|
)
|
||||||
.mutation(async ({ input }) => {
|
.mutation(async ({ input }) => {
|
||||||
try {
|
try {
|
||||||
let adminId = "";
|
let userId = "";
|
||||||
let ServerName = "";
|
let ServerName = "";
|
||||||
if (input.ServerType === "Dokploy") {
|
if (input.ServerType === "Dokploy") {
|
||||||
const result = await db
|
const result = await db
|
||||||
.select()
|
.select()
|
||||||
.from(admins)
|
.from(users_temp)
|
||||||
.where(
|
.where(
|
||||||
sql`${admins.metricsConfig}::jsonb -> 'server' ->> 'token' = ${input.Token}`,
|
sql`${users_temp.metricsConfig}::jsonb -> 'server' ->> 'token' = ${input.Token}`,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!result?.[0]?.adminId) {
|
if (!result?.[0]?.id) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "BAD_REQUEST",
|
code: "BAD_REQUEST",
|
||||||
message: "Token not found",
|
message: "Token not found",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
adminId = result?.[0]?.adminId;
|
userId = result?.[0]?.id;
|
||||||
ServerName = "Dokploy";
|
ServerName = "Dokploy";
|
||||||
} else {
|
} else {
|
||||||
const result = await db
|
const result = await db
|
||||||
@@ -359,18 +359,18 @@ export const notificationRouter = createTRPCRouter({
|
|||||||
sql`${server.metricsConfig}::jsonb -> 'server' ->> 'token' = ${input.Token}`,
|
sql`${server.metricsConfig}::jsonb -> 'server' ->> 'token' = ${input.Token}`,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!result?.[0]?.adminId) {
|
if (!result?.[0]?.userId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "BAD_REQUEST",
|
code: "BAD_REQUEST",
|
||||||
message: "Token not found",
|
message: "Token not found",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
adminId = result?.[0]?.adminId;
|
userId = result?.[0]?.userId;
|
||||||
ServerName = "Remote";
|
ServerName = "Remote";
|
||||||
}
|
}
|
||||||
|
|
||||||
await sendServerThresholdNotifications(adminId, {
|
await sendServerThresholdNotifications(userId, {
|
||||||
...input,
|
...input,
|
||||||
ServerName,
|
ServerName,
|
||||||
});
|
});
|
||||||
@@ -386,7 +386,7 @@ export const notificationRouter = createTRPCRouter({
|
|||||||
.input(apiCreateGotify)
|
.input(apiCreateGotify)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
try {
|
try {
|
||||||
return await createGotifyNotification(input, ctx.user.adminId);
|
return await createGotifyNotification(input, ctx.user.ownerId);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "BAD_REQUEST",
|
code: "BAD_REQUEST",
|
||||||
@@ -400,7 +400,7 @@ export const notificationRouter = createTRPCRouter({
|
|||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
try {
|
try {
|
||||||
const notification = await findNotificationById(input.notificationId);
|
const notification = await findNotificationById(input.notificationId);
|
||||||
if (IS_CLOUD && notification.adminId !== ctx.user.adminId) {
|
if (IS_CLOUD && notification.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to update this notification",
|
message: "You are not authorized to update this notification",
|
||||||
@@ -408,7 +408,7 @@ export const notificationRouter = createTRPCRouter({
|
|||||||
}
|
}
|
||||||
return await updateGotifyNotification({
|
return await updateGotifyNotification({
|
||||||
...input,
|
...input,
|
||||||
adminId: ctx.user.adminId,
|
userId: ctx.user.ownerId,
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw error;
|
throw error;
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ export const postgresRouter = createTRPCRouter({
|
|||||||
}
|
}
|
||||||
|
|
||||||
const project = await findProjectById(input.projectId);
|
const project = await findProjectById(input.projectId);
|
||||||
if (project.adminId !== ctx.user.adminId) {
|
if (project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to access this project",
|
message: "You are not authorized to access this project",
|
||||||
@@ -95,7 +95,7 @@ export const postgresRouter = createTRPCRouter({
|
|||||||
}
|
}
|
||||||
|
|
||||||
const postgres = await findPostgresById(input.postgresId);
|
const postgres = await findPostgresById(input.postgresId);
|
||||||
if (postgres.project.adminId !== ctx.user.adminId) {
|
if (postgres.project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to access this Postgres",
|
message: "You are not authorized to access this Postgres",
|
||||||
@@ -109,7 +109,7 @@ export const postgresRouter = createTRPCRouter({
|
|||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
const service = await findPostgresById(input.postgresId);
|
const service = await findPostgresById(input.postgresId);
|
||||||
|
|
||||||
if (service.project.adminId !== ctx.user.adminId) {
|
if (service.project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to start this Postgres",
|
message: "You are not authorized to start this Postgres",
|
||||||
@@ -131,7 +131,7 @@ export const postgresRouter = createTRPCRouter({
|
|||||||
.input(apiFindOnePostgres)
|
.input(apiFindOnePostgres)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
const postgres = await findPostgresById(input.postgresId);
|
const postgres = await findPostgresById(input.postgresId);
|
||||||
if (postgres.project.adminId !== ctx.user.adminId) {
|
if (postgres.project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to stop this Postgres",
|
message: "You are not authorized to stop this Postgres",
|
||||||
@@ -153,7 +153,7 @@ export const postgresRouter = createTRPCRouter({
|
|||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
const postgres = await findPostgresById(input.postgresId);
|
const postgres = await findPostgresById(input.postgresId);
|
||||||
|
|
||||||
if (postgres.project.adminId !== ctx.user.adminId) {
|
if (postgres.project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to save this external port",
|
message: "You are not authorized to save this external port",
|
||||||
@@ -169,7 +169,7 @@ export const postgresRouter = createTRPCRouter({
|
|||||||
.input(apiDeployPostgres)
|
.input(apiDeployPostgres)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
const postgres = await findPostgresById(input.postgresId);
|
const postgres = await findPostgresById(input.postgresId);
|
||||||
if (postgres.project.adminId !== ctx.user.adminId) {
|
if (postgres.project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to deploy this Postgres",
|
message: "You are not authorized to deploy this Postgres",
|
||||||
@@ -190,7 +190,7 @@ export const postgresRouter = createTRPCRouter({
|
|||||||
.input(apiDeployPostgres)
|
.input(apiDeployPostgres)
|
||||||
.subscription(async ({ input, ctx }) => {
|
.subscription(async ({ input, ctx }) => {
|
||||||
const postgres = await findPostgresById(input.postgresId);
|
const postgres = await findPostgresById(input.postgresId);
|
||||||
if (postgres.project.adminId !== ctx.user.adminId) {
|
if (postgres.project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to deploy this Postgres",
|
message: "You are not authorized to deploy this Postgres",
|
||||||
@@ -207,7 +207,7 @@ export const postgresRouter = createTRPCRouter({
|
|||||||
.input(apiChangePostgresStatus)
|
.input(apiChangePostgresStatus)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
const postgres = await findPostgresById(input.postgresId);
|
const postgres = await findPostgresById(input.postgresId);
|
||||||
if (postgres.project.adminId !== ctx.user.adminId) {
|
if (postgres.project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to change this Postgres status",
|
message: "You are not authorized to change this Postgres status",
|
||||||
@@ -226,7 +226,7 @@ export const postgresRouter = createTRPCRouter({
|
|||||||
}
|
}
|
||||||
const postgres = await findPostgresById(input.postgresId);
|
const postgres = await findPostgresById(input.postgresId);
|
||||||
|
|
||||||
if (postgres.project.adminId !== ctx.user.adminId) {
|
if (postgres.project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to delete this Postgres",
|
message: "You are not authorized to delete this Postgres",
|
||||||
@@ -249,7 +249,7 @@ export const postgresRouter = createTRPCRouter({
|
|||||||
.input(apiSaveEnvironmentVariablesPostgres)
|
.input(apiSaveEnvironmentVariablesPostgres)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
const postgres = await findPostgresById(input.postgresId);
|
const postgres = await findPostgresById(input.postgresId);
|
||||||
if (postgres.project.adminId !== ctx.user.adminId) {
|
if (postgres.project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to save this environment",
|
message: "You are not authorized to save this environment",
|
||||||
@@ -272,7 +272,7 @@ export const postgresRouter = createTRPCRouter({
|
|||||||
.input(apiResetPostgres)
|
.input(apiResetPostgres)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
const postgres = await findPostgresById(input.postgresId);
|
const postgres = await findPostgresById(input.postgresId);
|
||||||
if (postgres.project.adminId !== ctx.user.adminId) {
|
if (postgres.project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to reload this Postgres",
|
message: "You are not authorized to reload this Postgres",
|
||||||
@@ -302,7 +302,7 @@ export const postgresRouter = createTRPCRouter({
|
|||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
const { postgresId, ...rest } = input;
|
const { postgresId, ...rest } = input;
|
||||||
const postgres = await findPostgresById(postgresId);
|
const postgres = await findPostgresById(postgresId);
|
||||||
if (postgres.project.adminId !== ctx.user.adminId) {
|
if (postgres.project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to update this Postgres",
|
message: "You are not authorized to update this Postgres",
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ export const previewDeploymentRouter = createTRPCRouter({
|
|||||||
.input(apiFindAllByApplication)
|
.input(apiFindAllByApplication)
|
||||||
.query(async ({ input, ctx }) => {
|
.query(async ({ input, ctx }) => {
|
||||||
const application = await findApplicationById(input.applicationId);
|
const application = await findApplicationById(input.applicationId);
|
||||||
if (application.project.adminId !== ctx.user.adminId) {
|
if (application.project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to access this application",
|
message: "You are not authorized to access this application",
|
||||||
@@ -28,7 +28,7 @@ export const previewDeploymentRouter = createTRPCRouter({
|
|||||||
const previewDeployment = await findPreviewDeploymentById(
|
const previewDeployment = await findPreviewDeploymentById(
|
||||||
input.previewDeploymentId,
|
input.previewDeploymentId,
|
||||||
);
|
);
|
||||||
if (previewDeployment.application.project.adminId !== ctx.user.adminId) {
|
if (previewDeployment.application.project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to delete this preview deployment",
|
message: "You are not authorized to delete this preview deployment",
|
||||||
@@ -43,7 +43,7 @@ export const previewDeploymentRouter = createTRPCRouter({
|
|||||||
const previewDeployment = await findPreviewDeploymentById(
|
const previewDeployment = await findPreviewDeploymentById(
|
||||||
input.previewDeploymentId,
|
input.previewDeploymentId,
|
||||||
);
|
);
|
||||||
if (previewDeployment.application.project.adminId !== ctx.user.adminId) {
|
if (previewDeployment.application.project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to access this preview deployment",
|
message: "You are not authorized to access this preview deployment",
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ export const projectRouter = createTRPCRouter({
|
|||||||
const project = await db.query.projects.findFirst({
|
const project = await db.query.projects.findFirst({
|
||||||
where: and(
|
where: and(
|
||||||
eq(projects.projectId, input.projectId),
|
eq(projects.projectId, input.projectId),
|
||||||
eq(projects.adminId, ctx.user.adminId),
|
eq(projects.userId, ctx.user.ownerId),
|
||||||
),
|
),
|
||||||
with: {
|
with: {
|
||||||
compose: {
|
compose: {
|
||||||
@@ -115,7 +115,7 @@ export const projectRouter = createTRPCRouter({
|
|||||||
}
|
}
|
||||||
const project = await findProjectById(input.projectId);
|
const project = await findProjectById(input.projectId);
|
||||||
|
|
||||||
if (project.adminId !== ctx.user.adminId) {
|
if (project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to access this project",
|
message: "You are not authorized to access this project",
|
||||||
@@ -207,7 +207,7 @@ export const projectRouter = createTRPCRouter({
|
|||||||
await checkProjectAccess(ctx.user.authId, "delete");
|
await checkProjectAccess(ctx.user.authId, "delete");
|
||||||
}
|
}
|
||||||
const currentProject = await findProjectById(input.projectId);
|
const currentProject = await findProjectById(input.projectId);
|
||||||
if (currentProject.adminId !== ctx.user.adminId) {
|
if (currentProject.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to delete this project",
|
message: "You are not authorized to delete this project",
|
||||||
@@ -225,7 +225,7 @@ export const projectRouter = createTRPCRouter({
|
|||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
try {
|
try {
|
||||||
const currentProject = await findProjectById(input.projectId);
|
const currentProject = await findProjectById(input.projectId);
|
||||||
if (currentProject.adminId !== ctx.user.adminId) {
|
if (currentProject.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to update this project",
|
message: "You are not authorized to update this project",
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ export const redirectsRouter = createTRPCRouter({
|
|||||||
.input(apiCreateRedirect)
|
.input(apiCreateRedirect)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
const application = await findApplicationById(input.applicationId);
|
const application = await findApplicationById(input.applicationId);
|
||||||
if (application.project.adminId !== ctx.user.adminId) {
|
if (application.project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to access this application",
|
message: "You are not authorized to access this application",
|
||||||
@@ -31,7 +31,7 @@ export const redirectsRouter = createTRPCRouter({
|
|||||||
.query(async ({ input, ctx }) => {
|
.query(async ({ input, ctx }) => {
|
||||||
const redirect = await findRedirectById(input.redirectId);
|
const redirect = await findRedirectById(input.redirectId);
|
||||||
const application = await findApplicationById(redirect.applicationId);
|
const application = await findApplicationById(redirect.applicationId);
|
||||||
if (application.project.adminId !== ctx.user.adminId) {
|
if (application.project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to access this application",
|
message: "You are not authorized to access this application",
|
||||||
@@ -44,7 +44,7 @@ export const redirectsRouter = createTRPCRouter({
|
|||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
const redirect = await findRedirectById(input.redirectId);
|
const redirect = await findRedirectById(input.redirectId);
|
||||||
const application = await findApplicationById(redirect.applicationId);
|
const application = await findApplicationById(redirect.applicationId);
|
||||||
if (application.project.adminId !== ctx.user.adminId) {
|
if (application.project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to access this application",
|
message: "You are not authorized to access this application",
|
||||||
@@ -57,7 +57,7 @@ export const redirectsRouter = createTRPCRouter({
|
|||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
const redirect = await findRedirectById(input.redirectId);
|
const redirect = await findRedirectById(input.redirectId);
|
||||||
const application = await findApplicationById(redirect.applicationId);
|
const application = await findApplicationById(redirect.applicationId);
|
||||||
if (application.project.adminId !== ctx.user.adminId) {
|
if (application.project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to access this application",
|
message: "You are not authorized to access this application",
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ export const redisRouter = createTRPCRouter({
|
|||||||
}
|
}
|
||||||
|
|
||||||
const project = await findProjectById(input.projectId);
|
const project = await findProjectById(input.projectId);
|
||||||
if (project.adminId !== ctx.user.adminId) {
|
if (project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to access this project",
|
message: "You are not authorized to access this project",
|
||||||
@@ -80,7 +80,7 @@ export const redisRouter = createTRPCRouter({
|
|||||||
}
|
}
|
||||||
|
|
||||||
const redis = await findRedisById(input.redisId);
|
const redis = await findRedisById(input.redisId);
|
||||||
if (redis.project.adminId !== ctx.user.adminId) {
|
if (redis.project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to access this Redis",
|
message: "You are not authorized to access this Redis",
|
||||||
@@ -93,7 +93,7 @@ export const redisRouter = createTRPCRouter({
|
|||||||
.input(apiFindOneRedis)
|
.input(apiFindOneRedis)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
const redis = await findRedisById(input.redisId);
|
const redis = await findRedisById(input.redisId);
|
||||||
if (redis.project.adminId !== ctx.user.adminId) {
|
if (redis.project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to start this Redis",
|
message: "You are not authorized to start this Redis",
|
||||||
@@ -115,7 +115,7 @@ export const redisRouter = createTRPCRouter({
|
|||||||
.input(apiResetRedis)
|
.input(apiResetRedis)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
const redis = await findRedisById(input.redisId);
|
const redis = await findRedisById(input.redisId);
|
||||||
if (redis.project.adminId !== ctx.user.adminId) {
|
if (redis.project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to reload this Redis",
|
message: "You are not authorized to reload this Redis",
|
||||||
@@ -145,7 +145,7 @@ export const redisRouter = createTRPCRouter({
|
|||||||
.input(apiFindOneRedis)
|
.input(apiFindOneRedis)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
const redis = await findRedisById(input.redisId);
|
const redis = await findRedisById(input.redisId);
|
||||||
if (redis.project.adminId !== ctx.user.adminId) {
|
if (redis.project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to stop this Redis",
|
message: "You are not authorized to stop this Redis",
|
||||||
@@ -166,7 +166,7 @@ export const redisRouter = createTRPCRouter({
|
|||||||
.input(apiSaveExternalPortRedis)
|
.input(apiSaveExternalPortRedis)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
const mongo = await findRedisById(input.redisId);
|
const mongo = await findRedisById(input.redisId);
|
||||||
if (mongo.project.adminId !== ctx.user.adminId) {
|
if (mongo.project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to save this external port",
|
message: "You are not authorized to save this external port",
|
||||||
@@ -182,7 +182,7 @@ export const redisRouter = createTRPCRouter({
|
|||||||
.input(apiDeployRedis)
|
.input(apiDeployRedis)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
const redis = await findRedisById(input.redisId);
|
const redis = await findRedisById(input.redisId);
|
||||||
if (redis.project.adminId !== ctx.user.adminId) {
|
if (redis.project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to deploy this Redis",
|
message: "You are not authorized to deploy this Redis",
|
||||||
@@ -202,7 +202,7 @@ export const redisRouter = createTRPCRouter({
|
|||||||
.input(apiDeployRedis)
|
.input(apiDeployRedis)
|
||||||
.subscription(async ({ input, ctx }) => {
|
.subscription(async ({ input, ctx }) => {
|
||||||
const redis = await findRedisById(input.redisId);
|
const redis = await findRedisById(input.redisId);
|
||||||
if (redis.project.adminId !== ctx.user.adminId) {
|
if (redis.project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to deploy this Redis",
|
message: "You are not authorized to deploy this Redis",
|
||||||
@@ -218,7 +218,7 @@ export const redisRouter = createTRPCRouter({
|
|||||||
.input(apiChangeRedisStatus)
|
.input(apiChangeRedisStatus)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
const mongo = await findRedisById(input.redisId);
|
const mongo = await findRedisById(input.redisId);
|
||||||
if (mongo.project.adminId !== ctx.user.adminId) {
|
if (mongo.project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to change this Redis status",
|
message: "You are not authorized to change this Redis status",
|
||||||
@@ -238,7 +238,7 @@ export const redisRouter = createTRPCRouter({
|
|||||||
|
|
||||||
const redis = await findRedisById(input.redisId);
|
const redis = await findRedisById(input.redisId);
|
||||||
|
|
||||||
if (redis.project.adminId !== ctx.user.adminId) {
|
if (redis.project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to delete this Redis",
|
message: "You are not authorized to delete this Redis",
|
||||||
@@ -261,7 +261,7 @@ export const redisRouter = createTRPCRouter({
|
|||||||
.input(apiSaveEnvironmentVariablesRedis)
|
.input(apiSaveEnvironmentVariablesRedis)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
const redis = await findRedisById(input.redisId);
|
const redis = await findRedisById(input.redisId);
|
||||||
if (redis.project.adminId !== ctx.user.adminId) {
|
if (redis.project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to save this environment",
|
message: "You are not authorized to save this environment",
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import {
|
|||||||
createRegistry,
|
createRegistry,
|
||||||
execAsync,
|
execAsync,
|
||||||
execAsyncRemote,
|
execAsyncRemote,
|
||||||
findAllRegistryByAdminId,
|
findAllRegistryByUserId,
|
||||||
findRegistryById,
|
findRegistryById,
|
||||||
removeRegistry,
|
removeRegistry,
|
||||||
updateRegistry,
|
updateRegistry,
|
||||||
@@ -22,13 +22,13 @@ export const registryRouter = createTRPCRouter({
|
|||||||
create: adminProcedure
|
create: adminProcedure
|
||||||
.input(apiCreateRegistry)
|
.input(apiCreateRegistry)
|
||||||
.mutation(async ({ ctx, input }) => {
|
.mutation(async ({ ctx, input }) => {
|
||||||
return await createRegistry(input, ctx.user.adminId);
|
return await createRegistry(input, ctx.user.ownerId);
|
||||||
}),
|
}),
|
||||||
remove: adminProcedure
|
remove: adminProcedure
|
||||||
.input(apiRemoveRegistry)
|
.input(apiRemoveRegistry)
|
||||||
.mutation(async ({ ctx, input }) => {
|
.mutation(async ({ ctx, input }) => {
|
||||||
const registry = await findRegistryById(input.registryId);
|
const registry = await findRegistryById(input.registryId);
|
||||||
if (registry.adminId !== ctx.user.adminId) {
|
if (registry.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not allowed to delete this registry",
|
message: "You are not allowed to delete this registry",
|
||||||
@@ -41,7 +41,7 @@ export const registryRouter = createTRPCRouter({
|
|||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
const { registryId, ...rest } = input;
|
const { registryId, ...rest } = input;
|
||||||
const registry = await findRegistryById(registryId);
|
const registry = await findRegistryById(registryId);
|
||||||
if (registry.adminId !== ctx.user.adminId) {
|
if (registry.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not allowed to update this registry",
|
message: "You are not allowed to update this registry",
|
||||||
@@ -61,13 +61,13 @@ export const registryRouter = createTRPCRouter({
|
|||||||
return true;
|
return true;
|
||||||
}),
|
}),
|
||||||
all: protectedProcedure.query(async ({ ctx }) => {
|
all: protectedProcedure.query(async ({ ctx }) => {
|
||||||
return await findAllRegistryByAdminId(ctx.user.adminId);
|
return await findAllRegistryByUserId(ctx.user.ownerId);
|
||||||
}),
|
}),
|
||||||
one: adminProcedure
|
one: adminProcedure
|
||||||
.input(apiFindOneRegistry)
|
.input(apiFindOneRegistry)
|
||||||
.query(async ({ input, ctx }) => {
|
.query(async ({ input, ctx }) => {
|
||||||
const registry = await findRegistryById(input.registryId);
|
const registry = await findRegistryById(input.registryId);
|
||||||
if (registry.adminId !== ctx.user.adminId) {
|
if (registry.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not allowed to access this registry",
|
message: "You are not allowed to access this registry",
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ export const securityRouter = createTRPCRouter({
|
|||||||
.input(apiCreateSecurity)
|
.input(apiCreateSecurity)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
const application = await findApplicationById(input.applicationId);
|
const application = await findApplicationById(input.applicationId);
|
||||||
if (application.project.adminId !== ctx.user.adminId) {
|
if (application.project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to access this application",
|
message: "You are not authorized to access this application",
|
||||||
@@ -31,7 +31,7 @@ export const securityRouter = createTRPCRouter({
|
|||||||
.query(async ({ input, ctx }) => {
|
.query(async ({ input, ctx }) => {
|
||||||
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 (application.project.adminId !== ctx.user.adminId) {
|
if (application.project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to access this application",
|
message: "You are not authorized to access this application",
|
||||||
@@ -44,7 +44,7 @@ export const securityRouter = createTRPCRouter({
|
|||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
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 (application.project.adminId !== ctx.user.adminId) {
|
if (application.project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to access this application",
|
message: "You are not authorized to access this application",
|
||||||
@@ -57,7 +57,7 @@ export const securityRouter = createTRPCRouter({
|
|||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
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 (application.project.adminId !== ctx.user.adminId) {
|
if (application.project.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to access this application",
|
message: "You are not authorized to access this application",
|
||||||
|
|||||||
@@ -21,9 +21,9 @@ import {
|
|||||||
createServer,
|
createServer,
|
||||||
defaultCommand,
|
defaultCommand,
|
||||||
deleteServer,
|
deleteServer,
|
||||||
findAdminById,
|
|
||||||
findServerById,
|
findServerById,
|
||||||
findServersByAdminId,
|
findServersByUserId,
|
||||||
|
findUserById,
|
||||||
getPublicIpWithFallback,
|
getPublicIpWithFallback,
|
||||||
haveActiveServices,
|
haveActiveServices,
|
||||||
removeDeploymentsByServerId,
|
removeDeploymentsByServerId,
|
||||||
@@ -42,15 +42,15 @@ export const serverRouter = createTRPCRouter({
|
|||||||
.input(apiCreateServer)
|
.input(apiCreateServer)
|
||||||
.mutation(async ({ ctx, input }) => {
|
.mutation(async ({ ctx, input }) => {
|
||||||
try {
|
try {
|
||||||
const admin = await findAdminById(ctx.user.adminId);
|
const user = await findUserById(ctx.user.ownerId);
|
||||||
const servers = await findServersByAdminId(admin.adminId);
|
const servers = await findServersByUserId(user.id);
|
||||||
if (IS_CLOUD && servers.length >= admin.serversQuantity) {
|
if (IS_CLOUD && servers.length >= user.serversQuantity) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "BAD_REQUEST",
|
code: "BAD_REQUEST",
|
||||||
message: "You cannot create more servers",
|
message: "You cannot create more servers",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
const project = await createServer(input, ctx.user.adminId);
|
const project = await createServer(input, ctx.user.ownerId);
|
||||||
return project;
|
return project;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
@@ -65,7 +65,7 @@ export const serverRouter = createTRPCRouter({
|
|||||||
.input(apiFindOneServer)
|
.input(apiFindOneServer)
|
||||||
.query(async ({ input, ctx }) => {
|
.query(async ({ input, ctx }) => {
|
||||||
const server = await findServerById(input.serverId);
|
const server = await findServerById(input.serverId);
|
||||||
if (server.adminId !== ctx.user.adminId) {
|
if (server.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to access this server",
|
message: "You are not authorized to access this server",
|
||||||
@@ -93,7 +93,7 @@ export const serverRouter = createTRPCRouter({
|
|||||||
.leftJoin(mongo, eq(mongo.serverId, server.serverId))
|
.leftJoin(mongo, eq(mongo.serverId, server.serverId))
|
||||||
.leftJoin(mysql, eq(mysql.serverId, server.serverId))
|
.leftJoin(mysql, eq(mysql.serverId, server.serverId))
|
||||||
.leftJoin(postgres, eq(postgres.serverId, server.serverId))
|
.leftJoin(postgres, eq(postgres.serverId, server.serverId))
|
||||||
.where(eq(server.adminId, ctx.user.adminId))
|
.where(eq(server.userId, ctx.user.ownerId))
|
||||||
.orderBy(desc(server.createdAt))
|
.orderBy(desc(server.createdAt))
|
||||||
.groupBy(server.serverId);
|
.groupBy(server.serverId);
|
||||||
|
|
||||||
@@ -105,10 +105,10 @@ export const serverRouter = createTRPCRouter({
|
|||||||
where: IS_CLOUD
|
where: IS_CLOUD
|
||||||
? and(
|
? and(
|
||||||
isNotNull(server.sshKeyId),
|
isNotNull(server.sshKeyId),
|
||||||
eq(server.adminId, ctx.user.adminId),
|
eq(server.userId, ctx.user.ownerId),
|
||||||
eq(server.serverStatus, "active"),
|
eq(server.serverStatus, "active"),
|
||||||
)
|
)
|
||||||
: and(isNotNull(server.sshKeyId), eq(server.adminId, ctx.user.adminId)),
|
: and(isNotNull(server.sshKeyId), eq(server.userId, ctx.user.ownerId)),
|
||||||
});
|
});
|
||||||
return result;
|
return result;
|
||||||
}),
|
}),
|
||||||
@@ -117,7 +117,7 @@ export const serverRouter = createTRPCRouter({
|
|||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
try {
|
try {
|
||||||
const server = await findServerById(input.serverId);
|
const server = await findServerById(input.serverId);
|
||||||
if (server.adminId !== ctx.user.adminId) {
|
if (server.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to setup this server",
|
message: "You are not authorized to setup this server",
|
||||||
@@ -142,7 +142,7 @@ export const serverRouter = createTRPCRouter({
|
|||||||
.subscription(async ({ input, ctx }) => {
|
.subscription(async ({ input, ctx }) => {
|
||||||
try {
|
try {
|
||||||
const server = await findServerById(input.serverId);
|
const server = await findServerById(input.serverId);
|
||||||
if (server.adminId !== ctx.user.adminId) {
|
if (server.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to setup this server",
|
message: "You are not authorized to setup this server",
|
||||||
@@ -162,7 +162,7 @@ export const serverRouter = createTRPCRouter({
|
|||||||
.query(async ({ input, ctx }) => {
|
.query(async ({ input, ctx }) => {
|
||||||
try {
|
try {
|
||||||
const server = await findServerById(input.serverId);
|
const server = await findServerById(input.serverId);
|
||||||
if (server.adminId !== ctx.user.adminId) {
|
if (server.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to validate this server",
|
message: "You are not authorized to validate this server",
|
||||||
@@ -204,7 +204,7 @@ export const serverRouter = createTRPCRouter({
|
|||||||
.query(async ({ input, ctx }) => {
|
.query(async ({ input, ctx }) => {
|
||||||
try {
|
try {
|
||||||
const server = await findServerById(input.serverId);
|
const server = await findServerById(input.serverId);
|
||||||
if (server.adminId !== ctx.user.adminId) {
|
if (server.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to validate this server",
|
message: "You are not authorized to validate this server",
|
||||||
@@ -254,7 +254,7 @@ export const serverRouter = createTRPCRouter({
|
|||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
try {
|
try {
|
||||||
const server = await findServerById(input.serverId);
|
const server = await findServerById(input.serverId);
|
||||||
if (server.adminId !== ctx.user.adminId) {
|
if (server.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to setup this server",
|
message: "You are not authorized to setup this server",
|
||||||
@@ -296,7 +296,7 @@ export const serverRouter = createTRPCRouter({
|
|||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
try {
|
try {
|
||||||
const server = await findServerById(input.serverId);
|
const server = await findServerById(input.serverId);
|
||||||
if (server.adminId !== ctx.user.adminId) {
|
if (server.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to delete this server",
|
message: "You are not authorized to delete this server",
|
||||||
@@ -315,12 +315,9 @@ export const serverRouter = createTRPCRouter({
|
|||||||
await deleteServer(input.serverId);
|
await deleteServer(input.serverId);
|
||||||
|
|
||||||
if (IS_CLOUD) {
|
if (IS_CLOUD) {
|
||||||
const admin = await findAdminById(ctx.user.adminId);
|
const admin = await findUserById(ctx.user.ownerId);
|
||||||
|
|
||||||
await updateServersBasedOnQuantity(
|
await updateServersBasedOnQuantity(admin.id, admin.serversQuantity);
|
||||||
admin.adminId,
|
|
||||||
admin.serversQuantity,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return currentServer;
|
return currentServer;
|
||||||
@@ -333,7 +330,7 @@ export const serverRouter = createTRPCRouter({
|
|||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
try {
|
try {
|
||||||
const server = await findServerById(input.serverId);
|
const server = await findServerById(input.serverId);
|
||||||
if (server.adminId !== ctx.user.adminId) {
|
if (server.userId !== ctx.user.ownerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to update this server",
|
message: "You are not authorized to update this server",
|
||||||
|
|||||||
@@ -47,7 +47,6 @@ import {
|
|||||||
startServiceRemote,
|
startServiceRemote,
|
||||||
stopService,
|
stopService,
|
||||||
stopServiceRemote,
|
stopServiceRemote,
|
||||||
updateAdmin,
|
|
||||||
updateLetsEncryptEmail,
|
updateLetsEncryptEmail,
|
||||||
updateServerById,
|
updateServerById,
|
||||||
updateServerTraefik,
|
updateServerTraefik,
|
||||||
|
|||||||
@@ -24,9 +24,10 @@ export const sshRouter = createTRPCRouter({
|
|||||||
.input(apiCreateSshKey)
|
.input(apiCreateSshKey)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
try {
|
try {
|
||||||
|
console.log(ctx.user.ownerId);
|
||||||
await createSshKey({
|
await createSshKey({
|
||||||
...input,
|
...input,
|
||||||
adminId: ctx.user.adminId,
|
userId: ctx.user.ownerId,
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
@@ -41,7 +42,7 @@ export const sshRouter = createTRPCRouter({
|
|||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
try {
|
try {
|
||||||
const sshKey = await findSSHKeyById(input.sshKeyId);
|
const sshKey = await findSSHKeyById(input.sshKeyId);
|
||||||
if (IS_CLOUD && sshKey.adminId !== ctx.user.adminId) {
|
if (IS_CLOUD && sshKey.userId !== ctx.user.ownerId) {
|
||||||
// TODO: Remove isCloud in the next versions of dokploy
|
// TODO: Remove isCloud in the next versions of dokploy
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
@@ -59,7 +60,7 @@ export const sshRouter = createTRPCRouter({
|
|||||||
.query(async ({ input, ctx }) => {
|
.query(async ({ input, ctx }) => {
|
||||||
const sshKey = await findSSHKeyById(input.sshKeyId);
|
const sshKey = await findSSHKeyById(input.sshKeyId);
|
||||||
|
|
||||||
if (IS_CLOUD && sshKey.adminId !== ctx.user.adminId) {
|
if (IS_CLOUD && sshKey.userId !== ctx.user.ownerId) {
|
||||||
// TODO: Remove isCloud in the next versions of dokploy
|
// TODO: Remove isCloud in the next versions of dokploy
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
@@ -70,7 +71,7 @@ export const sshRouter = createTRPCRouter({
|
|||||||
}),
|
}),
|
||||||
all: protectedProcedure.query(async ({ ctx }) => {
|
all: protectedProcedure.query(async ({ ctx }) => {
|
||||||
return await db.query.sshKeys.findMany({
|
return await db.query.sshKeys.findMany({
|
||||||
...(IS_CLOUD && { where: eq(sshKeys.adminId, ctx.user.adminId) }),
|
...(IS_CLOUD && { where: eq(sshKeys.userId, ctx.user.ownerId) }),
|
||||||
orderBy: desc(sshKeys.createdAt),
|
orderBy: desc(sshKeys.createdAt),
|
||||||
});
|
});
|
||||||
// TODO: Remove this line when the cloud version is ready
|
// TODO: Remove this line when the cloud version is ready
|
||||||
@@ -85,7 +86,7 @@ export const sshRouter = createTRPCRouter({
|
|||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
try {
|
try {
|
||||||
const sshKey = await findSSHKeyById(input.sshKeyId);
|
const sshKey = await findSSHKeyById(input.sshKeyId);
|
||||||
if (IS_CLOUD && sshKey.adminId !== ctx.user.adminId) {
|
if (IS_CLOUD && sshKey.userId !== ctx.user.ownerId) {
|
||||||
// TODO: Remove isCloud in the next versions of dokploy
|
// TODO: Remove isCloud in the next versions of dokploy
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import { WEBSITE_URL, getStripeItems } from "@/server/utils/stripe";
|
import { WEBSITE_URL, getStripeItems } from "@/server/utils/stripe";
|
||||||
import {
|
import {
|
||||||
IS_CLOUD,
|
IS_CLOUD,
|
||||||
findAdminById,
|
findServersByUserId,
|
||||||
findServersByAdminId,
|
findUserById,
|
||||||
updateAdmin,
|
updateUser,
|
||||||
} from "@dokploy/server";
|
} from "@dokploy/server";
|
||||||
import { TRPCError } from "@trpc/server";
|
import { TRPCError } from "@trpc/server";
|
||||||
import Stripe from "stripe";
|
import Stripe from "stripe";
|
||||||
@@ -12,8 +12,8 @@ import { adminProcedure, createTRPCRouter } from "../trpc";
|
|||||||
|
|
||||||
export const stripeRouter = createTRPCRouter({
|
export const stripeRouter = createTRPCRouter({
|
||||||
getProducts: adminProcedure.query(async ({ ctx }) => {
|
getProducts: adminProcedure.query(async ({ ctx }) => {
|
||||||
const admin = await findAdminById(ctx.user.adminId);
|
const user = await findUserById(ctx.user.ownerId);
|
||||||
const stripeCustomerId = admin.stripeCustomerId;
|
const stripeCustomerId = user.stripeCustomerId;
|
||||||
|
|
||||||
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY!, {
|
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY!, {
|
||||||
apiVersion: "2024-09-30.acacia",
|
apiVersion: "2024-09-30.acacia",
|
||||||
@@ -56,15 +56,15 @@ export const stripeRouter = createTRPCRouter({
|
|||||||
});
|
});
|
||||||
|
|
||||||
const items = getStripeItems(input.serverQuantity, input.isAnnual);
|
const items = getStripeItems(input.serverQuantity, input.isAnnual);
|
||||||
const admin = await findAdminById(ctx.user.adminId);
|
const user = await findUserById(ctx.user.ownerId);
|
||||||
|
|
||||||
let stripeCustomerId = admin.stripeCustomerId;
|
let stripeCustomerId = user.stripeCustomerId;
|
||||||
|
|
||||||
if (stripeCustomerId) {
|
if (stripeCustomerId) {
|
||||||
const customer = await stripe.customers.retrieve(stripeCustomerId);
|
const customer = await stripe.customers.retrieve(stripeCustomerId);
|
||||||
|
|
||||||
if (customer.deleted) {
|
if (customer.deleted) {
|
||||||
await updateAdmin(admin.authId, {
|
await updateUser(user.id, {
|
||||||
stripeCustomerId: null,
|
stripeCustomerId: null,
|
||||||
});
|
});
|
||||||
stripeCustomerId = null;
|
stripeCustomerId = null;
|
||||||
@@ -78,7 +78,7 @@ export const stripeRouter = createTRPCRouter({
|
|||||||
customer: stripeCustomerId,
|
customer: stripeCustomerId,
|
||||||
}),
|
}),
|
||||||
metadata: {
|
metadata: {
|
||||||
adminId: admin.adminId,
|
ownerId: user.id,
|
||||||
},
|
},
|
||||||
allow_promotion_codes: true,
|
allow_promotion_codes: true,
|
||||||
success_url: `${WEBSITE_URL}/dashboard/settings/servers?success=true`,
|
success_url: `${WEBSITE_URL}/dashboard/settings/servers?success=true`,
|
||||||
@@ -89,15 +89,15 @@ export const stripeRouter = createTRPCRouter({
|
|||||||
}),
|
}),
|
||||||
createCustomerPortalSession: adminProcedure.mutation(
|
createCustomerPortalSession: adminProcedure.mutation(
|
||||||
async ({ ctx, input }) => {
|
async ({ ctx, input }) => {
|
||||||
const admin = await findAdminById(ctx.user.adminId);
|
const user = await findUserById(ctx.user.ownerId);
|
||||||
|
|
||||||
if (!admin.stripeCustomerId) {
|
if (!user.stripeCustomerId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "BAD_REQUEST",
|
code: "BAD_REQUEST",
|
||||||
message: "Stripe Customer ID not found",
|
message: "Stripe Customer ID not found",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
const stripeCustomerId = admin.stripeCustomerId;
|
const stripeCustomerId = user.stripeCustomerId;
|
||||||
|
|
||||||
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY!, {
|
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY!, {
|
||||||
apiVersion: "2024-09-30.acacia",
|
apiVersion: "2024-09-30.acacia",
|
||||||
@@ -119,13 +119,14 @@ export const stripeRouter = createTRPCRouter({
|
|||||||
),
|
),
|
||||||
|
|
||||||
canCreateMoreServers: adminProcedure.query(async ({ ctx }) => {
|
canCreateMoreServers: adminProcedure.query(async ({ ctx }) => {
|
||||||
const admin = await findAdminById(ctx.user.adminId);
|
const user = await findUserById(ctx.user.ownerId);
|
||||||
const servers = await findServersByAdminId(admin.adminId);
|
console.log(user);
|
||||||
|
// const servers = await findServersByUserId(user.id);
|
||||||
|
|
||||||
if (!IS_CLOUD) {
|
if (!IS_CLOUD) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return servers.length < admin.serversQuantity;
|
return servers.length < user.serversQuantity;
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ import { ZodError } from "zod";
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
interface CreateContextOptions {
|
interface CreateContextOptions {
|
||||||
user: (User & { authId: string; rol: "admin" | "user" }) | null;
|
user: (User & { rol: "admin" | "user"; ownerId: string }) | null;
|
||||||
session: Session | null;
|
session: Session | null;
|
||||||
req: CreateNextContextOptions["req"];
|
req: CreateNextContextOptions["req"];
|
||||||
res: CreateNextContextOptions["res"];
|
res: CreateNextContextOptions["res"];
|
||||||
@@ -81,10 +81,10 @@ export const createTRPCContext = async (opts: CreateNextContextOptions) => {
|
|||||||
session: session,
|
session: session,
|
||||||
...((user && {
|
...((user && {
|
||||||
user: {
|
user: {
|
||||||
authId: "Null",
|
|
||||||
email: user.email,
|
email: user.email,
|
||||||
rol: user.role,
|
rol: user.role,
|
||||||
id: user.id,
|
id: user.id,
|
||||||
|
ownerId: user.ownerId,
|
||||||
},
|
},
|
||||||
}) || {
|
}) || {
|
||||||
user: null,
|
user: null,
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { boolean, pgTable, text, timestamp } from "drizzle-orm/pg-core";
|
import { boolean, pgTable, text, timestamp } from "drizzle-orm/pg-core";
|
||||||
import { nanoid } from "nanoid";
|
import { nanoid } from "nanoid";
|
||||||
import { users_temp } from "./user";
|
import { users_temp } from "./user";
|
||||||
|
import { relations } from "drizzle-orm";
|
||||||
|
|
||||||
export const account = pgTable("account", {
|
export const account = pgTable("account", {
|
||||||
id: text("id")
|
id: text("id")
|
||||||
@@ -29,6 +30,13 @@ export const account = pgTable("account", {
|
|||||||
confirmationExpiresAt: text("confirmationExpiresAt"),
|
confirmationExpiresAt: text("confirmationExpiresAt"),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export const accountRelations = relations(account, ({ one }) => ({
|
||||||
|
user: one(users_temp, {
|
||||||
|
fields: [account.userId],
|
||||||
|
references: [users_temp.id],
|
||||||
|
}),
|
||||||
|
}));
|
||||||
|
|
||||||
export const verification = pgTable("verification", {
|
export const verification = pgTable("verification", {
|
||||||
id: text("id").primaryKey(),
|
id: text("id").primaryKey(),
|
||||||
identifier: text("identifier").notNull(),
|
identifier: text("identifier").notNull(),
|
||||||
@@ -52,6 +60,13 @@ export const organization = pgTable("organization", {
|
|||||||
.references(() => users_temp.id),
|
.references(() => users_temp.id),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export const organizationRelations = relations(organization, ({ one }) => ({
|
||||||
|
owner: one(users_temp, {
|
||||||
|
fields: [organization.ownerId],
|
||||||
|
references: [users_temp.id],
|
||||||
|
}),
|
||||||
|
}));
|
||||||
|
|
||||||
export const member = pgTable("member", {
|
export const member = pgTable("member", {
|
||||||
id: text("id")
|
id: text("id")
|
||||||
.primaryKey()
|
.primaryKey()
|
||||||
@@ -66,6 +81,17 @@ export const member = pgTable("member", {
|
|||||||
createdAt: timestamp("created_at").notNull(),
|
createdAt: timestamp("created_at").notNull(),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export const memberRelations = relations(member, ({ one }) => ({
|
||||||
|
organization: one(organization, {
|
||||||
|
fields: [member.organizationId],
|
||||||
|
references: [organization.id],
|
||||||
|
}),
|
||||||
|
user: one(users_temp, {
|
||||||
|
fields: [member.userId],
|
||||||
|
references: [users_temp.id],
|
||||||
|
}),
|
||||||
|
}));
|
||||||
|
|
||||||
export const invitation = pgTable("invitation", {
|
export const invitation = pgTable("invitation", {
|
||||||
id: text("id").primaryKey(),
|
id: text("id").primaryKey(),
|
||||||
organizationId: text("organization_id")
|
organizationId: text("organization_id")
|
||||||
@@ -79,3 +105,10 @@ export const invitation = pgTable("invitation", {
|
|||||||
.notNull()
|
.notNull()
|
||||||
.references(() => users_temp.id),
|
.references(() => users_temp.id),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export const invitationRelations = relations(invitation, ({ one }) => ({
|
||||||
|
organization: one(organization, {
|
||||||
|
fields: [invitation.organizationId],
|
||||||
|
references: [organization.id],
|
||||||
|
}),
|
||||||
|
}));
|
||||||
|
|||||||
@@ -61,5 +61,5 @@ export const apiUpdateBitbucket = createSchema.extend({
|
|||||||
name: z.string().min(1),
|
name: z.string().min(1),
|
||||||
bitbucketUsername: z.string().optional(),
|
bitbucketUsername: z.string().optional(),
|
||||||
bitbucketWorkspaceName: z.string().optional(),
|
bitbucketWorkspaceName: z.string().optional(),
|
||||||
adminId: z.string().optional(),
|
userId: z.string().optional(),
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ import { boolean, integer, pgEnum, pgTable, text } from "drizzle-orm/pg-core";
|
|||||||
import { createInsertSchema } from "drizzle-zod";
|
import { createInsertSchema } from "drizzle-zod";
|
||||||
import { nanoid } from "nanoid";
|
import { nanoid } from "nanoid";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
import { admins } from "./admin";
|
|
||||||
import { users_temp } from "./user";
|
import { users_temp } from "./user";
|
||||||
// import { user } from "./user";
|
// import { user } from "./user";
|
||||||
|
|
||||||
@@ -153,7 +152,7 @@ export const apiCreateSlack = notificationsSchema
|
|||||||
export const apiUpdateSlack = apiCreateSlack.partial().extend({
|
export const apiUpdateSlack = apiCreateSlack.partial().extend({
|
||||||
notificationId: z.string().min(1),
|
notificationId: z.string().min(1),
|
||||||
slackId: z.string(),
|
slackId: z.string(),
|
||||||
adminId: z.string().optional(),
|
userId: z.string().optional(),
|
||||||
});
|
});
|
||||||
|
|
||||||
export const apiTestSlackConnection = apiCreateSlack.pick({
|
export const apiTestSlackConnection = apiCreateSlack.pick({
|
||||||
@@ -180,7 +179,7 @@ export const apiCreateTelegram = notificationsSchema
|
|||||||
export const apiUpdateTelegram = apiCreateTelegram.partial().extend({
|
export const apiUpdateTelegram = apiCreateTelegram.partial().extend({
|
||||||
notificationId: z.string().min(1),
|
notificationId: z.string().min(1),
|
||||||
telegramId: z.string().min(1),
|
telegramId: z.string().min(1),
|
||||||
adminId: z.string().optional(),
|
userId: z.string().optional(),
|
||||||
});
|
});
|
||||||
|
|
||||||
export const apiTestTelegramConnection = apiCreateTelegram.pick({
|
export const apiTestTelegramConnection = apiCreateTelegram.pick({
|
||||||
@@ -207,7 +206,7 @@ export const apiCreateDiscord = notificationsSchema
|
|||||||
export const apiUpdateDiscord = apiCreateDiscord.partial().extend({
|
export const apiUpdateDiscord = apiCreateDiscord.partial().extend({
|
||||||
notificationId: z.string().min(1),
|
notificationId: z.string().min(1),
|
||||||
discordId: z.string().min(1),
|
discordId: z.string().min(1),
|
||||||
adminId: z.string().optional(),
|
userId: z.string().optional(),
|
||||||
});
|
});
|
||||||
|
|
||||||
export const apiTestDiscordConnection = apiCreateDiscord
|
export const apiTestDiscordConnection = apiCreateDiscord
|
||||||
@@ -241,7 +240,7 @@ export const apiCreateEmail = notificationsSchema
|
|||||||
export const apiUpdateEmail = apiCreateEmail.partial().extend({
|
export const apiUpdateEmail = apiCreateEmail.partial().extend({
|
||||||
notificationId: z.string().min(1),
|
notificationId: z.string().min(1),
|
||||||
emailId: z.string().min(1),
|
emailId: z.string().min(1),
|
||||||
adminId: z.string().optional(),
|
userId: z.string().optional(),
|
||||||
});
|
});
|
||||||
|
|
||||||
export const apiTestEmailConnection = apiCreateEmail.pick({
|
export const apiTestEmailConnection = apiCreateEmail.pick({
|
||||||
@@ -273,7 +272,7 @@ export const apiCreateGotify = notificationsSchema
|
|||||||
export const apiUpdateGotify = apiCreateGotify.partial().extend({
|
export const apiUpdateGotify = apiCreateGotify.partial().extend({
|
||||||
notificationId: z.string().min(1),
|
notificationId: z.string().min(1),
|
||||||
gotifyId: z.string().min(1),
|
gotifyId: z.string().min(1),
|
||||||
adminId: z.string().optional(),
|
userId: z.string().optional(),
|
||||||
});
|
});
|
||||||
|
|
||||||
export const apiTestGotifyConnection = apiCreateGotify
|
export const apiTestGotifyConnection = apiCreateGotify
|
||||||
|
|||||||
@@ -196,8 +196,8 @@ export const usersRelations = relations(users, ({ one }) => ({
|
|||||||
// }),
|
// }),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const createSchema = createInsertSchema(users, {
|
const createSchema = createInsertSchema(users_temp, {
|
||||||
userId: z.string().min(1),
|
id: z.string().min(1),
|
||||||
// authId: z.string().min(1),
|
// authId: z.string().min(1),
|
||||||
token: z.string().min(1),
|
token: z.string().min(1),
|
||||||
isRegistered: z.boolean().optional(),
|
isRegistered: z.boolean().optional(),
|
||||||
@@ -218,7 +218,7 @@ export const apiCreateUserInvitation = createSchema.pick({}).extend({
|
|||||||
|
|
||||||
export const apiRemoveUser = createSchema
|
export const apiRemoveUser = createSchema
|
||||||
.pick({
|
.pick({
|
||||||
// authId: true,
|
id: true,
|
||||||
})
|
})
|
||||||
.required();
|
.required();
|
||||||
|
|
||||||
@@ -230,7 +230,7 @@ export const apiFindOneToken = createSchema
|
|||||||
|
|
||||||
export const apiAssignPermissions = createSchema
|
export const apiAssignPermissions = createSchema
|
||||||
.pick({
|
.pick({
|
||||||
userId: true,
|
id: true,
|
||||||
canCreateProjects: true,
|
canCreateProjects: true,
|
||||||
canCreateServices: true,
|
canCreateServices: true,
|
||||||
canDeleteProjects: true,
|
canDeleteProjects: true,
|
||||||
@@ -247,7 +247,7 @@ export const apiAssignPermissions = createSchema
|
|||||||
|
|
||||||
export const apiFindOneUser = createSchema
|
export const apiFindOneUser = createSchema
|
||||||
.pick({
|
.pick({
|
||||||
userId: true,
|
id: true,
|
||||||
})
|
})
|
||||||
.required();
|
.required();
|
||||||
|
|
||||||
|
|||||||
@@ -44,6 +44,9 @@ export const auth = betterAuth({
|
|||||||
role: {
|
role: {
|
||||||
type: "string",
|
type: "string",
|
||||||
},
|
},
|
||||||
|
ownerId: {
|
||||||
|
type: "string",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
plugins: [organization()],
|
plugins: [organization()],
|
||||||
@@ -56,7 +59,20 @@ export const validateRequest = async (request: IncomingMessage) => {
|
|||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log(session);
|
if (session?.user.role === "user") {
|
||||||
|
const owner = await db.query.member.findFirst({
|
||||||
|
where: eq(schema.member.userId, session.user.id),
|
||||||
|
with: {
|
||||||
|
organization: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (owner) {
|
||||||
|
session.user.ownerId = owner.organization.ownerId;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
session.user.ownerId = session?.user.id;
|
||||||
|
}
|
||||||
|
|
||||||
if (!session?.session || !session.user) {
|
if (!session?.session || !session.user) {
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import * as bcrypt from "bcrypt";
|
|||||||
import { eq } from "drizzle-orm";
|
import { eq } from "drizzle-orm";
|
||||||
import { IS_CLOUD } from "../constants";
|
import { IS_CLOUD } from "../constants";
|
||||||
|
|
||||||
export type Admin = typeof admins.$inferSelect;
|
export type Admin = typeof users_temp.$inferSelect;
|
||||||
export const createInvitation = async (
|
export const createInvitation = async (
|
||||||
input: typeof apiCreateUserInvitation._type,
|
input: typeof apiCreateUserInvitation._type,
|
||||||
adminId: string,
|
adminId: string,
|
||||||
@@ -48,33 +48,30 @@ export const createInvitation = async (
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export const findAdminById = async (adminId: string) => {
|
export const findUserById = async (userId: string) => {
|
||||||
const admin = await db.query.admins.findFirst({
|
const user = await db.query.users_temp.findFirst({
|
||||||
where: eq(admins.adminId, adminId),
|
where: eq(users_temp.id, userId),
|
||||||
});
|
});
|
||||||
if (!admin) {
|
if (!user) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "NOT_FOUND",
|
code: "NOT_FOUND",
|
||||||
message: "Admin not found",
|
message: "User not found",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return admin;
|
return user;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const updateAdmin = async (
|
export const updateUser = async (userId: string, userData: Partial<Admin>) => {
|
||||||
authId: string,
|
const user = await db
|
||||||
adminData: Partial<Admin>,
|
.update(users_temp)
|
||||||
) => {
|
|
||||||
const admin = await db
|
|
||||||
.update(admins)
|
|
||||||
.set({
|
.set({
|
||||||
...adminData,
|
...userData,
|
||||||
})
|
})
|
||||||
.where(eq(admins.authId, authId))
|
.where(eq(users_temp.id, userId))
|
||||||
.returning()
|
.returning()
|
||||||
.then((res) => res[0]);
|
.then((res) => res[0]);
|
||||||
|
|
||||||
return admin;
|
return user;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const updateAdminById = async (
|
export const updateAdminById = async (
|
||||||
@@ -93,6 +90,13 @@ export const updateAdminById = async (
|
|||||||
return admin;
|
return admin;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const findAdminById = async (userId: string) => {
|
||||||
|
const admin = await db.query.admins.findFirst({
|
||||||
|
where: eq(admins.userId, userId),
|
||||||
|
});
|
||||||
|
return admin;
|
||||||
|
};
|
||||||
|
|
||||||
export const isAdminPresent = async () => {
|
export const isAdminPresent = async () => {
|
||||||
const admin = await db.query.user.findFirst({
|
const admin = await db.query.user.findFirst({
|
||||||
where: eq(user.role, "admin"),
|
where: eq(user.role, "admin"),
|
||||||
@@ -154,10 +158,10 @@ export const getUserByToken = async (token: string) => {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export const removeUserByAuthId = async (authId: string) => {
|
export const removeUserById = async (userId: string) => {
|
||||||
await db
|
await db
|
||||||
.delete(auth)
|
.delete(users_temp)
|
||||||
.where(eq(auth.id, authId))
|
.where(eq(users_temp.id, userId))
|
||||||
.returning()
|
.returning()
|
||||||
.then((res) => res[0]);
|
.then((res) => res[0]);
|
||||||
};
|
};
|
||||||
@@ -170,7 +174,7 @@ export const removeAdminByAuthId = async (authId: string) => {
|
|||||||
const users = admin.users;
|
const users = admin.users;
|
||||||
|
|
||||||
for (const user of users) {
|
for (const user of users) {
|
||||||
await removeUserByAuthId(user.authId);
|
await removeUserById(user.id);
|
||||||
}
|
}
|
||||||
// Then delete the auth record which will cascade delete the admin
|
// Then delete the auth record which will cascade delete the admin
|
||||||
return await db
|
return await db
|
||||||
|
|||||||
@@ -12,14 +12,14 @@ export type Bitbucket = typeof bitbucket.$inferSelect;
|
|||||||
|
|
||||||
export const createBitbucket = async (
|
export const createBitbucket = async (
|
||||||
input: typeof apiCreateBitbucket._type,
|
input: typeof apiCreateBitbucket._type,
|
||||||
adminId: string,
|
userId: string,
|
||||||
) => {
|
) => {
|
||||||
return await db.transaction(async (tx) => {
|
return await db.transaction(async (tx) => {
|
||||||
const newGitProvider = await tx
|
const newGitProvider = await tx
|
||||||
.insert(gitProvider)
|
.insert(gitProvider)
|
||||||
.values({
|
.values({
|
||||||
providerType: "bitbucket",
|
providerType: "bitbucket",
|
||||||
adminId: adminId,
|
userId: userId,
|
||||||
name: input.name,
|
name: input.name,
|
||||||
})
|
})
|
||||||
.returning()
|
.returning()
|
||||||
@@ -74,12 +74,12 @@ export const updateBitbucket = async (
|
|||||||
.where(eq(bitbucket.bitbucketId, bitbucketId))
|
.where(eq(bitbucket.bitbucketId, bitbucketId))
|
||||||
.returning();
|
.returning();
|
||||||
|
|
||||||
if (input.name || input.adminId) {
|
if (input.name || input.userId) {
|
||||||
await tx
|
await tx
|
||||||
.update(gitProvider)
|
.update(gitProvider)
|
||||||
.set({
|
.set({
|
||||||
name: input.name,
|
name: input.name,
|
||||||
adminId: input.adminId,
|
userId: input.userId,
|
||||||
})
|
})
|
||||||
.where(eq(gitProvider.gitProviderId, input.gitProviderId))
|
.where(eq(gitProvider.gitProviderId, input.gitProviderId))
|
||||||
.returning();
|
.returning();
|
||||||
|
|||||||
@@ -12,14 +12,14 @@ import { updatePreviewDeployment } from "./preview-deployment";
|
|||||||
export type Github = typeof github.$inferSelect;
|
export type Github = typeof github.$inferSelect;
|
||||||
export const createGithub = async (
|
export const createGithub = async (
|
||||||
input: typeof apiCreateGithub._type,
|
input: typeof apiCreateGithub._type,
|
||||||
adminId: string,
|
userId: string,
|
||||||
) => {
|
) => {
|
||||||
return await db.transaction(async (tx) => {
|
return await db.transaction(async (tx) => {
|
||||||
const newGitProvider = await tx
|
const newGitProvider = await tx
|
||||||
.insert(gitProvider)
|
.insert(gitProvider)
|
||||||
.values({
|
.values({
|
||||||
providerType: "github",
|
providerType: "github",
|
||||||
adminId: adminId,
|
userId: userId,
|
||||||
name: input.name,
|
name: input.name,
|
||||||
})
|
})
|
||||||
.returning()
|
.returning()
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ export type Notification = typeof notifications.$inferSelect;
|
|||||||
|
|
||||||
export const createSlackNotification = async (
|
export const createSlackNotification = async (
|
||||||
input: typeof apiCreateSlack._type,
|
input: typeof apiCreateSlack._type,
|
||||||
adminId: string,
|
userId: string,
|
||||||
) => {
|
) => {
|
||||||
await db.transaction(async (tx) => {
|
await db.transaction(async (tx) => {
|
||||||
const newSlack = await tx
|
const newSlack = await tx
|
||||||
@@ -54,7 +54,7 @@ export const createSlackNotification = async (
|
|||||||
dokployRestart: input.dokployRestart,
|
dokployRestart: input.dokployRestart,
|
||||||
dockerCleanup: input.dockerCleanup,
|
dockerCleanup: input.dockerCleanup,
|
||||||
notificationType: "slack",
|
notificationType: "slack",
|
||||||
adminId: adminId,
|
userId: userId,
|
||||||
serverThreshold: input.serverThreshold,
|
serverThreshold: input.serverThreshold,
|
||||||
})
|
})
|
||||||
.returning()
|
.returning()
|
||||||
@@ -84,7 +84,7 @@ export const updateSlackNotification = async (
|
|||||||
databaseBackup: input.databaseBackup,
|
databaseBackup: input.databaseBackup,
|
||||||
dokployRestart: input.dokployRestart,
|
dokployRestart: input.dokployRestart,
|
||||||
dockerCleanup: input.dockerCleanup,
|
dockerCleanup: input.dockerCleanup,
|
||||||
adminId: input.adminId,
|
userId: input.userId,
|
||||||
serverThreshold: input.serverThreshold,
|
serverThreshold: input.serverThreshold,
|
||||||
})
|
})
|
||||||
.where(eq(notifications.notificationId, input.notificationId))
|
.where(eq(notifications.notificationId, input.notificationId))
|
||||||
@@ -114,7 +114,7 @@ export const updateSlackNotification = async (
|
|||||||
|
|
||||||
export const createTelegramNotification = async (
|
export const createTelegramNotification = async (
|
||||||
input: typeof apiCreateTelegram._type,
|
input: typeof apiCreateTelegram._type,
|
||||||
adminId: string,
|
userId: string,
|
||||||
) => {
|
) => {
|
||||||
await db.transaction(async (tx) => {
|
await db.transaction(async (tx) => {
|
||||||
const newTelegram = await tx
|
const newTelegram = await tx
|
||||||
@@ -144,7 +144,7 @@ export const createTelegramNotification = async (
|
|||||||
dokployRestart: input.dokployRestart,
|
dokployRestart: input.dokployRestart,
|
||||||
dockerCleanup: input.dockerCleanup,
|
dockerCleanup: input.dockerCleanup,
|
||||||
notificationType: "telegram",
|
notificationType: "telegram",
|
||||||
adminId: adminId,
|
userId: userId,
|
||||||
serverThreshold: input.serverThreshold,
|
serverThreshold: input.serverThreshold,
|
||||||
})
|
})
|
||||||
.returning()
|
.returning()
|
||||||
@@ -174,7 +174,7 @@ export const updateTelegramNotification = async (
|
|||||||
databaseBackup: input.databaseBackup,
|
databaseBackup: input.databaseBackup,
|
||||||
dokployRestart: input.dokployRestart,
|
dokployRestart: input.dokployRestart,
|
||||||
dockerCleanup: input.dockerCleanup,
|
dockerCleanup: input.dockerCleanup,
|
||||||
adminId: input.adminId,
|
userId: input.userId,
|
||||||
serverThreshold: input.serverThreshold,
|
serverThreshold: input.serverThreshold,
|
||||||
})
|
})
|
||||||
.where(eq(notifications.notificationId, input.notificationId))
|
.where(eq(notifications.notificationId, input.notificationId))
|
||||||
@@ -204,7 +204,7 @@ export const updateTelegramNotification = async (
|
|||||||
|
|
||||||
export const createDiscordNotification = async (
|
export const createDiscordNotification = async (
|
||||||
input: typeof apiCreateDiscord._type,
|
input: typeof apiCreateDiscord._type,
|
||||||
adminId: string,
|
userId: string,
|
||||||
) => {
|
) => {
|
||||||
await db.transaction(async (tx) => {
|
await db.transaction(async (tx) => {
|
||||||
const newDiscord = await tx
|
const newDiscord = await tx
|
||||||
@@ -234,7 +234,7 @@ export const createDiscordNotification = async (
|
|||||||
dokployRestart: input.dokployRestart,
|
dokployRestart: input.dokployRestart,
|
||||||
dockerCleanup: input.dockerCleanup,
|
dockerCleanup: input.dockerCleanup,
|
||||||
notificationType: "discord",
|
notificationType: "discord",
|
||||||
adminId: adminId,
|
userId: userId,
|
||||||
serverThreshold: input.serverThreshold,
|
serverThreshold: input.serverThreshold,
|
||||||
})
|
})
|
||||||
.returning()
|
.returning()
|
||||||
@@ -264,7 +264,7 @@ export const updateDiscordNotification = async (
|
|||||||
databaseBackup: input.databaseBackup,
|
databaseBackup: input.databaseBackup,
|
||||||
dokployRestart: input.dokployRestart,
|
dokployRestart: input.dokployRestart,
|
||||||
dockerCleanup: input.dockerCleanup,
|
dockerCleanup: input.dockerCleanup,
|
||||||
adminId: input.adminId,
|
userId: input.userId,
|
||||||
serverThreshold: input.serverThreshold,
|
serverThreshold: input.serverThreshold,
|
||||||
})
|
})
|
||||||
.where(eq(notifications.notificationId, input.notificationId))
|
.where(eq(notifications.notificationId, input.notificationId))
|
||||||
@@ -294,7 +294,7 @@ export const updateDiscordNotification = async (
|
|||||||
|
|
||||||
export const createEmailNotification = async (
|
export const createEmailNotification = async (
|
||||||
input: typeof apiCreateEmail._type,
|
input: typeof apiCreateEmail._type,
|
||||||
adminId: string,
|
userId: string,
|
||||||
) => {
|
) => {
|
||||||
await db.transaction(async (tx) => {
|
await db.transaction(async (tx) => {
|
||||||
const newEmail = await tx
|
const newEmail = await tx
|
||||||
@@ -328,7 +328,7 @@ export const createEmailNotification = async (
|
|||||||
dokployRestart: input.dokployRestart,
|
dokployRestart: input.dokployRestart,
|
||||||
dockerCleanup: input.dockerCleanup,
|
dockerCleanup: input.dockerCleanup,
|
||||||
notificationType: "email",
|
notificationType: "email",
|
||||||
adminId: adminId,
|
userId: userId,
|
||||||
serverThreshold: input.serverThreshold,
|
serverThreshold: input.serverThreshold,
|
||||||
})
|
})
|
||||||
.returning()
|
.returning()
|
||||||
@@ -358,7 +358,7 @@ export const updateEmailNotification = async (
|
|||||||
databaseBackup: input.databaseBackup,
|
databaseBackup: input.databaseBackup,
|
||||||
dokployRestart: input.dokployRestart,
|
dokployRestart: input.dokployRestart,
|
||||||
dockerCleanup: input.dockerCleanup,
|
dockerCleanup: input.dockerCleanup,
|
||||||
adminId: input.adminId,
|
userId: input.userId,
|
||||||
serverThreshold: input.serverThreshold,
|
serverThreshold: input.serverThreshold,
|
||||||
})
|
})
|
||||||
.where(eq(notifications.notificationId, input.notificationId))
|
.where(eq(notifications.notificationId, input.notificationId))
|
||||||
@@ -392,7 +392,7 @@ export const updateEmailNotification = async (
|
|||||||
|
|
||||||
export const createGotifyNotification = async (
|
export const createGotifyNotification = async (
|
||||||
input: typeof apiCreateGotify._type,
|
input: typeof apiCreateGotify._type,
|
||||||
adminId: string,
|
userId: string,
|
||||||
) => {
|
) => {
|
||||||
await db.transaction(async (tx) => {
|
await db.transaction(async (tx) => {
|
||||||
const newGotify = await tx
|
const newGotify = await tx
|
||||||
@@ -424,7 +424,7 @@ export const createGotifyNotification = async (
|
|||||||
dokployRestart: input.dokployRestart,
|
dokployRestart: input.dokployRestart,
|
||||||
dockerCleanup: input.dockerCleanup,
|
dockerCleanup: input.dockerCleanup,
|
||||||
notificationType: "gotify",
|
notificationType: "gotify",
|
||||||
adminId: adminId,
|
userId: userId,
|
||||||
})
|
})
|
||||||
.returning()
|
.returning()
|
||||||
.then((value) => value[0]);
|
.then((value) => value[0]);
|
||||||
@@ -453,7 +453,7 @@ export const updateGotifyNotification = async (
|
|||||||
databaseBackup: input.databaseBackup,
|
databaseBackup: input.databaseBackup,
|
||||||
dokployRestart: input.dokployRestart,
|
dokployRestart: input.dokployRestart,
|
||||||
dockerCleanup: input.dockerCleanup,
|
dockerCleanup: input.dockerCleanup,
|
||||||
adminId: input.adminId,
|
userId: input.userId,
|
||||||
})
|
})
|
||||||
.where(eq(notifications.notificationId, input.notificationId))
|
.where(eq(notifications.notificationId, input.notificationId))
|
||||||
.returning()
|
.returning()
|
||||||
|
|||||||
@@ -12,14 +12,14 @@ export type Registry = typeof registry.$inferSelect;
|
|||||||
|
|
||||||
export const createRegistry = async (
|
export const createRegistry = async (
|
||||||
input: typeof apiCreateRegistry._type,
|
input: typeof apiCreateRegistry._type,
|
||||||
adminId: string,
|
userId: string,
|
||||||
) => {
|
) => {
|
||||||
return await db.transaction(async (tx) => {
|
return await db.transaction(async (tx) => {
|
||||||
const newRegistry = await tx
|
const newRegistry = await tx
|
||||||
.insert(registry)
|
.insert(registry)
|
||||||
.values({
|
.values({
|
||||||
...input,
|
...input,
|
||||||
adminId: adminId,
|
userId: userId,
|
||||||
})
|
})
|
||||||
.returning()
|
.returning()
|
||||||
.then((value) => value[0]);
|
.then((value) => value[0]);
|
||||||
@@ -135,9 +135,9 @@ export const findRegistryById = async (registryId: string) => {
|
|||||||
return registryResponse;
|
return registryResponse;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const findAllRegistryByAdminId = async (adminId: string) => {
|
export const findAllRegistryByUserId = async (userId: string) => {
|
||||||
const registryResponse = await db.query.registry.findMany({
|
const registryResponse = await db.query.registry.findMany({
|
||||||
where: eq(registry.adminId, adminId),
|
where: eq(registry.userId, userId),
|
||||||
});
|
});
|
||||||
return registryResponse;
|
return registryResponse;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -7,13 +7,13 @@ export type Server = typeof server.$inferSelect;
|
|||||||
|
|
||||||
export const createServer = async (
|
export const createServer = async (
|
||||||
input: typeof apiCreateServer._type,
|
input: typeof apiCreateServer._type,
|
||||||
adminId: string,
|
userId: string,
|
||||||
) => {
|
) => {
|
||||||
const newServer = await db
|
const newServer = await db
|
||||||
.insert(server)
|
.insert(server)
|
||||||
.values({
|
.values({
|
||||||
...input,
|
...input,
|
||||||
adminId: adminId,
|
userId: userId,
|
||||||
})
|
})
|
||||||
.returning()
|
.returning()
|
||||||
.then((value) => value[0]);
|
.then((value) => value[0]);
|
||||||
@@ -45,9 +45,9 @@ export const findServerById = async (serverId: string) => {
|
|||||||
return currentServer;
|
return currentServer;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const findServersByAdminId = async (adminId: string) => {
|
export const findServersByUserId = async (userId: string) => {
|
||||||
const servers = await db.query.server.findMany({
|
const servers = await db.query.server.findMany({
|
||||||
where: eq(server.adminId, adminId),
|
where: eq(server.userId, userId),
|
||||||
orderBy: desc(server.createdAt),
|
orderBy: desc(server.createdAt),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user