Skip to content

Commit

Permalink
feat: adapt emails for selfhosting (#541)
Browse files Browse the repository at this point in the history
  • Loading branch information
hughcrt authored Sep 4, 2024
1 parent 7cea62a commit 08861e6
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 8 deletions.
20 changes: 14 additions & 6 deletions packages/backend/src/api/v1/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { jwtVerify } from "jose"
import { roles } from "shared"
import { z } from "zod"
import { signJWT } from "./auth/utils"
import config from "@/src/utils/config"

const users = new Router({
prefix: "/users",
Expand Down Expand Up @@ -131,14 +132,18 @@ users.get("/verify-email", async (ctx: Context) => {
const { orgId, name } = acc

const [project] = await sql`
SELECT id
FROM project
WHERE org_id = ${orgId}
select
id
from
project
where
org_id = ${orgId}
`
const id = project?.id

await sendEmail(WELCOME_EMAIL(email, name, id))
// redirect to home page
if (!config.IS_SELF_HOSTED) {
await sendEmail(WELCOME_EMAIL(email, name, id))
}
ctx.redirect(process.env.APP_URL!)
})

Expand Down Expand Up @@ -254,8 +259,11 @@ users.post("/", checkAccess("teamMembers", "create"), async (ctx: Context) => {
group by account.id
`

const link = org.samlEnabled
? process.env.APP_URL
: `${process.env.APP_URL}/join?token=${token}`

if (!org.samlEnabled) {
const link = `${process.env.APP_URL}/join?token=${token}`
await sendEmail(INVITE_EMAIL(email, org.name, link))
}

Expand Down
6 changes: 5 additions & 1 deletion packages/backend/src/emails/templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,16 @@ Please click on the following link to accept the invitation:
${inviteLink}
We're looking forward to having you on board!
${
!config.IS_SELF_HOSTED &&
`We're looking forward to having you on board!
You can reply to this email if you have any question.
Thanks
- The Lunary team
`
}
`,
}
}
Expand Down
5 changes: 4 additions & 1 deletion packages/backend/src/emails/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { signJWT } from "@/src/api/v1/auth/utils"
import { sendEmail } from "./sender"
import { CONFIRM_EMAIL } from "./templates"
import config from "../utils/config"

function sanitizeName(name: string): string {
return name.replace(/\s+/g, " ").trim()
Expand All @@ -17,5 +18,7 @@ export async function sendVerifyEmail(email: string, name: string = "") {

const confirmLink = `${process.env.APP_URL}/verify-email?token=${token}`

await sendEmail(CONFIRM_EMAIL(email, name, confirmLink))
if (!config.IS_SELF_HOSTED) {
await sendEmail(CONFIRM_EMAIL(email, name, confirmLink))
}
}
4 changes: 4 additions & 0 deletions packages/backend/src/jobs/resetUsage.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import sql from "@/src/utils/db"
import { sendSlackMessage } from "@/src/utils/notifications"
import { LIMITED_EMAIL, sendEmail } from "../emails"
import config from "../utils/config"

async function updateLimitedStatus() {
if (config.IS_SELF_HOSTED) {
return
}
// set limited = false for all users that have been under the limit
// for the last 30 days
const alreadyLimited = await sql`UPDATE "public"."org" p
Expand Down

0 comments on commit 08861e6

Please sign in to comment.