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

Add Edly site config api - EDLY-6656 #82

Merged
merged 2 commits into from
May 14, 2024
Merged
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
10 changes: 10 additions & 0 deletions course_discovery/apps/edly_discovery_app/api/v1/constants.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""
Constants for Edly Sites API.
"""
from enum import Enum

from django.utils.translation import ugettext as _

ERROR_MESSAGES = {
Expand All @@ -19,3 +21,11 @@
]

DEFAULT_COURSE_ID = 'course-v1:{}+get_started_with+Edly'

class CoursePlans(Enum):
TRIAL = 'trial'
ESSENTIALS = 'essentials'
ELITE_PLAN = 'elite'
TRIAL_EXPIRED = 'trial expired'
DEACTIVATED = 'deactivated'
LEGACY = 'legacy'
1 change: 1 addition & 0 deletions course_discovery/apps/edly_discovery_app/api/v1/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
app_name = 'v1'
urlpatterns = [
url(r'^edly_sites/', edly_sites.EdlySiteViewSet.as_view(), name='edly_sites'),
url(r'^edly_site_config/', edly_sites.EdlySiteConfigViewset.as_view(), name='edly_site_config'),
url(r'^dataloader/', dataloader_api.EdlyDataLoaderView.as_view(), name='edly_dataloader'),
]
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@
Views for Edly Sites API.
"""
from django.contrib.sites.models import Site
from rest_framework import status, viewsets, filters
from rest_framework.authentication import SessionAuthentication
from rest_framework import status
from rest_framework.permissions import IsAuthenticated
from rest_framework.response import Response
from rest_framework.views import APIView

from course_discovery.apps.core.models import Partner
from course_discovery.apps.edly_discovery_app.tasks import run_dataloader
from edly_discovery_app.api.v1.constants import DEFAULT_COURSE_ID, ERROR_MESSAGES
from edly_discovery_app.api.v1.constants import CoursePlans, DEFAULT_COURSE_ID, ERROR_MESSAGES
from edly_discovery_app.api.v1.helpers import validate_partner_configurations
from edly_discovery_app.api.v1.permissions import CanAccessSiteCreation

Expand Down Expand Up @@ -96,3 +95,24 @@ def get_updated_site_partner(self, discovery_site):
partner.save()

return partner


class EdlySiteConfigViewset(APIView):
"""
Create Default Site and Partner Configuration.
"""
permission_classes = [IsAuthenticated, CanAccessSiteCreation]

def post(self, request):
"""
POST /edly_api/v1/edly_site_config/
"""
site = request.site
site_partner = Partner.objects.get(site=site)
request_data = request.data.get('discovery', {})
current_plan = request_data.get('DJANGO_SETTINGS_OVERRIDE', {}).get('CURRENT_PLAN')
if current_plan == CoursePlans.DEACTIVATED:
site_partner.is_disabled = True
site_partner.save()

return Response('Discovery site updated successfully', status=status.HTTP_200_OK)