Skip to content

Assessment: Allow renaming assessment schemas#1902

Merged
rappm merged 4 commits into
mainfrom
feature/1677-rename-assessment-schema
Jul 15, 2026
Merged

Assessment: Allow renaming assessment schemas#1902
rappm merged 4 commits into
mainfrom
feature/1677-rename-assessment-schema

Conversation

@rappm

@rappm rappm commented Jul 11, 2026

Copy link
Copy Markdown
Member

📝 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):

  • The PUT /course_phase/{coursePhaseID}/assessment-schema/{schemaID} route is widened from PromptAdmin to PromptAdmin, CourseLecturer, matching who may edit schema content (categories/competencies).
  • The update is guarded by ownership: a non-admin may only rename a schema whose source_phase_id is the current phase; otherwise the request is rejected with 403 (consistent with the phase-scoped GET, which already returns 403 for inaccessible schemas). PromptAdmin bypasses the guard, so admins keep the ability to rename global/template schemas.
  • Phase-scoped schema listings now include a computed isOwnedByCurrentPhase boolean (no raw source-phase id is exposed) so the client can gate the rename affordance.
  • Regenerated the assessment API spec.

Frontend (clients/assessment_component):

  • New updateAssessmentSchema mutation and useUpdateAssessmentSchema hook (invalidate ['assessmentSchemas', phaseId]).
  • New 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 UpdateAssessmentSchema query 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

  1. As a course lecturer, open the Assessment phase → Settings → open a schema your course created (Assessment/Self/Peer/Tutor).
  2. Click the pencil next to the schema name, change the name and/or description, and save. The title updates and the change persists.
  3. Confirm the rename control is not shown for a global/template schema the phase only consumes (and that the PUT returns 403 if called directly for such a schema as a non-admin).
  4. As a PromptAdmin, confirm renaming still works for any schema.

🖼️ Screenshots (if UI changes are included)

✅ PR Checklist

  • Tested locally or on the dev environment
  • Code is clean, readable, and documented
  • Tests added or updated (if needed)
  • Screenshots attached for UI changes (if any)
  • Documentation updated (if relevant)

Summary by CodeRabbit

  • New Features
    • Assessment schemas can now be renamed and descriptions edited directly from the configuration page, with inline validation and clear save/error feedback.
  • Security & Permissions
    • Ownership-based controls were tightened for schema updates; unauthorized users now receive appropriate forbidden/not-found responses.
  • API & Visibility
    • Schema listings now include an ownership indicator for the current phase to drive the UI’s available actions.
  • Documentation / Tests
    • API documentation was updated for the new response behavior, alongside added coverage for permission scenarios.

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.
@rappm
rappm requested a review from a team July 11, 2026 18:15
@coderabbitai

coderabbitai Bot commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e72d3e07-19a7-466d-82bb-6c3fd114cdbb

📥 Commits

Reviewing files that changed from the base of the PR and between 64f87fe and f2fe746.

📒 Files selected for processing (4)
  • clients/assessment_component/src/assessment/pages/SchemaConfigurationPage/components/RenameSchemaDialog.tsx
  • clients/core/src/managementConsole/courseConfigurator/handlers/handleSave.ts
  • clients/core/src/managementConsole/courseConfigurator/handlers/useGraphMutations.ts
  • servers/assessment/assessmentSchemas/router.go
🚧 Files skipped from review as they are similar to previous changes (2)
  • clients/assessment_component/src/assessment/pages/SchemaConfigurationPage/components/RenameSchemaDialog.tsx
  • servers/assessment/assessmentSchemas/router.go

📝 Walkthrough

Walkthrough

Assessment 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.

Changes

Assessment schema renaming

Layer / File(s) Summary
Ownership metadata contract
clients/assessment_component/src/assessment/interfaces/assessmentSchema.ts, servers/assessment/assessmentSchemas/..., servers/assessment/docs/...
Assessment schema DTOs expose optional ownership metadata, and phase-scoped listings populate it from source phase ownership.
Protected schema update API
servers/assessment/assessmentSchemas/..., servers/assessment/docs/...
The PUT endpoint accepts lecturers, derives admin status from token roles, enforces ownership for non-admins, and documents 403/404 responses with service and router coverage.
Frontend rename flow
clients/assessment_component/src/assessment/pages/SchemaConfigurationPage/..., clients/assessment_component/src/assessment/network/mutations/...
Phase-owned schemas show a validated rename dialog that submits updates, reports failures through a toast, and invalidates schema queries after success.
Async course mutation wiring
clients/core/src/managementConsole/courseConfigurator/handlers/...
Course configurator mutation handlers and prop types now use mutateAsync and UseMutateAsyncFunction.

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
Loading

Possibly related PRs

Suggested reviewers: mathildeshagl, jgstyle, mtze

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning The clients/core course configurator mutation typing changes appear unrelated to assessment schema renaming. Remove or justify the managementConsole handler/mutation type changes, or split them into a separate PR if they are not required for #1677.
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: enabling assessment schema renaming.
Description check ✅ Passed The PR description follows the template and covers the change, reason, testing, checklist, and UI notes, with only screenshots/doc items left incomplete.
Linked Issues check ✅ Passed The changes implement #1677 by adding rename UI, backend ownership checks, admin bypass, and updated schema metadata.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/1677-rename-assessment-schema

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

Comment @coderabbitai help to get the list of available commands.

@rappm rappm added the schau mi o Translation: Ready to review label Jul 12, 2026

@mathildeshagl mathildeshagl left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of changes requested on the rename dialog — both minor but worth fixing before merge. Backend authorization and tests look solid.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 value

Avoid using any for the error object.

Consider typing the error as unknown and checking it with instanceof AxiosError to ensure type safety when accessing nested properties like error.response.

♻️ Proposed refactor

Add the import for AxiosError at the top of the file:

import { AxiosError } from 'axios'

Then update the onError handler:

-    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

📥 Commits

Reviewing files that changed from the base of the PR and between a4c7721 and 64f87fe.

📒 Files selected for processing (13)
  • clients/assessment_component/src/assessment/interfaces/assessmentSchema.ts
  • clients/assessment_component/src/assessment/network/mutations/updateAssessmentSchema.ts
  • clients/assessment_component/src/assessment/pages/SchemaConfigurationPage/SchemaConfigurationPage.tsx
  • clients/assessment_component/src/assessment/pages/SchemaConfigurationPage/components/RenameSchemaDialog.tsx
  • clients/assessment_component/src/assessment/pages/SchemaConfigurationPage/hooks/useUpdateAssessmentSchema.ts
  • servers/assessment/assessmentSchemas/assessmentSchemaDTO/assessmentSchema.go
  • servers/assessment/assessmentSchemas/router.go
  • servers/assessment/assessmentSchemas/router_test.go
  • servers/assessment/assessmentSchemas/service.go
  • servers/assessment/assessmentSchemas/service_test.go
  • servers/assessment/docs/docs.go
  • servers/assessment/docs/swagger.json
  • servers/assessment/docs/swagger.yaml

Comment thread servers/assessment/assessmentSchemas/router.go
…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.
@rappm
rappm merged commit 3d55015 into main Jul 15, 2026
80 of 81 checks passed
@rappm
rappm deleted the feature/1677-rename-assessment-schema branch July 15, 2026 16:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Component: Assessment schau mi o Translation: Ready to review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Rename Assessment Schemas

3 participants