Skip to content

Commit

Permalink
fix: update Badges backends configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
wowkalucky committed Jan 17, 2024
1 parent a40642c commit f28dd63
Show file tree
Hide file tree
Showing 18 changed files with 92 additions and 87 deletions.
Empty file.
16 changes: 16 additions & 0 deletions credentials/apps/badges/distribution/backends.py
Original file line number Diff line number Diff line change
@@ -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;
14 changes: 12 additions & 2 deletions credentials/apps/badges/distribution/credly/credly_badges/apps.py
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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"

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
# Main requirements of the plugin application.
-c constraints.txt

This file was deleted.

4 changes: 2 additions & 2 deletions credentials/apps/badges/distribution/credly_badges/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 4 additions & 4 deletions credentials/apps/badges/distribution/credly_badges/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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.
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

32 changes: 0 additions & 32 deletions credentials/apps/badges/distribution/credly_badges/toggles.py

This file was deleted.

22 changes: 22 additions & 0 deletions credentials/apps/badges/distribution/credly_badges/utils.py
Original file line number Diff line number Diff line change
@@ -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
6 changes: 0 additions & 6 deletions credentials/apps/badges/settings/base.py

This file was deleted.

6 changes: 0 additions & 6 deletions credentials/apps/badges/settings/production.py

This file was deleted.

6 changes: 0 additions & 6 deletions credentials/apps/badges/settings/test.py

This file was deleted.

7 changes: 7 additions & 0 deletions credentials/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -585,3 +585,10 @@
},
},
}

# Badges Settings
BADGES_CONFIG = {
"backends": [
"credly_badges",
]
}
1 change: 0 additions & 1 deletion requirements/base.in
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]#egg=edx_credentials_themes==0.3.22
git+https://github.com/raccoongang/[email protected]#egg=openedx_events

0 comments on commit f28dd63

Please sign in to comment.