summaryrefslogtreecommitdiffstats
path: root/aurweb
AgeCommit message (Collapse)AuthorFilesLines
2021-05-02aurweb: Globalize a Translator instance, add more utilityKevin Morris2-123/+194
+ Added SUPPORTED_LANGUAGES, a global constant dictionary of language => display pairs for languages we support. + Add Translator.get_translator, a function used to retrieve a translator after initializing it (if needed). Use `fallback=True` while creating languages, in case we setup a language that we don't have a translation for, it will noop the translation. This is particularly useful for "en," since we do not translate it, but doing this will allow us to go through our normal translation flow in any case. + Added typing. + Added get_request_language, a function that grabs the language for a request session, defaulting to aurweb.config [options] default_lang. + Added get_raw_translator_for_request, a function that retrieves the concrete translation object for a given language. + Added tr, a jinja2 contextfilter that can be used to inline translate strings in jinja2 templates. + Added `python-jinja` dep to .gitlab-ci.yml. This needs to be included in documentation before this set is merged in. + Introduce pytest units (test_l10n.py) in `test` along with __init__.py, which marks `test` as a test package. + Additionally, fix up notify.py to use the global translator. Also reduce its source width to <= 80 by newlining some code. + Additionally, prepare locale in .gitlab-ci.yml and add aurweb.config [options] localedir to config.dev with YOUR_AUR_ROOT like others. Signed-off-by: Kevin Morris <kevr@0cost.org> Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
2021-04-27git update hook: gracefully error on completely broken .SRCINFOEli Schwartz1-1/+5
I've seen this happen a bunch of times now. Someone cannot push to the AUR, and the error report is some traceback with a KeyError which is difficult to understand without context: remote: Traceback (most recent call last): remote: File "/srv/http/aurweb/aur.git/hooks/update", line 33, in <module> remote: sys.exit(load_entry_point('aurweb==5.0.0', 'console_scripts', 'aurweb-git-update')()) remote: File "/usr/lib/python3.9/site-packages/aurweb-5.0.0-py3.9.egg/aurweb/git/update.py", line 306, in main remote: KeyError: 'pkgbase' Eventually it turns out that their .SRCINFO file is... badly corrupted. Generally, they managed to accidentally commit an *empty* file instead of a .SRCINFO, and in all cases, the problem was on the very first lookup for 'pkgbase'. Point people to the actual failing commit, and have a nicely formatted message indicating that the .SRCINFO is completely invalid. Signed-off-by: Eli Schwartz <eschwartz@archlinux.org>
2021-02-20add test_popupdate.pyKevin Morris2-1/+3
We had no coverage over aurweb.scripts.popupdate. This test covers all of its functionality. Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-02-20swap uvicorn out for hypercornKevin Morris1-3/+2
Signed-off-by: Kevin Morris <kevr@0cost.org> Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
2021-02-20spawn: expand AUR_CONFIG to the full pathFilipe Laíns1-0/+4
This allows using a relative path for the config. PHP didn't play well with it. Signed-off-by: Filipe Laíns <lains@archlinux.org> Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
2021-02-20Redirect to referer after SSO loginFrédéric Mangano-Tarumi1-6/+17
Introduce a `redirect` query argument to SSO login endpoints so that users are redirected to the page they were originally on when they clicked the Login link. Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
2021-02-20Remove the per-user session limitFrédéric Mangano-Tarumi1-1/+1
This feature was originally introduced by f961ffd9c7f2d3d51d3e3b060990a4fef9e56c1b as a fix for FS#12898 <https://bugs.archlinux.org/task/12898>. As of today, it is broken because of the `q.SessionID IS NULL` condition in the WHERE clause, which can’t be true because SessionID is not nullable. As a consequence, the session limit was not applied. The fact the absence of the session limit hasn’t caused any issue so far, and hadn’t even been noticed, suggests the feature is unneeded. Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
2021-02-20Guard OAuth exceptions to provide better messagesFrédéric Mangano-Tarumi1-3/+13
Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
2021-02-20HTML error pages for FastAPIFrédéric Mangano-Tarumi1-1/+15
Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
2021-02-20Update last login information on SSO loginFrédéric Mangano-Tarumi1-1/+7
Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
2021-02-20aurweb.spawn: Support stdout redirections to non-ttyFrédéric Mangano-Tarumi1-1/+5
Only ttys have a terminal size. If we can’t obtain it, we’ll just use 80 as a sane default. Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
2021-02-20Exclude suspended Users from being notifiedKevin Morris1-10/+18
The existing notify.py script was grabbing entries regardless of user suspension. This has been modified to only send notifications to unsuspended users. This change was written as a solution to https://bugs.archlinux.org/task/65554. Signed-off-by: Kevin Morris <kevr.gtalk@gmail.com> Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
2021-02-20Build a translation facility for FastAPIFrédéric Mangano-Tarumi2-9/+33
Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
2021-02-20SSO: Port account suspensionFrédéric Mangano-Tarumi1-1/+10
Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
2021-02-20SSO: Port IP ban checkingFrédéric Mangano-Tarumi1-2/+17
Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
2021-02-20Save id_token for the SSO logoutFrédéric Mangano-Tarumi1-4/+15
As far as I can see, Keycloak ignores it entirely. I can login in as SSO user A, then disconnect from the SSO directly and reconnect as user B, but when I disconnect user A from AUR, Keycloak disconnects B even though AUR passed it an ID token for A. Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
2021-02-20Implement SSO logoutFrédéric Mangano-Tarumi1-0/+18
Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
2021-02-20SSO: Explain the rationale behind prompt=loginFrédéric Mangano-Tarumi1-0/+7
We might reconsider it in the future. Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
2021-02-20Open AUR sessions from SSOFrédéric Mangano-Tarumi1-2/+49
Only the core functionality is implemented here. See the TODOs. Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
2021-02-20Integrate SQLAlchemy into FastAPIFrédéric Mangano-Tarumi1-0/+30
Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
2021-02-20Add SSO account ID in table UsersFrédéric Mangano-Tarumi1-0/+1
This column holds a user ID issed by the single sign-on provider. For Keycloak, it is an UUID. For more flexibility, we will be using a standardly-sized VARCHAR field. Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
2021-02-20aurweb.l10n: Translate without side effectsFrédéric Mangano-Tarumi1-2/+1
The install method in Python’s gettext API aliases the translator’s gettext method to an application-global _(). We don’t use that anywhere, and it’s clear from aurweb’s Translator interface that we want to translate a piece of text without affecting any global namespace. Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
2021-02-20Crude OpenID Connect client using AuthlibFrédéric Mangano-Tarumi4-0/+51
Developers can go to /sso/login to get redirected to the SSO. On successful login, the ID token is displayed. Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
2021-02-20aurweb.spawn: Fix isort errorsFrédéric Mangano-Tarumi1-2/+1
Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
2021-02-20Remove the FastAPI /hello test routeFrédéric Mangano-Tarumi2-8/+0
Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
2021-02-20aurweb.spawn: Integrate FastAPI and nginxFrédéric Mangano-Tarumi2-12/+76
aurweb.spawn used to launch only PHP’s built-in server. Now it spawns a dummy FastAPI application too. Since both stacks spawn their own HTTP server, aurweb.spawn also spawns nginx as a reverse proxy to mount them under the same base URL, defined by aur_location in the configuration. Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
2021-02-20Refactor code to comply with flake8 and isortFilipe Laíns8-22/+23
Signed-off-by: Filipe Laíns <lains@archlinux.org> Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
2021-02-20Create aurweb.spawn for spawing the test serverFrédéric Mangano-Tarumi1-0/+107
This program makes it easier for developers to spawn the PHP server since it fetches automatically what it needs from the configuration file, rather than having the user explicitly pass arguments to the php executable. When the setup gets more complicated as we introduce Python, aurweb.spawn will keep providing the same interface, while under the hood it is planned to support running multiple sub-processes. Its Python interface provides an way for the test suite to spawn the test server when it needs to perform HTTP requests to the test server. The current implementation is somewhat weak as it doesn’t detect when a child process dies, but this is not supposed to happen often, and it is only meant for aurweb developers. In the long term, aurweb.spawn will eventually become obsolete, and replaced by Docker or Flask’s tools. Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
2020-10-14Fix requests not being sent to the Cc recipientsFrederik Schwan1-1/+1
Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
2020-08-27Deliver emails to Cc in smtplib code pathLukas Fleischer1-6/+12
When using the sendmail() function with smtplib.SMTP or smtplib.SMTP_SSL, the list of actual recipients for the email (to be translated to RCPT commands) has to be provided as a parameter. Update the notification script and add all Cc recipients to that parameter. Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
2020-08-26Call sendmail with to, not recipientJelle van der Waa1-1/+1
After f7a57c8 (Localize notification emails, 2018-05-17), the server.sendmail line was not updated to now send the to the email address but instead sends to (email, 'en') and as sendmail accepts an iterable an email is also send to 'en'. Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
2020-03-22Map BIGINT to INTEGER for SQLiteFrédéric Mangano-Tarumi1-0/+11
Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
2020-02-27Disable Alembic support on test databasesFrédéric Mangano-Tarumi1-3/+9
Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
2020-02-27Set up Alembic for database migrationsFrédéric Mangano-Tarumi2-0/+17
Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
2020-02-27Migrate the database schema to SQLAlchemyFrédéric Mangano-Tarumi3-0/+461
The new schema was generated with sqlacodegen and then manually adjusted to fit schema/aur-schema.sql faithfully, both in the organisation of the code and in the SQL generated by SQLAlchemy. Initializing the database now requires the new tool aurweb.initdb. References to aur-schema.sql have been updated and the old schema dropped. Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
2020-02-11Make SMTP port and authentication configurableLukas Fleischer1-1/+19
Add more options to configure the smtplib implementation for sending notification emails. The port can be changed using the new smtp-port option. Encryption can be configured using smtp-use-ssl and smtp-use-starttls. Keep in mind that you usually also need to change the port when enabling either of these options. Authentication can be configured using smtp-user and smtp-password. Authentication is disabled if either of these values is empty. Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
2020-02-11Support smtplib for sending emailsLukas Fleischer1-4/+18
Support mail delivery without a local MTA. Instead, an SMTP server can now be configured using the smtp-server option in the [notifications] section. In order to use this option, the value of the sendmail option must be empty. Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
2020-02-02rendercomment: use python-markdown's new registration APIFrédéric Mangano-Tarumi1-4/+6
First, this gets rid of the deprecation warnings Python displayed. Second, this fixes the case where a link contained a pair of underscores, which used to be interpreted as an emphasis because the linkify processor ran after the emphasis processor. Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
2020-02-02rendercomment: safer Flyspray task linkificationFrédéric Mangano-Tarumi1-7/+14
When an FS#123 is part of a code block, it must not be converted into a link. FS#123 may also appear inside an URL, in which case regular linkifaction of URLs must take precedence. Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
2020-02-02rendercomment: safer auto-linkification of URLsFrédéric Mangano-Tarumi1-8/+11
Fixes a few edge cases: - URLs within code blocks used to get redundant <> added, breaking bash code snippets like `curl https://...` into `curl <https://...>`. - Links written with markdown's <https://...> syntax also used to get an extra pair of brackets. Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
2020-02-02rendercomment: respectful linkification of Git commitsFrédéric Mangano-Tarumi1-16/+20
Turn the git-commits markdown processor into an inline processor, which is smart enough not to convert Git hashes contained in code blocks or links. Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
2020-02-02Add support for backup email addressesLukas Fleischer1-4/+8
Support secondary email addresses that can be used to recover an account in case access to the primary email address is lost. Reset keys for an account are always sent to both the primary and the backup email address. Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
2020-01-30Keep signature delimiters intact in notificationsLukas Fleischer1-0/+3
Since commit eeaa1c3 (Separate text from footer in notification emails, 2020-01-04), information about unsubscribing from notifications is added in a signature block. However, the code to format the email body trimmed the RFC 3676 signature delimiter, replacing "-- " by "--". Fix this by adding a special case for signature delimiters. Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
2020-01-06Separate text from footer in notification emailsStephan Springer1-2/+3
Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
2019-11-23Store timestamp and user ID when closing requestsLukas Fleischer1-3/+7
Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
2019-11-23Don't require all Python database modules to be installedLukas Fleischer1-2/+9
We support multiple database backends. Don't require Python modules for all backends to be installed. Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
2019-11-23git-serve: check update hook permissionsLukas Fleischer2-0/+9
Verify that the update hook exists and is executable before running Git to prevent from broken repositories when permissions are broken. Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
2019-08-19notify.py: Use a/an correctly when sending request notificationsLars Rustand1-2/+3
Will no longer send notifications about "a orphan request", but determine whether to use a/an based on the first character of the request type. Signed-off-by: Lars Rustand <rustand.lars@gmail.com> Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
2019-04-28git-auth: deny login if no password has been setLukas Fleischer1-1/+2
After creating a new account, users need to verify their email address and set an initial password. Without setting a password, users cannot use their account on the web interface. However, when logging in via SSH, we did not check whether the account is verified. Fix this by only allowing SSH access once a password is set. Reported-by: Pat Hogan <pathtofile@gmail.com> Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
2019-02-08notify: add X-AUR-Reason header to allow conveniently filtering emailsEli Schwartz1-0/+4
Because filtering by matching the sender && regular expressions on the subject is awkward. Signed-off-by: Eli Schwartz <eschwartz@archlinux.org>