diff mbox

Revert "Allow assigning of any user as delegate"

Message ID 1474839431-12769-1-git-send-email-stephen@that.guru
State Accepted
Headers show

Commit Message

Stephen Finucane Sept. 25, 2016, 9:37 p.m. UTC
From: Stephen Finucane <stephenfinucane@hotmail.com>

This reverts commit e0fd7cd91a5fbe0a0077c46bea870ccd09c8920d.

This change does not scale with a larger number of lists, and clearly
needs more work. Revert until such a time as this is carried out.
---
 patchwork/forms.py | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

Comments

Stephen Finucane Oct. 8, 2016, 7:49 p.m. UTC | #1
On 25 Sep 22:37, Stephen Finucane wrote:
> From: Stephen Finucane <stephenfinucane@hotmail.com>
> 
> This reverts commit e0fd7cd91a5fbe0a0077c46bea870ccd09c8920d.
> 
> This change does not scale with a larger number of lists, and clearly
> needs more work. Revert until such a time as this is carried out.

Applied and backported to stable/1.1 for an upcoming 1.1.2 release.

Stephen
diff mbox

Patch

diff --git a/patchwork/forms.py b/patchwork/forms.py
index 8f73f8b..cd954cd 100644
--- a/patchwork/forms.py
+++ b/patchwork/forms.py
@@ -99,8 +99,13 @@  class DeleteBundleForm(forms.Form):
 
 class DelegateField(forms.ModelChoiceField):
 
-    def __init__(self, *args, **kwargs):
-        queryset = User.objects
+    def __init__(self, project, instance=None, *args, **kwargs):
+        q = Q(profile__in=UserProfile.objects
+              .filter(maintainer_projects=project)
+              .values('pk').query)
+        if instance and instance.delegate:
+            q = q | Q(username=instance.delegate)
+        queryset = User.objects.complex_filter(q)
         super(DelegateField, self).__init__(queryset, *args, **kwargs)
 
 
@@ -112,7 +117,8 @@  class PatchForm(forms.ModelForm):
         if not project:
             raise Exception("meep")
         super(PatchForm, self).__init__(instance=instance, *args, **kwargs)
-        self.fields['delegate'] = DelegateField(required=False)
+        self.fields['delegate'] = DelegateField(project, instance,
+                                                required=False)
 
     class Meta:
         model = Patch
@@ -225,7 +231,8 @@  class MultiplePatchForm(forms.Form):
 
     def __init__(self, project, *args, **kwargs):
         super(MultiplePatchForm, self).__init__(*args, **kwargs)
-        self.fields['delegate'] = OptionalDelegateField(required=False)
+        self.fields['delegate'] = OptionalDelegateField(project=project,
+                                                        required=False)
 
     def save(self, instance, commit=True):
         opts = instance.__class__._meta