From 12911a101e8a5adb4097ed503c3923bedaf98fa9 Mon Sep 17 00:00:00 2001 From: Jelle van der Waa Date: Sun, 27 Jun 2021 13:55:51 +0200 Subject: [PATCH] Port homepage intro to fastapi Port the main home page content to fastapi. --- aurweb/config.py | 6 +++ aurweb/routers/html.py | 2 + aurweb/util.py | 10 +++++ templates/index.html | 92 ++++++++++++++++++++++++++++++++++++++++++ test/test_homepage.py | 36 +++++++++++++++++ 5 files changed, 146 insertions(+) create mode 100644 test/test_homepage.py diff --git a/aurweb/config.py b/aurweb/config.py index 73db58dc..52fadda2 100644 --- a/aurweb/config.py +++ b/aurweb/config.py @@ -46,3 +46,9 @@ def getboolean(section, option): def getint(section, option, fallback=None): return _get_parser().getint(section, option, fallback=fallback) + + +def get_section(section_name): + for section in _get_parser().sections(): + if section == section_name: + return _get_parser()[section] diff --git a/aurweb/routers/html.py b/aurweb/routers/html.py index 580ee0d4..f6f1a54e 100644 --- a/aurweb/routers/html.py +++ b/aurweb/routers/html.py @@ -58,6 +58,8 @@ async def language(request: Request, async def index(request: Request): """ Homepage route. """ context = make_context(request, "Home") + context['ssh_fingerprints'] = util.get_ssh_fingerprints() + return render_template(request, "index.html", context) diff --git a/aurweb/util.py b/aurweb/util.py index 539af40e..d4a0b221 100644 --- a/aurweb/util.py +++ b/aurweb/util.py @@ -172,3 +172,13 @@ def add_samesite_fields(response: Response, value: str): cookie += f"; SameSite={value}" response.raw_headers[idx] = (header[0], cookie.encode()) return response + + +def get_ssh_fingerprints(): + fingerprints = {} + fingerprint_section = aurweb.config.get_section("fingerprints") + + if fingerprint_section: + fingerprints = {key: fingerprint_section[key] for key in fingerprint_section.keys()} + + return fingerprints diff --git a/templates/index.html b/templates/index.html index 27d3375d..8cd1cc78 100644 --- a/templates/index.html +++ b/templates/index.html @@ -1,4 +1,96 @@ {% extends 'partials/layout.html' %} {% block pageContent %} +
+

AUR {% trans %}Home{% endtrans %}

+

+ {{ "Welcome to the AUR! Please read the %sAUR User Guidelines%s and %sAUR TU Guidelines%s for more information." + | tr + | format('', "", + '', "") + | safe + }} + {{ "Contributed PKGBUILDs %smust%s conform to the %sArch Packaging Standards%s otherwise they will be deleted!" + | tr + | format("", "", + '', + "") + | safe + }} + {% trans %}Remember to vote for your favourite packages!{% endtrans %} + {% trans %}Some packages may be provided as binaries in [community].{% endtrans %} +

+ {% trans %}DISCLAIMER{% endtrans %}: + {% trans %}AUR packages are user produced content. Any use of the provided files is at your own risk.{% endtrans %} +

+

{% trans %}Learn more...{% endtrans %}

+

+
+
+

{% trans %}Support{% endtrans %}

+

{% trans %}Package Requests{% endtrans %}

+
+

+ {{ "There are three types of requests that can be filed in the %sPackage Actions%s box on the package details page:" + | tr + | format("", "") + | safe + }} +

+
    +
  • {% trans %}Orphan Request{% endtrans %}: {% trans %}Request a package to be disowned, e.g. when the maintainer is inactive and the package has been flagged out-of-date for a long time.{% endtrans %}
  • +
  • {% trans %}Deletion Request{% endtrans %}: {%trans %}Request a package to be removed from the Arch User Repository. Please do not use this if a package is broken and can be fixed easily. Instead, contact the package maintainer and file orphan request if necessary.{% endtrans %}
  • +
  • {% trans %}Merge Request{% endtrans %}: {% trans %}Request a package to be merged into another one. Can be used when a package needs to be renamed or replaced by a split package.{% endtrans %}
  • +
+

+ {{ "If you want to discuss a request, you can use the %saur-requests%s mailing list. However, please do not use that list to file requests." + | tr + | format('', "") + | safe + }} +

+
+

{% trans %}Submitting Packages{% endtrans %}

+
+

+ {{ "Git over SSH is now used to submit packages to the AUR. See the %sSubmitting packages%s section of the Arch User Repository ArchWiki page for more details." + | tr + | format('', "") + | safe + }} +

+ {% if ssh_fingerprints %} +

+ {% trans %}The following SSH fingerprints are used for the AUR:{% endtrans %} +

+

    + {% for keytype in ssh_fingerprints %} +
  • {{ keytype }}: {{ ssh_fingerprints[keytype] }} + {% endfor %} +
+ {% endif %} +
+

{% trans %}Discussion{% endtrans %}

+
+

+ {{ "General discussion regarding the Arch User Repository (AUR) and Trusted User structure takes place on %saur-general%s. For discussion relating to the development of the AUR web interface, use the %saur-dev%s mailing list." + | tr + | format('', "", + '', "") + | safe + }} +

+

+

{% trans %}Bug Reporting{% endtrans %}

+
+

+ {{ "If you find a bug in the AUR web interface, please fill out a bug report on our %sbug tracker%s. Use the tracker to report bugs in the AUR web interface %sonly%s. To report packaging bugs contact the package maintainer or leave a comment on the appropriate package page." + | tr + | format('', "", + "", "") + | safe + }} +

+
+
{% endblock %} diff --git a/test/test_homepage.py b/test/test_homepage.py new file mode 100644 index 00000000..23d7185f --- /dev/null +++ b/test/test_homepage.py @@ -0,0 +1,36 @@ +from http import HTTPStatus +from unittest.mock import patch + +from fastapi.testclient import TestClient + +from aurweb.asgi import app + +client = TestClient(app) + + +def test_homepage(): + with client as request: + response = request.get("/") + assert response.status_code == int(HTTPStatus.OK) + + +@patch('aurweb.util.get_ssh_fingerprints') +def test_homepage_ssh_fingerprints(get_ssh_fingerprints_mock): + fingerprints = {'Ed25519': "SHA256:RFzBCUItH9LZS0cKB5UE6ceAYhBD5C8GeOBip8Z11+4"} + get_ssh_fingerprints_mock.return_value = fingerprints + + with client as request: + response = request.get("/") + + assert list(fingerprints.values())[0] in response.content.decode() + assert 'The following SSH fingerprints are used for the AUR' in response.content.decode() + + +@patch('aurweb.util.get_ssh_fingerprints') +def test_homepage_no_ssh_fingerprints(get_ssh_fingerprints_mock): + get_ssh_fingerprints_mock.return_value = {} + + with client as request: + response = request.get("/") + + assert 'The following SSH fingerprints are used for the AUR' not in response.content.decode()