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

Added API support for edly multisite access model #396

Draft
wants to merge 1 commit into
base: develop-juniper
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
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
24 changes: 24 additions & 0 deletions openedx/features/edly/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
from rest_framework import serializers

from openedx.features.edly.utils import get_marketing_link
from openedx.features.edly.models import EdlyMultiSiteAccess, EdlySubOrganization
from django.contrib.auth import get_user_model


class UserSiteSerializer(serializers.Serializer):
Expand Down Expand Up @@ -49,3 +51,25 @@ def get_mobile_enabled(self, obj): # pylint: disable=unused-argument
Returns mobile_enabled flag
"""
return self.context['site_configuration'].get('MOBILE_ENABLED', False)


class UserSerializer(serializers.ModelSerializer):
class Meta:
model = get_user_model()
fields = '__all__'


class EdlySubOrganizationSerializer(serializers.ModelSerializer):
class Meta:
model = EdlySubOrganization
fields = '__all__'


class EdlyMultisiteAccessSerializer(serializers.ModelSerializer):

user = UserSerializer()
sub_org = EdlySubOrganizationSerializer()

class Meta:
model = EdlyMultiSiteAccess
fields = ['user', 'sub_org']
2 changes: 2 additions & 0 deletions openedx/features/edly/api/v1/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

from openedx.features.edly.api.v1.views.course_enrollments import EdlyCourseEnrollmentViewSet
from openedx.features.edly.api.v1.views.user_sites import UserSitesViewSet
from openedx.features.edly.api.v1.views.edly_multisite_access import EdlyMultisiteAccessViewSet

router = routers.SimpleRouter()
router.register(r'user_sites', UserSitesViewSet, base_name='user_sites')
router.register(r'edly_multisite_access', EdlyMultisiteAccessViewSet , base_name='edly_multisite_access')
router.register(
r'course_enrollment',
EdlyCourseEnrollmentViewSet,
Expand Down
38 changes: 38 additions & 0 deletions openedx/features/edly/api/v1/views/edly_multisite_access.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"""
Views for user sites API
"""
from rest_framework import viewsets
from rest_framework.permissions import IsAuthenticated
from rest_framework.response import Response

from lms.djangoapps.mobile_api.decorators import mobile_view
from openedx.features.edly.models import EdlyMultiSiteAccess
from openedx.features.edly.api.serializers import EdlyMultisiteAccessSerializer

@mobile_view()
class EdlyMultisiteAccessViewSet(viewsets.ViewSet):
"""
**Use Case**

Get information about the organizations associated with a user.

**Example Request**

GET /api/v1/courses/multisite_access/

**Response Values**

If the request is successful, the request returns an HTTP 200 "OK" response.

The HTTP 200 response has the following values.
"""
permission_classes = (IsAuthenticated,)

def list(self, request, *args, **kwargs):
"""
Get information about the organizations associated with a user.
"""
serializer = EdlyMultisiteAccessSerializer(
EdlyMultiSiteAccess.objects.filter(user=request.user), many=True
)
return Response(serializer.data)