Skip to content

Commit

Permalink
fix: update logic to correct getting accepted members count from a group
Browse files Browse the repository at this point in the history
  • Loading branch information
Ubuntu committed Oct 8, 2024
1 parent 0024644 commit 7ee9a25
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 49 deletions.
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.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
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.27.0"
__version__ = "4.27.1"
7 changes: 5 additions & 2 deletions enterprise/api/v1/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
47 changes: 1 addition & 46 deletions enterprise/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 7ee9a25

Please sign in to comment.