def get_user_threads(threads, lists_for_user, key): visible_threads = [] listnames_for_user = mailman.extract_listname_from_list(lists_for_user) for t in threads: if not t.mailinglist.is_private or \ t.mailinglist.name in listnames_for_user: visible_threads.append(key(t)) return visible_threads
def get(self, request, mailinglist, thread_token): thread = get_object_or_404(Thread, subject_token=thread_token, mailinglist__name=mailinglist) all_privates = [] all_privates.extend( [mlist.get('listname') for mlist in mailman.all_lists() if mlist.get('archive_private')] ) if all_privates.count(thread.mailinglist.name): if not request.user.is_authenticated(): raise PermissionDenied else: user = User.objects.get(username=request.user) emails = user.emails.values_list('address', flat=True) lists_for_user = mailman.get_user_mailinglists(user) listnames_for_user = mailman.extract_listname_from_list( lists_for_user) if thread.mailinglist.name not in listnames_for_user: raise PermissionDenied thread.hit(request) try: first_message = thread.message_set.first() except ObjectDoesNotExist: raise http.Http404 order_by = request.GET.get('order') if order_by == 'voted': msgs_query = Message.most_voted else: msgs_query = Message.objects msgs_query = msgs_query.filter(thread__subject_token=thread_token) msgs_query = msgs_query.filter(thread__mailinglist__name=mailinglist) emails = msgs_query.exclude(id=first_message.id) total_votes = first_message.votes_count() for email in emails: total_votes += email.votes_count() # Update relevance score thread.update_score() context = { 'first_msg': first_message, 'emails': [first_message] + list(emails), 'pagehits': thread.hits, 'total_votes': total_votes, 'thread': thread, } return render(request, 'message-thread.html', context)
def get(self, request, mailinglist, thread_token): thread = get_object_or_404(Thread, subject_token=thread_token, mailinglist__name=mailinglist) all_privates = [] all_privates.extend([ mlist.get('listname') for mlist in mailman.all_lists() if mlist.get('archive_private') ]) if all_privates.count(thread.mailinglist.name): if not request.user.is_authenticated(): raise PermissionDenied else: user = User.objects.get(username=request.user) emails = user.emails.values_list('address', flat=True) lists_for_user = mailman.get_user_mailinglists(user) listnames_for_user = mailman.extract_listname_from_list( lists_for_user) if thread.mailinglist.name not in listnames_for_user: raise PermissionDenied thread.hit(request) try: first_message = thread.message_set.first() except ObjectDoesNotExist: raise http.Http404 order_by = request.GET.get('order') if order_by == 'voted': msgs_query = Message.most_voted else: msgs_query = Message.objects msgs_query = msgs_query.filter(thread__subject_token=thread_token) msgs_query = msgs_query.filter(thread__mailinglist__name=mailinglist) emails = msgs_query.exclude(id=first_message.id) total_votes = first_message.votes_count() for email in emails: total_votes += email.votes_count() # Update relevance score thread.update_score() context = { 'first_msg': first_message, 'emails': [first_message] + list(emails), 'pagehits': thread.hits, 'total_votes': total_votes, 'thread': thread, } return render(request, 'message-thread.html', context)
def get_queryset(self): listnames_for_user = [] if self.request.user.is_authenticated(): user = User.objects.get(username=self.request.user) lists_for_user = mailman.get_user_mailinglists(user) listnames_for_user = mailman.extract_listname_from_list( lists_for_user) query = Q(is_private=False) | Q(name__in=listnames_for_user) return MailingList.objects.filter(query).order_by('name')
def get_visible_threads_queryset(logged_user): queryset = Thread.objects listnames_for_user = [] if logged_user: lists_for_user = mailman.get_user_mailinglists(logged_user) listnames_for_user = mailman.extract_listname_from_list(lists_for_user) user_lists = Q(mailinglist__name__in=listnames_for_user) public_lists = Q(mailinglist__is_private=False) queryset = Thread.objects.filter(user_lists | public_lists) return queryset
def check_list_membership(self, user, mailinglist_name): user = User.objects.get(username=user) lists_for_user = mailman.get_user_mailinglists(user) listnames_for_user = mailman.extract_listname_from_list(lists_for_user) if mailinglist_name not in listnames_for_user: error_message = _("You don't have permission to access this list") messages.add_message(self.request, messages.ERROR, error_message) return False return True
def check_list_membership(self, user, mailinglist_name): user = User.objects.get(username=user) lists_for_user = mailman.get_user_mailinglists(user) listnames_for_user = mailman.extract_listname_from_list( lists_for_user) if mailinglist_name not in listnames_for_user: error_message = _("You don't have permission to access this list") messages.add_message(self.request, messages.ERROR, error_message) return False return True