Conversation
…ation in TenantConfig
efcaa68 to
5b1fed8
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR introduces two key improvements to the
TenantConfigViewSet:update-by-domainaction: Allows updating aTenantConfigby searching for it using its domainroute__domain, rather than the default lookup fields (idorexternal_key).TenantConfigSerializer: Ensures that thelms_configs,studio_configs,theming_configs, andmetafields must always be dictionaries.Motivation
Why Add
update-by-domainaction?In Control Center, an automated process is required to create new subscriptions and correctly link them to their respective Open edX sites. To achieve this, Control Center must be able to update the
external_keyof the site (TenantConfig) so that it matches theexternal_keyassigned to the tenant in Control Center.This alignment is crucial because Control Center relies on the
external_keyto establish connections with the Open edX site and enable the necessary functionalities for managing the site.However, in this process, Control Center only has access to the site's domain (
route__domain), not itsidorexternal_key. Therefore, this newupdate-by-domainaction allows Control Center to update the TenantConfig using the domain as the lookup field, ensuring that the correct site is modified while maintaining compatibility with existing API consumers.Why Strengthen JSON Field Validation?
The existing serializer used
serializers.JSONField()for storing configurations (lms_configs,studio_configs,theming_configs, andmeta). However, DRF’sJSONFielddoes not enforce any specific type, meaning these fields could accept any valid JSON value (e.g., strings, numbers, lists). This led to unexpected behavior where incorrect data types were stored without validation.To address this, custom field validators were added to enforce that these fields must always be dictionaries. This ensures data integrity and prevents errors caused by unexpected input types.
Changes Introduced
update-by-domainActionPATCHrequest can now be made to:TenantConfigis found usingroute__domain, it is updated and returned.TenantConfigis found, a404 Not Foundresponse is returned.domainquery parameter is missing, a400 Bad Requestresponse is returned.How to Test
Update a TenantConfig by its
domainExpected:
200 OKwith updated TenantConfig.Backward Compatibility
update-by-domainaction does not modify existing API behavior.