Skip to content

Gate survey and live-poll staff actions on manage_surveys and run_polls - #1300

Open
DavidCzartoryski wants to merge 13 commits into
agents/DavidCzartoryski/cap-flashcardsfrom
agents/DavidCzartoryski/cap-surveys-polls
Open

DavidCzartoryski wants to merge 13 commits into
agents/DavidCzartoryski/cap-flashcardsfrom
agents/DavidCzartoryski/cap-surveys-polls

Conversation

@DavidCzartoryski

@DavidCzartoryski DavidCzartoryski commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Part of #1010. Stacked on #1299, which is stacked on #1286.

Agent: Cursor wrote this; nothing was run locally, CI is the first test run. GPT-6.1 Sol reviewed three times by reading; its findings are addressed in the later commits. CI passed on a9593067 (lint, unit-test job, e2e-local); the new commit awaits CI.

What changed

Adds manage_surveys and run_polls, puts them on the right default roles (and existing custom roles for run_polls), and switches survey/live-poll staff writes in RLS, RPCs, and management UI to those capabilities. Student survey/poll flows and staff views stay as they were. surveys.copy keeps today's grader class-access check so default graders do not lose CLI copy on day one.

Why

Instructors should be able to decide which TAs can manage surveys or run live polls, without changing what instructors and default graders can do on day one.

How

Table / function Before Category Capability
surveys INSERT (surveys_insert_instructors) instructor action manage_surveys
surveys UPDATE (surveys_update_instructors) instructor action manage_surveys
surveys SELECT staff / students grader / class member view / student-facing unchanged
survey_assignments INSERT instructor action manage_surveys + can_manage_survey_in_class (new values must point at a survey of the same class)
survey_assignments UPDATE instructor action USING: manage_surveys in the row's class; WITH CHECK: manage_surveys + can_manage_survey_in_class (so existing mismatched rows can be repaired, but cannot be saved pointing at another class's survey)
survey_assignments DELETE instructor action manage_surveys in the row's class only (a manager can delete a legacy mismatched row)
survey_assignments SELECT (assignee / graders / instructors) assignee / staff view / student-facing unchanged
survey_templates INSERT / UPDATE instructor action manage_surveys
survey_templates SELECT grader / global staff view unchanged
survey_templates DELETE creator only action unchanged (exception: not covered by manage_surveys)
survey_series INSERT / UPDATE / DELETE (was FOR ALL instructor) instructor action manage_surveys
survey_series SELECT grader/instructor view unchanged
create_survey_assignments instructor inside function action manage_surveys
soft_delete_survey instructor inside function action manage_surveys
reorder_surveys_in_series instructor inside function action manage_surveys
survey_responses INSERT / UPDATE / SELECT owner / staff student-facing / view unchanged
live_polls INSERT / UPDATE / DELETE grader action run_polls
live_polls SELECT live / staff anon+auth / grader student-facing / view unchanged
live_poll_responses staff INSERT / UPDATE / DELETE (was FOR ALL) grader action run_polls
live_poll_responses staff SELECT (split out) grader view unchanged (still grader; a grader without run_polls can read and cannot change)
live_poll_responses student/anon INSERT can_access_poll_response student-facing unchanged
analytics RPCs / broadcasts / can_respond_to_survey various view / student-facing unchanged
legacy polls / poll_questions / … n/a n/a dropped in 20251213200333_surveys_polls.sql; nothing left to migrate
CLI surveys.copy assertUserCanAccessClass action unchanged (still class access on both sides)

can_manage_survey_in_class(survey_id, class_id) is SECURITY DEFINER so survey_assignments INSERT and UPDATE WITH CHECK can check the parent survey without re-entering surveys RLS (surveys_select_students reads survey_assignments). It returns true only when the survey belongs to the class and the caller holds manage_surveys there, so /rpc cannot leak survey/class membership to an unrelated signed-in user. UPDATE USING and DELETE USING omit the helper so a manage_surveys holder in the row's class can repair or delete a legacy row whose survey_id and class_id disagree.

surveys INSERT / UPDATE stay the capability check alone. They do not require series_id to match the survey's class: CLI surveys.copy keeps the source series_id when copying into another class, and a same-class series check would block instructors from saving those rows.

seed_default_class_roles() still seeds manage_flashcards for graders and now also seeds run_polls. manage_surveys is instructor-only (existing classes get an explicit insert; new classes get it from the instructor CROSS JOIN).

Authoring pages (surveys/new, surveys/.../edit, polls/new) and poll Start/Stop use useCapabilityOnceLoaded / useCapability so a custom role with the capability is not bounced by an old grader role check.

Tests

Written, not run locally:

  • DB: instructor unchanged; default grader can run polls and cannot manage surveys; custom role with/without each capability; student survey response and poll answer still work; capability in class A does not reach class B; GRADER_SEEDED_CAPABILITIES includes run_polls.
  • DB (assignments): dual-enrolled grader with manage_surveys in A can manage A assignments; refused when class_id = A points at a B survey; retargeting an A assignment to a B survey raises 42501; any write to B's assignments is refused.
  • DB (legacy mismatched assignments): service-role seeds class_id = A rows pointing at a B survey; a manage_surveys holder in A can delete one and retarget another to an A survey.
  • DB (can_manage_survey_in_class): student of class B gets false for an A survey with A's class id; manage_surveys holder in A gets true for an A survey and false for a B survey with A's class id.
  • DB (templates/series/RPCs): insert/update with capability; refused without; template delete by non-creator with capability refused, by creator succeeds; management RPCs assert the specific Permission denied: manage_surveys required message.
  • DB (live poll responses): grader without run_polls can SELECT; UPDATE/DELETE leave the row unchanged; student can still answer.
  • UI: Create Survey / Manage Series hide without manage_surveys; custom-role grader with it opens new/edit; default grader and custom-role grader without it are redirected; Create / Open / Delete poll controls hide without run_polls; Start/Stop hidden (after Present is visible) and new-poll redirected without it; default grader (has run_polls) sees them.

Open questions

  1. CLI survey copying: with a write-scoped API token, an active grader of both classes can copy surveys between them with surveys copy (one or all, keeping the source status) without manage_surveys. assignments copy needs an instructor in the target class, so linked-survey copying there is not a grader path. Creating a survey in the app needs manage_surveys. Should surveys copy require manage_surveys on both classes? That would take it away from default graders.
  2. Cross-class series: a survey can reference a series from another class (CLI copy keeps series_id). That predates this PR and is left for a follow-up.

Made with Cursor

DavidCzartoryski and others added 3 commits November 16, 2026 00:16
…ls (#1010)

Move survey and live-poll writes onto capabilities so instructors can turn each action off for a role, without changing day-one access for instructors or default graders.

Co-authored-by: Cursor <cursoragent@cursor.com>
Record day-one seeding, what each capability covers, and which survey/poll rules stay views or student-facing.

Co-authored-by: Cursor <cursoragent@cursor.com>
Assert custom-role allow/deny, default grader day-one access, student responses, cross-class isolation, and hidden management controls without each capability.

Co-authored-by: Cursor <cursoragent@cursor.com>
@coderabbitai

coderabbitai Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

🗂️ Base branches to auto review: 1

  • staging

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: a8b08900-ccc9-45d3-b7aa-911c94422fbd

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

DavidCzartoryski and others added 8 commits November 16, 2026 00:27
…es (#1010)

Co-authored-by: Cursor <cursoragent@cursor.com>
…rects (#1010)

Co-authored-by: Cursor <cursoragent@cursor.com>
)

Co-authored-by: Cursor <cursoragent@cursor.com>
…ts (#1010)

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
@argos-ci

argos-ci Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Argos notifications ↗︎

Build Status Details Updated (UTC)
default (Inspect) ⚠️ Changes detected (Review) 7 changed Nov 16, 2026, 9:44 AM

This branch is waiting to be deployed

1 waiting deployment
report-unmask-review — 8c53d1b0 Waiting Nov 16, 2026 by DavidCzartoryski via owner-approval #323
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant