diff --git a/api/config/settings/local.py b/api/config/settings/local.py index 70fb5a21e..b1674f46d 100644 --- a/api/config/settings/local.py +++ b/api/config/settings/local.py @@ -152,3 +152,6 @@ REST_FRAMEWORK.update( ], } ) + +# allows makemigrations and superuser creation +FORCE = env("FORCE", default=1) diff --git a/api/funkwhale_api/common/management/commands/createsuperuser.py b/api/funkwhale_api/common/management/commands/createsuperuser.py index 49a59753f..244a280b9 100644 --- a/api/funkwhale_api/common/management/commands/createsuperuser.py +++ b/api/funkwhale_api/common/management/commands/createsuperuser.py @@ -1,5 +1,4 @@ -import os - +from django.conf import settings from django.contrib.auth.management.commands.createsuperuser import ( Command as BaseCommand, ) @@ -12,7 +11,8 @@ class Command(BaseCommand): Creating Django Superusers would bypass some of our username checks, which can lead to unexpected behaviour. We therefore prohibit the execution of the command. """ - if not os.environ.get("FORCE") == "1": + force = settings.FORCE + if not force == 1: raise CommandError( "Running createsuperuser on your Funkwhale instance bypasses some of our checks " "which can lead to unexpected behavior of your instance. We therefore suggest to " diff --git a/api/funkwhale_api/common/management/commands/makemigrations.py b/api/funkwhale_api/common/management/commands/makemigrations.py index f8530f1a7..42635deda 100644 --- a/api/funkwhale_api/common/management/commands/makemigrations.py +++ b/api/funkwhale_api/common/management/commands/makemigrations.py @@ -1,5 +1,4 @@ -import os - +from django.conf import settings from django.core.management.base import CommandError from django.core.management.commands.makemigrations import Command as BaseCommand @@ -11,8 +10,8 @@ class Command(BaseCommand): We ensure the command is disabled, unless a specific env var is provided. """ - force = os.environ.get("FORCE") == "1" - if not force: + force = settings.FORCE + if not force == 1: raise CommandError( "Running makemigrations on your Funkwhale instance can have desastrous" " consequences. This command is disabled, and should only be run in " diff --git a/api/tests/common/test_commands.py b/api/tests/common/test_commands.py index 59c900d0b..8b52dbd43 100644 --- a/api/tests/common/test_commands.py +++ b/api/tests/common/test_commands.py @@ -1,6 +1,5 @@ -import os - import pytest +from django.conf import settings from django.core.management import call_command from django.core.management.base import CommandError @@ -119,12 +118,13 @@ commands = ["createsuperuser", "makemigrations"] @pytest.mark.parametrize("command", commands) def test_blocked_commands(command): with pytest.raises(CommandError): + setattr(settings, "FORCE", 0) call_command(command) @pytest.mark.parametrize("command", commands) def test_unblocked_commands(command, mocker): - mocker.patch.dict(os.environ, {"FORCE": "1"}) + setattr(settings, "FORCE", 1) call_command(command)