Skip to content

Commit

Permalink
Merge pull request #1888 from openedx/asheehan-edx/fetching-api-reque…
Browse files Browse the repository at this point in the history
…st-data

chore: adding a more flexible way of fetching api request data
  • Loading branch information
alex-sheehan-edx authored Oct 3, 2023
2 parents adb7f83 + 38247f6 commit 795c4b9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 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.5.2]
-------
chore: adding a more flexible way of fetching api request data

[4.5.1]
-------
fix: fix how we determine the value of active flag within schedule for SAP
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.5.1"
__version__ = "4.5.2"
15 changes: 12 additions & 3 deletions enterprise/api/v1/views/enterprise_customer_sso_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,21 @@ def fetch_entity_id_from_metadata_xml(metadata_xml):
raise EntityIdNotFoundError('Could not find entity ID in metadata xml')


def fetch_request_data_from_request(request):
"""
Helper method to fetch the request data dictionary from the request object.
"""
if hasattr(request.data, 'dict'):
return request.data.dict().copy()
return request.data.copy()


class EnterpriseCustomerSsoConfigurationViewSet(viewsets.ModelViewSet):
"""
API views for the ``EnterpriseCustomerSsoConfiguration`` model.
"""
permission_classes = (permissions.IsAuthenticated,)
queryset = models.EnterpriseCustomerSsoConfiguration.all_objects.all()
queryset = models.EnterpriseCustomerSsoConfiguration.objects.all()

serializer_class = serializers.EnterpriseCustomerSsoConfiguration

Expand Down Expand Up @@ -199,7 +208,7 @@ def list(self, request, *args, **kwargs):
)
def create(self, request, *args, **kwargs):
# Force the enterprise customer to be the one associated with the user
request_data = request.data.dict().copy()
request_data = fetch_request_data_from_request(request)
requesting_user_customer = request_data.get('enterprise_customer')
if requesting_user_customer:
try:
Expand Down Expand Up @@ -264,7 +273,7 @@ def update(self, request, *args, **kwargs):
return Response(status=HTTP_403_FORBIDDEN)

# Parse the request data to see if the metadata url or xml has changed and update the entity id if so
request_data = request.data.dict()
request_data = fetch_request_data_from_request(request)
sso_config_metadata_xml = None
if request_metadata_url := request_data.get('metadata_url'):
sso_config_metadata_url = sso_configuration_record.first().metadata_url
Expand Down

0 comments on commit 795c4b9

Please sign in to comment.