Skip to content

Commit 53eb7c8

Browse files
committed
Added migrations for document url model changes. Updated the name fixtures. Added ability for individual draft authors to edit document urls.
- Legacy-Id: 14172
1 parent 7b2d921 commit 53eb7c8

8 files changed

Lines changed: 123 additions & 11 deletions

File tree

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# -*- coding: utf-8 -*-
2+
# Generated by Django 1.10.8 on 2017-09-26 05:36
3+
from __future__ import unicode_literals
4+
5+
from django.db import migrations, models
6+
import django.db.models.deletion
7+
8+
9+
class Migration(migrations.Migration):
10+
11+
dependencies = [
12+
('name', '0027_docurltagname'),
13+
('doc', '0033_fix_conflict_review_dochistory'),
14+
]
15+
16+
operations = [
17+
migrations.CreateModel(
18+
name='DocumentURL',
19+
fields=[
20+
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
21+
('desc', models.CharField(blank=True, default=b'', max_length=255)),
22+
('url', models.URLField()),
23+
('doc', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='doc.Document')),
24+
('tag', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='name.DocUrlTagName')),
25+
],
26+
),
27+
]

ietf/doc/models.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,9 @@ def is_rfc(self):
335335
def author_list(self):
336336
return u", ".join(author.email_id for author in self.documentauthor_set.all() if author.email_id)
337337

338+
def authors(self):
339+
return [ a.person for a in self.documentauthor_set.all() ]
340+
338341
# This, and several other ballot related functions here, assume that there is only one active ballot for a document at any point in time.
339342
# If that assumption is violated, they will only expose the most recently created ballot
340343
def ballot_open(self, ballot_type_slug):

ietf/doc/views_doc.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@
5454
from ietf.community.utils import augment_docs_with_tracking_info
5555
from ietf.group.models import Role
5656
from ietf.group.utils import can_manage_group_type, can_manage_materials
57-
from ietf.ietfauth.utils import has_role, is_authorized_in_doc_stream, user_is_person, role_required
57+
from ietf.ietfauth.utils import ( has_role, is_authorized_in_doc_stream, user_is_person,
58+
role_required, is_individual_draft_author)
5859
from ietf.name.models import StreamName, BallotPositionName
5960
from ietf.utils.history import find_history_active_at
6061
from ietf.doc.forms import TelechatForm, NotifyForm
@@ -284,6 +285,7 @@ def document_main(request, name, rev=None):
284285
can_edit_stream_info = is_authorized_in_doc_stream(request.user, doc)
285286
can_edit_shepherd_writeup = can_edit_stream_info or user_is_person(request.user, doc.shepherd and doc.shepherd.person) or has_role(request.user, ["Area Director"])
286287
can_edit_notify = can_edit_shepherd_writeup
288+
can_edit_individual = is_individual_draft_author(request.user, doc)
287289

288290
can_edit_consensus = False
289291
consensus = nice_consensus(default_consensus(doc))
@@ -383,6 +385,7 @@ def document_main(request, name, rev=None):
383385
can_edit=can_edit,
384386
can_change_stream=can_change_stream,
385387
can_edit_stream_info=can_edit_stream_info,
388+
can_edit_individual=can_edit_individual,
386389
is_shepherd = user_is_person(request.user, doc.shepherd and doc.shepherd.person),
387390
can_edit_shepherd_writeup=can_edit_shepherd_writeup,
388391
can_edit_notify=can_edit_notify,

ietf/doc/views_draft.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
from ietf.doc.fields import SearchableDocAliasesField
3333
from ietf.group.models import Group, Role
3434
from ietf.iesg.models import TelechatDate
35-
from ietf.ietfauth.utils import has_role, is_authorized_in_doc_stream, user_is_person
35+
from ietf.ietfauth.utils import has_role, is_authorized_in_doc_stream, user_is_person, is_individual_draft_author
3636
from ietf.ietfauth.utils import role_required
3737
from ietf.message.models import Message
3838
from ietf.name.models import IntendedStdLevelName, DocTagName, StreamName, DocUrlTagName
@@ -1153,7 +1153,8 @@ def format_urls(urls, fs="\n"):
11531153
doc = get_object_or_404(Document, name=name)
11541154

11551155
if not (has_role(request.user, ("Secretariat", "Area Director"))
1156-
or is_authorized_in_doc_stream(request.user, doc)):
1156+
or is_authorized_in_doc_stream(request.user, doc)
1157+
or is_individual_draft_author(request.user, doc)):
11571158
return HttpResponseForbidden("You do not have the necessary permissions to view this page")
11581159

11591160
old_urls = format_urls(doc.documenturl_set.all())

ietf/ietfauth/utils.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
from django.contrib.auth import REDIRECT_FIELD_NAME
1010
from django.utils.decorators import available_attrs
1111

12+
import debug # pyflakes:ignore
13+
1214
from ietf.group.models import Role
1315
from ietf.person.models import Person
1416

@@ -128,7 +130,7 @@ def is_authorized_in_doc_stream(user, doc):
128130
if not doc.stream:
129131
return False
130132

131-
if doc.stream.slug == "ietf" and doc.group.type == "individ":
133+
if doc.stream.slug == "ietf" and doc.group.type_id == "individ":
132134
return False
133135

134136
if doc.stream.slug == "ietf":
@@ -141,3 +143,17 @@ def is_authorized_in_doc_stream(user, doc):
141143
group_req = Q()
142144

143145
return Role.objects.filter(Q(name__in=("chair", "secr", "delegate", "auth"), person__user=user) & group_req).exists()
146+
147+
def is_individual_draft_author(user, doc):
148+
149+
if not user.is_authenticated:
150+
return False
151+
152+
if not doc.group.type_id == "individ" :
153+
return False
154+
155+
if user.person in doc.authors():
156+
return True
157+
158+
return False
159+

ietf/name/fixtures/names.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7769,17 +7769,17 @@
77697769
{
77707770
"fields": {
77717771
"desc": "",
7772-
"name": "Document Issue Tracker",
7772+
"name": "Document issue tracker",
77737773
"order": 0,
77747774
"used": true
77757775
},
77767776
"model": "name.docurltagname",
7777-
"pk": "tracker"
7777+
"pk": "issues"
77787778
},
77797779
{
77807780
"fields": {
77817781
"desc": "",
7782-
"name": "Document Wiki",
7782+
"name": "Document wiki",
77837783
"order": 0,
77847784
"used": true
77857785
},
@@ -7789,7 +7789,7 @@
77897789
{
77907790
"fields": {
77917791
"desc": "",
7792-
"name": "Yang Impact Analysis",
7792+
"name": "Yang impact analysis",
77937793
"order": 0,
77947794
"used": true
77957795
},
@@ -7799,7 +7799,7 @@
77997799
{
78007800
"fields": {
78017801
"desc": "",
7802-
"name": "Extracted Yang Module",
7802+
"name": "Extracted yang module",
78037803
"order": 0,
78047804
"used": true
78057805
},
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# -*- coding: utf-8 -*-
2+
# Generated by Django 1.10.8 on 2017-09-26 05:36
3+
from __future__ import unicode_literals
4+
5+
from django.db import migrations, models
6+
7+
def forwards(apps,schema_editor):
8+
DocUrlTagName = apps.get_model('name','DocUrlTagName')
9+
10+
DocUrlTagName.objects.create(
11+
slug='wiki',
12+
name='Document wiki',
13+
)
14+
DocUrlTagName.objects.create(
15+
slug='issues',
16+
name='Document Issue Tracker',
17+
)
18+
DocUrlTagName.objects.create(
19+
slug='repository',
20+
name='Document Source Repository',
21+
)
22+
DocUrlTagName.objects.create(
23+
slug='yang-module',
24+
name='Extracted Yang Module',
25+
)
26+
DocUrlTagName.objects.create(
27+
slug='yang-impact-analysis',
28+
name='Yang Impact Analysis',
29+
)
30+
DocUrlTagName.objects.create(
31+
slug='yang-module-metadata',
32+
name='Yang module metadata',
33+
)
34+
35+
def backwards(apps,schema_editor):
36+
pass
37+
38+
class Migration(migrations.Migration):
39+
40+
dependencies = [
41+
('name', '0026_popuulate-important-date-names'),
42+
]
43+
44+
operations = [
45+
migrations.CreateModel(
46+
name='DocUrlTagName',
47+
fields=[
48+
('slug', models.CharField(max_length=32, primary_key=True, serialize=False)),
49+
('name', models.CharField(max_length=255)),
50+
('desc', models.TextField(blank=True)),
51+
('used', models.BooleanField(default=True)),
52+
('order', models.IntegerField(default=0)),
53+
],
54+
options={
55+
'ordering': ['order', 'name'],
56+
'abstract': False,
57+
},
58+
),
59+
migrations.RunPython(forwards, backwards),
60+
]
61+
62+

ietf/templates/doc/document_draft.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,12 +241,12 @@
241241
{% endif %}
242242

243243
{% with doc.documenturl_set.all as urls %}
244-
{% if urls or can_edit_stream_info %}
244+
{% if urls or can_edit_stream_info or can_edit_individual %}
245245
<tr>
246246
<td></td>
247247
<th>Additional URLs</th>
248248
<td class="edit">
249-
{% if can_edit_stream_info %}
249+
{% if can_edit_stream_info or can_edit_individual %}
250250
<a class="btn btn-default btn-xs" href="{% url 'ietf.doc.views_draft.edit_document_urls' name=doc.name %}">Edit</a>
251251
{% endif %}
252252
</td>

0 commit comments

Comments
 (0)