Skip to content

Feature/563 problem role migration#570

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

Feature/563 problem role migration#570
whlongg wants to merge 2 commits intoVNOI-Admin:masterfrom
whlongg:feature/563-problem-role-migration

Conversation

@whlongg
Copy link
Copy Markdown
Contributor

@whlongg whlongg commented Apr 5, 2026

Description

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

Type of change: refactor

What

  • add the new ProblemRole model (extends role.py from the contest PR)
  • add a single migration that creates the role table, copies existing data, and removes the legacy M2M fields
  • update problem 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 (problem + submission), forms, queryset helpers, Polygon import, and related tests/utilities to use the new role structure
  • add unit tests for problem role behavior

Why

Same rationale as the contest PR (#564): the existing role system stores authors, curators, and testers as separate M2M fields on Problem, which duplicates the same concept in multiple places and makes permission logic harder to maintain. Consolidating into a dedicated role table gives us a single extensible structure while preserving current behavior.

Depends on #564 (contest role migration).

Fixes #563 (complete — problem side)

How Has This Been Tested?

  • python manage.py migrate judge
  • python manage.py test judge.models.tests.test_problem 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/problem.py judge/admin/problem.py judge/admin/submission.py judge/forms.py judge/views/problem.py judge/views/organization.py judge/views/submission.py judge/utils/problems.py judge/utils/codeforces_polygon.py judge/models/tests/test_problem.py judge/models/tests/test_role.py judge/models/tests/util.py judge/migrations/0221_migrate_problem_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 depends on Migrate contest, problem authors/curators/testers to Role #564 (contest role migration) — please merge that first
  • this PR includes a data migration; please run migrations in order through the full Django migration chain
  • old authors / curators / testers M2M fields on Problem are removed, but compatibility is preserved at the model usage level via adapter properties
  • 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 force-pushed the feature/563-problem-role-migration branch from 6f15024 to 95c7d09 Compare April 5, 2026 16:24
@whlongg whlongg force-pushed the feature/563-problem-role-migration branch from 95c7d09 to abbf77f Compare April 5, 2026 16:28
@whlongg whlongg closed this Apr 5, 2026
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

1 participant