Skip to content

Commit

Permalink
fix: removing applies_to_all_context EnterpriseGroup references (#2268)
Browse files Browse the repository at this point in the history
* fix: removing instances of old variable

* fix: removing migration file
  • Loading branch information
kiram15 authored Oct 22, 2024
1 parent 08b5e55 commit 64b24fd
Show file tree
Hide file tree
Showing 8 changed files with 8 additions and 68 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.28.3]
--------
* feat: removing all references of to-be-deleted field

[4.28.2]
--------
* fix: added content_title, progress_status in get_learner_data_records for derived classed of learner data exporters.
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.28.2"
__version__ = "4.28.3"
4 changes: 2 additions & 2 deletions enterprise/admin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1221,8 +1221,8 @@ class EnterpriseGroupAdmin(admin.ModelAdmin):
Django admin for EnterpriseGroup model.
"""
model = models.EnterpriseGroup
list_display = ('uuid', 'enterprise_customer', 'applies_to_all_contexts', )
list_filter = ('applies_to_all_contexts',)
list_display = ('uuid', 'enterprise_customer', )
list_filter = ('group_type',)
search_fields = (
'uuid',
'name',
Expand Down
13 changes: 1 addition & 12 deletions enterprise/api/v1/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ class EnterpriseGroupSerializer(serializers.ModelSerializer):
class Meta:
model = models.EnterpriseGroup
fields = (
'enterprise_customer', 'name', 'uuid', 'applies_to_all_contexts',
'enterprise_customer', 'name', 'uuid',
'accepted_members_count', 'group_type', 'created')

accepted_members_count = serializers.SerializerMethodField()
Expand Down Expand Up @@ -786,22 +786,11 @@ def get_enterprise_group(self, obj):
"""
Return the enterprise group membership for this enterprise customer user.
"""
related_customer = obj.enterprise_customer
# Find any groups that have ``applies_to_all_contexts`` set to True that are connected to the customer
# that's related to the customer associated with this customer user record.
all_context_groups = models.EnterpriseGroup.objects.filter(
enterprise_customer=related_customer,
applies_to_all_contexts=True
).values_list('uuid', flat=True)
enterprise_groups_from_memberships = obj.memberships.select_related('group').all().values_list(
'group',
flat=True
)
# Combine both sets of group UUIDs
group_uuids = set(enterprise_groups_from_memberships)
for group in all_context_groups:
group_uuids.add(group)

return list(group_uuids)


Expand Down
8 changes: 0 additions & 8 deletions enterprise/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4497,14 +4497,6 @@ class EnterpriseGroup(TimeStampedModel, SoftDeletableModel):
related_name='groups',
on_delete=models.deletion.CASCADE
)
applies_to_all_contexts = models.BooleanField(
verbose_name="Set group membership to the entire org of learners.",
default=False,
null=True,
help_text=_(
"When enabled, all learners connected to the org will be considered a member."
)
)
group_type = models.CharField(
verbose_name="Group Type",
max_length=20,
Expand Down
1 change: 0 additions & 1 deletion test_utils/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -1115,7 +1115,6 @@ class Meta:
model = EnterpriseGroup

uuid = factory.LazyAttribute(lambda x: UUID(FAKER.uuid4()))
applies_to_all_contexts = False
enterprise_customer = factory.SubFactory(EnterpriseCustomerFactory)
name = factory.LazyAttribute(lambda x: FAKER.company())

Expand Down
15 changes: 0 additions & 15 deletions tests/test_enterprise/api/test_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,21 +314,6 @@ def test_group_membership(self):
assert len(serializer.data['enterprise_group']) == 1
assert serializer.data['enterprise_group'][0] == membership.group.uuid

def test_group_membership_when_applies_to_all_contexts(self):
"""
Test that when a group has ``applies_to_all_contexts`` set to True, that group is included in the enterprise
customer user serializer data when there is an associated via an enterprise customer object.
"""
enterprise_group = factories.EnterpriseGroupFactory(
enterprise_customer=self.enterprise_customer_1,
applies_to_all_contexts=True,
)
serializer = EnterpriseCustomerUserReadOnlySerializer(self.enterprise_customer_user_1)
# Assert the enterprise customer user serializer found the group
assert serializer.data.get('enterprise_group') == [enterprise_group.uuid]
# Assert the group has no memberships that could be read by the serializer
assert not enterprise_group.members.all()

def test_multi_group_membership(self):
"""
Test that multiple group memberships are associated properly with a single instance.
Expand Down
29 changes: 0 additions & 29 deletions tests/test_enterprise/api/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8145,7 +8145,6 @@ def test_list_learners_filtered(self):
"""
group = EnterpriseGroupFactory(
enterprise_customer=self.enterprise_customer,
applies_to_all_contexts=True,
)
pending_user = PendingEnterpriseCustomerUserFactory(
user_email="[email protected]",
Expand All @@ -8160,7 +8159,6 @@ def test_list_learners_filtered(self):

assert response.json().get('count') == 0

group.applies_to_all_contexts = False
group.save()
pending_membership = EnterpriseGroupMembershipFactory(
group=group,
Expand Down Expand Up @@ -8203,7 +8201,6 @@ def test_list_learners_filtered(self):
def test_list_removed_learners(self):
group = EnterpriseGroupFactory(
enterprise_customer=self.enterprise_customer,
applies_to_all_contexts=False,
)
memberships_to_delete = []
membership = EnterpriseGroupMembershipFactory(
Expand Down Expand Up @@ -8895,32 +8892,6 @@ def test_remove_learners_from_group_only_removes_from_specified_group(self):
EnterpriseGroupMembership.objects.get(pk=membership_to_remove.pk)
assert EnterpriseGroupMembership.objects.get(pk=existing_membership.pk)

def test_group_applies_to_all_contexts_learner_list(self):
"""
Test that hitting the enterprise-group `/learners/` endpoint for a group that has ``applies_to_all_contexts``
will return all learners in the group's org regardless of what membership records exist.
"""
new_group = EnterpriseGroupFactory(applies_to_all_contexts=True)
new_user = EnterpriseCustomerUserFactory(
user_id=self.user.id, enterprise_customer=new_group.enterprise_customer,
active=True
)
pending_user = PendingEnterpriseCustomerUserFactory(
enterprise_customer=new_group.enterprise_customer,
)
url = settings.TEST_SERVER + reverse(
'enterprise-group-learners',
kwargs={'group_uuid': new_group.uuid},
)
response = self.client.get(url)
results = response.json().get('results')
for result in results:
assert (
result.get('pending_enterprise_customer_user_id') == pending_user.id
) or (
result.get('enterprise_customer_user_id') == new_user.id
)

def test_group_assign_realized_learner_adds_activated_at(self):
"""
Test that newly created membership records associated with an existing user have an activated at value written
Expand Down

0 comments on commit 64b24fd

Please sign in to comment.