Skip to content

Commit

Permalink
Merge branch 'master' into kiram15/ENT-9506
Browse files Browse the repository at this point in the history
  • Loading branch information
kiram15 committed Oct 8, 2024
2 parents 62166ca + 4731169 commit f3326c8
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 52 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ Unreleased
---------
* fix: Updating the EnterpriseGroup serializer with created variable

[4.27.2]
---------
* fix: updates `get_all_learners` to remove `_get_implicit_group_members`

[4.27.1]
---------
* chore: remove `replaces` sections from squashing migrations.

[4.27.0]
---------
* chore: Add index to the username field in the `Consent` model
Expand Down
1 change: 1 addition & 0 deletions enterprise/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
"""

__version__ = "4.27.3"

4 changes: 2 additions & 2 deletions enterprise/api/v1/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -645,8 +645,8 @@ 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)
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
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@

class Migration(migrations.Migration):

replaces = [('sap_success_factors', '0001_squashed_0022_auto_20200206_1046'), ('sap_success_factors', '0002_sapsuccessfactorslearnerdatatransmissionaudit_credit_hours'), ('sap_success_factors', '0003_auto_20210701_1556'), ('sap_success_factors', '0004_auto_20210708_1639'), ('sap_success_factors', '0005_sapsuccessfactorsenterprisecustomerconfiguration_prevent_learner_self_submit_grades'), ('sap_success_factors', '0006_sapsuccessfactorsenterprisecustomerconfiguration_idp_id'), ('sap_success_factors', '0007_sapsuccessfactorsenterprisecustomerconfiguration_disable_learner_data_transmissions'), ('sap_success_factors', '0008_alter_sapsuccessfactorsenterprisecustomerconfiguration_enterprise_customer'), ('sap_success_factors', '0009_auto_20220126_1837'), ('sap_success_factors', '0010_sapsuccessfactorsenterprisecustomerconfiguration_display_name'), ('sap_success_factors', '0011_alter_sapsuccessfactorslearnerdatatransmissionaudit_enterprise_course_enrollment_id')]
# Commenting out `replaces` to allow --prune to function correctly and clean up the migrations table.
# replaces = [('sap_success_factors', '0001_squashed_0022_auto_20200206_1046'), ('sap_success_factors', '0002_sapsuccessfactorslearnerdatatransmissionaudit_credit_hours'), ('sap_success_factors', '0003_auto_20210701_1556'), ('sap_success_factors', '0004_auto_20210708_1639'), ('sap_success_factors', '0005_sapsuccessfactorsenterprisecustomerconfiguration_prevent_learner_self_submit_grades'), ('sap_success_factors', '0006_sapsuccessfactorsenterprisecustomerconfiguration_idp_id'), ('sap_success_factors', '0007_sapsuccessfactorsenterprisecustomerconfiguration_disable_learner_data_transmissions'), ('sap_success_factors', '0008_alter_sapsuccessfactorsenterprisecustomerconfiguration_enterprise_customer'), ('sap_success_factors', '0009_auto_20220126_1837'), ('sap_success_factors', '0010_sapsuccessfactorsenterprisecustomerconfiguration_display_name'), ('sap_success_factors', '0011_alter_sapsuccessfactorslearnerdatatransmissionaudit_enterprise_course_enrollment_id')]

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@

class Migration(migrations.Migration):

replaces = [('sap_success_factors', '0004_auto_20220324_1550'), ('sap_success_factors', '0005_auto_20220325_1757'), ('sap_success_factors', '0006_auto_20220330_1157')]
# Commenting out `replaces` to allow --prune to function correctly and clean up the migrations table.
# replaces = [('sap_success_factors', '0004_auto_20220324_1550'), ('sap_success_factors', '0005_auto_20220325_1757'), ('sap_success_factors', '0006_auto_20220330_1157')]

dependencies = [
('sap_success_factors', '0003_alter_sapsuccessfactorslearnerdatatransmissionaudit_completed_timestamp'),
Expand Down
3 changes: 1 addition & 2 deletions tests/test_enterprise/api/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8158,8 +8158,7 @@ def test_list_learners_filtered(self):
) + pending_user_query_string
response = self.client.get(url)

assert response.json().get('count') == 1
assert response.json().get('results')[0].get('pending_enterprise_customer_user_id') == pending_user.id
assert response.json().get('count') == 0

group.applies_to_all_contexts = False
group.save()
Expand Down

0 comments on commit f3326c8

Please sign in to comment.