feat(ECR-013A): Admin RBAC 实现并 Closed

角色权限、RequirePermission、/me permissions 与 migration 000015;
Reviewer Approve → Closed。Next:ECR-013B Contract Definition。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
jackyu66git
2026-08-07 17:19:45 +08:00
co-authored by Cursor
parent 85ed0901bb
commit b5a05941d9
35 changed files with 1518 additions and 49 deletions
+6 -3
View File
@@ -32,12 +32,15 @@ func (r *AdminRepo) CountAccounts(ctx context.Context) (int, error) {
return n, err
}
// CreateAccount inserts an admin account.
// CreateAccount inserts an admin account with seeded super_admin role.
func (r *AdminRepo) CreateAccount(ctx context.Context, username, hash string) (uuid.UUID, error) {
var id uuid.UUID
err := r.Pool.QueryRow(ctx, `
INSERT INTO admin_accounts(username, password_hash)
VALUES ($1,$2) RETURNING id`, username, hash).Scan(&id)
INSERT INTO admin_accounts(username, password_hash, role_id)
VALUES (
$1, $2,
(SELECT id FROM admin_roles WHERE name = 'super_admin' LIMIT 1)
) RETURNING id`, username, hash).Scan(&id)
return id, err
}