Skip to content

Commit

Permalink
feat: update enterprise group model and serializer
Browse files Browse the repository at this point in the history
  • Loading branch information
katrinan029 committed Sep 25, 2024
1 parent 3ce3b38 commit 8acbb85
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 2 deletions.
18 changes: 16 additions & 2 deletions enterprise/api/v1/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@
from enterprise import models, utils # pylint: disable=cyclic-import
from enterprise.api.v1.fields import Base64EmailCSVField
from enterprise.api_client.lms import ThirdPartyAuthApiClient
from enterprise.constants import ENTERPRISE_ADMIN_ROLE, ENTERPRISE_PERMISSION_GROUPS, DefaultColors
from enterprise.constants import (
ENTERPRISE_ADMIN_ROLE,
ENTERPRISE_PERMISSION_GROUPS,
DefaultColors,
GROUP_MEMBERSHIP_ACCEPTED_STATUS,
)
from enterprise.logging import getEnterpriseLogger
from enterprise.models import (
AdminNotification,
Expand Down Expand Up @@ -632,7 +637,16 @@ class EnterpriseGroupSerializer(serializers.ModelSerializer):
"""
class Meta:
model = models.EnterpriseGroup
fields = ('enterprise_customer', 'name', 'uuid', 'applies_to_all_contexts')
fields = (
'enterprise_customer', 'name', 'uuid', 'applies_to_all_contexts',
'accepted_members_count', 'group_type')

accepted_members_count = serializers.SerializerMethodField()

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)


class EnterpriseGroupMembershipSerializer(serializers.ModelSerializer):
Expand Down
6 changes: 6 additions & 0 deletions enterprise/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,12 @@ class FulfillmentTypes:
(GROUP_MEMBERSHIP_INTERNAL_API_ERROR_STATUS, 'Internal API error'),
(GROUP_MEMBERSHIP_EMAIL_ERROR_STATUS, 'Email error')
)
GROUP_TYPE_BUDGET = 'budget'
GROUP_TYPE_FLEX = 'flex'
GROUP_TYPE_CHOICES = (
(GROUP_TYPE_BUDGET, 'Budget'),
(GROUP_TYPE_FLEX, 'Flex')
)

ENTITY_ID_REGEX = r"<(\w+:)?EntityDescriptor.*?entityID=['\"](.*?)['\"].*?>"

Expand Down
23 changes: 23 additions & 0 deletions enterprise/migrations/0221_enterprisegroup_group_type_and_more.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 4.2.15 on 2024-09-24 21:39

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('enterprise', '0220_alter_updateroleassignmentswithcustomersconfig_role'),
]

operations = [
migrations.AddField(
model_name='enterprisegroup',
name='group_type',
field=models.CharField(blank=True, choices=[('budget', 'Budget'), ('flex', 'Flex')], default='flex', help_text='The type of enterprise group', max_length=20, null=True, verbose_name='Group Type'),
),
migrations.AddField(
model_name='historicalenterprisegroup',
name='group_type',
field=models.CharField(blank=True, choices=[('budget', 'Budget'), ('flex', 'Flex')], default='flex', help_text='The type of enterprise group', max_length=20, null=True, verbose_name='Group Type'),
),
]
11 changes: 11 additions & 0 deletions enterprise/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@
GROUP_MEMBERSHIP_ACCEPTED_STATUS,
GROUP_MEMBERSHIP_PENDING_STATUS,
GROUP_MEMBERSHIP_STATUS_CHOICES,
GROUP_TYPE_CHOICES,
GROUP_TYPE_FLEX,
MAX_INVITE_KEYS,
DefaultColors,
FulfillmentTypes,
Expand Down Expand Up @@ -4405,6 +4407,15 @@ class EnterpriseGroup(TimeStampedModel, SoftDeletableModel):
"When enabled, all learners connected to the org will be considered a member."
)
)
group_type = models.CharField(
verbose_name="Group Type",
max_length=20,
blank=True,
null=True,
choices=GROUP_TYPE_CHOICES,
default=GROUP_TYPE_FLEX,
help_text=_("The type of enterprise group"),
)

history = HistoricalRecords()

Expand Down
2 changes: 2 additions & 0 deletions tests/test_enterprise/api/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8042,6 +8042,8 @@ def test_successful_list_groups(self):
)
response = self.client.get(url)
assert response.json().get('count') == 2
assert response.json().get('results')[0].get('group_type') == 'flex'
assert response.json().get('results')[0].get('accepted_members_count') == 10

def test_successful_retrieve_group(self):
"""
Expand Down

0 comments on commit 8acbb85

Please sign in to comment.