fix: superadmin course access + navigate to correct course from courses page

Backend: list_students, add_student, import_students now bypass
tutor_courses check for superadmins, matching the existing pattern
in list_assigned_tutors. A superadmin creating a new course was
getting 401 when accessing it because no tutor_courses row exists
for them.

Frontend: courses page passes ?courseId= to students/sessions links;
both pages now pre-select the matching course on mount instead of
always defaulting to courses[0].
This commit is contained in:
2026-05-06 15:46:54 +02:00
parent 553eb00f87
commit c8a4bc1820
4 changed files with 19 additions and 12 deletions
@@ -139,8 +139,8 @@
{/if}
<td style="padding:12px 14px;text-align:right">
<div style="display:flex;gap:6px;justify-content:flex-end">
<a href="/admin/students" class="btn ghost sm">Studierende</a>
<a href="/admin/sessions" class="btn ghost sm">Sitzungen</a>
<a href="/admin/students?courseId={course.id}" class="btn ghost sm">Studierende</a>
<a href="/admin/sessions?courseId={course.id}" class="btn ghost sm">Sitzungen</a>
</div>
</td>
</tr>
@@ -1,5 +1,6 @@
<script lang="ts">
import { onMount } from 'svelte';
import { page } from '$app/state';
import { api } from '$lib/api';
import type { Course, Room, Session } from '$lib/types';
import Icon from '$lib/components/Icon.svelte';
@@ -23,8 +24,9 @@
onMount(async () => {
courses = await api.admin.courses.list();
rooms = await api.admin.rooms.list();
const first = courses[0];
if (first) selectedCourseId = first.id;
const paramId = page.url.searchParams.get('courseId');
const match = paramId ? courses.find(c => c.id === Number(paramId)) : null;
selectedCourseId = (match ?? courses[0])?.id ?? null;
});
$effect(() => {
@@ -1,5 +1,6 @@
<script lang="ts">
import { onMount } from 'svelte';
import { page } from '$app/state';
import { api } from '$lib/api';
import type { Course, Student } from '$lib/types';
import Icon from '$lib/components/Icon.svelte';
@@ -13,8 +14,9 @@
onMount(async () => {
courses = await api.admin.courses.list();
const first = courses[0];
if (first) selectedCourseId = first.id;
const paramId = page.url.searchParams.get('courseId');
const match = paramId ? courses.find(c => c.id === Number(paramId)) : null;
selectedCourseId = (match ?? courses[0])?.id ?? null;
});
$effect(() => {