From 1c68e6b724870ef34d01e95a3930573bc5caeab5 Mon Sep 17 00:00:00 2001 From: florianfederspiel Date: Mon, 18 May 2026 21:47:28 +0200 Subject: [PATCH] =?UTF-8?q?KI-AGENT:=20Aktiviere=20importierten=20Mandante?= =?UTF-8?q?n=20f=C3=BCr=20Zieladmin?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/routes/admin.ts | 33 +++++++++++++++++++ .../pages/administration/tenants/[id].vue | 2 ++ .../pages/administration/tenants/index.vue | 2 ++ 3 files changed, 37 insertions(+) diff --git a/backend/src/routes/admin.ts b/backend/src/routes/admin.ts index daf10a8..a4f2845 100644 --- a/backend/src/routes/admin.ts +++ b/backend/src/routes/admin.ts @@ -246,6 +246,7 @@ export default async function adminRoutes(server: FastifyInstance) { const [currentUser] = await server.db .select({ id: authUsers.id, + email: authUsers.email, is_admin: authUsers.is_admin, }) .from(authUsers) @@ -971,6 +972,38 @@ export default async function adminRoutes(server: FastifyInstance) { const exportData = req.body as TenantFullExport; 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 { success: true, diff --git a/frontend/pages/administration/tenants/[id].vue b/frontend/pages/administration/tenants/[id].vue index c6630a2..488dddb 100644 --- a/frontend/pages/administration/tenants/[id].vue +++ b/frontend/pages/administration/tenants/[id].vue @@ -152,6 +152,8 @@ const importTenantExport = async (event: Event) => { } await fetchTenant() + await auth.fetchMe() + await auth.switchTenant(String(result.tenantId)) toast.add({ title: "Mandantenimport abgeschlossen", diff --git a/frontend/pages/administration/tenants/index.vue b/frontend/pages/administration/tenants/index.vue index 9e04873..60ecd26 100644 --- a/frontend/pages/administration/tenants/index.vue +++ b/frontend/pages/administration/tenants/index.vue @@ -108,6 +108,7 @@ const importTenantExport = async (event: Event) => { const rowCount = (result.tables || []).reduce((sum, table) => sum + table.rows, 0) await fetchTenants() + await auth.fetchMe() toast.add({ title: "Mandantenimport abgeschlossen", @@ -116,6 +117,7 @@ const importTenantExport = async (event: Event) => { }) if (result.tenantId) { + await auth.switchTenant(String(result.tenantId)) await router.push(`/administration/tenants/${result.tenantId}`) } } catch (err: any) {