Commit graph

356 commits

Author SHA1 Message Date
Kevin Morris
d675c0dc26
feat(python): catch all exceptions thrown through fastapi route paths
This commit does quite a bit:
- Catches unhandled exceptions raised in the route handler and
  produces a 500 Internal Server Error Arch-themed response.
- Each unhandled exception causes a notification to be sent to new
  `notifications.postmaster` email with a "Traceback ID."
- Traceback ID is logged to the server along with the traceback which
  caused the 500: `docker-compose logs fastapi | grep '<traceback_id>'`
- If `options.traceback` is set to `1`, traceback is displayed in
  the new 500.html template.

Signed-off-by: Kevin Morris <kevr@0cost.org>
2022-01-09 23:10:02 -08:00
Kevin Morris
6f6f067597
feat: add aurweb-adduser console script
Originally left at util/adduser.py, this script allows administrators
to simply add a user to the configured aurweb database.

See --help for options.

Signed-off-by: Kevin Morris <kevr@0cost.org>
2022-01-08 13:40:38 -08:00
Kevin Morris
9e7ae5904f
feat(python): handle RuntimeErrors raised through routes
This gets raised when a client closes a connection before receiving
a valid response; this is not controllable from our side.

Signed-off-by: Kevin Morris <kevr@0cost.org>
2022-01-07 18:21:23 -08:00
Kevin Morris
efd61979f7
fix(models.tu_voteinfo): default vote-count related columns to 0
Signed-off-by: Kevin Morris <kevr@0cost.org>
2022-01-06 20:25:30 -08:00
Kevin Morris
059733cb8c
fix(routers.trusted_user): use creds to determine authorization
Closes #237

Signed-off-by: Kevin Morris <kevr@0cost.org>
2022-01-05 22:09:49 -08:00
Kevin Morris
ae7621fb54
fix(routers.trusted_user): fix missing submitter link on /tu/{id}
Closes #235

Signed-off-by: Kevin Morris <kevr@0cost.org>
2022-01-05 17:18:19 -08:00
Kevin Morris
8ffff6261b
fix(models.package_dependency): add DepTypeID to PKs
This was stopping us from using numerous records for each dep type.

Signed-off-by: Kevin Morris <kevr@0cost.org>
2022-01-05 14:36:57 -08:00
Kevin Morris
6c6eb2c21b
test: add tests to check various 404 paths and 503
Signed-off-by: Kevin Morris <kevr@0cost.org>
2022-01-03 18:22:10 -08:00
Kevin Morris
51b60f4210
feat(auth): add requires_{auth,guest} decorators
These new decorators are meant to be used without any arguments
and provide aliases to auth_required:
- `auth_required(True) -> requires_auth`
- `auth_required(False) -> requires_guest`

These decorators should be used without arguments, e.g.:

    @router.get("/")
    @requires_guest
    async def my_route(request: Request):
        return HTMLResponse()

Signed-off-by: Kevin Morris <kevr@0cost.org>
2022-01-02 16:57:42 -08:00
Kevin Morris
a1f46611e1
change(python): move request & pkgbase request routes
Move package request routes and related routes to their
respective routers. In addition, move some utility used
for requests over from `aurweb.packages`.

Introduced routers:
- `aurweb.routers.requests`

Introduced package:
- `aurweb.requests`

Introduced module:
- `aurweb.requests.util`

Changes:
- Moved `aurweb.packages.validate` to `aurweb.pkgbase.validate`
- Moved requests listing & request closure routes to
  `aurweb.routers.requests`
- Moved pkgbase request creation route to `aurweb.routers.pkgbase`
- Moved `get_pkgreq_by_id` from `aurweb.packages.util` to
  `aurweb.requests.util` and fixed its return type hint.

Signed-off-by: Kevin Morris <kevr@0cost.org>
2022-01-02 01:44:36 -08:00
Kevin Morris
c735f9868b
change(routers.packages): delete_package -> pkgbase_delete_instance
`delete_package` was processing package deletions through `Package`
instances. This doesn't make sense; if we delete a package, we want
to target its package base.

This new function vastly simplifies the previous.

Signed-off-by: Kevin Morris <kevr@0cost.org>
2022-01-01 12:29:50 -08:00
Kevin Morris
53fabdfaea
fix(templates): require valid User relationships for <a> usage
Previously, when the relationship was None, an <a> would still
wrap the None value erroneously. This addresses that for all
three user fields.

In addition, this commit adds direct testing for the
`templates/partials/packages/details.html` template.

Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-12-31 18:31:48 -08:00
Kevin Morris
8f8929f324
fix(routers.packages): handle package source display
Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-12-30 23:10:00 -08:00
Kevin Morris
6fdaeee026
change(packages.util): handle queried record links via .is_official
This removes an unneeded query from our path.

Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-12-30 19:49:41 -08:00
Kevin Morris
fc229d755b
change(python): refactor & centralize comaintainer management
This commit centralizes comaintainer management with a few new
functions and uses them more appropriately within routes:

- aurweb.packages.util.latest_priority
- aurweb.packages.util.remove_comaintainer
- aurweb.packages.util.remove_comaintainers
- aurweb.packages.util.add_comaintainer
- aurweb.packages.util.add_comaintainers
- aurweb.packages.util.rotate_comaintainers

Closes #117

Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-12-29 19:50:17 -08:00
Kevin Morris
3a771fc807
fix(packages.requests): disown as maintainer does not need handle_requests
As a maintainer, we don't deal with requests at all.

Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-12-28 18:31:21 -08:00
Kevin Morris
d55dab93da
revert account type permission changes
While this does make more sense to me personally, there is no need
to change how the AUR treats its users; it has been accepted for
ages and not found to be ridden with flaws. Stay with the tried
and true method.

Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-12-27 22:41:18 -08:00
Kevin Morris
260b67c49e
change(models.user): can_edit_user should check account type id priority
The credential alone does not completely encapsulate our new
requirements for editing an account.

Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-12-27 16:04:57 -08:00
Kevin Morris
2baf061b96
test(routers.packages): fix package view dependency test
Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-12-26 17:03:16 -08:00
Kevin Morris
56bd60559c
fix(packages.search): fix default ordering & improve performance
- Use queries more closely aligned to PHP's implementation; removes
  the need for separate vote/notification queries.
- Default sort by popularity

Closes #214

Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-12-25 11:15:20 -08:00
Kevin Morris
50eec96dd0
fix(routers.packages): fix related package metadata
Closes #218

Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-12-21 18:02:37 -08:00
Kevin Morris
22093c5c38
fix(routers.packages): restrict /pkgbase/{name}/voters to those with creds
Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-12-19 17:15:47 -08:00
Kevin Morris
36bc9ae29b
fix(notify): gracefully fail notifications
Instead of allowing an exception to propogate through the framework
routes, catch it and log out an error about notifications not being
sent.

Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-12-17 18:08:36 -08:00
Kevin Morris
d6d41cdbad
fix(templates): add missing empty package results text
Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-12-16 22:01:14 -08:00
Kevin Morris
94e8d34948
fix(routers.accounts): use target user's account type for autofill
Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-12-16 16:10:01 -08:00
Kevin Morris
e17389485b
test(templates): add pager tests
Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-12-15 17:50:53 -08:00
Kevin Morris
f357615bfb
change(users.validate): users can't edit their own account types
This commit also decouples testing regarding this feature
into several test functions.

Signed-off-by: Kevin Morris <kevr@0cost.org>

bump

Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-12-14 16:45:40 -08:00
Kevin Morris
26b1674c9e
fix(requests): rework handling of requests
This commit changes several things about how we were handling
package requests.

Modifications (requests):
-------------
- `/requests/{id}/close` no longer provides an Accepted selection.
  All manual request closures will cause a rejection.
- Relevent `pkgbase` actions now trigger request closures:
  `/pkgbase/{name}/delete` (deletion), `/pkgbase/{name}/merge` (merge)
  and `/pkgbase/{name}/disown` (orphan).
- Comment fields have been added to
  `/pkgbase/{name}/{delete,merge,disown}`, which is used to set the
  `PackageRequest.ClosureComment` on pending requests. If the comment
  field is left blank, a closure comment is autogenerated.
- Autogenerated request notifications are only sent out once
  as a closure notification.
- Some markup has been fixed.

Modifications (disown/orphan):
-----------------------------
- Orphan requests are now handled through the same path as
  deletion/merge.
- We now check for due date when disowning as non-maintainer;
  previously, this was only done for display and not functionally.
  This check applies to Trusted Users' disowning of a package.

This style of notification flow does reduce our visibility, but
accounting can still be done via the close request; it includes
the action, pkgbase name and the user who accepted it.

Closes #204

Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-12-09 19:09:51 -08:00
Kevin Morris
bad57ba502
feat(exceptions): add InvariantError
This exception is to be used when a known invariant is violated.

Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-12-09 15:10:06 -08:00
Kevin Morris
85e6ad03db
feat(testing.email): add Email.dump
Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-12-09 15:10:04 -08:00
Kevin Morris
cf978e23aa
fix(python): use S argument to decide Suspended
Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-12-04 17:56:02 -08:00
Kevin Morris
8501bba0ac
change(python): rework session timing
Previously, we were just relying on the cookie expiration
for sessions to expire. We were not cleaning up Session
records either.

Rework timing to depend on an AURREMEMBER cookie which is
now emitted on login during BasicAuthBackend processing.

If the SID does still have a session but it's expired,
we now delete the session record before returning.

Otherwise, we update the session's LastUpdateTS to
the current time.

In addition, stored the unauthenticated result value
in a variable to reduce redundancy.

Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-12-04 02:16:22 -08:00
Kevin Morris
d0fc56d53f
fix(python): redirect when the request user can't edit target user
Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-12-04 00:14:55 -08:00
Kevin Morris
81f8c23265
fix(fastapi): log out IntegrityError from failed SID generation
Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-12-02 23:42:13 -08:00
Kevin Morris
806a19b91a
feat(fastapi): render a 500 html response when unique SID generation fails
We've seen a bug in the past where unique SID generation fails and
still ends up raising an exception.

This commit reworks how we deal with database exceptions internally,
tries for 36 iterations to set a fresh unique SID, and raises a 500
HTTPException if we were unable to.

Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-12-02 23:26:42 -08:00
Kevin Morris
abfd41f31e
change(fastapi): centralize HTTPException
Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-12-02 23:23:27 -08:00
Kevin Morris
0435c56a41
update test/README.md to be more aligned with the current state
Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-12-01 12:27:14 -08:00
Kevin Morris
112837e0e9
fix(test_auth): cover mismatched referer situation
Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-12-01 11:53:43 -08:00
Kevin Morris
043ac7fe92
fix(test_aurblup): use correct type hint for tmpdir
Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-12-01 00:33:31 -08:00
Kevin Morris
fccd8b63d2
housekeep(fastapi): rewrite test_auth_routes with fixtures
Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-12-01 00:33:30 -08:00
Kevin Morris
7ef3e34386
housekeep(fastapi): rewrite test_accounts_routes with fixtures
Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-12-01 00:33:30 -08:00
Kevin Morris
de0f919077
housekeep(fastapi): rewrite test_ban with fixtures
Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-12-01 00:33:30 -08:00
Kevin Morris
eb396813a8
housekeep(fastapi): rewrite test_package with fixtures
Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-12-01 00:33:29 -08:00
Kevin Morris
5b14ad4065
housekeep(fastapi): rewrite test_user with fixtures
Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-12-01 00:33:28 -08:00
Kevin Morris
140f9b1fb2
housekeep(fastapi): rewrite test_package_dependency with fixtures
Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-12-01 00:30:23 -08:00
Kevin Morris
05bd6e9076
housekeep(fastapi): rewrite test_package_vote with fixtures
Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-12-01 00:30:22 -08:00
Kevin Morris
150c944758
housekeep(fastapi): rewrite test_package_group with fixtures
Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-12-01 00:30:22 -08:00
Kevin Morris
df530d8a73
housekeep(fastapi): rewrite test_package_source with fixtures
Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-12-01 00:30:22 -08:00
Kevin Morris
171b347dad
housekeep(fastapi): rewrite test_package_base with fixtures
Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-12-01 00:30:21 -08:00
Kevin Morris
93bc91cce2
housekeep(fastapi): rewrite test_tu_voteinfo with fixtures
Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-12-01 00:30:21 -08:00