feat(security): JWT required on every API route, gated dev fallback, role checks
- main.py: global get_current_user dependency on all routers except /auth/login and /health; prod fail-fast startup guard rejects wildcard CORS, default credentials, DEV_LOGIN_ENABLED - inventory/pm: X-User-Role header identity fallback now only active when PROCUREMENT_DEV_LOGIN_ENABLED=true (was unconditional in production) - item_decisions writes + attachment deletes: require_role( procurement_manager, admin) — require_role was defined but never used - config.py: ENVIRONMENT flag, comma-separated CORS_ORIGINS, no default Casdoor client secret/admin password, DEV_LOGIN_ENABLED=false - frontend: authenticated file downloads (Bearer + blob) — <a href> links cannot send the token; FileList/QuoteDetail/AcceptModal/EditModal/ PurchaseHistory converted; DEV_LOGIN_ENABLED build arg defaults false - smoke tests authenticate via POST /auth/login (SMOKE_USER/SMOKE_PASSWORD) - traefik: security headers, API rate limit, 12MB body cap (prod overlay) - nginx client_max_body_size aligned to 12MB
This commit is contained in:
+25
-2
@@ -1282,8 +1282,31 @@ export const api = {
|
||||
remove: async (quoteId: string, kind: FileKind, id: string): Promise<void> => {
|
||||
await deleteData(`/quotes/${quoteId}/${kind}/${id}`);
|
||||
},
|
||||
downloadUrl: (quoteId: string, kind: FileKind, id: string): string =>
|
||||
`${BASE_URL}/quotes/${quoteId}/${kind}/${id}`,
|
||||
// دانلود احراز هویتشده: <a href> توکن Authorization نمیفرستد، پس بایتها
|
||||
// را با توکن میگیریم و به شکل blob در مرورگر ذخیره میکنیم.
|
||||
download: async (quoteId: string, kind: FileKind, id: string, fileName: string): Promise<void> => {
|
||||
let res: Response;
|
||||
try {
|
||||
res = await fetch(`${BASE_URL}/quotes/${quoteId}/${kind}/${id}`, {
|
||||
headers: authHeaders(),
|
||||
});
|
||||
} catch {
|
||||
throw new ApiError("اتصال به سرور برقرار نشد — آیا بکاند در دسترس است؟", 0);
|
||||
}
|
||||
if (!res.ok) throw new ApiError(faHttpError(res.status, "خطای سرور"), res.status);
|
||||
const blob = await res.blob();
|
||||
const url = URL.createObjectURL(blob);
|
||||
try {
|
||||
const a = document.createElement("a");
|
||||
a.href = url;
|
||||
a.download = fileName || "attachment";
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
a.remove();
|
||||
} finally {
|
||||
URL.revokeObjectURL(url);
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
// ---------- برندها (از بکاند) ----------
|
||||
|
||||
Reference in New Issue
Block a user