Skip to content

Migrate contest, problem authors/curators/testers to Role#564

Open
whlongg wants to merge 2 commits intoVNOI-Admin:masterfrom
whlongg:feature/563-role-migration-v2
Open

Migrate contest, problem authors/curators/testers to Role#564
whlongg wants to merge 2 commits intoVNOI-Admin:masterfrom
whlongg:feature/563-role-migration-v2

Conversation

@whlongg
Copy link
Copy Markdown
Contributor

@whlongg whlongg commented Mar 26, 2026

Description

Refactor role management for Contest by migrating the separate authors, curators, and testers M2M relationships to a unified ContestRole model.

Type of change: refactor

What

  • add shared role constants and the new ContestRole model
  • add a single migration that creates the role table, copies existing data, and removes the legacy M2M fields
  • update contest permission and visibility logic to use the new role table
  • keep compatibility at the model API level by exposing authors, curators, and testers via query adapters, so most callers continue to work unchanged
  • update admin, queryset helpers, submission visibility logic, and related tests/utilities to use the new role structure
  • add unit tests for contest role behavior

Why

The existing role system stores authors, curators, and testers as separate M2M fields on Contest, which duplicates the same concept in multiple places and makes permission logic harder to maintain. Consolidating these relationships into a dedicated role table gives us a single extensible structure while preserving current behavior.

A follow-up PR will apply the same pattern to Problem.

Fixes #563 (partial — contest side)

How Has This Been Tested?

  • python manage.py migrate judge
  • python manage.py test judge.models.tests.test_contest judge.models.tests.test_role --keepdb
  • python manage.py test judge.views.tests.test_submission --keepdb
  • flake8 judge/models/role.py judge/models/__init__.py judge/models/contest.py judge/admin/contest.py judge/views/contests.py judge/views/organization.py judge/views/submission.py judge/views/api/api_v2.py judge/jinja2/submission.py judge/models/tests/test_contest.py judge/models/tests/test_role.py judge/models/tests/util.py judge/migrations/0220_migrate_contest_roles.py

Checklist

  • I have explained the purpose of this PR.
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the README/documentation
  • Any dependent changes have been merged and published in downstream modules
  • Informed of breaking changes, testing and migrations (if applicable).
  • Attached screenshots (if applicable).

Notes for reviewers

  • this PR includes a data migration; please run migrations in order through the full Django migration chain
  • old authors / curators / testers M2M fields on Contest are removed, but compatibility is preserved at the model usage level via adapter properties
  • Problem role migration will follow in a separate PR
  • no UI screenshots are included because this change is backend/model/admin focused

By submitting this pull request, I confirm that my contribution is made under the terms of the AGPL-3.0 License.

@whlongg whlongg changed the title refactor: unify contest and problem roles Migrate contest, problem authors/curators/testers to Role Mar 26, 2026
@whlongg whlongg force-pushed the feature/563-role-migration-v2 branch 3 times, most recently from 955a995 to d4d6086 Compare April 5, 2026 16:05
@whlongg whlongg mentioned this pull request Apr 5, 2026
11 tasks
@whlongg whlongg force-pushed the feature/563-role-migration-v2 branch from d4d6086 to a153e3f Compare April 5, 2026 16:24
@whlongg whlongg force-pushed the feature/563-role-migration-v2 branch from a153e3f to c56fcb7 Compare April 5, 2026 16:28
@whlongg whlongg mentioned this pull request Apr 5, 2026
11 tasks
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.

Migrate contest, problem authors/curators/testers to Role

2 participants