Commit graph

2739 commits

Author SHA1 Message Date
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
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
Kevin Morris
e15a18e9fb
remove unneeded comment
Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-08-30 23:04:55 -07:00
Kevin Morris
718ae1acba
aurweb.templates: loader -> _loader, env -> _env
These are module local globals and we don't want to expose
global functionality to users, so privatize them with a
leading `_` prefix.

These things should **really** not be accessible by users.
2021-08-30 22:47:28 -07:00
Kevin Morris
55c29c4519
partials/packages/details.html: Add package request count
This was missed during the original implementation merge.

Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-08-30 18:58:03 -07:00
Kevin Morris
45fbf214b4
jinja2: add 'tn' filter, a numerical translation
The possibly plural version of `tr`, `tn` provides a way to translate
strings into singular or plural form based on a given integer
being 1 or not 1.

Example use:

```
{{ 1 | tn("%d package found.", "%d packages found.") | format(1) }}
```

Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-08-30 18:49:01 -07:00
Kevin Morris
1c26ce52a5
[FastAPI] include DepArch in dependency list
Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-08-30 18:48:53 -07:00
Kevin Morris
a0be018547
Docker: Reorder dependency installation for cache purposes
Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-08-28 21:32:20 -07:00
Hunter Wittenborn
eff7d478ab Updated CI tests for pip dependencies; Changed styling in install-deps.sh 2021-08-28 20:12:35 -05:00
Hunter Wittenborn
85b1a05d01 Removed pip dependencies from docker/scripts/install-deps.sh 2021-08-28 19:51:05 -05:00
Hunter Wittenborn
e61050adcf Added env/ to .gitignore
Folder will be used under virtualenv for pip dependencies
2021-08-28 19:31:11 -05:00
Hunter Wittenborn
e69004bc4a Alphabetized .gitignore file so it looks prettier 2021-08-28 19:29:44 -05:00
Hunter Wittenborn
0075ba3c33 Added .python-version from Pyenv 2021-08-28 19:27:36 -05:00
Hunter Wittenborn
b88fa8386a Removed pyalpm and srcinfo from pip requirements; Changed section title
Changed 'Generic' to 'General'
2021-08-28 19:25:51 -05:00
Hunter Wittenborn
fb908189b6 Began port of dependencies to pip
Adds Python dependencies to requirements list to allow installation via 
pip
2021-08-28 17:18:32 -05:00
Kevin Morris
f147ef3476
models.account_type: remove duplicated constants
Clearly made in mistake, removing to keep things organized.

Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-08-25 17:08:19 -07:00
Kevin Morris
a72ab61902
[FastAPI] fix dashboard template
Some columns should only be shown when a user is authenticated.

Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-08-25 16:57:19 -07:00
Kevin Morris
6eafb457ec
aurweb.util: fix code style violation
Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-08-25 16:36:55 -07:00
Kevin Morris
f086457741
aurweb.redis: Reduce logging
Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-08-17 21:59:15 -07:00
Kevin Morris
5a175bd92a
routers.html: add authenticated dashboard to homepage
Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-08-17 21:59:13 -07:00
Kevin Morris
af51b5c460
User: add several utility methods
Added:
- User.voted_for(package)
    - Has a user voted for a particular package?
- User.notified(package)
    - Is a user being notified about a particular package?
- User.packages()
    - Entire collection of Package objects related to User.

Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-08-17 21:59:11 -07:00
Kevin Morris
5bd3a7bbab
RequestType: add name_display() and record constants
Just like some of the other tables, we have some constant
records that we use to denote types of things. This commit
adds constants which correlate with these record constants.

Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-08-17 21:59:10 -07:00
Kevin Morris
eb8ea53a44
PackageRequest: add status_display()
A helper function which provides a textual string conversion
of a particular Status column.

In a PackageRequest, Status is split up into four different types:
- PENDING  : "Pending", PENDING_ID: 0
- CLOSED   : "Closed", CLOSED_ID: 1
- ACCEPTED : "Accepted", ACCEPTED_ID: 2
- REJECTED : "Rejected", REJECTED_ID: 3

This commit adds constants for the textual strings and the
IDs. It also adds a PackageRequest.status_display() function which
grabs the proper display string for a particular Status ID.

Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-08-17 21:59:08 -07:00
Kevin Morris
469c141f6b [FastAPI] bugfix: remove use of scalar() in plural context
Anything where we can have more than one of something, scalar()
cannot be used.

Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-08-17 20:59:38 -07:00
Kevin Morris
d9cdd5faef
[FastAPI] Modularize homepage and add side panel
This puts one more toward completion of the homepage
overall; we'll need to still implement the authenticated
user dashboard after this.

Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-08-17 19:58:32 -07:00
Kevin Morris
9e73936c4e
add aurweb.cache, a redis caching utility module
Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-08-17 19:58:31 -07:00
Kevin Morris
968ed736c1
add python-orjson dependency
python-orjson speeds up a lot of JSON serialization steps,
so we choose to use it over the standard library json module.

Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-08-17 19:58:29 -07:00
Kevin Morris
91e769f603
FastAPI: add redis integration
This includes the addition of the python-fakeredis package,
used for stubbing python-redis when a user does not have a
configured cache.

Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-08-17 19:58:28 -07:00
Kevin Morris
96d1af9363
docker-compose: add redis service
Now, the fastapi docker-compose service uses the new redis
service for a cache option.

Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-08-17 19:58:26 -07:00
Kevin Morris
35851d5533
Docker: add service 'memcached'
Additionally, setup memcached for php-fpm.

Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-08-16 22:09:09 -07:00