diff --git a/credentials/apps/badges/distribution/__init__.py b/credentials/apps/badges/distribution/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/credentials/apps/badges/distribution/backends.py b/credentials/apps/badges/distribution/backends.py new file mode 100644 index 0000000000..0187e7b55c --- /dev/null +++ b/credentials/apps/badges/distribution/backends.py @@ -0,0 +1,16 @@ +""" +Badges distribution conventional hooks. +""" + +from typing import Any +from django.apps import AppConfig + + +class BadgesBackendConfig(AppConfig): + """ + Extended application config with additional Badge-specific logic. + """ + + # TODO: move backend conditional configuration here. + # - `plugin_app` check; + # - `is_enabled` check; diff --git a/credentials/apps/badges/distribution/credly/credly_badges/apps.py b/credentials/apps/badges/distribution/credly/credly_badges/apps.py index 458fe94233..86047f654a 100644 --- a/credentials/apps/badges/distribution/credly/credly_badges/apps.py +++ b/credentials/apps/badges/distribution/credly/credly_badges/apps.py @@ -1,4 +1,4 @@ -from django.apps import AppConfig +from credentials.apps.badges.distribution.backends import BadgesBackendConfig from credentials.apps.plugins.constants import ( PluginURLs, PluginSettings, @@ -7,7 +7,17 @@ ) -class CredlyBadgesConfig(AppConfig): +class CredlyBadgesConfig(BadgesBackendConfig): + """ + Credly distribution backend. + + This app is built on the top of the credentials.apps.badges. + It allows configuration and issuance specific to the Credly (by Pearson) badges inside Open edX. + In addition in a context of Credly Organization: + - organization badge templates are used to setup Open edX badge templates; + - earned badges are distributed to the Credly service; + """ + name = "credly_badges" verbose_name = "Credly Badges" diff --git a/credentials/apps/badges/distribution/credly/credly_badges/toggles.py b/credentials/apps/badges/distribution/credly/credly_badges/toggles.py index 541c24375c..357e9dd83a 100644 --- a/credentials/apps/badges/distribution/credly/credly_badges/toggles.py +++ b/credentials/apps/badges/distribution/credly/credly_badges/toggles.py @@ -1,3 +1,32 @@ """ Credly Badges app toggles. """ + +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 diff --git a/credentials/apps/badges/distribution/credly/requirements/base.in b/credentials/apps/badges/distribution/credly/requirements/base.in index fb93b059bc..7e49e82ea7 100644 --- a/credentials/apps/badges/distribution/credly/requirements/base.in +++ b/credentials/apps/badges/distribution/credly/requirements/base.in @@ -1,2 +1 @@ # Main requirements of the plugin application. --c constraints.txt diff --git a/credentials/apps/badges/distribution/credly/requirements/constraints.txt b/credentials/apps/badges/distribution/credly/requirements/constraints.txt deleted file mode 100644 index 94595ab168..0000000000 --- a/credentials/apps/badges/distribution/credly/requirements/constraints.txt +++ /dev/null @@ -1,9 +0,0 @@ -# Version constraints for pip-installation. -# -# This file doesn't install any packages. It specifies version constraints -# that will be applied if a package is needed. -# -# When pinning something here, please provide an explanation of why. Ideally, -# link to other information that will help people in the future to remove the -# pin when possible. Writing an issue against the offending project and -# linking to it here is good. diff --git a/credentials/apps/badges/distribution/credly_badges/admin.py b/credentials/apps/badges/distribution/credly_badges/admin.py index 06c687112e..0745482413 100644 --- a/credentials/apps/badges/distribution/credly_badges/admin.py +++ b/credentials/apps/badges/distribution/credly_badges/admin.py @@ -2,8 +2,8 @@ Admin section configuration for credly badges. """ -from .toggles import is_credly_badges_enabled +from .utils import is_backend_enabled -if is_credly_badges_enabled(): +if is_backend_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 18d98f7f29..71175a23e0 100644 --- a/credentials/apps/badges/distribution/credly_badges/apps.py +++ b/credentials/apps/badges/distribution/credly_badges/apps.py @@ -5,11 +5,11 @@ SettingsType, PROJECT_TYPE, ) -from .toggles import is_credly_badges_enabled, check_credly_badges_enabled +from .utils import is_backend_enabled, if_backend_enabled class CredlyBadgesConfig(AppConfig): - name = "credentials.apps.badges.distribution.credly_badges" + name = "credly_badges" verbose_name = "Credly badges" plugin_app = { @@ -27,9 +27,9 @@ class CredlyBadgesConfig(AppConfig): SettingsType.TEST: {PluginSettings.RELATIVE_PATH: 'settings.test'}, }, } - } if is_credly_badges_enabled() else {} + } if is_backend_enabled() else {} - @check_credly_badges_enabled + @if_backend_enabled def ready(self): """ Performs initial registrations for checks, signals, etc. diff --git a/credentials/apps/badges/distribution/credly_badges/settings/base.py b/credentials/apps/badges/distribution/credly_badges/settings/base.py deleted file mode 100644 index 2dba1c5832..0000000000 --- a/credentials/apps/badges/distribution/credly_badges/settings/base.py +++ /dev/null @@ -1,6 +0,0 @@ -""" -Credly badges base settings. -""" - -def plugin_settings(settings): # pylint: disable=unused-argument - pass diff --git a/credentials/apps/badges/distribution/credly_badges/settings/production.py b/credentials/apps/badges/distribution/credly_badges/settings/production.py deleted file mode 100644 index 53a716219f..0000000000 --- a/credentials/apps/badges/distribution/credly_badges/settings/production.py +++ /dev/null @@ -1,6 +0,0 @@ -""" -Credly badges production settings. -""" - -def plugin_settings(settings): # pylint: disable=unused-argument - pass diff --git a/credentials/apps/badges/distribution/credly_badges/settings/test.py b/credentials/apps/badges/distribution/credly_badges/settings/test.py deleted file mode 100644 index 2655a2c4ab..0000000000 --- a/credentials/apps/badges/distribution/credly_badges/settings/test.py +++ /dev/null @@ -1,6 +0,0 @@ -""" -Credly badges test settings. -""" - -def plugin_settings(settings): # pylint: disable=unused-argument - pass diff --git a/credentials/apps/badges/distribution/credly_badges/toggles.py b/credentials/apps/badges/distribution/credly_badges/toggles.py deleted file mode 100644 index 9ecbbe285f..0000000000 --- a/credentials/apps/badges/distribution/credly_badges/toggles.py +++ /dev/null @@ -1,32 +0,0 @@ -""" -Toggles for credly badges app. -""" - -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 diff --git a/credentials/apps/badges/distribution/credly_badges/utils.py b/credentials/apps/badges/distribution/credly_badges/utils.py new file mode 100644 index 0000000000..a73255cd45 --- /dev/null +++ b/credentials/apps/badges/distribution/credly_badges/utils.py @@ -0,0 +1,22 @@ +""" +Toggles for credly badges app. +""" + +from django.conf import settings + + +def is_backend_enabled(): + """ + Checks if Credly Badges app enabled. + """ + return "credly_badges" in settings.BADGES_CONFIG.get("backends", []) + + +def if_backend_enabled(func): + """ + Intercept action if Credly Badges backend is not activated. + """ + def wrapper(*args, **kwargs): + if is_backend_enabled(): + return func(*args, **kwargs) + return wrapper diff --git a/credentials/apps/badges/settings/base.py b/credentials/apps/badges/settings/base.py deleted file mode 100644 index 0b1a5982ef..0000000000 --- a/credentials/apps/badges/settings/base.py +++ /dev/null @@ -1,6 +0,0 @@ -""" -Badges base settings. -""" - -def plugin_settings(settings): # pylint: disable=unused-argument - pass diff --git a/credentials/apps/badges/settings/production.py b/credentials/apps/badges/settings/production.py deleted file mode 100644 index 1f2087330e..0000000000 --- a/credentials/apps/badges/settings/production.py +++ /dev/null @@ -1,6 +0,0 @@ -""" -Badges production settings. -""" - -def plugin_settings(settings): # pylint: disable=unused-argument - pass diff --git a/credentials/apps/badges/settings/test.py b/credentials/apps/badges/settings/test.py deleted file mode 100644 index f6bc2ae050..0000000000 --- a/credentials/apps/badges/settings/test.py +++ /dev/null @@ -1,6 +0,0 @@ -""" -Badges test settings. -""" - -def plugin_settings(settings): # pylint: disable=unused-argument - pass diff --git a/credentials/settings/base.py b/credentials/settings/base.py index 2eb782f5a9..8f572b726d 100644 --- a/credentials/settings/base.py +++ b/credentials/settings/base.py @@ -585,3 +585,10 @@ }, }, } + +# Badges Settings +BADGES_CONFIG = { + "backends": [ + "credly_badges", + ] +} \ No newline at end of file diff --git a/requirements/base.in b/requirements/base.in index 63b7c0413f..c750148724 100644 --- a/requirements/base.in +++ b/requirements/base.in @@ -54,7 +54,6 @@ xss-utils # Badges app baked-in backend plugins: -e credentials/apps/badges/distribution/credly - # TODO Install in configuration git+https://github.com/openedx/credentials-themes.git@0.3.22#egg=edx_credentials_themes==0.3.22 git+https://github.com/raccoongang/openedx-events.git@aci.main#egg=openedx_events