Commit graph

2749 commits

Author SHA1 Message Date
Kevin Morris
2a47aa09cd Merge branch 'pu_php_extra_2' into pu 2021-06-29 10:15:21 -07:00
Leonidas Spyropoulos
c3a29171cd [php] aurweb.spawn avoid permission denied when running as user
Signed-off-by: Leonidas Spyropoulos <artafinde@gmail.com>
2021-06-29 18:02:20 +01:00
Leonidas Spyropoulos
2f5d9c63c4 [php] Support DB mysql backend with port instead of socket
Signed-off-by: Leonidas Spyropoulos <artafinde@gmail.com>
2021-06-29 17:59:46 +01:00
Kevin Morris
dbbafc15fa bugfix: PackageKeyword should have two PKs
Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-06-28 12:44:55 -07:00
Kevin Morris
719fa82ae5 Merge branch 'pu_package' into pu 2021-06-28 09:56:05 -07:00
Kevin Morris
7d695f0c6a Update .gitignore
Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-06-28 09:53:05 -07:00
Kevin Morris
f8d2d4c82a PackageBase.package -> PackageBase.packages
A PackageBase can have more than one package
associated with it.

Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-06-28 08:31:13 -07:00
Kevin Morris
3c6b2203e9 Docker: bugfix: /usr/local/bin instead of /aurweb/app/bin
Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-06-28 05:36:12 -07:00
Kevin Morris
28300ee889 bugfix: populate context on invalid password (account edit)
Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-06-28 04:12:29 -07:00
Kevin Morris
a26e703343 bugfix: use empty string if backup_email is None
Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-06-28 04:04:52 -07:00
Kevin Morris
987f825714 Merge branch 'account_form' into pu 2021-06-27 09:09:42 -07:00
Jelle van der Waa
222d995e95
Use backup_email field for backup email
The context gives backup_email and not backup for the backup email
field.

Fixes: #91
2021-06-27 17:29:44 +02:00
Jelle van der Waa
b2491ddc07
Use type=email for email fields
Setting the input type gives the use a hint that the field should be an
email and also shows an error when a non-email is filled into the email
field.
2021-06-27 17:25:46 +02:00
Kevin Morris
acc100eb52 Docker: Fix installation, remove pip, simplify sshd
Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-06-27 06:37:06 -07:00
Jelle van der Waa
12911a101e
Port homepage intro to fastapi
Port the main home page content to fastapi.
2021-06-27 15:17:04 +02:00
Kevin Morris
0a3aa40f20 Docker: Fix git sshd
This was completely bugged out. This commit fixes git, provides
two separate cgit servers for the different URL bases and also
supplies a smartgit service for $AURWEB_URL/repo.git interaction.

Docker image needs to be rebuilt with this change:

    $ docker build -t aurweb:latest .

Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-06-27 05:16:12 -07:00
Kevin Morris
83f93c8dbb aurweb.routers.accounts: strip host out of ssh pubkeys
We must store the paired key, otherwise aurweb-git-auth
will fail.

Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-06-27 03:54:13 -07:00
Kevin Morris
97c1247b57 /tu/{proposal_id}: Do not show voters if there are none
This was different than PHP.

Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-06-26 04:43:00 -07:00
Kevin Morris
04ab98907a aurweb.asgi: patch invalid f-string
Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-06-26 04:20:55 -07:00
Kevin Morris
bfffdd4d91 aurweb.asgi: Allow unsafe-inline style-src in CSP
Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-06-26 04:13:28 -07:00
Kevin Morris
85ba4a33a8 add /tu/{proposal_id} (get, post) routes
This commit ports the `/tu/?id={proposal_id}` PHP routes to
FastAPI into two individual GET and POST routes.

With this port of the single proposal view and POST logic,
several things have changed.

- The only parameter used is now `decision`, which
  must contain `Yes`, `No`, or `Abstain` as a string.
  When an invalid value is given, a BAD_REQUEST response
  is returned in plaintext: Invalid 'decision' value.
- The `doVote` parameter has been removed.
- The details section has been rearranged into a set
  of divs with specific classes that can be used for
  testing. CSS has been added to persist the layout with
  the element changes.
- Several errors that can be discovered in the POST path
  now trigger their own non-200 HTTPStatus codes.

Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-06-26 01:11:52 -07:00
Kevin Morris
83c038a42a add TUVoteInfo.total_votes()
Returns the sum of TUVoteInfo.Yes, TUVoteInfo.No and
TUVoteInfo.Abstain.

Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-06-26 01:11:52 -07:00
Kevin Morris
ac1779b705 add util.number_format -> number_format Jinja2 filter
Implement a `number_format` equivalent to PHP's version.

Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-06-26 01:11:52 -07:00
Kevin Morris
dc4cc9b604 add aurweb.asgi.id_redirect_middleware
A new middleware which redirects requests going to '/route?id=some_id'
to '/route/some_id'. In the FastAPI application, we'll prefer using
restful layouts where possible where resource-based ids are
parameters of the request uri: '/route/{resource_id}'.

Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-06-26 01:11:52 -07:00
Kevin Morris
e534704a98 [FastAPI] remove unused Requests navbar item
Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-06-26 01:10:20 -07:00
Kevin Morris
d674aaf736 add /tu/ (get) index
This commit implements the '/tu' Trusted User index page.

In addition to this functionality, this commit introduces
the following jinja2 filters:

- dt: util.timestamp_to_datetime
- as_timezone: util.as_timezone
- dedupe_qs: util.dedupe_qs
- urlencode: urllib.parse.quote_plus

There's also a new decorator that can be used to enforce
permissions: `account_type_required`. If a user does not
meet account type requirements, they are redirected to '/'.

```
@auth_required(True)
@account_type_required({"Trusted User"})
async def some_route(request: fastapi.Request):
    return Response("You are a Trusted User!")
```

Routes added:

- `GET /tu`: aurweb.routers.trusted_user.trusted_user

Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-06-26 01:03:27 -07:00
Kevin Morris
a6bba601a9 add util.get_vote -> get_vote Jinja2 filter
This filter gets a vote of a request's user toward a voteinfo.

Example: {% set vote = (voteinfo | get_vote(request)) %}

Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-06-26 01:03:27 -07:00
Kevin Morris
d606ebc0f1 add User.is_trusted_user() and User.is_developer()
Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-06-26 01:03:27 -07:00
Kevin Morris
ef4a7308ee add AccountType constants
New constants (in aurweb.models.account_type):

- USER: "User"
- USER_ID: USER's ID
- TRUSTED_USER: "Trusted User"
- TRUSTED_USER_ID: TRUSTED_USER's ID
- DEVELOPER: "Developer"
- DEVELOPER_ID: DEVELOPER's ID
- TRUSTED_USER_AND_DEV: "TRUSTED_USER_AND_DEV"
- TRUSTED_USER_AND_DEV_ID: TRUSTED_USER_AND_DEV's ID

Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-06-26 01:03:27 -07:00
Kevin Morris
4927a61378 add TUVoteInfo.is_running() method
Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-06-26 01:03:27 -07:00
Kevin Morris
07c4be0afb Docker: add .dockerignore
Currently, this ignores compiled translation files.

Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-06-26 00:42:20 -07:00
Kevin Morris
9ee7be4a1c Docker: remove web/locale from volume mounts
This caused a bug where generated locale would not be used.

Also, removed appending to /etc/hosts which was bugging out
on Mac OS X. archlinux:base-devel seems to come with a valid
/etc/hosts.

Additionally, remove AUR_CONFIG from Dockerfile. We don't
set it up; just use the defaults during installation.

Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-06-26 00:38:54 -07:00
Kevin Morris
ff3519ae11 [alembic] Log db name being used in a migration
Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-06-25 22:33:30 -07:00
Kevin Morris
cec07c76b6 User: use aurweb.config options.salt_rounds
Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-06-25 21:39:41 -07:00
Kevin Morris
d8556b0d86 config: add options.salt_rounds
During development, the lower this value is (must be >= 4)
equals faster User generation. This is particularly useful
for running tests.

In production, a higher value (like 12 which is used by various
popular frameworks) should be used.

Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-06-25 21:30:11 -07:00
Kevin Morris
a702f7bc0b Merge branch 'master' into pu 2021-06-25 19:03:29 -07:00
Kevin Morris
eb56305091 gendummydata: lower record counts
This commit halves MAX_USERS and MAX_PKGS, in addition
to setting OPEN_PROPOSALS to 15 and CLOSE_PROPOSALS to 50.

A few counts are now configurable via environment variable:

- MAX_USERS, default: 38000
- MAX_PKGS, default: 32000
- OPEN_PROPOSALS, default: 15
- CLOSE_PROPOSALS, default: 15

Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-06-25 18:26:40 -07:00
Kevin Morris
201a04ffb9 gendummydata: employ a salted hash for users
As of Python updates, we are no longer considering rows with
empty salts to be legacy hashes. Update gendummydata.py to
generate salts for the legacy passwords it uses with
salt rounds = 4.

Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-06-25 17:09:59 -07:00
Kevin Morris
d95e4ec443 Docker: create missing 'aurweb' DB if needed
Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-06-25 17:09:21 -07:00
Jelle van der Waa
c8d88464b1
Update mailing list address
https://lists.archlinux.org/pipermail/arch-dev-public/2021-June/030462.html
2021-06-25 17:25:24 +02:00
Jelle van der Waa
42bd0027b3
Add archweb typeahead implementation
Use a pure vanilla JavaScript typeahead implementation to finally
deprecate the old jQuery version and typeahead library.
2021-06-25 17:08:54 +02:00
Jelle van der Waa
512f8064c1
Fix JavaScript error on packages overview page 2021-06-25 17:08:47 +02:00
Kevin Morris
61c473405f Docker: add ./templates volume mount
Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-06-24 21:42:19 -07:00
Kevin Morris
df161ef38e Docker: add .env configurable FASTAPI_BACKEND
By default we now use uvicorn because it has a much
better developer feedback out of the box. We'll work
on hypercorn logging, but for now, hypercorn is usable
via: `docker-compose --env-file docker/hypercorn.env up nginx`.

Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-06-24 21:31:49 -07:00
Kevin Morris
495dd2d821 Docker: add missing git link to pytest-sqlite
Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-06-24 20:35:29 -07:00
Kevin Morris
565b928a59 Docker: mount codebase volumes
Before, docker build was the only way to transfer new code
over to the docker image. This allows users to execute code
in their working directory.

Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-06-24 20:33:02 -07:00
Kevin Morris
a36cc0c00a eradicate Term records after testing them
Otherwise, Terms can leak out into other tests causing /tos
redirects unexpectedly.

Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-06-24 19:52:17 -07:00
Kevin Morris
adb42882c5 [FastAPI] add /tos routes (get, post)
This clones the end goal behavior of PHP, but it does not
concern itself with the revision form array at all.

Since this page on PHP renders out the entire list of
terms that a user needs to accept, we can treat a
POST request with the "accept" checkbox enabled as a
request to accept all unaccepted (or outdated revision)
terms.

This commit also adds in a new http middleware used to
redirect authenticated users to '/tos' if they have not
yet accepted all terms.

Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-06-24 19:12:49 -07:00
Kevin Morris
e624e25c0f Docker: Add colored output to tests
Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-06-24 19:02:35 -07:00
Kevin Morris
2a3df086d3 Docker: add [c]git, nginx, fastapi, php-fpm, ca
Now, we have a full collection of services used to run
aurweb over HTTPS using a self-signed CA.

New Docker services:

- `ca` - Certificate authority services
    - When the `ca` service is run, it will (if needed) generate
      a CA certificate and leaf certificate for localhost AUR
      access. This ca is then shared with things like nginx to
      use the leaf certificate. Users can import
      `./cache/ca.root.pem` into their browser or ca-certificates
      as a root CA who issued aurweb's certificate.
- `git` - Start sshd and set it up for aur git access
- `cgit` - Serve cgit with uwsgi on port 3000
- `fastapi` - Serve our FastAPI app with `hypercorn` on port 8000
- `php-fpm` - Serve our PHP-wise aurweb
- `nginx` - Serve FastAPI, PHP and CGit with an HTTPS certificate.
    - PHP: https://localhost:8443
    - PHP CGit: https://localhost:8443/cgit
    - FastAPI: https://localhost:8444
    - FastAPI CGit: https://localhost:8444/cgit

Short of it: Run the following in a shell to run PHP and FastAPI
servers on port **8443** and **8444**, respectively.

    $ docker-compose up nginx

This will host the PHP, FastAPI, CGit and Git ecosystems.

Git SSH can be knocked at `aur@localhost:2222` as long as you have a
valid public key in the aurweb database.

Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-06-24 19:02:35 -07:00