Skip to content

Feat/frontend multi degree - #41

Merged
AsierCL merged 27 commits into
mainfrom
feat/frontend-multi-degree
Nov 17, 2026
Merged

AsierCL merged 27 commits into
mainfrom
feat/frontend-multi-degree

Conversation

@AsierCL

@AsierCL AsierCL commented Nov 17, 2026

Copy link
Copy Markdown
Collaborator

No description provided.

Specifies the move from a single-degree platform to three degrees
(Ingenieria Informatica G4012, Ingenieria Quimica G4022, Inteligencia
Artificial G4121) with an immutable degree per user and per-degree write
scope. Documents decisions D1-D13, the API contract, the error catalog,
frontend flows and the migration plan.

Includes the full catalog extracted from the official USC study plans
(49 + 47 + 50 subjects) and the ODD task plan for the implementation.
Introduces the degrees table and assigns Ingenieria Informatica to every
existing user and course (D8), makes the course code unique per degree
instead of globally, and adds the official study-plan metadata to subjects
(credits, semester, subject_type) per D13.

The migration is additive over existing rows: subjects keep their ids, so
files.subject_id and temp_files.subject_id are not re-pointed.

Adds a Postgres migration scenario that runs V1-V9, seeds legacy data and
then migrates, asserting the backfill, the preserved subject ids and the new
course uniqueness.
Adds the courses of Ingenieria Quimica and Inteligencia Artificial and
renames the 49 Information Engineering subjects to their official USC codes
in place, so files.subject_id and temp_files.subject_id keep pointing to the
same rows. Backfills the official study-plan metadata (credits with decimals,
semester, type) for every subject.

The migration test now migrates a V9 database to the current head and asserts
the catalog counts (49/47/50), the in-place rename and the decimal credits.
Adds the Degree entity on top of Course, makes users.degree and courses.degree
mandatory, and stores the official study-plan metadata on subjects. The degree
of a subject is not persisted: it is derived from its course, so there is a
single source of truth.

Registration now requires a degreeId and answers DEGREE_REQUIRED or
DEGREE_NOT_FOUND with stable error codes; login and profile responses expose
the degree as read-only output. There is no endpoint to change it, by design.

The bootstrap master and the demo seeds get the Information Engineering degree,
which is also what the migration assigned to every existing user.

Test fixtures use support/TestDegrees because the test profile generates the
schema with Hibernate and never runs the Flyway catalog.
Introduces the ADMIN role (V12) and moves /admin/** from MASTER to ADMIN.
With masters scoped per degree, a MASTER of one degree must not inherit the
platform panel of all of them, so governance (MASTER) and operations (ADMIN)
are now separate roles.

Login and profile responses expose isPlatformAdmin so the frontend never has
to infer administration rights from role == MASTER. An ADMIN cannot propose
its own promotion: it is an operational role and does not vote (D12).
Adds PATCH /admin/users/{id}/degree: ADMIN only, mandatory reason, audited as
DEGREE_CHANGE (V13) and bumps tokenVersion so open sessions of the moved user
die immediately. The degree stays immutable for the user (D2); this exists to
fix a signup mistake.

The endpoint surfaced two contract defects that are fixed here as well:

- Method-level validation failures (HandlerMethodValidationException, raised by
  @positive on a @PathVariable in Spring 6.2) answered 400 with an empty body.
  They now return the documented VALIDATION_ERROR envelope.
- Lombok plus Jackson exposed the boolean as both isPlatformAdmin and
  platformAdmin. Using Boolean collapses it into a single property.
Single enforcement point for the degree scope (GRADOS.md 5.3). Services resolve
the resource's degree from the resource itself and call the guard before any
mutation; the guard answers 403 DEGREE_SCOPE_FORBIDDEN with a stable code.

Reads never go through it: reading is public for everyone (D6). A resource
without degree is an internal data bug and fails as 500 instead of degrading
to allowed or to a misleading 403.
Upload proposals, deletion proposals, file scoring and visibility changes now
go through DegreeAccessGuard, resolving the degree from the subject or file
itself and never from the request payload. A cross-degree write answers 403
DEGREE_SCOPE_FORBIDDEN before touching S3, consuming quota or creating rows.

The new test also caught a real entity/DB divergence: Course.code still
declared a global unique, which Hibernate recreated in the H2 test schema
while the migration had dropped it in Postgres. Uniqueness is now
(degree_id, code) only.
Voting a file, promotion or expulsion proposal now requires the voter to belong
to the proposal's degree; the degree is derived from the proposal itself. The
vote count filters by that same degree, so votes left behind by a user who was
moved to another degree no longer count towards quorum.

Global configuration proposals stay the exception by design (D11): any master of
any degree may vote them because they affect every degree, and the quorum is
still measured over all masters. An ADMIN does not vote anything, proposals or
file scores (D12).
Expelling a master now requires sharing their degree, and the enabled-master
count that protects a degree from being left without representation is counted
per degree instead of platform-wide.

Closes a hole the global count could not see: an approved expulsion vote could
leave a degree with zero masters, because the vote path only checked that the
candidate was a MASTER. The approval path now re-checks that another enabled
master of that degree remains, and rejects the proposal otherwise.
Commenting counts as participating (D10): the thread of a file from another
degree stays readable, but writing in it answers 403 DEGREE_SCOPE_FORBIDDEN and
creates neither thread nor comment.
Adds the public catalogue endpoints: GET /degrees, /degrees/{id} and
/degrees/{id}/courses (the latter is the default screen after login).

Additive metadata so the frontend can tell apart subjects that share a name:
courses and subjects expose their degree, subjects expose credits, semester and
subject type, and files expose subjectId, subjectCode and the degree. Grouping
by subject name is no longer safe, by design.

GET /courses and /subjects keep working without filters for the current
frontend and accept an optional degreeId. Ordering now sorts by degree code in
the service, because H2 rejects ORDER BY on a column outside a DISTINCT
projection, so the repositories order by degree id instead.
Marks the specification as implemented and adds an as-built section listing the
nine deviations from the plan (no endpoint to appoint the first master, no
degree_id on subjects, isPlatformAdmin, degree filters, the Course.code unique
that only diverged in H2, the validation error envelope, ADMIN not scoring
files, the last-master recheck on the vote path and the reused error code).

Updates the overview (three degrees, ADMIN, immutable degree), the architecture
(Degree at the root, derivation rules, single enforcement point), the reputation
document (global reputation, per-degree ballots) and the endpoint guide with the
new catalogue routes and error codes.
Independent verification found two blocking gaps:

- editComment, deleteComment and setThreadLocked had no degree check, so a
  master of another degree could delete comments or lock threads of a community
  they do not belong to. All three now go through DegreeAccessGuard.
- PUT /users/me silently ignored a degreeId instead of rejecting it. The field
  is now declared only to answer 403 DEGREE_IMMUTABLE, so the client cannot
  believe the change was applied.

Documents D14: retractions (undoing your own vote, deleting your own proposal)
are deliberately not guarded, because they only remove the actor's contribution
and blocking them would trap stale rows after an administrative degree change.

Also fixes the shared test cleaner, which did not delete audit_records or
degrees and caused failures across test classes.
The global GET /courses and GET /subjects lists only existed for backward
compatibility: a course code is unique per degree, so a flat list of the three
degrees is ambiguous. The catalogue is now navigated from the degree with
GET /degrees/{id}/courses and the new GET /degrees/{id}/subjects. Detail by id
stays.

Cleanups that came with it:

- DegreeServiceImpl composes the collection services instead of querying the
  repositories, so the courses/subjects cache keeps working, and it answers 404
  for an unknown degree instead of an empty list.
- Fetch joins on degree for courses, subjects and files: every DTO with degree
  metadata was triggering one extra query per row.
- coursesCount is resolved with a fetch join instead of a lazy collection.
- FileProposalResponse exposes subjectId, subjectCode, courseId, courseName and
  the degree; FileProposalMapper stopped duplicating the same derivation three
  times.
- The last-master guard now answers 409 DEGREE_LAST_MASTER instead of reusing
  INVALID_ROLE_OPERATION, and the invariant is also tested at the service layer
  where the controller annotation cannot protect it.

Verified with 182 tests and PostgresMigrationIT (V1 to V13 on a clean database
and V9 to V13 on seeded data).
… proposals

V1 declared audit_records.actor_id as NOT NULL, but AuditServiceImpl.record
explicitly supports a null actor for system audits, and the expiration
scheduler runs without a SecurityContext.

In production that combination broke proposal expiration: closing an expired
proposal inserted an audit row with a null actor, the NOT NULL constraint
aborted the insert and the exception stopped the close. Tests never saw it
because the test profile generates the schema from the entity, where the actor
is nullable.

V14 aligns the database with the documented behaviour and switches the foreign
key to ON DELETE SET NULL so deleting a user keeps the audit trail instead of
blocking the delete. The entity annotation follows suit and the Postgres
migration test now inserts a null-actor audit row.
@AsierCL
AsierCL merged commit 29d9ea5 into main Nov 17, 2026
3 checks passed
@AsierCL
AsierCL deleted the feat/frontend-multi-degree branch November 17, 2026 19:00
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