Push-Zeitmail: Vorlage T15, Zuordnung Pusher → Mitarbeiter, Versand
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
ec3f22d98e
commit
1a1005d099
5 files changed
+306
-3
No files matched your search
@@ -0,0 +1,60 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="de" xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<!--
|
||||
T15 · Zeit für einen Git-Push eintragen
|
||||
Betreff: [Zeit] #{{woid}} {{kunde}} – {{anzahl_commits}} Commit(s)
|
||||
Absender: „WEBklar Kundenportal“ <Portal-Postfach>
|
||||
Empfänger: die Person, die gepusht hat (employees.email)
|
||||
Platzhalter: {{vorname}}, {{woid}}, {{kunde}}, {{ticket_titel}}, {{ticket_beschreibung}}, {{ticket_status}}, {{repo}}, {{branch}}, {{push_zeit}}, {{anzahl_commits}}, {{commits}}, {{link_15}}, {{link_30}}, {{link_45}}, {{link_60}}, {{link_90}}, {{link_120}}, {{link_180}}, {{link_andere}}, {{ticket_link}}
|
||||
commits ist Text (je Zeile Kurz-SHA und Titel); die link_*-Adressen öffnen die Bestätigungsseite /zeit/… (speichert erst nach Klick auf „Speichern“).
|
||||
-->
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<meta name="color-scheme" content="light dark">
|
||||
<meta name="supported-color-schemes" content="light dark">
|
||||
<title>[Zeit] #{{woid}} {{kunde}} – {{anzahl_commits}} Commit(s)</title>
|
||||
<!--[if mso]><style>table,td{font-family:Arial,Helvetica,sans-serif!important;}</style><![endif]-->
|
||||
<style>
|
||||
a{color:#111111;}
|
||||
@media (max-width:620px){.w{width:100%!important;}.px{padding-left:24px!important;padding-right:24px!important;}.lbl{display:block!important;width:100%!important;padding-bottom:2px!important;border-bottom:0!important;}.val{display:block!important;width:100%!important;padding-top:0!important;}}
|
||||
@media (prefers-color-scheme:dark){.bg{background:#161615!important;}.card{background:#1f1f1e!important;}.ink{color:#f2f1ee!important;}.mut{color:#a8a6a0!important;}.box{background:#2a2a28!important;border-color:#3a3a37!important;}.btn{background:#f2f1ee!important;}.btn a{color:#161615!important;}.btn2{background:#2a2a28!important;border-color:#3a3a37!important;}.btn2 a{color:#f2f1ee!important;}.rowline{border-color:#3a3a37!important;}}
|
||||
</style>
|
||||
</head>
|
||||
<body style="margin:0;padding:0;background:#f1f0ec;">
|
||||
<span style="display:none;max-height:0;overflow:hidden;opacity:0;mso-hide:all;font-size:1px;line-height:1px;color:#f1f0ec;">Push auf {{repo}} – trag kurz deine Zeit ein. ͏ ͏ ͏</span>
|
||||
<table role="presentation" class="bg" width="100%" cellpadding="0" cellspacing="0" border="0" style="background:#f1f0ec;">
|
||||
<tr><td align="center" style="padding:32px 12px;">
|
||||
<table role="presentation" class="w" width="600" cellpadding="0" cellspacing="0" border="0" style="width:600px;max-width:600px;">
|
||||
<tr><td class="px" style="padding:0 40px 20px 40px;"><table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0"><tr>
|
||||
<td><table role="presentation" cellpadding="0" cellspacing="0" border="0"><tr><td valign="middle" style="padding-right:10px;"><img src="https://project.webklar.com/webklar-logo.png" width="40" height="40" alt="WEBklar" style="display:block;width:40px;height:40px;border:0;outline:none;text-decoration:none;border-radius:10px;"></td><td valign="middle" class="ink" style="font-family:Arial,Helvetica,sans-serif;font-size:26px;font-weight:bold;letter-spacing:-1px;color:#111111;">WEBklar</td></tr></table></td>
|
||||
<td align="right" class="mut" style="font-family:Arial,Helvetica,sans-serif;font-size:12px;color:#6b6964;">Intern · Ticketsystem</td>
|
||||
</tr></table></td></tr>
|
||||
<tr><td class="card" style="background:#ffffff;border-radius:16px;">
|
||||
<table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0">
|
||||
<tr><td class="px" style="padding:44px 40px 8px 40px;"><table role="presentation" cellpadding="0" cellspacing="0" border="0"><tr><td style="background:#fdebd3;border-radius:100px;padding:6px 12px;font-family:Arial,Helvetica,sans-serif;font-size:12px;font-weight:bold;color:#8a4b00;">Zeit eintragen</td></tr></table></td></tr>
|
||||
<tr><td class="px ink" style="padding:16px 40px 0 40px;font-family:Arial,Helvetica,sans-serif;font-size:28px;line-height:34px;mso-line-height-rule:exactly;font-weight:bold;letter-spacing:-0.5px;color:#111111;">Hallo {{vorname}}, wie lange hast du daran gearbeitet?</td></tr>
|
||||
<tr><td class="px mut" style="padding:10px 40px 0 40px;font-family:Arial,Helvetica,sans-serif;font-size:16px;line-height:25px;mso-line-height-rule:exactly;color:#4a4843;">Du hast gerade auf {{repo}} ({{branch}}) gepusht. Ein Klick trägt die Zeit im Ticket ein.</td></tr>
|
||||
<tr><td class="px" style="padding:24px 40px 0 40px;"><table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0">
|
||||
<tr><td class="btn" bgcolor="#111111" align="center" style="background:#111111;border-radius:10px;"><a href="{{link_15}}" style="display:block;padding:12px 4px;font-family:Arial,Helvetica,sans-serif;font-size:14px;font-weight:bold;color:#ffffff;text-decoration:none;">15 Min</a></td><td width="8" style="width:8px;font-size:0;line-height:0;"> </td><td class="btn" bgcolor="#111111" align="center" style="background:#111111;border-radius:10px;"><a href="{{link_30}}" style="display:block;padding:12px 4px;font-family:Arial,Helvetica,sans-serif;font-size:14px;font-weight:bold;color:#ffffff;text-decoration:none;">30 Min</a></td><td width="8" style="width:8px;font-size:0;line-height:0;"> </td><td class="btn" bgcolor="#111111" align="center" style="background:#111111;border-radius:10px;"><a href="{{link_45}}" style="display:block;padding:12px 4px;font-family:Arial,Helvetica,sans-serif;font-size:14px;font-weight:bold;color:#ffffff;text-decoration:none;">45 Min</a></td><td width="8" style="width:8px;font-size:0;line-height:0;"> </td><td class="btn" bgcolor="#111111" align="center" style="background:#111111;border-radius:10px;"><a href="{{link_60}}" style="display:block;padding:12px 4px;font-family:Arial,Helvetica,sans-serif;font-size:14px;font-weight:bold;color:#ffffff;text-decoration:none;">1 Std</a></td></tr>
|
||||
<tr><td colspan="7" style="height:8px;font-size:0;line-height:0;"> </td></tr>
|
||||
<tr><td class="btn" bgcolor="#111111" align="center" style="background:#111111;border-radius:10px;"><a href="{{link_90}}" style="display:block;padding:12px 4px;font-family:Arial,Helvetica,sans-serif;font-size:14px;font-weight:bold;color:#ffffff;text-decoration:none;">1,5 Std</a></td><td width="8" style="width:8px;font-size:0;line-height:0;"> </td><td class="btn" bgcolor="#111111" align="center" style="background:#111111;border-radius:10px;"><a href="{{link_120}}" style="display:block;padding:12px 4px;font-family:Arial,Helvetica,sans-serif;font-size:14px;font-weight:bold;color:#ffffff;text-decoration:none;">2 Std</a></td><td width="8" style="width:8px;font-size:0;line-height:0;"> </td><td class="btn" bgcolor="#111111" align="center" style="background:#111111;border-radius:10px;"><a href="{{link_180}}" style="display:block;padding:12px 4px;font-family:Arial,Helvetica,sans-serif;font-size:14px;font-weight:bold;color:#ffffff;text-decoration:none;">3 Std</a></td><td width="8" style="width:8px;font-size:0;line-height:0;"> </td><td class="btn" bgcolor="#111111" align="center" style="background:#111111;border-radius:10px;"><a href="{{link_andere}}" style="display:block;padding:12px 4px;font-family:Arial,Helvetica,sans-serif;font-size:14px;font-weight:bold;color:#ffffff;text-decoration:none;">Andere Zeit</a></td></tr>
|
||||
</table></td></tr>
|
||||
<tr><td class="px" style="padding:24px 40px 0 40px;"><table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0" style="font-family:Arial,Helvetica,sans-serif;font-size:14px;line-height:21px;mso-line-height-rule:exactly;">
|
||||
<tr><td class="lbl mut rowline" width="150" valign="top" style="width:150px;padding:10px 12px 10px 0;color:#6b6964;border-bottom:1px solid #eeece6;">Ticket</td><td class="val ink rowline" valign="top" style="padding:10px 0;color:#111111;border-bottom:1px solid #eeece6;">#{{woid}} · {{ticket_titel}}</td></tr>
|
||||
<tr><td class="lbl mut rowline" width="150" valign="top" style="width:150px;padding:10px 12px 10px 0;color:#6b6964;border-bottom:1px solid #eeece6;">Kunde</td><td class="val ink rowline" valign="top" style="padding:10px 0;color:#111111;border-bottom:1px solid #eeece6;">{{kunde}}</td></tr>
|
||||
<tr><td class="lbl mut rowline" width="150" valign="top" style="width:150px;padding:10px 12px 10px 0;color:#6b6964;border-bottom:1px solid #eeece6;">Status</td><td class="val ink rowline" valign="top" style="padding:10px 0;color:#111111;border-bottom:1px solid #eeece6;">{{ticket_status}}</td></tr>
|
||||
<tr><td class="lbl mut rowline" width="150" valign="top" style="width:150px;padding:10px 12px 10px 0;color:#6b6964;border-bottom:1px solid #eeece6;">Beschreibung</td><td class="val ink rowline" valign="top" style="padding:10px 0;color:#111111;border-bottom:1px solid #eeece6;">{{ticket_beschreibung}}</td></tr>
|
||||
<tr><td class="lbl mut rowline" width="150" valign="top" style="width:150px;padding:10px 12px 10px 0;color:#6b6964;border-bottom:1px solid #eeece6;">Push</td><td class="val ink rowline" valign="top" style="padding:10px 0;color:#111111;border-bottom:1px solid #eeece6;">{{push_zeit}} · {{anzahl_commits}} Commit(s)</td></tr>
|
||||
</table></td></tr>
|
||||
<tr><td class="px" style="padding:20px 40px 0 40px;"><table role="presentation" class="box" width="100%" cellpadding="0" cellspacing="0" border="0" style="background:#f7f6f3;border:1px solid #e8e6e0;border-radius:12px;"><tr><td class="ink" style="padding:16px 20px;font-family:Menlo,Consolas,monospace;font-size:13px;line-height:20px;color:#111111;">{{commits}}</td></tr></table></td></tr>
|
||||
<tr><td class="px" style="padding:24px 40px 0 40px;"><table role="presentation" cellpadding="0" cellspacing="0" border="0"><tr><td class="btn2" bgcolor="#ffffff" style="background:#ffffff;border:1px solid #d9d6ce;border-radius:10px;"><a href="{{ticket_link}}" style="display:block;padding:12px 22px;font-family:Arial,Helvetica,sans-serif;font-size:15px;font-weight:bold;color:#111111;text-decoration:none;">Ticket öffnen →</a></td></tr></table></td></tr>
|
||||
<tr><td style="padding:0 0 40px 0;font-size:0;line-height:0;"> </td></tr>
|
||||
</table>
|
||||
</td></tr>
|
||||
<tr><td class="px mut" align="center" style="padding:24px 40px 0 40px;font-family:Arial,Helvetica,sans-serif;font-size:12px;line-height:19px;color:#6b6964;">Der Link gilt 14 Tage und trägt nur die Zeit für diesen Push ein. Ändern kannst du sie danach im Ticketsystem.</td></tr>
|
||||
</table>
|
||||
</td></tr>
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
||||
@@ -129,3 +129,22 @@ export async function sendCustomerMail(to, { attachments = [], ...message }) {
|
||||
attachments,
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Mail an eine einzelne Person im Team aus einer T-Vorlage (z. B. T15 Push-Zeitmail), ohne BCC.
|
||||
* Wirft bei fehlendem SMTP oder Versandfehler - der Aufrufer entscheidet, ob das schlimm ist.
|
||||
* @param {string} to
|
||||
* @param {{ template: string, values?: object, blocks?: object }} message
|
||||
*/
|
||||
export async function sendStaffMail(to, message) {
|
||||
const mailer = getTransporter()
|
||||
if (!mailer) throw new Error('SMTP nicht konfiguriert')
|
||||
const mail = render(message)
|
||||
return mailer.sendMail({
|
||||
from: `"${TEAM_SENDER}" <${config.smtp.from}>`,
|
||||
to,
|
||||
subject: mail.subject,
|
||||
text: mail.text,
|
||||
html: mail.html,
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
import { config } from '../config.js'
|
||||
import { berlinDateTime } from './berlinTime.js'
|
||||
import { listDocuments, Query } from './appwriteAdmin.js'
|
||||
import { sendStaffMail } from './mailer.js'
|
||||
import { createPushTimeToken } from './pushTimeToken.js'
|
||||
|
||||
/**
|
||||
* Push-Zeitmail (Vorlage T15): nach einem neuen Git-Push-Arbeitsblatt bekommt die pushende Person
|
||||
* eine Mail mit Ticket- und Push-Infos und Schnell-Knoepfen zum Eintragen der Zeit (/zeit/<token>).
|
||||
*/
|
||||
|
||||
const QUICK_MINUTES = [15, 30, 45, 60, 90, 120, 180]
|
||||
const MAX_COMMITS = 10
|
||||
const DESCRIPTION_MAX = 300
|
||||
|
||||
// Deutsche Bezeichnungen wie in WOMS (lib/ticketStatus.js)
|
||||
const STATUS_LABELS = {
|
||||
Open: 'Offen',
|
||||
Assigned: 'Eingeplant',
|
||||
Occupied: 'In Arbeit',
|
||||
Awaiting: 'Wartet',
|
||||
'In Test': 'Prüfung',
|
||||
Closed: 'Erledigt',
|
||||
Cancelled: 'Abgebrochen',
|
||||
}
|
||||
|
||||
const norm = (value) => String(value || '').trim().toLowerCase()
|
||||
|
||||
/**
|
||||
* Gitea-Pusher einem Mitarbeiter zuordnen - dieselbe Regel wie canEditWorksheetTimes in WOMS:
|
||||
* Gitea-Name gegen Kuerzel oder Anzeigenamen, ohne Gross-/Kleinschreibung. Nur mit E-Mail-Adresse.
|
||||
*/
|
||||
export function findEmployeeForPusher(pusher, employees) {
|
||||
const names = [pusher?.username, pusher?.login, pusher?.full_name].map(norm).filter(Boolean)
|
||||
if (!names.length) return null
|
||||
const sorted = [...(employees || [])].sort((a, b) => String(a.$createdAt || '').localeCompare(String(b.$createdAt || '')))
|
||||
return (
|
||||
sorted.find(
|
||||
(emp) => String(emp.email || '').trim() && names.some((n) => n === norm(emp.shortcode) || n === norm(emp.displayName))
|
||||
) || null
|
||||
)
|
||||
}
|
||||
|
||||
function commitLines(commits) {
|
||||
const list = Array.isArray(commits) ? commits : []
|
||||
const lines = list.slice(0, MAX_COMMITS).map((commit) => {
|
||||
const sha = String(commit.id || commit.sha || '').slice(0, 7)
|
||||
const title = String(commit.message || '').trim().split('\n')[0]
|
||||
return `${sha} ${title}`.trim()
|
||||
})
|
||||
if (list.length > MAX_COMMITS) lines.push(`… und ${list.length - MAX_COMMITS} weitere`)
|
||||
return lines.join('\n') || '(keine Commit-Details)'
|
||||
}
|
||||
|
||||
function shorten(text, max) {
|
||||
const value = String(text || '').trim()
|
||||
return value.length > max ? `${value.slice(0, max)}…` : value
|
||||
}
|
||||
|
||||
/** Werte fuer Vorlage T15 */
|
||||
export function buildPushTimeMail({ employee, ticket, worksheet, repoFullName, branch, commits, pushedAt = new Date() }) {
|
||||
const token = createPushTimeToken({ worksheetId: worksheet.$id, employeeId: employee.$id })
|
||||
const base = `${config.publicBaseUrl}/zeit/${token}`
|
||||
const { date, time } = berlinDateTime(pushedAt)
|
||||
const woid = String(ticket?.woid || worksheet?.woid || '')
|
||||
const links = Object.fromEntries(QUICK_MINUTES.map((m) => [`link_${m}`, `${base}?min=${m}`]))
|
||||
|
||||
return {
|
||||
template: 'T15',
|
||||
values: {
|
||||
vorname: String(employee.displayName || '').trim().split(/\s+/)[0] || 'du',
|
||||
woid,
|
||||
kunde: ticket?.customerName || 'ohne Kunde',
|
||||
ticket_titel: ticket?.topic || '',
|
||||
ticket_beschreibung: shorten(ticket?.details, DESCRIPTION_MAX),
|
||||
ticket_status: STATUS_LABELS[ticket?.status] || ticket?.status || '',
|
||||
repo: repoFullName,
|
||||
branch,
|
||||
push_zeit: `${date} ${time.slice(0, 2)}:${time.slice(2)}`,
|
||||
anzahl_commits: Array.isArray(commits) ? commits.length : 0,
|
||||
commits: commitLines(commits),
|
||||
...links,
|
||||
link_andere: base,
|
||||
ticket_link: `${config.womsBaseUrl}/tickets?woid=${encodeURIComponent(woid)}`,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
/** Mail verschicken; wirft nie (Webhook darf daran nicht scheitern). */
|
||||
export async function sendPushTimeMail({ ticket, worksheet, repoFullName, branch, commits, pusher, pushedAt }) {
|
||||
try {
|
||||
const employees = await listDocuments(config.collections.employees, [Query.limit(100)])
|
||||
const employee = findEmployeeForPusher(pusher, employees)
|
||||
if (!employee) {
|
||||
const name = pusher?.username || pusher?.login || pusher?.full_name || '?'
|
||||
console.warn(`[pushTimeMail] Pusher "${name}" keinem Mitarbeiter mit E-Mail zugeordnet – keine Zeitmail`)
|
||||
return { sent: false, reason: 'no_employee' }
|
||||
}
|
||||
const mail = buildPushTimeMail({ employee, ticket, worksheet, repoFullName, branch, commits, pushedAt })
|
||||
await sendStaffMail(employee.email, mail)
|
||||
return { sent: true }
|
||||
} catch (err) {
|
||||
console.error('[pushTimeMail] Versand fehlgeschlagen:', err.message)
|
||||
return { sent: false, reason: err.message }
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user