Skip to content

Commit

Permalink
Merge pull request #1965 from openedx/asheehan-edx/sso-orchestrator-r…
Browse files Browse the repository at this point in the history
…elease-ff

feat: not submitting sso orchestrator records if no changes occur
  • Loading branch information
alex-sheehan-edx authored Dec 8, 2023
2 parents 774ceba + 8179f81 commit 4a1687f
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 8 deletions.
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.8.10]
--------
feat: not submitting sso orchestrator records if no changes occur

[4.8.9]
-------
feat: adding timeouts to sso orchestrator configurations and 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.8.9"
__version__ = "4.8.10"
24 changes: 20 additions & 4 deletions enterprise/api/v1/views/enterprise_customer_sso_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,15 +321,31 @@ def update(self, request, *args, **kwargs):
return Response(status=HTTP_403_FORBIDDEN)
try:
with transaction.atomic():
needs_submitting = False
for request_key in request_data.keys():
# If the requested data to update includes a field that is locked while configuring
if request_key in EnterpriseCustomerSsoConfiguration.fields_locked_while_configuring:
# If any of the provided values differ from the existing value
existing_value = getattr(
sso_configuration_record.first(), request_key, request_data[request_key]
)
if existing_value != request_data[request_key]:
# Indicate that the record needs to be submitted for configuration to the orchestrator
needs_submitting = True
sso_configuration_record.update(**request_data)
sp_metadata_url = sso_configuration_record.first().submit_for_configuration(
updating_existing_record=True
)
sp_metadata_url = ''
if needs_submitting:
sp_metadata_url = sso_configuration_record.first().submit_for_configuration(
updating_existing_record=True
)
except (TypeError, FieldDoesNotExist, ValidationError, SsoOrchestratorClientError) as e:
LOGGER.error(f'{CONFIG_UPDATE_ERROR} {e}')
return Response({'error': f'{CONFIG_UPDATE_ERROR} {e}'}, status=HTTP_400_BAD_REQUEST)
serializer = self.serializer_class(sso_configuration_record.first())
return Response({'record': serializer.data, 'sp_metadata_url': sp_metadata_url}, status=HTTP_200_OK)
response = {'record': serializer.data}
if sp_metadata_url:
response['sp_metadata_url'] = sp_metadata_url
return Response(response, status=HTTP_200_OK)

@permission_required(
'enterprise.can_access_admin_dashboard',
Expand Down
4 changes: 2 additions & 2 deletions enterprise/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4110,9 +4110,9 @@ def submit_for_configuration(self, updating_existing_record=False):
for field in self.base_saml_config_fields:
if field == "active":
if not updating_existing_record:
config_data['enable'] = True
config_data['enabled'] = True
else:
config_data['enable'] = getattr(self, field)
config_data['enabled'] = getattr(self, field)
elif field_value := getattr(self, field):
config_data[utils.camelCase(field)] = field_value

Expand Down
3 changes: 2 additions & 1 deletion tests/test_enterprise/api/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7763,7 +7763,8 @@ def test_sso_configurations_update_submitted_config(self):
enterprise_sso_orchestration_config = EnterpriseCustomerSsoConfigurationFactory(
uuid=config_pk,
enterprise_customer=self.enterprise_customer,
submitted_at=localized_utcnow()
submitted_at=localized_utcnow(),
metadata_url="old_url",
)
data = {
"metadata_url": "https://example.com/metadata.xml",
Expand Down

0 comments on commit 4a1687f

Please sign in to comment.