|
@@ -1,12 +1,88 @@
|
|
|
|
+from django.http import Http404
|
|
|
|
+from django.shortcuts import get_object_or_404
|
|
from django.utils.translation import ugettext as _
|
|
from django.utils.translation import ugettext as _
|
|
|
|
|
|
from misago.acl import add_acl
|
|
from misago.acl import add_acl
|
|
from misago.forums.models import Forum
|
|
from misago.forums.models import Forum
|
|
|
|
|
|
|
|
+from misago.threads.models import Thread, ThreadParticipant
|
|
from misago.threads.permissions import (allow_use_private_threads,
|
|
from misago.threads.permissions import (allow_use_private_threads,
|
|
|
|
+ allow_see_private_thread,
|
|
|
|
+ allow_see_private_post,
|
|
exclude_invisible_private_threads)
|
|
exclude_invisible_private_threads)
|
|
from misago.threads.views import generic
|
|
from misago.threads.views import generic
|
|
-from misago.threads.views.posting import PostingView as BasePostingView
|
|
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+def private_threads_view(klass):
|
|
|
|
+ """
|
|
|
|
+ decorator for making views check allow_use_private_threads
|
|
|
|
+ """
|
|
|
|
+ def dispatch(self, request, *args, **kwargs):
|
|
|
|
+ allow_use_private_threads(request.user)
|
|
|
|
+
|
|
|
|
+ return super(self.__class__, self).dispatch(
|
|
|
|
+ request, *args, **kwargs)
|
|
|
|
+ klass.dispatch = dispatch
|
|
|
|
+ return klass
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+class PrivateThreadsMixin(object):
|
|
|
|
+ """
|
|
|
|
+ Mixin is used to make views use different permission tests
|
|
|
|
+ """
|
|
|
|
+ def get_forum(self, request, lock=False, **kwargs):
|
|
|
|
+ forum = Forum.objects.private_threads()
|
|
|
|
+ add_acl(request.user, forum)
|
|
|
|
+ return forum
|
|
|
|
+
|
|
|
|
+ def check_forum_permissions(self, request, forum):
|
|
|
|
+ add_acl(request.user, forum)
|
|
|
|
+ allow_use_private_threads(request.user)
|
|
|
|
+
|
|
|
|
+ def fetch_thread(self, request, lock=False, select_related=None,
|
|
|
|
+ queryset=None, **kwargs):
|
|
|
|
+ queryset = queryset or Thread.objects
|
|
|
|
+ if lock:
|
|
|
|
+ queryset = queryset.select_for_update()
|
|
|
|
+
|
|
|
|
+ select_related = select_related or []
|
|
|
|
+ if not 'forum' in select_related:
|
|
|
|
+ select_related.append('forum')
|
|
|
|
+ queryset = queryset.select_related(*select_related)
|
|
|
|
+
|
|
|
|
+ where = {'id': kwargs.get('thread_id')}
|
|
|
|
+ thread = get_object_or_404(queryset, **where)
|
|
|
|
+ if thread.forum.special_role != 'private_threads':
|
|
|
|
+ raise Http404()
|
|
|
|
+ return thread
|
|
|
|
+
|
|
|
|
+ def fetch_thread_participants(self, thread):
|
|
|
|
+ thread.participants_list = []
|
|
|
|
+ participants_qs = ThreadParticipant.objects.filter(thread=thread)
|
|
|
|
+ participants_qs = participants_qs.select_related('user')
|
|
|
|
+ for participant in participants_qs:
|
|
|
|
+ participant.thread = thread
|
|
|
|
+ thread.participants_list.append(participant)
|
|
|
|
+
|
|
|
|
+ def check_thread_permissions(self, request, thread):
|
|
|
|
+ add_acl(request.user, thread.forum)
|
|
|
|
+ add_acl(request.user, thread)
|
|
|
|
+
|
|
|
|
+ self.fetch_thread_participants(thread)
|
|
|
|
+
|
|
|
|
+ allow_see_private_thread(request.user, thread)
|
|
|
|
+ allow_use_private_threads(request.user)
|
|
|
|
+
|
|
|
|
+ def check_post_permissions(self, request, post):
|
|
|
|
+ add_acl(request.user, post.forum)
|
|
|
|
+ add_acl(request.user, post.thread)
|
|
|
|
+ add_acl(request.user, post)
|
|
|
|
+
|
|
|
|
+ self.fetch_thread_participants(post.thread)
|
|
|
|
+
|
|
|
|
+ allow_see_private_post(request.user, post)
|
|
|
|
+ allow_see_private_thread(request.user, post.thread)
|
|
|
|
+ allow_use_private_threads(request.user)
|
|
|
|
|
|
|
|
|
|
class PrivateThreads(generic.Threads):
|
|
class PrivateThreads(generic.Threads):
|
|
@@ -29,53 +105,65 @@ class PrivateThreadsFiltering(generic.ThreadsFiltering):
|
|
return filters
|
|
return filters
|
|
|
|
|
|
|
|
|
|
-def private_threads_view(klass):
|
|
|
|
- def get_forum(self, request, lock=False, **kwargs):
|
|
|
|
- forum = Forum.objects.private_threads()
|
|
|
|
- add_acl(request.user, forum)
|
|
|
|
- return forum
|
|
|
|
|
|
+@private_threads_view
|
|
|
|
+class PrivateThreadsView(generic.ThreadsView):
|
|
|
|
+ link_name = 'misago:private_threads'
|
|
|
|
+ template = 'misago/privatethreads/list.html'
|
|
|
|
|
|
- def dispatch(self, request, *args, **kwargs):
|
|
|
|
- allow_use_private_threads(request.user)
|
|
|
|
|
|
+ Threads = PrivateThreads
|
|
|
|
+ Filtering = PrivateThreadsFiltering
|
|
|
|
|
|
- return super(self.__class__, self).dispatch(
|
|
|
|
- request, *args, **kwargs)
|
|
|
|
|
|
|
|
- klass.get_forum = get_forum
|
|
|
|
- klass.dispatch = dispatch
|
|
|
|
|
|
+@private_threads_view
|
|
|
|
+class ThreadView(PrivateThreadsMixin, generic.ThreadView):
|
|
|
|
+ pass
|
|
|
|
|
|
- return klass
|
|
|
|
|
|
+
|
|
|
|
+@private_threads_view
|
|
|
|
+class GotoLastView(PrivateThreadsMixin, generic.GotoLastView):
|
|
|
|
+ pass
|
|
|
|
|
|
|
|
|
|
@private_threads_view
|
|
@private_threads_view
|
|
-class ThreadsView(generic.ThreadsView):
|
|
|
|
- link_name = 'misago:private_threads'
|
|
|
|
- template = 'misago/privatethreads/list.html'
|
|
|
|
|
|
+class GotoNewView(PrivateThreadsMixin, generic.GotoNewView):
|
|
|
|
+ pass
|
|
|
|
|
|
- Threads = PrivateThreads
|
|
|
|
- Filtering = PrivateThreadsFiltering
|
|
|
|
|
|
+
|
|
|
|
+@private_threads_view
|
|
|
|
+class GotoPostView(PrivateThreadsMixin, generic.GotoPostView):
|
|
|
|
+ pass
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+@private_threads_view
|
|
|
|
+class ReportedPostsListView(PrivateThreadsMixin, generic.ReportedPostsListView):
|
|
|
|
+ pass
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+@private_threads_view
|
|
|
|
+class QuotePostView(PrivateThreadsMixin, generic.QuotePostView):
|
|
|
|
+ pass
|
|
|
|
|
|
|
|
|
|
@private_threads_view
|
|
@private_threads_view
|
|
-class ThreadView(generic.ThreadView):
|
|
|
|
|
|
+class UnhidePostView(PrivateThreadsMixin, generic.UnhidePostView):
|
|
pass
|
|
pass
|
|
|
|
|
|
|
|
|
|
@private_threads_view
|
|
@private_threads_view
|
|
-class GotoLastView(generic.GotoLastView):
|
|
|
|
|
|
+class HidePostView(PrivateThreadsMixin, generic.HidePostView):
|
|
pass
|
|
pass
|
|
|
|
|
|
|
|
|
|
@private_threads_view
|
|
@private_threads_view
|
|
-class GotoNewView(generic.GotoNewView):
|
|
|
|
|
|
+class DeletePostView(PrivateThreadsMixin, generic.DeletePostView):
|
|
pass
|
|
pass
|
|
|
|
|
|
|
|
|
|
@private_threads_view
|
|
@private_threads_view
|
|
-class GotoPostView(generic.GotoPostView):
|
|
|
|
|
|
+class EventsView(PrivateThreadsMixin, generic.EventsView):
|
|
pass
|
|
pass
|
|
|
|
|
|
|
|
|
|
@private_threads_view
|
|
@private_threads_view
|
|
-class PostingView(BasePostingView):
|
|
|
|
|
|
+class PostingView(PrivateThreadsMixin, generic.PostingView):
|
|
pass
|
|
pass
|