diff --git a/license_manager/apps/api/tasks.py b/license_manager/apps/api/tasks.py index e0b78b04..76b50ece 100644 --- a/license_manager/apps/api/tasks.py +++ b/license_manager/apps/api/tasks.py @@ -21,13 +21,11 @@ from license_manager.apps.api import utils from license_manager.apps.api.email import EmailClient from license_manager.apps.api.models import BulkEnrollmentJob -from license_manager.apps.api_client.braze import BrazeApiClient from license_manager.apps.api_client.enterprise import EnterpriseApiClient from license_manager.apps.subscriptions.constants import ( ACTIVATED, ASSIGNMENT_EMAIL_BATCH_SIZE, DAYS_BEFORE_INITIAL_UTILIZATION_EMAIL_SENT, - ENTERPRISE_BRAZE_ALIAS_LABEL, LICENSE_UTILIZATION_THRESHOLDS, NOTIFICATION_CHOICE_AND_CAMPAIGN_BY_THRESHOLD, NOTIFY_EMAIL_ACTION_TYPE, @@ -83,27 +81,6 @@ class LoggedTaskWithRetry(LoggedTask): # pylint: disable=abstract-method retry_jitter = True -@shared_task(base=LoggedTaskWithRetry, soft_time_limit=SOFT_TIME_LIMIT, time_limit=MAX_TIME_LIMIT) -def create_braze_aliases_task(user_emails): - """ - Creates a Braze alias for each email using the ENTERPRISE_BRAZE_ALIAS_LABEL. - A Braze alias must be created when sending emails to anonymous users. - - Arguments: - user_emails (list of str): List of emails to create aliases for. - - """ - try: - braze_client_instance = BrazeApiClient(logger_prefix=LICENSE_DEBUG_PREFIX) - braze_client_instance.create_braze_alias( - user_emails, - ENTERPRISE_BRAZE_ALIAS_LABEL, - ) - except BrazeClientError as exc: - logger.exception(exc) - raise exc - - @shared_task(base=LoggedTaskWithRetry, soft_time_limit=SOFT_TIME_LIMIT, time_limit=MAX_TIME_LIMIT) def link_learners_to_enterprise_task(learner_emails, enterprise_customer_uuid): """ diff --git a/license_manager/apps/api/tests/test_tasks.py b/license_manager/apps/api/tests/test_tasks.py index 7b4c28b8..33902b57 100644 --- a/license_manager/apps/api/tests/test_tasks.py +++ b/license_manager/apps/api/tests/test_tasks.py @@ -74,29 +74,6 @@ def setUp(self): self.enterprise_sender_alias = 'Mock Enterprise Alias' self.contact_email = 'cool_biz@example.com' - @mock.patch('license_manager.apps.api.tasks.BrazeApiClient', return_value=mock.MagicMock()) - def test_create_braze_aliases_task(self, mock_braze_client): - """ - Assert create_braze_aliases_task calls Braze API with the correct arguments. - """ - tasks.create_braze_aliases_task( - self.email_recipient_list - ) - mock_braze_client().create_braze_alias.assert_any_call( - self.email_recipient_list, - ENTERPRISE_BRAZE_ALIAS_LABEL, - ) - - @mock.patch('license_manager.apps.api.tasks.BrazeApiClient', side_effect=BrazeClientError) - def test_create_braze_aliases_task_reraises_braze_exceptions(self, _): - """ - Assert create_braze_aliases_task reraises any braze exceptions. - """ - with self.assertRaises(BrazeClientError): - tasks.create_braze_aliases_task( - self.email_recipient_list - ) - @mock.patch('license_manager.apps.api.tasks.EnterpriseApiClient', return_value=mock.MagicMock()) @mock.patch( 'license_manager.apps.api_client.braze.BrazeClient.send_campaign_message', diff --git a/license_manager/apps/api/v1/tests/test_views.py b/license_manager/apps/api/v1/tests/test_views.py index bb7fd732..8da9a23b 100644 --- a/license_manager/apps/api/v1/tests/test_views.py +++ b/license_manager/apps/api/v1/tests/test_views.py @@ -1788,7 +1788,6 @@ def test_assign_dedupe_casing_input(self, mock_send_assignment_email_task, mock_ ) @ddt.unpack @mock.patch('license_manager.apps.api.v1.views.link_learners_to_enterprise_task.si') - @mock.patch('license_manager.apps.api.v1.views.create_braze_aliases_task.si') @mock.patch('license_manager.apps.api.v1.views.send_assignment_email_task.si') def test_assign_notify_users( self, @@ -1797,7 +1796,6 @@ def test_assign_notify_users( should_send_assignment_email, mock_send_assignment_email_task, _, - __, ): """ Verify that users are not sent a license assignment email if notify_users=False diff --git a/license_manager/apps/api/v1/views.py b/license_manager/apps/api/v1/views.py index 44c9a2ea..1f2b460e 100644 --- a/license_manager/apps/api/v1/views.py +++ b/license_manager/apps/api/v1/views.py @@ -32,7 +32,6 @@ from license_manager.apps.api.models import BulkEnrollmentJob from license_manager.apps.api.permissions import CanRetireUser from license_manager.apps.api.tasks import ( - create_braze_aliases_task, execute_post_revocation_tasks, link_learners_to_enterprise_task, revoke_all_licenses_task, @@ -629,7 +628,7 @@ class LicenseAdminViewSet(BaseLicenseViewSet): lookup_field = 'uuid' lookup_url_kwarg = 'license_uuid' - permission_required = '' + permission_required = constants.SUBSCRIPTIONS_ADMIN_ACCESS_PERMISSION allowed_roles = [constants.SUBSCRIPTIONS_ADMIN_ROLE] pagination_class = LicensePagination @@ -732,9 +731,9 @@ def _link_and_notify_assigned_emails( custom_template_text, ): """ - Helper to create async chains of link_learners_to_enterprise_task, create_braze_aliases_task, - and send_assignment_email_task for each batch of users. The task signatures are immutable, - hence the `si()` - we don't want the result of each task passed to the next task in the chain. + Helper to create async chains of link_learners_to_enterprise_task, and send_assignment_email_task + for each batch of users. The task signatures are immutable, hence the `si()` - we don't want the + result of each task passed to the next task in the chain. If disable_onboarding_notifications is set to true on the CustomerAgreement or notify_users=False, Braze aliases will be created but no license assignment email will be sent. @@ -752,10 +751,6 @@ def _link_and_notify_assigned_emails( ) if notify_users and not disable_onboarding_notifications: - # Braze aliases must be created before we attempt to send assignment emails. - tasks.link( - create_braze_aliases_task.si(pending_learner_batch), - ) tasks.link( send_assignment_email_task.si( custom_template_text,