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

fix: ensure correct admin_users in EnterpriseCustomerUserViewSet response #2287

Merged
merged 3 commits into from
Nov 15, 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
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion enterprise/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
Your project description goes here.
"""

__version__ = "4.32.1"
__version__ = "4.32.2"
11 changes: 10 additions & 1 deletion enterprise/api/v1/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@ class Meta:
)

user = UserSerializer()
enterprise_customer = EnterpriseCustomerSerializer()
enterprise_customer = serializers.SerializerMethodField()
data_sharing_consent_records = serializers.SerializerMethodField()
groups = serializers.SerializerMethodField()
role_assignments = serializers.SerializerMethodField()
Expand Down Expand Up @@ -756,6 +756,15 @@ def __init__(self, instance=None, data=empty, **kwargs):
)
self.role_assignments_by_ecu_id = role_assignments_by_ecu_id

def get_enterprise_customer(self, obj):
"""
Return serialization of EnterpriseCustomer associated with the EnterpriseCustomerUser.
"""
return EnterpriseCustomerSerializer(
instance=obj.enterprise_customer,
context=self.context
).data

def get_data_sharing_consent_records(self, obj):
"""
Return serialization of EnterpriseCustomerUser.data_sharing_consent_records property.
Expand Down
31 changes: 31 additions & 0 deletions tests/test_enterprise/api/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
Loading