From ff3021d1f3d093c5e51b9ded9e57f23aa28f4484 Mon Sep 17 00:00:00 2001 From: Joachim Date: Tue, 28 Dec 2021 21:40:01 +0100 Subject: [PATCH 1/5] Redirect /@ to /user/ --- bookwyrm/urls.py | 1 + bookwyrm/views/__init__.py | 2 +- bookwyrm/views/user.py | 5 +++++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/bookwyrm/urls.py b/bookwyrm/urls.py index 7220b545..1cc30092 100644 --- a/bookwyrm/urls.py +++ b/bookwyrm/urls.py @@ -276,6 +276,7 @@ urlpatterns = [ # users re_path(rf"{USER_PATH}\.json$", views.User.as_view()), re_path(rf"{USER_PATH}/?$", views.User.as_view(), name="user-feed"), + re_path(rf"@(?P{regex.USERNAME})$", views.user_redirect), re_path(rf"{USER_PATH}/rss/?$", views.rss_feed.RssFeed(), name="user-rss"), re_path( rf"{USER_PATH}/followers(.json)?/?$", diff --git a/bookwyrm/views/__init__.py b/bookwyrm/views/__init__.py index 8b1f5648..f77a3b50 100644 --- a/bookwyrm/views/__init__.py +++ b/bookwyrm/views/__init__.py @@ -94,7 +94,7 @@ from .search import Search from .status import CreateStatus, EditStatus, DeleteStatus, update_progress from .status import edit_readthrough from .updates import get_notification_count, get_unread_status_count -from .user import User, Followers, Following, hide_suggestions +from .user import User, Followers, Following, hide_suggestions, user_redirect from .wellknown import * from .annual_summary import ( AnnualSummary, diff --git a/bookwyrm/views/user.py b/bookwyrm/views/user.py index 188f8e66..92ab9737 100644 --- a/bookwyrm/views/user.py +++ b/bookwyrm/views/user.py @@ -151,3 +151,8 @@ def hide_suggestions(request): request.user.show_suggested_users = False request.user.save(broadcast=False, update_fields=["show_suggested_users"]) return redirect(request.headers.get("Referer", "/")) + + +def user_redirect(request, username): + """redirect to a user's feed""" + return redirect("user-feed", username=username) From 05142f4b73905eb5a187a6345c792611d9cd8c23 Mon Sep 17 00:00:00 2001 From: Joachim Date: Tue, 28 Dec 2021 21:49:41 +0100 Subject: [PATCH 2/5] Add test --- bookwyrm/tests/views/test_user.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/bookwyrm/tests/views/test_user.py b/bookwyrm/tests/views/test_user.py index 231ecec9..00131dd1 100644 --- a/bookwyrm/tests/views/test_user.py +++ b/bookwyrm/tests/views/test_user.py @@ -186,3 +186,12 @@ class UserViews(TestCase): self.local_user.refresh_from_db() self.assertFalse(self.local_user.show_suggested_users) + + + def test_user_redirect(self): + """test the basic redirect""" + request = self.factory.get("@mouse") + request.user = self.anonymous_user + result = views.user_redirect(request, "mouse") + + self.assertEqual(result.status_code, 302) From cae4934b48833b38c803414464d234f2b37c0f7d Mon Sep 17 00:00:00 2001 From: Joachim Date: Tue, 28 Dec 2021 21:49:52 +0100 Subject: [PATCH 3/5] Apply review suggestion --- bookwyrm/urls.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bookwyrm/urls.py b/bookwyrm/urls.py index 1cc30092..87c1e160 100644 --- a/bookwyrm/urls.py +++ b/bookwyrm/urls.py @@ -276,7 +276,7 @@ urlpatterns = [ # users re_path(rf"{USER_PATH}\.json$", views.User.as_view()), re_path(rf"{USER_PATH}/?$", views.User.as_view(), name="user-feed"), - re_path(rf"@(?P{regex.USERNAME})$", views.user_redirect), + re_path(rf"^@(?P{regex.USERNAME})$", views.user_redirect), re_path(rf"{USER_PATH}/rss/?$", views.rss_feed.RssFeed(), name="user-rss"), re_path( rf"{USER_PATH}/followers(.json)?/?$", From 5284e7009dd307487866426d4b0a3ad8c28f9396 Mon Sep 17 00:00:00 2001 From: Joachim Date: Tue, 28 Dec 2021 21:51:45 +0100 Subject: [PATCH 4/5] fix pylint remark --- bookwyrm/views/user.py | 1 + 1 file changed, 1 insertion(+) diff --git a/bookwyrm/views/user.py b/bookwyrm/views/user.py index 92ab9737..9deea14b 100644 --- a/bookwyrm/views/user.py +++ b/bookwyrm/views/user.py @@ -153,6 +153,7 @@ def hide_suggestions(request): return redirect(request.headers.get("Referer", "/")) +# pylint: disable=unused-argument def user_redirect(request, username): """redirect to a user's feed""" return redirect("user-feed", username=username) From 17cb936a16c3f65114ebc6c9ddde392a892ef300 Mon Sep 17 00:00:00 2001 From: Joachim Date: Tue, 28 Dec 2021 21:54:06 +0100 Subject: [PATCH 5/5] Update test_user.py --- bookwyrm/tests/views/test_user.py | 1 - 1 file changed, 1 deletion(-) diff --git a/bookwyrm/tests/views/test_user.py b/bookwyrm/tests/views/test_user.py index 00131dd1..5fab9386 100644 --- a/bookwyrm/tests/views/test_user.py +++ b/bookwyrm/tests/views/test_user.py @@ -187,7 +187,6 @@ class UserViews(TestCase): self.local_user.refresh_from_db() self.assertFalse(self.local_user.show_suggested_users) - def test_user_redirect(self): """test the basic redirect""" request = self.factory.get("@mouse")