Skip to content

Commit

Permalink
Merge pull request #82 from edly-io/tai/EDLY-6656
Browse files Browse the repository at this point in the history
Add Edly site config api - EDLY-6656
  • Loading branch information
taimoor-ahmed-1 authored May 14, 2024
2 parents 3ff19f4 + 62bb430 commit 24f0081
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
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)

0 comments on commit 24f0081

Please sign in to comment.