From: Stephen Finucane Date: Sun, 25 Sep 2016 21:37:11 +0000 (+0100) Subject: Revert "Allow assigning of any user as delegate" X-Git-Tag: v2.0.0-rc1~201 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=198139e4112cf337ffea403000441931b4ddad06;p=thirdparty%2Fpatchwork.git Revert "Allow assigning of any user as delegate" 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 --- diff --git a/patchwork/forms.py b/patchwork/forms.py index 8f73f8ba..6a9afe14 100644 --- a/patchwork/forms.py +++ b/patchwork/forms.py @@ -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 django.db.utils import ProgrammingError from patchwork.models import Patch, State, Bundle, UserProfile @@ -99,8 +100,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 +118,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 +232,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