Commit graph

329 commits

Author SHA1 Message Date
Kevin Morris
65240c8343
feat(rpc): enforce ratelimiting
New configuration options:

- `[ratelimit] cache`
    - A boolean indicating whether we should use configured cache (1)
      or database (0) for ratelimiting.

Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-10-21 11:07:36 -07:00
Kevin Morris
a06f4ec19c
fix(fastapi): centralize logging initialization
With this change, we provide a wrapper to `logging.getLogger`
in the `aurweb.logging` module. Modules wishing to log using
logging.conf should get their module-local loggers by calling
`aurweb.logging.getLogger(__name__)`, similar to `logging.getLogger`,
this way initialization with logging.conf is guaranteed.

Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-10-21 10:40:52 -07:00
Kevin Morris
7c4fb539d8
change(fastapi): rework /rpc (get)
This reworks the base implementation of the RPC to use a
class called RPC for handling of requests. Took a bit of
a different approach than PHP in terms of exposed methods,
but it does end up achieving the same goal, with one additional
error: "Request type '{type}' is not yet implemented."

For FastAPI development, we'll stick with:

- If the supplied 'type' argument has an alias mapping in
  RPC.ALIASES, we convert the type argument over to its alias
  before doing anything. Example: 'info' is aliased to 'multiinfo',
  so when a user requests type=info, it is converted to type=multiinfo.
- If the type does not exist in RPC.EXPOSED_TYPES, the following
  error is produced: "No request type/data specified."
- If the type **does** exist in RPC.EXPOSED_TYPES, but does not
  have an implemented `RPC._handle_{type}_type` function, the
  following error is produced: "Request type '{type}' is not yet
  implemented."

Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-10-20 22:17:05 -07:00
Kevin Morris
2b9840149e
feat(fastapi): add /pkgbase/{name}/merge (get)
Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-10-20 20:31:44 -07:00
Kevin Morris
990f4d182b
feat(rpc): add 'suggest-pkgbase' type
This feature of RPC is required to take advantage of
javascript typeahead.

Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-10-20 20:31:42 -07:00
Kevin Morris
ddc51dd5eb
Merge branch 'fix-trailing-slashes' into pu 2021-10-20 17:46:12 -07:00
Kevin Morris
37f0c352f6
feat(FastAPI): add /pkgbase/{name}/flag-comment (get)
Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-10-19 13:39:00 -07:00
Kevin Morris
210d92e382
Merge branch 'pu_packages_action_post' into pu 2021-10-19 13:38:02 -07:00
Bert Peters via aur-dev
36c1ee35a7
Send request notifications to co-maintainers
This is in addition to the current recipients. Co-maintainers should
also be made aware when their package has pending requests.

NOTE: This commit was slightly modified to resolve cherry-pick
conflicts in `pu`.
2021-10-19 12:18:40 -07:00
Kevin Morris
267f2cb2c4
fix(fastapi): remove trailing slashes from fastapi-driven links
With our FastAPI server, trailing slashes causes a 307 redirect
which ends up redirecting users to routes which do not contain
trailing slashes. This removes trailing slashes from our templates
where FastAPI is concerned to avoid unnecessary redirects.

There may still be links or usages around which have unnecessary
usages of a trailing slash; please keep a look out for these and
remove them where possible.

Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-10-18 22:42:40 -07:00
Kevin Morris
c588a4e82e
feat(FastAPI): add /packages (post)
The POST /packages route takes an `action`, `merge_into` and `confirm`
form data arguments. It then routes over to `action`'s callback provided
by `PACKAGE_ACTIONS`. This commit does not implement actions, but
mocks out the flow we would expect from the POST route.

Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-10-18 17:43:27 -07:00
Kevin Morris
c572a97d1c
fix(fastapi): EXPECTATION_FAILED -> BAD_REQUEST
Usage of EXPECTATION_FAILED in these cases is totally wrong.
EXPECTATION_FAILED is a failure in terms of the HTTP protocol,
not user input. Change all usage of EXPECTATION_FAILED to BAD_REQUEST.

Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-10-16 17:38:33 -07:00
Kevin Morris
2d46811c45
fix(FastAPI): display VCS note when flagging a VCS package
Closes: #131

Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-10-15 16:16:11 -07:00
Kevin Morris
71b3f781f7
fix(FastAPI): maintainers are allowed to unflag their packages
Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-10-15 15:11:45 -07:00
Kevin Morris
b631dcb756
Merge branch 'pu_pkgbase_flag_fix' into pu 2021-10-15 13:50:56 -07:00
Kevin Morris
27fbda5e7b
feat(FastAPI): add get_(errors|successes) testing HTML helpers
These functions will allow us to more easily check errors or success
messages when testing routes.

Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-10-09 22:04:48 -07:00
Kevin Morris
5bbc94f2ef
fix(FastAPI): add /pkgbase/{name}/flag (get)
This was missed in the [un]flag (post) commit.

Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-10-09 18:41:32 -07:00
Kevin Morris
305d077973
feat(FastAPI): add /pkgbase/{name}/adopt (post)
Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-10-08 15:58:00 -07:00
Kevin Morris
63498f5edd
fix(FastAPI): use popupdate when [un]voting
The `aurweb.scripts.popupdate` script is used to maintain
the NumVotes and Popularity field. We could do the NumVotes
change more simply; however, since this is already a long-term
implementation, we're going to use it until we move scripts
over to ORM.

Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-10-08 15:29:47 -07:00
Kevin Morris
d38abd7832
feat(FastAPI): add /pkgbase/{name}/delete (get, post)
In addition, we've had to add cascade arguments to backref so
sqlalchemy treats the relationships as proper cascades.

Furthermore, our pkgbase actions template was not rendering
actions properly based on TU credentials.

Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-10-07 20:36:24 -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
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
e5299b5ed4
fix(FastAPI): pkgbase/package tests
Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-10-06 23:17:08 -07:00
Steven Guikal
1956be0f46 fix(FastAPI): prefill login fields with entered data 2021-10-05 14:13:48 -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
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
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
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
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
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
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
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