Skip to content

Commit 1c2e85d

Browse files
committed
Fix issue #222
Tested locally, should work to expose the autograder table to students & allow for reading submission limits
1 parent 0954525 commit 1c2e85d

File tree

3 files changed

+61
-6
lines changed

3 files changed

+61
-6
lines changed

app/course/[course_id]/assignments/[assignment_id]/page.tsx

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,20 @@ import {
1515
Repository,
1616
SelfReviewSettings,
1717
SubmissionWithGraderResultsAndReview,
18-
UserRole
18+
UserRole,
19+
AutograderWithAssignment
1920
} from "@/utils/supabase/DatabaseTypes";
2021
import { Alert, Box, Flex, Heading, HStack, Link, Skeleton, Table } from "@chakra-ui/react";
2122
import { TZDate } from "@date-fns/tz";
2223
import { CrudFilter, useList } from "@refinedev/core";
23-
import { differenceInDays, format } from "date-fns";
24+
import { differenceInDays, format, secondsToHours } from "date-fns";
2425
import { useParams } from "next/navigation";
2526
import { useEffect, useMemo, useRef } from "react";
2627
import { CommitHistoryDialog } from "./commitHistory";
2728
import ManageGroupWidget from "./manageGroupWidget";
2829

2930
export default function AssignmentPage() {
30-
const { course_id, assignment_id } = useParams();
31+
const { course_id, assignment_id, id } = useParams();
3132
const { private_profile_id } = useClassProfiles();
3233
const { role: enrollment } = useClassProfiles();
3334
const { assignment } = useAssignmentController();
@@ -54,6 +55,11 @@ export default function AssignmentPage() {
5455
}
5556
return filters;
5657
}, [assignment_id, assignmentGroup, private_profile_id]);
58+
const autograderFilters = useMemo(() => {
59+
const filters: CrudFilter[] = [];
60+
filters.push({ field: "id", operator: "eq", value: assignment_id });
61+
return filters;
62+
}, [assignment_id]);
5763
const { data: submissionsData } = useList<SubmissionWithGraderResultsAndReview>({
5864
resource: "submissions",
5965
meta: {
@@ -72,7 +78,27 @@ export default function AssignmentPage() {
7278
]
7379
});
7480

81+
const { data: autograderData } = useList<AutograderWithAssignment>({
82+
resource: "autograder",
83+
meta: {
84+
select: "*",
85+
order: "created_at, { ascending: false }"
86+
},
87+
pagination: {
88+
pageSize: 1000
89+
},
90+
filters: autograderFilters,
91+
sorters: [
92+
{
93+
field: "created_at",
94+
order: "desc"
95+
}
96+
]
97+
});
98+
7599
const submissions = submissionsData?.data;
100+
const autograder = autograderData?.data;
101+
76102
const review_settings = assignment.assignment_self_review_settings;
77103
const timeZone = course?.time_zone || "America/New_York";
78104

@@ -84,18 +110,20 @@ export default function AssignmentPage() {
84110
const daysUntilDue = assignment.due_date ? differenceInDays(new Date(assignment.due_date), new Date()) : null;
85111
const isGroupAssignment = assignment.group_config !== "individual";
86112
const hasSubmissions = (submissions?.length ?? 0) > 0;
87-
88113
trackEvent("assignment_viewed", {
89114
assignment_id: Number(assignment_id),
90115
course_id: Number(course_id),
91116
is_group_assignment: isGroupAssignment,
92117
days_until_due: daysUntilDue,
93118
has_submissions: hasSubmissions,
94-
assignment_slug: assignment.slug
119+
assignment_slug: assignment.slug
95120
});
96121
}
97122
}, [assignment, course_id, assignment_id, submissions, trackEvent]); // Include all values used inside
98123

124+
const submissionsPeriod = secondsToHours(autograder?.[0].max_submissions_period_secs);
125+
const maxSubmissions = autograder?.[0].max_submissions_count;
126+
99127
if (!assignment) {
100128
return <Skeleton height="40" width="100%" />;
101129
}
@@ -135,7 +163,18 @@ export default function AssignmentPage() {
135163
return sm.is_active;
136164
})}
137165
/>
138-
166+
{submissionsPeriod > 0 ? (
167+
<Box w="925px">
168+
<Alert.Root status="info" flexDirection="column" size="md">
169+
<Alert.Title>Submission Limit for this assignment</Alert.Title>
170+
<Alert.Description>
171+
This assignment has a submission limit of {maxSubmissions} submissions per every {submissionsPeriod} hour(s).
172+
</Alert.Description>
173+
</Alert.Root>
174+
</Box>
175+
) : (
176+
<></>
177+
)}
139178
<Heading size="md">Submission History</Heading>
140179
<CommitHistoryDialog
141180
assignment={assignment}

hooks/useAssignment.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,12 @@ class AssignmentController {
309309
}) {
310310
this._client = client;
311311
this._classRealTimeController = classRealTimeController;
312+
this.autograder = new TableController({
313+
query: client.from("autograder").select("*").eq("id", assignment_id),
314+
client: client,
315+
table: "autograder",
316+
classRealTimeController
317+
});
312318
this.submissions = new TableController({
313319
query: client.from("submissions").select("*").eq("assignment_id", assignment_id).eq("is_active", true),
314320
client: client,
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
--Migration: Allow students to view autograder data such as submissions count and max submissions in a period
2+
3+
CREATE POLICY "Students can view autograder data"
4+
ON public.autograder
5+
USING (
6+
SELECT up.private_profile_id
7+
FROM public.user_privileges up
8+
WHERE up.role = ('student')
9+
AND up.user_id = auth.uid()
10+
);

0 commit comments

Comments
 (0)