mirror of
https://github.com/Dokploy/dokploy.git
synced 2026-06-28 02:25:23 +02:00
- Introduced new test files for permission checks, including `check-permission.test.ts`, `enterprise-only-resources.test.ts`, `resolve-permissions.test.ts`, and `service-access.test.ts`. - Implemented permission checks in various components to ensure actions are gated by user permissions, including `ShowTraefikConfig`, `UpdateTraefikConfig`, `ShowVolumes`, `ShowDomains`, and others. - Enhanced the logic for displaying UI elements based on user permissions, ensuring that only authorized users can access or modify resources.
77 lines
1.7 KiB
TypeScript
77 lines
1.7 KiB
TypeScript
import { IS_CLOUD } from "@dokploy/server/constants";
|
|
import { validateRequest } from "@dokploy/server/lib/auth";
|
|
import { createServerSideHelpers } from "@trpc/react-query/server";
|
|
import type { GetServerSidePropsContext } from "next";
|
|
import type { ReactElement } from "react";
|
|
import superjson from "superjson";
|
|
import { ShowTraefikSystem } from "@/components/dashboard/file-system/show-traefik-system";
|
|
import { DashboardLayout } from "@/components/layouts/dashboard-layout";
|
|
import { appRouter } from "@/server/api/root";
|
|
|
|
const Dashboard = () => {
|
|
return <ShowTraefikSystem />;
|
|
};
|
|
|
|
export default Dashboard;
|
|
|
|
Dashboard.getLayout = (page: ReactElement) => {
|
|
return <DashboardLayout>{page}</DashboardLayout>;
|
|
};
|
|
export async function getServerSideProps(
|
|
ctx: GetServerSidePropsContext<{ serviceId: string }>,
|
|
) {
|
|
if (IS_CLOUD) {
|
|
return {
|
|
redirect: {
|
|
permanent: true,
|
|
destination: "/dashboard/projects",
|
|
},
|
|
};
|
|
}
|
|
const { user, session } = await validateRequest(ctx.req);
|
|
if (!user) {
|
|
return {
|
|
redirect: {
|
|
permanent: true,
|
|
destination: "/",
|
|
},
|
|
};
|
|
}
|
|
const { req, res } = ctx;
|
|
|
|
const helpers = createServerSideHelpers({
|
|
router: appRouter,
|
|
ctx: {
|
|
req: req as any,
|
|
res: res as any,
|
|
db: null as any,
|
|
session: session as any,
|
|
user: user as any,
|
|
},
|
|
transformer: superjson,
|
|
});
|
|
try {
|
|
await helpers.project.all.prefetch();
|
|
|
|
const userPermissions = await helpers.user.getPermissions.fetch();
|
|
|
|
if (!userPermissions?.traefikFiles.read) {
|
|
return {
|
|
redirect: {
|
|
permanent: true,
|
|
destination: "/",
|
|
},
|
|
};
|
|
}
|
|
return {
|
|
props: {
|
|
trpcState: helpers.dehydrate(),
|
|
},
|
|
};
|
|
} catch {
|
|
return {
|
|
props: {},
|
|
};
|
|
}
|
|
}
|