From 3288a379da08e15535504b97b141eee68daedd75 Mon Sep 17 00:00:00 2001 From: Ehmad Saeed Date: Wed, 24 Jan 2024 11:37:48 +0500 Subject: [PATCH] feat: add serializers for bulk license enrollment endpoint --- license_manager/apps/api/serializers.py | 47 +++++++++++++++++++++++++ license_manager/apps/api/v1/views.py | 7 ++++ 2 files changed, 54 insertions(+) diff --git a/license_manager/apps/api/serializers.py b/license_manager/apps/api/serializers.py index 928136e1..f1545060 100644 --- a/license_manager/apps/api/serializers.py +++ b/license_manager/apps/api/serializers.py @@ -395,3 +395,50 @@ def validate(self, attrs): ) return super().validate(attrs) + + +class EnterpriseEnrollmentWithLicenseSubsidyQueryParamsSerializer(serializers.Serializer): # pylint: disable=abstract-method + """ + Serializer for the enterprise enrollment with license subsidy query params + """ + + enterprise_customer_uuid = serializers.UUIDField(required=True) + enroll_all = serializers.BooleanField(required=False) + subscription_uuid = serializers.UUIDField(required=False) + + class Meta: + fields = [ + 'enterprise_customer_uuid', + 'enroll_all', + 'subscription_uuid', + ] + + +class EnterpriseEnrollmentWithLicenseSubsidyRequestSerializer(serializers.Serializer): # pylint: disable=abstract-method + """ + Serializer for the enterprise enrollment with license subsidy request + """ + + emails = serializers.ListField( + child=serializers.EmailField( + allow_blank=False, + ), + allow_empty=False, + required=True, + ) + course_run_keys = serializers.ListField( + child=serializers.CharField( + allow_blank=False, + write_only=True, + ), + allow_empty=False, + required=True, + ) + notify = serializers.BooleanField(required=True) + + class Meta: + fields = [ + 'emails', + 'course_run_keys', + 'notify', + ] diff --git a/license_manager/apps/api/v1/views.py b/license_manager/apps/api/v1/views.py index 0a2ddc6d..ce8b7291 100644 --- a/license_manager/apps/api/v1/views.py +++ b/license_manager/apps/api/v1/views.py @@ -11,6 +11,7 @@ from django.db.models import Count from django.shortcuts import get_object_or_404 from django_filters.rest_framework import DjangoFilterBackend +from drf_spectacular.utils import extend_schema from edx_rbac.decorators import permission_required from edx_rbac.mixins import PermissionRequiredForListingMixin from edx_rest_framework_extensions.auth.jwt.authentication import ( @@ -1262,6 +1263,12 @@ def _validate_enrollment_request_params(self): constants.SUBSCRIPTIONS_ADMIN_LEARNER_ACCESS_PERMISSION, fn=lambda request: utils.get_context_for_customer_agreement_from_request(request), # pylint: disable=unnecessary-lambda ) + @extend_schema( + parameters=[ + serializers.EnterpriseEnrollmentWithLicenseSubsidyQueryParamsSerializer, + ], + request=serializers.EnterpriseEnrollmentWithLicenseSubsidyRequestSerializer, + ) def post(self, request): """ Returns the enterprise bulk enrollment API response after validating that each user requesting to be enrolled