Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: [ACI-262] credly_badges feature flag #54

Merged
merged 1 commit into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions credentials/apps/badges/admin.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
"""
Admin section configuration.
"""
from django.contrib import admin

from .toggles import is_badges_enabled


# register admin configurations with respect to the feature flag
if is_badges_enabled():
# TODO: Define registering admin classes here `admin.site.register(...)`
pass
pass
52 changes: 26 additions & 26 deletions credentials/apps/badges/apps.py
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
from django.apps import AppConfig
from credentials.apps.plugins.constants import (
PluginURLs,
PluginSettings,
SettingsType,
PROJECT_TYPE,
)
from .toggles import is_badges_enabled, check_badges_enabled
from django.conf import settings

from credentials.apps.plugins.constants import PROJECT_TYPE, PluginSettings, PluginURLs, SettingsType

class BadgesConfig(AppConfig):
from .toggles import check_badges_enabled, is_badges_enabled


class BadgesAppConfig(AppConfig):
"""
Extended application config with additional Badges-specific logic.
"""

@property
def verbose_name(self):
return f"Badges: {self.plugin_label}"


class BadgesConfig(BadgesAppConfig):
"""
Core badges application configuration.
"""
default = True
name = "credentials.apps.badges"
verbose_name = "Badges"

plugin_app = {
PluginURLs.CONFIG: {
PROJECT_TYPE: {
PluginURLs.NAMESPACE: 'badges',
PluginURLs.REGEX: 'badges/',
PluginURLs.RELATIVE_PATH: 'urls',
}
},
PluginSettings.CONFIG: {
PROJECT_TYPE: {
SettingsType.BASE: {PluginSettings.RELATIVE_PATH: 'settings.base'},
SettingsType.PRODUCTION: {PluginSettings.RELATIVE_PATH: 'settings.production'},
SettingsType.TEST: {PluginSettings.RELATIVE_PATH: 'settings.test'},
},
}
} if is_badges_enabled() else {}

@check_badges_enabled
def ready(self):
"""
Activate installed badges plugins if they are enabled.

Performs initial registrations for checks, signals, etc.
"""
# TODO: from .checks import configuration_checks
from .checks import badges_checks # pylint: disable=unused-import,import-outside-toplevel
from .signals import handlers # pylint: disable=unused-import,import-outside-toplevel

super().ready()
2 changes: 1 addition & 1 deletion credentials/apps/badges/checks.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
Badges checks.
Badges app self-checks.
"""
from django.conf import settings
from django.core.checks import Error, Tags, register
Expand Down
18 changes: 18 additions & 0 deletions credentials/apps/badges/distribution/credly/credly_badges/admin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
"""
Credly Badges admin configuration.
"""

from django.contrib import admin

from credentials.apps.badges.toggles import is_badges_enabled

from .models import CredlyOrganization


class CredlyOrganizationAdmin(admin.ModelAdmin):
"""
Credly organization admin setup.
"""
list_display = ("name", "uuid", "api_key",)


# register admin configurations with respect to the feature flag
if is_badges_enabled():
admin.site.register(CredlyOrganization, CredlyOrganizationAdmin)
35 changes: 25 additions & 10 deletions credentials/apps/badges/distribution/credly/credly_badges/apps.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
from django.apps import AppConfig
from credentials.apps.plugins.constants import (
PluginURLs,
PluginSettings,
SettingsType,
PROJECT_TYPE,
)
from credentials.apps.badges.apps import BadgesAppConfig
from credentials.apps.badges.toggles import is_badges_enabled
from credentials.apps.plugins.constants import PROJECT_TYPE, PluginSettings, PluginURLs, SettingsType


class CredlyBadgesConfig(AppConfig):
class CredlyBadgesConfig(BadgesAppConfig):
"""
Credly distribution backend.

This app is the Credential service plugin.
It is built on the top of the `credentials.apps.badges`.
It allows configuration and issuance specific to the Credly (by Pearson) badges from 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"
plugin_label = "Credly (by Pearson)"

plugin_app = {
PluginURLs.CONFIG: {
Expand All @@ -26,4 +33,12 @@ class CredlyBadgesConfig(AppConfig):
SettingsType.TEST: {PluginSettings.RELATIVE_PATH: 'settings.test'},
},
}
}
} if is_badges_enabled() else {} # TODO: improve this

def ready(self):
"""
Activate installed badges plugins if they are enabled.

Performs initial registrations for checks, signals, etc.
"""
super().ready()
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
"""
Credly Badges DB models.
"""

from django.db import models
from django.utils.translation import gettext_lazy as _
from django_extensions.db.models import TimeStampedModel


class CredlyOrganization(TimeStampedModel):
"""
Credly organization configuration.
"""
uuid = models.UUIDField(unique=True, help_text=_('Unique organization ID.'))
name = models.CharField(max_length=255, help_text=_('Organization display name.'))
api_key = models.CharField(max_length=255, help_text=_('Credly API shared secret for organization.'))
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import base64
import logging
from attrs import asdict
from functools import lru_cache
from urllib.parse import urljoin

import requests
from attrs import asdict
from django.conf import settings
from requests.packages.urllib3.exceptions import HTTPError

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
"""

def plugin_settings(settings): # pylint: disable=unused-argument
pass
settings.CREDLY_API_BASE_URL = 'https://api.credly.com/v1/'

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
"""
Credly Badges routing configuration.
"""

from credentials.apps.badges.toggles import is_badges_enabled

urlpatterns = []

if is_badges_enabled():
urlpatterns = [
# Define urls here
]
4 changes: 2 additions & 2 deletions credentials/apps/badges/distribution/credly/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ classifiers = [
dynamic = ["version", "dependencies", "optional-dependencies"]

[project.entry-points."credentials.djangoapp"]
credly_badges = "credly_badges.apps:CredlyBadgesConfig"
badges = "credly_badges.apps:CredlyBadgesConfig"

[project.urls]
Repository = "https://github.com/openedx/credentials.git"
Expand All @@ -37,7 +37,7 @@ packages = ["credly_badges"]

[tool.setuptools.dynamic]
version = { attr = "credly_badges.__version__" }
dependencies = { file = "requirements/base.in" }
dependencies = { file = "requirements/base.txt" }

[tool.ruff]
# https://docs.astral.sh/ruff/configuration/
Expand Down
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.

19 changes: 0 additions & 19 deletions credentials/apps/badges/distribution/credly_badges/admin.py

This file was deleted.

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

This file was deleted.

3 changes: 0 additions & 3 deletions credentials/apps/badges/distribution/credly_badges/checks.py

This file was deleted.

16 changes: 0 additions & 16 deletions credentials/apps/badges/distribution/credly_badges/models.py

This file was deleted.

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.

4 changes: 0 additions & 4 deletions credentials/apps/badges/distribution/credly_badges/urls.py

This file was deleted.

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.

Loading
Loading