mirror of
https://github.com/Dokploy/dokploy
synced 2025-06-26 18:27:59 +00:00
refactor: update
This commit is contained in:
@@ -1,7 +1,8 @@
|
|||||||
import { ShowContainers } from "@/components/dashboard/docker/show/show-containers";
|
import { ShowContainers } from "@/components/dashboard/docker/show/show-containers";
|
||||||
import { DashboardLayout } from "@/components/layouts/dashboard-layout";
|
import { DashboardLayout } from "@/components/layouts/dashboard-layout";
|
||||||
import { appRouter } from "@/server/api/root";
|
import { appRouter } from "@/server/api/root";
|
||||||
import { IS_CLOUD, validateRequest } from "@dokploy/server";
|
import { IS_CLOUD } from "@dokploy/server/constants";
|
||||||
|
import { validateRequest } from "@dokploy/server/lib/auth";
|
||||||
import { createServerSideHelpers } from "@trpc/react-query/server";
|
import { createServerSideHelpers } from "@trpc/react-query/server";
|
||||||
import type { GetServerSidePropsContext } from "next";
|
import type { GetServerSidePropsContext } from "next";
|
||||||
import React, { type ReactElement } from "react";
|
import React, { type ReactElement } from "react";
|
||||||
@@ -27,7 +28,7 @@ export async function getServerSideProps(
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
const { user, session } = await validateRequest(ctx.req, ctx.res);
|
const { user, session } = await validateRequest(ctx.req);
|
||||||
if (!user) {
|
if (!user) {
|
||||||
return {
|
return {
|
||||||
redirect: {
|
redirect: {
|
||||||
@@ -44,21 +45,20 @@ export async function getServerSideProps(
|
|||||||
req: req as any,
|
req: req as any,
|
||||||
res: res as any,
|
res: res as any,
|
||||||
db: null as any,
|
db: null as any,
|
||||||
session: session,
|
session: session as any,
|
||||||
user: user,
|
user: user as any,
|
||||||
},
|
},
|
||||||
transformer: superjson,
|
transformer: superjson,
|
||||||
});
|
});
|
||||||
try {
|
try {
|
||||||
await helpers.project.all.prefetch();
|
await helpers.project.all.prefetch();
|
||||||
const auth = await helpers.auth.get.fetch();
|
|
||||||
|
|
||||||
if (auth.role === "member") {
|
if (user.role === "member") {
|
||||||
const user = await helpers.user.byAuthId.fetch({
|
const userR = await helpers.user.get.fetch({
|
||||||
authId: auth.id,
|
userId: user.id,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!user.canAccessToDocker) {
|
if (!userR.canAccessToDocker) {
|
||||||
return {
|
return {
|
||||||
redirect: {
|
redirect: {
|
||||||
permanent: true,
|
permanent: true,
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import { Switch } from "@/components/ui/switch";
|
|||||||
import { useLocalStorage } from "@/hooks/useLocalStorage";
|
import { useLocalStorage } from "@/hooks/useLocalStorage";
|
||||||
import { api } from "@/utils/api";
|
import { api } from "@/utils/api";
|
||||||
import { IS_CLOUD } from "@dokploy/server/constants";
|
import { IS_CLOUD } from "@dokploy/server/constants";
|
||||||
import { validateRequest } from "@dokploy/server/index";
|
import { validateRequest } from "@dokploy/server/lib/auth";
|
||||||
import { Loader2 } from "lucide-react";
|
import { Loader2 } from "lucide-react";
|
||||||
import type { GetServerSidePropsContext } from "next";
|
import type { GetServerSidePropsContext } from "next";
|
||||||
import type React from "react";
|
import type React from "react";
|
||||||
@@ -104,7 +104,7 @@ export async function getServerSideProps(
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
const { user } = await validateRequest(ctx.req, ctx.res);
|
const { user } = await validateRequest(ctx.req);
|
||||||
if (!user) {
|
if (!user) {
|
||||||
return {
|
return {
|
||||||
redirect: {
|
redirect: {
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ import { cn } from "@/lib/utils";
|
|||||||
import { appRouter } from "@/server/api/root";
|
import { appRouter } from "@/server/api/root";
|
||||||
import { api } from "@/utils/api";
|
import { api } from "@/utils/api";
|
||||||
import type { findProjectById } from "@dokploy/server";
|
import type { findProjectById } from "@dokploy/server";
|
||||||
import { validateRequest } from "@dokploy/server";
|
import { validateRequest } from "@dokploy/server/lib/auth";
|
||||||
import { createServerSideHelpers } from "@trpc/react-query/server";
|
import { createServerSideHelpers } from "@trpc/react-query/server";
|
||||||
import {
|
import {
|
||||||
Ban,
|
Ban,
|
||||||
@@ -658,7 +658,7 @@ export async function getServerSideProps(
|
|||||||
const { params } = ctx;
|
const { params } = ctx;
|
||||||
|
|
||||||
const { req, res } = ctx;
|
const { req, res } = ctx;
|
||||||
const { user, session } = await validateRequest(req, res);
|
const { user, session } = await validateRequest(req);
|
||||||
if (!user) {
|
if (!user) {
|
||||||
return {
|
return {
|
||||||
redirect: {
|
redirect: {
|
||||||
|
|||||||
@@ -39,7 +39,8 @@ import {
|
|||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
import { appRouter } from "@/server/api/root";
|
import { appRouter } from "@/server/api/root";
|
||||||
import { api } from "@/utils/api";
|
import { api } from "@/utils/api";
|
||||||
import { validateRequest } from "@dokploy/server";
|
import { validateRequest } from "@dokploy/server/lib/auth";
|
||||||
|
// import { validateRequest } from "@dokploy/server";
|
||||||
import { createServerSideHelpers } from "@trpc/react-query/server";
|
import { createServerSideHelpers } from "@trpc/react-query/server";
|
||||||
import copy from "copy-to-clipboard";
|
import copy from "copy-to-clipboard";
|
||||||
import { GlobeIcon, HelpCircle, ServerOff, Trash2 } from "lucide-react";
|
import { GlobeIcon, HelpCircle, ServerOff, Trash2 } from "lucide-react";
|
||||||
@@ -370,7 +371,7 @@ export async function getServerSideProps(
|
|||||||
const { query, params, req, res } = ctx;
|
const { query, params, req, res } = ctx;
|
||||||
|
|
||||||
const activeTab = query.tab;
|
const activeTab = query.tab;
|
||||||
const { user, session } = await validateRequest(req, res);
|
const { user, session } = await validateRequest(req);
|
||||||
if (!user) {
|
if (!user) {
|
||||||
return {
|
return {
|
||||||
redirect: {
|
redirect: {
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ import {
|
|||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
import { appRouter } from "@/server/api/root";
|
import { appRouter } from "@/server/api/root";
|
||||||
import { api } from "@/utils/api";
|
import { api } from "@/utils/api";
|
||||||
import { validateRequest } from "@dokploy/server";
|
import { validateRequest } from "@dokploy/server/lib/auth";
|
||||||
import { createServerSideHelpers } from "@trpc/react-query/server";
|
import { createServerSideHelpers } from "@trpc/react-query/server";
|
||||||
import copy from "copy-to-clipboard";
|
import copy from "copy-to-clipboard";
|
||||||
import { CircuitBoard, ServerOff } from "lucide-react";
|
import { CircuitBoard, ServerOff } from "lucide-react";
|
||||||
@@ -366,7 +366,7 @@ export async function getServerSideProps(
|
|||||||
const { query, params, req, res } = ctx;
|
const { query, params, req, res } = ctx;
|
||||||
|
|
||||||
const activeTab = query.tab;
|
const activeTab = query.tab;
|
||||||
const { user, session } = await validateRequest(req, res);
|
const { user, session } = await validateRequest(req);
|
||||||
if (!user) {
|
if (!user) {
|
||||||
return {
|
return {
|
||||||
redirect: {
|
redirect: {
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ import {
|
|||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
import { appRouter } from "@/server/api/root";
|
import { appRouter } from "@/server/api/root";
|
||||||
import { api } from "@/utils/api";
|
import { api } from "@/utils/api";
|
||||||
import { validateRequest } from "@dokploy/server";
|
import { validateRequest } from "@dokploy/server/lib/auth";
|
||||||
import { createServerSideHelpers } from "@trpc/react-query/server";
|
import { createServerSideHelpers } from "@trpc/react-query/server";
|
||||||
import { HelpCircle, ServerOff, Trash2 } from "lucide-react";
|
import { HelpCircle, ServerOff, Trash2 } from "lucide-react";
|
||||||
import type {
|
import type {
|
||||||
@@ -316,7 +316,7 @@ export async function getServerSideProps(
|
|||||||
const { query, params, req, res } = ctx;
|
const { query, params, req, res } = ctx;
|
||||||
const activeTab = query.tab;
|
const activeTab = query.tab;
|
||||||
|
|
||||||
const { user, session } = await validateRequest(req, res);
|
const { user, session } = await validateRequest(req);
|
||||||
if (!user) {
|
if (!user) {
|
||||||
return {
|
return {
|
||||||
redirect: {
|
redirect: {
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ import {
|
|||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
import { appRouter } from "@/server/api/root";
|
import { appRouter } from "@/server/api/root";
|
||||||
import { api } from "@/utils/api";
|
import { api } from "@/utils/api";
|
||||||
import { validateRequest } from "@dokploy/server";
|
import { validateRequest } from "@dokploy/server/lib/auth";
|
||||||
import { createServerSideHelpers } from "@trpc/react-query/server";
|
import { createServerSideHelpers } from "@trpc/react-query/server";
|
||||||
import { HelpCircle, ServerOff, Trash2 } from "lucide-react";
|
import { HelpCircle, ServerOff, Trash2 } from "lucide-react";
|
||||||
import type {
|
import type {
|
||||||
@@ -318,7 +318,7 @@ export async function getServerSideProps(
|
|||||||
const { query, params, req, res } = ctx;
|
const { query, params, req, res } = ctx;
|
||||||
const activeTab = query.tab;
|
const activeTab = query.tab;
|
||||||
|
|
||||||
const { user, session } = await validateRequest(req, res);
|
const { user, session } = await validateRequest(req);
|
||||||
if (!user) {
|
if (!user) {
|
||||||
return {
|
return {
|
||||||
redirect: {
|
redirect: {
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ import {
|
|||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
import { appRouter } from "@/server/api/root";
|
import { appRouter } from "@/server/api/root";
|
||||||
import { api } from "@/utils/api";
|
import { api } from "@/utils/api";
|
||||||
import { validateRequest } from "@dokploy/server";
|
import { validateRequest } from "@dokploy/server/lib/auth";
|
||||||
import { createServerSideHelpers } from "@trpc/react-query/server";
|
import { createServerSideHelpers } from "@trpc/react-query/server";
|
||||||
import { HelpCircle, ServerOff, Trash2 } from "lucide-react";
|
import { HelpCircle, ServerOff, Trash2 } from "lucide-react";
|
||||||
import type {
|
import type {
|
||||||
@@ -323,7 +323,7 @@ export async function getServerSideProps(
|
|||||||
const { query, params, req, res } = ctx;
|
const { query, params, req, res } = ctx;
|
||||||
const activeTab = query.tab;
|
const activeTab = query.tab;
|
||||||
|
|
||||||
const { user, session } = await validateRequest(req, res);
|
const { user, session } = await validateRequest(req);
|
||||||
if (!user) {
|
if (!user) {
|
||||||
return {
|
return {
|
||||||
redirect: {
|
redirect: {
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ import {
|
|||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
import { appRouter } from "@/server/api/root";
|
import { appRouter } from "@/server/api/root";
|
||||||
import { api } from "@/utils/api";
|
import { api } from "@/utils/api";
|
||||||
import { validateRequest } from "@dokploy/server";
|
import { validateRequest } from "@dokploy/server/lib/auth";
|
||||||
import { createServerSideHelpers } from "@trpc/react-query/server";
|
import { createServerSideHelpers } from "@trpc/react-query/server";
|
||||||
import { HelpCircle, ServerOff, Trash2 } from "lucide-react";
|
import { HelpCircle, ServerOff, Trash2 } from "lucide-react";
|
||||||
import type {
|
import type {
|
||||||
@@ -319,7 +319,7 @@ export async function getServerSideProps(
|
|||||||
) {
|
) {
|
||||||
const { query, params, req, res } = ctx;
|
const { query, params, req, res } = ctx;
|
||||||
const activeTab = query.tab;
|
const activeTab = query.tab;
|
||||||
const { user, session } = await validateRequest(req, res);
|
const { user, session } = await validateRequest(req);
|
||||||
if (!user) {
|
if (!user) {
|
||||||
return {
|
return {
|
||||||
redirect: {
|
redirect: {
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ import {
|
|||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
import { appRouter } from "@/server/api/root";
|
import { appRouter } from "@/server/api/root";
|
||||||
import { api } from "@/utils/api";
|
import { api } from "@/utils/api";
|
||||||
import { validateRequest } from "@dokploy/server";
|
import { validateRequest } from "@dokploy/server/lib/auth";
|
||||||
import { createServerSideHelpers } from "@trpc/react-query/server";
|
import { createServerSideHelpers } from "@trpc/react-query/server";
|
||||||
import { HelpCircle, ServerOff } from "lucide-react";
|
import { HelpCircle, ServerOff } from "lucide-react";
|
||||||
import type {
|
import type {
|
||||||
@@ -311,7 +311,7 @@ export async function getServerSideProps(
|
|||||||
const { query, params, req, res } = ctx;
|
const { query, params, req, res } = ctx;
|
||||||
const activeTab = query.tab;
|
const activeTab = query.tab;
|
||||||
|
|
||||||
const { user, session } = await validateRequest(req, res);
|
const { user, session } = await validateRequest(req);
|
||||||
if (!user) {
|
if (!user) {
|
||||||
return {
|
return {
|
||||||
redirect: {
|
redirect: {
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { ShowProjects } from "@/components/dashboard/projects/show";
|
|||||||
import { DashboardLayout } from "@/components/layouts/dashboard-layout";
|
import { DashboardLayout } from "@/components/layouts/dashboard-layout";
|
||||||
import { appRouter } from "@/server/api/root";
|
import { appRouter } from "@/server/api/root";
|
||||||
import { api } from "@/utils/api";
|
import { api } from "@/utils/api";
|
||||||
import { validateRequest } from "@dokploy/server";
|
import { validateRequest } from "@dokploy/server/lib/auth";
|
||||||
import { createServerSideHelpers } from "@trpc/react-query/server";
|
import { createServerSideHelpers } from "@trpc/react-query/server";
|
||||||
import type { GetServerSidePropsContext } from "next";
|
import type { GetServerSidePropsContext } from "next";
|
||||||
import dynamic from "next/dynamic";
|
import dynamic from "next/dynamic";
|
||||||
@@ -38,7 +38,7 @@ export async function getServerSideProps(
|
|||||||
ctx: GetServerSidePropsContext<{ serviceId: string }>,
|
ctx: GetServerSidePropsContext<{ serviceId: string }>,
|
||||||
) {
|
) {
|
||||||
const { req, res } = ctx;
|
const { req, res } = ctx;
|
||||||
const { user, session } = await validateRequest(req, res);
|
const { user, session } = await validateRequest(req);
|
||||||
|
|
||||||
const helpers = createServerSideHelpers({
|
const helpers = createServerSideHelpers({
|
||||||
router: appRouter,
|
router: appRouter,
|
||||||
@@ -46,8 +46,8 @@ export async function getServerSideProps(
|
|||||||
req: req as any,
|
req: req as any,
|
||||||
res: res as any,
|
res: res as any,
|
||||||
db: null as any,
|
db: null as any,
|
||||||
session: session,
|
session: session as any,
|
||||||
user: user,
|
user: user as any,
|
||||||
},
|
},
|
||||||
transformer: superjson,
|
transformer: superjson,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { ShowRequests } from "@/components/dashboard/requests/show-requests";
|
import { ShowRequests } from "@/components/dashboard/requests/show-requests";
|
||||||
import { DashboardLayout } from "@/components/layouts/dashboard-layout";
|
import { DashboardLayout } from "@/components/layouts/dashboard-layout";
|
||||||
import { IS_CLOUD, validateRequest } from "@dokploy/server";
|
import { IS_CLOUD } from "@dokploy/server/constants";
|
||||||
|
import { validateRequest } from "@dokploy/server/lib/auth";
|
||||||
import type { GetServerSidePropsContext } from "next";
|
import type { GetServerSidePropsContext } from "next";
|
||||||
import type { ReactElement } from "react";
|
import type { ReactElement } from "react";
|
||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
@@ -22,7 +23,7 @@ export async function getServerSideProps(
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
const { user } = await validateRequest(ctx.req, ctx.res);
|
const { user } = await validateRequest(ctx.req);
|
||||||
if (!user) {
|
if (!user) {
|
||||||
return {
|
return {
|
||||||
redirect: {
|
redirect: {
|
||||||
|
|||||||
@@ -2,7 +2,8 @@ import { ShowBilling } from "@/components/dashboard/settings/billing/show-billin
|
|||||||
import { DashboardLayout } from "@/components/layouts/dashboard-layout";
|
import { DashboardLayout } from "@/components/layouts/dashboard-layout";
|
||||||
|
|
||||||
import { appRouter } from "@/server/api/root";
|
import { appRouter } from "@/server/api/root";
|
||||||
import { IS_CLOUD, validateRequest } from "@dokploy/server";
|
import { IS_CLOUD } from "@dokploy/server/constants";
|
||||||
|
import { validateRequest } from "@dokploy/server/lib/auth";
|
||||||
import { createServerSideHelpers } from "@trpc/react-query/server";
|
import { createServerSideHelpers } from "@trpc/react-query/server";
|
||||||
import type { GetServerSidePropsContext } from "next";
|
import type { GetServerSidePropsContext } from "next";
|
||||||
import React, { type ReactElement } from "react";
|
import React, { type ReactElement } from "react";
|
||||||
@@ -29,7 +30,7 @@ export async function getServerSideProps(
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
const { req, res } = ctx;
|
const { req, res } = ctx;
|
||||||
const { user, session } = await validateRequest(req, res);
|
const { user, session } = await validateRequest(req);
|
||||||
if (!user || user.role === "member") {
|
if (!user || user.role === "member") {
|
||||||
return {
|
return {
|
||||||
redirect: {
|
redirect: {
|
||||||
@@ -45,8 +46,8 @@ export async function getServerSideProps(
|
|||||||
req: req as any,
|
req: req as any,
|
||||||
res: res as any,
|
res: res as any,
|
||||||
db: null as any,
|
db: null as any,
|
||||||
session: session,
|
session: session as any,
|
||||||
user: user,
|
user: user as any,
|
||||||
},
|
},
|
||||||
transformer: superjson,
|
transformer: superjson,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
import SwarmMonitorCard from "@/components/dashboard/swarm/monitoring-card";
|
import SwarmMonitorCard from "@/components/dashboard/swarm/monitoring-card";
|
||||||
import { DashboardLayout } from "@/components/layouts/dashboard-layout";
|
import { DashboardLayout } from "@/components/layouts/dashboard-layout";
|
||||||
import { appRouter } from "@/server/api/root";
|
import { appRouter } from "@/server/api/root";
|
||||||
import { IS_CLOUD, validateRequest } from "@dokploy/server";
|
import { IS_CLOUD } from "@dokploy/server/constants";
|
||||||
|
import { validateRequest } from "@dokploy/server/lib/auth";
|
||||||
import { createServerSideHelpers } from "@trpc/react-query/server";
|
import { createServerSideHelpers } from "@trpc/react-query/server";
|
||||||
import type { GetServerSidePropsContext } from "next";
|
import type { GetServerSidePropsContext } from "next";
|
||||||
import type { ReactElement } from "react";
|
import type { ReactElement } from "react";
|
||||||
@@ -27,7 +28,7 @@ export async function getServerSideProps(
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
const { user, session } = await validateRequest(ctx.req, ctx.res);
|
const { user, session } = await validateRequest(ctx.req);
|
||||||
if (!user) {
|
if (!user) {
|
||||||
return {
|
return {
|
||||||
redirect: {
|
redirect: {
|
||||||
@@ -44,21 +45,20 @@ export async function getServerSideProps(
|
|||||||
req: req as any,
|
req: req as any,
|
||||||
res: res as any,
|
res: res as any,
|
||||||
db: null as any,
|
db: null as any,
|
||||||
session: session,
|
session: session as any,
|
||||||
user: user,
|
user: user as any,
|
||||||
},
|
},
|
||||||
transformer: superjson,
|
transformer: superjson,
|
||||||
});
|
});
|
||||||
try {
|
try {
|
||||||
await helpers.project.all.prefetch();
|
await helpers.project.all.prefetch();
|
||||||
const auth = await helpers.auth.get.fetch();
|
|
||||||
|
|
||||||
if (auth.role === "member") {
|
if (user.role === "member") {
|
||||||
const user = await helpers.user.byAuthId.fetch({
|
const userR = await helpers.user.get.fetch({
|
||||||
authId: auth.id,
|
userId: user.id,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!user.canAccessToDocker) {
|
if (!userR.canAccessToDocker) {
|
||||||
return {
|
return {
|
||||||
redirect: {
|
redirect: {
|
||||||
permanent: true,
|
permanent: true,
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
import { ShowTraefikSystem } from "@/components/dashboard/file-system/show-traefik-system";
|
import { ShowTraefikSystem } from "@/components/dashboard/file-system/show-traefik-system";
|
||||||
import { DashboardLayout } from "@/components/layouts/dashboard-layout";
|
import { DashboardLayout } from "@/components/layouts/dashboard-layout";
|
||||||
import { appRouter } from "@/server/api/root";
|
import { appRouter } from "@/server/api/root";
|
||||||
import { IS_CLOUD, validateRequest } from "@dokploy/server";
|
import { IS_CLOUD } from "@dokploy/server/constants";
|
||||||
|
import { validateRequest } from "@dokploy/server/lib/auth";
|
||||||
import { createServerSideHelpers } from "@trpc/react-query/server";
|
import { createServerSideHelpers } from "@trpc/react-query/server";
|
||||||
import type { GetServerSidePropsContext } from "next";
|
import type { GetServerSidePropsContext } from "next";
|
||||||
import React, { type ReactElement } from "react";
|
import React, { type ReactElement } from "react";
|
||||||
@@ -27,7 +28,7 @@ export async function getServerSideProps(
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
const { user, session } = await validateRequest(ctx.req, ctx.res);
|
const { user, session } = await validateRequest(ctx.req);
|
||||||
if (!user) {
|
if (!user) {
|
||||||
return {
|
return {
|
||||||
redirect: {
|
redirect: {
|
||||||
@@ -44,21 +45,20 @@ export async function getServerSideProps(
|
|||||||
req: req as any,
|
req: req as any,
|
||||||
res: res as any,
|
res: res as any,
|
||||||
db: null as any,
|
db: null as any,
|
||||||
session: session,
|
session: session as any,
|
||||||
user: user,
|
user: user as any,
|
||||||
},
|
},
|
||||||
transformer: superjson,
|
transformer: superjson,
|
||||||
});
|
});
|
||||||
try {
|
try {
|
||||||
await helpers.project.all.prefetch();
|
await helpers.project.all.prefetch();
|
||||||
const auth = await helpers.auth.get.fetch();
|
|
||||||
|
|
||||||
if (auth.role === "member") {
|
if (user.role === "member") {
|
||||||
const user = await helpers.user.byAuthId.fetch({
|
const userR = await helpers.user.get.fetch({
|
||||||
authId: auth.id,
|
userId: user.id,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!user.canAccessToTraefikFiles) {
|
if (!userR.canAccessToTraefikFiles) {
|
||||||
return {
|
return {
|
||||||
redirect: {
|
redirect: {
|
||||||
permanent: true,
|
permanent: true,
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ export const composeRouter = createTRPCRouter({
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
const project = await findProjectById(input.projectId);
|
const project = await findProjectById(input.projectId);
|
||||||
if (project.userId !== ctx.user.ownerId) {
|
if (project.organizationId !== ctx.session.activeOrganizationId) {
|
||||||
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",
|
||||||
@@ -98,7 +98,7 @@ export const composeRouter = createTRPCRouter({
|
|||||||
}
|
}
|
||||||
|
|
||||||
const compose = await findComposeById(input.composeId);
|
const compose = await findComposeById(input.composeId);
|
||||||
if (compose.project.userId !== ctx.user.ownerId) {
|
if (compose.project.organizationId !== ctx.session.activeOrganizationId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to access this compose",
|
message: "You are not authorized to access this compose",
|
||||||
@@ -111,7 +111,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.userId !== ctx.user.ownerId) {
|
if (compose.project.organizationId !== ctx.session.activeOrganizationId) {
|
||||||
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",
|
||||||
@@ -127,7 +127,10 @@ export const composeRouter = createTRPCRouter({
|
|||||||
}
|
}
|
||||||
const composeResult = await findComposeById(input.composeId);
|
const composeResult = await findComposeById(input.composeId);
|
||||||
|
|
||||||
if (composeResult.project.userId !== ctx.user.ownerId) {
|
if (
|
||||||
|
composeResult.project.organizationId !==
|
||||||
|
ctx.session.activeOrganizationId
|
||||||
|
) {
|
||||||
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",
|
||||||
@@ -158,7 +161,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.userId !== ctx.user.ownerId) {
|
if (compose.project.organizationId !== ctx.session.activeOrganizationId) {
|
||||||
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",
|
||||||
@@ -171,7 +174,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.userId !== ctx.user.ownerId) {
|
if (compose.project.organizationId !== ctx.session.activeOrganizationId) {
|
||||||
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",
|
||||||
@@ -185,7 +188,9 @@ export const composeRouter = createTRPCRouter({
|
|||||||
try {
|
try {
|
||||||
const compose = await findComposeById(input.composeId);
|
const compose = await findComposeById(input.composeId);
|
||||||
|
|
||||||
if (compose.project.userId !== ctx.user.ownerId) {
|
if (
|
||||||
|
compose.project.organizationId !== ctx.session.activeOrganizationId
|
||||||
|
) {
|
||||||
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",
|
||||||
@@ -210,7 +215,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.userId !== ctx.user.ownerId) {
|
if (compose.project.organizationId !== ctx.session.activeOrganizationId) {
|
||||||
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",
|
||||||
@@ -222,7 +227,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.userId !== ctx.user.ownerId) {
|
if (compose.project.organizationId !== ctx.session.activeOrganizationId) {
|
||||||
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",
|
||||||
@@ -237,7 +242,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.userId !== ctx.user.ownerId) {
|
if (compose.project.organizationId !== ctx.session.activeOrganizationId) {
|
||||||
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",
|
||||||
@@ -255,7 +260,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.userId !== ctx.user.ownerId) {
|
if (compose.project.organizationId !== ctx.session.activeOrganizationId) {
|
||||||
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",
|
||||||
@@ -288,7 +293,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.userId !== ctx.user.ownerId) {
|
if (compose.project.organizationId !== ctx.session.activeOrganizationId) {
|
||||||
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",
|
||||||
@@ -320,7 +325,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.userId !== ctx.user.ownerId) {
|
if (compose.project.organizationId !== ctx.session.activeOrganizationId) {
|
||||||
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",
|
||||||
@@ -334,7 +339,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.userId !== ctx.user.ownerId) {
|
if (compose.project.organizationId !== ctx.session.activeOrganizationId) {
|
||||||
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",
|
||||||
@@ -349,7 +354,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.userId !== ctx.user.ownerId) {
|
if (compose.project.organizationId !== ctx.session.activeOrganizationId) {
|
||||||
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",
|
||||||
@@ -362,7 +367,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.userId !== ctx.user.ownerId) {
|
if (compose.project.organizationId !== ctx.session.activeOrganizationId) {
|
||||||
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",
|
||||||
|
|||||||
@@ -57,7 +57,10 @@ export const notificationRouter = createTRPCRouter({
|
|||||||
.input(apiCreateSlack)
|
.input(apiCreateSlack)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
try {
|
try {
|
||||||
return await createSlackNotification(input, ctx.user.ownerId);
|
return await createSlackNotification(
|
||||||
|
input,
|
||||||
|
ctx.session.activeOrganizationId,
|
||||||
|
);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "BAD_REQUEST",
|
code: "BAD_REQUEST",
|
||||||
@@ -80,7 +83,7 @@ export const notificationRouter = createTRPCRouter({
|
|||||||
}
|
}
|
||||||
return await updateSlackNotification({
|
return await updateSlackNotification({
|
||||||
...input,
|
...input,
|
||||||
userId: ctx.user.ownerId,
|
organizationId: ctx.session.activeOrganizationId,
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw error;
|
throw error;
|
||||||
@@ -131,7 +134,7 @@ export const notificationRouter = createTRPCRouter({
|
|||||||
}
|
}
|
||||||
return await updateTelegramNotification({
|
return await updateTelegramNotification({
|
||||||
...input,
|
...input,
|
||||||
userId: ctx.user.ownerId,
|
organizationId: ctx.session.activeOrganizationId,
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
@@ -183,7 +186,7 @@ export const notificationRouter = createTRPCRouter({
|
|||||||
}
|
}
|
||||||
return await updateDiscordNotification({
|
return await updateDiscordNotification({
|
||||||
...input,
|
...input,
|
||||||
userId: ctx.user.ownerId,
|
organizationId: ctx.session.activeOrganizationId,
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
@@ -243,7 +246,7 @@ export const notificationRouter = createTRPCRouter({
|
|||||||
}
|
}
|
||||||
return await updateEmailNotification({
|
return await updateEmailNotification({
|
||||||
...input,
|
...input,
|
||||||
userId: ctx.user.ownerId,
|
organizationId: ctx.session.activeOrganizationId,
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
@@ -314,13 +317,7 @@ export const notificationRouter = createTRPCRouter({
|
|||||||
gotify: true,
|
gotify: true,
|
||||||
},
|
},
|
||||||
orderBy: desc(notifications.createdAt),
|
orderBy: desc(notifications.createdAt),
|
||||||
...(IS_CLOUD && {
|
where: eq(notifications.organizationId, ctx.session.activeOrganizationId),
|
||||||
where: eq(
|
|
||||||
notifications.organizationId,
|
|
||||||
ctx.session.activeOrganizationId,
|
|
||||||
),
|
|
||||||
}),
|
|
||||||
// TODO: Remove this line when the cloud version is ready
|
|
||||||
});
|
});
|
||||||
}),
|
}),
|
||||||
receiveNotification: publicProcedure
|
receiveNotification: publicProcedure
|
||||||
@@ -337,7 +334,7 @@ export const notificationRouter = createTRPCRouter({
|
|||||||
)
|
)
|
||||||
.mutation(async ({ input }) => {
|
.mutation(async ({ input }) => {
|
||||||
try {
|
try {
|
||||||
let userId = "";
|
let organizationId = "";
|
||||||
let ServerName = "";
|
let ServerName = "";
|
||||||
if (input.ServerType === "Dokploy") {
|
if (input.ServerType === "Dokploy") {
|
||||||
const result = await db
|
const result = await db
|
||||||
@@ -354,7 +351,7 @@ export const notificationRouter = createTRPCRouter({
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
userId = result?.[0]?.id;
|
organizationId = result?.[0]?.id;
|
||||||
ServerName = "Dokploy";
|
ServerName = "Dokploy";
|
||||||
} else {
|
} else {
|
||||||
const result = await db
|
const result = await db
|
||||||
@@ -364,18 +361,18 @@ export const notificationRouter = createTRPCRouter({
|
|||||||
sql`${server.metricsConfig}::jsonb -> 'server' ->> 'token' = ${input.Token}`,
|
sql`${server.metricsConfig}::jsonb -> 'server' ->> 'token' = ${input.Token}`,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!result?.[0]?.userId) {
|
if (!result?.[0]?.organizationId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "BAD_REQUEST",
|
code: "BAD_REQUEST",
|
||||||
message: "Token not found",
|
message: "Token not found",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
userId = result?.[0]?.userId;
|
organizationId = result?.[0]?.organizationId;
|
||||||
ServerName = "Remote";
|
ServerName = "Remote";
|
||||||
}
|
}
|
||||||
|
|
||||||
await sendServerThresholdNotifications(userId, {
|
await sendServerThresholdNotifications(organizationId, {
|
||||||
...input,
|
...input,
|
||||||
ServerName,
|
ServerName,
|
||||||
});
|
});
|
||||||
@@ -416,7 +413,7 @@ export const notificationRouter = createTRPCRouter({
|
|||||||
}
|
}
|
||||||
return await updateGotifyNotification({
|
return await updateGotifyNotification({
|
||||||
...input,
|
...input,
|
||||||
userId: ctx.user.ownerId,
|
organizationId: ctx.session.activeOrganizationId,
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw error;
|
throw error;
|
||||||
|
|||||||
@@ -49,7 +49,10 @@ export const projectRouter = createTRPCRouter({
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const project = await createProject(input, ctx.user.ownerId);
|
const project = await createProject(
|
||||||
|
input,
|
||||||
|
ctx.session.activeOrganizationId,
|
||||||
|
);
|
||||||
if (ctx.user.rol === "member") {
|
if (ctx.user.rol === "member") {
|
||||||
await addNewProject(ctx.user.id, project.projectId);
|
await addNewProject(ctx.user.id, project.projectId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,10 +41,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 (
|
if (sshKey.organizationId !== ctx.session.activeOrganizationId) {
|
||||||
IS_CLOUD &&
|
|
||||||
sshKey.organizationId !== ctx.session.activeOrganizationId
|
|
||||||
) {
|
|
||||||
// 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",
|
||||||
@@ -62,11 +59,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 (
|
if (sshKey.organizationId !== ctx.session.activeOrganizationId) {
|
||||||
IS_CLOUD &&
|
|
||||||
sshKey.organizationId !== ctx.session.activeOrganizationId
|
|
||||||
) {
|
|
||||||
// TODO: Remove isCloud in the next versions of dokploy
|
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not allowed to access this SSH key",
|
message: "You are not allowed to access this SSH key",
|
||||||
@@ -76,12 +69,9 @@ 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.organizationId, ctx.session.activeOrganizationId),
|
||||||
where: eq(sshKeys.organizationId, ctx.session.activeOrganizationId),
|
|
||||||
}),
|
|
||||||
orderBy: desc(sshKeys.createdAt),
|
orderBy: desc(sshKeys.createdAt),
|
||||||
});
|
});
|
||||||
// TODO: Remove this line when the cloud version is ready
|
|
||||||
}),
|
}),
|
||||||
generate: protectedProcedure
|
generate: protectedProcedure
|
||||||
.input(apiGenerateSSHKey)
|
.input(apiGenerateSSHKey)
|
||||||
@@ -93,11 +83,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 (
|
if (sshKey.organizationId !== ctx.session.activeOrganizationId) {
|
||||||
IS_CLOUD &&
|
|
||||||
sshKey.organizationId !== ctx.session.activeOrganizationId
|
|
||||||
) {
|
|
||||||
// TODO: Remove isCloud in the next versions of dokploy
|
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not allowed to update this SSH key",
|
message: "You are not allowed to update this SSH key",
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import { member } from "@dokploy/server/db/schema";
|
|||||||
import { TRPCError } from "@trpc/server";
|
import { TRPCError } from "@trpc/server";
|
||||||
import { eq } from "drizzle-orm";
|
import { eq } from "drizzle-orm";
|
||||||
import { adminProcedure, createTRPCRouter, protectedProcedure } from "../trpc";
|
import { adminProcedure, createTRPCRouter, protectedProcedure } from "../trpc";
|
||||||
|
import { z } from "zod";
|
||||||
export const userRouter = createTRPCRouter({
|
export const userRouter = createTRPCRouter({
|
||||||
all: adminProcedure.query(async ({ ctx }) => {
|
all: adminProcedure.query(async ({ ctx }) => {
|
||||||
return await db.query.member.findMany({
|
return await db.query.member.findMany({
|
||||||
@@ -14,16 +15,20 @@ export const userRouter = createTRPCRouter({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
}),
|
}),
|
||||||
byAuthId: protectedProcedure
|
get: protectedProcedure
|
||||||
.input(apiFindOneUserByAuth)
|
.input(
|
||||||
|
z.object({
|
||||||
|
userId: z.string(),
|
||||||
|
}),
|
||||||
|
)
|
||||||
.query(async ({ input, ctx }) => {
|
.query(async ({ input, ctx }) => {
|
||||||
const user = await findUserByAuthId(input.authId);
|
const user = await findUserById(input.userId);
|
||||||
if (user.adminId !== ctx.user.adminId) {
|
// if (user.adminId !== ctx.user.adminId) {
|
||||||
throw new TRPCError({
|
// throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
// code: "UNAUTHORIZED",
|
||||||
message: "You are not allowed to access this user",
|
// message: "You are not allowed to access this user",
|
||||||
});
|
// });
|
||||||
}
|
// }
|
||||||
return user;
|
return user;
|
||||||
}),
|
}),
|
||||||
byUserId: protectedProcedure
|
byUserId: protectedProcedure
|
||||||
|
|||||||
@@ -270,7 +270,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),
|
||||||
userId: z.string().optional(),
|
organizationId: z.string().optional(),
|
||||||
});
|
});
|
||||||
|
|
||||||
export const apiTestGotifyConnection = apiCreateGotify
|
export const apiTestGotifyConnection = apiCreateGotify
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ interface ServerThresholdPayload {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const sendServerThresholdNotifications = async (
|
export const sendServerThresholdNotifications = async (
|
||||||
userId: string,
|
organizationId: string,
|
||||||
payload: ServerThresholdPayload,
|
payload: ServerThresholdPayload,
|
||||||
) => {
|
) => {
|
||||||
const date = new Date(payload.Timestamp);
|
const date = new Date(payload.Timestamp);
|
||||||
@@ -27,7 +27,7 @@ export const sendServerThresholdNotifications = async (
|
|||||||
const notificationList = await db.query.notifications.findMany({
|
const notificationList = await db.query.notifications.findMany({
|
||||||
where: and(
|
where: and(
|
||||||
eq(notifications.serverThreshold, true),
|
eq(notifications.serverThreshold, true),
|
||||||
eq(notifications.userId, userId),
|
eq(notifications.organizationId, organizationId),
|
||||||
),
|
),
|
||||||
with: {
|
with: {
|
||||||
email: true,
|
email: true,
|
||||||
|
|||||||
Reference in New Issue
Block a user