This function is now used as `render_template`'s underlying
implementation of rendering a template, and uses that render
in its HTMLResponse path.
This separation allows users to directly render a template
without producing a Response object.
Signed-off-by: Kevin Morris <kevr@0cost.org>
`get_pkgbase` has been replaced with `get_pkg_or_base`, which is
quite similar, but it does take a new `cls` keyword argument which
is to be the model class which we search for via its `Name` column.
Additionally, this change fixes a bug in the `/packages/{name}` route
by supplying the Package object in question to the context and modifying
the template to use it instead of a hacky through-base workaround.
Examples:
pkgbase = get_pkg_or_base("some_pkgbase_name", PackageBase)
pkg = get_pkg_or_base("some_package_name", Package)
Signed-off-by: Kevin Morris <kevr@0cost.org>
For the dev environment, we use a no-op address. We don't want
to be spamming aur-requests with development notifications.
Signed-off-by: Kevin Morris <kevr@0cost.org>
Additionally, `up -d` will no longer run tests unless `--profile dev`
is specified by the Docker user.
People should now be running docker with two files:
$ docker-compose -f docker-compose.yml -f docker-compose.override.yml up -d nginx
$ docker-compose -f docker-compose.yml -f docker-compose.dev.yml run test
Contributed by @klausenbusk. Thanks!
Now, when a `./cache/production.{cert,key}.pem` pair is found, it is
used in place of any certificates generated by the `ca` service.
This allows users to customize the certificate that the FastAPI
ASGI server uses as well as the front-end nginx certificates.
Optional:
- ./cache/production.cert.pem
- ./cache/production.key.pem
Fallback:
- ./cache/localhost.cert.pem + ./cache/root.ca.pem (chain)
- ./cache/localhost.key.pem
Signed-off-by: Kevin Morris <kevr@0cost.org>
We'll need to add tests for these things at some point. However,
I'd like to include this script in here immediately for ease of
testing or administration in general.
Signed-off-by: Kevin Morris <kevr@0cost.org>
In terms of performance, most queries on this page win over
PHP in query times, with the exception of sorting by Voted or
Notify (https://gitlab.archlinux.org/archlinux/aurweb/-/issues/102).
Otherwise, there are a few modifications: described below.
* Pagination
* The `paginate` Python module has been used in the FastAPI
project
here to implement paging on the packages search page. This
changes how pagination is displayed, however it serves the
same purpose. We'll take advantage of this module in other
places as well.
* Form action
* The form action for actions now use `POST /packages` to
perform. This is currently implemented and will be
addressed in a follow-up commit.
* Input names and values
* Input names and values have been modified to satisfy the
snake_case naming convention we'd like to use as much as
possible.
* Some input names and values were modified to comply with
FastAPI Forms: (IDs[<id>]) -> (IDs, <id>).
Signed-off-by: Kevin Morris <kevr@0cost.org>
With upstream at https://github.com/Pylons/paginate, this module
helps us deal with pagination without reinventing the wheel.
Signed-off-by: Kevin Morris <kevr@0cost.org>
Previously, we were running a single ORM query for every single package
to check for its voted or notified states. Now, we perform a single
ORM query for each of the set of voted or notified packages in
relation with the request user.
This improves performance drastically at the expense of some
manual code additions and set-dependency; i.e. we add a bit
more complexity and roundabout way of getting our data.
Closes: https://gitlab.archlinux.org/archlinux/aurweb/-/issues/102
Signed-off-by: Kevin Morris <kevr@0cost.org>
- Removed 'if type == "info"' as requested by @kevr
- Checked for valid type against the type dictionary, removing the
needed to maintain two separate spots for type definitions.
Additionally, simplify some of the certificate generation
scripts and rename `ca.ext` to `localhost.ext`.
Certificates should be regenerated as of this commit.
Users can run `rm -rf ./cache/*` to clear out any existing
certs, which will cause the `ca` service to regenerate them.
Additionally, since Docker infrastructure has been modified,
a new `aurweb:latest` image will need to be built.
See https://gitlab.archlinux.org/archlinux/aurweb/-/wikis/Docker
Signed-off-by: Kevin Morris <kevr@0cost.org>
The "Account Type" selection was not properly being rendered
due to an incorrect equality. This has been fixed in
templates/partials/account_form.html.
Signed-off-by: Kevin Morris <kevr@0cost.org>
Provides a single source of truth for mariadb database
initialization. Previously, php-fpm and fastapi were
racing against each other; while this wasn't an issue,
it was very messy.
Signed-off-by: Kevin Morris <kevr@0cost.org>
The update hook was incorrectly linked to /usr/local/bin/aurweb-git-update,
which was neglected during the original patch regarding dependency
conversion to `poetry`.
Signed-off-by: Kevin Morris <kevr@0cost.org>
PHP was doing this correctly, but FastAPI was doing this
in it's exec script @ docker/scripts/run-fastapi.sh.
Modify the fastapi service so that it does the same thing as
PHP, and the existing "fastapi restart quirk" is no more.
Signed-off-by: Kevin Morris <kevr@0cost.org>
As root, seems that $HOME doesn't work like I expected it to.
Tested this before, but I apparently had some cache still holding
on. Fixing the issue in this commit here.
Signed-off-by: Kevin Morris <kevr@0cost.org>
As the new-age Python package manager, Poetry brings a lot
of good additions to the table. It allows us to more easily
deal with virtualenvs for the project and resolve dependencies.
As of this commit, `requirements.txt` is replaced by Poetry,
configured at `pyproject.toml`.
In Docker and GitLab, we currently use Poetry in a root fashion.
We should work toward purely using virtualenvs in Docker, but,
for now we'd like to move forward with other things. The project
can still be installed to a virtualenv and used on a user's system
through Poetry; it is just not yet doing so in Docker.
Modifications:
* docker/scripts/install-deps.sh
* Remove python dependencies.
* conf/config.defaults
* Script paths have been updated to use '/usr/bin'.
* docker/git-entrypoint.sh
* Use '/usr/bin/aurweb-git-auth' instead of
'/usr/local/bin/aurweb-git-auth'.
Additions:
* docker/scripts/install-python-deps.sh
* A script used purely to install Python dependencies with Poetry.
This has to be used within the aurweb project directory and
requires system-wide dependencies are installed beforehand.
* Also upgrades system-wide pip.
Signed-off-by: Kevin Morris <kevr@0cost.org>
For SQLAlchemy to automatically understand updates from the
external world, it must use an `autocommit=True` in its session.
This change breaks how we were using commit previously, as
`autocommit=True` causes SQLAlchemy to commit when a
SessionTransaction context hits __exit__.
So, a refactoring was required of our tests: All usage of
any `db.{create,delete}` must be called **within** a
SessionTransaction context, created via new `db.begin()`.
From this point forward, we're going to require:
```
with db.begin():
db.create(...)
db.delete(...)
db.session.delete(object)
```
With this, we now get external DB modifications automatically
without reloading or restarting the FastAPI server, which we
absolutely need for production.
Signed-off-by: Kevin Morris <kevr@0cost.org>
With FastAPI starting to come closer to a close, we've got to advertise
this deprecation so that users have some time to adjust before making
the changes. We have not specified a specific time here, but we'd like
this message to reach users of the RPC API for at least a month before
any modifications are made to the interface.
Signed-off-by: Kevin Morris <kevr@0cost.org>
The new `extend_query` and `urlencode` filters are way cleaner ways
to achieve what we did with `dedupe_qs`.
Signed-off-by: Kevin Morris <kevr@0cost.org>
The first addition, extend_query, can be used to take an existing
query parameter dictionary and inject an *additions as replacement
key/value pairs.
The second, to_qs, converts a query parameter dictionary to
a query string in the form "a=b&c=d".
These two functions simplify and make dedupe_qs and quote_plus more
efficient in terms of constructing custom query string overrides.
Signed-off-by: Kevin Morris <kevr@0cost.org>
urlencode does more than just a quote_plus. Using urlencode
was not sensible, so this commit addresses that.
Signed-off-by: Kevin Morris <kevr@0cost.org>