Skip to content

Commit 1a3aa3b

Browse files
committed
Refactor slightly to make views_doc.py independent of other idrfc code
- Legacy-Id: 5294
1 parent 3e8de2a commit 1a3aa3b

5 files changed

Lines changed: 19 additions & 29 deletions

File tree

ietf/doc/utils.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,10 +220,16 @@ def add_state_change_event(doc, by, prev_state, new_state, timestamp=None):
220220
e.save()
221221
return e
222222

223-
224223
def prettify_std_name(n):
225224
if re.match(r"(rfc|bcp|fyi|std)[0-9]{4}", n):
226225
return n[:3].upper() + " " + n[3:]
227226
else:
228227
return n
229228

229+
def nice_consensus(consensus):
230+
mapping = {
231+
None: "Unknown",
232+
True: "Yes",
233+
False: "No"
234+
}
235+
return mapping[consensus]

ietf/idrfc/utils.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -177,19 +177,3 @@ def update_telechatREDESIGN(request, doc, by, new_telechat_date, new_returning_i
177177
if settings.USE_DB_REDESIGN_PROXY_CLASSES:
178178
update_telechat = update_telechatREDESIGN
179179

180-
def can_edit_intended_std_level(user, doc):
181-
return user.is_authenticated() and (
182-
has_role(user, ["Secretariat", "Area Director"]) or is_authorized_in_doc_stream(user, doc))
183-
184-
def can_edit_consensus(user, doc):
185-
return user.is_authenticated() and (
186-
has_role(user, ["Secretariat", "Area Director"]) or is_authorized_in_doc_stream(user, doc))
187-
188-
def nice_consensus(consensus):
189-
mapping = {
190-
None: "Unknown",
191-
True: "Yes",
192-
False: "No"
193-
}
194-
return mapping[consensus]
195-

ietf/idrfc/views_doc.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
from django.core.urlresolvers import reverse as urlreverse, NoReverseMatch
4444
from django.conf import settings
4545

46-
from ietf.idrfc.utils import *
4746
from ietf.doc.models import *
4847
from ietf.doc.utils import *
4948
from ietf.utils.history import find_history_active_at
@@ -140,10 +139,11 @@ def document_main(request, name, rev=None):
140139

141140
can_edit = has_role(request.user, ("Area Director", "Secretariat"))
142141
stream_slugs = StreamName.objects.values_list("slug", flat=True)
143-
can_change_stream = bool(can_edit or (request.user.is_authenticated() and
144-
Role.objects.filter(name__in=("chair", "auth"),
145-
group__acronym__in=stream_slugs,
146-
person__user=request.user)))
142+
can_change_stream = bool(can_edit or (
143+
request.user.is_authenticated() and
144+
Role.objects.filter(name__in=("chair", "auth"),
145+
group__acronym__in=stream_slugs,
146+
person__user=request.user)))
147147
can_edit_iana_state = has_role(request.user, ("Secretariat", "IANA"))
148148

149149
rfc_number = name[3:] if name.startswith("") else None
@@ -313,8 +313,6 @@ def document_main(request, name, rev=None):
313313
can_change_stream=can_change_stream,
314314
can_edit_stream_info=can_edit_stream_info,
315315
can_edit_shepherd_writeup=can_edit_shepherd_writeup,
316-
can_edit_intended_std_level=can_edit_intended_std_level(request.user, doc),
317-
can_edit_consensus=can_edit_consensus(request.user, doc),
318316
can_edit_iana_state=can_edit_iana_state,
319317

320318
rfc_number=rfc_number,
@@ -644,7 +642,7 @@ def get_ballot(name):
644642
from ietf.doc.models import DocAlias
645643
alias = get_object_or_404(DocAlias, name=name)
646644
d = alias.document
647-
from ietf.idtracker.models import InternetDraft
645+
from ietf.idtracker.models import InternetDraft, BallotInfo
648646
from ietf.idrfc.idrfc_wrapper import BallotWrapper, IdWrapper, RfcWrapper
649647
id = None
650648
bw = None

ietf/idrfc/views_edit.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,8 @@ def change_intention(request, name):
271271
if doc.type_id != 'draft':
272272
raise Http404
273273

274-
if not can_edit_intended_std_level(request.user, doc):
274+
if not (has_role(request.user, ("Secretariat", "Area Director"))
275+
or is_authorized_in_doc_stream(request.user, doc)):
275276
return HttpResponseForbidden("You do not have the necessary permissions to view this page")
276277

277278
login = request.user.get_profile()
@@ -902,7 +903,8 @@ def edit_consensus(request, name):
902903

903904
doc = get_object_or_404(Document, type="draft", name=name)
904905

905-
if not can_edit_consensus(request.user, doc):
906+
if not (has_role(request.user, ("Secretariat", "Area Director"))
907+
or is_authorized_in_doc_stream(request.user, doc)):
906908
return HttpResponseForbidden("You do not have the necessary permissions to view this page")
907909

908910
e = doc.latest_event(ConsensusDocEvent, type="changed_consensus")

ietf/templates/idrfc/document_draft.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
<tr>
6363
<td>Intended RFC status:</td>
6464
<td>
65-
<a {% if can_edit %}class="editlink" href="{% url doc_change_intended_status name=doc.name %}"{% endif %}>
65+
<a {% if can_edit or can_edit_stream_info %}class="editlink" href="{% url doc_change_intended_status name=doc.name %}"{% endif %}>
6666
{{ doc.intended_std_level|default:"Unknown" }}</a>
6767
</td>
6868
</tr>
@@ -110,7 +110,7 @@
110110
<tr>
111111
<td>Consensus:</td>
112112
<td>
113-
<a title="Whether the document is the result of a community consensus process as defined in RFC 5741" {% if can_edit_consensus %}class="editlink" href="{% url doc_edit_consensus name=doc.name %}"{% endif %}>
113+
<a title="Whether the document is the result of a community consensus process as defined in RFC 5741" {% if can_edit or can_edit_stream_info %}class="editlink" href="{% url doc_edit_consensus name=doc.name %}"{% endif %}>
114114
{{ consensus }}
115115
</a>
116116
</td>

0 commit comments

Comments
 (0)