feat: add platform staff management

This commit is contained in:
Codex
2026-06-30 08:28:44 +08:00
parent 780feee4f8
commit 4f64b7aed8
21 changed files with 1205 additions and 25 deletions

View File

@@ -83,11 +83,44 @@ function runWorkerOnce() {
}
async function cleanup(pool) {
await pool.query(
`
delete from public.platform_audit_notification_events
where channel_id in (
select id
from public.platform_audit_notification_channels
where channel_code in ('worker_platform_audit_test', 'integration_platform_audit')
)
or alert_id in (
select id
from public.platform_audit_alerts
where details->>'source' in ('worker-test', 'api-integration-test')
or details->>'workerId' = 'platform-audit-alert-worker-test'
)
`,
);
await pool.query("delete from public.platform_audit_notification_events where alert_id = $1", [ids.alert]);
await pool.query("delete from public.platform_audit_notification_channels where channel_code = 'worker_platform_audit_test'");
await pool.query("delete from app_private.platform_secrets where secret_scope = 'webhook' and secret_key = 'worker_platform_audit_test'");
await pool.query('delete from public.platform_audit_alerts where id = $1 or audit_log_id = $2', [ids.alert, ids.auditLog]);
await pool.query('delete from public.audit_logs where id = $1 or tenant_id = $2', [ids.auditLog, ids.tenant]);
await pool.query(
`
delete from public.platform_audit_alerts
where id = $1
or audit_log_id = $2
or details->>'source' in ('worker-test', 'api-integration-test')
or details->>'workerId' = 'platform-audit-alert-worker-test'
`,
[ids.alert, ids.auditLog],
);
await pool.query(
`
delete from public.audit_logs
where id = $1
or tenant_id = $2
or user_agent in ('platform-audit-notification-worker-test', 'platform-audit-alert-worker-test')
`,
[ids.auditLog, ids.tenant],
);
await pool.query('delete from public.tenant_billing_profiles where tenant_id = $1', [ids.tenant]);
await pool.query('delete from public.tenant_domains where tenant_id = $1', [ids.tenant]);
await pool.query('delete from public.tenants where id = $1', [ids.tenant]);
@@ -108,7 +141,7 @@ async function seed(pool, webhookUrl) {
details, ip_address, user_agent, created_at
)
values (
$1, $2::uuid, null, 'platform.tenant.status_updated', 'tenant', $3,
$1, $2::uuid, null, 'platform.worker_test.status_updated', 'tenant', $3,
'{"status":"suspended","apiKey":"must-not-leak","nested":{"password":"must-not-leak"}}'::jsonb,
'127.0.0.1', 'platform-audit-notification-worker-test', now()
)
@@ -125,7 +158,7 @@ async function seed(pool, webhookUrl) {
)
values (
$1, $2, $3, $4::uuid, 'high', 'open',
'platform.tenant.status_updated', 'tenant', $4,
'platform.worker_test.status_updated', 'tenant', $4,
'租户状态变更告警', 'platform audit notification integration alert',
'{"source":"worker-test","apiKey":"must-not-leak","nested":{"password":"must-not-leak"}}'::jsonb,
now(), now()
@@ -153,7 +186,7 @@ async function seed(pool, webhookUrl) {
values (
'worker_platform_audit_test', 'Worker 平台审计通知', true, 'generic',
$1, 'app_private.platform_secrets:webhook:worker_platform_audit_test',
'medium', array['open']::text[], array['platform.tenant.*']::text[], 5
'medium', array['open']::text[], array['platform.worker_test.*']::text[], 5
)
on conflict (channel_code)
do update set enabled = excluded.enabled,