diff --git a/apps/dokploy/pages/index.tsx b/apps/dokploy/pages/index.tsx
index cb3684a5..795d7a86 100644
--- a/apps/dokploy/pages/index.tsx
+++ b/apps/dokploy/pages/index.tsx
@@ -4,6 +4,14 @@ import { AlertBlock } from "@/components/shared/alert-block";
import { Logo } from "@/components/shared/logo";
import { Button, buttonVariants } from "@/components/ui/button";
import { CardContent, CardDescription } from "@/components/ui/card";
+import {
+ Dialog,
+ DialogContent,
+ DialogDescription,
+ DialogHeader,
+ DialogTitle,
+ DialogTrigger,
+} from "@/components/ui/dialog";
import {
Form,
FormControl,
@@ -20,14 +28,6 @@ import {
InputOTPSlot,
} from "@/components/ui/input-otp";
import { Label } from "@/components/ui/label";
-import {
- Dialog,
- DialogContent,
- DialogDescription,
- DialogHeader,
- DialogTitle,
- DialogTrigger,
-} from "@/components/ui/dialog";
import { authClient } from "@/lib/auth-client";
import { cn } from "@/lib/utils";
import { api } from "@/utils/api";
diff --git a/apps/dokploy/pages/invitation.tsx b/apps/dokploy/pages/invitation.tsx
index 60cdfa85..c11cc822 100644
--- a/apps/dokploy/pages/invitation.tsx
+++ b/apps/dokploy/pages/invitation.tsx
@@ -85,7 +85,7 @@ const Invitation = ({
userAlreadyExists,
}: Props) => {
const router = useRouter();
- const { data } = api.admin.getUserByToken.useQuery(
+ const { data } = api.user.getUserByToken.useQuery(
{
token,
},
diff --git a/apps/dokploy/server/api/routers/admin.ts b/apps/dokploy/server/api/routers/admin.ts
index b15ed616..293b7dfe 100644
--- a/apps/dokploy/server/api/routers/admin.ts
+++ b/apps/dokploy/server/api/routers/admin.ts
@@ -1,4 +1,3 @@
-import { db } from "@/server/db";
import {
apiAssignPermissions,
apiCreateUserInvitation,
@@ -14,11 +13,9 @@ import {
getUserByToken,
removeUserById,
setupWebMonitoring,
- updateAdminById,
updateUser,
} from "@dokploy/server";
import { TRPCError } from "@trpc/server";
-import { eq } from "drizzle-orm";
import { z } from "zod";
import {
adminProcedure,
@@ -131,7 +128,7 @@ export const adminRouter = createTRPCRouter({
if (user.id !== ctx.user.ownerId) {
throw new TRPCError({
code: "UNAUTHORIZED",
- message: "You are not authorized to setup this server",
+ message: "You are not authorized to setup the monitoring",
});
}
diff --git a/apps/dokploy/server/api/routers/compose.ts b/apps/dokploy/server/api/routers/compose.ts
index a74c2bfb..d9cd46d2 100644
--- a/apps/dokploy/server/api/routers/compose.ts
+++ b/apps/dokploy/server/api/routers/compose.ts
@@ -39,7 +39,6 @@ import {
createComposeByTemplate,
createDomain,
createMount,
- findAdminById,
findComposeById,
findDomainsByComposeId,
findProjectById,
diff --git a/apps/dokploy/server/api/routers/organization.ts b/apps/dokploy/server/api/routers/organization.ts
index 30c2630d..ad77b85c 100644
--- a/apps/dokploy/server/api/routers/organization.ts
+++ b/apps/dokploy/server/api/routers/organization.ts
@@ -1,11 +1,6 @@
import { db } from "@/server/db";
-import {
- invitation,
- member,
- organization,
- users_temp,
-} from "@/server/db/schema";
-import { IS_CLOUD, auth } from "@dokploy/server/index";
+import { invitation, member, organization } from "@/server/db/schema";
+import { IS_CLOUD } from "@dokploy/server/index";
import { TRPCError } from "@trpc/server";
import { and, desc, eq, exists } from "drizzle-orm";
import { nanoid } from "nanoid";
@@ -45,7 +40,7 @@ export const organizationRouter = createTRPCRouter({
});
}
- const memberResult = await db.insert(member).values({
+ await db.insert(member).values({
organizationId: result.id,
role: "owner",
createdAt: new Date(),
@@ -142,7 +137,7 @@ export const organizationRouter = createTRPCRouter({
allInvitations: adminProcedure.query(async ({ ctx }) => {
return await db.query.invitation.findMany({
where: eq(invitation.organizationId, ctx.session.activeOrganizationId),
- orderBy: [desc(invitation.status)],
+ orderBy: [desc(invitation.status), desc(invitation.expiresAt)],
});
}),
acceptInvitation: adminProcedure
diff --git a/apps/dokploy/server/api/routers/user.ts b/apps/dokploy/server/api/routers/user.ts
index 2bfc06f7..c0717a92 100644
--- a/apps/dokploy/server/api/routers/user.ts
+++ b/apps/dokploy/server/api/routers/user.ts
@@ -1,18 +1,31 @@
import { apiFindOneUser, apiFindOneUserByAuth } from "@/server/db/schema";
import {
IS_CLOUD,
+ findOrganizationById,
findUserByAuthId,
findUserById,
+ getUserByToken,
removeUserById,
updateUser,
verify2FA,
} from "@dokploy/server";
import { db } from "@dokploy/server/db";
-import { account, apiUpdateUser, member } from "@dokploy/server/db/schema";
+import {
+ account,
+ apiAssignPermissions,
+ apiFindOneToken,
+ apiUpdateUser,
+ member,
+} from "@dokploy/server/db/schema";
import { TRPCError } from "@trpc/server";
-import { eq } from "drizzle-orm";
+import { and, eq } from "drizzle-orm";
import { z } from "zod";
-import { adminProcedure, createTRPCRouter, protectedProcedure } from "../trpc";
+import {
+ adminProcedure,
+ createTRPCRouter,
+ protectedProcedure,
+ publicProcedure,
+} from "../trpc";
export const userRouter = createTRPCRouter({
all: adminProcedure.query(async ({ ctx }) => {
return await db.query.member.findMany({
@@ -39,14 +52,36 @@ export const userRouter = createTRPCRouter({
return user;
}),
get: protectedProcedure.query(async ({ ctx }) => {
- return await findUserById(ctx.user.id);
+ const memberResult = await db.query.member.findFirst({
+ where: and(
+ eq(member.userId, ctx.user.id),
+ eq(member.organizationId, ctx.session?.activeOrganizationId || ""),
+ ),
+ with: {
+ user: true,
+ },
+ });
+
+ return memberResult;
}),
update: protectedProcedure
.input(apiUpdateUser)
.mutation(async ({ input, ctx }) => {
return await updateUser(ctx.user.id, input);
}),
-
+ getUserByToken: publicProcedure
+ .input(apiFindOneToken)
+ .query(async ({ input }) => {
+ return await getUserByToken(input.token);
+ }),
+ getMetricsToken: protectedProcedure.query(async ({ ctx }) => {
+ const user = await findUserById(ctx.user.ownerId);
+ return {
+ serverIp: user.serverIp,
+ enabledFeatures: user.enablePaidFeatures,
+ metricsConfig: user?.metricsConfig,
+ };
+ }),
remove: protectedProcedure
.input(
z.object({
@@ -59,4 +94,28 @@ export const userRouter = createTRPCRouter({
}
return await removeUserById(input.userId);
}),
+ assignPermissions: adminProcedure
+ .input(apiAssignPermissions)
+ .mutation(async ({ input, ctx }) => {
+ try {
+ const user = await findUserById(input.id);
+
+ const organization = await findOrganizationById(
+ ctx.session?.activeOrganizationId || "",
+ );
+
+ if (organization?.ownerId !== ctx.user.ownerId) {
+ throw new TRPCError({
+ code: "UNAUTHORIZED",
+ message: "You are not allowed to assign permissions",
+ });
+ }
+
+ await updateUser(user.id, {
+ ...input,
+ });
+ } catch (error) {
+ throw error;
+ }
+ }),
});