diff --git a/backend/lcfs/web/api/email/services.py b/backend/lcfs/web/api/email/services.py
index 856874d92..602283e03 100644
--- a/backend/lcfs/web/api/email/services.py
+++ b/backend/lcfs/web/api/email/services.py
@@ -36,9 +36,12 @@ def __init__(self, repo: CHESEmailRepository = Depends()):
self._token_expiry = None
self._validate_configuration()
- # Initialize template environment
+ # Update template directory path to the root templates directory
template_dir = os.path.join(os.path.dirname(__file__), "templates")
- self.template_env = Environment(loader=FileSystemLoader(template_dir))
+ self.template_env = Environment(
+ loader=FileSystemLoader(template_dir),
+ autoescape=True # Enable autoescaping for security
+ )
def _validate_configuration(self):
"""
@@ -63,7 +66,8 @@ async def send_notification_email(
notification_type, organization_id
)
if not recipient_emails:
- logger.info(f"No subscribers for notification type: {notification_type}")
+ logger.info(f"""No subscribers for notification type: {
+ notification_type}""")
return False
# Render the email content
@@ -84,15 +88,16 @@ def _render_email_template(
) -> str:
"""
Render an email template using a predefined mapping of template names to file paths.
+ Raises an exception if template is not found.
"""
- # Fetch template file path from the imported mapping
- template_file = TEMPLATE_MAPPING.get(
- template_name, TEMPLATE_MAPPING["default"]
- )
-
- # Render the template
- template = self.template_env.get_template(template_file)
- return template.render(context)
+ try:
+ template_file = TEMPLATE_MAPPING[template_name]
+ template = self.template_env.get_template(template_file)
+ return template.render(**context)
+ except Exception as e:
+ logger.error(f"Template rendering error: {str(e)}")
+ raise ValueError(
+ f"Failed to render email template for {template_name}")
def _build_email_payload(
self, recipients: List[str], context: Dict[str, Any], body: str
diff --git a/backend/lcfs/web/api/email/template_mapping.py b/backend/lcfs/web/api/email/template_mapping.py
index d31291666..4aa78e163 100644
--- a/backend/lcfs/web/api/email/template_mapping.py
+++ b/backend/lcfs/web/api/email/template_mapping.py
@@ -16,5 +16,4 @@
"IDIR_DIRECTOR__COMPLIANCE_REPORT__MANAGER_RECOMMENDATION": "idir_director__compliance_report__manager_recommendation.html",
"IDIR_DIRECTOR__INITIATIVE_AGREEMENT__ANALYST_RECOMMENDATION": "idir_director__initiative_agreement__analyst_recommendation.html",
"IDIR_DIRECTOR__TRANSFER__ANALYST_RECOMMENDATION": "idir_director__transfer__analyst_recommendation.html",
- "default": "default.html",
}
diff --git a/backend/lcfs/web/api/email/templates/bceid__compliance_report__director_assessment.html b/backend/lcfs/web/api/email/templates/bceid__compliance_report__director_assessment.html
new file mode 100644
index 000000000..56009ef1b
--- /dev/null
+++ b/backend/lcfs/web/api/email/templates/bceid__compliance_report__director_assessment.html
@@ -0,0 +1,3 @@
+{% extends 'notification_base.html' %}
+{% set notification_type = 'Credit Record' %}
+{% set url_slug = 'credit-records' %}
\ No newline at end of file
diff --git a/backend/lcfs/web/api/email/templates/bceid__initiative_agreement__director_approval.html b/backend/lcfs/web/api/email/templates/bceid__initiative_agreement__director_approval.html
new file mode 100644
index 000000000..35e2912d7
--- /dev/null
+++ b/backend/lcfs/web/api/email/templates/bceid__initiative_agreement__director_approval.html
@@ -0,0 +1,3 @@
+{% extends 'notification_base.html' %}
+{% set notification_type = 'Initiative Agreement' %}
+{% set url_slug = 'initiative-agreement' %}
\ No newline at end of file
diff --git a/backend/lcfs/web/api/email/templates/bceid__transfer__director_decision.html b/backend/lcfs/web/api/email/templates/bceid__transfer__director_decision.html
new file mode 100644
index 000000000..18063fc72
--- /dev/null
+++ b/backend/lcfs/web/api/email/templates/bceid__transfer__director_decision.html
@@ -0,0 +1,3 @@
+{% extends 'notification_base.html' %}
+{% set notification_type = 'Transfer' %}
+{% set url_slug = 'transfers' %}
\ No newline at end of file
diff --git a/backend/lcfs/web/api/email/templates/bceid__transfer__partner_actions.html b/backend/lcfs/web/api/email/templates/bceid__transfer__partner_actions.html
new file mode 100644
index 000000000..18063fc72
--- /dev/null
+++ b/backend/lcfs/web/api/email/templates/bceid__transfer__partner_actions.html
@@ -0,0 +1,3 @@
+{% extends 'notification_base.html' %}
+{% set notification_type = 'Transfer' %}
+{% set url_slug = 'transfers' %}
\ No newline at end of file
diff --git a/backend/lcfs/web/api/email/templates/default.html b/backend/lcfs/web/api/email/templates/default.html
deleted file mode 100644
index 18e1cd851..000000000
--- a/backend/lcfs/web/api/email/templates/default.html
+++ /dev/null
@@ -1,10 +0,0 @@
-
-
- System Notification
- A {{ email_type }} has occurred in the Low Carbon Fuel Reporting System.
-
- For more details, please visit: {{ link }}
-
- You received this email because you subscribed to notifications.
-
-
\ No newline at end of file
diff --git a/backend/lcfs/web/api/email/templates/idir_analyst__compliance_report__director_decision.html b/backend/lcfs/web/api/email/templates/idir_analyst__compliance_report__director_decision.html
new file mode 100644
index 000000000..56009ef1b
--- /dev/null
+++ b/backend/lcfs/web/api/email/templates/idir_analyst__compliance_report__director_decision.html
@@ -0,0 +1,3 @@
+{% extends 'notification_base.html' %}
+{% set notification_type = 'Credit Record' %}
+{% set url_slug = 'credit-records' %}
\ No newline at end of file
diff --git a/backend/lcfs/web/api/email/templates/idir_analyst__compliance_report__manager_recommendation.html b/backend/lcfs/web/api/email/templates/idir_analyst__compliance_report__manager_recommendation.html
new file mode 100644
index 000000000..56009ef1b
--- /dev/null
+++ b/backend/lcfs/web/api/email/templates/idir_analyst__compliance_report__manager_recommendation.html
@@ -0,0 +1,3 @@
+{% extends 'notification_base.html' %}
+{% set notification_type = 'Credit Record' %}
+{% set url_slug = 'credit-records' %}
\ No newline at end of file
diff --git a/backend/lcfs/web/api/email/templates/idir_analyst__compliance_report__submitted_for_review.html b/backend/lcfs/web/api/email/templates/idir_analyst__compliance_report__submitted_for_review.html
new file mode 100644
index 000000000..56009ef1b
--- /dev/null
+++ b/backend/lcfs/web/api/email/templates/idir_analyst__compliance_report__submitted_for_review.html
@@ -0,0 +1,3 @@
+{% extends 'notification_base.html' %}
+{% set notification_type = 'Credit Record' %}
+{% set url_slug = 'credit-records' %}
\ No newline at end of file
diff --git a/backend/lcfs/web/api/email/templates/idir_analyst__initiative_agreement__returned_to_analyst.html b/backend/lcfs/web/api/email/templates/idir_analyst__initiative_agreement__returned_to_analyst.html
new file mode 100644
index 000000000..43a49a9d1
--- /dev/null
+++ b/backend/lcfs/web/api/email/templates/idir_analyst__initiative_agreement__returned_to_analyst.html
@@ -0,0 +1,3 @@
+{% extends 'notification_base.html' %}
+{% set notification_type = 'Initiative Agreement' %}
+{% set url_slug = 'initiative-agreements' %}
\ No newline at end of file
diff --git a/backend/lcfs/web/api/email/templates/idir_analyst__transfer__director_recorded.html b/backend/lcfs/web/api/email/templates/idir_analyst__transfer__director_recorded.html
new file mode 100644
index 000000000..9ddb47ee8
--- /dev/null
+++ b/backend/lcfs/web/api/email/templates/idir_analyst__transfer__director_recorded.html
@@ -0,0 +1,3 @@
+{% extends 'notification_base.html' %}
+{% set notification_type = 'Transfer' %}
+{% set url_slug = 'transfer-requests' %}
\ No newline at end of file
diff --git a/backend/lcfs/web/api/email/templates/idir_analyst__transfer__rescinded_action.html b/backend/lcfs/web/api/email/templates/idir_analyst__transfer__rescinded_action.html
new file mode 100644
index 000000000..9ddb47ee8
--- /dev/null
+++ b/backend/lcfs/web/api/email/templates/idir_analyst__transfer__rescinded_action.html
@@ -0,0 +1,3 @@
+{% extends 'notification_base.html' %}
+{% set notification_type = 'Transfer' %}
+{% set url_slug = 'transfer-requests' %}
\ No newline at end of file
diff --git a/backend/lcfs/web/api/email/templates/idir_analyst__transfer__submitted_for_review.html b/backend/lcfs/web/api/email/templates/idir_analyst__transfer__submitted_for_review.html
new file mode 100644
index 000000000..9ddb47ee8
--- /dev/null
+++ b/backend/lcfs/web/api/email/templates/idir_analyst__transfer__submitted_for_review.html
@@ -0,0 +1,3 @@
+{% extends 'notification_base.html' %}
+{% set notification_type = 'Transfer' %}
+{% set url_slug = 'transfer-requests' %}
\ No newline at end of file
diff --git a/backend/lcfs/web/api/email/templates/idir_compliance_manager__compliance_report__analyst_recommendation.html b/backend/lcfs/web/api/email/templates/idir_compliance_manager__compliance_report__analyst_recommendation.html
new file mode 100644
index 000000000..56009ef1b
--- /dev/null
+++ b/backend/lcfs/web/api/email/templates/idir_compliance_manager__compliance_report__analyst_recommendation.html
@@ -0,0 +1,3 @@
+{% extends 'notification_base.html' %}
+{% set notification_type = 'Credit Record' %}
+{% set url_slug = 'credit-records' %}
\ No newline at end of file
diff --git a/backend/lcfs/web/api/email/templates/idir_compliance_manager__compliance_report__director_assessment.html b/backend/lcfs/web/api/email/templates/idir_compliance_manager__compliance_report__director_assessment.html
new file mode 100644
index 000000000..56009ef1b
--- /dev/null
+++ b/backend/lcfs/web/api/email/templates/idir_compliance_manager__compliance_report__director_assessment.html
@@ -0,0 +1,3 @@
+{% extends 'notification_base.html' %}
+{% set notification_type = 'Credit Record' %}
+{% set url_slug = 'credit-records' %}
\ No newline at end of file
diff --git a/backend/lcfs/web/api/email/templates/idir_compliance_manager__compliance_report__submitted_for_review.html b/backend/lcfs/web/api/email/templates/idir_compliance_manager__compliance_report__submitted_for_review.html
new file mode 100644
index 000000000..56009ef1b
--- /dev/null
+++ b/backend/lcfs/web/api/email/templates/idir_compliance_manager__compliance_report__submitted_for_review.html
@@ -0,0 +1,3 @@
+{% extends 'notification_base.html' %}
+{% set notification_type = 'Credit Record' %}
+{% set url_slug = 'credit-records' %}
\ No newline at end of file
diff --git a/backend/lcfs/web/api/email/templates/idir_director__compliance_report__manager_recommendation.html b/backend/lcfs/web/api/email/templates/idir_director__compliance_report__manager_recommendation.html
new file mode 100644
index 000000000..56009ef1b
--- /dev/null
+++ b/backend/lcfs/web/api/email/templates/idir_director__compliance_report__manager_recommendation.html
@@ -0,0 +1,3 @@
+{% extends 'notification_base.html' %}
+{% set notification_type = 'Credit Record' %}
+{% set url_slug = 'credit-records' %}
\ No newline at end of file
diff --git a/backend/lcfs/web/api/email/templates/idir_director__initiative_agreement__analyst_recommendation.html b/backend/lcfs/web/api/email/templates/idir_director__initiative_agreement__analyst_recommendation.html
new file mode 100644
index 000000000..43a49a9d1
--- /dev/null
+++ b/backend/lcfs/web/api/email/templates/idir_director__initiative_agreement__analyst_recommendation.html
@@ -0,0 +1,3 @@
+{% extends 'notification_base.html' %}
+{% set notification_type = 'Initiative Agreement' %}
+{% set url_slug = 'initiative-agreements' %}
\ No newline at end of file
diff --git a/backend/lcfs/web/api/email/templates/idir_director__transfer__analyst_recommendation.html b/backend/lcfs/web/api/email/templates/idir_director__transfer__analyst_recommendation.html
new file mode 100644
index 000000000..9ddb47ee8
--- /dev/null
+++ b/backend/lcfs/web/api/email/templates/idir_director__transfer__analyst_recommendation.html
@@ -0,0 +1,3 @@
+{% extends 'notification_base.html' %}
+{% set notification_type = 'Transfer' %}
+{% set url_slug = 'transfer-requests' %}
\ No newline at end of file
diff --git a/backend/lcfs/web/api/email/templates/initiative_approved.html b/backend/lcfs/web/api/email/templates/initiative_approved.html
deleted file mode 100644
index f2ae933b6..000000000
--- a/backend/lcfs/web/api/email/templates/initiative_approved.html
+++ /dev/null
@@ -1,8 +0,0 @@
-
-
- Initiative agreement approved notification
- IA ID: {{ initiative_agreement_id }}
- Compliance units: {{ compliance_units }}
- Effective date: {{ transaction_effective_date }}
-
-
\ No newline at end of file
diff --git a/backend/lcfs/web/api/email/templates/notification_base.html b/backend/lcfs/web/api/email/templates/notification_base.html
new file mode 100644
index 000000000..560b93243
--- /dev/null
+++ b/backend/lcfs/web/api/email/templates/notification_base.html
@@ -0,0 +1,109 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+ |
+
+ Low Carbon Fuels Standard Reporting System
+ |
+
+
+
+
+ This email was generated by the Government of British Columbia, Low Carbon Fuel Standard
+ portal.
+ A {{ notification_type }} update has occurred within the Low Carbon Fuel Standard portal.
+ For more details, please go to: https://lowcarbonfuels.gov.bc.ca/{{
+ url_slug }}
+
+ You received this email because you subscribed at the site above, to stop receiving these
+ email, log in to your account here: https://lowcarbonfuels.gov.bc.ca/notifications
+
+
+ |
+
+
+
+
+
+
\ No newline at end of file