From 09ae369044117d24dae29f728701d7fcea0b9268 Mon Sep 17 00:00:00 2001 From: Andrii Date: Fri, 22 Mar 2024 16:36:25 +0200 Subject: [PATCH 1/4] feat: [ACI-461] define CredlyBadge credential --- .../credly/credly_badges/admin.py | 26 ++++++++++++++++++- .../credly/credly_badges/models.py | 16 +++++++++++- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/credentials/apps/badges/distribution/credly/credly_badges/admin.py b/credentials/apps/badges/distribution/credly/credly_badges/admin.py index 3e3102efe..accd93153 100644 --- a/credentials/apps/badges/distribution/credly/credly_badges/admin.py +++ b/credentials/apps/badges/distribution/credly/credly_badges/admin.py @@ -7,7 +7,7 @@ from credentials.apps.badges.toggles import is_badges_enabled from .forms import CredlyOrganizationAdminForm -from .models import CredlyBadgeTemplate, CredlyOrganization +from .models import CredlyBadge, CredlyBadgeTemplate, CredlyOrganization from .utils import sync_badge_templates_for_organization @@ -63,6 +63,30 @@ class CredlyBadgeTemplateAdmin(admin.ModelAdmin): ] +class CredlyBadgeAdmin(admin.ModelAdmin): + """ + Credly badge admin setup. + """ + list_display = ( + "recipient_email", + "issuing_state", + "uuid", + "issued_at", + ) + list_filter = ( + "issuing_state", + ) + search_fields = ( + "recipient_email", + "uuid", + ) + readonly_fields = ( + "issuing_state", + "uuid", + ) + + if is_badges_enabled(): admin.site.register(CredlyOrganization, CredlyOrganizationAdmin) admin.site.register(CredlyBadgeTemplate, CredlyBadgeTemplateAdmin) + admin.site.register(CredlyBadge, CredlyBadgeAdmin) diff --git a/credentials/apps/badges/distribution/credly/credly_badges/models.py b/credentials/apps/badges/distribution/credly/credly_badges/models.py index ee5e92840..b7109d1c1 100644 --- a/credentials/apps/badges/distribution/credly/credly_badges/models.py +++ b/credentials/apps/badges/distribution/credly/credly_badges/models.py @@ -55,4 +55,18 @@ class CredlyBadge(UserCredential): """ Earned Credly badge template for user. """ - # TODO: check if we can fetch pii for username from LMS for badge issuing? \ No newline at end of file + # TODO: check if we can fetch pii for username from LMS for badge issuing? + + ISSUING_STATES = Choices("created", "no_response", "error", "pending", "accepted", "rejected", "revoked") + + issuing_state = StatusField( + choices_name="ISSUING_STATES", + help_text=_("Credly badge issuing state"), + default=ISSUING_STATES.created, + ) + recipient_email = models.EmailField() + issued_to_first_name = models.CharField(max_length=30) + issued_to_last_name = models.CharField(max_length=150) + issued_at = models.DateTimeField(auto_now_add=True) + + badge_template_id = models.PositiveIntegerField() From 164c7365000837d0fd270294cdcc4f810d304d44 Mon Sep 17 00:00:00 2001 From: Andrii Date: Tue, 26 Mar 2024 14:05:28 +0200 Subject: [PATCH 2/4] feat: [ACI-461] remove user pii from CredlyBadge model --- .../badges/distribution/credly/credly_badges/models.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/credentials/apps/badges/distribution/credly/credly_badges/models.py b/credentials/apps/badges/distribution/credly/credly_badges/models.py index b7109d1c1..dec43e867 100644 --- a/credentials/apps/badges/distribution/credly/credly_badges/models.py +++ b/credentials/apps/badges/distribution/credly/credly_badges/models.py @@ -55,7 +55,6 @@ class CredlyBadge(UserCredential): """ Earned Credly badge template for user. """ - # TODO: check if we can fetch pii for username from LMS for badge issuing? ISSUING_STATES = Choices("created", "no_response", "error", "pending", "accepted", "rejected", "revoked") @@ -64,9 +63,3 @@ class CredlyBadge(UserCredential): help_text=_("Credly badge issuing state"), default=ISSUING_STATES.created, ) - recipient_email = models.EmailField() - issued_to_first_name = models.CharField(max_length=30) - issued_to_last_name = models.CharField(max_length=150) - issued_at = models.DateTimeField(auto_now_add=True) - - badge_template_id = models.PositiveIntegerField() From 96cf1d9874dc3f94c902803aa7ee6def8375bd82 Mon Sep 17 00:00:00 2001 From: Andrii Date: Tue, 26 Mar 2024 14:07:37 +0200 Subject: [PATCH 3/4] feat: [ACI-461] remove user pii from CredlyBadge admin --- .../apps/badges/distribution/credly/credly_badges/admin.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/credentials/apps/badges/distribution/credly/credly_badges/admin.py b/credentials/apps/badges/distribution/credly/credly_badges/admin.py index accd93153..85a4e1b5c 100644 --- a/credentials/apps/badges/distribution/credly/credly_badges/admin.py +++ b/credentials/apps/badges/distribution/credly/credly_badges/admin.py @@ -68,16 +68,15 @@ class CredlyBadgeAdmin(admin.ModelAdmin): Credly badge admin setup. """ list_display = ( - "recipient_email", + "username", "issuing_state", "uuid", - "issued_at", ) list_filter = ( "issuing_state", ) search_fields = ( - "recipient_email", + "username", "uuid", ) readonly_fields = ( From c6244abffa51f0a646d69a74e13b17bceb0fb866 Mon Sep 17 00:00:00 2001 From: Andrii Date: Wed, 27 Mar 2024 13:51:34 +0200 Subject: [PATCH 4/4] feat: [ACI-461] rename state field and add migration files --- .../credly/credly_badges/admin.py | 6 ++-- .../migrations/0004_credlybadge.py | 26 +++++++++++++++ .../migrations/0005_auto_20240327_1118.py | 32 +++++++++++++++++++ ...ename_credlybadgecredential_credlybadge.py | 20 ++++++++++++ .../credly/credly_badges/models.py | 8 ++--- 5 files changed, 85 insertions(+), 7 deletions(-) create mode 100644 credentials/apps/badges/distribution/credly/credly_badges/migrations/0004_credlybadge.py create mode 100644 credentials/apps/badges/distribution/credly/credly_badges/migrations/0005_auto_20240327_1118.py create mode 100644 credentials/apps/badges/distribution/credly/credly_badges/migrations/0006_rename_credlybadgecredential_credlybadge.py diff --git a/credentials/apps/badges/distribution/credly/credly_badges/admin.py b/credentials/apps/badges/distribution/credly/credly_badges/admin.py index 85a4e1b5c..32f8c1464 100644 --- a/credentials/apps/badges/distribution/credly/credly_badges/admin.py +++ b/credentials/apps/badges/distribution/credly/credly_badges/admin.py @@ -69,18 +69,18 @@ class CredlyBadgeAdmin(admin.ModelAdmin): """ list_display = ( "username", - "issuing_state", + "state", "uuid", ) list_filter = ( - "issuing_state", + "state", ) search_fields = ( "username", "uuid", ) readonly_fields = ( - "issuing_state", + "state", "uuid", ) diff --git a/credentials/apps/badges/distribution/credly/credly_badges/migrations/0004_credlybadge.py b/credentials/apps/badges/distribution/credly/credly_badges/migrations/0004_credlybadge.py new file mode 100644 index 000000000..fb14d8da4 --- /dev/null +++ b/credentials/apps/badges/distribution/credly/credly_badges/migrations/0004_credlybadge.py @@ -0,0 +1,26 @@ +# Generated by Django 3.2.20 on 2024-03-20 12:30 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('credentials', '0026_alter_usercredential_credential_content_type'), + ('credly_badges', '0003_credlybadgetemplate_state_and_more'), + ] + + operations = [ + migrations.CreateModel( + name='CredlyBadge', + fields=[ + ('usercredential_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='credentials.usercredential')), + ], + options={ + 'get_latest_by': 'modified', + 'abstract': False, + }, + bases=('credentials.usercredential',), + ), + ] diff --git a/credentials/apps/badges/distribution/credly/credly_badges/migrations/0005_auto_20240327_1118.py b/credentials/apps/badges/distribution/credly/credly_badges/migrations/0005_auto_20240327_1118.py new file mode 100644 index 000000000..025b06fa5 --- /dev/null +++ b/credentials/apps/badges/distribution/credly/credly_badges/migrations/0005_auto_20240327_1118.py @@ -0,0 +1,32 @@ +# Generated by Django 3.2.20 on 2024-03-27 11:18 + +from django.db import migrations, models +import django.db.models.deletion +import model_utils.fields + + +class Migration(migrations.Migration): + + dependencies = [ + ('badges', '0001_initial'), + ('credentials', '0026_alter_usercredential_credential_content_type'), + ('credly_badges', '0004_credlybadge'), + ] + + operations = [ + migrations.CreateModel( + name='CredlyBadgeCredential', + fields=[ + ('usercredential_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='credentials.usercredential')), + ('state', model_utils.fields.StatusField(choices=[('created', 'created'), ('no_response', 'no_response'), ('error', 'error'), ('pending', 'pending'), ('accepted', 'accepted'), ('rejected', 'rejected'), ('revoked', 'revoked')], default='created', help_text='Credly badge issuing state', max_length=100, no_check_for_status=True)), + ], + options={ + 'get_latest_by': 'modified', + 'abstract': False, + }, + bases=('credentials.usercredential',), + ), + migrations.DeleteModel( + name='CredlyBadge', + ), + ] diff --git a/credentials/apps/badges/distribution/credly/credly_badges/migrations/0006_rename_credlybadgecredential_credlybadge.py b/credentials/apps/badges/distribution/credly/credly_badges/migrations/0006_rename_credlybadgecredential_credlybadge.py new file mode 100644 index 000000000..8864f55c7 --- /dev/null +++ b/credentials/apps/badges/distribution/credly/credly_badges/migrations/0006_rename_credlybadgecredential_credlybadge.py @@ -0,0 +1,20 @@ +# Generated by Django 3.2.20 on 2024-03-27 11:46 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('credentials', '0026_alter_usercredential_credential_content_type'), + ('contenttypes', '0002_remove_content_type_name'), + ('badges', '0001_initial'), + ('credly_badges', '0005_auto_20240327_1118'), + ] + + operations = [ + migrations.RenameModel( + old_name='CredlyBadgeCredential', + new_name='CredlyBadge', + ), + ] diff --git a/credentials/apps/badges/distribution/credly/credly_badges/models.py b/credentials/apps/badges/distribution/credly/credly_badges/models.py index dec43e867..2d8e6d060 100644 --- a/credentials/apps/badges/distribution/credly/credly_badges/models.py +++ b/credentials/apps/badges/distribution/credly/credly_badges/models.py @@ -56,10 +56,10 @@ class CredlyBadge(UserCredential): Earned Credly badge template for user. """ - ISSUING_STATES = Choices("created", "no_response", "error", "pending", "accepted", "rejected", "revoked") + STATES = Choices("created", "no_response", "error", "pending", "accepted", "rejected", "revoked") - issuing_state = StatusField( - choices_name="ISSUING_STATES", + state = StatusField( + choices_name="STATES", help_text=_("Credly badge issuing state"), - default=ISSUING_STATES.created, + default=STATES.created, )