Restrict admin to system management

This commit is contained in:
2026-08-06 08:07:26 +02:00
parent 0bef65ab75
commit 19e4621aeb
13 changed files with 634 additions and 882 deletions
+36 -28
View File
@@ -1,5 +1,4 @@
import type {
AdminSession,
AdminUser,
AuthUser,
BillingStatus,
@@ -10,7 +9,6 @@ import type {
StatisticsOverview,
TicketMeta,
TicketPeriod,
UserRole,
WorkType
} from "./types";
@@ -99,7 +97,6 @@ export function createAdminUser(payload: {
username: string;
displayName: string;
password: string;
role: UserRole;
active: boolean;
}) {
return request<{ user: AdminUser }>("/api/admin/users", {
@@ -114,7 +111,6 @@ export function updateAdminUser(
username: string;
displayName: string;
password?: string;
role: UserRole;
active: boolean;
}
) {
@@ -124,8 +120,42 @@ export function updateAdminUser(
});
}
export function getAdminSessions() {
return request<{ sessions: AdminSession[] }>("/api/admin/sessions");
export async function downloadDatabaseExport() {
const response = await fetch("/api/admin/export/database", {
credentials: "same-origin"
});
if (!response.ok) {
const body = await response.json().catch(() => ({}));
throw new ApiError(body.error ?? "Export fehlgeschlagen", response.status);
}
const contentDisposition = response.headers.get("content-disposition") ?? "";
const filenameMatch = contentDisposition.match(/filename="([^"]+)"/);
return {
blob: await response.blob(),
filename: filenameMatch?.[1] ?? `tickettracker-backup-${new Date().toISOString().replace(/[:.]/g, "-")}.sql`
};
}
export async function downloadMonthExport(month: string) {
const response = await fetch(`/api/export/months/${month}`, {
credentials: "same-origin"
});
if (!response.ok) {
const body = await response.json().catch(() => ({}));
throw new ApiError(body.error ?? "Export fehlgeschlagen", response.status);
}
const contentDisposition = response.headers.get("content-disposition") ?? "";
const filenameMatch = contentDisposition.match(/filename="([^"]+)"/);
return {
blob: await response.blob(),
filename: filenameMatch?.[1] ?? `tickettracker-monat-${month}.csv`
};
}
export function getOrganizations(search = "") {
@@ -214,28 +244,6 @@ export function deleteRecurringBilling(billingId: string) {
});
}
export function createAdminSession(payload: {
userId: string;
ticketNumber: string;
organizationId: string;
activity: string;
workType: WorkType;
startedAt: string;
endedAt: string;
}) {
return request<{ session: AdminSession }>("/api/admin/sessions", {
method: "POST",
body: JSON.stringify(payload)
});
}
export function reassignAdminSession(sessionId: string, userId: string) {
return request<{ session: AdminSession }>(`/api/admin/sessions/${sessionId}/owner`, {
method: "PATCH",
body: JSON.stringify({ userId })
});
}
export function createSession(payload: CreateSessionPayload) {
return request("/api/sessions", {
method: "POST",