From 975093a30367561e069fcacea82a00c45f75be90 Mon Sep 17 00:00:00 2001 From: Jelte Fennema-Nio Date: Sun, 16 Feb 2025 11:56:18 +0100 Subject: [PATCH] Disallow assigning others as reviewer/committer on open patches --- pgcommitfest/commitfest/forms.py | 8 ++++++++ pgcommitfest/commitfest/models.py | 9 +++++++++ 2 files changed, 17 insertions(+) diff --git a/pgcommitfest/commitfest/forms.py b/pgcommitfest/commitfest/forms.py index 1353fc2d..6284f0b3 100644 --- a/pgcommitfest/commitfest/forms.py +++ b/pgcommitfest/commitfest/forms.py @@ -98,6 +98,14 @@ def __init__(self, *args, **kwargs): u.username, u.get_full_name() ) + # Only allow modifying reviewers and committers if the patch is closed. + if ( + self.instance.id is None + or self.instance.current_patch_on_commitfest().is_open + ): + del self.fields["committer"] + del self.fields["reviewers"] + class NewPatchForm(PatchForm): # Put threadmsgid first diff --git a/pgcommitfest/commitfest/models.py b/pgcommitfest/commitfest/models.py index 05956b83..88b184b6 100644 --- a/pgcommitfest/commitfest/models.py +++ b/pgcommitfest/commitfest/models.py @@ -1,5 +1,6 @@ from django.contrib.auth.models import User from django.db import models +from django.shortcuts import get_object_or_404 from datetime import datetime @@ -154,6 +155,10 @@ class Patch(models.Model, DiffableModel): def current_commitfest(self): return self.commitfests.order_by("-startdate").first() + def current_patch_on_commitfest(self): + cf = self.current_commitfest() + return get_object_or_404(PatchOnCommitFest, patch=self, commitfest=cf) + # Some accessors @property def authors_string(self): @@ -258,6 +263,10 @@ def OPEN_STATUS_CHOICES(cls): def is_closed(self): return self.status not in self.OPEN_STATUSES + @property + def is_open(self): + return not self.is_closed + @property def statusstring(self): return [v for k, v in self._STATUS_CHOICES if k == self.status][0]