KI-AGENT: Aktiviere importierten Mandanten für Zieladmin

This commit is contained in:
2026-05-18 21:47:28 +02:00
parent cc3c405473
commit 1c68e6b724
3 changed files with 37 additions and 0 deletions

View File

@@ -246,6 +246,7 @@ export default async function adminRoutes(server: FastifyInstance) {
const [currentUser] = await server.db const [currentUser] = await server.db
.select({ .select({
id: authUsers.id, id: authUsers.id,
email: authUsers.email,
is_admin: authUsers.is_admin, is_admin: authUsers.is_admin,
}) })
.from(authUsers) .from(authUsers)
@@ -971,6 +972,38 @@ export default async function adminRoutes(server: FastifyInstance) {
const exportData = req.body as TenantFullExport; const exportData = req.body as TenantFullExport;
const result = await importTenantFullExport(server, exportData); const result = await importTenantFullExport(server, exportData);
const fallbackName = deriveNameFromEmail(currentUser.email);
await server.db
.insert(authTenantUsers)
.values({
tenant_id: result.tenantId,
user_id: currentUser.id,
created_by: currentUser.id,
})
.onConflictDoNothing();
const [existingAdminProfile] = await server.db
.select({ id: authProfiles.id })
.from(authProfiles)
.where(and(
eq(authProfiles.tenant_id, result.tenantId),
eq(authProfiles.user_id, currentUser.id)
))
.limit(1);
if (!existingAdminProfile) {
await server.db
.insert(authProfiles)
.values({
tenant_id: result.tenantId,
user_id: currentUser.id,
first_name: fallbackName.first_name,
last_name: fallbackName.last_name,
email: currentUser.email,
active: true,
});
}
return { return {
success: true, success: true,

View File

@@ -152,6 +152,8 @@ const importTenantExport = async (event: Event) => {
} }
await fetchTenant() await fetchTenant()
await auth.fetchMe()
await auth.switchTenant(String(result.tenantId))
toast.add({ toast.add({
title: "Mandantenimport abgeschlossen", title: "Mandantenimport abgeschlossen",

View File

@@ -108,6 +108,7 @@ const importTenantExport = async (event: Event) => {
const rowCount = (result.tables || []).reduce((sum, table) => sum + table.rows, 0) const rowCount = (result.tables || []).reduce((sum, table) => sum + table.rows, 0)
await fetchTenants() await fetchTenants()
await auth.fetchMe()
toast.add({ toast.add({
title: "Mandantenimport abgeschlossen", title: "Mandantenimport abgeschlossen",
@@ -116,6 +117,7 @@ const importTenantExport = async (event: Event) => {
}) })
if (result.tenantId) { if (result.tenantId) {
await auth.switchTenant(String(result.tenantId))
await router.push(`/administration/tenants/${result.tenantId}`) await router.push(`/administration/tenants/${result.tenantId}`)
} }
} catch (err: any) { } catch (err: any) {