feat(system): consolidate system admin and settings into one Settings panel

Replace the standalone /platform/system/* routes with a single
"系统设置" section inside the canonical Settings modal. The previous
SystemLayout.vue / SystemAdmins.vue surfaces are removed and their
functionality (system admin roster, global settings) is hosted directly
in SystemSettings.vue under the standard `.section-header` /
`.settings-group` skeleton. Legacy URLs redirect to the modal section
so external bookmarks don't 404.

Backend:
- SystemSettingService.Reset + repo.Delete: drop the DB override for a
  key so the 3-tier resolver falls back to ENV / built-in default.
  Idempotent (resetting a never-persisted key returns nil); emits an
  audit row only on real deletions, invalidates the local cache, and
  publishes to peers via the existing pubsub channel.
- TenantService.BulkSetStorageQuota: overwrite every tenant's
  storage_quota in one statement. Powers POST /system/admin/tenants/
  apply-default-storage-quota; bypasses the per-tenant whitelist on
  PUT /tenants/:id which intentionally forbids storage_quota edits.
- AuditAction{SystemAdminPromoted,SystemAdminRevoked} constants and
  emitAdminAudit() in SystemHandler — promote / revoke now leave an
  audit trail with TenantID=0 and {target_email,target_username,
  idempotent|changed} in details.
- SystemSetting.LastModifiedByName: derived per-request display label
  (username, email fallback) so the UI shows "wizardchen" instead of
  a UUID prefix without storing a denormalised column.

Frontend:
- SystemSettings.vue rewritten against the Settings modal skeleton with
  auto-persisting controls (switch/select @change, input/inputnumber
  @blur, tag-input + per-delta popconfirm for SSRF whitelist and admin
  roster). auth.registration_mode change goes through an inline
  popconfirm; cancel rolls back. Reset / bulk-apply also inline
  popconfirms — no dialog modal for these per-row affordances.
- Priority hint panel surfaces the DB > ENV > default resolver order
  so operators can reason about "I set the env but it doesn't show up".
- Router: /platform/system, /platform/system/settings, /platform/system/
  admins are now compatibility redirects to /platform/settings?section=
  system-global.
- Settings modal sized 900x700 → 1080x780 and content-wrapper 600 → 760
  so the wider tables (members, system settings) breathe; <1100px
  viewport still flexes to the screen.
- i18n: system.globalSettings.* keys for title / description / loading /
  empty / badges / priority hint / per-key labels / reset / bulkApply /
  admins (label, placeholder, save messages, popconfirm copy) across
  zh-CN, en-US, ko-KR, ru-RU.

Misc:
- internal/utils/filesize.go doc: clarify MAX_FILE_SIZE_MB is a
  deploy-time-only knob (nginx + docreader + frontend each cache the
  env at startup); a SystemAdmin UI override would mislead operators
  because nginx would still 413. Until all four layers can hot-reload
  the limit in lockstep, this stays env-only.
- internal/utils/security.go: SSRF whitelist parser/runtime now drives
  off SystemSettingService for live updates; ENV remains the fallback
  for never-overridden deployments.
This commit is contained in:
wizardchen
2026-05-26 20:03:35 +08:00
committed by lyingbug
parent 311a033523
commit 9cce0c8e5e
31 changed files with 2207 additions and 753 deletions
+18
View File
@@ -98,6 +98,24 @@ const (
// for now no setting is marked secret). Audit rows always have
// tenant_id=0 because the change is system-scope, not tenant-scope.
AuditActionSystemSettingChanged AuditAction = "system.setting_changed"
// AuditActionSystemAdminPromoted fires when a SystemAdmin grants
// system-administrator privileges to another user via
// POST /api/v1/system/admin/promote. ActorUserID is the promoter,
// TargetUserID is the user being promoted. Details payload carries
// {target_email, target_username, idempotent} — `idempotent=true`
// means the user was already a system admin and no row was written
// (we still emit the row so probing the endpoint leaves a trail).
// TenantID=0 because the change is system-scope.
AuditActionSystemAdminPromoted AuditAction = "system.admin_promoted"
// AuditActionSystemAdminRevoked fires when a SystemAdmin removes
// system-administrator privileges from another user via
// POST /api/v1/system/admin/revoke. Details payload carries
// {target_email, target_username, changed} — `changed=false` covers
// the idempotent path (target was already not an admin) so an audit
// reader can distinguish a real revoke from a noop attempt.
// TenantID=0 because the change is system-scope.
AuditActionSystemAdminRevoked AuditAction = "system.admin_revoked"
)
// AuditOutcome distinguishes successful mutations from middleware-level
@@ -20,6 +20,11 @@ type SystemSettingRepository interface {
// Upsert writes a row keyed by Key. Insert if missing, update if
// present. Used by SystemSettingService.Update on every save.
Upsert(ctx context.Context, s *types.SystemSetting) error
// Delete removes the row by key. Returns (true, nil) if a row was
// deleted, (false, nil) if no row matched (idempotent — service
// layer treats this as a no-op for audit purposes). Real DB errors
// surface as (_, err).
Delete(ctx context.Context, key string) (bool, error)
}
// SystemSettingService exposes both the 3-tier resolver (used by
@@ -70,6 +75,14 @@ type SystemSettingService interface {
// written to last_modified_by + the audit log.
// Returns the persisted row on success.
Update(ctx context.Context, key string, rawValue any) (*types.SystemSetting, error)
// Reset removes the DB override for `key` so the resolver falls
// back to ENV / built-in default. Idempotent: deleting a key that
// was never persisted returns nil. Emits an audit row on actual
// deletions, invalidates the local cache, and publishes to peers.
// Returns an error only when the DB write itself fails; callers
// must NOT translate "no row" into a 404 — that's the success
// path for an idempotent reset.
Reset(ctx context.Context, key string) error
// SubscribeRedis is a P2 hook: when implemented, it will subscribe
// to a "weknora:system_settings:changed" channel and invalidate any
+9
View File
@@ -28,6 +28,13 @@ type TenantService interface {
ExtractTenantIDFromAPIKey(apiKey string) (uint64, error)
// ListAllTenants lists all tenants (for users with cross-tenant access permission)
ListAllTenants(ctx context.Context) ([]*types.Tenant, error)
// BulkSetStorageQuota overwrites every tenant's storage_quota with
// quotaBytes. Returns how many rows were affected. Used by the
// SystemAdmin "apply default to all tenants" action; bypasses the
// per-tenant whitelist on PUT /tenants/:id (which intentionally
// forbids storage_quota edits for Owners). quotaBytes must be > 0;
// callers are responsible for resolving GB→bytes.
BulkSetStorageQuota(ctx context.Context, quotaBytes int64) (int64, error)
// SearchTenants searches tenants with pagination and filters
SearchTenants(ctx context.Context, keyword string, tenantID uint64, page, pageSize int) ([]*types.Tenant, int64, error)
// GetTenantByIDForUser gets a tenant by ID with permission check
@@ -54,4 +61,6 @@ type TenantRepository interface {
DeleteTenant(ctx context.Context, id uint64) error
// AdjustStorageUsed adjusts the storage used for a tenant
AdjustStorageUsed(ctx context.Context, tenantID uint64, delta int64) error
// BulkSetStorageQuota — see TenantService.BulkSetStorageQuota.
BulkSetStorageQuota(ctx context.Context, quotaBytes int64) (int64, error)
}
+7
View File
@@ -52,6 +52,13 @@ type SystemSetting struct {
// means the UI should render a select with these options. Tagged
// `gorm:"-"` so GORM never tries to read/write the column.
Enum []string `gorm:"-" json:"enum,omitempty"`
// LastModifiedByName is a display label resolved from LastModifiedBy
// (the user's UUID) at handler time — username when available,
// otherwise email. Empty for virtual rows that were never persisted
// (LastModifiedBy=""). Not stored: derived per request so renaming
// a user reflects on the next reload without a backfill job.
LastModifiedByName string `gorm:"-" json:"last_modified_by_name,omitempty"`
}
// TableName pins the schema to migration 000053 — GORM's default