Skip to content

Commit

Permalink
Merge pull request #177 from BartoszCki/make-accept-invite-viewname-c…
Browse files Browse the repository at this point in the history
…onfigurable

Make accept-invite viewname configurable in django settings
  • Loading branch information
valberg authored Mar 31, 2022
2 parents ab0df00 + bd08874 commit ab92147
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 18 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions invitations/app_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,9 @@ 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_")
3 changes: 1 addition & 2 deletions invitations/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
8 changes: 5 additions & 3 deletions tests/allauth/test_allauth.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from invitations.app_settings import app_settings

try:
from django.urls import reverse
except ImportError:
Expand Down Expand Up @@ -37,7 +39,7 @@ def test_accept_invite_accepted_invitation_after_signup(
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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -126,7 +128,7 @@ def test_accept_invite_allauth(
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,
Expand Down
29 changes: 16 additions & 13 deletions tests/basic/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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},
)

Expand All @@ -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},
)

Expand All @@ -151,7 +151,10 @@ 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
Expand All @@ -166,7 +169,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
Expand All @@ -183,7 +186,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/"
Expand All @@ -199,7 +202,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,
Expand All @@ -224,7 +227,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,
Expand All @@ -248,7 +251,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,
Expand All @@ -274,7 +277,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,
Expand All @@ -293,7 +296,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,
Expand All @@ -307,7 +310,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,
Expand All @@ -328,7 +331,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("/")
Expand Down Expand Up @@ -358,7 +361,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,
Expand Down

0 comments on commit ab92147

Please sign in to comment.