Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add serializers for bulk license enrollment endpoint #567

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
)
Comment on lines +1266 to +1271
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Consider copoying some of the docs below about expected params into the help_text of your new serializer fields.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@iloveagent57 added the help_text field to serializer fields.

def post(self, request):
"""
Returns the enterprise bulk enrollment API response after validating that each user requesting to be enrolled
Expand Down
Loading