Skip to content
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
4 changes: 4 additions & 0 deletions django_email_learning/platform/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ class UserResponse(BaseModel):
model_config = ConfigDict(from_attributes=True)


class Identifier(BaseModel):
id: int


class CreateCourseRequest(BaseModel):
title: str = Field(min_length=1, examples=["Introduction to Python"])
slug: str = Field(
Expand Down
6 changes: 6 additions & 0 deletions django_email_learning/platform/api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from django_email_learning.platform.api.views import (
ApiKeyView,
GetOrCreateUserByEmail,
SendLessonToPlatformUser,
SingleApiKeyView,
CourseView,
EnrollmentsView,
Expand Down Expand Up @@ -92,6 +93,11 @@
EnrollmentsStatisticsView.as_view(),
name="enrollments_statistics_view",
),
path(
"organizations/<int:organization_id>/send-lesson/",
SendLessonToPlatformUser.as_view(),
name="send_lesson_to_platform_user_view",
),
path(
"organizations/<int:organization_id>/file/",
FileView.as_view(),
Expand Down
34 changes: 34 additions & 0 deletions django_email_learning/platform/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
from pydantic import ValidationError
from enum import StrEnum
from django_email_learning.services.command_models.enroll_command import EnrollCommand
from django_email_learning.services.command_models.send_lesson_command import (
SendLessonCommand,
)
from django_email_learning.services.command_models.verify_enrollment_command import (
VerifyEnrollmentCommand,
)
Expand Down Expand Up @@ -628,6 +631,37 @@ def post(self, request, *args, **kwargs) -> JsonResponse: # type: ignore[no-unt
return JsonResponse({"error": str(e)}, status=409)


@method_decorator(accessible_for(roles={"admin", "editor"}), name="post")
class SendLessonToPlatformUser(View):
def post(self, request, *args, **kwargs) -> JsonResponse: # type: ignore[no-untyped-def]
if not request.user.email:
return JsonResponse(
{"error": "User does not have an email address"}, status=400
)
payload = json.loads(request.body)
serializer = serializers.Identifier.model_validate(payload)
email = request.user.email
try:
# Accept course content id directly (used by platform content table),
# with a lesson-id fallback for backward compatibility.
course_content = CourseContent.objects.filter(
id=serializer.id,
type="lesson",
course__organization_id=kwargs["organization_id"],
).first()
if course_content is None:
course_content = CourseContent.objects.get(
lesson_id=serializer.id,
course__organization_id=kwargs["organization_id"],
)
SendLessonCommand(content_id=course_content.id, email=email).execute()
except CourseContent.DoesNotExist:
return JsonResponse({"error": "Lesson not found"}, status=404)
return JsonResponse(
{"message": "Email content logged successfully"}, status=200
)


@method_decorator(accessible_for(roles={"admin", "editor"}), name="post")
@method_decorator(accessible_for(roles={"admin", "editor"}), name="delete")
class FileView(View):
Expand Down
3 changes: 3 additions & 0 deletions django_email_learning/platform/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ def get_locale_messages(self) -> Dict[str, str]:
"waiting_time": _("Waiting Time"),
"title": _("Title"),
"add_quiz": _("Add Quiz"),
"send_lesson_to_yourself": _("Send it to yourself"),
"add_lesson": _("Add Lesson"),
"lesson": _("Lesson"),
"quiz": _("Quiz"),
Expand Down Expand Up @@ -284,6 +285,8 @@ def get_locale_messages(self) -> Dict[str, str]:
"cancel": _("Cancel"),
"delete": _("Delete"),
"save_lesson": _("Save Lesson"),
"lesson_saved_success": _("Lesson content saved successfully."),
"lesson_unsaved_changes_hint": _("You have unsaved changes."),
"save_quiz": _("Save Quiz"),
"quiz_title": _("Quiz Title"),
"add_question": _("Add Question"),
Expand Down
Loading