feat(admin): Phase 0 平台超管基础 — is_platform_admin + IsPlatformAdmin + create_platform_admin(admin/admin123) + AdminAuditLog + Admin 后台外壳与路由 gating

后端:User.is_platform_admin + migration;权限类 IsPlatformAdmin;管理命令建 admin/admin123(幂等);
AdminAuditLog 模型 + log_admin_action() helper;me/login 对无团队超管优雅返回 team=null;UserSerializer 暴露标志。
前端:routes/admin 后台外壳(分组侧栏 + 概览 + 占位)、/admin 路由解析与 gating(超管直落、非超管纠回)、
侧栏平台入口、admin-page.css(仅 token)、IconKitSvg 补图标。
测试:accounts 11/11 单测过;无头 e2e _admin-p0.mjs 全断言过 + 0 console error;tsc+build 绿。

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
seaislee1209
2026-06-19 20:49:34 +08:00
co-authored by Claude Opus 4.8
parent 8fc3870fa3
commit 443023a1a9
21 changed files with 907 additions and 12 deletions
@@ -0,0 +1,42 @@
# Generated by Django 5.1.15 on 2026-06-19 12:35
import django.db.models.deletion
import uuid
from django.conf import settings
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('accounts', '0003_invitation'),
]
operations = [
migrations.AddField(
model_name='user',
name='is_platform_admin',
field=models.BooleanField(default=False),
),
migrations.CreateModel(
name='AdminAuditLog',
fields=[
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
('operator_name', models.CharField(blank=True, max_length=150)),
('action', models.CharField(max_length=48)),
('target_type', models.CharField(blank=True, max_length=32)),
('target_id', models.CharField(blank=True, max_length=64)),
('target_name', models.CharField(blank=True, max_length=200)),
('before', models.JSONField(blank=True, null=True)),
('after', models.JSONField(blank=True, null=True)),
('ip_address', models.GenericIPAddressField(blank=True, null=True)),
('operator', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='admin_audit_logs', to=settings.AUTH_USER_MODEL)),
],
options={
'ordering': ['-created_at'],
'indexes': [models.Index(fields=['action'], name='accounts_ad_action_46dc9d_idx'), models.Index(fields=['-created_at'], name='accounts_ad_created_1ae9d4_idx')],
},
),
]