added button for administration

This commit is contained in:
daniel31x13
2024-07-03 17:29:33 -04:00
parent c67526e54c
commit 7c95761990
7 changed files with 26 additions and 7 deletions

View File

@@ -21,7 +21,7 @@ BROWSER_TIMEOUT=
IGNORE_UNAUTHORIZED_CA=
IGNORE_HTTPS_ERRORS=
IGNORE_URL_SIZE_LIMIT=
ADMINISTRATOR=
NEXT_PUBLIC_ADMIN=
NEXT_PUBLIC_MAX_FILE_BUFFER=
MONOLITH_MAX_BUFFER=
MONOLITH_CUSTOM_OPTIONS=

View File

@@ -11,6 +11,8 @@ export default function ProfileDropdown() {
const { settings, updateSettings } = useLocalSettingsStore();
const { account } = useAccountStore();
const isAdmin = account.id === Number(process.env.NEXT_PUBLIC_ADMIN || 1);
const handleToggle = () => {
const newTheme = settings.theme === "dark" ? "light" : "dark";
updateSettings({ theme: newTheme });
@@ -29,7 +31,11 @@ export default function ProfileDropdown() {
priority={true}
/>
</div>
<ul className="dropdown-content z-[1] menu shadow bg-base-200 border border-neutral-content rounded-box w-40 mt-1">
<ul
className={`dropdown-content z-[1] menu shadow bg-base-200 border border-neutral-content rounded-box ${
isAdmin ? "w-48" : "w-40"
} mt-1`}
>
<li>
<Link
href="/settings/account"
@@ -54,6 +60,18 @@ export default function ProfileDropdown() {
})}
</div>
</li>
{isAdmin ? (
<li>
<Link
href="/admin"
onClick={() => (document?.activeElement as HTMLElement)?.blur()}
tabIndex={0}
role="button"
>
{t("server_administration")}
</Link>
</li>
) : null}
<li>
<div
onClick={() => {

View File

@@ -36,7 +36,7 @@ export default async function isServerAdmin({ req }: Props): Promise<boolean> {
},
});
if (findUser?.username === process.env.ADMINISTRATOR) {
if (findUser?.id === Number(process.env.NEXT_PUBLIC_ADMIN || 1)) {
return true;
} else {
return false;

View File

@@ -1,4 +1,3 @@
import DeleteUserModal from "@/components/ModalContent/DeleteUserModal";
import NewUserModal from "@/components/ModalContent/NewUserModal";
import useUserStore from "@/store/admin/users";
import { User as U } from "@prisma/client";

View File

@@ -22,7 +22,7 @@ export default async function users(req: NextApiRequest, res: NextApiResponse) {
},
});
const isServerAdmin = process.env.ADMINISTRATOR === user?.username;
const isServerAdmin = user?.id === Number(process.env.NEXT_PUBLIC_ADMIN || 1);
const userId = isServerAdmin ? Number(req.query.id) : token.id;

View File

@@ -9,7 +9,8 @@ export default async function users(req: NextApiRequest, res: NextApiResponse) {
return res.status(response.status).json({ response: response.response });
} else if (req.method === "GET") {
const user = await verifyUser({ req, res });
if (!user || process.env.ADMINISTRATOR !== user.username)
if (!user || user.id !== Number(process.env.NEXT_PUBLIC_ADMIN || 1))
return res.status(401).json({ response: "Unauthorized..." });
const response = await getUsers();

View File

@@ -363,5 +363,6 @@
"hide_link_details": "Hide Link Details",
"link_pinned": "Link Pinned!",
"link_unpinned": "Link Unpinned!",
"webpage": "Webpage"
"webpage": "Webpage",
"server_administration": "Server Administration"
}