Skip to content

enhance: email template functions to include tenant and organization in header and footer#852

Merged
nevil-mathew merged 1 commit intodevelopfrom
notification-temp-fix
Oct 24, 2025
Merged

enhance: email template functions to include tenant and organization in header and footer#852
nevil-mathew merged 1 commit intodevelopfrom
notification-temp-fix

Conversation

@nevil-mathew
Copy link
Collaborator

@nevil-mathew nevil-mathew commented Oct 24, 2025

Summary by CodeRabbit

  • Bug Fixes
    • Improved email template scoping to ensure email headers and footers are properly filtered and isolated by tenant and organization, preventing potential cross-tenant data access issues.

@coderabbitai
Copy link

coderabbitai bot commented Oct 24, 2025

Walkthrough

The notificationTemplate.js file is updated to add tenant and organization scoping to email header and footer retrieval functions. The getEmailHeader and getEmailFooter functions now accept tenantCode and organizationCode parameters and propagate them into their respective database query filters. The findOneEmailTemplate function invokes these functions with the additional parameters.

Changes

Cohort / File(s) Summary
Email template multi-tenant scoping
src/database/queries/notificationTemplate.js
Extended getEmailHeader and getEmailFooter to accept and filter by tenantCode and organizationCode parameters; updated findOneEmailTemplate to pass these values when querying headers and footers.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Poem

🐰 Headers and footers now know where they dwell,
With tenants and orgs in their SQL spell,
Each query rings out with a scope-filtered bell,
Multi-tenant harmony—all's now well! ✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The pull request title "enhance: email template functions to include tenant and organization in header and footer" accurately and directly describes the primary changes in the changeset. The modifications focus on enhancing email template functions (getEmailHeader, getEmailFooter, and findOneEmailTemplate) to accept and propagate tenant and organization codes into their query filters, which is precisely what the title conveys. The title is concise, specific, and uses clear language that would help a developer quickly understand the nature of the enhancement when scanning through the project history.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch notification-temp-fix

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/database/queries/notificationTemplate.js (1)

58-58: Add default value for tenantCode parameter.

The function signature has tenantCode without a default value, but src/services/organization.js line 111 calls this function with only one parameter. This causes tenantCode to be undefined, which is then used in the filter at line 67.

Apply this diff to fix the backwards compatibility issue:

-exports.findOneEmailTemplate = async (code, orgCode = null, tenantCode) => {
+exports.findOneEmailTemplate = async (code, orgCode = null, tenantCode = null) => {

Additionally, you may need to conditionally add tenant_code to the filter only when it's provided:

 		const filter = {
 			code: code,
 			type: 'email',
-			tenant_code: tenantCode,
 			status: common.ACTIVE_STATUS,
 			organization_code:
 				orgCode && orgCode != defaultOrgCode
 					? {
 							[Op.or]: [orgCode, defaultOrgCode],
 					  }
 					: defaultOrgCode,
 		}
+		
+		if (tenantCode) {
+			filter.tenant_code = tenantCode
+		}
♻️ Duplicate comments (1)
src/database/queries/notificationTemplate.js (1)

97-101: Same fallback concern applies to footer retrieval.

The footer lookup has the same limitation as the header: no fallback to DEFAULT_ORGANISATION_CODE. This could result in missing footers when the main template uses the default organization fallback.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f968909 and 2cde904.

📒 Files selected for processing (1)
  • src/database/queries/notificationTemplate.js (3 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
src/database/queries/**

⚙️ CodeRabbit configuration file

Review database queries for performance. Check for N+1 problems and ensure indexes can be used.

Files:

  • src/database/queries/notificationTemplate.js
🧬 Code graph analysis (1)
src/database/queries/notificationTemplate.js (2)
src/services/organization.js (2)
  • templateData (112-112)
  • tenantCode (281-281)
src/utils/notification.js (2)
  • templateData (14-18)
  • templateData (58-62)

@nevil-mathew nevil-mathew merged commit 0ff1979 into develop Oct 24, 2025
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant