summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md1
-rw-r--r--python/fatcat_web/routes.py8
-rw-r--r--python/tests/web_editor.py8
3 files changed, 17 insertions, 0 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index c9ef0b22..c8636cca 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -35,6 +35,7 @@ command line tool to upgrade old dumps.
still actively publishing, discontinued, or "stub"
- above API schema changes added to elasticsearch 'release' and 'container' schemas
- editor "lookup" API endpoint, for fetching editor object by username
+- web `/u/{username}` redirect helper for inspecting editors, bots, etc
### Fixed
diff --git a/python/fatcat_web/routes.py b/python/fatcat_web/routes.py
index 41027710..e9741b6d 100644
--- a/python/fatcat_web/routes.py
+++ b/python/fatcat_web/routes.py
@@ -606,6 +606,14 @@ def editor_annotations(ident):
return render_template('editor_annotations.html', editor=editor,
annotations=annotations)
+@app.route('/u/<string:username>', methods=['GET', 'HEAD'])
+def editor_username_redirect(username):
+ try:
+ editor = api.lookup_editor(username=username)
+ except ApiException as ae:
+ abort(ae.status)
+ return redirect(f'/editor/{editor.editor_id}')
+
@app.route('/changelog', methods=['GET'])
def changelog_view():
try:
diff --git a/python/tests/web_editor.py b/python/tests/web_editor.py
index 58b21ddf..0d0679bb 100644
--- a/python/tests/web_editor.py
+++ b/python/tests/web_editor.py
@@ -22,3 +22,11 @@ def test_change_username(app_admin):
assert rv.status_code == 200
rv = app_admin.get('/auth/account')
assert b'admin-tmp' not in rv.data
+
+def test_username_redirect(app_admin):
+
+ rv = app_admin.get('/u/admin')
+ assert rv.status_code == 302
+
+ rv = app_admin.get('/u/bogus-not-registered')
+ assert rv.status_code == 404