Skip to content

Commit dcd372a

Browse files
committed
Restrict editor access in all states but proposed.
- Legacy-Id: 19205
1 parent 040e26b commit dcd372a

6 files changed

Lines changed: 55 additions & 13 deletions

File tree

ietf/doc/tests_bofreq.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def test_bofreq_main_page(self):
8080
self.write_bofreq_file(doc)
8181
editors = bofreq_editors(doc)
8282
responsible = bofreq_responsible(doc)
83-
url = urlreverse('ietf.doc.views_doc.document_main', kwargs=dict(name=doc))
83+
url = urlreverse('ietf.doc.views_doc.document_main', kwargs=dict(name=doc.name))
8484
r = self.client.get(url)
8585
self.assertContains(r,'Version: 01',status_code=200)
8686
q = PyQuery(r.content)
@@ -365,4 +365,31 @@ def test_start_new_bofreq(self):
365365
self.assertEqual(r.status_code, 200)
366366
q = PyQuery(r.content)
367367
self.assertTrue(q('form div.has-error'))
368+
369+
def test_post_proposed_restrictions(self):
370+
states = State.objects.filter(type_id='bofreq').exclude(slug='proposed')
371+
bofreq = BofreqFactory()
372+
editor = bofreq_editors(bofreq).first()
373+
374+
for view in ('submit', 'change_editors', 'edit_title'):
375+
url = urlreverse(f'ietf.doc.views_bofreq.{view}', kwargs=dict(name=bofreq.name))
376+
for state in states:
377+
bofreq.set_state(state)
378+
for username in ('secretary', 'ad', 'iab-member'):
379+
self.client.login(username=username, password=username+'+password')
380+
r = self.client.get(url)
381+
self.assertEqual(r.status_code,200)
382+
self.client.logout()
383+
self.client.login(username=editor.user.username, password=editor.user.username+'+password')
384+
r = self.client.get(url)
385+
self.assertEqual(r.status_code, 403, f'editor should not be able to use {view} in state {state.slug}')
386+
self.client.logout()
387+
388+
url = urlreverse('ietf.doc.views_doc.document_main', kwargs=dict(name=bofreq.name))
389+
self.client.login(username=editor.user.username, password=editor.user.username+'+password')
390+
r = self.client.get(url)
391+
self.assertEqual(r.status_code,200)
392+
q = PyQuery(r.content)
393+
self.assertEqual(0, len(q('td.edit>a.btn')))
394+
self.assertEqual([],q('#change-request'))
368395

ietf/doc/utils.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
from ietf.doc.models import TelechatDocEvent, DocumentActionHolder, EditedAuthorsDocEvent
3030
from ietf.name.models import DocReminderTypeName, DocRelationshipName
3131
from ietf.group.models import Role, Group
32-
from ietf.ietfauth.utils import has_role, is_authorized_in_doc_stream, is_individual_draft_author
32+
from ietf.ietfauth.utils import has_role, is_authorized_in_doc_stream, is_individual_draft_author, is_bofreq_editor
3333
from ietf.person.models import Person
3434
from ietf.review.models import ReviewWish
3535
from ietf.utils import draft, text
@@ -152,7 +152,8 @@ def can_unadopt_draft(user, doc):
152152
def can_edit_docextresources(user, doc):
153153
return (has_role(user, ("Secretariat", "Area Director"))
154154
or is_authorized_in_doc_stream(user, doc)
155-
or is_individual_draft_author(user, doc))
155+
or is_individual_draft_author(user, doc)
156+
or is_bofreq_editor(user, doc))
156157

157158
def two_thirds_rule( recused=0 ):
158159
# For standards-track, need positions from 2/3 of the non-recused current IESG.

ietf/doc/views_bofreq.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ def require_field(f):
7676
def submit(request, name):
7777
bofreq = get_object_or_404(Document, type="bofreq", name=name)
7878
previous_editors = bofreq_editors(bofreq)
79-
if not (has_role(request.user,('Secretariat', 'Area Director', 'IAB')) or request.user.person in previous_editors):
79+
state_id = bofreq.get_state_slug('bofreq')
80+
if not (has_role(request.user,('Secretariat', 'Area Director', 'IAB')) or (state_id=='proposed' and request.user.person in previous_editors)):
8081
permission_denied(request,"You do not have permission to upload a new revision of this BOF Request")
8182

8283
if request.method == 'POST':
@@ -189,7 +190,8 @@ class ChangeEditorsForm(forms.Form):
189190
def change_editors(request, name):
190191
bofreq = get_object_or_404(Document, type="bofreq", name=name)
191192
previous_editors = bofreq_editors(bofreq)
192-
if not (has_role(request.user,('Secretariat', 'Area Director', 'IAB')) or request.user.person in previous_editors):
193+
state_id = bofreq.get_state_slug('bofreq')
194+
if not (has_role(request.user,('Secretariat', 'Area Director', 'IAB')) or (state_id=='proposed' and request.user.person in previous_editors)):
193195
permission_denied(request,"You do not have permission to change this document's editors")
194196

195197
if request.method == 'POST':
@@ -267,7 +269,8 @@ class ChangeTitleForm(forms.Form):
267269
def edit_title(request, name):
268270
bofreq = get_object_or_404(Document, type="bofreq", name=name)
269271
editors = bofreq_editors(bofreq)
270-
if not (has_role(request.user,('Secretariat', 'Area Director', 'IAB')) or request.user.person in editors):
272+
state_id = bofreq.get_state_slug('bofreq')
273+
if not (has_role(request.user,('Secretariat', 'Area Director', 'IAB')) or (state_id=='proposed' and request.user.person in editors)):
271274
permission_denied(request, "You do not have permission to edit this document's title")
272275

273276
if request.method == 'POST':

ietf/doc/views_doc.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ def document_main(request, name, rev=None):
533533
editors = bofreq_editors(doc)
534534
responsible = bofreq_responsible(doc)
535535
can_manage = has_role(request.user,['Secretariat', 'Area Director', 'IAB'])
536-
is_editor = request.user.is_authenticated and request.user.person in editors
536+
editor_can_manage = doc.get_state_slug('bofreq')=='proposed' and request.user.is_authenticated and request.user.person in editors
537537

538538
return render(request, "doc/document_bofreq.html",
539539
dict(doc=doc,
@@ -545,7 +545,7 @@ def document_main(request, name, rev=None):
545545
can_manage=can_manage,
546546
editors=editors,
547547
responsible=responsible,
548-
is_editor=is_editor,
548+
editor_can_manage=editor_can_manage,
549549
))
550550

551551
if doc.type_id == "conflrev":

ietf/ietfauth/utils.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
from ietf.group.models import Role, GroupFeatures
2727
from ietf.person.models import Person
28+
from ietf.doc.utils_bofreq import bofreq_editors
2829

2930
def user_is_person(user, person):
3031
"""Test whether user is associated with person."""
@@ -194,6 +195,9 @@ def is_individual_draft_author(user, doc):
194195
if not user.is_authenticated:
195196
return False
196197

198+
if not doc.type_id=='draft':
199+
return False
200+
197201
if not doc.group.type_id == "individ" :
198202
return False
199203

@@ -204,6 +208,13 @@ def is_individual_draft_author(user, doc):
204208
return True
205209

206210
return False
211+
212+
def is_bofreq_editor(user, doc):
213+
if not user.is_authenticated:
214+
return False
215+
if not doc.type_id=='bofreq':
216+
return False
217+
return user.person in bofreq_editors(doc)
207218

208219
def openid_userinfo(claims, user):
209220
# Populate claims dict.

ietf/templates/doc/document_bofreq.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
<th>Title</th>
5151
<td class="edit">
5252
{% if not snapshot %}
53-
{% if is_editor or can_manage %}
53+
{% if editor_can_manage or can_manage %}
5454
{% doc_edit_button 'ietf.doc.views_bofreq.edit_title' name=doc.name %}
5555
{% endif %}
5656
{% endif %}
@@ -87,7 +87,7 @@
8787
<th>Editor{{editors|pluralize}}</th>
8888
<td class="edit">
8989
{% if not snapshot %}
90-
{% if is_editor or can_manage %}
90+
{% if editor_can_manage or can_manage %}
9191
{% doc_edit_button 'ietf.doc.views_bofreq.change_editors' name=doc.name %}
9292
{% endif %}
9393
{% endif %}
@@ -117,12 +117,12 @@
117117
</tr>
118118

119119
{% with doc.docextresource_set.all as resources %}
120-
{% if resources or is_editor or can_manage %}
120+
{% if resources or editor_can_manage or can_manage %}
121121
<tr>
122122
<td></td>
123123
<th>Additional Resources</th>
124124
<td class="edit">
125-
{% if is_editor or can_manage %}
125+
{% if editor_can_manage or can_manage %}
126126
<a class="btn btn-default btn-xs" href="{% url 'ietf.doc.views_draft.edit_doc_extresources' name=doc.name %}">Edit</a>
127127
{% endif %}
128128
</td>
@@ -165,7 +165,7 @@
165165
</table>
166166

167167
{% if not snapshot %}
168-
{% if is_editor or can_manage %}
168+
{% if editor_can_manage or can_manage %}
169169
<p id="change-request"><a class="btn btn-default" href="{% url 'ietf.doc.views_bofreq.submit' name=doc.name %}">Change BOF request text</a></p>
170170
{% endif %}
171171
{% endif %}

0 commit comments

Comments
 (0)