Restrict admin to system management
This commit is contained in:
+36
-28
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user