Repository: imAsparky/django-cookiecutter

Issue:
[FEAT]: Add Admin site setting to disable new sign ups
**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

Enabling and disabling new signups is not simple with django-allauth.

**Describe the solution you'd like**
A clear and concise description of what you want to happen.

Add a django-allauth adaptor, changeable in Admin.

**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.

**Additional context**
Add any other context or screenshots about the feature request here.



Discussion:

Resolving patch:
diff --git a/{{cookiecutter.git_project_name}}/config/settings/base.py b/{{cookiecutter.git_project_name}}/config/settings/base.py
--- a/{{cookiecutter.git_project_name}}/config/settings/base.py
+++ b/{{cookiecutter.git_project_name}}/config/settings/base.py
@@ -161,7 +161,21 @@
         "NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",
     },
 ]
-{% if cookiecutter.use_constance != "n" %}
+{% if cookiecutter.allow_new_user_signup != "n" %}
+# Constance Configuration
+CONSTANCE_BACKEND = "constance.backends.database.DatabaseBackend"
+
+CONSTANCE_CONFIG = {
+    "ALLOW_NEW_USER_SIGNUP": (False, "Check to allow new user signups!", bool),
+}
+
+CONSTANCE_CONFIG_FIELDSETS = {
+    "User Settings": (
+        "ALLOW_NEW_USER_SIGNUP",
+    ),
+}
+
+{% elif cookiecutter.use_constance != "n" %}
 # Constance Configuration
 CONSTANCE_BACKEND = "constance.backends.database.DatabaseBackend"
 
@@ -171,6 +185,7 @@
         "Answer to the Ultimate Question of Life, The Universe, and Everything",
         int,
     ),
+
 }
 
 CONSTANCE_CONFIG_FIELDSETS = {
diff --git a/{{cookiecutter.git_project_name}}/core/utils/context_processors.py b/{{cookiecutter.git_project_name}}/core/utils/context_processors.py
--- a/{{cookiecutter.git_project_name}}/core/utils/context_processors.py
+++ b/{{cookiecutter.git_project_name}}/core/utils/context_processors.py
@@ -1,8 +1,12 @@
 """Django context processors."""
 
 import environ
+{% if cookiecutter.allow_new_user_signup != "n" %}
+from constance import config
+{% endif %}
 from django.conf import settings
 
+from users.models import CustomUser
 
 env = environ.FileAwareEnv()
 
@@ -79,4 +83,9 @@ def export_vars(request) -> dict:
             else:
                 data["ENVIRONMENT"] = f"{environ}: Debug False"
     {% endif %}
+    {% if cookiecutter.allow_new_user_signup != "n" %}
+    data["ALLOW_NEW_USER_SIGNUP"] = config.ALLOW_NEW_USER_SIGNUP
+    {% endif %}
+
+
     return data


Test patch:
diff --git a/tests/test_bake_django.py b/tests/test_bake_django.py
--- a/tests/test_bake_django.py
+++ b/tests/test_bake_django.py
@@ -19,6 +19,74 @@ def test_django_bakes_ok_with_defaults(cookies):
     assert default_django.project_path.name == "django-boilerplate"
 
 
+def test_baked_with_allow_new_user_signup(cookies):
+    non_default_django = cookies.bake(
+        extra_context={"allow_new_user_signup": "y"}
+    )
+
+    context_path = (
+        non_default_django.project_path / "core/utils/context_processors.py"
+    )
+    context_file = context_path.read_text().splitlines()
+    settings_path = non_default_django.project_path / "config/settings/base.py"
+    settings_file = settings_path.read_text().splitlines()
+    requirements_path = (
+        non_default_django.project_path / "config/requirements/base.txt"
+    )
+    requirements_file = requirements_path.read_text().splitlines()
+
+    assert (
+        '    data["ALLOW_NEW_USER_SIGNUP"] = config.ALLOW_NEW_USER_SIGNUP'
+        in context_file
+    )
+    assert (
+        'CONSTANCE_BACKEND = "constance.backends.database.DatabaseBackend"'
+        in settings_file
+    )
+    assert "CONSTANCE_CONFIG = {" in settings_file
+    assert (
+        '    "ALLOW_NEW_USER_SIGNUP": (False, "Check to allow new user signups!", bool),'
+        in settings_file
+    )
+    assert "CONSTANCE_CONFIG_FIELDSETS = {" in settings_file
+    assert '    "User Settings": (' in settings_file
+    assert '        "ALLOW_NEW_USER_SIGNUP",' in settings_file
+    assert "django-constance[database]==2.8.0" in requirements_file
+
+
+def test_baked_without_allow_new_user_signup(cookies):
+    default_django = cookies.bake()
+
+    context_path = (
+        default_django.project_path / "core/utils/context_processors.py"
+    )
+    context_file = context_path.read_text().splitlines()
+    settings_path = default_django.project_path / "config/settings/base.py"
+    settings_file = settings_path.read_text().splitlines()
+    requirements_path = (
+        default_django.project_path / "config/requirements/base.txt"
+    )
+    requirements_file = requirements_path.read_text().splitlines()
+
+    assert (
+        '    data["ALLOW_NEW_USER_SIGNUP"] = config.ALLOW_NEW_USER_SIGNUP'
+        not in context_file
+    )
+    assert (
+        'CONSTANCE_BACKEND = "constance.backends.database.DatabaseBackend"'
+        not in settings_file
+    )
+    assert "CONSTANCE_CONFIG = {" not in settings_file
+    assert (
+        '    "ALLOW_NEW_USER_SIGNUP": (False, "Check to allow new user signups!", bool),'
+        not in settings_file
+    )
+    assert "CONSTANCE_CONFIG_FIELDSETS = {" not in settings_file
+    assert '    "User Settings": (' not in settings_file
+    assert '        "ALLOW_NEW_USER_SIGNUP",' not in settings_file
+    assert "django-constance[database]==2.8.0" not in requirements_file
+
+
 def test_baked_django_core_asgi_file_ok(cookies):
     """Test Django Core asgi.py file has been generated correctly."""
     default_django = cookies.bake()