]> git.ipfire.org Git - thirdparty/patchwork.git/commitdiff
Revert "Allow assigning of any user as delegate" v1.1.2
authorStephen Finucane <stephenfinucane@hotmail.com>
Sun, 25 Sep 2016 21:37:11 +0000 (22:37 +0100)
committerStephen Finucane <stephen@that.guru>
Sat, 8 Oct 2016 19:54:21 +0000 (20:54 +0100)
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.

Signed-off-by: Stephen Finucane <stephen@that.guru>
(cherry picked from commit 198139e4112cf337ffea403000441931b4ddad06)

patchwork/forms.py

index 628761bc902d9a57fb424aa33e16e1dc307d10d7..567249676e10816caaf71640a68ff06f62576198 100644 (file)
@@ -21,6 +21,7 @@ from __future__ import absolute_import
 
 from django.contrib.auth.models import User
 from django import forms
+from django.db.models import Q
 
 from patchwork.models import Patch, State, Bundle, UserProfile
 
@@ -98,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)
 
 
@@ -111,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
@@ -218,7 +225,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