diff --git a/components/pages/inspector/ServerActions.tsx b/components/pages/inspector/ServerActions.tsx index 6d9b6c3..79c8614 100644 --- a/components/pages/inspector/ServerActions.tsx +++ b/components/pages/inspector/ServerActions.tsx @@ -14,13 +14,18 @@ import { import { Check, ChevronsUpDown } from "lucide-react"; import { cn } from "@/lib/utils"; import { useState } from "react"; -import { updateServerDiscoverability, updateServerFlags } from "@/lib/actions"; +import { updateServerDiscoverability, updateServerFlags, updateServerOwner } from "@/lib/actions"; import { useToast } from "../../ui/use-toast"; import Link from "next/link"; +import { DropdownMenu, DropdownMenuContent } from "@/components/ui/dropdown-menu"; +import { DropdownMenuTrigger } from "@radix-ui/react-dropdown-menu"; +import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger } from "@/components/ui/alert-dialog"; +import { Input } from "@/components/ui/input"; export function ServerActions({ server }: { server: Server }) { const [selectBadges, setSelectBadges] = useState(false); const [serverDraft, setDraft] = useState(server); + const [newOwner, setNewOwner] = useState(""); const { toast } = useToast(); return ( @@ -138,6 +143,59 @@ export function ServerActions({ server }: { server: Server }) { + + + + + + + + + + + + + + Change server owner + + + Enter the ID of the new server owner. + setNewOwner(e.currentTarget.value)} + /> + + + + Cancel + { + try { + await updateServerOwner(server._id, newOwner); + setNewOwner(""); + toast({ title: "Server owner changed" }); + } catch(e) { + toast({ + title: "Owner update failed", + description: String(e), + variant: "destructive", + }); + } + }} + > + Update + + + + + + ); } diff --git a/lib/accessPermissions.ts b/lib/accessPermissions.ts index 85fae63..c5a7cda 100644 --- a/lib/accessPermissions.ts +++ b/lib/accessPermissions.ts @@ -37,7 +37,7 @@ type Permission = | `servers${ | "" | `/fetch${"" | "/by-id"}` - | `/update${"" | "/flags" | "/discoverability"}`}` + | `/update${"" | "/flags" | "/discoverability" | "/owner"}`}` | `users${ | "" | `/fetch${ @@ -112,6 +112,8 @@ const PermissionSets = { "users/fetch/notices", "users/update/badges", + "servers/update/owner", + "accounts/fetch/by-id", "accounts/fetch/by-email", "accounts/disable", diff --git a/lib/actions.ts b/lib/actions.ts index 2081b6e..b698244 100644 --- a/lib/actions.ts +++ b/lib/actions.ts @@ -588,6 +588,27 @@ export async function updateServerDiscoverability( ); } +export async function updateServerOwner(serverId: string, userId: string) { + await checkPermission("servers/update/owner", { serverId, userId }); + + await mongo() + .db("revolt") + .collection("servers") + .updateOne( + { _id: serverId }, + { $set: { owner: userId } }, + ); + + await publishMessage(serverId, { + type: "ServerUpdate", + id: serverId, + data: { + owner: userId, + }, + clear: [], + }); +} + export async function deleteInvite(invite: string) { await checkPermission("channels/update/invites", invite);