Skip to content

Commit

Permalink
Revert "Allow assigning of any user as delegate"
Browse files Browse the repository at this point in the history
This reverts commit e0fd7cd.

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 198139e)
  • Loading branch information
stephenfin committed Oct 8, 2016
1 parent 6703cb5 commit 424617b
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions patchwork/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

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

Expand Down Expand Up @@ -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)


Expand All @@ -111,7 +117,8 @@ def __init__(self, instance=None, project=None, *args, **kwargs):
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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 424617b

Please sign in to comment.