Commit graph

3267 commits

Author SHA1 Message Date
Kevin Morris
7961fa932a
feat(FastAPI): add templates.render_raw_template
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>
2021-10-02 16:59:09 -07:00
Kevin Morris
5e95cfbc8a
fix(FastAPI): get_pkgbase -> get_pkg_or_base
`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>
2021-10-02 16:59:09 -07:00
Kevin Morris
f849e8b696
change(FastAPI): allow User.notified to accept a Package OR PackageBase
In addition, shorten the `package_notifications` relationship to
`notifications`.

Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-10-02 16:59:09 -07:00
Kevin Morris
4abbf9a917
fix: use @localhost for dev email addresses
Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-10-02 16:34:34 -07:00
Kevin Morris
a3cb81962f
add: added aur_request_ml setting to config.dev
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>
2021-10-02 16:18:18 -07:00
Kevin Morris
438080827a
fix(Docker): add production config overrides
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!
2021-10-02 15:14:54 -07:00
Kevin Morris
eaf012963a
Merge branch 'docker-compose' of ssh://gitlab.archlinux.org:222/klausenbusk/aurweb into docker-compose 2021-10-02 15:05:22 -07:00
Kristian Klausen
ef0c2d5a28 magic 2021-10-02 23:54:10 +02:00
Kevin Morris
3b1809e2ea
feat(Docker): allow custom certificates for fastapi/nginx
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>
2021-10-02 13:27:19 -07:00
Kevin Morris
ad9997c48f
feat(Docker): build aurweb:latest via docker-compose build
Users can now build the required image by running (in the aurweb root):

    $ docker-compose build

Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-10-02 12:59:49 -07:00
Kevin Morris
fbd91f346a
feat(FastAPI): add /pkgbase/{name}/voters (get)
Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-10-02 12:28:32 -07:00
Kevin Morris
836af2d588
Merge branch 'pu_packages' into pu 2021-09-21 13:42:52 -07:00
Kevin Morris
dc5dc233ec
.gitlab-ci.yml: add coverage regex
This was required for the GitLab coverage badge to get the %
of coverage.

Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-09-21 00:13:29 -07:00
Kevin Morris
7e58986356
feat: add util/adduser.py database tooling script
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>
2021-09-20 01:30:12 -07:00
Kevin Morris
5cf7062092
feat(FastAPI): add /packages (get) search
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>
2021-09-19 12:44:19 -07:00
Kevin Morris
6298b1228a
feat(FastAPI): add templates/partials/widgets/pager.html
A pager that can be used for paginated result tables.

Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-09-19 12:44:19 -07:00
Kevin Morris
741cbfaa4e
auth: add several AnonymousUser method stubs
We'll need to use these, so this commit implements them here
with tests for coverage.

Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-09-19 12:44:18 -07:00
Kevin Morris
c006386079
add User.is_elevated()
This one returns true if the user is either a Trusted User
or a Developer.

Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-09-19 12:44:18 -07:00
Kevin Morris
b59601a8b7
feat(poetry): add paginate==0.5.6
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>
2021-09-19 12:44:16 -07:00
Kevin Morris
aee1390e2c
fix(FastAPI): registration sends WelcomeNotification
Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-09-19 11:48:19 -07:00
Kevin Morris
4de18d8134
fix(FastAPI): voted/notified query efficiency
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>
2021-09-19 00:34:08 -07:00
Kevin Morris
fd9b07c429 Merge branch 'pu-rpc-ontop' into pu 2021-09-17 12:48:40 -07:00
Kevin Morris
f7818e26b5
fix(FastAPI): test_rpc.setup() should be a pytest.fixture
Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-09-17 12:42:32 -07:00
Kevin Morris
0bbb3cc4d0
fix(FastAPI): rpc - include other fields with errors
PHP does this, we should persist the behavior here for
v=5.

Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-09-17 12:33:23 -07:00
Kevin Morris
06ec6388b4
fix(FastAPI): fix flake8 violation
Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-09-17 12:13:02 -07:00
Kevin Morris
6afcaf665e
fix(FastAPI): Fix aurweb.template warnings
Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-09-16 20:49:06 -07:00
Hunter Wittenborn
c56a23d21c Fixed bug with with type in returned JSON introduced in previous commit
Also removed some redundant return statements
2021-09-16 03:47:33 -05:00
Hunter Wittenborn
25aea216c5 Simplified and reduced redundancy in code
- 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.
2021-09-16 03:34:52 -05:00
Hunter Wittenborn
a4f5c8bef6 Fixed autopep violations in test/test_rpc.py 2021-09-16 03:20:56 -05:00
Kevin Morris
3ea515d705
fix(Docker): use cert chain for nginx
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>
2021-09-13 14:19:48 -07:00
Kevin Morris
ab8a44cede
fix(FastAPI): only show comments partial if they exist
This was incorrectly displaying a comment section header
when no comments existed.

Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-09-12 00:47:34 -07:00
Hunter Wittenborn
c2d3dc1daf Added info and multiinfo types for /rpc 2021-09-12 02:21:55 -05:00
Kevin Morris
db2718fcba
fix: util/fix-coverage sys.stderr typo
Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-09-09 16:21:11 -07:00
Kevin Morris
ad3016ef4f
fix: /account/{name}/edit Account Type selection
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>
2021-09-08 17:36:37 -07:00
Kevin Morris
0fd31b8d36
refactor(docker): New mariadb_init service
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>
2021-09-08 17:14:55 -07:00
Kevin Morris
2e3f69ab12
fix(docker): Fix git service's update hook
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>
2021-09-08 17:10:14 -07:00
Hunter Wittenborn
0386e0dbc2 Merge branch 'pu' of ssh://gitlab.archlinux.org:222/hwittenborn/aurweb into pu 2021-09-05 16:14:00 -05:00
Hunter Wittenborn
95357687f9 Added ability to specify fortune file via an environment variable 2021-09-05 16:13:45 -05:00
Kevin Morris
e93b0a9b45
Docker: expose fastapi (18000) and php-fpm (19000)
Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-09-05 00:08:47 -07:00
Kevin Morris
fa07f94051
Docker: Fix FastAPI db initialization
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>
2021-09-04 19:08:10 -07:00
Kevin Morris
3f034ac128
Docker: Fix incorrect ENV PATH specification
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>
2021-09-04 18:59:24 -07:00
Kevin Morris
2f9994807b
use Poetry to deal with deps and package install
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>
2021-09-04 15:46:40 -07:00
Kevin Morris
5e6f0cb8d7
Revert "Add GPL 2.0 LICENSE file"
This was already in the repository in ./COPYING

This reverts commit 1b452d1264.
2021-09-04 10:02:46 -07:00
Kevin Morris
1b452d1264
Add GPL 2.0 LICENSE file
This was missing from the project and really needs to be here.

Closes #107

Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-09-03 21:03:36 -07:00
Kevin Morris
a5943bf2ad
[FastAPI] Refactor db modifications
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>
2021-09-03 15:03:34 -07:00
Kevin Morris
b52059d437
RPC: add deprecation warning for v1-v4 usage
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>
2021-08-31 17:18:10 -07:00
Kevin Morris
210e459ba9
Eradicate the dedupe_qs filter
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>
2021-08-31 14:44:29 -07:00
Kevin Morris
c9374732c0
add filters for extend_query, to_qs
New jinja2 filters:

* `extend_query` -> `aurweb.util.extend_query`
* `urlencode` -> `aurweb.util.to_qs`

Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-08-31 14:25:58 -07:00
Kevin Morris
a114bd3e16
aurweb.util: add extend_query and to_qs helpers
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>
2021-08-31 13:29:06 -07:00
Kevin Morris
49cc12f99d
jinja2: rename filter 'urlencode' to 'quote_plus'
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>
2021-08-31 13:28:54 -07:00