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
7 changes: 5 additions & 2 deletions django_email_learning/jobs/deliver_contents_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,12 @@ def run(self) -> None:
)

def get_delivery_queue(self) -> DeliveryQueueProtocol:
DJANGO_EMAIL_LEARNING_SETTINGS: dict = getattr(
settings, "DJANGO_EMAIL_LEARNING", {}
)
try:
return import_string(settings.DJANGO_EMAIL_LEARNING["DELIVERY_QUEUE"])
except (AttributeError, KeyError):
return import_string(DJANGO_EMAIL_LEARNING_SETTINGS["DELIVERY_QUEUE"])
except KeyError:
from django_email_learning.services.defaults.database_delivery_queue import (
DatabaseDeliveryQueue,
)
Expand Down
7 changes: 5 additions & 2 deletions django_email_learning/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,12 @@ def _fernet(cls, salt: str) -> Fernet:
salt=salt.encode(),
iterations=100000,
)
DJANGO_EMAIL_LEARNING_SETTINGS: dict = getattr(
settings, "DJANGO_EMAIL_LEARNING", {}
)
try:
secret = settings.DJANGO_EMAIL_LEARNING["ENCRYPTION_SECRET_KEY"]
except (AttributeError, KeyError):
secret = DJANGO_EMAIL_LEARNING_SETTINGS["ENCRYPTION_SECRET_KEY"]
except KeyError:
raise ImproperlyConfigured(
"DJANGO_EMAIL_LEARNING['ENCRYPTION_SECRET_KEY'] must be set in settings.py"
)
Expand Down
8 changes: 5 additions & 3 deletions django_email_learning/platform/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@

logger = logging.getLogger(__name__)

DJANGO_EMAIL_LEARNING_SETTINGS: dict = getattr(settings, "DJANGO_EMAIL_LEARNING", {})


@method_decorator(ensure_csrf_cookie, name="get")
@method_decorator(accessible_for(roles={"admin", "editor"}), name="post")
Expand Down Expand Up @@ -581,7 +583,7 @@ def post(self, request, *args, **kwargs) -> JsonResponse: # type: ignore[no-unt
form.save(
request=request,
use_https=request.is_secure(),
from_email=settings.DJANGO_EMAIL_LEARNING.get(
from_email=DJANGO_EMAIL_LEARNING_SETTINGS.get(
"FROM_EMAIL", settings.DEFAULT_FROM_EMAIL
),
email_template_name="emails/password_reset.txt",
Expand Down Expand Up @@ -831,10 +833,10 @@ def get(self, request, *args, **kwargs) -> JsonResponse: # type: ignore[no-unty

@staticmethod
def calculate_job_health_status(last_execution_started_at: datetime) -> str:
success_threshold = settings.DJANGO_EMAIL_LEARNING.get(
success_threshold = DJANGO_EMAIL_LEARNING_SETTINGS.get(
"JOB_HEALTH_SUCCESS_THRESHOLD_MINUTES", DEFAULT_SUCCESS_THRESHOLD_MINUTES
)
warning_threshold = settings.DJANGO_EMAIL_LEARNING.get(
warning_threshold = DJANGO_EMAIL_LEARNING_SETTINGS.get(
"JOB_HEALTH_WARNING_THRESHOLD_MINUTES", DEFAULT_WARNING_THRESHOLD_MINUTES
)
if not isinstance(success_threshold, int) or success_threshold <= 0:
Expand Down
16 changes: 16 additions & 0 deletions django_email_learning/platform/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
is_an_organization_member,
)
from typing import Dict, Any
from django.conf import settings


@method_decorator(login_required, name="dispatch")
Expand All @@ -36,10 +37,25 @@ def get_shared_context(self) -> Dict[str, Any]:
current_lang_code = get_language()
lang_info = get_language_info(current_lang_code)

DJANGO_EMAIL_LEARNING_SETTINGS: dict = getattr(
settings, "DJANGO_EMAIL_LEARNING", {}
)

return {
"appContext": {
"apiBaseUrl": reverse("django_email_learning:api_platform:root")[:-1],
"platformBaseUrl": reverse("django_email_learning:platform:root")[:-1],
"sidebarCustomComponent": {
"scriptUrl": DJANGO_EMAIL_LEARNING_SETTINGS.get("SIDEBAR", {})
.get("CUSTOM_COMPONENT", {})
.get("SCRIPT_URL"),
"componentTag": DJANGO_EMAIL_LEARNING_SETTINGS.get("SIDEBAR", {})
.get("CUSTOM_COMPONENT", {})
.get("COMPONENT_TAG"),
"styleUrl": DJANGO_EMAIL_LEARNING_SETTINGS.get("SIDEBAR", {})
.get("CUSTOM_COMPONENT", {})
.get("STYLE_URL"),
},
"userRole": role,
"direction": "rtl" if lang_info["bidi"] else "ltr",
"isPlatformAdmin": (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,11 @@ def execute(self) -> None:
reverse("django_email_learning:personalised:verify_enrollment")
+ f"?token={token}"
)
DJANGO_EMAIL_LEARNING_SETTINGS: dict = getattr(
settings, "DJANGO_EMAIL_LEARNING", {}
)
verification_link = (
settings.DJANGO_EMAIL_LEARNING["SITE_BASE_URL"] + verification_relative_path
DJANGO_EMAIL_LEARNING_SETTINGS["SITE_BASE_URL"] + verification_relative_path
)

template_context = {
Expand Down
9 changes: 6 additions & 3 deletions django_email_learning/services/email_sender_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,22 @@

class EmailSenderService:
def __init__(self) -> None:
DJANGO_EMAIL_LEARNING_SETTINGS: dict = getattr(
settings, "DJANGO_EMAIL_LEARNING", {}
)
try:
self.email_sender = import_string(
settings.DJANGO_EMAIL_LEARNING["EMAIL_SENDER"]
DJANGO_EMAIL_LEARNING_SETTINGS["EMAIL_SENDER"]
)
except (AttributeError, KeyError):
except KeyError:
from django_email_learning.services.defaults.email_sender import (
DjangoEmailSender,
)

self.email_sender = DjangoEmailSender()

try:
self.from_email = settings.DJANGO_EMAIL_LEARNING["FROM_EMAIL"]
self.from_email = DJANGO_EMAIL_LEARNING_SETTINGS["FROM_EMAIL"]
except (AttributeError, KeyError):
try:
self.from_email = settings.DEFAULT_FROM_EMAIL
Expand Down
6 changes: 6 additions & 0 deletions django_email_learning/templates/platform/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
<script>
localStorage.setItem('activeOrganizationId', '{{ activeOrganizationId | escapejs }}');
</script>
{% if appContext.sidebarCustomComponent.styleUrl %}
<link rel="stylesheet" href="{{ appContext.sidebarCustomComponent.styleUrl }}">
{% endif %}
{% if appContext.sidebarCustomComponent.scriptUrl %}
<script src="{{ appContext.sidebarCustomComponent.scriptUrl }}" type="module"></script>
{% endif %}
{{ appContext | json_script:"app-context" }}
{% block extra_head %}{% endblock %}
<meta charset="UTF-8" />
Expand Down
7 changes: 7 additions & 0 deletions django_service/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,13 @@
"SITE_BASE_URL": "http://localhost:8000",
"ENCRYPTION_SECRET_KEY": "your-very-secure-and-random-key",
"FROM_EMAIL": os.environ.get("FROM_EMAIL", "webmaster@localhost"),
"SIDEBAR": {
"CUSTOM_COMPONENT": {
"SCRIPT_URL": "https://cdn.jsdelivr.net/npm/ldrs/dist/auto/helix.js",
"STYLE_URL": None,
"COMPONENT_TAG": "<l-helix />",
}
},
}


Expand Down
5 changes: 3 additions & 2 deletions frontend/src/components/MenuBar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function MenuBar({activeOrganizationId, changeOrganizationCallback, showOrganiza
const [organizations, setOrganizations] = useState([])
const [deliverContentsJobStatus, setDeliverContentsJobStatus] = useState(null)
const [chip, setChip] = useState(null)
const { localeMessages, isPlatformAdmin, isOrganizationAdmin, direction, apiBaseUrl, platformBaseUrl } = useAppContext();
const { localeMessages, isPlatformAdmin, isOrganizationAdmin, direction, apiBaseUrl, platformBaseUrl, sidebarCustomComponent } = useAppContext();

const theme = useTheme();
const isMdUpScreen = useMediaQuery(theme.breakpoints.up('md'));
Expand Down Expand Up @@ -166,7 +166,7 @@ function MenuBar({activeOrganizationId, changeOrganizationCallback, showOrganiza
</Box>
</AppBar>
<Drawer anchor={direction === 'rtl' ? 'right' : 'left'} variant={drawerVariant} onClose={toggleMenuDrawer(false)} display={{md: "none" }} open={menuOpen} sx={{ '& .MuiDrawer-paper': { boxSizing: 'border-box', width: drawerWidth } }}
slotProps={{ backdrop: { sx: { backgroundColor: 'rgba(251, 251, 255, 0.57)', backdropFilter: 'blur(5px)' }}, paper: { sx: { boxShadow: '2px 0px 8px rgba(0, 0, 0, 0.1)'}}}}>
slotProps={{ backdrop: { sx: { backgroundColor: 'rgba(251, 251, 255, 0.57)', backdropFilter: 'blur(5px)' }}, paper: { sx: { borderRadius: 0, boxShadow: '2px 0px 8px rgba(0, 0, 0, 0.1)'}}}}>
<Box my={2} textAlign="center">
<img src={logoVerticalUrl} alt="Logo" style={{ width: "50%" }} />
</Box>
Expand All @@ -185,6 +185,7 @@ function MenuBar({activeOrganizationId, changeOrganizationCallback, showOrganiza
</MenuItem>
)) }
</MenuList>
{sidebarCustomComponent && <Box sx={{ height: "100px", width: "100%" }} dangerouslySetInnerHTML={{ __html: sidebarCustomComponent.componentTag }} />}
</Drawer>
</Box>)
}
Expand Down