Skip to content

Commit

Permalink
Merge pull request #567 from openedx/justEhmadSaeed/add-serializers-t…
Browse files Browse the repository at this point in the history
…o-bulk-enrollment-api

feat: add serializers for bulk license enrollment endpoint
  • Loading branch information
justEhmadSaeed authored Jan 25, 2024
2 parents 31a4ccf + 4ea89b0 commit dbfd551
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
61 changes: 61 additions & 0 deletions license_manager/apps/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,3 +395,64 @@ 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,
help_text='The UUID of the associated enterprise customer',
)
enroll_all = serializers.BooleanField(
required=False,
help_text='A boolean indicating whether to enroll all learners or not',
)
subscription_uuid = serializers.UUIDField(
required=False,
help_text='The UUID of the subscription',
)

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,
help_text='an array of learners\' emails',
)
course_run_keys = serializers.ListField(
child=serializers.CharField(
allow_blank=False,
write_only=True,
),
allow_empty=False,
required=True,
help_text='an array of course run keys',
)
notify = serializers.BooleanField(
required=True,
help_text='a boolean indicating whether to notify learners or not',
)

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 dbfd551

Please sign in to comment.