def create(self, request): allow_use_private_threads(request.user) if not request.user.acl_cache['can_start_private_threads']: raise PermissionDenied(_("You can't start private threads.")) request.user.lock() # Initialize empty instances for new thread thread = Thread() post = Post(thread=thread) # Put them through posting pipeline posting = PostingEndpoint( request, PostingEndpoint.START, tree_name=PRIVATE_THREADS_ROOT_NAME, thread=thread, post=post, ) if posting.is_valid(): posting.save() return Response({ 'id': thread.pk, 'title': thread.title, 'url': thread.get_absolute_url(), }) else: return Response(posting.errors, status=400)
def check_thread_permissions(self, request, thread): add_acl(request.user, thread.forum) add_acl(request.user, thread) participants.make_thread_participants_aware(request.user, thread) allow_see_private_thread(request.user, thread) allow_use_private_threads(request.user)
def check_thread_permissions(self, request, thread): add_acl(request.user, thread.forum) add_acl(request.user, thread) self.fetch_thread_participants(request.user, 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(request.user, post.thread) allow_see_private_post(request.user, post) allow_see_private_thread(request.user, post.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) participants.make_thread_participants_aware(request.user, thread) allow_see_private_post(request.user, post) allow_see_private_thread(request.user, post.thread) allow_use_private_threads(request.user)
def get_thread(self, request, pk, slug=None): allow_use_private_threads(request.user) thread = get_object_or_404( Thread.objects.select_related(*BASE_RELATIONS), pk=pk, category__tree_id=trees_map.get_tree_id_for_root(PRIVATE_THREADS_ROOT_NAME), ) make_participants_aware(request.user, thread) allow_see_private_thread(request.user, thread) if slug: validate_slug(thread, slug) return thread
def get_category(self, request, categories, **kwargs): allow_use_private_threads(request.user) return categories[0]
def read(self, request): allow_use_private_threads(request.user) read_private_threads(request.user) return Response({})
def check_forum_permissions(self, request, forum): add_acl(request.user, forum) allow_use_private_threads(request.user)
def dispatch(self, request, *args, **kwargs): allow_use_private_threads(request.user) return f(self, request, *args, **kwargs)