Skip to content

Commit

Permalink
feat: add serializers for bulk license enrollment endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
justEhmadSaeed committed Jan 24, 2024
1 parent 31a4ccf commit 3288a37
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
47 changes: 47 additions & 0 deletions license_manager/apps/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
]
7 changes: 7 additions & 0 deletions license_manager/apps/api/v1/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 3288a37

Please sign in to comment.