Skip to content

⚡️⚡️⚡️ Self-hosted collaborative bookmark manager to collect, read, annotate, and fully preserve what matters, all in one place.

added button for administration

daniel31x137c95761990b0
diff --git a/.env.sample b/.env.sample
index 4d54f0ad..65f5a816 100644
--- a/.env.sample
+++ b/.env.sample
@@ -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=
diff --git a/components/ProfileDropdown.tsx b/components/ProfileDropdown.tsx
index c4e817b1..21ce54e7 100644
--- a/components/ProfileDropdown.tsx
+++ b/components/ProfileDropdown.tsx
@@ -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={() => {
diff --git a/lib/api/isServerAdmin.ts b/lib/api/isServerAdmin.ts
index e58c329c..d34cc07b 100644
--- a/lib/api/isServerAdmin.ts
+++ b/lib/api/isServerAdmin.ts
@@ -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;
diff --git a/pages/admin.tsx b/pages/admin.tsx
index a11affce..7211e08b 100644
--- a/pages/admin.tsx
+++ b/pages/admin.tsx
@@ -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";
diff --git a/pages/api/v1/users/[id].ts b/pages/api/v1/users/[id].ts
index 128b4262..de8ef562 100644
--- a/pages/api/v1/users/[id].ts
+++ b/pages/api/v1/users/[id].ts
@@ -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;
diff --git a/pages/api/v1/users/index.ts b/pages/api/v1/users/index.ts
index c0d4f7be..c94e9f24 100644
--- a/pages/api/v1/users/index.ts
+++ b/pages/api/v1/users/index.ts
@@ -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();
diff --git a/public/locales/en/common.json b/public/locales/en/common.json
index f1b5c724..3677aa32 100644
--- a/public/locales/en/common.json
+++ b/public/locales/en/common.json
@@ -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"
}
\ No newline at end of file