Deleters and edits were not previously taken into account.
This fix addresses that issue using User.has_credential.
Signed-off-by: Kevin Morris <kevr@0cost.org>
In PHP, this was implemented using an /rpc type 'get-comment-form'.
With FastAPI, we've decided to reorganize this into a non-RPC route:
`/pkgbase/{name}/comments/{id}/form`, rendered via the new
`templates/partials/packages/comment_form.html` template.
When the comment_form.html template is provided a `comment` object,
it will produce an edit comment form. Otherwise, it will produce a new
comment form.
A few new FastAPI routes have been introduced:
- GET `/pkgbase/{name}/comments/{id}/form`
- Produces a JSON response based on {"form": "<form_markup>"}.
- POST `/pkgbase/{name}/comments'
- Creates a new comment.
- POST `/pkgbase/{name}/comments/{id}`
- Edits an existing comment.
In addition, some Javascript has been modified for our new routes.
Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit decouples most of the rendercomment.py logic into
a function, `update_comment_render`, which can be used by other
Python modules to perform comment rendering.
In addition, we silence some deprecation warnings from python-markdown
by removing `md_globals` parameters from python-markdown callbacks.
Signed-off-by: Kevin Morris <kevr@0cost.org>
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>