From 65e5298630b82de761af9d86b0ed85ebb267f14b Mon Sep 17 00:00:00 2001 From: Ole Laursen Date: Thu, 26 Jan 2012 13:28:02 +0000 Subject: [PATCH] Be more careful in handling Document.stream now that it can be null - Legacy-Id: 3865 --- ietf/doc/utils.py | 4 +--- ietf/idrfc/testsREDESIGN.py | 3 +-- ietf/ietfworkflows/accounts.py | 8 ++++++-- ietf/ietfworkflows/forms.py | 6 ++++++ ietf/ietfworkflows/tests.py | 2 ++ ietf/ietfworkflows/utils.py | 4 +++- 6 files changed, 19 insertions(+), 8 deletions(-) diff --git a/ietf/doc/utils.py b/ietf/doc/utils.py index 7a30959bd..83530d53d 100644 --- a/ietf/doc/utils.py +++ b/ietf/doc/utils.py @@ -8,10 +8,8 @@ def get_state_types(doc): res.append(doc.type_id) - #if doc.type_id in ("agenda", "minutes", "slides", "liai-att"): - # res.append(doc.type_id) if doc.type_id == "draft": - if doc.stream_id != "legacy": + if doc.stream_id and doc.stream_id != "legacy": res.append("draft-stream-%s" % doc.stream_id) res.append("draft-iesg") diff --git a/ietf/idrfc/testsREDESIGN.py b/ietf/idrfc/testsREDESIGN.py index 5b2f5196f..ffb9e6369 100644 --- a/ietf/idrfc/testsREDESIGN.py +++ b/ietf/idrfc/testsREDESIGN.py @@ -257,7 +257,6 @@ class EditInfoTestCase(django.test.TestCase): time=datetime.datetime.now(), type_id="draft", title="Testing adding a draft", - stream_id="ietf", group=Group.objects.get(acronym="mars"), abstract="Test test test.", rev="01", @@ -297,7 +296,7 @@ class EditInfoTestCase(django.test.TestCase): r = self.client.post(url, dict(intended_std_level=str(draft.intended_std_level_id), - stream=draft.stream_id, + stream="ietf", via_rfc_editor="1", ad=ad.pk, create_in_state=State.objects.get(type="draft-iesg", slug="watching").pk, diff --git a/ietf/ietfworkflows/accounts.py b/ietf/ietfworkflows/accounts.py index e44869ad9..ccf3c945d 100644 --- a/ietf/ietfworkflows/accounts.py +++ b/ietf/ietfworkflows/accounts.py @@ -83,8 +83,12 @@ def is_authorized_in_draft_streamREDESIGN(user, draft): if is_secretariat(user): return True - # must be a chair or delegate of the stream group (or draft group) from ietf.doc.models import Document + + if not super(Document, draft).stream: + return False + + # 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": group_req |= Q(group=draft.group) @@ -118,7 +122,7 @@ 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 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 == "ietf") and draft.group.type_id == "individ": person = get_person_for_user(user) if not person: return False diff --git a/ietf/ietfworkflows/forms.py b/ietf/ietfworkflows/forms.py index 2fd18bd5f..53c5c1a85 100644 --- a/ietf/ietfworkflows/forms.py +++ b/ietf/ietfworkflows/forms.py @@ -199,6 +199,9 @@ class DraftTagsStateForm(StreamDraftForm): def get_next_states(self): if settings.USE_DB_REDESIGN_PROXY_CLASSES: + if not self.draft.stream_id: + return [] + from ietf.doc.models import State state_type = "draft-stream-%s" % self.draft.stream_id s = self.draft.get_state(state_type) @@ -226,6 +229,9 @@ class DraftTagsStateForm(StreamDraftForm): def get_states(self): if settings.USE_DB_REDESIGN_PROXY_CLASSES: + if not self.draft.stream_id: + return [] + from ietf.doc.models import State states = State.objects.filter(type="draft-stream-%s" % self.draft.stream_id) if self.draft.stream_id == "ietf" and self.draft.group: diff --git a/ietf/ietfworkflows/tests.py b/ietf/ietfworkflows/tests.py index e4337b76e..ef3576a3f 100644 --- a/ietf/ietfworkflows/tests.py +++ b/ietf/ietfworkflows/tests.py @@ -141,6 +141,8 @@ class EditStreamInfoTestCase(django.test.TestCase): def test_set_stream(self): draft = make_test_data() + draft.stream = None + draft.save() url = urlreverse('edit_stream', kwargs=dict(name=draft.name)) login_testing_unauthorized(self, "secretary", url) diff --git a/ietf/ietfworkflows/utils.py b/ietf/ietfworkflows/utils.py index 65a5cf6a2..e5474d0dd 100644 --- a/ietf/ietfworkflows/utils.py +++ b/ietf/ietfworkflows/utils.py @@ -390,7 +390,9 @@ def update_stream(request, doc, comment, person, to_stream, extra_notify=[]): doc.save() e = DocEvent(type="changed_stream", time=doc.time, by=person, doc=doc) - e.desc = u"Stream changed to %s from %s" % (to_stream.name, from_stream.name) + e.desc = u"Stream changed to %s" % to_stream.name + if from_stream: + e.desc += u"from %s" % from_stream.name e.save() receivers = get_notification_receivers(doc, extra_notify)