Skip to content

Commit

Permalink
fix: SOCIALACCOUNT_ENABLED wrong when using custom AppConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
pennersr committed Oct 12, 2023
1 parent 01c49fe commit 0dadd0d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 9 deletions.
4 changes: 2 additions & 2 deletions allauth/account/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import datetime

from django.conf import settings
from django.contrib.auth import get_user_model
from django.core import signing
from django.db import models
Expand All @@ -9,15 +10,14 @@
from django.utils import timezone
from django.utils.translation import gettext_lazy as _

from .. import app_settings as allauth_app_settings
from . import app_settings, signals
from .adapter import get_adapter
from .managers import EmailAddressManager, EmailConfirmationManager


class EmailAddress(models.Model):
user = models.ForeignKey(
allauth_app_settings.USER_MODEL,
settings.AUTH_USER_MODEL,
verbose_name=_("user"),
on_delete=models.CASCADE,
)
Expand Down
33 changes: 27 additions & 6 deletions allauth/app_settings.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,31 @@
from django.conf import settings
from django.apps import apps


SITES_ENABLED = "django.contrib.sites" in settings.INSTALLED_APPS
SOCIALACCOUNT_ENABLED = "allauth.socialaccount" in settings.INSTALLED_APPS
MFA_ENABLED = "allauth.mfa" in settings.INSTALLED_APPS
class AppSettings(object):
def __init__(self, prefix):
self.prefix = prefix

LOGIN_REDIRECT_URL = getattr(settings, "LOGIN_REDIRECT_URL", "/")
def _setting(self, name, dflt):
from allauth.utils import get_setting

USER_MODEL = getattr(settings, "AUTH_USER_MODEL", "auth.User")
return get_setting(self.prefix + name, dflt)

@property
def SITES_ENABLED(self):
return apps.is_installed("django.contrib.sites")

@property
def SOCIALACCOUNT_ENABLED(self):
return apps.is_installed("allauth.socialaccount")

@property
def MFA_ENABLED(self):
return apps.is_installed("allauth.mfa")


_app_settings = AppSettings("ALLAUTH_")


def __getattr__(name):
# See https://peps.python.org/pep-0562/
return getattr(_app_settings, name)
3 changes: 2 additions & 1 deletion allauth/socialaccount/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import absolute_import

from django.conf import settings
from django.contrib.auth import authenticate, get_user_model
from django.contrib.sites.shortcuts import get_current_site
from django.core.exceptions import PermissionDenied
Expand Down Expand Up @@ -88,7 +89,7 @@ def get_provider(self, request):


class SocialAccount(models.Model):
user = models.ForeignKey(allauth.app_settings.USER_MODEL, on_delete=models.CASCADE)
user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
# Given a `SocialApp` from which this account originates, this field equals
# the app's `app.provider_id` if available, `app.provider` otherwise.
provider = models.CharField(
Expand Down

0 comments on commit 0dadd0d

Please sign in to comment.