KI-AGENT: Mailkonten deaktivierbar machen und Synczeit anzeigen
All checks were successful
Build and Push Docker Images / build-backend (push) Successful in 44s
Build and Push Docker Images / build-frontend (push) Successful in 1m15s
Build and Push Docker Images / build-website (push) Successful in 23s
Build and Push Docker Images / build-central-services-api (push) Successful in 21s
Build and Push Docker Images / build-central-services-admin (push) Successful in 21s
Build and Push Docker Images / build-docs (push) Successful in 22s
All checks were successful
Build and Push Docker Images / build-backend (push) Successful in 44s
Build and Push Docker Images / build-frontend (push) Successful in 1m15s
Build and Push Docker Images / build-website (push) Successful in 23s
Build and Push Docker Images / build-central-services-api (push) Successful in 21s
Build and Push Docker Images / build-central-services-admin (push) Successful in 21s
Build and Push Docker Images / build-docs (push) Successful in 22s
This commit is contained in:
2
backend/db/migrations/0067_email_account_enabled.sql
Normal file
2
backend/db/migrations/0067_email_account_enabled.sql
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
ALTER TABLE "user_credentials"
|
||||||
|
ADD COLUMN IF NOT EXISTS "email_enabled" boolean DEFAULT true NOT NULL;
|
||||||
@@ -449,6 +449,13 @@
|
|||||||
"when": 1788799700000,
|
"when": 1788799700000,
|
||||||
"tag": "0066_email_entity_links",
|
"tag": "0066_email_entity_links",
|
||||||
"breakpoints": true
|
"breakpoints": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"idx": 64,
|
||||||
|
"version": "7",
|
||||||
|
"when": 1788801000000,
|
||||||
|
"tag": "0067_email_account_enabled",
|
||||||
|
"breakpoints": true
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ export const userCredentials = pgTable("user_credentials", {
|
|||||||
smtpSsl: boolean("smtp_ssl"),
|
smtpSsl: boolean("smtp_ssl"),
|
||||||
|
|
||||||
type: credentialTypesEnum("type").notNull(),
|
type: credentialTypesEnum("type").notNull(),
|
||||||
|
emailEnabled: boolean("email_enabled").notNull().default(true),
|
||||||
|
|
||||||
imapPort: numeric("imap_port"),
|
imapPort: numeric("imap_port"),
|
||||||
imapSsl: boolean("imap_ssl"),
|
imapSsl: boolean("imap_ssl"),
|
||||||
|
|||||||
@@ -1,12 +1,13 @@
|
|||||||
import nodemailer from "nodemailer"
|
import nodemailer from "nodemailer"
|
||||||
import { FastifyInstance } from "fastify"
|
import { FastifyInstance } from "fastify"
|
||||||
import { and, desc, eq } from "drizzle-orm"
|
import { and, desc, eq, isNotNull } from "drizzle-orm"
|
||||||
|
|
||||||
import { encrypt, decrypt } from "../utils/crypt"
|
import { encrypt, decrypt } from "../utils/crypt"
|
||||||
import {
|
import {
|
||||||
customers,
|
customers,
|
||||||
emailEntityLinks,
|
emailEntityLinks,
|
||||||
emailMessages,
|
emailMessages,
|
||||||
|
emailSyncState,
|
||||||
plants,
|
plants,
|
||||||
projects,
|
projects,
|
||||||
userCredentials,
|
userCredentials,
|
||||||
@@ -54,6 +55,7 @@ export default async function emailAsUserRoutes(server: FastifyInstance) {
|
|||||||
userId: row.userId,
|
userId: row.userId,
|
||||||
tenantId: row.tenantId,
|
tenantId: row.tenantId,
|
||||||
type: row.type,
|
type: row.type,
|
||||||
|
emailEnabled: row.emailEnabled !== false,
|
||||||
email,
|
email,
|
||||||
displayName: email || `Mailkonto ${String(row.id).slice(0, 8)} muss repariert werden`,
|
displayName: email || `Mailkonto ${String(row.id).slice(0, 8)} muss repariert werden`,
|
||||||
smtpHost,
|
smtpHost,
|
||||||
@@ -68,6 +70,24 @@ export default async function emailAsUserRoutes(server: FastifyInstance) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const accountResponseWithStatus = async (row: any) => {
|
||||||
|
const syncRows = await server.db
|
||||||
|
.select({ lastSyncedAt: emailSyncState.lastSyncedAt })
|
||||||
|
.from(emailSyncState)
|
||||||
|
.where(and(
|
||||||
|
eq(emailSyncState.accountId, row.id),
|
||||||
|
eq(emailSyncState.tenantId, row.tenantId),
|
||||||
|
isNotNull(emailSyncState.lastSyncedAt),
|
||||||
|
))
|
||||||
|
.orderBy(desc(emailSyncState.lastSyncedAt))
|
||||||
|
.limit(1)
|
||||||
|
|
||||||
|
return {
|
||||||
|
...accountResponse(row),
|
||||||
|
lastSyncedAt: syncRows[0]?.lastSyncedAt || null,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const accountCredentials = (row: any) => {
|
const accountCredentials = (row: any) => {
|
||||||
const account = accountResponse(row)
|
const account = accountResponse(row)
|
||||||
if (!account.credentialsReadable) {
|
if (!account.credentialsReadable) {
|
||||||
@@ -148,13 +168,14 @@ export default async function emailAsUserRoutes(server: FastifyInstance) {
|
|||||||
reply.header("Access-Control-Expose-Headers", "Authorization, Content-Disposition, Content-Type, Content-Length")
|
reply.header("Access-Control-Expose-Headers", "Authorization, Content-Disposition, Content-Type, Content-Length")
|
||||||
}
|
}
|
||||||
|
|
||||||
const accountWhere = (tenantId: number, userId: string, id?: string) => {
|
const accountWhere = (tenantId: number, userId: string, id?: string, enabledOnly = false) => {
|
||||||
const conditions = [
|
const conditions = [
|
||||||
eq(userCredentials.tenantId, tenantId),
|
eq(userCredentials.tenantId, tenantId),
|
||||||
eq(userCredentials.userId, userId),
|
eq(userCredentials.userId, userId),
|
||||||
eq(userCredentials.type, "mail"),
|
eq(userCredentials.type, "mail"),
|
||||||
]
|
]
|
||||||
if (id) conditions.push(eq(userCredentials.id, id))
|
if (id) conditions.push(eq(userCredentials.id, id))
|
||||||
|
if (enabledOnly) conditions.push(eq(userCredentials.emailEnabled, true))
|
||||||
return and(...conditions)
|
return and(...conditions)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -185,6 +206,7 @@ export default async function emailAsUserRoutes(server: FastifyInstance) {
|
|||||||
imap_host?: string
|
imap_host?: string
|
||||||
imap_port?: number
|
imap_port?: number
|
||||||
imap_ssl?: boolean
|
imap_ssl?: boolean
|
||||||
|
emailEnabled?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------
|
// -----------------------------
|
||||||
@@ -208,6 +230,7 @@ export default async function emailAsUserRoutes(server: FastifyInstance) {
|
|||||||
imapHostEncrypted: bodyValue(body, "imapHost", "imap_host") ? encrypt(bodyValue(body, "imapHost", "imap_host")) : undefined,
|
imapHostEncrypted: bodyValue(body, "imapHost", "imap_host") ? encrypt(bodyValue(body, "imapHost", "imap_host")) : undefined,
|
||||||
imapPort: bodyValue(body, "imapPort", "imap_port"),
|
imapPort: bodyValue(body, "imapPort", "imap_port"),
|
||||||
imapSsl: bodyValue(body, "imapSsl", "imap_ssl"),
|
imapSsl: bodyValue(body, "imapSsl", "imap_ssl"),
|
||||||
|
emailEnabled: typeof body.emailEnabled === "boolean" ? body.emailEnabled : undefined,
|
||||||
updatedAt: new Date(),
|
updatedAt: new Date(),
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -227,6 +250,7 @@ export default async function emailAsUserRoutes(server: FastifyInstance) {
|
|||||||
userId: req.user.user_id,
|
userId: req.user.user_id,
|
||||||
tenantId: req.user.tenant_id,
|
tenantId: req.user.tenant_id,
|
||||||
type: "mail",
|
type: "mail",
|
||||||
|
emailEnabled: body.emailEnabled !== false,
|
||||||
|
|
||||||
emailEncrypted: encrypt(body.email),
|
emailEncrypted: encrypt(body.email),
|
||||||
passwordEncrypted: encrypt(body.password),
|
passwordEncrypted: encrypt(body.password),
|
||||||
@@ -262,6 +286,7 @@ export default async function emailAsUserRoutes(server: FastifyInstance) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const { id } = req.params as { id?: string }
|
const { id } = req.params as { id?: string }
|
||||||
|
const query = (req.query || {}) as { includeDisabled?: string | boolean }
|
||||||
|
|
||||||
// ============================================================
|
// ============================================================
|
||||||
// LOAD SINGLE ACCOUNT
|
// LOAD SINGLE ACCOUNT
|
||||||
@@ -276,7 +301,7 @@ export default async function emailAsUserRoutes(server: FastifyInstance) {
|
|||||||
const row = rows[0]
|
const row = rows[0]
|
||||||
if (!row) return reply.code(404).send({ error: "Not found" })
|
if (!row) return reply.code(404).send({ error: "Not found" })
|
||||||
|
|
||||||
return reply.send(accountResponse(row))
|
return reply.send(await accountResponseWithStatus(row))
|
||||||
}
|
}
|
||||||
|
|
||||||
// ============================================================
|
// ============================================================
|
||||||
@@ -285,9 +310,14 @@ export default async function emailAsUserRoutes(server: FastifyInstance) {
|
|||||||
const rows = await server.db
|
const rows = await server.db
|
||||||
.select()
|
.select()
|
||||||
.from(userCredentials)
|
.from(userCredentials)
|
||||||
.where(accountWhere(req.user.tenant_id, req.user.user_id))
|
.where(accountWhere(
|
||||||
|
req.user.tenant_id,
|
||||||
|
req.user.user_id,
|
||||||
|
undefined,
|
||||||
|
query.includeDisabled !== "true" && query.includeDisabled !== true,
|
||||||
|
))
|
||||||
|
|
||||||
return reply.send(rows.map(accountResponse))
|
return reply.send(await Promise.all(rows.map(accountResponseWithStatus)))
|
||||||
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error("GET /email/accounts error:", err)
|
console.error("GET /email/accounts error:", err)
|
||||||
@@ -319,7 +349,7 @@ export default async function emailAsUserRoutes(server: FastifyInstance) {
|
|||||||
const rows = await server.db
|
const rows = await server.db
|
||||||
.select()
|
.select()
|
||||||
.from(userCredentials)
|
.from(userCredentials)
|
||||||
.where(accountWhere(req.user.tenant_id, req.user.user_id, body.account))
|
.where(accountWhere(req.user.tenant_id, req.user.user_id, body.account, true))
|
||||||
.limit(1)
|
.limit(1)
|
||||||
|
|
||||||
const row = rows[0]
|
const row = rows[0]
|
||||||
@@ -444,6 +474,17 @@ export default async function emailAsUserRoutes(server: FastifyInstance) {
|
|||||||
const { id } = req.params as { id: string }
|
const { id } = req.params as { id: string }
|
||||||
const body = (req.body || {}) as { mailbox?: string; limit?: number }
|
const body = (req.body || {}) as { mailbox?: string; limit?: number }
|
||||||
|
|
||||||
|
const accountRows = await server.db
|
||||||
|
.select({ emailEnabled: userCredentials.emailEnabled })
|
||||||
|
.from(userCredentials)
|
||||||
|
.where(accountWhere(req.user.tenant_id, req.user.user_id, id))
|
||||||
|
.limit(1)
|
||||||
|
|
||||||
|
if (!accountRows[0]) return reply.code(404).send({ error: "E-Mail-Konto nicht gefunden" })
|
||||||
|
if (!accountRows[0].emailEnabled) {
|
||||||
|
return reply.code(409).send({ error: "Das E-Mail-Konto ist deaktiviert" })
|
||||||
|
}
|
||||||
|
|
||||||
const result = await emailSync.syncAccount(
|
const result = await emailSync.syncAccount(
|
||||||
req.user.tenant_id,
|
req.user.tenant_id,
|
||||||
req.user.user_id,
|
req.user.user_id,
|
||||||
|
|||||||
@@ -3,16 +3,58 @@ const toast = useToast()
|
|||||||
const items = ref([])
|
const items = ref([])
|
||||||
const loading = ref(true)
|
const loading = ref(true)
|
||||||
const syncingAccount = ref<string | null>(null)
|
const syncingAccount = ref<string | null>(null)
|
||||||
|
const updatingAccount = ref<string | null>(null)
|
||||||
|
|
||||||
|
const formatLastUpdated = (value?: string | null) => {
|
||||||
|
if (!value) return "Noch nicht synchronisiert"
|
||||||
|
const date = new Date(value)
|
||||||
|
if (Number.isNaN(date.getTime())) return "Unbekannt"
|
||||||
|
|
||||||
|
return new Intl.DateTimeFormat("de-DE", {
|
||||||
|
dateStyle: "medium",
|
||||||
|
timeStyle: "short",
|
||||||
|
}).format(date)
|
||||||
|
}
|
||||||
|
|
||||||
const setupPage = async () => {
|
const setupPage = async () => {
|
||||||
loading.value = true
|
loading.value = true
|
||||||
try {
|
try {
|
||||||
items.value = await useNuxtApp().$api("/api/email/accounts")
|
items.value = await useNuxtApp().$api("/api/email/accounts", {
|
||||||
|
query: { includeDisabled: true },
|
||||||
|
})
|
||||||
} finally {
|
} finally {
|
||||||
loading.value = false
|
loading.value = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const toggleAccount = async (account: any) => {
|
||||||
|
updatingAccount.value = account.id
|
||||||
|
const nextEnabled = account.emailEnabled === false
|
||||||
|
|
||||||
|
try {
|
||||||
|
await useNuxtApp().$api(`/api/email/accounts/${account.id}`, {
|
||||||
|
method: "POST",
|
||||||
|
body: { emailEnabled: nextEnabled },
|
||||||
|
})
|
||||||
|
toast.add({
|
||||||
|
title: nextEnabled ? "E-Mail-Konto aktiviert" : "E-Mail-Konto deaktiviert",
|
||||||
|
description: nextEnabled
|
||||||
|
? "Das Konto erscheint wieder in der Mailoberfläche."
|
||||||
|
: "Das Konto wird in der Mailoberfläche nicht mehr angezeigt.",
|
||||||
|
color: "success",
|
||||||
|
})
|
||||||
|
await setupPage()
|
||||||
|
} catch (err: any) {
|
||||||
|
toast.add({
|
||||||
|
title: "Status konnte nicht geändert werden",
|
||||||
|
description: err?.data?.error || err?.message,
|
||||||
|
color: "error",
|
||||||
|
})
|
||||||
|
} finally {
|
||||||
|
updatingAccount.value = null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const syncAccount = async (account: any) => {
|
const syncAccount = async (account: any) => {
|
||||||
syncingAccount.value = account.id
|
syncingAccount.value = account.id
|
||||||
try {
|
try {
|
||||||
@@ -82,11 +124,19 @@ setupPage()
|
|||||||
>
|
>
|
||||||
IMAP/SMTP
|
IMAP/SMTP
|
||||||
</UBadge>
|
</UBadge>
|
||||||
|
<UBadge
|
||||||
|
size="xs"
|
||||||
|
:color="account.emailEnabled === false ? 'neutral' : 'success'"
|
||||||
|
variant="soft"
|
||||||
|
>
|
||||||
|
{{ account.emailEnabled === false ? "Deaktiviert" : "Aktiv" }}
|
||||||
|
</UBadge>
|
||||||
</div>
|
</div>
|
||||||
<div class="mt-1 flex flex-wrap gap-x-4 gap-y-1 text-sm text-dimmed">
|
<div class="mt-1 flex flex-wrap gap-x-4 gap-y-1 text-sm text-dimmed">
|
||||||
<span>IMAP: {{ account.imapHost || "nicht gesetzt" }}:{{ account.imapPort || "-" }}</span>
|
<span>IMAP: {{ account.imapHost || "nicht gesetzt" }}:{{ account.imapPort || "-" }}</span>
|
||||||
<span>SMTP: {{ account.smtpHost || "nicht gesetzt" }}:{{ account.smtpPort || "-" }}</span>
|
<span>SMTP: {{ account.smtpHost || "nicht gesetzt" }}:{{ account.smtpPort || "-" }}</span>
|
||||||
<span>{{ account.hasPassword ? "Passwort hinterlegt" : "Passwort fehlt" }}</span>
|
<span>{{ account.hasPassword ? "Passwort hinterlegt" : "Passwort fehlt" }}</span>
|
||||||
|
<span>Zuletzt aktualisiert: {{ formatLastUpdated(account.lastSyncedAt) }}</span>
|
||||||
</div>
|
</div>
|
||||||
<p v-if="account.credentialsReadable === false" class="mt-2 text-sm text-error">
|
<p v-if="account.credentialsReadable === false" class="mt-2 text-sm text-error">
|
||||||
Die verschlüsselten Zugangsdaten sind nicht lesbar. Öffne das Konto und trage alle Zugangsdaten neu ein.
|
Die verschlüsselten Zugangsdaten sind nicht lesbar. Öffne das Konto und trage alle Zugangsdaten neu ein.
|
||||||
@@ -99,11 +149,20 @@ setupPage()
|
|||||||
color="neutral"
|
color="neutral"
|
||||||
variant="soft"
|
variant="soft"
|
||||||
:loading="syncingAccount === account.id"
|
:loading="syncingAccount === account.id"
|
||||||
:disabled="account.credentialsReadable === false"
|
:disabled="account.credentialsReadable === false || account.emailEnabled === false"
|
||||||
@click.stop="syncAccount(account)"
|
@click.stop="syncAccount(account)"
|
||||||
>
|
>
|
||||||
Synchronisieren
|
Synchronisieren
|
||||||
</UButton>
|
</UButton>
|
||||||
|
<UButton
|
||||||
|
:icon="account.emailEnabled === false ? 'i-heroicons-play' : 'i-heroicons-pause'"
|
||||||
|
:color="account.emailEnabled === false ? 'primary' : 'neutral'"
|
||||||
|
variant="soft"
|
||||||
|
:loading="updatingAccount === account.id"
|
||||||
|
@click.stop="toggleAccount(account)"
|
||||||
|
>
|
||||||
|
{{ account.emailEnabled === false ? "Aktivieren" : "Deaktivieren" }}
|
||||||
|
</UButton>
|
||||||
<UButton
|
<UButton
|
||||||
icon="i-heroicons-pencil-square"
|
icon="i-heroicons-pencil-square"
|
||||||
color="neutral"
|
color="neutral"
|
||||||
|
|||||||
Reference in New Issue
Block a user