diff --git a/packages/views/flag.py b/packages/views/flag.py index a5cdf67eb..f66ed32c7 100644 --- a/packages/views/flag.py +++ b/packages/views/flag.py @@ -1,157 +1,9 @@ -import re -from django import forms -from django.conf import settings from django.contrib.auth.decorators import permission_required -from django.core.mail import EmailMessage -from django.db import transaction -from django.shortcuts import get_object_or_404, redirect, render -from django.template import loader -from django.utils.timezone import now -from django.views.decorators.cache import cache_page, never_cache +from django.shortcuts import get_object_or_404, redirect from main.models import Package -from ..models import FlagDenylist, FlagRequest - - -class FlagForm(forms.Form): - email = forms.EmailField(label='E-mail Address') - message = forms.CharField(label='Message To Developer', - widget=forms.Textarea) - # The field below is used to filter out bots that blindly fill out all - # input elements - website = forms.CharField(label='', - widget=forms.TextInput(), - required=False) - - def __init__(self, *args, **kwargs): - # we remove the 'email' field if this form is being shown to a - # logged-in user, e.g., a developer. - auth = kwargs.pop('authenticated', False) - super().__init__(*args, **kwargs) - if auth: - del self.fields['email'] - - def clean_message(self): - data = self.cleaned_data['message'] - # make sure the message isn't garbage (only punctuation or whitespace) - # or spam (using a simple denylist) - # and ensure a certain minimum length - if re.match(r'^[^0-9A-Za-z]+$', data) or any(fd.keyword in data for fd in FlagDenylist.objects.all()) \ - or len(data) < 3: - raise forms.ValidationError("Enter a valid and useful out-of-date message.") - return data - - -@cache_page(3600) -def flaghelp(request): - return render(request, 'packages/flaghelp.html') - - -@never_cache -def flag(request, name, repo, arch): - pkg = get_object_or_404(Package.objects.normal(), - pkgname=name, repo__name__iexact=repo, arch__name=arch) - if pkg.flag_date is not None: - # already flagged. do nothing. - return render(request, 'packages/flagged.html', {'pkg': pkg}) - # find all packages from (hopefully) the same PKGBUILD - pkgs = Package.objects.normal().filter( - pkgbase=pkg.pkgbase, flag_date__isnull=True, - repo__testing=pkg.repo.testing, - repo__staging=pkg.repo.staging).order_by( - 'pkgname', 'repo__name', 'arch__name') - - authenticated = request.user.is_authenticated - - if request.POST: - form = FlagForm(request.POST, authenticated=authenticated) - if form.is_valid() and form.cleaned_data['website'] == '': - # save the package list for later use - flagged_pkgs = list(pkgs) - - # find a common version if there is one available to store - versions = {(pkg.pkgver, pkg.pkgrel, pkg.epoch) for pkg in flagged_pkgs} - if len(versions) == 1: - version = versions.pop() - else: - version = ('', '', 0) - - message = form.cleaned_data['message'] - ip_addr = request.META.get('REMOTE_ADDR') - if authenticated: - email = request.user.email - else: - email = form.cleaned_data['email'] - - @transaction.atomic - def perform_updates(): - current_time = now() - pkgs.update(flag_date=current_time) - # store our flag request - flag_request = FlagRequest(created=current_time, - user_email=email, message=message, - ip_address=ip_addr, pkgbase=pkg.pkgbase, - repo=pkg.repo, pkgver=version[0], pkgrel=version[1], - epoch=version[2], num_packages=len(flagged_pkgs)) - if authenticated: - flag_request.user = request.user - flag_request.save() - - perform_updates() - - maints = pkg.maintainers - if not maints: - toemail = settings.NOTIFICATIONS - subject = f'Orphan {pkg.repo.name} package [{pkg.pkgname}] marked out-of-date' - else: - toemail = [] - subject = f'{pkg.repo.name} package [{pkg.pkgname}] marked out-of-date' - for maint in maints: - if maint.userprofile.notify is True: - toemail.append(maint.email) - - if toemail: - # send notification email to the maintainers - tmpl = loader.get_template('packages/outofdate.txt') - ctx = { - 'email': email, - 'message': message, - 'pkg': pkg, - 'packages': flagged_pkgs, - } - msg = EmailMessage(subject, - tmpl.render(ctx), - 'Arch Website Notification ', - toemail) - msg.send(fail_silently=True) - - return redirect('package-flag-confirmed', name=name, repo=repo, arch=arch) - else: - form = FlagForm(authenticated=authenticated) - - context = { - 'package': pkg, - 'packages': pkgs, - 'form': form - } - return render(request, 'packages/flag.html', context) - - -def flag_confirmed(request, name, repo, arch): - pkg = get_object_or_404(Package, - pkgname=name, repo__name__iexact=repo, arch__name=arch) - pkgs = Package.objects.normal().filter( - pkgbase=pkg.pkgbase, flag_date=pkg.flag_date, - repo__testing=pkg.repo.testing, - repo__staging=pkg.repo.staging).order_by( - 'pkgname', 'repo__name', 'arch__name') - - context = {'package': pkg, 'packages': pkgs} - - return render(request, 'packages/flag_confirmed.html', context) - @permission_required('main.change_package') def unflag(request, name, repo, arch): diff --git a/templates/packages/flag.html b/templates/packages/flag.html deleted file mode 100644 index db1c82a07..000000000 --- a/templates/packages/flag.html +++ /dev/null @@ -1,54 +0,0 @@ -{% extends "base.html" %} -{% load package_extras %} -{% load humanize %} -{% load details_link %} - -{% block title %}Arch Linux - Flag Package - {{ package.pkgname }} {{ package.full_version }} ({{ package.arch.name }}){% endblock %} -{% block head %}{% endblock %} -{% block navbarclass %}anb-packages{% endblock %} - -{% block content %} -
-

Flag Package: {{ package.pkgname }} {{ package.full_version }} ({{ package.arch.name }})

- -

If you notice a package is out-of-date (i.e., there is a newer - stable release available), then please notify us using - the form below. Do not report bugs via this form!

- -

Note that the following {{ packages|length }} package{{ packages|pluralize }} will be marked out of date:

- - -

The message box portion is meant - for short messages only. If you need more than 200 characters for your - message, then file a bug report, email the maintainer directly, or send - an email to the arch-general mailing list - with your additional text.

- -

Note: Do not use this facility if the - package is broken! The package will be unflagged and the report will be ignored! File an issue on - the package's GitLab repository - instead.

- -

Please confirm your flag request for {{package.pkgname}}:

- -
{% csrf_token %} -
- {{ form.as_p }} -
- {% if package.is_recent %} -
- -
- This package was updated {{ package.last_update|naturaltime }} and may not yet be available on your mirror. Are you sure {{ package.pkgver }} is not the latest available version{% if package.url %} from upstream{% endif %}? -
-
- {% endif %} -

-
-
-{% endblock %} diff --git a/templates/packages/flag_confirmed.html b/templates/packages/flag_confirmed.html deleted file mode 100644 index 6274adbbd..000000000 --- a/templates/packages/flag_confirmed.html +++ /dev/null @@ -1,22 +0,0 @@ -{% extends "base.html" %} -{% load package_extras %} - -{% block title %}Arch Linux - Package Flagged - {{ package.pkgname }} {{ package.full_version }} ({{ package.arch.name }}){% endblock %} -{% block head %}{% endblock %} -{% block navbarclass %}anb-packages{% endblock %} - -{% block content %} -
-

Package Flagged - {{ package.pkgname }}

- -

Thank you, the maintainers have been notified the following - {{ packages|length }} package{{ packages|pluralize }} are out-of-date:

- - -

You can return to the package details page for {% pkg_details_link package %}.

-
-{% endblock %} diff --git a/templates/packages/flaghelp.html b/templates/packages/flaghelp.html deleted file mode 100644 index 179cc3c95..000000000 --- a/templates/packages/flaghelp.html +++ /dev/null @@ -1,31 +0,0 @@ -{% load static %} - - - Flagging Packages - - - - - - -

Flagging Packages

-

If you notice that a package is out-of-date (i.e., there is a newer - stable release available), then please notify us by - using the Flag button in the Package Details - screen. This will notify the maintainer(s) responsible for that - package so they can update it. If the package is unmaintained, the - notification will be sent to a developer mailing list.

- -

The message box portion of the flag utility is meant - for short messages only. If you need more than 200 characters for your - message, then file a bug report, email the maintainer directly, or send - an email to the arch-general mailing list - with your additional text.

- -

Note: Please do not use this facility if the - package is broken! File an issue on the package's GitLab repository - instead.

- -