feat(system-admin): implement bootstrap for system admin promotion and enhance system settings management
- Added WEKNORA_BOOTSTRAP_SYSTEM_ADMIN_EMAIL environment variable to promote a specified user to system admin on startup. - Introduced a new bootstrap process in `bootstrap.go` to handle the promotion logic. - Updated `.env.example` to document the new environment variable and its behavior. - Created new views for managing system administrators and system settings, including listing, promoting, and revoking admin privileges. - Enhanced the frontend to reflect the new system admin features, including UI elements for admin management and settings configuration. - Updated API interfaces to support system admin functionalities, ensuring proper data handling and user management.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { createRouter, createWebHistory } from 'vue-router'
|
||||
import type { RouteLocationNormalized } from 'vue-router'
|
||||
import { useAuthStore } from '@/stores/auth'
|
||||
import { autoSetup, getCurrentUser } from '@/api/auth'
|
||||
import { autoSetup, getCurrentUser, userInfoFromApi } from '@/api/auth'
|
||||
|
||||
/** Lite /桌面 WebView 硬刷新时可能只打开 `/`,用 session 记住上次页面以便恢复 */
|
||||
const LITE_LAST_PATH_KEY = 'weknora_lite_last_path'
|
||||
@@ -140,6 +140,33 @@ const router = createRouter({
|
||||
component: () => import("../views/organization/OrganizationList.vue"),
|
||||
meta: { requiresInit: true, requiresAuth: true }
|
||||
},
|
||||
// System administration area — gated to users with
|
||||
// user.is_system_admin === true. The route guard below honours
|
||||
// the meta.requiresSystemAdmin flag; non-admins are bounced to
|
||||
// /platform/knowledge-bases. Real authorisation lives server-side.
|
||||
{
|
||||
path: "system",
|
||||
component: () => import("../views/system/SystemLayout.vue"),
|
||||
meta: { requiresInit: true, requiresAuth: true, requiresSystemAdmin: true },
|
||||
redirect: "/platform/system/settings",
|
||||
children: [
|
||||
{
|
||||
// P1 default landing page — the SystemAdmin lands here
|
||||
// because most platform-level operations involve tweaking
|
||||
// a setting, not promoting another admin.
|
||||
path: "settings",
|
||||
name: "systemSettings",
|
||||
component: () => import("../views/system/SystemSettings.vue"),
|
||||
meta: { requiresInit: true, requiresAuth: true, requiresSystemAdmin: true }
|
||||
},
|
||||
{
|
||||
path: "admins",
|
||||
name: "systemAdmins",
|
||||
component: () => import("../views/system/SystemAdmins.vue"),
|
||||
meta: { requiresInit: true, requiresAuth: true, requiresSystemAdmin: true }
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
// Dev-only markdown rendering test page
|
||||
@@ -155,17 +182,7 @@ const router = createRouter({
|
||||
// 持久化 auto-setup / login 返回的认证信息到 store
|
||||
function persistLoginResponse(authStore: ReturnType<typeof useAuthStore>, response: any) {
|
||||
if (response.user && response.tenant && response.token) {
|
||||
authStore.setUser({
|
||||
id: response.user.id || '',
|
||||
username: response.user.username || '',
|
||||
email: response.user.email || '',
|
||||
avatar: response.user.avatar,
|
||||
tenant_id: String(response.tenant.id) || '',
|
||||
can_access_all_tenants: response.user.can_access_all_tenants || false,
|
||||
preferences: response.user.preferences,
|
||||
created_at: response.user.created_at || new Date().toISOString(),
|
||||
updated_at: response.user.updated_at || new Date().toISOString()
|
||||
})
|
||||
authStore.setUser(userInfoFromApi(response.user, response.tenant.id))
|
||||
authStore.setToken(response.token)
|
||||
if (response.refresh_token) {
|
||||
authStore.setRefreshToken(response.refresh_token)
|
||||
@@ -201,17 +218,7 @@ async function hydrateSessionFromToken(authStore: ReturnType<typeof useAuthStore
|
||||
return false
|
||||
}
|
||||
|
||||
authStore.setUser({
|
||||
id: user.id || '',
|
||||
username: user.username || '',
|
||||
email: user.email || '',
|
||||
avatar: user.avatar,
|
||||
tenant_id: String(user.tenant_id || response.data?.tenant?.id || ''),
|
||||
can_access_all_tenants: user.can_access_all_tenants || false,
|
||||
preferences: user.preferences,
|
||||
created_at: user.created_at || new Date().toISOString(),
|
||||
updated_at: user.updated_at || new Date().toISOString(),
|
||||
})
|
||||
authStore.setUser(userInfoFromApi(user, response.data?.tenant?.id))
|
||||
|
||||
const tenant = response.data?.tenant
|
||||
if (tenant) {
|
||||
@@ -315,6 +322,17 @@ router.beforeEach(async (to, from, next) => {
|
||||
}
|
||||
}
|
||||
|
||||
// SystemAdmin gate — checked AFTER auth so a non-admin who's logged
|
||||
// out gets redirected to /login first (consistent with how the rest
|
||||
// of the auth flow works), and only an authenticated non-admin sees
|
||||
// the bounce. This is UI-only; the server enforces the real check.
|
||||
if (to.meta.requiresSystemAdmin === true) {
|
||||
if (!authStore.isSystemAdmin) {
|
||||
next('/platform/knowledge-bases')
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
next()
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user