Browse Source

fix domain

master
mortezaei 7 months ago
parent
commit
6c5cce5bb0
  1. 15
      apps/course/views/course.py

15
apps/course/views/course.py

@ -334,7 +334,7 @@ class CourseOnlineClassTokenAPIView(GenericAPIView):
}) })
redirect_path = serializer.validated_data.get('redirect_path') redirect_path = serializer.validated_data.get('redirect_path')
base_url = self._build_base_url(redirect_path)
base_url = self._build_base_url(request, redirect_path)
entry_url = manager.build_entry_url(token, base_url=base_url) entry_url = manager.build_entry_url(token, base_url=base_url)
return Response({ return Response({
@ -343,12 +343,13 @@ class CourseOnlineClassTokenAPIView(GenericAPIView):
'expires_in': getattr(settings, 'ONLINE_CLASS_TOKEN_TTL', 300), 'expires_in': getattr(settings, 'ONLINE_CLASS_TOKEN_TTL', 300),
}, status=status.HTTP_201_CREATED) }, status=status.HTTP_201_CREATED)
def _build_base_url(self, redirect_path=None) -> str:
domain = getattr(settings, 'ONLINE_CLASS_FRONTEND_DOMAIN', getattr(settings, 'SITE_DOMAIN', '')).rstrip('/')
if redirect_path:
sanitized = redirect_path.strip('/')
return f"{domain}/{sanitized}" if domain else f"/{sanitized}"
return domain
def _build_base_url(self, request, redirect_path=None) -> str:
base_uri = request.build_absolute_uri('/')
domain = base_uri.rstrip('/')
default_path = getattr(settings, 'ONLINE_CLASS_DEFAULT_PATH', 'join-class')
target_path = redirect_path or default_path
sanitized = str(target_path).strip('/')
return f"{domain}/{sanitized}" if sanitized else domain
@staticmethod @staticmethod
def _user_has_access(user, course: Course) -> bool: def _user_has_access(user, course: Course) -> bool:

Loading…
Cancel
Save