-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adds endpoint to list group memberships by learner
- Loading branch information
1 parent
ff9cd5a
commit b46b7ab
Showing
6 changed files
with
129 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,4 @@ | |
Your project description goes here. | ||
""" | ||
|
||
__version__ = "5.6.12" | ||
__version__ = "5.7.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
""" | ||
Views for the ``enterprise-group-membership`` API endpoint. | ||
""" | ||
|
||
from django_filters.rest_framework import DjangoFilterBackend | ||
from rest_framework import filters, permissions | ||
from rest_framework.decorators import action | ||
from rest_framework.response import Response | ||
from rest_framework.status import HTTP_400_BAD_REQUEST | ||
|
||
from django.contrib import auth | ||
|
||
from enterprise import models | ||
from enterprise.api.v1 import serializers | ||
from enterprise.api.v1.views.base_views import EnterpriseReadWriteModelViewSet | ||
from enterprise.logging import getEnterpriseLogger | ||
|
||
LOGGER = getEnterpriseLogger(__name__) | ||
|
||
User = auth.get_user_model() | ||
|
||
|
||
class EnterpriseGroupMembershipViewSet(EnterpriseReadWriteModelViewSet): | ||
""" | ||
API views for the ``enterprise-group-membership`` API endpoint. | ||
""" | ||
queryset = models.EnterpriseGroupMembership.all_objects.all() | ||
permission_classes = (permissions.IsAuthenticated,) | ||
filter_backends = (filters.OrderingFilter, DjangoFilterBackend,) | ||
serializer_class = serializers.EnterpriseGroupMembershipSerializer | ||
|
||
@action(detail=False, methods=['get']) | ||
def get_memberships(self, request): | ||
""" | ||
Endpoint that filters by `lms_user_id` and `enterprise_uuid`. | ||
Parameters: | ||
- `lms_user_id` (str): Filter results by the LMS user ID. | ||
- `enterprise_uuid` (str): Filter results by the Enterprise UUID. | ||
Response: | ||
- Returns a list of EnterpriseGroupMemberships matching the filters. | ||
- Response format: JSON array of serialized `EnterpriseGroupMembership` objects. | ||
""" | ||
queryset = self.queryset | ||
|
||
lms_user_id = request.query_params.get('lms_user_id') | ||
enterprise_uuid = request.query_params.get('enterprise_uuid') | ||
|
||
if not lms_user_id or not enterprise_uuid: | ||
return Response( | ||
{"error": "Both 'lms_user_id' and 'enterprise_uuid' are required parameters."}, | ||
status=HTTP_400_BAD_REQUEST | ||
) | ||
|
||
if lms_user_id: | ||
queryset = queryset.filter(enterprise_customer_user__user_id=lms_user_id) | ||
if enterprise_uuid: | ||
queryset = queryset.filter(enterprise_customer_user__enterprise_customer__uuid=enterprise_uuid) | ||
|
||
page = self.paginate_queryset(queryset) | ||
|
||
serializer = self.get_serializer(page, many=True) | ||
return self.get_paginated_response(serializer.data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters