Skip to content

Commit

Permalink
Merge branch 'master' into django42-migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
irtazaakram committed Sep 28, 2023
2 parents d9fb4b4 + 699cdea commit fa6e6d2
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ Change Log
Unreleased
----------
[4.3.3]
-------
chore: adding display name to the sso orchestrator table

[4.3.2]
-------
fix: enterprise sso orchestrator api cleanup
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.3.2"
__version__ = "4.3.3"
23 changes: 23 additions & 0 deletions enterprise/migrations/0187_auto_20230926_1627.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 3.2.20 on 2023-09-26 16:27

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('enterprise', '0186_auto_20230921_1828'),
]

operations = [
migrations.AddField(
model_name='enterprisecustomerssoconfiguration',
name='display_name',
field=models.CharField(blank=True, help_text='The display name of the SSO configuration.', max_length=255, null=True),
),
migrations.AddField(
model_name='historicalenterprisecustomerssoconfiguration',
name='display_name',
field=models.CharField(blank=True, help_text='The display name of the SSO configuration.', max_length=255, null=True),
),
]
9 changes: 9 additions & 0 deletions enterprise/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3765,6 +3765,15 @@ class Meta:

# ---------------------------- base configurations ---------------------------- #

display_name = models.CharField(
blank=True,
null=True,
max_length=255,
help_text=_(
"The display name of the SSO configuration."
),
)

uuid = models.UUIDField(primary_key=True, default=uuid4, editable=False)

enterprise_customer = models.ForeignKey(
Expand Down
13 changes: 13 additions & 0 deletions enterprise/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,19 @@ def create_enterprise_enrollment_receiver(sender, instance, **kwargs): # pyl
)


@receiver(pre_save, sender=models.EnterpriseCustomerSsoConfiguration)
def generate_default_orchestration_record_display_name(sender, instance, **kwargs): # pylint: disable=unused-argument
"""
Ensure that the display_name field is populated with a default value if it is not provided while creating.
"""
if not models.EnterpriseCustomerSsoConfiguration.objects.filter(pk=instance.pk).exists():
if instance.display_name is None:
num_records_for_customer = models.EnterpriseCustomerSsoConfiguration.objects.filter(
enterprise_customer=instance.enterprise_customer,
).count()
instance.display_name = f'SSO-config-{instance.identity_provider}-{num_records_for_customer + 1}'


# Don't connect this receiver if we dont have access to CourseEnrollment model
if CourseEnrollment is not None:
post_save.connect(create_enterprise_enrollment_receiver, sender=CourseEnrollment)
Expand Down
41 changes: 41 additions & 0 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2710,3 +2710,44 @@ def test_submitting_already_submitted_sso_config(self):
)
with raises(ValidationError):
sso_configuration.submit_for_configuration()

def test_sso_config_default_display_name(self):
"""
Test the default naming functionality of the SSO orchestration config table
"""
customer = factories.EnterpriseCustomerFactory()
# Confirm display name is generated correctly on creation if absent from the kwargs
sso_configuration, _ = EnterpriseCustomerSsoConfiguration.objects.get_or_create(
enterprise_customer=customer,
identity_provider='foobar',
)
assert sso_configuration.display_name == 'SSO-config-foobar-1'

# Confirm display name is not generated or effected by updating a record
sso_configuration.display_name = None
sso_configuration.save()
sso_configuration.metadata_url = 'ayylmao'
sso_configuration.save()
assert sso_configuration.display_name is None

# Confirm the display name is kept if specified during creation
second_sso_configuration, _ = EnterpriseCustomerSsoConfiguration.objects.get_or_create(
enterprise_customer=customer,
identity_provider='SAP',
display_name='im-a-display-name',
)
assert second_sso_configuration.display_name == 'im-a-display-name'

# Confirm the display name is generated based on how many records exist for the customer
third_sso_configuration, _ = EnterpriseCustomerSsoConfiguration.objects.get_or_create(
enterprise_customer=customer,
identity_provider='ayylmao',
)
assert third_sso_configuration.display_name == 'SSO-config-ayylmao-3'

# Confirm the display name default value is not effected by other customers' records
different_customer_sso_configuration, _ = EnterpriseCustomerSsoConfiguration.objects.get_or_create(
enterprise_customer=factories.EnterpriseCustomerFactory(),
identity_provider='SAP',
)
assert different_customer_sso_configuration.display_name == 'SSO-config-SAP-1'

0 comments on commit fa6e6d2

Please sign in to comment.