mirror of
https://github.com/andwati/dokploy.git
synced 2026-11-18 09:55:19 +00:00
refactor: align cluster/swarm read queries with docker.read, gate node actions by server permissions
This commit is contained in:
@@ -52,6 +52,7 @@ export const ShowNodes = ({ serverId }: Props) => {
|
|||||||
serverId,
|
serverId,
|
||||||
});
|
});
|
||||||
const { data: registry } = api.registry.all.useQuery();
|
const { data: registry } = api.registry.all.useQuery();
|
||||||
|
const { data: permissions } = api.user.getPermissions.useQuery();
|
||||||
|
|
||||||
const { mutateAsync: deleteNode } = api.cluster.removeWorker.useMutation();
|
const { mutateAsync: deleteNode } = api.cluster.removeWorker.useMutation();
|
||||||
|
|
||||||
@@ -68,7 +69,7 @@ export const ShowNodes = ({ serverId }: Props) => {
|
|||||||
</CardTitle>
|
</CardTitle>
|
||||||
<CardDescription>Add nodes to your cluster</CardDescription>
|
<CardDescription>Add nodes to your cluster</CardDescription>
|
||||||
</div>
|
</div>
|
||||||
{haveAtLeastOneRegistry && (
|
{haveAtLeastOneRegistry && permissions?.server.create && (
|
||||||
<div className="flex flex-row gap-2">
|
<div className="flex flex-row gap-2">
|
||||||
<AddNode serverId={serverId} />
|
<AddNode serverId={serverId} />
|
||||||
</div>
|
</div>
|
||||||
@@ -144,34 +145,35 @@ export const ShowNodes = ({ serverId }: Props) => {
|
|||||||
<DropdownMenuContent align="end">
|
<DropdownMenuContent align="end">
|
||||||
<DropdownMenuLabel>Actions</DropdownMenuLabel>
|
<DropdownMenuLabel>Actions</DropdownMenuLabel>
|
||||||
<ShowNodeData data={node} />
|
<ShowNodeData data={node} />
|
||||||
{!node?.ManagerStatus?.Leader && (
|
{!node?.ManagerStatus?.Leader &&
|
||||||
<DialogAction
|
permissions?.server.delete && (
|
||||||
title="Delete Node"
|
<DialogAction
|
||||||
description="Are you sure you want to delete this node from the cluster?"
|
title="Delete Node"
|
||||||
type="destructive"
|
description="Are you sure you want to delete this node from the cluster?"
|
||||||
onClick={async () => {
|
type="destructive"
|
||||||
await deleteNode({
|
onClick={async () => {
|
||||||
nodeId: node.ID,
|
await deleteNode({
|
||||||
serverId,
|
nodeId: node.ID,
|
||||||
})
|
serverId,
|
||||||
.then(() => {
|
|
||||||
refetch();
|
|
||||||
toast.success(
|
|
||||||
"Node deleted successfully",
|
|
||||||
);
|
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.then(() => {
|
||||||
toast.error("Error deleting node");
|
refetch();
|
||||||
});
|
toast.success(
|
||||||
}}
|
"Node deleted successfully",
|
||||||
>
|
);
|
||||||
<DropdownMenuItem
|
})
|
||||||
onSelect={(e) => e.preventDefault()}
|
.catch(() => {
|
||||||
|
toast.error("Error deleting node");
|
||||||
|
});
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
Delete
|
<DropdownMenuItem
|
||||||
</DropdownMenuItem>
|
onSelect={(e) => e.preventDefault()}
|
||||||
</DialogAction>
|
>
|
||||||
)}
|
Delete
|
||||||
|
</DropdownMenuItem>
|
||||||
|
</DialogAction>
|
||||||
|
)}
|
||||||
</DropdownMenuContent>
|
</DropdownMenuContent>
|
||||||
</DropdownMenu>
|
</DropdownMenu>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import { getLocalServerIp } from "@/server/wss/terminal";
|
|||||||
import { createTRPCRouter, withPermission } from "../trpc";
|
import { createTRPCRouter, withPermission } from "../trpc";
|
||||||
|
|
||||||
export const clusterRouter = createTRPCRouter({
|
export const clusterRouter = createTRPCRouter({
|
||||||
getNodes: withPermission("server", "read")
|
getNodes: withPermission("docker", "read")
|
||||||
.input(
|
.input(
|
||||||
z.object({
|
z.object({
|
||||||
serverId: z.string().optional(),
|
serverId: z.string().optional(),
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import { createTRPCRouter, withPermission } from "../trpc";
|
|||||||
import { containerIdRegex } from "./docker";
|
import { containerIdRegex } from "./docker";
|
||||||
|
|
||||||
export const swarmRouter = createTRPCRouter({
|
export const swarmRouter = createTRPCRouter({
|
||||||
getNodes: withPermission("server", "read")
|
getNodes: withPermission("docker", "read")
|
||||||
.input(
|
.input(
|
||||||
z.object({
|
z.object({
|
||||||
serverId: z.string().optional(),
|
serverId: z.string().optional(),
|
||||||
@@ -30,7 +30,7 @@ export const swarmRouter = createTRPCRouter({
|
|||||||
}
|
}
|
||||||
return await getSwarmNodes(input.serverId);
|
return await getSwarmNodes(input.serverId);
|
||||||
}),
|
}),
|
||||||
getNodeInfo: withPermission("server", "read")
|
getNodeInfo: withPermission("docker", "read")
|
||||||
.input(z.object({ nodeId: z.string(), serverId: z.string().optional() }))
|
.input(z.object({ nodeId: z.string(), serverId: z.string().optional() }))
|
||||||
.query(async ({ input, ctx }) => {
|
.query(async ({ input, ctx }) => {
|
||||||
if (input.serverId) {
|
if (input.serverId) {
|
||||||
@@ -44,7 +44,7 @@ export const swarmRouter = createTRPCRouter({
|
|||||||
}
|
}
|
||||||
return await getNodeInfo(input.nodeId, input.serverId);
|
return await getNodeInfo(input.nodeId, input.serverId);
|
||||||
}),
|
}),
|
||||||
getNodeApps: withPermission("server", "read")
|
getNodeApps: withPermission("docker", "read")
|
||||||
.input(
|
.input(
|
||||||
z.object({
|
z.object({
|
||||||
serverId: z.string().optional(),
|
serverId: z.string().optional(),
|
||||||
@@ -62,7 +62,7 @@ export const swarmRouter = createTRPCRouter({
|
|||||||
}
|
}
|
||||||
return getNodeApplications(input.serverId);
|
return getNodeApplications(input.serverId);
|
||||||
}),
|
}),
|
||||||
getAppInfos: withPermission("server", "read")
|
getAppInfos: withPermission("docker", "read")
|
||||||
.meta({
|
.meta({
|
||||||
openapi: {
|
openapi: {
|
||||||
path: "/drop-deployment",
|
path: "/drop-deployment",
|
||||||
@@ -93,7 +93,7 @@ export const swarmRouter = createTRPCRouter({
|
|||||||
}
|
}
|
||||||
return await getApplicationInfo(input.appName, input.serverId);
|
return await getApplicationInfo(input.appName, input.serverId);
|
||||||
}),
|
}),
|
||||||
getContainerStats: withPermission("server", "read")
|
getContainerStats: withPermission("docker", "read")
|
||||||
.input(
|
.input(
|
||||||
z.object({
|
z.object({
|
||||||
serverId: z.string().optional(),
|
serverId: z.string().optional(),
|
||||||
|
|||||||
Reference in New Issue
Block a user