Merge pull request #21 from khink/master

Fix conversation view: shouldn't break on invalid URLs
This commit is contained in:
Timo Stollenwerk 2012-11-16 01:34:10 -08:00
commit df7e6978ba
4 changed files with 18 additions and 2 deletions

View File

@ -4,6 +4,10 @@ Changelog
2.2.1 (unreleased) 2.2.1 (unreleased)
------------------ ------------------
- Make conversation view not break when comment-id cannot be converted to long.
Fixes #13327
[khink]
- fix insufficient privileges when trying to view - fix insufficient privileges when trying to view
the RSS feed of a comment collection the RSS feed of a comment collection
[maartenkling] [maartenkling]

View File

@ -210,7 +210,11 @@ class Conversation(Traversable, Persistent, Explicit):
def __getitem__(self, key): def __getitem__(self, key):
"""Get an item by its long key """Get an item by its long key
""" """
return self._comments[long(key)].__of__(self) try:
comment_id = long(key)
except ValueError:
return
return self._comments[comment_id].__of__(self)
def __delitem__(self, key, suppress_container_modified=False): def __delitem__(self, key, suppress_container_modified=False):
"""Delete an item by its long key """Delete an item by its long key

View File

@ -699,6 +699,14 @@ class ConversationTest(unittest.TestCase):
self.assertEqual('http://nohost/plone/doc1/++conversation++default', self.assertEqual('http://nohost/plone/doc1/++conversation++default',
conversation.absolute_url()) conversation.absolute_url())
def test_unconvertible_id(self):
# make sure the conversation view doesn't break when given comment id
# can't be converted to long
conversation = self.portal.doc1.restrictedTraverse(
'++conversation++default/ThisCantBeRight')
self.assertEqual(conversation, None)
def test_parent(self): def test_parent(self):
# Check that conversation has a content object as parent # Check that conversation has a content object as parent

View File

@ -20,7 +20,7 @@ optionflags = (
doctest.REPORT_ONLY_FIRST_FAILURE) doctest.REPORT_ONLY_FIRST_FAILURE)
normal_testfiles = [ normal_testfiles = [
'functional_test_comments.txt', 'functional_test_comments.txt',
'functional_test_comment_review_workflow.txt' 'functional_test_comment_review_workflow.txt',
] ]