This commit is contained in:
mike12345567 2021-07-22 22:37:20 +01:00
parent 313302cae2
commit 3f7bafe23d
5 changed files with 32 additions and 8 deletions

View File

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

View File

@ -62,7 +62,10 @@ class TestConfiguration {
null,
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,
} = require("../index")
const { join } = require("path")
const { getTemplateParams, getTenantIdFromCtx, getGlobalDB } = require("@budibase/auth/db")
const {
getTemplateParams,
getTenantIdFromCtx,
getGlobalDB,
} = require("@budibase/auth/db")
exports.EmailTemplates = {
[EmailTemplatePurpose.PASSWORD_RECOVERY]: readStaticFile(
@ -53,7 +57,7 @@ exports.getTemplatesCtx = async (ctx, 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 response = await db.allDocs(
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.
* @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
if (FULL_EMAIL_PURPOSES.indexOf(purpose) === -1) {
throw `Unable to build an email of type ${purpose}`
@ -160,7 +166,10 @@ exports.sendEmail = async (
const message = {
from: from || config.from,
to: email,
html: await buildEmail(tenantId, purpose, email, context, { user, contents }),
html: await buildEmail(tenantId, purpose, email, context, {
user,
contents,
}),
}
if (subject || config.subject) {
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.DOCS_URL]:
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_YEAR]: new Date().getFullYear(),
}
@ -49,7 +51,10 @@ exports.getSettingsTemplateContext = async (tenantId, purpose, code = null) => {
case EmailTemplatePurpose.INVITATION:
context[InternalTemplateBindings.INVITE_CODE] = code
context[InternalTemplateBindings.INVITE_URL] = checkSlashesInUrl(
addTenantToUrl(`${URL}/builder/invite?code=${code}&tenantId=${tenantId}`, tenantId)
addTenantToUrl(
`${URL}/builder/invite?code=${code}&tenantId=${tenantId}`,
tenantId
)
)
break
}