diff --git a/core/static/user/user_godfathers.scss b/core/static/user/user_godfathers.scss index 7c69def7..d4cdd304 100644 --- a/core/static/user/user_godfathers.scss +++ b/core/static/user/user_godfathers.scss @@ -195,18 +195,18 @@ } } } + } - &.delete { - margin-top: 10px; - display: block; - text-align: center; - color: orangered; + form .link-like { + margin-top: 10px; + display: block; + text-align: center; + color: orangered; - @media (max-width: 375px) { - position: absolute; - bottom: 0; - right: 0; - } + @media (max-width: 375px) { + position: absolute; + bottom: 0; + right: 0; } } } diff --git a/core/templates/core/macros.jinja b/core/templates/core/macros.jinja index 78eb756b..42180a15 100644 --- a/core/templates/core/macros.jinja +++ b/core/templates/core/macros.jinja @@ -78,12 +78,6 @@ {% endif %} {% endmacro %} -{% macro delete_godfather(user, profile, godfather, is_father) %} - {% if user == profile or user.is_root or user.is_board_member %} - {% trans %}Delete{% endtrans %} - {% endif %} -{% endmacro %} - {% macro paginate_alpine(page, nb_pages) %} {# Add pagination buttons for ajax based content with alpine diff --git a/core/templates/core/password_change.jinja b/core/templates/core/password_change.jinja index 7cd27b1e..a90fd39b 100644 --- a/core/templates/core/password_change.jinja +++ b/core/templates/core/password_change.jinja @@ -3,7 +3,7 @@ {% block content %} {% if target %} -
{% trans user=target.get_display_name() %}Change password for {{ user }}{% endtrans %}
+{% trans user=form.user.get_display_name() %}Change password for {{ user }}{% endtrans %}
{% endif %} + {% endif %} {% endfor %} @@ -46,7 +55,16 @@ {{ u.get_mini_item()|safe }} - {{ delete_godfather(user, profile, u, False) }} + {% if user == profile or user.is_root or user.is_board_member %} + + {% endif %} {% endfor %} diff --git a/core/tests/test_user.py b/core/tests/test_user.py index 62a05e1b..edd6a54b 100644 --- a/core/tests/test_user.py +++ b/core/tests/test_user.py @@ -427,6 +427,19 @@ class TestUserQuerySetViewableBy: assert not viewable.exists() +@pytest.mark.django_db +def test_user_preferences(client: Client): + user = subscriber_user.make() + client.force_login(user) + url = reverse("core:user_prefs", kwargs={"user_id": user.id}) + response = client.get(url) + assert response.status_code == 200 + response = client.post(url, {"notify_on_click": "true"}) + assertRedirects(response, url) + user.preferences.refresh_from_db() + assert user.preferences.notify_on_click is True + + @pytest.mark.django_db def test_user_stats(client: Client): user = subscriber_user.make() @@ -450,3 +463,68 @@ def test_user_stats(client: Client): client.force_login(user) response = client.get(reverse("core:user_stats", kwargs={"user_id": user.id})) assert response.status_code == 200 + + +@pytest.mark.django_db +class TestChangeUserPassword: + def test_as_root(self, client: Client, admin_user: User): + client.force_login(admin_user) + user = subscriber_user.make() + url = reverse("core:password_root_change", kwargs={"user_id": user.id}) + response = client.get(url) + assert response.status_code == 200 + response = client.post( + url, {"new_password1": "poutou", "new_password2": "poutou"} + ) + assertRedirects(response, reverse("core:password_change_done")) + user.refresh_from_db() + assert user.check_password("poutou") is True + + +@pytest.mark.django_db +class TestUserGodfather: + @pytest.mark.parametrize("godfather", [True, False]) + def test_add_family(self, client: Client, godfather): + user = subscriber_user.make() + other_user = subscriber_user.make() + client.force_login(user) + url = reverse("core:user_godfathers", kwargs={"user_id": user.id}) + response = client.get(url) + assert response.status_code == 200 + response = client.post( + url, + {"type": "godfather" if godfather else "godchild", "user": other_user.id}, + ) + assertRedirects(response, url) + if godfather: + assert user.godfathers.contains(other_user) + else: + assert user.godchildren.contains(other_user) + + def test_tree(self, client: Client): + user = subscriber_user.make() + client.force_login(user) + response = client.get( + reverse("core:user_godfathers_tree", kwargs={"user_id": user.id}) + ) + assert response.status_code == 200 + + def test_remove_family(self, client: Client): + user = subscriber_user.make() + other_user = subscriber_user.make() + user.godfathers.add(other_user) + client.force_login(user) + response = client.post( + reverse( + "core:user_godfathers_delete", + kwargs={ + "user_id": user.id, + "godfather_id": other_user.id, + "is_father": True, + }, + ) + ) + assertRedirects( + response, reverse("core:user_godfathers", kwargs={"user_id": user.id}) + ) + assert not user.godfathers.contains(other_user) diff --git a/core/urls.py b/core/urls.py index 0695e009..71f76261 100644 --- a/core/urls.py +++ b/core/urls.py @@ -54,6 +54,7 @@ from core.views import ( PagePropView, PageRevView, PageView, + PasswordRootChangeView, SearchView, SithLoginView, SithPasswordChangeDoneView, @@ -80,7 +81,6 @@ from core.views import ( delete_user_godfather, logout, notification, - password_root_change, send_file, ) @@ -100,7 +100,7 @@ urlpatterns = [ path("password_change/", SithPasswordChangeView.as_view(), name="password_change"), path( "password_change/