From 18c3a8b3ad2cae49e3bb6ab5dcf0b79ecec63e35 Mon Sep 17 00:00:00 2001 From: root Date: Mon, 11 May 2026 15:11:10 +0000 Subject: [PATCH] =?UTF-8?q?feat:=20add=20useradmin=20role=20-=E8=BF=90?= =?UTF-8?q?=E8=90=A5=E7=AE=A1=E7=90=86=E5=91=98=E6=9D=83=E9=99=90=EF=BC=8C?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E7=AE=A1=E7=90=86=E7=94=A8=E6=88=B7/?= =?UTF-8?q?=E8=AE=A2=E5=8D=95/=E9=A3=8E=E6=8E=A7=E7=AD=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/internal/domain/constants.go | 3 ++- backend/internal/server/middleware/admin_only.go | 2 +- backend/internal/service/domain_constants.go | 5 +++-- backend/internal/service/user.go | 2 +- frontend/src/router/index.ts | 4 ++-- frontend/src/stores/auth.ts | 5 +++++ 6 files changed, 14 insertions(+), 7 deletions(-) diff --git a/backend/internal/domain/constants.go b/backend/internal/domain/constants.go index 27c543dd..7859e596 100644 --- a/backend/internal/domain/constants.go +++ b/backend/internal/domain/constants.go @@ -13,7 +13,8 @@ const ( // Role constants const ( RoleAdmin = "admin" - RoleUser = "user" + RoleUser = "user" + RoleUserAdmin = "useradmin" ) // Platform constants diff --git a/backend/internal/server/middleware/admin_only.go b/backend/internal/server/middleware/admin_only.go index 2cd697a3..ff34da64 100644 --- a/backend/internal/server/middleware/admin_only.go +++ b/backend/internal/server/middleware/admin_only.go @@ -16,7 +16,7 @@ func AdminOnly() gin.HandlerFunc { return } - // 检查是否为管理员 + // 检查是否为超级管理员(admin) if role != service.RoleAdmin { AbortWithError(c, 403, "FORBIDDEN", "Admin access required") return diff --git a/backend/internal/service/domain_constants.go b/backend/internal/service/domain_constants.go index 17c40ba1..46db22c2 100644 --- a/backend/internal/service/domain_constants.go +++ b/backend/internal/service/domain_constants.go @@ -14,8 +14,9 @@ const ( // Role constants const ( - RoleAdmin = domain.RoleAdmin - RoleUser = domain.RoleUser + RoleAdmin = domain.RoleAdmin + RoleUser = domain.RoleUser + RoleUserAdmin = domain.RoleUserAdmin ) // Affiliate rebate settings diff --git a/backend/internal/service/user.go b/backend/internal/service/user.go index f9833611..90725f02 100644 --- a/backend/internal/service/user.go +++ b/backend/internal/service/user.go @@ -63,7 +63,7 @@ type User struct { } func (u *User) IsAdmin() bool { - return u.Role == RoleAdmin + return u.Role == RoleAdmin || u.Role == RoleUserAdmin } func (u *User) IsActive() bool { diff --git a/frontend/src/router/index.ts b/frontend/src/router/index.ts index 656421cc..49bab903 100644 --- a/frontend/src/router/index.ts +++ b/frontend/src/router/index.ts @@ -765,8 +765,8 @@ router.beforeEach((to, _from, next) => { return } - // Check admin requirement - if (requiresAdmin && !authStore.isAdmin) { + // Check admin requirement (requires admin role, not useradmin) + if (requiresAdmin && !authStore.isSuperAdmin) { // User is authenticated but not admin, redirect to user dashboard next('/dashboard') return diff --git a/frontend/src/stores/auth.ts b/frontend/src/stores/auth.ts index 4b712692..e0a1d758 100644 --- a/frontend/src/stores/auth.ts +++ b/frontend/src/stores/auth.ts @@ -87,6 +87,10 @@ export const useAuthStore = defineStore('auth', () => { }) const isAdmin = computed(() => { + return user.value?.role === 'admin' || user.value?.role === 'useradmin' + }) + + const isSuperAdmin = computed(() => { return user.value?.role === 'admin' }) @@ -476,6 +480,7 @@ export const useAuthStore = defineStore('auth', () => { // Computed isAuthenticated, isAdmin, + isSuperAdmin, isSimpleMode, hasPendingAuthSession,