diff --git a/CHANGELOG.rst b/CHANGELOG.rst index d564d7e004..ff34491826 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -20,6 +20,18 @@ Unreleased [4.18.0] -------- * feat: updates tasks usage of create_recipient to create_recipients +======= +[4.17.8] +-------- +* fix: adding missing migration file + +[4.17.7] +-------- +* fix: update group invite and removal notification tasks + +[4.17.6] +-------- +* fix: allowing for search lookup of group members in django admin [4.17.5] -------- diff --git a/enterprise/admin/__init__.py b/enterprise/admin/__init__.py index a5b8d3e929..3e223b9389 100644 --- a/enterprise/admin/__init__.py +++ b/enterprise/admin/__init__.py @@ -1203,9 +1203,10 @@ class EnterpriseGroupMembershipAdmin(admin.ModelAdmin): list_display = ('group', 'membership_user',) search_fields = ( 'uuid', - 'group__enterprise_customer_user', - 'enterprise_customer_user', - 'pending_enterprise_customer_user', + 'group__uuid', + 'group__enterprise_customer__uuid', + 'enterprise_customer_user__id', + 'pending_enterprise_customer_user__user_email', ) autocomplete_fields = ( 'group', diff --git a/enterprise/migrations/0207_alter_enterprisegroupmembership_enterprise_customer_user_and_more.py b/enterprise/migrations/0207_alter_enterprisegroupmembership_enterprise_customer_user_and_more.py new file mode 100644 index 0000000000..e1f4a8653f --- /dev/null +++ b/enterprise/migrations/0207_alter_enterprisegroupmembership_enterprise_customer_user_and_more.py @@ -0,0 +1,24 @@ +# Generated by Django 4.2.13 on 2024-05-09 18:15 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('enterprise', '0206_auto_20240408_1344'), + ] + + operations = [ + migrations.AlterField( + model_name='enterprisegroupmembership', + name='enterprise_customer_user', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='memberships', to='enterprise.enterprisecustomeruser'), + ), + migrations.AlterField( + model_name='enterprisegroupmembership', + name='pending_enterprise_customer_user', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='memberships', to='enterprise.pendingenterprisecustomeruser'), + ), + ] diff --git a/enterprise/tasks.py b/enterprise/tasks.py index c7db032464..ca29efe7c6 100644 --- a/enterprise/tasks.py +++ b/enterprise/tasks.py @@ -304,6 +304,11 @@ def send_group_membership_invitation_notification( recipients = [] for pecu_email in pecu_emails: recipients.append(braze_client_instance.create_recipient_no_external_id(pecu_email)) + if pecu_emails: + braze_client_instance.create_braze_alias( + pecu_emails, + ENTERPRISE_BRAZE_ALIAS_LABEL, + ) braze_client_instance.create_braze_alias( [pecu_emails], ENTERPRISE_BRAZE_ALIAS_LABEL, @@ -357,8 +362,14 @@ def send_group_membership_removal_notification(enterprise_customer_uuid, members ] = group_membership.enterprise_customer_user.user_id recipients = [] + for pecu_email in pecu_emails: recipients.append(braze_client_instance.create_recipient_no_external_id(pecu_email)) + if pecu_emails: + braze_client_instance.create_braze_alias( + pecu_emails, + ENTERPRISE_BRAZE_ALIAS_LABEL, + ) braze_client_instance.create_braze_alias( [pecu_emails], ENTERPRISE_BRAZE_ALIAS_LABEL, diff --git a/tests/test_enterprise/test_tasks.py b/tests/test_enterprise/test_tasks.py index bc54fbc59a..9ac2c5da46 100644 --- a/tests/test_enterprise/test_tasks.py +++ b/tests/test_enterprise/test_tasks.py @@ -10,6 +10,7 @@ from pytest import mark +from enterprise.api_client.braze import ENTERPRISE_BRAZE_ALIAS_LABEL from enterprise.constants import SSO_BRAZE_CAMPAIGN_ID from enterprise.models import EnterpriseCourseEnrollment, EnterpriseEnrollmentSource, EnterpriseGroupMembership from enterprise.settings.test import BRAZE_GROUPS_INVITATION_EMAIL_CAMPAIGN_ID, BRAZE_GROUPS_REMOVAL_EMAIL_CAMPAIGN_ID @@ -203,7 +204,7 @@ def test_send_group_membership_invitation_notification(self, mock_braze_api_clie """ EnterpriseGroupMembershipFactory( group=self.enterprise_group, - pending_enterprise_customer_user=PendingEnterpriseCustomerUserFactory(), + pending_enterprise_customer_user=self.pending_enterprise_customer_user, enterprise_customer_user=None, ) EnterpriseGroupMembershipFactory( @@ -263,6 +264,8 @@ def test_send_group_membership_invitation_notification(self, mock_braze_api_clie }, )] mock_braze_api_client().send_campaign_message.assert_has_calls(calls) + mock_braze_api_client().create_braze_alias.assert_called_once_with( + [self.pending_enterprise_customer_user.user_email], ENTERPRISE_BRAZE_ALIAS_LABEL) @mock.patch('enterprise.tasks.EnterpriseCatalogApiClient', return_value=mock.MagicMock()) @mock.patch('enterprise.tasks.BrazeAPIClient', return_value=mock.MagicMock()) @@ -272,7 +275,7 @@ def test_send_group_membership_removal_notification(self, mock_braze_api_client, """ EnterpriseGroupMembershipFactory( group=self.enterprise_group, - pending_enterprise_customer_user=PendingEnterpriseCustomerUserFactory(), + pending_enterprise_customer_user=self.pending_enterprise_customer_user, enterprise_customer_user=None, ) EnterpriseGroupMembershipFactory( @@ -328,6 +331,9 @@ def test_send_group_membership_removal_notification(self, mock_braze_api_client, 'catalog_content_count': mock_catalog_content_count, }, )] + + mock_braze_api_client().create_braze_alias.assert_called_once_with( + [self.pending_enterprise_customer_user.user_email], ENTERPRISE_BRAZE_ALIAS_LABEL) mock_braze_api_client().send_campaign_message.assert_has_calls(calls) @mock.patch('enterprise.tasks.BrazeAPIClient', return_value=mock.MagicMock())