Merge branch 'master' into live

This commit is contained in:
Kevin Morris 2022-02-14 15:46:58 -08:00
commit 10c8433e62
No known key found for this signature in database
GPG key ID: F7E46DED420788F3
10 changed files with 66 additions and 20 deletions

View file

@ -6,7 +6,7 @@ from typing import Any
# Publicly visible version of aurweb. This is used to display # Publicly visible version of aurweb. This is used to display
# aurweb versioning in the footer and must be maintained. # aurweb versioning in the footer and must be maintained.
# Todo: Make this dynamic/automated. # Todo: Make this dynamic/automated.
AURWEB_VERSION = "v6.0.11" AURWEB_VERSION = "v6.0.13"
_parser = None _parser = None

View file

@ -52,3 +52,11 @@ class PackageComment(Base):
if self.RenderedComment is None: if self.RenderedComment is None:
self.RenderedComment = str() self.RenderedComment = str()
def maintainers(self):
return list(filter(
lambda e: e is not None,
[self.PackageBase.Maintainer] + [
c.User for c in self.PackageBase.comaintainers
]
))

View file

@ -25,9 +25,11 @@ def make_context(request: Request, pkgbase: PackageBase) -> Dict[str, Any]:
context["git_clone_uri_anon"] = config.get("options", "git_clone_uri_anon") context["git_clone_uri_anon"] = config.get("options", "git_clone_uri_anon")
context["git_clone_uri_priv"] = config.get("options", "git_clone_uri_priv") context["git_clone_uri_priv"] = config.get("options", "git_clone_uri_priv")
context["pkgbase"] = pkgbase context["pkgbase"] = pkgbase
context["comaintainers"] = pkgbase.comaintainers.order_by( context["comaintainers"] = [
PackageComaintainer.Priority.asc() c.User for c in pkgbase.comaintainers.order_by(
).all() PackageComaintainer.Priority.asc()
).all()
]
context["packages_count"] = pkgbase.packages.count() context["packages_count"] = pkgbase.packages.count()
context["keywords"] = pkgbase.keywords context["keywords"] = pkgbase.keywords
context["comments"] = pkgbase.comments.order_by( context["comments"] = pkgbase.comments.order_by(

View file

@ -39,14 +39,17 @@ async def pkgbase(request: Request, name: str) -> Response:
# Get the PackageBase. # Get the PackageBase.
pkgbase = get_pkg_or_base(name, PackageBase) pkgbase = get_pkg_or_base(name, PackageBase)
# If this is not a split package, redirect to /packages/{name}. # Redirect to /packages if there's only one related Package
if pkgbase.packages.count() == 1: # and its name matches its PackageBase.
return RedirectResponse(f"/packages/{name}", packages = pkgbase.packages.all()
pkg = packages[0]
if len(packages) == 1 and pkg.Name == pkgbase.Name:
return RedirectResponse(f"/packages/{pkg.Name}",
status_code=int(HTTPStatus.SEE_OTHER)) status_code=int(HTTPStatus.SEE_OTHER))
# Add our base information. # Add our base information.
context = pkgbaseutil.make_context(request, pkgbase) context = pkgbaseutil.make_context(request, pkgbase)
context["packages"] = pkgbase.packages.all() context["packages"] = packages
return render_template(request, "pkgbase/index.html", context) return render_template(request, "pkgbase/index.html", context)
@ -318,7 +321,7 @@ async def pkgbase_comment_pin(request: Request, name: str, id: int,
comment = get_pkgbase_comment(pkgbase, id) comment = get_pkgbase_comment(pkgbase, id)
has_cred = request.user.has_credential(creds.COMMENT_PIN, has_cred = request.user.has_credential(creds.COMMENT_PIN,
approved=[pkgbase.Maintainer]) approved=comment.maintainers())
if not has_cred: if not has_cred:
_ = l10n.get_translator_for_request(request) _ = l10n.get_translator_for_request(request)
raise HTTPException( raise HTTPException(
@ -353,7 +356,7 @@ async def pkgbase_comment_unpin(request: Request, name: str, id: int,
comment = get_pkgbase_comment(pkgbase, id) comment = get_pkgbase_comment(pkgbase, id)
has_cred = request.user.has_credential(creds.COMMENT_PIN, has_cred = request.user.has_credential(creds.COMMENT_PIN,
approved=[pkgbase.Maintainer]) approved=comment.maintainers())
if not has_cred: if not has_cred:
_ = l10n.get_translator_for_request(request) _ = l10n.get_translator_for_request(request)
raise HTTPException( raise HTTPException(

View file

@ -2,6 +2,7 @@
import sys import sys
from urllib.parse import quote_plus
from xml.etree.ElementTree import Element from xml.etree.ElementTree import Element
import bleach import bleach
@ -72,13 +73,16 @@ class GitCommitsInlineProcessor(markdown.inlinepatterns.InlineProcessor):
def handleMatch(self, m, data): def handleMatch(self, m, data):
oid = m.group(1) oid = m.group(1)
if oid not in self._repo: if oid not in self._repo:
# Unkwown OID; preserve the orginal text. # Unknown OID; preserve the orginal text.
return (None, None, None) return (None, None, None)
el = Element('a') el = Element('a')
commit_uri = aurweb.config.get("options", "commit_uri") commit_uri = aurweb.config.get("options", "commit_uri")
prefixlen = util.git_search(self._repo, oid) prefixlen = util.git_search(self._repo, oid)
el.set('href', commit_uri % (self._head, oid[:prefixlen])) el.set('href', commit_uri % (
quote_plus(self._head),
quote_plus(oid[:prefixlen])
))
el.text = markdown.util.AtomicString(oid[:prefixlen]) el.text = markdown.util.AtomicString(oid[:prefixlen])
return (el, m.start(0), m.end(0)) return (el, m.start(0), m.end(0))

View file

@ -8,7 +8,7 @@
# #
[tool.poetry] [tool.poetry]
name = "aurweb" name = "aurweb"
version = "v6.0.11" version = "v6.0.13"
license = "GPL-2.0-only" license = "GPL-2.0-only"
description = "Source code for the Arch User Repository's website" description = "Source code for the Arch User Repository's website"
homepage = "https://aur.archlinux.org" homepage = "https://aur.archlinux.org"

View file

@ -47,13 +47,13 @@
{% endif %} {% endif %}
{% if request.user.has_credential(creds.COMMENT_PIN, approved=[comment.PackageBase.Maintainer]) %} {% if request.user.has_credential(creds.COMMENT_PIN, approved=comment.maintainers()) %}
{% if comment.PinnedTS %} {% if comment.PinnedTS %}
<form class="pin-comment-form" <form class="pin-comment-form"
method="post" method="post"
action="/pkgbase/{{ comment.PackageBase.Name }}/comments/{{ comment.ID }}/unpin" action="/pkgbase/{{ comment.PackageBase.Name }}/comments/{{ comment.ID }}/unpin"
> >
<fieldset style="display:inline;"> <fieldset style="display: inline;">
<input type="hidden" name="next" value="{{ request.url.path }}" /> <input type="hidden" name="next" value="{{ request.url.path }}" />
<input type="image" <input type="image"
class="pin-comment" class="pin-comment"

View file

@ -6,21 +6,21 @@
<h4>{{ "Package Actions" | tr }}</h4> <h4>{{ "Package Actions" | tr }}</h4>
<ul class="small"> <ul class="small">
<li> <li>
<a href="/cgit/aur.git/tree/PKGBUILD?h={{ pkgbase.Name }}"> <a href="{{ config.get('options', 'source_file_uri') | format("PKGBUILD", pkgbase.Name | quote_plus) }}">
{{ "View PKGBUILD" | tr }} {{ "View PKGBUILD" | tr }}
</a> </a>
/ /
<a href="/cgit/aur.git/log/?h={{ pkgbase.Name }}"> <a href="{{ config.get('options', 'log_uri') | format(pkgbase.Name | quote_plus) }}">
{{ "View Changes" | tr }} {{ "View Changes" | tr }}
</a> </a>
</li> </li>
<li> <li>
<a href="/cgit/aur.git/snapshot/{{ pkgbase.Name }}.tar.gz"> <a href="{{ config.get('options', 'snapshot_uri') | format(pkgbase.Name | quote_plus) }}">
{{ "Download snapshot" | tr }} {{ "Download snapshot" | tr }}
</a> </a>
</li> </li>
<li> <li>
<a href="https://wiki.archlinux.org/title/Special:Search?search={{ pkgbase.Name }}"> <a href="https://wiki.archlinux.org/title/Special:Search?{{ { 'search': pkgbase.Name } | urlencode }}">
{{ "Search wiki" | tr }} {{ "Search wiki" | tr }}
</a> </a>
</li> </li>

View file

@ -114,7 +114,7 @@
</a> </a>
{% set len = comaintainers | length %} {% set len = comaintainers | length %}
{% if comaintainers %} {% if comaintainers %}
({% for co in comaintainers %}<a href="{{ co.User | account_url }}">{{ co.User }}</a>{% if loop.index < len %}, {% endif %}{% endfor %}) ({% for co in comaintainers %}<a href="{{ co | account_url }}">{{ co }}</a>{% if loop.index < len %}, {% endif %}{% endfor %})
{% endif %} {% endif %}
{% else %} {% else %}
{{ pkgbase.Maintainer.Username | default("None" | tr) }} {{ pkgbase.Maintainer.Username | default("None" | tr) }}

View file

@ -534,6 +534,35 @@ def test_pkgbase_comment_undelete_not_found(client: TestClient,
assert resp.status_code == int(HTTPStatus.NOT_FOUND) assert resp.status_code == int(HTTPStatus.NOT_FOUND)
def test_pkgbase_comment_pin_as_co(client: TestClient, package: Package,
comment: PackageComment):
comaint = create_user("comaint1")
with db.begin():
db.create(PackageComaintainer, PackageBase=package.PackageBase,
User=comaint, Priority=1)
# Pin the comment.
pkgbasename = package.PackageBase.Name
endpoint = f"/pkgbase/{pkgbasename}/comments/{comment.ID}/pin"
cookies = {"AURSID": comaint.login(Request(), "testPassword")}
with client as request:
resp = request.post(endpoint, cookies=cookies)
assert resp.status_code == int(HTTPStatus.SEE_OTHER)
# Assert that PinnedTS got set.
assert comment.PinnedTS > 0
# Unpin the comment we just pinned.
endpoint = f"/pkgbase/{pkgbasename}/comments/{comment.ID}/unpin"
with client as request:
resp = request.post(endpoint, cookies=cookies)
assert resp.status_code == int(HTTPStatus.SEE_OTHER)
# Let's assert that PinnedTS was unset.
assert comment.PinnedTS == 0
def test_pkgbase_comment_pin(client: TestClient, def test_pkgbase_comment_pin(client: TestClient,
maintainer: User, maintainer: User,
package: Package, package: Package,