From ed6de127c31c7cf30045c22aac6a9b2961f7b406 Mon Sep 17 00:00:00 2001 From: Kyrylo Kholodenko Date: Wed, 17 Jan 2024 12:36:08 +0200 Subject: [PATCH] feat: [ACI-222] feature flag for badges --- credentials/apps/badges/admin.py | 6 ++++++ credentials/apps/badges/apps.py | 8 ++++---- credentials/apps/badges/toggles.py | 26 +++++++++++++++++++++++++- credentials/apps/badges/urls.py | 7 ++++++- 4 files changed, 41 insertions(+), 6 deletions(-) diff --git a/credentials/apps/badges/admin.py b/credentials/apps/badges/admin.py index b7bbe442f..9d8b9afb5 100644 --- a/credentials/apps/badges/admin.py +++ b/credentials/apps/badges/admin.py @@ -1,3 +1,9 @@ """ Admin section configuration. """ + +from .toggles import is_badges_enabled + +if is_badges_enabled(): + # TODO: Define registering admin classes here `admin.site.register(...)` + pass diff --git a/credentials/apps/badges/apps.py b/credentials/apps/badges/apps.py index 767bbbd76..b85440653 100644 --- a/credentials/apps/badges/apps.py +++ b/credentials/apps/badges/apps.py @@ -1,16 +1,16 @@ from django.apps import AppConfig -from .toggles import is_badges_enabled +from .toggles import check_badges_enabled class BadgesConfig(AppConfig): name = "credentials.apps.badges" verbose_name = "Badges" + @check_badges_enabled def ready(self): """ Performs initial registrations for checks, signals, etc. """ - if is_badges_enabled(): - from . import signals # pylint: disable=unused-import,import-outside-toplevel - from . checks import badges_checks # pylint: disable=unused-import,import-outside-toplevel + from . import signals # pylint: disable=unused-import,import-outside-toplevel + from . checks import badges_checks # pylint: disable=unused-import,import-outside-toplevel diff --git a/credentials/apps/badges/toggles.py b/credentials/apps/badges/toggles.py index 31bf742b7..04bbfecab 100644 --- a/credentials/apps/badges/toggles.py +++ b/credentials/apps/badges/toggles.py @@ -3,7 +3,31 @@ """ +from edx_toggles.toggles import SettingToggle + +# .. toggle_name: BADGES_ENABLED +# .. toggle_implementation: DjangoSetting +# .. toggle_default: False +# .. toggle_description: Determines if the Credentials IDA uses badges functionality. +# .. toggle_life_expectancy: permanent +# .. toggle_permanent_justification: Badges are optional for usage. +# .. toggle_creation_date: 2024-01-12 +# .. toggle_use_cases: open_edx +ENABLE_BADGES = SettingToggle('BADGES_ENABLED', default=False, module_name=__name__) + + def is_badges_enabled(): """ + Checks if badges app enabled. + """ + return ENABLE_BADGES.is_enabled() + + +def check_badges_enabled(func): + """ + Decorator for checking the applicability of a badges app. """ - return True + def wrapper(*args, **kwargs): + if is_badges_enabled(): + return func(*args, **kwargs) + return wrapper diff --git a/credentials/apps/badges/urls.py b/credentials/apps/badges/urls.py index e4dd8cd0b..6bc02b91e 100644 --- a/credentials/apps/badges/urls.py +++ b/credentials/apps/badges/urls.py @@ -1,4 +1,9 @@ """ URLs for badges. """ -urlpatterns = [] + +from .toggles import is_badges_enabled + +urlpatterns = [] if not is_badges_enabled else [ + # Define urls here +]