allura
修訂 | a3d6d91c61bfcf84c1a114867cbaf8d1a485b2ef (tree) |
---|---|
時間 | 2011-07-15 05:53:48 |
作者 | Dave Brondsema <dbrondsema@geek...> |
Commiter | Dave Brondsema |
[#2455] fix anonymous lookup when post author is not found
Signed-off-by: Dave Brondsema <dbrondsema@geek.net>
@@ -411,7 +411,7 @@ class Message(Artifact): | ||
411 | 411 | |
412 | 412 | def author(self): |
413 | 413 | from .auth import User |
414 | - return User.query.get(_id=self.author_id) or User.anonymous | |
414 | + return User.query.get(_id=self.author_id) or User.anonymous() | |
415 | 415 | |
416 | 416 | def reply(self): |
417 | 417 | new_id = h.gen_message_id() |
@@ -149,3 +149,11 @@ def test_messages(): | ||
149 | 149 | assert 'author_display_name_t' in idx |
150 | 150 | assert 'timestamp_dt' in idx |
151 | 151 | assert m.shorthand_id() == m.slug |
152 | + | |
153 | +@with_setup(setUp, tearDown) | |
154 | +def test_messages_unknown_lookup(): | |
155 | + from bson import ObjectId | |
156 | + m = Checkmessage() | |
157 | + m.author_id = ObjectId() # something new | |
158 | + assert type(m.author()) == M.User, type(m.author()) | |
159 | + assert m.author() == M.User.anonymous() |
@@ -48,7 +48,7 @@ class TestAppDefaults(WithDatabase): | ||
48 | 48 | assert self.app.sidebar_menu() == [] |
49 | 49 | |
50 | 50 | def test_that_it_denies_access_for_everything(self): |
51 | - assert not self.app.has_access(model.User.anonymous, 'any.topic') | |
51 | + assert not self.app.has_access(model.User.anonymous(), 'any.topic') | |
52 | 52 | |
53 | 53 | |
54 | 54 | def install_app(): |
@@ -64,7 +64,7 @@ class BlogPost(M.VersionedArtifact): | ||
64 | 64 | |
65 | 65 | def author(self): |
66 | 66 | '''The author of the first snapshot of this BlogPost''' |
67 | - return M.User.query.get(_id=self.get_version(1).author.id) or M.User.anonymous | |
67 | + return M.User.query.get(_id=self.get_version(1).author.id) or M.User.anonymous() | |
68 | 68 | |
69 | 69 | def _get_date(self): |
70 | 70 | return self.timestamp.date() |