From 08dbab73d28819a5406174cc709978b5a42275b9 Mon Sep 17 00:00:00 2001 From: Vadim Stepanov Date: Thu, 2 Feb 2023 13:21:04 +0000 Subject: [PATCH] Remove mobile_app_settings DynamicSetting (#1268) # What this PR does Remove checks for `mobile_app_settings` DynamicSetting, so changing `FEATURE_MOBILE_APP_INTEGRATION_ENABLED` is enough for toggling the mobile app backend (aka remove per-org feature flag) Co-authored-by: Joey Orlando --- Makefile | 6 ------ dev/README.md | 4 ---- engine/apps/api/views/features.py | 12 +---------- engine/apps/mobile_app/backend.py | 13 ------------ .../management/commands/enable_mobile_app.py | 21 ------------------- 5 files changed, 1 insertion(+), 55 deletions(-) delete mode 100644 engine/engine/management/commands/enable_mobile_app.py diff --git a/Makefile b/Makefile index 809f70c6..863a9566 100644 --- a/Makefile +++ b/Makefile @@ -137,12 +137,6 @@ _backend-debug-disable: backend-debug-enable: _backend-debug-enable stop start backend-debug-disable: _backend-debug-disable stop start -_enable-mobile-app-feature-flags: - $(shell ./dev/add_env_var.sh FEATURE_MOBILE_APP_INTEGRATION_ENABLED True $(DEV_ENV_FILE)) - $(call run_engine_docker_command,python manage.py enable_mobile_app) - -enable-mobile-app-feature-flags: _enable-mobile-app-feature-flags stop start - # The below commands are useful for running backend services outside of docker define backend_command export `grep -v '^#' $(DEV_ENV_FILE) | xargs -0` && \ diff --git a/dev/README.md b/dev/README.md index b1b2ee65..bd88dabf 100644 --- a/dev/README.md +++ b/dev/README.md @@ -150,10 +150,6 @@ make build # rebuild images (e.g. when changing requirements.txt) # run Django's `manage.py` script, inside of a docker container, passing `$CMD` as arguments. # e.g. `make engine-manage CMD="makemigrations"` - https://docs.djangoproject.com/en/4.1/ref/django-admin/#django-admin-makemigrations make engine-manage CMD="..." -# sets a feature flag, related to mobile app backend functionality, in your ./dev/.env.dev -# and sets the necessary database values -# NOTE: you need to enable, and configure, the plugin before running this command -make enable-mobile-app-feature-flags make backend-debug-enable # enable Django's debug mode and Silk profiling (this is disabled by default for performance reasons) make backend-debug-disable # disable Django's debug mode and Silk profiling diff --git a/engine/apps/api/views/features.py b/engine/apps/api/views/features.py index 3a0ebfd5..b705c23c 100644 --- a/engine/apps/api/views/features.py +++ b/engine/apps/api/views/features.py @@ -37,17 +37,7 @@ class FeaturesAPIView(APIView): enabled_features.append(FEATURE_TELEGRAM) if settings.FEATURE_MOBILE_APP_INTEGRATION_ENABLED: - mobile_app_settings = DynamicSetting.objects.get_or_create( - name="mobile_app_settings", - defaults={ - "json_value": { - "org_ids": [], - } - }, - )[0] - - if request.auth.organization.pk in mobile_app_settings.json_value["org_ids"]: - enabled_features.append(MOBILE_APP_PUSH_NOTIFICATIONS) + enabled_features.append(MOBILE_APP_PUSH_NOTIFICATIONS) if settings.OSS_INSTALLATION: # Features below should be enabled only in OSS diff --git a/engine/apps/mobile_app/backend.py b/engine/apps/mobile_app/backend.py index 93e35f30..43f257c3 100644 --- a/engine/apps/mobile_app/backend.py +++ b/engine/apps/mobile_app/backend.py @@ -4,7 +4,6 @@ from django.conf import settings from fcm_django.models import FCMDevice from apps.base.messaging import BaseMessagingBackend -from apps.base.models import DynamicSetting from apps.mobile_app.tasks import notify_user_async @@ -51,18 +50,6 @@ class MobileAppBackend(BaseMessagingBackend): critical=critical, ) - @staticmethod - def is_enabled_for_organization(organization): - # Setting FEATURE_MOBILE_APP_INTEGRATION_ENABLED to True is enough to enable mobile app on OSS instances - if settings.LICENSE == settings.OPEN_SOURCE_LICENSE_NAME: - return True - - mobile_app_settings, _ = DynamicSetting.objects.get_or_create( - name="mobile_app_settings", defaults={"json_value": {"org_ids": []}} - ) - - return organization.pk in mobile_app_settings.json_value["org_ids"] - class MobileAppCriticalBackend(MobileAppBackend): """ diff --git a/engine/engine/management/commands/enable_mobile_app.py b/engine/engine/management/commands/enable_mobile_app.py deleted file mode 100644 index 01208147..00000000 --- a/engine/engine/management/commands/enable_mobile_app.py +++ /dev/null @@ -1,21 +0,0 @@ -from django.core.management.base import BaseCommand, CommandError - -from apps.base.models.dynamic_setting import DynamicSetting -from apps.user_management.models.organization import Organization - - -class Command(BaseCommand): - note = "Note: you will also need to set the appropriate environment variables in your ./dev/.env.dev file." - help = f"Handles the database portion of enabling the mobile app related features. {note}" - - def handle(self, *args, **options): - org = Organization.objects.first() - - if not org: - raise CommandError("No organization exists. Have you enabled, and configured, the plugin?") - - DynamicSetting.objects.update_or_create( - name="mobile_app_settings", defaults={"json_value": {"org_ids": [org.pk]}} - ) - - self.stdout.write(self.style.SUCCESS(f"Mobile app successfully enabled."))