diff --git a/credentials/apps/badges/distribution/credly_badges/admin.py b/credentials/apps/badges/distribution/credly_badges/admin.py index 8d9902d42f..06c687112e 100644 --- a/credentials/apps/badges/distribution/credly_badges/admin.py +++ b/credentials/apps/badges/distribution/credly_badges/admin.py @@ -1,3 +1,9 @@ """ Admin section configuration for credly badges. """ + +from .toggles import is_credly_badges_enabled + +if is_credly_badges_enabled(): + # TODO: Define registering admin classes here `admin.site.register(...)` + pass diff --git a/credentials/apps/badges/distribution/credly_badges/apps.py b/credentials/apps/badges/distribution/credly_badges/apps.py index a32b04b477..18d98f7f29 100644 --- a/credentials/apps/badges/distribution/credly_badges/apps.py +++ b/credentials/apps/badges/distribution/credly_badges/apps.py @@ -5,6 +5,7 @@ SettingsType, PROJECT_TYPE, ) +from .toggles import is_credly_badges_enabled, check_credly_badges_enabled class CredlyBadgesConfig(AppConfig): @@ -26,4 +27,11 @@ class CredlyBadgesConfig(AppConfig): SettingsType.TEST: {PluginSettings.RELATIVE_PATH: 'settings.test'}, }, } - } + } if is_credly_badges_enabled() else {} + + @check_credly_badges_enabled + def ready(self): + """ + Performs initial registrations for checks, signals, etc. + """ + # TODO: from .checks import configuration_checks diff --git a/credentials/apps/badges/distribution/credly_badges/toggles.py b/credentials/apps/badges/distribution/credly_badges/toggles.py index 99462a9e16..9ecbbe285f 100644 --- a/credentials/apps/badges/distribution/credly_badges/toggles.py +++ b/credentials/apps/badges/distribution/credly_badges/toggles.py @@ -1,3 +1,32 @@ """ Toggles for credly badges app. -""" \ No newline at end of file +""" + +from edx_toggles.toggles import SettingToggle + +# .. toggle_name: CREDLY_BADGES_ENABLED +# .. toggle_implementation: DjangoSetting +# .. toggle_default: False +# .. toggle_description: Determines if the Credentials IDA uses credly badges functionality. +# .. toggle_life_expectancy: permanent +# .. toggle_permanent_justification: Credly badges are optional for usage. +# .. toggle_creation_date: 2024-01-16 +# .. toggle_use_cases: open_edx +ENABLE_CREDLY_BADGES = SettingToggle('CREDLY_BADGES_ENABLED', default=False, module_name=__name__) + + +def is_credly_badges_enabled(): + """ + Checks if credly badges app enabled. + """ + return ENABLE_CREDLY_BADGES.is_enabled() + + +def check_credly_badges_enabled(func): + """ + Decorator for checking the applicability of a credly badges app. + """ + def wrapper(*args, **kwargs): + if is_credly_badges_enabled(): + return func(*args, **kwargs) + return wrapper