Commit graph

3818 commits

Author SHA1 Message Date
Kevin Morris
4e7d2295da
fix(FastAPI): add package-related missing backref cascades
Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-10-07 20:25:24 -07:00
Kevin Morris
0ddc969bdc
feat(FastAPI-dev): add package_delete helper
Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-10-07 20:25:23 -07:00
Kevin Morris
ed68fa2b57
feat(FastAPI): add aurweb.db.delete_all(iterable)
Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-10-07 20:25:23 -07:00
Kevin Morris
c8d01cc5e8
feat(FastAPI): add aurweb.util.apply_all(iterable, fn)
A helper which allows us to apply a specific function to each
item in an iterable.

Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-10-07 20:25:20 -07:00
Kevin Morris
16d516c221
feat(FastAPI): add /pkgbase/{name}/disown (get, post)
Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-10-07 20:13:40 -07:00
Kevin Morris
0a02df363a
feat(FastAPI): add /pkgbase/{name}/[un]vote (post)
Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-10-07 18:22:04 -07:00
Kevin Morris
0dfff2bcb2
feat(FastAPI): add /pkgbase/{name}/[un]notify (post)
Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-10-07 17:23:14 -07:00
Kevin Morris
8eadb4251d
feat(FastAPI): add /pkgbase/{name}/[un]flag (post)
Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-10-07 16:04:54 -07:00
Kevin Morris
55ebfa0d01
Merge branch 'pu_auth_redirect_vars' into pu 2021-10-07 12:42:53 -07:00
Kevin Morris
2e6f8cb9f4
change(FastAPI): @auth_required login kwarg defaulted to True
We pretty much want @auth_required to send users to login
if we enforce auth requirements but don't otherwise specify
a way to deal with it.

Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-10-07 12:38:34 -07:00
Kevin Morris
a756691d08
change(FastAPI): user_developer_or_trusted_user always True
Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-10-07 10:00:46 -07:00
Kevin Morris
dc11a88ed3
change(FastAPI): depend on auth_required redirect for pkgbase actions
Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-10-07 00:40:22 -07:00
Kevin Morris
8bc1fab74d
change(FastAPI): automate request login requirement
Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-10-07 00:27:51 -07:00
Kevin Morris
75c49e4f8a
feat(FastAPI): support {named} fmt in auth_required redirect
Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-10-07 00:27:47 -07:00
Kevin Morris
e5299b5ed4
fix(FastAPI): pkgbase/package tests
Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-10-06 23:17:08 -07:00
Kevin Morris
33b18907eb
feat(FastAPI): add CRED_PKGBASE_MERGE
Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-10-06 22:30:15 -07:00
Kevin Morris
889c5b1e21
fix(FastAPI): pkgbase actions template
Display Delete, Merge and Disown actions based on user credentials.

Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-10-06 22:09:58 -07:00
Steven Guikal
a54a09f61d fix(FastAPI): fix padding on email inputs
Signed-off-by: Steven Guikal <void@fluix.one>
2021-10-05 17:50:22 -04:00
Steven Guikal
1bce53bbb7 fix(FastAPI): mark user and passwd as required fields 2021-10-05 14:36:46 -04:00
Steven Guikal
1956be0f46 fix(FastAPI): prefill login fields with entered data 2021-10-05 14:13:48 -04:00
Kevin Morris
82a3349649
Merge branch 'fix-reqname-tr' into pu 2021-10-05 01:48:14 -07:00
Kevin Morris
aac13cd123
Merge branch 'fix-key-case' into pu 2021-10-05 01:38:18 -07:00
Steven Guikal
f392b3607e fix(FastAPI): add missing translation filter for request type
Signed-off-by: Steven Guikal <void@fluix.one>
2021-10-04 17:42:55 -04:00
Steven Guikal
9af76a73a3 fix(FastAPI): include MergeBaseName in merge request type
This was done on the dedicated requests page, but missed on the
dashboard.

Signed-off-by: Steven Guikal <void@fluix.one>
2021-10-04 17:36:10 -04:00
Steven Guikal
5c179dc4d3 fix(FastAPI): use consistent ordering on dashboard and request page
Signed-off-by: Steven Guikal <void@fluix.one>
2021-10-04 17:11:29 -04:00
Steven Guikal
08068e0a5c fix(FastAPI): use configured letter case for SSH fingerprints
Currently, the config parser converts all keys to lowercase which is
inconsistent with the old PHP behavior. This has been fixed and relevant
fingerprint-getting functions have been simplified without changes in
behavior.

Signed-off-by: Steven Guikal <void@fluix.one>
2021-10-04 18:00:50 +00:00
Kevin Morris
7bfc2bf9b4
fix(FastAPI): Improve sqlite testing speed
This commit adds a new Arch dependency: `libeatmydata`, which
provides the `eatmydata` executable that stubs out fsync() operations.
We use `eatmydata` to run our sharness and pytests in Docker now.

With `autocommit=True`, required by SQLAlchemy to keep the
session up to date with external DB modifications, many fsync
calls are used in the SQLite backend; especially because we're wiping
and creating records in every DB-bound test.

**Before:**

- mysql: 1m42s (elapsed during pytest run)
- sqlite: 3m06s (elapsed during pytest run)

**After:**

- mysql: 1m40s (elapsed during pytest run)
- sqlite: 1m50s (elapsed during pytest run)

Shout out to @klausenbusk, who suggested this as a possible fix,
and it was. Thanks, Kristian!

Closes #120

Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-10-03 15:59:52 -07:00
Kevin Morris
b5f8e69b8a
feat(FastAPI): use SQLAlchemy's scoped_session
Closes #113

Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-10-03 10:47:15 -07:00
Kevin Morris
f6141ff177
feat(FastAPI): add /requests/{id}/close (get, post)
Changes from PHP:

- If a user submits a POST request with an invalid reason,
  they are returned back to the closure form with a BAD_REQUEST status.
- Now, users which created a PackageRequest have the ability to close
  their own.
- Form action has been changed to `/requests/{id}/close`.

Closes https://gitlab.archlinux.org/archlinux/aurweb/-/issues/20

Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-10-02 22:47:05 -07:00
Kevin Morris
1c031638c6
feat(FastAPI): add /pkgbase/{name}/request (post)
This change implements the FastAPI version of the
/pkgbase/{name}/request form's action.

Changes from PHP:

- Additional errors are now displayed for the **merge_into** field,
  which are only displayed when the Merge type is selected.
    - If the **merge_into** field is empty, a new error is displayed:
      'The "Merge into" field must not be empty.'
    - If the **merge_into** field is given the name of a package base
      which does not exist, a new error is displayed:
      "The package base you want to merge into does not exist."
    - If the **merge_into** field is given the name of the package
      base that a request is being created for, a new error is
      displayed: "You cannot merge a package base into itself."
- When an error is encountered, users are now brought back to
  the request form which they submitted and an error is displayed
  at the top of the page.
- If an invalid type is provided, users are returned to a BAD_REQUEST
  status rendering of the request form.

Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-10-02 22:46:49 -07:00
Kevin Morris
ad8369395e
feat(FastAPI): add /pkgbase/{name}/request (get)
This change brings in the package base request form
for new submissions.

Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-10-02 22:46:48 -07:00
Kevin Morris
1cf9420997
feat(FastAPI): allow reporters to cancel their own requests (1/2)
This change required a slight modification of how we handle
the Requests page. It is now available to all users.

This commit provides 1/2 of the implementation which actually
satisfies this feature. 2/2 will contain the actual implementation
of closures of requests, which will also allow users who created
the request to decide to close it.

Issue: https://gitlab.archlinux.org/archlinux/aurweb/-/issues/20

Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-10-02 22:46:38 -07:00
Kevin Morris
99482f9962
feat(FastAPI): added /requests (get) route
Introduces `aurweb.defaults` and `aurweb.filters`.

`aurweb.filters` is a location developers can put their additional
Jinja2 filters and/or functions. We should slowly move all of our
filters over here, where it makes sense.

`aurweb.defaults` is a new module which hosts some default constants
and utility functions, starting with offsets (O) and per page values
(PP).

As far as the new GET /requests is concerned, we match up here to
PHP's implementation, with some minor improvements:

Improvements:

* PP on this page is now configurable: 50 (default), 100, or 250.
    * Example: `https://localhost:8444/requests?PP=250`

Modifications:

* The pagination is a bit different, but serves the exact same purpose.
* "Last" no longer goes to an empty page.
    * Closes: https://gitlab.archlinux.org/archlinux/aurweb/-/issues/14

Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-10-02 22:43:48 -07:00
Kevin Morris
c164abe256
feat(FastAPI): add Requests navigation item
Along with this, created a new test suite at test/test_html.py,
which has the responsibility of testing various HTML things
that are not suitable for another test suite.

Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-10-02 22:43:01 -07:00
Kevin Morris
4d191b51f9
feat(FastAPI): add /pkgbase/{name}/comaintainers (get, post)
Changes from PHP:

- Form action now points to `/pkgbase/{name}/comaintainers`.
- When an error occurs, users are sent back to
  `/pkgbase/{name}/comaintainers` with an error at the top of the page.
  (PHP used to send people to /pkgbase/, which ended up at a blank
  search page).

Closes: https://gitlab.archlinux.org/archlinux/aurweb/-/issues/51

Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-10-02 20:19:09 -07:00
Kevin Morris
986fa9ee30
feat(PHP): add aurweb Prometheus metrics
Along with this initial requests metric implementation,
we also now serve the `/metrics` route, which grabs request
metrics out of cache and renders them properly for Prometheus.

**NOTE** Metrics are only enabled when the aurweb system admin
has enabled caching by configuring `options.cache` correctly
in `$AUR_CONFIG`. Otherwise, an error is logged about no cache
being configured.

New dependencies have been added which require the use of
`composer`. See `INSTALL` for the dependency section in regards
to composer dependencies and how to install them properly for
aurweb.

Metrics are in the following forms:

    aurweb_http_requests_count(method="GET",route="/some_route")
    aurweb_api_requests_count(method="GET",route="/rpc",type="search")

This should allow us to search through the requests for specific routes
and queries.

Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-10-02 18:51:45 -07:00
Kevin Morris
2efd254974
feat(FastAPI): add /pkgbase/{name}/comments/{id}/unpin (post)
Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-10-02 16:59:46 -07:00
Kevin Morris
0895dd07ee
feat(FastAPI): add /pkgbase/{name}/comments/{id}/pin (post)
In addition, fix up some templates to display pinned comments,
and include the unpin form input for pinned comments, which is
not yet implemented.

Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-10-02 16:59:38 -07:00
Kevin Morris
bb45ae7ac3
feat(FastAPI): add /pkgbase/{name}/comments/{id}/undelete (post)
Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-10-02 16:59:30 -07:00
Kevin Morris
40cd1b9029
feat(FastAPI): add /pkgbase/{name}/comments/{id}/delete (post)
Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-10-02 16:59:22 -07:00
Kevin Morris
d3be30744c
add(FeatAPI): comment pytest.fixture
Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-10-02 16:59:22 -07:00
Kevin Morris
6644c42922
fix(FastAPI): AnonymousUser.has_credential also takes kwargs
Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-10-02 16:59:21 -07:00
Kevin Morris
59d04d6e0c
fix(FastAPI): comment.html template rendering
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>
2021-10-02 16:59:21 -07:00
Kevin Morris
fc28aad245
feat(FastAPI): add pkgbase comments (new, edit)
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>
2021-10-02 16:59:10 -07:00
Kevin Morris
0d8216e8ea
change(FastAPI): decouple rendercomment logic from main
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>
2021-10-02 16:59:10 -07:00
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