forge
Explore
Log in

Don't you dare go Hollow

👤 course creator is an embedded PersonRef

Browse files at this commit

723ae1e2f89786c5595c6fa15dfc10f2e396668fAhmet Kaan GümüşParent: cbcc77f
  • feat
    • 👤 course creator is an embedded PersonRef
Show full message
feat: 👤 course creator is an embedded PersonRef

Mirrors backend 9b8c3b2: CourseResponse.creator is now {id, username,
display_name}. Courses page drops the users lookup (a blank-q
/users/search call that 400'd, leaving students staring at raw ULIDs
in the creator column) and renders personLabel(course.creator).
Permission checks compare creator.id.
src/api/types.tsmodified+1 -1
@@ -90,7 +90,7 @@ export type EventRegistration = {
90 90
91 export type Course = {91 export type Course = {
92 id: string;92 id: string;
93- creator: string;93+ creator: PersonRef;
94 title: string;94 title: string;
95 description: string;95 description: string;
96 kind: CourseKind;96 kind: CourseKind;
src/pages/course-detail-page.tsxmodified+1 -1
@@ -72,7 +72,7 @@ function CourseDetailContent() {
72 const c = course();72 const c = course();
73 const u = auth.user();73 const u = auth.user();
74 if (!c || !u) return false;74 if (!c || !u) return false;
75- return c.creator === u.id || hasMinRole(u.role, "manager");75+ return c.creator.id === u.id || hasMinRole(u.role, "manager");
76 };76 };
77 const [roster, { refetch: refetchRoster }] = createResource(77 const [roster, { refetch: refetchRoster }] = createResource(
78 () => (hasCourseManagementRights() ? id() : null),78 () => (hasCourseManagementRights() ? id() : null),
src/pages/courses-page.tsxmodified+4 -13
@@ -4,7 +4,6 @@ import { useLocation, useNavigate } from "@tanstack/solid-router";
4 import { getCourses } from "@/api/getCourses";4 import { getCourses } from "@/api/getCourses";
5 import { getMyCourses } from "@/api/getMyCourses";5 import { getMyCourses } from "@/api/getMyCourses";
6 import { getTerms } from "@/api/getTerms";6 import { getTerms } from "@/api/getTerms";
7-import { getUserSearch } from "@/api/getUserSearch";
8 import { postCourse } from "@/api/postCourse";7 import { postCourse } from "@/api/postCourse";
9 import { formatApiError } from "@/api/client";8 import { formatApiError } from "@/api/client";
10 import type { Course, CourseKind } from "@/api/types";9 import type { Course, CourseKind } from "@/api/types";
@@ -22,6 +21,7 @@ import { SidePanel } from "@/components/ui/side-panel";
22 import { TableRowActions } from "@/components/ui/table-row-actions";21 import { TableRowActions } from "@/components/ui/table-row-actions";
23 import { Textarea } from "@/components/ui/textarea";22 import { Textarea } from "@/components/ui/textarea";
24 import { createFlash } from "@/lib/flash";23 import { createFlash } from "@/lib/flash";
24+import { personLabel } from "@/lib/person";
25 import { useAuth } from "@/stores/auth-context";25 import { useAuth } from "@/stores/auth-context";
26 import { useT } from "@/stores/preferences-context";26 import { useT } from "@/stores/preferences-context";
27 import { hasMinRole } from "@/lib/roles";27 import { hasMinRole } from "@/lib/roles";
@@ -55,21 +55,12 @@ function CoursesContent() {
55 const isStudent = () => auth.user()?.role === "student";55 const isStudent = () => auth.user()?.role === "student";
56 56
57 const [terms] = createResource(async () => (await getTerms()).items);57 const [terms] = createResource(async () => (await getTerms()).items);
58- const [users] = createResource(
59- () => (hasMinRole(auth.user()?.role, "manager") ? true : null),
60- async (enabled) => (enabled ? (await getUserSearch("")).items : []),
61- );
62 58
63 const termName = (id: string | null | undefined) => terms()?.find((term) => term.id === id)?.name ?? t("terms.unassigned");59 const termName = (id: string | null | undefined) => terms()?.find((term) => term.id === id)?.name ?? t("terms.unassigned");
64 const courseKindLabel = (value: CourseKind | undefined) =>60 const courseKindLabel = (value: CourseKind | undefined) =>
65 value === "study" ? t("courses.kind.study") : value === "club" ? t("courses.kind.club") : t("courses.kind.course");61 value === "study" ? t("courses.kind.study") : value === "club" ? t("courses.kind.club") : t("courses.kind.course");
66 const pageKind = (): CourseKind => location().pathname.startsWith("/studies") ? "study" : location().pathname.startsWith("/clubs") ? "club" : "course";62 const pageKind = (): CourseKind => location().pathname.startsWith("/studies") ? "study" : location().pathname.startsWith("/clubs") ? "club" : "course";
67 const pageLabel = () => courseKindLabel(pageKind());63 const pageLabel = () => courseKindLabel(pageKind());
68- const creatorName = (creatorId: string) => {
69- if (creatorId === auth.user()?.id) return auth.user()?.username ?? creatorId;
70- return users()?.find((user) => user.id === creatorId)?.username ?? creatorId;
71- };
72-
73 const filterCourses = (items: Course[]) => {64 const filterCourses = (items: Course[]) => {
74 const selectedTerm = termFilter();65 const selectedTerm = termFilter();
75 return items.filter((course) => {66 return items.filter((course) => {
@@ -79,7 +70,7 @@ function CoursesContent() {
79 });70 });
80 };71 };
81 const searchCourse = (course: Course, query: string) =>72 const searchCourse = (course: Course, query: string) =>
82- [course.title, course.description, course.creator, creatorName(course.creator), termName(course.term), courseKindLabel(course.kind)]73+ [course.title, course.description, personLabel(course.creator), course.creator.username, termName(course.term), courseKindLabel(course.kind)]
83 .join(" ")74 .join(" ")
84 .toLocaleLowerCase()75 .toLocaleLowerCase()
85 .includes(query.toLocaleLowerCase());76 .includes(query.toLocaleLowerCase());
@@ -117,10 +108,10 @@ function CoursesContent() {
117 },108 },
118 {109 {
119 id: "creator",110 id: "creator",
120- accessorFn: (course) => creatorName(course.creator),111+ accessorFn: (course) => personLabel(course.creator),
121 header: t("common.creator"),112 header: t("common.creator"),
122 meta: { cellClass: "truncate text-muted-foreground" },113 meta: { cellClass: "truncate text-muted-foreground" },
123- cell: (cell) => creatorName(cell.row.original.creator),114+ cell: (cell) => personLabel(cell.row.original.creator),
124 },115 },
125 {116 {
126 id: "actions",117 id: "actions",
src/pages/exams-page.tsxmodified+1 -1
@@ -69,7 +69,7 @@ function ExamsContent() {
69 const canEditExam = (exam: Exam) => exam.creator === auth.user()?.id || hasMinRole(auth.user()?.role, "manager");69 const canEditExam = (exam: Exam) => exam.creator === auth.user()?.id || hasMinRole(auth.user()?.role, "manager");
70 const visibleCourses = createMemo(() => (isStudent() ? mine() : courses()) ?? []);70 const visibleCourses = createMemo(() => (isStudent() ? mine() : courses()) ?? []);
71 const manageableCourses = createMemo(() =>71 const manageableCourses = createMemo(() =>
72- visibleCourses().filter((course) => course.creator === auth.user()?.id || hasMinRole(auth.user()?.role, "manager")),72+ visibleCourses().filter((course) => course.creator.id === auth.user()?.id || hasMinRole(auth.user()?.role, "manager")),
73 );73 );
74 const canCreate = () => hasMinRole(auth.user()?.role, "teacher") && manageableCourses().length > 0;74 const canCreate = () => hasMinRole(auth.user()?.role, "teacher") && manageableCourses().length > 0;
75 const courseById = createMemo(() => new Map(visibleCourses().map((course) => [course.id, course])));75 const courseById = createMemo(() => new Map(visibleCourses().map((course) => [course.id, course])));