From 5087f1e801611cae46e959cc6c515c9352181fd0 Mon Sep 17 00:00:00 2001 From: Bartosz Cierocki Date: Thu, 31 Mar 2022 10:55:10 +0200 Subject: [PATCH 1/4] Make accept-invite viewname configurable in django settings --- invitations/app_settings.py | 7 +++++++ invitations/models.py | 3 +-- tests/allauth/test_allauth.py | 12 +++++++----- tests/basic/tests.py | 26 +++++++++++++------------- 4 files changed, 28 insertions(+), 20 deletions(-) diff --git a/invitations/app_settings.py b/invitations/app_settings.py index 25e47a6..806ae54 100644 --- a/invitations/app_settings.py +++ b/invitations/app_settings.py @@ -97,5 +97,12 @@ def ADMIN_CHANGE_FORM(self): "invitations.forms.InvitationAdminChangeForm", ) + @property + def CONFIRMATION_URL_NAME(self): + return self._setting( + "CONFIRMATION_URL_NAME", + "invitations:accept-invite" + ) + app_settings = AppSettings("INVITATIONS_") diff --git a/invitations/models.py b/invitations/models.py index 053b1c1..96539b5 100644 --- a/invitations/models.py +++ b/invitations/models.py @@ -43,8 +43,7 @@ def key_expired(self): def send_invitation(self, request, **kwargs): current_site = get_current_site(request) - invite_url = reverse("invitations:accept-invite", args=[self.key]) - + invite_url = reverse(app_settings.CONFIRMATION_URL_NAME, args=[self.key]) invite_url = request.build_absolute_uri(invite_url) ctx = kwargs ctx.update( diff --git a/tests/allauth/test_allauth.py b/tests/allauth/test_allauth.py index 193ba74..7089779 100644 --- a/tests/allauth/test_allauth.py +++ b/tests/allauth/test_allauth.py @@ -1,3 +1,5 @@ +from invitations.app_settings import app_settings + try: from django.urls import reverse except ImportError: @@ -37,8 +39,8 @@ def test_accept_invite_accepted_invitation_after_signup( client_with_method = getattr(self.client, method) resp = client_with_method( reverse( - "invitations:accept-invite", - kwargs={"key": sent_invitation_by_user_a.key}, + app_settings.CONFIRMATION_URL_NAME, + kwargs={"key": sent_invitation_by_user_a.key} ), follow=True, ) @@ -81,7 +83,7 @@ def test_invite_accepted_after_signup_with_altered_case_email( client_with_method = getattr(self.client, method) resp = client_with_method( reverse( - "invitations:accept-invite", + app_settings.CONFIRMATION_URL_NAME, kwargs={"key": sent_invitation_by_user_a.key}, ), follow=True, @@ -126,8 +128,8 @@ def test_accept_invite_allauth( client_with_method = getattr(self.client, method) resp = client_with_method( reverse( - "invitations:accept-invite", - kwargs={"key": sent_invitation_by_user_a.key}, + app_settings.CONFIRMATION_URL_NAME, + kwargs={"key": sent_invitation_by_user_a.key} ), follow=True, ) diff --git a/tests/basic/tests.py b/tests/basic/tests.py index 57b5cd5..bb4363e 100644 --- a/tests/basic/tests.py +++ b/tests/basic/tests.py @@ -114,7 +114,7 @@ def test_valid_form_submission(self, user_a): "url", ) assert url == reverse( - "invitations:accept-invite", + app_settings.CONFIRMATION_URL_NAME, kwargs={"key": invitation.key}, ) @@ -139,7 +139,7 @@ def test_valid_form_submission_with_swapped_model(self, user_a): "url", ) assert url == reverse( - "invitations:accept-invite", + app_settings.CONFIRMATION_URL_NAME, kwargs={"key": invitation.key}, ) @@ -151,7 +151,7 @@ class TestInvitationsAcceptView: def test_accept_invite_get_is_404(self, settings, invitation_b): settings.INVITATIONS_CONFIRM_INVITE_ON_GET = False resp = self.client.get( - reverse("invitations:accept-invite", kwargs={"key": invitation_b.key}), + reverse(app_settings.CONFIRMATION_URL_NAME, kwargs={"key": invitation_b.key}), follow=True, ) assert resp.status_code == 404 @@ -166,7 +166,7 @@ def test_accept_invite_get_is_404(self, settings, invitation_b): def test_accept_invite_invalid_key(self, method): client_with_method = getattr(self.client, method) resp = client_with_method( - reverse("invitations:accept-invite", kwargs={"key": "invalidKey"}), + reverse(app_settings.CONFIRMATION_URL_NAME, kwargs={"key": "invalidKey"}), follow=True, ) assert resp.status_code == 410 @@ -183,7 +183,7 @@ def test_accept_invite_invalid_key_error_disabled(self, settings, method): settings.INVITATIONS_LOGIN_REDIRECT = "/login-url/" client_with_method = getattr(self.client, method) resp = client_with_method( - reverse("invitations:accept-invite", kwargs={"key": "invalidKey"}), + reverse(app_settings.CONFIRMATION_URL_NAME, kwargs={"key": "invalidKey"}), follow=True, ) assert resp.request["PATH_INFO"] == "/login-url/" @@ -199,7 +199,7 @@ def test_accept_invite_accepted_key(self, accepted_invitation, method): client_with_method = getattr(self.client, method) resp = client_with_method( reverse( - "invitations:accept-invite", + app_settings.CONFIRMATION_URL_NAME, kwargs={"key": accepted_invitation.key}, ), follow=True, @@ -224,7 +224,7 @@ def test_accept_invite_accepted_key_error_disabled( client_with_method = getattr(self.client, method) resp = client_with_method( reverse( - "invitations:accept-invite", + app_settings.CONFIRMATION_URL_NAME, kwargs={"key": accepted_invitation.key}, ), follow=True, @@ -248,7 +248,7 @@ def test_accept_invite_expired_key( client_with_method = getattr(self.client, method) resp = client_with_method( reverse( - "invitations:accept-invite", + app_settings.CONFIRMATION_URL_NAME, kwargs={"key": sent_invitation_by_user_a.key}, ), follow=True, @@ -274,7 +274,7 @@ def test_accept_invite_expired_key_error_disabled( client_with_method = getattr(self.client, method) resp = client_with_method( reverse( - "invitations:accept-invite", + app_settings.CONFIRMATION_URL_NAME, kwargs={"key": sent_invitation_by_user_a.key}, ), follow=True, @@ -293,7 +293,7 @@ def test_accept_invite(self, settings, sent_invitation_by_user_a, user_a, method client_with_method = getattr(self.client, method) resp = client_with_method( reverse( - "invitations:accept-invite", + app_settings.CONFIRMATION_URL_NAME, kwargs={"key": sent_invitation_by_user_a.key}, ), follow=True, @@ -307,7 +307,7 @@ def test_signup_redirect(self, settings, sent_invitation_by_user_a): settings.INVITATIONS_SIGNUP_REDIRECT = "/non-existent-url/" resp = self.client.post( reverse( - "invitations:accept-invite", + app_settings.CONFIRMATION_URL_NAME, kwargs={"key": sent_invitation_by_user_a.key}, ), follow=True, @@ -328,7 +328,7 @@ def test_invite_url_sent_triggered_correctly( user_a, ): invite_url = reverse( - "invitations:accept-invite", + app_settings.CONFIRMATION_URL_NAME, args=[sent_invitation_by_user_a.key], ) request = RequestFactory().get("/") @@ -358,7 +358,7 @@ def test_invite_invite_accepted_triggered_correctly( self.client.post( reverse( - "invitations:accept-invite", + app_settings.CONFIRMATION_URL_NAME, kwargs={"key": sent_invitation_by_user_a.key}, ), follow=True, From 2bfa96ad470d99305839fbd9f81b6ed448ef966f Mon Sep 17 00:00:00 2001 From: Bartosz Cierocki Date: Thu, 31 Mar 2022 11:18:29 +0200 Subject: [PATCH 2/4] Update README --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index cb39362..87c1e4b 100644 --- a/README.md +++ b/README.md @@ -175,6 +175,10 @@ Bulk invites are supported via JSON. Post a list of comma separated emails to t App registry path of the invitation model used in the current project, for customization purposes. +* `CONFIRMATION_URL_NAME` (default=`invitations:accept-invite`) + + String. Invitation confirmation URL + ### Signals The following signals are emitted: From 040312f33384c32a52187445623e13bbd1023aa1 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 31 Mar 2022 09:21:10 +0000 Subject: [PATCH 3/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- invitations/app_settings.py | 5 +---- tests/allauth/test_allauth.py | 4 ++-- tests/basic/tests.py | 4 +++- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/invitations/app_settings.py b/invitations/app_settings.py index 806ae54..c3737f0 100644 --- a/invitations/app_settings.py +++ b/invitations/app_settings.py @@ -99,10 +99,7 @@ def ADMIN_CHANGE_FORM(self): @property def CONFIRMATION_URL_NAME(self): - return self._setting( - "CONFIRMATION_URL_NAME", - "invitations:accept-invite" - ) + return self._setting("CONFIRMATION_URL_NAME", "invitations:accept-invite") app_settings = AppSettings("INVITATIONS_") diff --git a/tests/allauth/test_allauth.py b/tests/allauth/test_allauth.py index 7089779..103f1f2 100644 --- a/tests/allauth/test_allauth.py +++ b/tests/allauth/test_allauth.py @@ -40,7 +40,7 @@ def test_accept_invite_accepted_invitation_after_signup( resp = client_with_method( reverse( app_settings.CONFIRMATION_URL_NAME, - kwargs={"key": sent_invitation_by_user_a.key} + kwargs={"key": sent_invitation_by_user_a.key}, ), follow=True, ) @@ -129,7 +129,7 @@ def test_accept_invite_allauth( resp = client_with_method( reverse( app_settings.CONFIRMATION_URL_NAME, - kwargs={"key": sent_invitation_by_user_a.key} + kwargs={"key": sent_invitation_by_user_a.key}, ), follow=True, ) diff --git a/tests/basic/tests.py b/tests/basic/tests.py index bb4363e..d720047 100644 --- a/tests/basic/tests.py +++ b/tests/basic/tests.py @@ -151,7 +151,9 @@ class TestInvitationsAcceptView: def test_accept_invite_get_is_404(self, settings, invitation_b): settings.INVITATIONS_CONFIRM_INVITE_ON_GET = False resp = self.client.get( - reverse(app_settings.CONFIRMATION_URL_NAME, kwargs={"key": invitation_b.key}), + reverse( + app_settings.CONFIRMATION_URL_NAME, kwargs={"key": invitation_b.key}, + ), follow=True, ) assert resp.status_code == 404 From bd088740358346ec66d4d714b47db11bce73138e Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 31 Mar 2022 09:22:32 +0000 Subject: [PATCH 4/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/basic/tests.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/basic/tests.py b/tests/basic/tests.py index d720047..d0f9fd3 100644 --- a/tests/basic/tests.py +++ b/tests/basic/tests.py @@ -152,7 +152,8 @@ def test_accept_invite_get_is_404(self, settings, invitation_b): settings.INVITATIONS_CONFIRM_INVITE_ON_GET = False resp = self.client.get( reverse( - app_settings.CONFIRMATION_URL_NAME, kwargs={"key": invitation_b.key}, + app_settings.CONFIRMATION_URL_NAME, + kwargs={"key": invitation_b.key}, ), follow=True, )