diff --git a/openedx/core/djangoapps/user_api/accounts/serializers.py b/openedx/core/djangoapps/user_api/accounts/serializers.py index c4072f1324d569495745ded51ddd4dd84e21c87f..20178b0cb57673a8253350c22fe4739796beef2c 100644 --- a/openedx/core/djangoapps/user_api/accounts/serializers.py +++ b/openedx/core/djangoapps/user_api/accounts/serializers.py @@ -67,6 +67,17 @@ class SocialLinkSerializer(serializers.ModelSerializer): model = SocialLink fields = ("platform", "social_link") + def validate_platform(self, platform): + """ + Validate that the platform value is one of (facebook, twitter or linkedin) + """ + valid_platforms = ["facebook", "twitter", "linkedin"] + if platform not in valid_platforms: + raise serializers.ValidationError( + u"The social platform must be facebook, twitter or linkedin" + ) + return platform + class UserReadOnlySerializer(serializers.Serializer): """ diff --git a/openedx/core/djangoapps/user_api/accounts/tests/test_api.py b/openedx/core/djangoapps/user_api/accounts/tests/test_api.py index f52f5a11132d2233704ecd90dfdc134d788c12b7..9f6a1e9dc9d111f44dcd63168be46ffdc8ff8618 100644 --- a/openedx/core/djangoapps/user_api/accounts/tests/test_api.py +++ b/openedx/core/djangoapps/user_api/accounts/tests/test_api.py @@ -217,7 +217,7 @@ class TestAccountApi(UserSettingsEventTestMixin, EmailTemplateTagMixin, Retireme social_links = [ dict(platform="unsupported", social_link="https://www.unsupported.com/{}".format(self.user.username)) ] - with self.assertRaises(AccountUpdateError): + with self.assertRaises(AccountValidationError): update_account_settings(self.user, {"social_links": social_links}) def test_update_success_for_enterprise(self):