Port recently merged stream delegate management in ietfworkflows to new schema

- Legacy-Id: 3687
This commit is contained in:
Ole Laursen 2011-11-22 21:15:49 +00:00
parent 576b2bacce
commit 367d6b2116
5 changed files with 67 additions and 7 deletions

View file

@ -41,7 +41,7 @@ def is_delegate_of_stream(user, stream):
def is_delegate_of_streamREDESIGN(user, stream):
if is_secretariat(user):
return True
return bool(Role.objects.filter(group__acronym=stream.slug, name="delegate", person__user=user))
return user.is_authenticated() and bool(Role.objects.filter(group__acronym=stream.slug, name="delegate", person__user=user))
def is_chair_of_stream(user, stream):
@ -53,7 +53,7 @@ def is_chair_of_stream(user, stream):
def is_chair_of_streamREDESIGN(user, stream):
if is_secretariat(user):
return True
return bool(Role.objects.filter(group__acronym=stream.slug, name="chair", person__user=user))
return user.is_authenticated() and bool(Role.objects.filter(group__acronym=stream.slug, name="chair", person__user=user))
def is_authorized_in_draft_stream(user, draft):

View file

@ -20,8 +20,9 @@ from ietf.ietfworkflows.streams import (get_stream_from_draft, get_streamed_draf
from ietf.ietfworkflows.constants import CALL_FOR_ADOPTION, IETF_STREAM
from redesign.doc.utils import get_tags_for_stream_id
from redesign.doc.models import save_document_in_history, DocEvent, Document
from redesign.name.models import DocTagName, DocStreamName
from redesign.group.models import Group, GroupStateTransitions
from redesign.name.models import DocTagName, DocStreamName, RoleName
from redesign.group.models import Group, GroupStateTransitions, Role
from redesign.person.models import Person, Email
class StreamDraftForm(forms.Form):
@ -333,7 +334,10 @@ class StreamDelegatesForm(forms.Form):
super(StreamDelegatesForm, self).__init__(*args, **kwargs)
def get_person(self, email):
persons = PersonOrOrgInfo.objects.filter(emailaddress__address=email).distinct()
if settings.USE_DB_REDESIGN_PROXY_CLASSES:
persons = Person.objects.filter(email__address=email).distinct()
else:
persons = PersonOrOrgInfo.objects.filter(emailaddress__address=email).distinct()
if not persons:
return None
return persons[0]
@ -343,8 +347,17 @@ class StreamDelegatesForm(forms.Form):
self.person = self.get_person(email)
if not self.person:
raise forms.ValidationError('There is no user with this email in the system')
return email
def save(self):
if settings.USE_DB_REDESIGN_PROXY_CLASSES:
# FIXME: should save group history here
Role.objects.get_or_create(person=self.person,
group=Group.objects.get(acronym=self.stream.slug),
name=RoleName.objects.get(slug="delegate"),
email=Email.objects.get(address=self.cleaned_data.get('email')))
return
StreamDelegate.objects.get_or_create(
person=self.person,
stream=self.stream)

View file

@ -168,6 +168,35 @@ class EditStreamInfoTestCase(django.test.TestCase):
self.assertTrue("wgchairman@ietf.org" in unicode(outbox[-1]))
self.assertTrue("wgdelegate@ietf.org" in unicode(outbox[-1]))
def test_manage_stream_delegates(self):
make_test_data()
url = urlreverse('stream_delegates', kwargs=dict(stream_name="IETF"))
login_testing_unauthorized(self, "secretary", url)
# get
r = self.client.get(url)
self.assertEquals(r.status_code, 200)
q = PyQuery(r.content)
self.assertEquals(len(q('input[type=submit][value*=Add]')), 1)
delegate = Email.objects.get(address="plain@example.com")
# add delegate
r = self.client.post(url,
dict(email=delegate.address))
self.assertEquals(r.status_code, 200)
self.assertEquals(Role.objects.filter(group__acronym="ietf", name="delegate", person__email=delegate).count(), 1)
# remove delegate again
r = self.client.post(url,
dict(remove_delegate=[delegate.person.pk],
delete="1"))
self.assertEquals(r.status_code, 200)
self.assertEquals(Role.objects.filter(group__acronym="ietf", name="delegate", person__email=delegate).count(), 0)
if not settings.USE_DB_REDESIGN_PROXY_CLASSES:
# the above tests only work with the new schema
del EditStreamInfoTestCase

View file

@ -122,7 +122,12 @@ def stream_delegates(request, stream_name):
if request.method == 'POST':
if request.POST.get('delete', False):
pk_list = request.POST.getlist('remove_delegate')
StreamDelegate.objects.filter(stream=stream, person__pk__in=pk_list).delete()
if settings.USE_DB_REDESIGN_PROXY_CLASSES:
# FIXME: should save group history here
from redesign.group.models import Role
Role.objects.filter(person__in=pk_list, group__acronym=stream.slug, name="delegate").delete()
else:
StreamDelegate.objects.filter(stream=stream, person__pk__in=pk_list).delete()
else:
form = StreamDelegatesForm(request.POST, stream=stream)
if form.is_valid():

View file

@ -17,12 +17,25 @@ def make_test_data():
state_id="active",
type_id="ietf",
parent=None)
ietf = Group.objects.create(
name="IETF",
acronym="ietf",
state_id="active",
type_id="ietf",
parent=None)
for x in ["irtf", "iab", "ise"]:
Group.objects.create(
name=x.upper(),
acronym=x,
state_id="active",
type_id="ietf",
parent=None)
area = Group.objects.create(
name="Far Future",
acronym="farfut",
state_id="active",
type_id="area",
parent=None)
parent=ietf)
group = Group.objects.create(
name="Martian Special Interest Group",
acronym="mars",