mirror of
https://github.com/OHTU-German-learning-website/OHTU-German-learning-website.git
synced 2026-10-12 19:13:51 +03:00
fix: sidebar, role access and copy links
This commit is contained in:
@@ -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;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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",
|
||||
},
|
||||
];
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user