def get_queryset(self):
     mlist = MailingList.objects.get(name=self.kwargs["mlist_fqdn"])
     if not is_mlist_authorized(self.request, mlist):
         raise PermissionDenied
     return Thread.objects.filter(
         mailinglist__name=self.kwargs["mlist_fqdn"], ).order_by(
             "-date_active")
Example #2
0
def posts(request, user_id):
    mlist_fqdn = request.GET.get("list")
    if mlist_fqdn is None:
        mlist = None
        return HttpResponse("Not implemented yet", status=500)
    else:
        try:
            mlist = MailingList.objects.get(name=mlist_fqdn)
        except MailingList.DoesNotExist:
            raise Http404("No archived mailing-list by that name.")
        if not is_mlist_authorized(request, mlist):
            return render(request, "hyperkitty/errors/private.html", {
                            "mlist": mlist,
                          }, status=403)

    fullname = Email.objects.filter(
            sender__mailman_id=user_id, sender_name__isnull=False
        ).exclude(sender_name="").values_list(
        "sender_name", flat=True).first()
    # Get the messages and paginate them
    emails = Email.objects.filter(
        mailinglist=mlist, sender__mailman_id=user_id)
    emails = paginate(emails, request.GET.get("page"))

    for email in emails:
        email.myvote = email.votes.filter(user=request.user).first()

    context = {
        'user_id': user_id,
        'mlist': mlist,
        'emails': emails,
        'fullname': fullname,
    }
    return render(request, "hyperkitty/user_posts.html", context)
 def get_queryset(self):
     mlist = MailingList.objects.get(name=self.kwargs["mlist_fqdn"])
     if not is_mlist_authorized(self.request, mlist):
         raise PermissionDenied
     query = Email.objects.filter(
         mailinglist__name=self.kwargs["mlist_fqdn"])
     if "thread_id" in self.kwargs:
         query = query.filter(thread__thread_id=self.kwargs["thread_id"]
                              ).order_by("thread_order")
     else:
         query = query.order_by("-archived_date")
     return query
Example #4
0
def index(request):
    lists = [
        ml for ml in MailingList.objects.all()
        if not settings.FILTER_VHOST or show_mlist(ml, request)
    ]
    for mlist in lists:
        if not mlist.is_private:
            mlist.can_view = True
        else:
            if is_mlist_authorized(request, mlist):
                mlist.can_view = True
            else:
                mlist.can_view = False
        if mlist.can_view:
            mlist.recent_threads_count = mlist.recent_threads.count()
        else:
            mlist.recent_threads_count = None

    # sorting
    sort_mode = request.GET.get('sort')
    if not sort_mode:
        sort_mode = "popular"
    if sort_mode == "name":
        lists.sort(key=lambda l: l.name)
    elif sort_mode == "active":
        # Don't show private lists when sorted by activity, to avoid disclosing
        # info about the private list's activity
        lists = [l for l in lists if l.is_private == False]
        lists.sort(key=lambda l: l.recent_threads_count, reverse=True)
    elif sort_mode == "popular":
        # Don't show private lists when sorted by popularity, to avoid disclosing
        # info about the private list's popularity
        lists = [l for l in lists if l.is_private == False]
        lists.sort(key=lambda l: l.recent_participants_count, reverse=True)
    elif sort_mode == "creation":
        lists.sort(key=lambda l: l.created_at, reverse=True)
    else:
        return HttpResponse("Wrong search parameter",
                            content_type="text/plain",
                            status=500)

    context = {
        'view_name': 'all_lists',
        'all_lists': lists,
        'sort_mode': sort_mode,
    }
    return render(request, "hyperkitty/index.html", context)
Example #5
0
def index(request):
    lists = [
        ml for ml in MailingList.objects.all()
        if not settings.FILTER_VHOST or show_mlist(ml, request) ]
    for mlist in lists:
        if not mlist.is_private:
            mlist.can_view = True
        else:
            if is_mlist_authorized(request, mlist):
                mlist.can_view = True
            else:
                mlist.can_view = False
        if mlist.can_view:
            mlist.recent_threads_count = mlist.recent_threads.count()
        else:
            mlist.recent_threads_count = None

    # sorting
    sort_mode = request.GET.get('sort')
    if not sort_mode:
        sort_mode = "popular"
    if sort_mode == "name":
        lists.sort(key=lambda l: l.name)
    elif sort_mode == "active":
        # Don't show private lists when sorted by activity, to avoid disclosing
        # info about the private list's activity
        lists = [ l for l in lists if l.is_private == False ]
        lists.sort(key=lambda l: l.recent_threads_count, reverse=True)
    elif sort_mode == "popular":
        # Don't show private lists when sorted by popularity, to avoid disclosing
        # info about the private list's popularity
        lists = [ l for l in lists if l.is_private == False ]
        lists.sort(key=lambda l: l.recent_participants_count, reverse=True)
    elif sort_mode == "creation":
        lists.sort(key=lambda l: l.created_at, reverse=True)
    else:
        return HttpResponse("Wrong search parameter",
                            content_type="text/plain", status=500)

    context = {
        'view_name': 'all_lists',
        'all_lists': lists,
        'sort_mode': sort_mode,
        }
    return render(request, "hyperkitty/index.html", context)
Example #6
0
def index(request):
    mlists = [ml for ml in MailingList.objects.all() if not settings.FILTER_VHOST or show_mlist(ml, request)]

    # Sorting
    sort_mode = request.GET.get("sort")
    if not sort_mode:
        sort_mode = "popular"
    if sort_mode == "name":
        mlists.sort(key=lambda ml: ml.name)
    elif sort_mode == "active":
        # Don't show private lists when sorted by activity, to avoid disclosing
        # info about the private list's activity
        mlists = [ml for ml in mlists if ml.is_private == False]
        mlists.sort(key=lambda l: l.recent_threads_count, reverse=True)
    elif sort_mode == "popular":
        # Don't show private lists when sorted by popularity, to avoid disclosing
        # info about the private list's popularity
        mlists = [l for l in mlists if l.is_private == False]
        mlists.sort(key=lambda l: l.recent_participants_count, reverse=True)
    elif sort_mode == "creation":
        mlists.sort(key=lambda l: l.created_at, reverse=True)
    else:
        return HttpResponse("Wrong search parameter", content_type="text/plain", status=500)

    mlists = paginate(mlists, request.GET.get("page"), results_per_page=request.GET.get("count"))

    # Permissions
    for mlist in mlists:
        if not mlist.is_private:
            mlist.can_view = True
        else:
            if is_mlist_authorized(request, mlist):
                mlist.can_view = True
            else:
                mlist.can_view = False

    context = {"view_name": "all_lists", "all_lists": mlists, "sort_mode": sort_mode}
    return render(request, "hyperkitty/index.html", context)
Example #7
0
def posts(request, user_id):
    mlist_fqdn = request.GET.get("list")
    if mlist_fqdn is None:
        mlist = None
        return HttpResponse("Not implemented yet", status=500)
    else:
        try:
            mlist = MailingList.objects.get(name=mlist_fqdn)
        except MailingList.DoesNotExist:
            raise Http404("No archived mailing-list by that name.")
        if not is_mlist_authorized(request, mlist):
            return render(request,
                          "hyperkitty/errors/private.html", {
                              "mlist": mlist,
                          },
                          status=403)

    fullname = Sender.objects.filter(mailman_id=user_id).exclude(
        name="").values_list("name", flat=True).first()
    # Get the messages and paginate them
    messages = Email.objects.filter(mailinglist=mlist,
                                    sender__mailman_id=user_id)
    try:
        page_num = int(request.GET.get('page', "1"))
    except ValueError:
        page_num = 1
    messages = paginate(messages, page_num)

    for message in messages:
        message.myvote = message.votes.filter(user=request.user).first()

    context = {
        'user_id': user_id,
        'mlist': mlist,
        'messages': messages,
        'fullname': fullname,
    }
    return render(request, "hyperkitty/user_posts.html", context)
Example #8
0
def posts(request, user_id):
    mlist_fqdn = request.GET.get("list")
    if mlist_fqdn is None:
        mlist = None
        return HttpResponse("Not implemented yet", status=500)
    else:
        try:
            mlist = MailingList.objects.get(name=mlist_fqdn)
        except MailingList.DoesNotExist:
            raise Http404("No archived mailing-list by that name.")
        if not is_mlist_authorized(request, mlist):
            return render(request, "hyperkitty/errors/private.html", {
                            "mlist": mlist,
                          }, status=403)

    fullname = Sender.objects.filter(mailman_id=user_id).exclude(name=""
        ).values_list("name", flat=True).first()
    # Get the messages and paginate them
    messages = Email.objects.filter(
        mailinglist=mlist, sender__mailman_id=user_id)
    try:
        page_num = int(request.GET.get('page', "1"))
    except ValueError:
        page_num = 1
    messages = paginate(messages, page_num)

    for message in messages:
        message.myvote = message.votes.filter(
            user=request.user).first()

    context = {
        'user_id': user_id,
        'mlist' : mlist,
        'messages': messages,
        'fullname': fullname,
    }
    return render(request, "hyperkitty/user_posts.html", context)
Example #9
0
 def has_object_permission(self, request, view, obj):
     mlist = self._get_mlist(obj)
     if mlist is None:
         # This is not a object linked to a mailing-list.
         return True
     return is_mlist_authorized(request, mlist)
Example #10
0
def index(request):
    mlists = MailingList.objects.all()
    sort_mode = request.GET.get("sort", "popular")

    # Domain filtering
    if settings.FILTER_VHOST:
        domain = request.get_host().split(":")[0]
        if domain.startswith("www."):
            domain = domain[4:]
        domain = "@%s" % domain
        mlists = mlists.filter(name__iendswith=domain)

    # Name filtering
    name_filter = request.GET.get('name')
    if name_filter:
        sort_mode = "name"
        mlists = mlists.filter(
            Q(name__icontains=name_filter)
            | Q(display_name__icontains=name_filter))
        if mlists.count() == 1:
            return redirect('hk_list_overview', mlist_fqdn=mlists.first().name)

    # Sorting
    if sort_mode == "name":
        mlists = mlists.order_by("name")
    elif sort_mode == "active":
        # Don't show private lists when sorted by activity, to avoid disclosing
        # info about the private list's activity
        mlists = list(
            mlists.exclude(archive_policy=ArchivePolicy.private.value))
        mlists.sort(key=lambda l: l.recent_threads_count, reverse=True)
    elif sort_mode == "popular":
        # Don't show private lists when sorted by popularity, to avoid
        # disclosing info about the private list's popularity.
        mlists = list(
            mlists.exclude(archive_policy=ArchivePolicy.private.value))
        mlists.sort(key=lambda l: l.recent_participants_count, reverse=True)
    elif sort_mode == "creation":
        mlists = mlists.order_by("-created_at")
    else:
        return HttpResponse("Wrong search parameter",
                            content_type="text/plain",
                            status=500)

    mlists = paginate(mlists, request.GET.get('page'),
                      request.GET.get('count'))

    # Permissions
    for mlist in mlists:
        if not mlist.is_private:
            mlist.can_view = True
        else:
            if is_mlist_authorized(request, mlist):
                mlist.can_view = True
            else:
                mlist.can_view = False

    context = {
        'view_name': 'all_lists',
        'all_lists': mlists,
        'sort_mode': sort_mode,
    }
    return render(request, "hyperkitty/index.html", context)
Example #11
0
def search(request):
    """ Returns messages corresponding to a query """
    mlist_fqdn = request.GET.get("mlist")
    if mlist_fqdn is None:
        mlist = None
    else:
        try:
            mlist = MailingList.objects.get(name=mlist_fqdn)
        except MailingList.DoesNotExist:
            raise Http404("No archived mailing-list by that name.")
        if not is_mlist_authorized(request, mlist):
            return render(request, "hyperkitty/errors/private.html", {
                            "mlist": mlist,
                          }, status=403)


    query = ''
    results = EmptySearchQuerySet()
    sqs = RelatedSearchQuerySet()

    # Remove private non-subscribed lists
    if mlist is not None:
        sqs = sqs.filter(mailinglist__exact=mlist.name)
    else:
        excluded_mlists = MailingList.objects.filter(
            archive_policy=ArchivePolicy.private.value)
        if request.user.is_authenticated():
            subscriptions = request.user.hyperkitty_profile.get_subscriptions()
            excluded_mlists = excluded_mlists.exclude(
                list_id__in=subscriptions.keys())
        excluded_mlists = excluded_mlists.values_list("name", flat=True)
        sqs = sqs.exclude(mailinglist__in=excluded_mlists)

    # Sorting
    sort_mode = request.GET.get('sort')
    if sort_mode == "date-asc":
        sqs = sqs.order_by("date")
    elif sort_mode == "date-desc":
        sqs = sqs.order_by("-date")

    # Handle data
    if request.GET.get('q'):
        form = SearchForm(
            request.GET, searchqueryset=sqs, load_all=True)
        if form.is_valid():
            query = form.cleaned_data['q']
            results = form.search()
    else:
        form = SearchForm(searchqueryset=sqs, load_all=True)

    emails = paginate(results, page_num=request.GET.get('page'))
    for email in emails:
        if request.user.is_authenticated():
            email.object.myvote = email.object.votes.filter(user=request.user).first()
        else:
            email.object.myvote = None


    context = {
        'mlist' : mlist,
        'form': form,
        'emails': emails,
        'query': query,
        'sort_mode': sort_mode,
        'suggestion': None,
    }
    if results.query.backend.include_spelling:
        context['suggestion'] = form.get_suggestion()

    return render(request, "hyperkitty/search_results.html", context)
Example #12
0
def search(request):
    """ Returns messages corresponding to a query """
    mlist_fqdn = request.GET.get("mlist")
    if mlist_fqdn is None:
        mlist = None
    else:
        try:
            mlist = MailingList.objects.get(name=mlist_fqdn)
        except MailingList.DoesNotExist:
            raise Http404("No archived mailing-list by that name.")
        if not is_mlist_authorized(request, mlist):
            return render(request,
                          "hyperkitty/errors/private.html", {
                              "mlist": mlist,
                          },
                          status=403)
    query = ''
    results = EmptySearchQuerySet()
    sqs = RelatedSearchQuerySet()

    # Remove private non-subscribed lists
    if mlist is not None:
        sqs = sqs.filter(mailinglist__exact=mlist.name)
    else:
        excluded_mlists = MailingList.objects.filter(
            archive_policy=ArchivePolicy.private.value)
        if request.user.is_authenticated:
            subscriptions = get_subscriptions(request.user)
            excluded_mlists = excluded_mlists.exclude(
                list_id__in=subscriptions.keys())
        excluded_mlists = excluded_mlists.values_list("name", flat=True)
        sqs = sqs.exclude(mailinglist__in=excluded_mlists)

    # Sorting
    sort_mode = request.GET.get('sort')
    if sort_mode == "date-asc":
        sqs = sqs.order_by("date")
    elif sort_mode == "date-desc":
        sqs = sqs.order_by("-date")

    # Handle data
    if request.GET.get('q'):
        form = SearchForm(request.GET, searchqueryset=sqs, load_all=True)
        if form.is_valid():
            query = form.cleaned_data['q']
            results = form.search()
    else:
        form = SearchForm(searchqueryset=sqs, load_all=True)

    try:
        emails = paginate(
            results,
            request.GET.get('page'),
            request.GET.get('count'),
        )
    except Exception as e:
        backend = settings.HAYSTACK_CONNECTIONS[DEFAULT_ALIAS]["ENGINE"]
        if backend == "haystack.backends.whoosh_backend.WhooshEngine":
            from whoosh.qparser.common import QueryParserError
            search_exception = QueryParserError
        if backend == "xapian_backend.XapianEngine":
            from xapian import QueryParserError
            search_exception = QueryParserError
        if not isinstance(e, search_exception):
            raise
        emails = paginate([])
        form.add_error(
            "q",
            ValidationError(
                _('Parsing error: %(error)s'),
                params={"error": e},
                code="parse",
            ))
    for email in emails:
        if request.user.is_authenticated:
            email.object.myvote = email.object.votes.filter(
                user=request.user).first()
        else:
            email.object.myvote = None

    context = {
        'mlist': mlist,
        'form': form,
        'emails': emails,
        'query': query,
        'sort_mode': sort_mode,
        'suggestion': None,
    }
    if results.query.backend.include_spelling:
        context['suggestion'] = form.get_suggestion()

    return render(request, "hyperkitty/search_results.html", context)
Example #13
0
def search(request):
    """ Returns messages corresponding to a query """
    mlist_fqdn = request.GET.get("mlist")
    if mlist_fqdn is None:
        mlist = None
    else:
        try:
            mlist = MailingList.objects.get(name=mlist_fqdn)
        except MailingList.DoesNotExist:
            raise Http404("No archived mailing-list by that name.")
        if not is_mlist_authorized(request, mlist):
            return render(request, "hyperkitty/errors/private.html", {
                            "mlist": mlist,
                          }, status=403)


    query = ''
    results = EmptySearchQuerySet()
    sqs = RelatedSearchQuerySet()

    # Remove private non-subscribed lists
    if mlist is not None:
        sqs = sqs.filter(mailinglist__exact=mlist.name)
    else:
        excluded_mlists = MailingList.objects.filter(
            archive_policy=ArchivePolicy.private.value)
        if request.user.is_authenticated():
            subscriptions = request.user.hyperkitty_profile.get_subscriptions()
            excluded_mlists = excluded_mlists.exclude(
                name__in=subscriptions.keys())
        excluded_mlists = excluded_mlists.values_list("name", flat=True)
        sqs = sqs.exclude(mailinglist__in=excluded_mlists)

    # Sorting
    sort_mode = request.GET.get('sort')
    if sort_mode == "date-asc":
        sqs = sqs.order_by("date")
    elif sort_mode == "date-desc":
        sqs = sqs.order_by("-date")

    # Handle data
    if request.GET.get('q'):
        form = SearchForm(
            request.GET, searchqueryset=sqs, load_all=True)
        if form.is_valid():
            query = form.cleaned_data['q']
            results = form.search()
    else:
        form = SearchForm(searchqueryset=sqs, load_all=True)

    messages = paginate(results, page_num=request.GET.get('page'))
    for message in messages:
        if request.user.is_authenticated():
            message.object.myvote = message.object.votes.filter(user=request.user).first()
        else:
            message.object.myvote = None


    context = {
        'mlist' : mlist,
        'form': form,
        'messages': messages,
        'query': query,
        'sort_mode': sort_mode,
        'suggestion': None,
    }
    if results.query.backend.include_spelling:
        context['suggestion'] = form.get_suggestion()

    return render(request, "hyperkitty/search_results.html", context)