Tweaked code to correct access to document metadata and actions, adding RGs to the groups and group secretaries to the roles which are given access.

- Legacy-Id: 5939
This commit is contained in:
Henrik Levkowetz 2013-08-01 14:37:50 +00:00
commit 17eb95c180
5 changed files with 42 additions and 30 deletions
ietf
group
ietfworkflows
templates/ietfworkflows

View file

@ -100,12 +100,12 @@ class IETFWG(Group):
group_acronym__acronym__in="acronym__in",
group_acronym__acronym__contains="acronym__contains",
email_archive__startswith="list_archive__startswith",
group_type=lambda v: ("type", { 1: "wg" }[int(v)]),
group_type=lambda v: ("type__in", { 1: ("wg", "rg") }[int(v)]),
status=lambda v: ("state__in", { 1: ("active", "bof") }[int(v)]),
areagroup__area__status=lambda v: ("parent__state", { 1: "active" }[v]),
start_date__isnull=lambda v: None if v else ("groupevent__changestategroupevent__state__slug", "active"),
),
always_filter=dict(type__in=("wg", "individ", "area")))
always_filter=dict(type__in=("wg", "rg", "individ", "area")))
def from_object(self, base):
for f in base._meta.fields:

View file

@ -25,6 +25,8 @@ def is_wgchair(person):
def is_wgchairREDESIGN(person):
return bool(Role.objects.filter(name="chair", group__type="wg", group__state="active", person=person))
def is_rgchairREDESIGN(person):
return bool(Role.objects.filter(name="chair", group__type="rg", group__state="active", person=person))
def is_wgdelegate(person):
return bool(person.wgdelegate_set.all())
@ -32,6 +34,9 @@ def is_wgdelegate(person):
def is_wgdelegateREDESIGN(person):
return bool(Role.objects.filter(name="delegate", group__type="wg", group__state="active", person=person))
def is_rgdelegateREDESIGN(person):
return bool(Role.objects.filter(name="delegate", group__type="rg", group__state="active", person=person))
def is_delegate_of_stream(user, stream):
if is_secretariat(user):
return True
@ -57,7 +62,6 @@ def is_chair_of_streamREDESIGN(user, stream):
return False
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):
if is_secretariat(user):
return True
@ -92,16 +96,18 @@ def is_authorized_in_draft_streamREDESIGN(user, draft):
# must be a chair or delegate of the stream group (or draft group)
group_req = Q(group__acronym=super(Document, draft).stream.slug)
if draft.group and super(Document, draft).stream.slug == "ietf":
if draft.group and super(Document, draft).stream.slug in ["ietf", "irtf"]:
group_req |= Q(group=draft.group)
return user.is_authenticated() and bool(Role.objects.filter(name__in=("chair", "delegate"), person__user=user).filter(group_req))
return user.is_authenticated() and bool(Role.objects.filter(name__in=("chair", "secr", "delegate"), person__user=user).filter(group_req))
if settings.USE_DB_REDESIGN_PROXY_CLASSES:
from ietf.liaisons.accounts import is_secretariat, get_person_for_user
is_wgdelegate = is_wgdelegateREDESIGN
is_wgchair = is_wgchairREDESIGN
is_rgdelegate = is_rgdelegateREDESIGN
is_rgchair = is_rgchairREDESIGN
is_chair_of_stream = is_chair_of_streamREDESIGN
is_delegate_of_stream = is_delegate_of_streamREDESIGN
is_authorized_in_draft_stream = is_authorized_in_draft_streamREDESIGN
@ -116,11 +122,11 @@ def can_edit_stream(user, draft):
return is_secretariat(user)
def can_adopt(user, draft):
if settings.USE_DB_REDESIGN_PROXY_CLASSES and (not draft.stream_id or draft.stream_id == "ietf") and draft.group.type_id == "individ":
if settings.USE_DB_REDESIGN_PROXY_CLASSES and (not draft.stream_id or draft.stream_id in ["ietf", "irtf"]) and draft.group.type_id == "individ":
person = get_person_for_user(user)
if not person:
return False
return is_wgchair(person) or is_wgdelegate(person) or is_secretariat(user)
return is_wgchair(person) or is_rgchair(person) or is_wgdelegate(person) or is_rgdelegate() or is_secretariat(user)
else:
return is_secretariat(user)

View file

@ -53,32 +53,32 @@ class StreamDraftForm(forms.Form):
class NoWorkflowStateForm(StreamDraftForm):
comment = forms.CharField(widget=forms.Textarea, required=False)
weeks = forms.IntegerField(required=False)
wg = forms.ChoiceField(required=False)
group = forms.ChoiceField(required=False)
template = 'ietfworkflows/noworkflow_state_form.html'
def __init__(self, *args, **kwargs):
super(NoWorkflowStateForm, self).__init__(*args, **kwargs)
self.wgs = None
self.groups = None
if is_secretariat(self.user):
wgs = IETFWG.objects.all().order_by('group_acronym__acronym')
groups = IETFWG.objects.all().order_by('group_acronym__acronym')
else:
if settings.USE_DB_REDESIGN_PROXY_CLASSES:
wgs = IETFWG.objects.filter(type="wg", state="active", role__name__in=("chair", "delegate"), role__person__user=self.user).order_by('acronym').distinct()
groups = IETFWG.objects.filter(type__in=["wg", "rg"], state="active", role__name__in=("chair", "secr", "delegate"), role__person__user=self.user).order_by('acronym').distinct()
else:
wgs = set([i.group_acronym for i in self.person.wgchair_set.all()]).union(set([i.wg for i in self.person.wgdelegate_set.all()]))
wgs = list(wgs)
wgs.sort(lambda x, y: cmp(x.group_acronym.acronym, y.group_acronym.acronym))
self.wgs = wgs
groups = set([i.group_acronym for i in self.person.wgchair_set.all()]).union(set([i.wg for i in self.person.wgdelegate_set.all()]))
groups = list(groups)
groups.sort(lambda x, y: cmp(x.group_acronym.acronym, y.group_acronym.acronym))
self.groups = groups
if settings.USE_DB_REDESIGN_PROXY_CLASSES:
self.fields['wg'].choices = [(i.pk, '%s - %s' % (i.acronym, i.name)) for i in self.wgs]
self.fields['group'].choices = [(i.pk, '%s - %s' % (i.acronym, i.name)) for i in self.groups]
else:
self.fields['wg'].choices = [(i.pk, '%s - %s' % (i.group_acronym.acronym, i.group_acronym.name)) for i in self.wgs]
self.fields['group'].choices = [(i.pk, '%s - %s' % (i.group_acronym.acronym, i.group_acronym.name)) for i in self.groups]
def save(self):
comment = self.cleaned_data.get('comment').strip()
weeks = self.cleaned_data.get('weeks')
wg = IETFWG.objects.get(pk=self.cleaned_data.get('wg'))
group = IETFWG.objects.get(pk=self.cleaned_data.get('group'))
estimated_date = None
if weeks:
now = datetime.date.today()
@ -90,7 +90,10 @@ class NoWorkflowStateForm(StreamDraftForm):
doc.time = datetime.datetime.now()
new_stream = StreamName.objects.get(slug="ietf")
if group.type.slug == "rg":
new_stream = StreamName.objects.get(slug="irtf")
else:
new_stream = StreamName.objects.get(slug="ietf")
if doc.stream != new_stream:
e = DocEvent(type="changed_stream")
@ -103,16 +106,16 @@ class NoWorkflowStateForm(StreamDraftForm):
e.save()
doc.stream = new_stream
if doc.group.pk != wg.pk:
if doc.group.pk != group.pk:
e = DocEvent(type="changed_group")
e.time = doc.time
e.by = self.user.get_profile()
e.doc = doc
e.desc = u"Changed group to <b>%s (%s)</b>" % (wg.name, wg.acronym.upper())
e.desc = u"Changed group to <b>%s (%s)</b>" % (group.name, group.acronym.upper())
if doc.group.type_id != "individ":
e.desc += " from %s (%s)" % (doc.group.name, doc.group.acronym)
e.save()
doc.group_id = wg.pk
doc.group_id = group.pk
doc.save()
self.draft = InternetDraft.objects.get(pk=doc.pk) # make sure proxy object is updated
@ -130,7 +133,10 @@ class NoWorkflowStateForm(StreamDraftForm):
if settings.USE_DB_REDESIGN_PROXY_CLASSES:
from ietf.doc.models import State
to_state = State.objects.get(used=True, slug="c-adopt", type="draft-stream-%s" % self.draft.stream_id)
if self.draft.stream_id == "irtf":
to_state = State.objects.get(used=True, slug="active", type="draft-stream-irtf")
else:
to_state = State.objects.get(used=True, slug="c-adopt", type="draft-stream-%s" % self.draft.stream_id)
else:
to_state = get_state_by_name(CALL_FOR_ADOPTION)
update_state(self.request, self.draft,

View file

@ -36,14 +36,14 @@ class EditStreamInfoTestCase(django.test.TestCase):
self.assertEquals(r.status_code, 200)
q = PyQuery(r.content)
self.assertEquals(len(q('form input[type=submit][value*=adopt]')), 1)
self.assertEquals(len(q('form select[name="wg"] option')), 1) # we can only select "mars"
self.assertEquals(len(q('form select[name="group"] option')), 1) # we can only select "mars"
# adopt in mars WG
mailbox_before = len(outbox)
events_before = draft.docevent_set.count()
r = self.client.post(url,
dict(comment="some comment",
wg=Group.objects.get(acronym="mars").pk,
group=Group.objects.get(acronym="mars").pk,
weeks="10"))
self.assertEquals(r.status_code, 302)

View file

@ -1,7 +1,7 @@
<form action="" method="post">
<table class="ietf-table edit-form" style="width: 100%;">
<tr>
<th>Adopt this draft in your WG</th>
<th>Adopt this draft in your group</th>
</tr>
<tr style="vertical-align: top;"><td style="width: 50%;">
<div class="field{% if form.errors.comment %} error{% endif %}">
@ -11,11 +11,11 @@
</div>
<div class="field{% if form.errors.weeks %} error{% endif %}">
{{ form.weeks.errors }}
Estimated time in 'Call for Adoption by WG Issued': <input type="text" name="weeks" value="{{ form.data.weeks }}" /> (in weeks)
Estimated time in 'Call for Adoption by WG/RG Issued': <input type="text" name="weeks" value="{{ form.data.weeks }}" /> (in weeks)
</div>
<div class="field{% if form.errors.wg %} error{% endif %}">
Adopt in WG: {{ form.wg }}
{{ form.wg.errors }}
<div class="field{% if form.errors.group %} error{% endif %}">
Adopt in Group: {{ form.group }}
{{ form.group.errors }}
</div>
<input type="submit" name="change" value="Call for adoption" />
</td></tr>