From ce929545248ffa0c0bbdfd04c230f8f60ee3939f Mon Sep 17 00:00:00 2001 From: asadazam93 Date: Wed, 21 Aug 2019 15:06:54 +0500 Subject: [PATCH] social platform validation --- .../core/djangoapps/user_api/accounts/serializers.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/openedx/core/djangoapps/user_api/accounts/serializers.py b/openedx/core/djangoapps/user_api/accounts/serializers.py index e51b2e114974..cdb715bafe31 100644 --- a/openedx/core/djangoapps/user_api/accounts/serializers.py +++ b/openedx/core/djangoapps/user_api/accounts/serializers.py @@ -64,6 +64,17 @@ class Meta(object): 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): """