google-code-export / django-forum

Automatically exported from code.google.com/p/django-forum
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

Staff-only forums #47

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Hello, I did a extension on django-forum, for use as a private forum. Forums 
can simply be 
asigned to be private by checking a Checkbox.

For me it works. Maybe also for you.

Sorry for my bad english

Index: lib/forum/feeds.py
===========================================================
========
--- .   (revision 28)
+++ .   (working copy)
@@ -47,7 +47,7 @@
         if obj:
             return Post.objects.filter(thread__forum__pk=obj.id).order_by('-time')
         else:
-            return Post.objects.order_by('-time')
+            return 
Post.objects.filter(thread__forum__is_private=None).order_by('-time')

     def items(self, obj):
         return self.get_query_set(obj)[:15]
Index: lib/forum/models.py
===========================================================
========
--- .   (revision 28)
+++ .   (working copy)
@@ -26,7 +26,8 @@
     description = models.TextField(_("Description"))
     threads = models.IntegerField(_("Threads"), default=0)
     posts = models.IntegerField(_("Posts"), default=0)
-
+    is_private = models.BooleanField('Privat', blank=True, null=True)
+    
     def _get_forum_latest_post(self):
         """This gets the latest post for the forum"""
         if not hasattr(self, '__forum_latest_post'):
Index: lib/forum/views.py
===========================================================
========
--- .   (revision 28)
+++ .   (working copy)
@@ -28,6 +28,9 @@
     f = get_object_or_404(Forum, slug=slug)

     form = CreateThreadForm()
+    
+    if f.is_private and request.user.is_staff != True:
+        return HttpResponseRedirect('/forum')

     return object_list( request,
                         queryset=f.thread_set.all(),
@@ -45,6 +48,10 @@
     posts for that thread, in chronological order.
     """
     t = get_object_or_404(Thread, pk=thread)
+    
+    if t.forum.is_private and request.user.is_staff != True:
+        return HttpResponseRedirect('/forum')
+    
     p = t.post_set.all().order_by('time')
     s = t.subscription_set.filter(author=request.user)

Original issue reported on code.google.com by he...@sandgrave-media.de on 4 Dec 2008 at 10:35

GoogleCodeExporter commented 9 years ago
This is a good idea, if we are going down a permissions-based path should we 
try to
use the existing Django permissions framework?

EG Perhaps only certain *groups* of people should be able to access a forum?

If we are going to use the code above, we also need to allow superusers to view 
staff
forums.

I'll ponder the groups/permissions changes that would be needed and make a 
decision
over the next few days. Thanks for the suggestion & code contribution!

Original comment by rwpoul...@gmail.com on 4 Dec 2008 at 9:19

GoogleCodeExporter commented 9 years ago
I like the idea of this but the patch will need significant work before I can 
accept
it. Can you please update this code to include the following?

* Allow superusers to view staff forums
* Ensure you're using i18n around text (eg field names)
* On all redirects, use reverse lookups as not everybody uses /forum.
* When listing forums, only list forums that user can access. This means we 
won't
even list private forums to non-staff users.
* Update the new templatetags
(http://code.google.com/p/django-forum/wiki/RecentPostTemplateTags) to exclude
private forums.
* In the forum list we should somehow signify a forum is private if the user has
access to it, eg the word 'Private' next to the thread count.

If you can update the patch I'll accept it right away. Unfortunately in it's 
current
state it isn't complete enough IMO.

Original comment by rwpoul...@gmail.com on 30 Dec 2008 at 1:56

GoogleCodeExporter commented 9 years ago
Issue 53 has been merged into this issue.

Original comment by rwpoul...@gmail.com on 30 Jan 2009 at 11:07

GoogleCodeExporter commented 9 years ago
Here is a first version of the patch.

Original comment by xphuture on 1 Feb 2009 at 12:40

Attachments:

GoogleCodeExporter commented 9 years ago
Committed in SVN r38. Thanks for your patch!

Next step is a small patch so that superusers can see all forums - but that 
isn't
important enough to prevent me putting this in.

I will leave this open as a reminder to me if it hasn't been done soon.

Original comment by rwpoul...@gmail.com on 7 Feb 2009 at 12:46