fix: sidebar, role access and copy links

This commit is contained in:
Erza
2026-04-01 16:14:02 +00:00
parent 973b4179f3
commit a445e8ec65
6 changed files with 39 additions and 55 deletions
@@ -89,7 +89,9 @@ export default function ClickExercisesPage() {
Erstellt: {new Date(exercise.created_at).toLocaleDateString()}
</Container>
</Column>
<ExerciseLinkButton id={exercise.exercise_id}>
<ExerciseLinkButton
href={`/grammar/exercises/click/${exercise.click_id}`}
>
Link kopieren
</ExerciseLinkButton>
</Row>
@@ -89,7 +89,9 @@ export default function FreeFormExercisesPage() {
Erstellt: {new Date(exercise.created_at).toLocaleDateString()}
</Container>
</Column>
<ExerciseLinkButton id={exercise.exercise_id}>
<ExerciseLinkButton
href={`/grammar/exercises/freeform/${exercise.id}`}
>
Link kopieren
</ExerciseLinkButton>
</Row>
@@ -90,7 +90,9 @@ export default function MultichoiceExercisesPage() {
Erstellt: {new Date(exercise.created_at).toLocaleDateString()}
</Container>
</Column>
<ExerciseLinkButton id={exercise.exercise_id}>
<ExerciseLinkButton
href={`/grammar/exercises/multichoice/${exercise.multichoice_exercise_id}`}
>
Link kopieren
</ExerciseLinkButton>
</Row>
@@ -1,17 +1,19 @@
"use client";
import { Button } from "@/components/ui/button";
export function ExerciseLinkButton({ id, children, ...props }) {
export function ExerciseLinkButton({ href, children, ...props }) {
const copyToClipboard = async (e) => {
e.preventDefault();
e.stopPropagation();
try {
const origin = window.location.origin;
const url = `${origin}/api/redirect/exercises/${id}`;
const url = `${origin}${href}`;
await navigator.clipboard.writeText(url);
alert("Link kopiert!");
return true;
} catch (err) {
console.error("Failed to copy text: ", err);
alert("Link konnte nicht kopiert werden.");
return false;
}
};
+12 -32
View File
@@ -115,26 +115,6 @@ function StudentSideBar() {
}
const extraLinks = [
{
title: "DeepL",
link: "https://www.deepl.com/de/translator",
id: "deepl",
},
{
title: "Google Translator",
link: "https://translate.google.com/",
id: "google-translator",
},
{
title: "ChatGPT",
link: "https://chatgpt.com/",
id: "chatgpt",
},
{
title: "Google Gemini",
link: "https://gemini.google.com",
id: "google-gemini",
},
{
title: "Wortschatz Uni Leipzig",
link: "https://wortschatz.uni-leipzig.de/de",
@@ -166,24 +146,24 @@ const extraLinks = [
id: "progr@mm",
},
{
title: "Hamburger Fernhochschule",
link: "https://www.hfh-fernstudium.de/blog/welcher-lerntyp-bist-du",
id: "hamburger-fernhochschule",
title: "DeepL",
link: "https://www.deepl.com/de/translator",
id: "deepl",
},
{
title: "IQLingua",
link: "https://www.iq-lingua.de/typ-checks/welcher-lerntyp-bin-ich/#c42954",
id: "iq-lingua",
title: "Google Translator",
link: "https://translate.google.com/",
id: "google-translator",
},
{
title: "Geolino",
link: "https://www.geo.de/geolino/mensch/5849-rtkl-lernen-welcher-lerntyp-bist-du",
id: "geolino",
title: "ChatGPT",
link: "https://chatgpt.com/",
id: "chatgpt",
},
{
title: "Kapiert.de",
link: "https://www.kapiert.de/lerntypentest/",
id: "kapiert-de",
title: "Google Gemini",
link: "https://gemini.google.com",
id: "google-gemini",
},
];
+14 -18
View File
@@ -234,28 +234,24 @@ export function useIsSuperAdmin() {
}
/**
* checkUseIsAdmin - utility that inspects the current `UserContext` and
* returns a boolean indicating admin rights.
* checkUseIsAdmin - utility that inspects the current UserContext and
* returns whether the authenticated user has admin rights.
*
* Note: this function relies on `useUser()` so it must be called from
* React component or hook context (i.e. during render) to access the
* current context value.
* Note: this function relies on useUser() so it must be called from
* a React component or hook context (i.e. during render) to access
* the current context value.
*
* @returns {boolean|undefined} `true` when user is admin, `false` when
* not an admin, or `undefined` when there is no authenticated user.
* This check is based on the actual authenticated user (auth.user.is_admin)
* and not on the temporary "actAs" role used for UI switching.
*
* @returns {boolean} true when the user is an admin, otherwise false.
*/
export function checkUseIsAdmin() {
let is_admin = true;
const { auth, actAs } = useUser();
const { auth } = useUser();
if (!auth.user?.id) return;
if (!auth.user?.is_admin || !auth.isLoggedIn || actAs.value == "admin") {
is_admin = false;
// Evaluate the truth of this statement.
// Should be true if and only if the user has admin rights
// Find out what is the definition of an admin user
// Also these functions might be better if they used whitelisting instead of blacklisting
}
if (!auth.user?.id) return false;
if (!auth.isLoggedIn) return false;
if (!auth.user?.is_admin) return false;
return is_admin;
return true;
}