mirror of
https://github.com/ae-utbm/sith.git
synced 2025-06-06 11:15:20 +00:00
redirect /user/me/*
This commit is contained in:
parent
2fc51e9901
commit
9256aff944
@ -318,3 +318,20 @@ def test_displayed_other_user_tabs(user_factory, expected_tabs: list[str]):
|
||||
view.object = subscriber_user.make() # user whose page is being seen
|
||||
tabs = [tab["slug"] for tab in view.get_list_of_tabs()]
|
||||
assert tabs == expected_tabs
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
class TestRedirectMe:
|
||||
@pytest.mark.parametrize(
|
||||
"route", ["core:user_profile", "core:user_account", "core:user_edit"]
|
||||
)
|
||||
def test_redirect(self, client: Client, route: str):
|
||||
user = subscriber_user.make()
|
||||
client.force_login(user)
|
||||
target_url = reverse(route, kwargs={"user_id": user.id})
|
||||
src_url = target_url.replace(str(user.id), "me")
|
||||
assertRedirects(client.get(src_url), target_url)
|
||||
|
||||
def test_anonymous_user(self, client: Client):
|
||||
url = reverse("core:user_me_redirect")
|
||||
assertRedirects(client.get(url), reverse("core:login", query={"next": url}))
|
||||
|
@ -21,7 +21,6 @@
|
||||
# Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
#
|
||||
#
|
||||
|
||||
from django.urls import path, re_path, register_converter
|
||||
from django.views.generic import RedirectView
|
||||
|
||||
@ -68,6 +67,7 @@ from core.views import (
|
||||
UserGodfathersTreeView,
|
||||
UserGodfathersView,
|
||||
UserListView,
|
||||
UserMeRedirect,
|
||||
UserMiniView,
|
||||
UserPreferencesView,
|
||||
UserStatsView,
|
||||
@ -141,6 +141,12 @@ urlpatterns = [
|
||||
),
|
||||
# User views
|
||||
path("user/", UserListView.as_view(), name="user_list"),
|
||||
path(
|
||||
"user/me/<path:remaining_path>/",
|
||||
UserMeRedirect.as_view(),
|
||||
name="user_me_redirect_with_path",
|
||||
),
|
||||
path("user/me/", UserMeRedirect.as_view(), name="user_me_redirect"),
|
||||
path("user/<int:user_id>/mini/", UserMiniView.as_view(), name="user_profile_mini"),
|
||||
path("user/<int:user_id>/", UserView.as_view(), name="user_profile"),
|
||||
path(
|
||||
|
@ -48,6 +48,7 @@ from django.views.generic import (
|
||||
DeleteView,
|
||||
DetailView,
|
||||
ListView,
|
||||
RedirectView,
|
||||
TemplateView,
|
||||
)
|
||||
from django.views.generic.dates import MonthMixin, YearMixin
|
||||
@ -182,6 +183,13 @@ class UserCreationView(FormView):
|
||||
return super().form_valid(form)
|
||||
|
||||
|
||||
class UserMeRedirect(LoginRequiredMixin, RedirectView):
|
||||
def get_redirect_url(self, *args, **kwargs):
|
||||
if remaining := kwargs.get("remaining_path"):
|
||||
return f"/user/{self.request.user.id}/{remaining}/"
|
||||
return f"/user/{self.request.user.id}/"
|
||||
|
||||
|
||||
class UserTabsMixin(TabedViewMixin):
|
||||
def get_tabs_title(self):
|
||||
return self.object.get_display_name()
|
||||
|
Loading…
x
Reference in New Issue
Block a user