@davoodmehraban89 / Aram-2 Mirror · read-only / commits / 77fbe70
Fork 0

Mirrored from https://github.com/davoodmehraban89/Aram.git

Synced Dec 4, 04:15 UTC

feat(ui): admin panel — login, audit verify, lock/reopen, backup/verify

Phase 7 workbench surface: role-gated login, audit-chain check, year lock, reopen request->approve->reopen, and backup create/verify against the admin API. Gates: eslint/tsc/vitest/build pass. Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>

davoodmehraban89 committed Dec 3, 2026 at 11:39 UTC 77fbe7040afad3654927a4ce7df9e8d2a49e39b8
4 files changed +215
frontend/src/App.test.tsx
+9
@@ -21,6 +21,15 @@ vi.mock('./api/client', async () => {
21 exportMappingsUrl: (id: number) => `/api/v1/years/${id}/mappings/export`,
22 exportStatementsUrl: (id: number, format: string) =>
23 `/api/v1/years/${id}/statements/export?format=${format}`,
24 + login: vi.fn(),
25 + createUser: vi.fn(),
26 + auditVerify: vi.fn(),
27 + lockYear: vi.fn(),
28 + requestReopen: vi.fn(),
29 + approveReopen: vi.fn(),
30 + reopenYear: vi.fn(),
31 + backup: vi.fn(),
32 + verifyBackup: vi.fn(),
33 },
34 }
35 })
frontend/src/App.tsx
+2
@@ -1,5 +1,6 @@
1 import { useState } from 'react'
2 import type { CompanyResult } from './api/types'
3 +import AdminPanel from './components/AdminPanel'
4 import ApprovalPanel from './components/ApprovalPanel'
5 import CompanySetup from './components/CompanySetup'
6 import LedgerUpload from './components/LedgerUpload'
@@ -35,6 +36,7 @@ export default function App() {
36 <MappingPanel yearId={company.year_id} />
37 <StatementView yearId={company.year_id} refreshKey={statementRefresh} />
38 <ApprovalPanel yearId={company.year_id} />
39 + <AdminPanel yearId={company.year_id} />
40 </>
41 )}
42 </main>
frontend/src/api/client.ts
+26
@@ -86,4 +86,30 @@ export const api = {
86
87 exportStatementsUrl: (yearId: number, format: 'xlsx' | 'json') =>
88 `${BASE}/years/${yearId}/statements/export?format=${format}`,
89 +
90 + login: (username: string, password: string) =>
91 + request<{ username: string; display_name: string; role: string }>('/auth/login', json({ username, password })),
92 +
93 + createUser: (username: string, password: string, role: string, actor: string) =>
94 + request<{ username: string; role: string }>('/users', json({ username, password, role, actor })),
95 +
96 + auditVerify: () => request<{ chain_valid: boolean }>('/audit/verify'),
97 +
98 + lockYear: (yearId: number, actor: string) =>
99 + request<{ year_id: number; status: string }>(`/years/${yearId}/lock`, json({ actor })),
100 +
101 + requestReopen: (yearId: number, reason: string, actor: string) =>
102 + request<{ request_id: number; status: string }>(`/years/${yearId}/reopen/request`, json({ reason, actor })),
103 +
104 + approveReopen: (requestId: number, actor: string) =>
105 + request<{ request_id: number; status: string }>(`/reopen/${requestId}/approve`, json({ actor })),
106 +
107 + reopenYear: (yearId: number, actor: string) =>
108 + request<{ year_id: number; status: string }>(`/years/${yearId}/reopen`, json({ actor })),
109 +
110 + backup: (dest: string, actor: string) =>
111 + request<{ dest: string; manifest: { audit_chain_valid: boolean } }>('/backup', json({ dest, actor })),
112 +
113 + verifyBackup: (dest: string, actor: string) =>
114 + request<{ valid: boolean; source_files: number; audit_entries: number }>('/backup/verify', json({ dest, actor })),
115 }
frontend/src/components/AdminPanel.tsx new
+178
@@ -0,0 +1,178 @@
1 +import { useState } from 'react'
2 +import { api, ApiError } from '../api/client'
3 +
4 +interface Props {
5 + yearId: number
6 +}
7 +
8 +interface Session {
9 + username: string
10 + role: string
11 +}
12 +
13 +export default function AdminPanel({ yearId }: Props) {
14 + const [session, setSession] = useState<Session | null>(null)
15 + const [username, setUsername] = useState('')
16 + const [password, setPassword] = useState('')
17 + const [message, setMessage] = useState<string | null>(null)
18 + const [error, setError] = useState<string | null>(null)
19 + const [busy, setBusy] = useState(false)
20 + const [backupDest, setBackupDest] = useState('')
21 + const [reopenReason, setReopenReason] = useState('')
22 + const [lastRequestId, setLastRequestId] = useState<number | null>(null)
23 +
24 + async function run(fn: () => Promise<string>) {
25 + setBusy(true)
26 + setError(null)
27 + setMessage(null)
28 + try {
29 + setMessage(await fn())
30 + } catch (err) {
31 + setError(err instanceof ApiError ? err.message : String(err))
32 + } finally {
33 + setBusy(false)
34 + }
35 + }
36 +
37 + async function login(e: React.FormEvent) {
38 + e.preventDefault()
39 + setBusy(true)
40 + setError(null)
41 + try {
42 + const res = await api.login(username.trim(), password)
43 + setSession({ username: res.username, role: res.role })
44 + setPassword('')
45 + } catch (err) {
46 + setError(err instanceof ApiError ? err.message : String(err))
47 + } finally {
48 + setBusy(false)
49 + }
50 + }
51 +
52 + const actor = session?.username ?? ''
53 +
54 + return (
55 + <section className="card">
56 + <h2>مدیریت، ممیزی و پشتیبان‌گیری</h2>
57 +
58 + {!session ? (
59 + <form className="row" onSubmit={login}>
60 + <label>
61 + نام کاربری
62 + <input value={username} onChange={(e) => setUsername(e.target.value)} required />
63 + </label>
64 + <label>
65 + گذرواژه
66 + <input
67 + type="password"
68 + value={password}
69 + onChange={(e) => setPassword(e.target.value)}
70 + required
71 + />
72 + </label>
73 + <button type="submit" disabled={busy}>
74 + ورود
75 + </button>
76 + </form>
77 + ) : (
78 + <p className="ok">
79 + وارد شده: {session.username} ({session.role})
80 + </p>
81 + )}
82 +
83 + {session && (
84 + <>
85 + <div className="row">
86 + <button
87 + type="button"
88 + disabled={busy}
89 + onClick={() =>
90 + run(async () => {
91 + const r = await api.auditVerify()
92 + return r.chain_valid ? 'زنجیرهٔ ممیزی سالم است.' : 'زنجیرهٔ ممیزی مخدوش است!'
93 + })
94 + }
95 + >
96 + بررسی زنجیرهٔ ممیزی
97 + </button>
98 + <button
99 + type="button"
100 + disabled={busy}
101 + onClick={() => run(async () => `سال قفل شد: ${(await api.lockYear(yearId, actor)).status}`)}
102 + >
103 + قفل سال
104 + </button>
105 + </div>
106 +
107 + <div className="row">
108 + <label>
109 + دلیل بازگشایی
110 + <input value={reopenReason} onChange={(e) => setReopenReason(e.target.value)} />
111 + </label>
112 + <button
113 + type="button"
114 + disabled={busy || !reopenReason}
115 + onClick={() =>
116 + run(async () => {
117 + const r = await api.requestReopen(yearId, reopenReason, actor)
118 + setLastRequestId(r.request_id)
119 + return `درخواست بازگشایی ثبت شد (${r.request_id}).`
120 + })
121 + }
122 + >
123 + درخواست بازگشایی
124 + </button>
125 + <button
126 + type="button"
127 + disabled={busy || lastRequestId === null}
128 + onClick={() =>
129 + run(async () => {
130 + if (lastRequestId === null) return ''
131 + await api.approveReopen(lastRequestId, actor)
132 + const r = await api.reopenYear(yearId, actor)
133 + return `سال بازگشایی شد: ${r.status}`
134 + })
135 + }
136 + >
137 + تصویب و بازگشایی
138 + </button>
139 + </div>
140 +
141 + <div className="row">
142 + <label>
143 + مسیر پشتیبان
144 + <input value={backupDest} onChange={(e) => setBackupDest(e.target.value)} />
145 + </label>
146 + <button
147 + type="button"
148 + disabled={busy || !backupDest}
149 + onClick={() =>
150 + run(async () => {
151 + const r = await api.backup(backupDest, actor)
152 + return `پشتیبان ساخته شد (زنجیرهٔ ممیزی: ${r.manifest.audit_chain_valid ? 'سالم' : 'مخدوش'}).`
153 + })
154 + }
155 + >
156 + پشتیبان‌گیری
157 + </button>
158 + <button
159 + type="button"
160 + disabled={busy || !backupDest}
161 + onClick={() =>
162 + run(async () => {
163 + const r = await api.verifyBackup(backupDest, actor)
164 + return `پشتیبان ${r.valid ? 'سالم' : 'مخدوش'} است (${r.source_files} فایل، ${r.audit_entries} ممیزی).`
165 + })
166 + }
167 + >
168 + بررسی پشتیبان
169 + </button>
170 + </div>
171 + </>
172 + )}
173 +
174 + {message && <p className="ok">{message}</p>}
175 + {error && <p className="error">{error}</p>}
176 + </section>
177 + )
178 +}