Merge lp:~sinzui/launchpad/system-bug-comments-api into lp:launchpad

Proposed by Curtis Hovey
Status: Merged
Approved by: Curtis Hovey
Approved revision: no longer in the source branch.
Merged at revision: 16331
Proposed branch: lp:~sinzui/launchpad/system-bug-comments-api
Merge into: lp:launchpad
Diff against target: 73 lines (+32/-0)
3 files modified
lib/lp/bugs/tests/test_bug_messages_webservice.py (+19/-0)
lib/lp/services/messages/interfaces/message.py (+9/-0)
lib/lp/services/messages/model/message.py (+4/-0)
To merge this branch: bzr merge lp:~sinzui/launchpad/system-bug-comments-api
Reviewer Review Type Date Requested Status
Brad Crittenden (community) Approve
Review via email: mp+137308@code.launchpad.net

Commit message

Do not make links to a message's parent message.

Description of the change

A bug message is accessible over the API via two approaches. Iterating
over bug.messages or directly loading the message via its URL
(eg, +bug/1004834/comments/2). The latter case can oops with
NoCanonicalUrl (OOPS-2f0df95d0ba20796d46cfe2a1b3c3fa1) because the parent
message is not one of the bug's messages, it it does not have an index number.
bug.message returns IIndexedMessage which sets the parent to None to enforce
non-threaded messaging in bugs, but the latter case an IMessage which is
threaded. Both IIndexedMessage and IMessage claim to be bug messages, but
we know that the DB is storing all messages in the table.

--------------------------------------------------------------------

RULES

    Pre-implementation: no one
    * IMessage was exported as an accident of exporting bug messages, and
      they are now permanently in the API. They claim to just be bug messages
      as can be seen by their URL.
    * Since bug messages are not threaded, and we cannot unexport the
      parent attribute, we can follow IIndexedMessage's example by ensuring
      None is the value returned.
    * Export a replacement parent attr on the API that retrofits the beta
      api to return None.

QA

    * visit https://api.qastaging.launchpad.net/devel/ubuntu/+source/request-tracker3.8/+bug/1004834/comments/2
    * Verify the page loads.

LoC

    I have a 16,000 line credit this week.

LINT

    lib/lp/bugs/tests/test_bug_messages_webservice.py
    lib/lp/services/messages/interfaces/message.py
    lib/lp/services/messages/model/message.py

TEST

    ./bin/test -vvc -t MessageTraversal lp.bugs.tests.test_bug_messages_webservice

IMPLEMENTATION

I added getAPIParent to IMessage and exported it using accessor_for(parent)
to ensure the API never sees a parent message.
    lib/lp/bugs/tests/test_bug_messages_webservice.py
    lib/lp/services/messages/interfaces/message.py
    lib/lp/services/messages/model/message.py

To post a comment you must log in.
Revision history for this message
Brad Crittenden (bac) wrote :

Hi Curtis,

* typo: representtion

* typo: s/it is might/it might

Otherwise it looks good. Thanks.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/bugs/tests/test_bug_messages_webservice.py'
2--- lib/lp/bugs/tests/test_bug_messages_webservice.py 2012-09-18 18:36:09 +0000
3+++ lib/lp/bugs/tests/test_bug_messages_webservice.py 2012-11-30 20:14:21 +0000
4@@ -50,6 +50,25 @@
5 messages,
6 expected_messages)
7
8+ def test_message_with_parent(self):
9+ # The API exposes the parent attribute IMessage that is hidden by
10+ # IIndexedMessage. The representation cannot make a link to the
11+ # parent message because it might switch to another context
12+ # object that is not exposed or the user may not have access to.
13+ message_1 = self.factory.makeMessage()
14+ message_2 = self.factory.makeMessage()
15+ message_2.parent = message_1
16+ bug = self.factory.makeBug()
17+ bug.linkMessage(message_2)
18+ user = self.factory.makePerson()
19+ lp_bug = self.wsObject(bug, user)
20+ for lp_message in lp_bug.messages:
21+ # An IIndexedMessage's representation.
22+ self.assertIs(None, lp_message.parent)
23+ # An IMessage's representation.
24+ lp_message = self.wsObject(message_2, user)
25+ self.assertIs(None, lp_message.parent)
26+
27
28 class TestSetCommentVisibility(TestCaseWithFactory):
29 """Tests who can successfully set comment visibility."""
30
31=== modified file 'lib/lp/services/messages/interfaces/message.py'
32--- lib/lp/services/messages/interfaces/message.py 2012-04-27 19:03:32 +0000
33+++ lib/lp/services/messages/interfaces/message.py 2012-11-30 20:14:21 +0000
34@@ -23,8 +23,11 @@
35
36 from lazr.delegates import delegates
37 from lazr.restful.declarations import (
38+ accessor_for,
39 export_as_webservice_entry,
40+ export_read_operation,
41 exported,
42+ operation_for_version,
43 )
44 from lazr.restful.fields import (
45 CollectionField,
46@@ -108,6 +111,12 @@
47 def __iter__():
48 """Iterate over all the message chunks."""
49
50+ @accessor_for(parent)
51+ @export_read_operation()
52+ @operation_for_version('beta')
53+ def getAPIParent():
54+ """Return None because messages are not threaded over the API."""
55+
56
57 # Fix for self-referential schema.
58 IMessage['parent'].schema = IMessage
59
60=== modified file 'lib/lp/services/messages/model/message.py'
61--- lib/lp/services/messages/model/message.py 2012-04-27 19:03:32 +0000
62+++ lib/lp/services/messages/model/message.py 2012-11-30 20:14:21 +0000
63@@ -163,6 +163,10 @@
64 # interface because it is used as a UI field in MessageAddView
65 content = None
66
67+ def getAPIParent(self):
68+ """See `IMessage`."""
69+ return None
70+
71
72 def get_parent_msgids(parsed_message):
73 """Returns a list of message ids the mail was a reply to.