Commit a99befc
Rework student dashboard data path as a SECURITY DEFINER RPC
Replaces `public.assignments_for_student_dashboard` (security_invoker view) with
`public.get_assignments_for_student_dashboard(p_class_id, p_student_profile_id)`,
a SECURITY DEFINER plpgsql function. Per CLAUDE.md ("Prefer Postgres RPCs for
data operations") and Jon's explicit guidance:
- Authorization is one explicit gate at the top of the function: the caller
must be either the requested student themselves OR an instructor/grader of
the requested class. Unauthorized calls raise 42501.
- `public.user_privileges` RLS is untouched and stays strictly the inlinable
`(user_id = auth.uid())` only. The recursion trap from earlier drafts
(function-based or inline-EXISTS policies on user_privileges) is avoided
entirely because the RPC bypasses RLS by definer privilege.
- The CTE chain is bounded by the (p_class_id, p_student_profile_id) args,
so every downstream join is O(assignments) regardless of class size.
- Defensive cleanup at the top of the migration drops any leftover policies/
helpers that earlier exploratory iterations may have applied locally
(DROP ... IF EXISTS — no-op on fresh environments).
Frontend callers updated:
- app/course/[course_id]/assignments/page.tsx: replaces
`useList({ resource: "assignments_for_student_dashboard", ... })` with
`supabase.rpc("get_assignments_for_student_dashboard", { p_class_id, p_student_profile_id })`.
- hooks/useGradebookWhatIf.tsx: same switch. This also fixes a latent view-as
bug here (the prior code filtered by `courseController.userId`, which is
always the real signed-in user, so the gradebook what-if wouldn't have
matched a viewed-as student's row either).
Types regenerated via `npm run client-local`; the view entry is gone from
SupabaseTypes.d.ts and the new RPC appears under Functions.
All 8 view-as E2E tests (4 specs × chromium + webkit) pass locally.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent bfe13e9 commit a99befc
5 files changed
Lines changed: 23705 additions & 24041 deletions
File tree
- app/course/[course_id]/assignments
- hooks
- supabase
- migrations
- utils/supabase
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
10 | 9 | | |
11 | 10 | | |
| 11 | + | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
| 16 | + | |
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
| 46 | + | |
| 47 | + | |
52 | 48 | | |
53 | 49 | | |
54 | 50 | | |
| |||
70 | 66 | | |
71 | 67 | | |
72 | 68 | | |
73 | | - | |
74 | 69 | | |
75 | 70 | | |
76 | 71 | | |
77 | 72 | | |
78 | 73 | | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | 74 | | |
84 | 75 | | |
85 | 76 | | |
| |||
95 | 86 | | |
96 | 87 | | |
97 | 88 | | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
115 | 123 | | |
116 | 124 | | |
117 | 125 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
52 | | - | |
| 52 | + | |
| 53 | + | |
53 | 54 | | |
54 | 55 | | |
55 | 56 | | |
| |||
72 | 73 | | |
73 | 74 | | |
74 | 75 | | |
75 | | - | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
76 | 81 | | |
77 | 82 | | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
83 | 87 | | |
84 | 88 | | |
85 | 89 | | |
| |||
0 commit comments