Assessment: Allow renaming assessment schemas#1902
Conversation
Assessment schemas could only be created, not renamed. Schema editors (course lecturers) can now rename a schema their phase owns; admins can rename any schema. Backend: - Widen the PUT /assessment-schema/:schemaID route to CourseLecturer (was PromptAdmin only), matching who can edit schema content. - Guard the update by ownership: a non-admin may only rename a schema owned by the current course phase (source_phase_id match), returning 403 otherwise, consistent with the phase-scoped GET. Admins bypass the guard so they keep renaming global/template schemas. - Expose a computed isOwnedByCurrentPhase flag on phase-scoped schema listings (no raw source phase id) so the client can gate the affordance. Frontend: - Add an updateAssessmentSchema mutation, useUpdateAssessmentSchema hook, and a RenameSchemaDialog surfaced next to the schema title on the schema configuration page, shown only for schemas the phase owns. Regenerated the assessment API spec.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughAssessment schema listings now expose phase ownership. Authorized lecturers can rename owned schemas through a new PUT flow, while admins bypass ownership checks. The frontend adds a validated rename dialog, mutation handling, cache invalidation, and error toasts. Course configurator mutations now use async handlers. ChangesAssessment schema renaming
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant User
participant RenameSchemaDialog
participant useUpdateAssessmentSchema
participant AssessmentSchemaAPI
participant UpdateAssessmentSchema
User->>RenameSchemaDialog: edit name and description
RenameSchemaDialog->>useUpdateAssessmentSchema: submit form
useUpdateAssessmentSchema->>AssessmentSchemaAPI: PUT schema update
AssessmentSchemaAPI->>UpdateAssessmentSchema: authorize and update
UpdateAssessmentSchema-->>AssessmentSchemaAPI: success or access error
AssessmentSchemaAPI-->>useUpdateAssessmentSchema: mutation result
useUpdateAssessmentSchema-->>RenameSchemaDialog: close and refresh or show error
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
mathildeshagl
left a comment
There was a problem hiding this comment.
A couple of changes requested on the rename dialog — both minor but worth fixing before merge. Backend authorization and tests look solid.
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
clients/assessment_component/src/assessment/pages/SchemaConfigurationPage/hooks/useUpdateAssessmentSchema.ts (1)
21-27: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueAvoid using
anyfor the error object.Consider typing the error as
unknownand checking it withinstanceof AxiosErrorto ensure type safety when accessing nested properties likeerror.response.♻️ Proposed refactor
Add the import for
AxiosErrorat the top of the file:import { AxiosError } from 'axios'Then update the
onErrorhandler:- onError: (error: any) => { - if (error?.response?.data?.error) { - setError(error.response.data.error) + onError: (error: unknown) => { + if (error instanceof AxiosError && error.response?.data?.error) { + setError(error.response.data.error) } else { setError('An unexpected error occurred. Please try again.') }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@clients/assessment_component/src/assessment/pages/SchemaConfigurationPage/hooks/useUpdateAssessmentSchema.ts` around lines 21 - 27, Update the onError handler in useUpdateAssessmentSchema to accept an unknown error instead of any, import and use AxiosError narrowing before accessing response.data.error, and retain the existing fallback message for non-Axios errors or missing error details.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@servers/assessment/assessmentSchemas/router.go`:
- Around line 204-216: Update the admin role lookup in the assessment schema
route to use promptSDK.PromptAdmin when reading tokenUser.Roles. Keep the
existing isAdmin value and UpdateAssessmentSchema flow unchanged.
---
Nitpick comments:
In
`@clients/assessment_component/src/assessment/pages/SchemaConfigurationPage/hooks/useUpdateAssessmentSchema.ts`:
- Around line 21-27: Update the onError handler in useUpdateAssessmentSchema to
accept an unknown error instead of any, import and use AxiosError narrowing
before accessing response.data.error, and retain the existing fallback message
for non-Axios errors or missing error details.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 03ecbf1c-400b-48ca-9d39-68fa5eda3068
📒 Files selected for processing (13)
clients/assessment_component/src/assessment/interfaces/assessmentSchema.tsclients/assessment_component/src/assessment/network/mutations/updateAssessmentSchema.tsclients/assessment_component/src/assessment/pages/SchemaConfigurationPage/SchemaConfigurationPage.tsxclients/assessment_component/src/assessment/pages/SchemaConfigurationPage/components/RenameSchemaDialog.tsxclients/assessment_component/src/assessment/pages/SchemaConfigurationPage/hooks/useUpdateAssessmentSchema.tsservers/assessment/assessmentSchemas/assessmentSchemaDTO/assessmentSchema.goservers/assessment/assessmentSchemas/router.goservers/assessment/assessmentSchemas/router_test.goservers/assessment/assessmentSchemas/service.goservers/assessment/assessmentSchemas/service_test.goservers/assessment/docs/docs.goservers/assessment/docs/swagger.jsonservers/assessment/docs/swagger.yaml
…e reload The graph mutations (delete, rename, phase graph, phase/participation data graph) used React Query's fire-and-forget `mutate`, so the `await`s in handleSave resolved immediately without waiting for the HTTP requests. The final participation mutation's onSuccess triggered window.location.reload(), which aborted the still-in-flight DELETE, leaving the removed phase persisted. Switch these to `mutateAsync` so each request completes before the next step and before the reload.
📝 Pull Request Template
Use this template to provide all necessary information for reviewing and testing your changes.
✨ What is the change?
Assessment schemas can now be renamed. On the schema configuration page, schemas owned by the current course phase show a rename (pencil) control that opens a dialog to edit the schema's name and description.
Backend (
servers/assessment):PUT /course_phase/{coursePhaseID}/assessment-schema/{schemaID}route is widened fromPromptAdmintoPromptAdmin, CourseLecturer, matching who may edit schema content (categories/competencies).source_phase_idis the current phase; otherwise the request is rejected with403(consistent with the phase-scopedGET, which already returns403for inaccessible schemas).PromptAdminbypasses the guard, so admins keep the ability to rename global/template schemas.isOwnedByCurrentPhaseboolean (no raw source-phase id is exposed) so the client can gate the rename affordance.Frontend (
clients/assessment_component):updateAssessmentSchemamutation anduseUpdateAssessmentSchemahook (invalidate['assessmentSchemas', phaseId]).RenameSchemaDialog, surfaced next to the schema title, shown only for schemas the phase owns.📌 Reason for the change / Link to issue
Closes #1677. Previously assessment schemas could only be created, never renamed. The people who can edit a schema should also be able to give it a new name.
The backend already had an
UpdateAssessmentSchemaquery and route, but it was admin-only, ignored the course phase, and had no UI. Renaming a shared/global schema in place would affect every consuming phase, so a non-admin rename is limited to schemas the phase owns; admins retain the broader ability via the existing endpoint.🧪 How to Test
PUTreturns403if called directly for such a schema as a non-admin).PromptAdmin, confirm renaming still works for any schema.🖼️ Screenshots (if UI changes are included)
✅ PR Checklist
Summary by CodeRabbit