def patch_best_answer(request, thread, value): try: post_id = int(value) except (TypeError, ValueError): raise PermissionDenied(_("A valid integer is required.")) allow_mark_best_answer(request.user, thread) post = get_object_or_404(thread.post_set, id=post_id) post.category = thread.category post.thread = thread allow_see_post(request.user, post) allow_mark_as_best_answer(request.user, post) if post.is_best_answer: raise PermissionDenied( _("This post is already marked as thread's best answer.")) if thread.has_best_answer: allow_change_best_answer(request.user, thread) thread.set_best_answer(request.user, post) thread.save() return { 'best_answer': thread.best_answer_id, 'best_answer_is_protected': thread.best_answer_is_protected, 'best_answer_marked_on': thread.best_answer_marked_on, 'best_answer_marked_by': thread.best_answer_marked_by_id, 'best_answer_marked_by_name': thread.best_answer_marked_by_name, 'best_answer_marked_by_slug': thread.best_answer_marked_by_slug, }
def check_post_permissions(self, request, post): add_acl(request.user, post.forum) add_acl(request.user, post.thread) add_acl(request.user, post) allow_see_post(request.user, post) allow_see_thread(request.user, post.thread) allow_see_forum(request.user, post.forum)
def check_post_permissions(self, request, post): if post.forum.special_role: raise Http404() add_acl(request.user, post.forum) add_acl(request.user, post.thread) add_acl(request.user, post) allow_see_post(request.user, post) allow_see_thread(request.user, post.thread) allow_see_forum(request.user, post.forum)
def check_post_permissions(self, request, post): add_acl(request.user, post) allow_see_post(request.user, post)