Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow subclassing InvitationsAdapter #255

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions invitations/adapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,7 @@ def add_message(

def get_invitations_adapter():
# Compatibility with legacy allauth only version.
LEGACY_ALLAUTH = (
hasattr(settings, "ACCOUNT_ADAPTER")
and settings.ACCOUNT_ADAPTER == "invitations.models.InvitationsAdapter"
)
LEGACY_ALLAUTH = hasattr(settings, "ACCOUNT_ADAPTER")
if LEGACY_ALLAUTH:
# defer to allauth
from allauth.account.adapter import get_adapter
Expand Down
37 changes: 18 additions & 19 deletions invitations/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,22 +75,21 @@ def __str__(self):

# here for backwards compatibility, historic allauth adapter
if hasattr(settings, "ACCOUNT_ADAPTER"):
if settings.ACCOUNT_ADAPTER == "invitations.models.InvitationsAdapter":
from allauth.account.adapter import DefaultAccountAdapter
from allauth.account.signals import user_signed_up

class InvitationsAdapter(DefaultAccountAdapter):
def is_open_for_signup(self, request):
if hasattr(request, "session") and request.session.get(
"account_verified_email",
):
return True
elif app_settings.INVITATION_ONLY is True:
# Site is ONLY open for invites
return False
else:
# Site is open to signup
return True

def get_user_signed_up_signal(self):
return user_signed_up
from allauth.account.adapter import DefaultAccountAdapter
from allauth.account.signals import user_signed_up

class InvitationsAdapter(DefaultAccountAdapter):
def is_open_for_signup(self, request):
if hasattr(request, "session") and request.session.get(
"account_verified_email",
):
return True
elif app_settings.INVITATION_ONLY is True:
# Site is ONLY open for invites
return False
else:
# Site is open to signup
return True

def get_user_signed_up_signal(self):
return user_signed_up
10 changes: 10 additions & 0 deletions test_allauth_adapters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from invitations.models import InvitationsAdapter


class TestInvitationsAdapter(InvitationsAdapter):
"""Class used to test that subclasses to InvitationsAdapter work as
expected

"""

pass
2 changes: 1 addition & 1 deletion test_allauth_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"allauth.account.auth_backends.AuthenticationBackend",
)

ACCOUNT_ADAPTER = "invitations.models.InvitationsAdapter"
ACCOUNT_ADAPTER = "test_allauth_adapters.TestInvitationsAdapter"

MIDDLEWARE.append("allauth.account.middleware.AccountMiddleware") # noqa: F405

Expand Down
Loading