Anonymous avatar Anonymous committed 064a296

[project @ 339]
Fixed bug #11, by removing inks to posts in hidden topics, and making that /posts/[id]/ page robust against hidden topics

Comments (0)

Files changed (3)

cciw/cciwmain/models/forums.py

         page = int(previous_posts/settings.FORUM_PAGINATE_POSTS_BY) + 1
         return "%s?page=%s#id%s" % (thread.get_absolute_url(), page, self.id)
 
+    def is_parent_visible(self):
+        if self.topic_id is not None:
+            try:
+                topic = self.topic
+                return True
+            except Topic.DoesNotExist:
+                return False
+        elif self.photo_id is not None:
+            try:
+                photo = self.photo
+                return True
+            except Photo.DoesNotExist:
+                return False
+        else:
+            # no parent?
+            return False
+
     @staticmethod
     def create_post(member, message, topic=None, photo=None):
         """Creates a post with the correct defaults for a member."""

cciw/cciwmain/views/forums.py

         post = Post.objects.get(pk=id)
     except Post.DoesNotExist:
         raise Http404()
-    return HttpResponseRedirect(post.get_forum_url())
+    try:
+        url = post.get_forum_url()
+    except Topic.DoesNotExist:
+        return HttpResponseForbidden("<h1>Access denied</h1><p>Topic is hidden.</p>")
+    return HttpResponseRedirect(url)
 
 def all_topics(request):
     context = standard_extra_context(title="Recent new topics")

templates/cciw/forums/posts.html

 		<div class="postHeader">
 		{% ifchanged %}
 			<h2>
-			{% if post.topic_id %}In topic <a href="{{ post.topic.get_absolute_url }}">{{ post.topic.subject|escape }}</a>:{% endif %}
+			{% if post.topic_id %}{% if post.is_parent_visible %}In topic <a href="{{ post.topic.get_absolute_url }}">{{ post.topic.subject|escape }}</a>:{% else %}In a hidden topic:{% endif %}{% endif %}
 			{% if post.photo_id %}On photo <a href="{{ post.photo.get_absolute_url }}">{{ post.photo.id }}</a>:{% endif %}
 			</h2>
 		{% endifchanged %}
-		From {% memberlink %}{{ post.posted_by_id }}{% endmemberlink %}, at {{ post.posted_at|date:"d M y, h:i" }} &mdash; <span class="readmore"><a href="{{ post.get_absolute_url }}">view in context</a></span>:
+		From {% memberlink %}{{ post.posted_by_id }}{% endmemberlink %}, at {{ post.posted_at|date:"d M y, h:i" }}{% if post.is_parent_visible %} &mdash; <span class="readmore"><a href="{{ post.get_absolute_url }}">view in context</a></span>{% endif %}:
 		</div>
 		<div class="postMessage">
 		{% if post.subject %}<div class="postSubject">{{ post.subject|bb2html }}</div>{% endif %}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.