added button for administration
This commit is contained in:
+1
-1
@@ -21,7 +21,7 @@ BROWSER_TIMEOUT=
|
|||||||
IGNORE_UNAUTHORIZED_CA=
|
IGNORE_UNAUTHORIZED_CA=
|
||||||
IGNORE_HTTPS_ERRORS=
|
IGNORE_HTTPS_ERRORS=
|
||||||
IGNORE_URL_SIZE_LIMIT=
|
IGNORE_URL_SIZE_LIMIT=
|
||||||
ADMINISTRATOR=
|
NEXT_PUBLIC_ADMIN=
|
||||||
NEXT_PUBLIC_MAX_FILE_BUFFER=
|
NEXT_PUBLIC_MAX_FILE_BUFFER=
|
||||||
MONOLITH_MAX_BUFFER=
|
MONOLITH_MAX_BUFFER=
|
||||||
MONOLITH_CUSTOM_OPTIONS=
|
MONOLITH_CUSTOM_OPTIONS=
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ export default function ProfileDropdown() {
|
|||||||
const { settings, updateSettings } = useLocalSettingsStore();
|
const { settings, updateSettings } = useLocalSettingsStore();
|
||||||
const { account } = useAccountStore();
|
const { account } = useAccountStore();
|
||||||
|
|
||||||
|
const isAdmin = account.id === Number(process.env.NEXT_PUBLIC_ADMIN || 1);
|
||||||
|
|
||||||
const handleToggle = () => {
|
const handleToggle = () => {
|
||||||
const newTheme = settings.theme === "dark" ? "light" : "dark";
|
const newTheme = settings.theme === "dark" ? "light" : "dark";
|
||||||
updateSettings({ theme: newTheme });
|
updateSettings({ theme: newTheme });
|
||||||
@@ -29,7 +31,11 @@ export default function ProfileDropdown() {
|
|||||||
priority={true}
|
priority={true}
|
||||||
/>
|
/>
|
||||||
</div>
|
</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>
|
<li>
|
||||||
<Link
|
<Link
|
||||||
href="/settings/account"
|
href="/settings/account"
|
||||||
@@ -54,6 +60,18 @@ export default function ProfileDropdown() {
|
|||||||
})}
|
})}
|
||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
|
{isAdmin ? (
|
||||||
|
<li>
|
||||||
|
<Link
|
||||||
|
href="/admin"
|
||||||
|
onClick={() => (document?.activeElement as HTMLElement)?.blur()}
|
||||||
|
tabIndex={0}
|
||||||
|
role="button"
|
||||||
|
>
|
||||||
|
{t("server_administration")}
|
||||||
|
</Link>
|
||||||
|
</li>
|
||||||
|
) : null}
|
||||||
<li>
|
<li>
|
||||||
<div
|
<div
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
|
|||||||
@@ -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;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import DeleteUserModal from "@/components/ModalContent/DeleteUserModal";
|
|
||||||
import NewUserModal from "@/components/ModalContent/NewUserModal";
|
import NewUserModal from "@/components/ModalContent/NewUserModal";
|
||||||
import useUserStore from "@/store/admin/users";
|
import useUserStore from "@/store/admin/users";
|
||||||
import { User as U } from "@prisma/client";
|
import { User as U } from "@prisma/client";
|
||||||
|
|||||||
@@ -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;
|
const userId = isServerAdmin ? Number(req.query.id) : token.id;
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,8 @@ export default async function users(req: NextApiRequest, res: NextApiResponse) {
|
|||||||
return res.status(response.status).json({ response: response.response });
|
return res.status(response.status).json({ response: response.response });
|
||||||
} else if (req.method === "GET") {
|
} else if (req.method === "GET") {
|
||||||
const user = await verifyUser({ req, res });
|
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..." });
|
return res.status(401).json({ response: "Unauthorized..." });
|
||||||
|
|
||||||
const response = await getUsers();
|
const response = await getUsers();
|
||||||
|
|||||||
@@ -363,5 +363,6 @@
|
|||||||
"hide_link_details": "Hide Link Details",
|
"hide_link_details": "Hide Link Details",
|
||||||
"link_pinned": "Link Pinned!",
|
"link_pinned": "Link Pinned!",
|
||||||
"link_unpinned": "Link Unpinned!",
|
"link_unpinned": "Link Unpinned!",
|
||||||
"webpage": "Webpage"
|
"webpage": "Webpage",
|
||||||
|
"server_administration": "Server Administration"
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user