This commit is contained in:
mike12345567 2021-07-22 22:37:20 +01:00
parent 155e30965f
commit 1153001af8
5 changed files with 32 additions and 8 deletions

View File

@ -338,7 +338,10 @@ class TestConfiguration {
if (!email || !password) { if (!email || !password) {
await this.createUser() await this.createUser()
} }
await createASession(userId, { sessionId: "sessionid", tenantId: TENANT_ID }) await createASession(userId, {
sessionId: "sessionid",
tenantId: TENANT_ID,
})
// have to fake this // have to fake this
const auth = { const auth = {
userId, userId,

View File

@ -62,7 +62,10 @@ class TestConfiguration {
null, null,
controllers.users.save controllers.users.save
) )
await createASession("us_uuid1", { sessionId: "sessionid", tenantId: TENANT_ID }) await createASession("us_uuid1", {
sessionId: "sessionid",
tenantId: TENANT_ID,
})
} }
} }

View File

@ -6,7 +6,11 @@ const {
GLOBAL_OWNER, GLOBAL_OWNER,
} = require("../index") } = require("../index")
const { join } = require("path") const { join } = require("path")
const { getTemplateParams, getTenantIdFromCtx, getGlobalDB } = require("@budibase/auth/db") const {
getTemplateParams,
getTenantIdFromCtx,
getGlobalDB,
} = require("@budibase/auth/db")
exports.EmailTemplates = { exports.EmailTemplates = {
[EmailTemplatePurpose.PASSWORD_RECOVERY]: readStaticFile( [EmailTemplatePurpose.PASSWORD_RECOVERY]: readStaticFile(
@ -53,7 +57,7 @@ exports.getTemplatesCtx = async (ctx, opts = {}) => {
return exports.getTemplates(tenantId, opts) return exports.getTemplates(tenantId, opts)
} }
exports.getTemplates = async (tenantId, { ownerId, type, id} = {}) => { exports.getTemplates = async (tenantId, { ownerId, type, id } = {}) => {
const db = getGlobalDB(tenantId) const db = getGlobalDB(tenantId)
const response = await db.allDocs( const response = await db.allDocs(
getTemplateParams(ownerId || GLOBAL_OWNER, id, { getTemplateParams(ownerId || GLOBAL_OWNER, id, {

View File

@ -68,7 +68,13 @@ async function getLinkCode(purpose, email, user, info = null) {
* @param {string|null} contents if using a custom template can supply contents for context. * @param {string|null} contents if using a custom template can supply contents for context.
* @return {Promise<string>} returns the built email HTML if all provided parameters were valid. * @return {Promise<string>} returns the built email HTML if all provided parameters were valid.
*/ */
async function buildEmail(tenantId, purpose, email, context, { user, contents } = {}) { async function buildEmail(
tenantId,
purpose,
email,
context,
{ user, contents } = {}
) {
// this isn't a full email // this isn't a full email
if (FULL_EMAIL_PURPOSES.indexOf(purpose) === -1) { if (FULL_EMAIL_PURPOSES.indexOf(purpose) === -1) {
throw `Unable to build an email of type ${purpose}` throw `Unable to build an email of type ${purpose}`
@ -160,7 +166,10 @@ exports.sendEmail = async (
const message = { const message = {
from: from || config.from, from: from || config.from,
to: email, to: email,
html: await buildEmail(tenantId, purpose, email, context, { user, contents }), html: await buildEmail(tenantId, purpose, email, context, {
user,
contents,
}),
} }
if (subject || config.subject) { if (subject || config.subject) {
message.subject = await processString(subject || config.subject, context) message.subject = await processString(subject || config.subject, context)

View File

@ -34,7 +34,9 @@ exports.getSettingsTemplateContext = async (tenantId, purpose, code = null) => {
[InternalTemplateBindings.COMPANY]: settings.company || BASE_COMPANY, [InternalTemplateBindings.COMPANY]: settings.company || BASE_COMPANY,
[InternalTemplateBindings.DOCS_URL]: [InternalTemplateBindings.DOCS_URL]:
settings.docsUrl || "https://docs.budibase.com/", settings.docsUrl || "https://docs.budibase.com/",
[InternalTemplateBindings.LOGIN_URL]: checkSlashesInUrl(addTenantToUrl(`${URL}/login`, tenantId)), [InternalTemplateBindings.LOGIN_URL]: checkSlashesInUrl(
addTenantToUrl(`${URL}/login`, tenantId)
),
[InternalTemplateBindings.CURRENT_DATE]: new Date().toISOString(), [InternalTemplateBindings.CURRENT_DATE]: new Date().toISOString(),
[InternalTemplateBindings.CURRENT_YEAR]: new Date().getFullYear(), [InternalTemplateBindings.CURRENT_YEAR]: new Date().getFullYear(),
} }
@ -49,7 +51,10 @@ exports.getSettingsTemplateContext = async (tenantId, purpose, code = null) => {
case EmailTemplatePurpose.INVITATION: case EmailTemplatePurpose.INVITATION:
context[InternalTemplateBindings.INVITE_CODE] = code context[InternalTemplateBindings.INVITE_CODE] = code
context[InternalTemplateBindings.INVITE_URL] = checkSlashesInUrl( context[InternalTemplateBindings.INVITE_URL] = checkSlashesInUrl(
addTenantToUrl(`${URL}/builder/invite?code=${code}&tenantId=${tenantId}`, tenantId) addTenantToUrl(
`${URL}/builder/invite?code=${code}&tenantId=${tenantId}`,
tenantId
)
) )
break break
} }