Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update enterprise group model and serializer #2251

Merged
merged 3 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.26.0]
---------
* feat: add new field to EnterpriseGroup model and EnterpriseGroupSerializer

[4.25.19]
---------
* feat: remove logging to debug SAP SuccessFactors transmission issues
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.25.19"
__version__ = "4.26.0"
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,
GROUP_MEMBERSHIP_ACCEPTED_STATUS,
DefaultColors,
)
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'),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 4.2.15 on 2024-09-25 20:39

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('enterprise', '0221_enterprisegroup_group_type_and_more'),
]

operations = [
migrations.AlterField(
model_name='enterprisegroup',
name='group_type',
field=models.CharField(choices=[('budget', 'Budget'), ('flex', 'Flex')], default='flex', help_text='The type of enterprise group', max_length=20, verbose_name='Group Type'),
),
migrations.AlterField(
model_name='historicalenterprisegroup',
name='group_type',
field=models.CharField(choices=[('budget', 'Budget'), ('flex', 'Flex')], default='flex', help_text='The type of enterprise group', max_length=20, verbose_name='Group Type'),
),
]
9 changes: 9 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,13 @@ 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,
choices=GROUP_TYPE_CHOICES,
default=GROUP_TYPE_FLEX,
help_text=_("The type of enterprise group"),
)

history = HistoricalRecords()

Expand Down
6 changes: 5 additions & 1 deletion tests/test_enterprise/api/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8030,7 +8030,8 @@ def setUp(self):
group=self.group_1,
pending_enterprise_customer_user=None,
enterprise_customer_user__enterprise_customer=self.enterprise_customer,
activated_at=datetime.now()
activated_at=datetime.now(),
status='accepted',
))

def test_group_permissions(self):
Expand All @@ -8054,6 +8055,9 @@ 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'
serializer = serializers.EnterpriseGroupSerializer(self.group_1)
assert serializer.data['accepted_members_count'] == 11

def test_successful_retrieve_group(self):
"""
Expand Down
Loading