diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 9f23413a0..ca7d954bf 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -17,6 +17,10 @@ Unreleased ---------- * nothing unreleased +[4.32.2] +-------- +* fix: ensure admin_users in EnterpriseCustomerUserViewSet is correct. + [4.32.1] -------- * feat: enable search filter on learner data transmission audit admin views for all integrated channels. diff --git a/enterprise/__init__.py b/enterprise/__init__.py index aceba5514..7073c032b 100644 --- a/enterprise/__init__.py +++ b/enterprise/__init__.py @@ -2,4 +2,4 @@ Your project description goes here. """ -__version__ = "4.32.1" +__version__ = "4.32.2" diff --git a/enterprise/api/v1/serializers.py b/enterprise/api/v1/serializers.py index 219fbf978..541754029 100644 --- a/enterprise/api/v1/serializers.py +++ b/enterprise/api/v1/serializers.py @@ -721,12 +721,25 @@ class Meta: ) user = UserSerializer() - enterprise_customer = EnterpriseCustomerSerializer() data_sharing_consent_records = serializers.SerializerMethodField() groups = serializers.SerializerMethodField() role_assignments = serializers.SerializerMethodField() enterprise_group = serializers.SerializerMethodField() + def to_representation(self, instance): + """ + Override to pass the instance of `enterprise_customer` to the nested serializer. + """ + representation = super().to_representation(instance) + enterprise_customer_instance = instance.enterprise_customer + enterprise_customer_serializer = EnterpriseCustomerSerializer( + instance=enterprise_customer_instance, + context=self.context + ) + representation['enterprise_customer'] = enterprise_customer_serializer.data + + return representation + def _get_role_assignments_by_ecu_id(self, enterprise_customer_users): """ Get enterprise role assignments for each enterprise customer user. diff --git a/tests/test_enterprise/api/test_views.py b/tests/test_enterprise/api/test_views.py index 10074e34f..9391f4cff 100644 --- a/tests/test_enterprise/api/test_views.py +++ b/tests/test_enterprise/api/test_views.py @@ -555,6 +555,37 @@ def test_get_enterprise_customer_user_contains_features(self): response = self.load_json(response.content) assert response['enterprise_features'] is not None + def test_get_enterprise_customer_user_contains_admin_users(self): + """ + Assert whether the paginated response contains `enterprise_customer.admin_users`. + """ + user = factories.UserFactory() + enterprise_customer = factories.EnterpriseCustomerFactory(uuid=FAKE_UUIDS[0]) + factories.EnterpriseCustomerUserFactory( + user_id=user.id, + enterprise_customer=enterprise_customer + ) + admin_user = factories.UserFactory() + SystemWideEnterpriseUserRoleAssignment.objects.create( + role=admin_role(), + user=admin_user, + enterprise_customer=enterprise_customer + ) + response = self.client.get( + '{host}{path}?username={username}'.format( + host=settings.TEST_SERVER, + path=ENTERPRISE_LEARNER_LIST_ENDPOINT, + username=user.username + ) + ) + response = self.load_json(response.content) + assert response['results'][0]['enterprise_customer']['admin_users'] == [ + { + 'email': admin_user.email, + 'lms_user_id': admin_user.id, + } + ] + def test_get_enterprise_customer_user_contains_consent_records(self): user = factories.UserFactory() enterprise_customer = factories.EnterpriseCustomerFactory(uuid=FAKE_UUIDS[0])