From 7ee9a259641a540221c9df24eac51b2545b68532 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Tue, 8 Oct 2024 18:45:04 +0000 Subject: [PATCH] fix: update logic to correct getting accepted members count from a group --- CHANGELOG.rst | 4 +++ enterprise/__init__.py | 2 +- enterprise/api/v1/serializers.py | 7 +++-- enterprise/models.py | 47 +------------------------------- 4 files changed, 11 insertions(+), 49 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 14e8ca520..4870aa924 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -17,6 +17,10 @@ Unreleased ---------- * nothing unreleased +[4.27.1] +--------- +* fix: update logic to correct getting the accepted members count from a group + [4.27.0] --------- * chore: Add index to the username field in the `Consent` model diff --git a/enterprise/__init__.py b/enterprise/__init__.py index b15308fbf..291322e71 100644 --- a/enterprise/__init__.py +++ b/enterprise/__init__.py @@ -2,4 +2,4 @@ Your project description goes here. """ -__version__ = "4.27.0" +__version__ = "4.27.1" diff --git a/enterprise/api/v1/serializers.py b/enterprise/api/v1/serializers.py index 945e4e795..a975e4bfa 100644 --- a/enterprise/api/v1/serializers.py +++ b/enterprise/api/v1/serializers.py @@ -645,8 +645,11 @@ class Meta: def get_accepted_members_count(self, obj): "Returns count for accepted members" - all_members = obj.get_all_learners().filter(status=GROUP_MEMBERSHIP_ACCEPTED_STATUS) - return len(all_members) + + # groups that have applies_to_all_contexts enabled returns a list of of objects + # so we need to loop through the list to check for the status + accepted_members = obj.get_all_learners().filter(status=GROUP_MEMBERSHIP_ACCEPTED_STATUS) + return len(accepted_members) class EnterpriseGroupMembershipSerializer(serializers.ModelSerializer): diff --git a/enterprise/models.py b/enterprise/models.py index 014f8eaf2..b1c5adebe 100644 --- a/enterprise/models.py +++ b/enterprise/models.py @@ -4444,48 +4444,6 @@ def _get_filtered_ecu_ids(self, user_query): ecus = EnterpriseCustomerUser.objects.raw(sql_string, (customer_id, var_q)) return [ecu.id for ecu in ecus] - def _get_implicit_group_members(self, user_query=None, pending_users_only=False): - """ - Fetches all implicit members of a group, indicated by a (pending) enterprise customer user records. - """ - members = [] - customer_users = [] - - # Regardless of user_query, we will need all pecus related to the group's customer - pending_customer_users = PendingEnterpriseCustomerUser.objects.filter( - enterprise_customer=self.enterprise_customer, - ) - - if user_query: - # Get all ecus relevant to the user query - if not pending_users_only: - customer_users = EnterpriseCustomerUser.objects.filter( - id__in=self._get_filtered_ecu_ids(user_query) - ) - # pecu has user_email as a field, so we can filter directly - pending_customer_users = pending_customer_users.filter(user_email__icontains=user_query) - else: - if not pending_users_only: - # No filtering query so get all ecus related to the group's customer - customer_users = EnterpriseCustomerUser.objects.filter( - enterprise_customer=self.enterprise_customer, - active=True, - ) - # Build an in memory array of all the implicit memberships - for ent_user in customer_users: - members.append(EnterpriseGroupMembership( - uuid=None, - enterprise_customer_user=ent_user, - group=self, - )) - for pending_user in pending_customer_users: - members.append(EnterpriseGroupMembership( - uuid=None, - pending_enterprise_customer_user=pending_user, - group=self, - )) - return members - def _get_explicit_group_members(self, user_query=None, fetch_removed=False, pending_users_only=False,): """ Fetch explicitly defined members of a group, indicated by an existing membership record @@ -4521,10 +4479,7 @@ def get_all_learners(self, are `memberDetails`, `memberStatus`, and `recentAction`. Ordering can be reversed by supplying a `-` at the beginning of the sorting value ie `-memberStatus`. """ - if self.applies_to_all_contexts: - members = self._get_implicit_group_members(user_query, pending_users_only) - else: - members = self._get_explicit_group_members(user_query, fetch_removed, pending_users_only) + members = self._get_explicit_group_members(user_query, fetch_removed, pending_users_only) if sort_by: lambda_keys = { 'member_details': lambda t: t.member_email,