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
12 changes: 12 additions & 0 deletions django_email_learning/public/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
)


def get_terms_of_service_url() -> str | None:
return settings.DJANGO_EMAIL_LEARNING.get("TERMS_OF_SERVICE_URL") # type: ignore[return-value]


def get_organization_json_ld_links(organization: Organization) -> dict[str, object]:
json_ld_links: dict[str, object] = {"url": organization.public_url}
same_as: list[str] = []
Expand Down Expand Up @@ -165,6 +169,7 @@ def get_context_data(self, **kwargs) -> dict: # type: ignore[no-untyped-def]
"organization": organization_data.model_dump(),
"enrollApiUrl": f"{settings.DJANGO_EMAIL_LEARNING['SITE_BASE_URL']}{enroll_api_path}",
"direction": "rtl" if lang_info["bidi"] else "ltr",
"termsOfServiceUrl": get_terms_of_service_url(),
"localeMessages": {
"courses": _("Courses"),
"enroll_now": _("Enroll Now"),
Expand All @@ -188,6 +193,9 @@ def get_context_data(self, **kwargs) -> dict: # type: ignore[no-untyped-def]
"linkedin_page": _("LinkedIn Page"),
"youtube_channel": _("YouTube Channel"),
"website": _("Website"),
"terms_of_service_confirmation": _(
"By enrolling, you agree to our <a href='TERMS_OF_SERVICE_URL' target='_blank'>Terms of Service</a>."
),
},
}
context["organization_name"] = organization.name
Expand Down Expand Up @@ -270,6 +278,7 @@ def get_context_data(self, **kwargs) -> dict: # type: ignore[no-untyped-def]
"organization": organization_data.model_dump(),
"enrollApiUrl": f"{settings.DJANGO_EMAIL_LEARNING['SITE_BASE_URL']}{enroll_api_path}",
"direction": "rtl" if lang_info["bidi"] else "ltr",
"termsOfServiceUrl": get_terms_of_service_url(),
"localeMessages": {
"enroll_now": _("Enroll Now"),
"enrol_for_course": _("Enroll for COURSE_NAME"),
Expand All @@ -294,6 +303,9 @@ def get_context_data(self, **kwargs) -> dict: # type: ignore[no-untyped-def]
"continue": _("Continue"),
"target_audience_title": _("Who is this course for?"),
"external_references_title": _("External References"),
"terms_of_service_confirmation": _(
"By enrolling, you agree to our <a href='TERMS_OF_SERVICE_URL' target='_blank'>Terms of Service</a>."
),
},
}
context["course_title"] = course.title
Expand Down
1 change: 1 addition & 0 deletions django_service/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
"SITE_BASE_URL": "http://localhost:8000",
"ENCRYPTION_SECRET_KEY": "your-very-secure-and-random-key",
"FROM_EMAIL": os.environ.get("FROM_EMAIL", "webmaster@localhost"),
"TERMS_OF_SERVICE_URL": "https://www.example.com/terms",
"AI": {
"OPENAI_API_KEY": os.environ.get("OPENAI_API_KEY"),
"TEXT_EDITING_MODEL": LanguageModel.GPT_4O_MINI.model_name,
Expand Down
12 changes: 12 additions & 0 deletions docs/source/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,18 @@ The default email address for outgoing course emails. If not specified, falls ba
'FROM_EMAIL': 'courses@yourdomain.com',
}

**TERMS_OF_SERVICE_URL**

Optional link to your terms of service. When provided, this link is displayed in the public enrollment dialog so learners can review your terms before submitting their email address.

.. code-block:: python

DJANGO_EMAIL_LEARNING = {
'SITE_BASE_URL': 'https://yourdomain.com',
'ENCRYPTION_SECRET_KEY': 'your-very-long-random-string',
'TERMS_OF_SERVICE_URL': 'https://yourdomain.com/terms',
}

**SIDEBAR.CUSTOM_COMPONENT**

Optional configuration for injecting a custom component in the platform sidebar.
Expand Down
23 changes: 21 additions & 2 deletions frontend/public/components/EnrollmentForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const EnrollmentForm = ({course_title, course_slug, organization_id, endpoint, o
const [isProcessing, setIsProcessing] = React.useState(false);
const [csrfToken, setCsrfToken] = React.useState(getCookie('csrftoken'));
const [showReloadDialog, setShowReloadDialog] = React.useState(false);
const { localeMessages } = useAppContext();
const { localeMessages, termsOfServiceUrl } = useAppContext();

useEffect(() => {
if (!csrfToken) {
Expand Down Expand Up @@ -95,8 +95,27 @@ const EnrollmentForm = ({course_title, course_slug, organization_id, endpoint, o
enroll();
}
}} />
{termsOfServiceUrl && (
<Typography
variant='caption'
sx={{
display: 'block',
mt: 2.5,
mb: 1.5,
color: 'text.secondary',
lineHeight: 1.6,
'& a': {
color: 'primary.main',
textDecoration: 'underline',
fontWeight: 500,
},
}}
>
<span dangerouslySetInnerHTML={{ __html: localeMessages['terms_of_service_confirmation'].replace('TERMS_OF_SERVICE_URL', termsOfServiceUrl) }} />
</Typography>
)}
<input type="hidden" name="course_slug" value={course_slug} />
<Box sx={{ mt: 2, textAlign: 'right' }}>
<Box sx={{ mt: 1.5, textAlign: 'right' }}>
<Button variant="outlined" sx={{ mx: 1 }} onClick={onCancle}>
{localeMessages['cancel']}
</Button>
Expand Down
35 changes: 35 additions & 0 deletions tests/public/test_views/test_public_course_view.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
import json

from django.conf import settings
from django.test import override_settings
from django.urls import reverse

from django_email_learning.models import ExternalReference
import pytest


@pytest.fixture
def tos_settings(request):
with override_settings(
DJANGO_EMAIL_LEARNING={
**settings.DJANGO_EMAIL_LEARNING,
"TERMS_OF_SERVICE_URL": request.param,
}
):
yield settings.DJANGO_EMAIL_LEARNING["TERMS_OF_SERVICE_URL"]


def test_course_view_anonymous_client(
Expand Down Expand Up @@ -65,3 +79,24 @@ def test_course_view_non_existent_course(db, anonymous_client):
)
response = anonymous_client.get(url)
assert response.status_code == 404


@pytest.mark.parametrize(
"tos_settings",
["https://example.com/terms", None],
indirect=True,
)
def test_course_view_includes_terms_of_service_url_when_configured(
db, anonymous_client, course, tos_settings
):
course.enabled = True
course.save()

url = reverse(
"django_email_learning:public:course_view",
kwargs={"organization_id": 1, "course_slug": course.slug},
)
response = anonymous_client.get(url)

assert response.status_code == 200
assert response.context["appContext"]["termsOfServiceUrl"] == tos_settings