All files / utils/emailTemplates accountBanned.js

100% Statements 11/11
100% Branches 12/12
100% Functions 2/2
100% Lines 11/11

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105            2x   2x                                                                                                                         4x 4x 4x   4x                   4x 9x   4x                           4x     2x  
/**
 * "Your account was suspended" email (UC-REPORT-008.1): a banned user can no
 * longer sign in to read the in-app notification, so the statement of reasons
 * reaches them by email — what was decided, why, and how to contest it.
 */
 
const { escapeHtml } = require('../email')
 
const TRANSLATIONS = {
  en: {
    subject: 'Your Browsway Flows account was suspended',
    title: 'Your account was suspended',
    intro:
      'After reports from other users, a platform administrator found that content you posted breaks the rules of Browsway Flows. Your account is suspended: you can no longer sign in.',
    reason: 'Reason',
    content: 'Content concerned',
    note: 'Note from the administrator',
    contest: 'If you think this decision is wrong, reply to this email or write to {email}.',
    reasons: {
      spam: 'Spam or scam',
      harassment: 'Harassment or hate',
      inappropriate: 'Inappropriate content',
      illegal: 'Illegal content',
      other: 'Other'
    }
  },
  fr: {
    subject: 'Votre compte Browsway Flows a été suspendu',
    title: 'Votre compte a été suspendu',
    intro:
      'Suite à des signalements d’autres utilisateurs, un administrateur de la plateforme a constaté qu’un contenu que vous avez publié enfreint les règles de Browsway Flows. Votre compte est suspendu : vous ne pouvez plus vous connecter.',
    reason: 'Motif',
    content: 'Contenu concerné',
    note: 'Note de l’administrateur',
    contest:
      'Si vous pensez que cette décision est une erreur, répondez à cet email ou écrivez à {email}.',
    reasons: {
      spam: 'Spam ou arnaque',
      harassment: 'Harcèlement ou haine',
      inappropriate: 'Contenu inapproprié',
      illegal: 'Contenu illégal',
      other: 'Autre'
    }
  },
  es: {
    subject: 'Tu cuenta de Browsway Flows ha sido suspendida',
    title: 'Tu cuenta ha sido suspendida',
    intro:
      'Tras las denuncias de otros usuarios, un administrador de la plataforma ha constatado que un contenido que publicaste infringe las normas de Browsway Flows. Tu cuenta está suspendida: ya no puedes iniciar sesión.',
    reason: 'Motivo',
    content: 'Contenido afectado',
    note: 'Nota del administrador',
    contest: 'Si crees que esta decisión es un error, responde a este email o escribe a {email}.',
    reasons: {
      spam: 'Spam o estafa',
      harassment: 'Acoso u odio',
      inappropriate: 'Contenido inapropiado',
      illegal: 'Contenido ilegal',
      other: 'Otro'
    }
  }
}
 
/**
 * @param {{ lang: string, reason: string, excerpt?: string | null, note?: string | null,
 *   contactEmail: string }} params
 * @returns {{ subject: string, html: string, text: string }}
 */
function renderAccountBannedEmail({ lang, reason, excerpt, note, contactEmail }) {
  const t = TRANSLATIONS[lang] || TRANSLATIONS.en
  const reasonLabel = t.reasons[reason] || t.reasons.other
  const contest = t.contest.replace('{email}', contactEmail)
 
  const text = [
    t.intro,
    '',
    `${t.reason}: ${reasonLabel}`,
    ...(excerpt ? [`${t.content}: ${excerpt}`] : []),
    ...(note ? [`${t.note}: ${note}`] : []),
    '',
    contest
  ].join('\n')
 
  const row = (label, value) =>
    `<tr><td style="color: #64748b; padding: 4px 12px 4px 0; vertical-align: top;">${label}</td><td style="color: #1e293b;">${escapeHtml(value)}</td></tr>`
 
  const html = `
<div style="font-family: Arial, sans-serif; max-width: 600px; margin: 0 auto; padding: 20px; background-color: #f9f9f9;">
  <div style="background-color: #ffffff; border-radius: 10px; padding: 30px 20px;">
    <h1 style="color: #b91c1c; margin: 0 0 20px; font-size: 24px;">${t.title}</h1>
    <p style="color: #475569; line-height: 1.6;">${t.intro}</p>
    <table style="margin: 20px 0; font-size: 14px;">
      ${row(t.reason, reasonLabel)}
      ${excerpt ? row(t.content, excerpt) : ''}
      ${note ? row(t.note, note) : ''}
    </table>
    <p style="color: #64748b; font-size: 13px; line-height: 1.6; border-top: 1px solid #e2e8f0; padding-top: 20px;">${escapeHtml(contest)}</p>
  </div>
</div>`
 
  return { subject: t.subject, html, text }
}
 
module.exports = { renderAccountBannedEmail }