Merge branch 'role' into dev
Co-authored-by: Cursor <cursoragent@cursor.com> # Conflicts: # backend/app/services/shipping_notice/rpa_worker_heartbeat_alert.py # backend/app/services/voucher_check/schedule_seed.py # docs/features/shipping-notice/technical.md # docs/tec.md # frontend/src/features/user/views/UserProfilePage.vue
This commit is contained in:
commit
bb7e0977b8
94 files changed
+4493
-388
No files matched your search
@@ -0,0 +1,129 @@
|
||||
/**
|
||||
* features/workspace/components/WorkspaceSidebar.spec.ts
|
||||
* 用途:验证工作台侧栏「管理控制台」仅对平台管理员露出。
|
||||
* 依赖:Vue Test Utils、vue-router、vue-i18n、workspace.context。
|
||||
* 逻辑:admin 渲染入口并调用 openAdminPanel;普通用户不渲染,避免误点后被守卫踢回。
|
||||
*/
|
||||
import { mount } from '@vue/test-utils';
|
||||
import { createMemoryHistory, createRouter } from 'vue-router';
|
||||
import { createI18n } from 'vue-i18n';
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { WORKSPACE_PATHS } from '../constants/routes';
|
||||
import { WORKSPACE_KEY } from '../composables/workspace.context';
|
||||
import WorkspaceSidebar from './WorkspaceSidebar.vue';
|
||||
|
||||
vi.mock('../composables/useShippingTodoBadge', () => ({
|
||||
useShippingTodoBadge: () => ({
|
||||
pendingBadge: { value: 0 },
|
||||
startShippingTodoBadgePolling: vi.fn(),
|
||||
stopShippingTodoBadgePolling: vi.fn(),
|
||||
}),
|
||||
}));
|
||||
|
||||
vi.mock('@/features/sso', () => ({
|
||||
ExternalSystemLinks: {
|
||||
name: 'ExternalSystemLinks',
|
||||
template: '<div data-testid="external-system-links" />',
|
||||
},
|
||||
}));
|
||||
|
||||
const i18n = createI18n({
|
||||
legacy: false,
|
||||
locale: 'zh-CN',
|
||||
messages: {
|
||||
'zh-CN': {
|
||||
workspace: {
|
||||
brandTitle: 'AI工作台',
|
||||
collapseSidebar: '折叠',
|
||||
expandSidebar: '展开',
|
||||
nav: {
|
||||
profile: '个人中心',
|
||||
admin: '管理控制台',
|
||||
applications: '应用管理',
|
||||
scheduleRuns: '排程记录',
|
||||
receiptReports: '收料文件',
|
||||
shippingNotice: '货代发货',
|
||||
shippingCustomers: '客户主数据',
|
||||
shippingMyTasks: '我的待办',
|
||||
feedback: '意见反馈',
|
||||
updates: '最近更新',
|
||||
knowledgeBase: '知识库',
|
||||
backToChat: '返回聊天',
|
||||
logout: '退出登录',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
/**
|
||||
* 挂载侧栏并注入可观察的工作台上下文。
|
||||
* 核心逻辑:用内存路由承接 RouterLink;按 is_platform_admin 切换 currentUser。
|
||||
*/
|
||||
async function mountSidebar(user: { role: string; is_platform_admin?: boolean }) {
|
||||
const openAdminPanel = vi.fn();
|
||||
const router = createRouter({
|
||||
history: createMemoryHistory(),
|
||||
routes: [
|
||||
{ path: WORKSPACE_PATHS.applications, name: 'workspace-applications', component: { template: '<div />' } },
|
||||
{ path: WORKSPACE_PATHS.profile, name: 'workspace-profile', component: { template: '<div />' } },
|
||||
{ path: WORKSPACE_PATHS.scheduleRuns, name: 'workspace-schedule-runs', component: { template: '<div />' } },
|
||||
{ path: WORKSPACE_PATHS.receiptReports, name: 'workspace-receipt-reports', component: { template: '<div />' } },
|
||||
{ path: WORKSPACE_PATHS.feedback, name: 'workspace-feedback', component: { template: '<div />' } },
|
||||
{ path: WORKSPACE_PATHS.updates, name: 'workspace-updates', component: { template: '<div />' } },
|
||||
{ path: WORKSPACE_PATHS.shippingNoticeCustomers, name: 'workspace-shipping-customers', component: { template: '<div />' } },
|
||||
{ path: WORKSPACE_PATHS.shippingNoticeMyTasks, name: 'workspace-shipping-my-tasks', component: { template: '<div />' } },
|
||||
],
|
||||
});
|
||||
await router.push(WORKSPACE_PATHS.applications);
|
||||
await router.isReady();
|
||||
|
||||
const wrapper = mount(WorkspaceSidebar, {
|
||||
global: {
|
||||
plugins: [i18n, router],
|
||||
provide: {
|
||||
[WORKSPACE_KEY as symbol]: {
|
||||
currentUser: {
|
||||
username: 'admin',
|
||||
role: user.role,
|
||||
is_platform_admin: user.is_platform_admin,
|
||||
},
|
||||
router,
|
||||
openAdminPanel,
|
||||
navigateToKnowledgeBase: vi.fn(),
|
||||
navigateToGeneralChat: vi.fn(),
|
||||
handleLogout: vi.fn(),
|
||||
toggleSidebarCollapsed: vi.fn(),
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
return { wrapper, openAdminPanel };
|
||||
}
|
||||
|
||||
describe('WorkspaceSidebar admin console entry', () => {
|
||||
it('shows the admin console action for platform admins and opens /admin', async () => {
|
||||
const { wrapper, openAdminPanel } = await mountSidebar({
|
||||
role: 'platform_ops',
|
||||
is_platform_admin: true,
|
||||
});
|
||||
const button = wrapper.get('[data-testid="workspace-nav-admin"]');
|
||||
|
||||
// 平台管理员必须能在「返回聊天」上方看到入口。
|
||||
expect(button.text()).toContain('管理控制台');
|
||||
await button.trigger('click');
|
||||
expect(openAdminPanel).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('does not render the admin console action for ordinary users', async () => {
|
||||
const { wrapper, openAdminPanel } = await mountSidebar({
|
||||
role: 'admin',
|
||||
is_platform_admin: false,
|
||||
});
|
||||
|
||||
// 无权限不渲染,避免点了被守卫踢回应用管理。
|
||||
expect(wrapper.find('[data-testid="workspace-nav-admin"]').exists()).toBe(false);
|
||||
expect(openAdminPanel).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
@@ -1,19 +1,20 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* features/workspace/components/WorkspaceSidebar.vue
|
||||
* 工作台左侧导航:子路由链接、货代二级菜单、关联服务入口、返回聊天与退出登录。
|
||||
* 工作台左侧导航:子路由链接、货代二级菜单、关联服务入口、管理控制台、返回聊天与退出登录。
|
||||
* 依赖:WORKSPACE_PATHS、workspace.context、ExternalSystemLinks。
|
||||
* 逻辑:底部关联服务复用 ws-nav-btn,与返回聊天/退出登录对齐。合同付款、立账凭证已迁入 Chat Agent,不再在此展示。
|
||||
* 矮屏时中间导航独立滚动,底部返回聊天/退出登录始终留在视口内。
|
||||
* 逻辑:底部关联服务复用 ws-nav-btn,与管理控制台/返回聊天/退出登录对齐。管理控制台仅平台管理员渲染。
|
||||
* 合同付款、立账凭证已迁入 Chat Agent,不再在此展示。矮屏时中间导航独立滚动,底部操作始终留在视口内。
|
||||
*/
|
||||
import { computed, inject, onBeforeUnmount, onMounted, ref, watch } from 'vue';
|
||||
import { useRoute } from 'vue-router';
|
||||
import {
|
||||
LayoutGrid, Bot, FileText, User, LogOut, Edit, Megaphone, Clock, Package, PanelLeftClose, PanelLeftOpen,
|
||||
ChevronDown, ChevronRight, ContactRound, Inbox, FileDown,
|
||||
ChevronDown, ChevronRight, ContactRound, Inbox, FileDown, Settings,
|
||||
} from 'lucide-vue-next';
|
||||
import { WORKSPACE_PATHS } from '../constants/routes';
|
||||
import { WORKSPACE_KEY } from '../composables/workspace.context';
|
||||
import { isPlatformAdminUser } from '@/shared/utils/auth';
|
||||
import { useShippingTodoBadge } from '../composables/useShippingTodoBadge';
|
||||
import { ExternalSystemLinks } from '@/features/sso';
|
||||
|
||||
@@ -25,7 +26,7 @@ const ws = inject(WORKSPACE_KEY)! as any;
|
||||
const route = useRoute();
|
||||
const shippingRouteNames = ['workspace-shipping-customers', 'workspace-shipping-tasks', 'workspace-shipping-my-tasks'] as const;
|
||||
const shippingExpanded = ref(false);
|
||||
const isAdmin = computed(() => String(ws.currentUser?.role || '').trim().toLowerCase() === 'admin');
|
||||
const isAdmin = computed(() => isPlatformAdminUser(ws.currentUser));
|
||||
const { pendingBadge, startShippingTodoBadgePolling, stopShippingTodoBadgePolling } = useShippingTodoBadge();
|
||||
|
||||
const primaryLinkItems = [
|
||||
@@ -214,6 +215,18 @@ onBeforeUnmount(() => {
|
||||
:button-class="collapsed ? 'ws-nav-btn justify-center px-0' : 'ws-nav-btn'"
|
||||
icon-class="h-[18px] w-[18px] shrink-0"
|
||||
/>
|
||||
<button
|
||||
v-if="isAdmin"
|
||||
type="button"
|
||||
data-testid="workspace-nav-admin"
|
||||
class="ws-nav-btn"
|
||||
:class="collapsed ? 'justify-center px-0' : ''"
|
||||
:title="$t('workspace.nav.admin')"
|
||||
@click="ws.openAdminPanel"
|
||||
>
|
||||
<Settings class="h-[18px] w-[18px]" />
|
||||
<span v-if="!collapsed">{{ $t('workspace.nav.admin') }}</span>
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
@click="ws.navigateToGeneralChat"
|
||||
|
||||
@@ -113,12 +113,18 @@ export function useWorkspaceHome(deps: WorkspaceDeps, options: HomeOptions) {
|
||||
id: data.user.id,
|
||||
username: data.user.username,
|
||||
role: data.user.role,
|
||||
role_name: data.user.role_name,
|
||||
is_platform_admin: data.user.is_platform_admin,
|
||||
default_agent_id: data.user.default_agent_id,
|
||||
feature_permissions: data.user.feature_permissions || {},
|
||||
};
|
||||
if (data.user?.feature_permissions && typeof data.user.feature_permissions === 'object') {
|
||||
// 首页刷新把服务端有效权限写回登录态,避免管理员刚授权后必须重新登录。
|
||||
patchStoredAuthUser({ feature_permissions: data.user.feature_permissions });
|
||||
if (data.user && typeof data.user === 'object') {
|
||||
patchStoredAuthUser({
|
||||
role: data.user.role,
|
||||
role_name: data.user.role_name,
|
||||
is_platform_admin: data.user.is_platform_admin,
|
||||
feature_permissions: data.user.feature_permissions || {},
|
||||
});
|
||||
useAuthStore().syncFromStorage();
|
||||
}
|
||||
agents.value = data.agents || [];
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
* features/workspace/composables/useWorkspaceNavigation.ts
|
||||
* 用途:子路由导航、移动端 Tab、聊天跳转、企微 deeplink 与旧 view 参数兼容。
|
||||
* 用途:子路由导航、移动端 Tab、聊天/管理控制台跳转、企微 deeplink 与旧 view 参数兼容。
|
||||
* 依赖:vue-router、config、auth、requestJson、workspace routes/types。
|
||||
* 逻辑:由 useWorkspace 注入;知识库无权限时 toast t('workspace.kb.accessDenied')。
|
||||
* 逻辑:由 useWorkspace 注入;知识库无权限时 toast t('workspace.kb.accessDenied');管理控制台入口由侧栏按管理员角色渲染。
|
||||
*/
|
||||
import { computed, nextTick, ref, watch, type ComputedRef, type Ref } from 'vue';
|
||||
import { config } from '@/config';
|
||||
@@ -138,6 +138,11 @@ export function useWorkspaceNavigation(deps: WorkspaceDeps, options: NavigationO
|
||||
router.push(`/chat/${getLastChatAgentId(DEFAULT_POST_LOGIN_AGENT_ID)}`);
|
||||
};
|
||||
|
||||
/**
|
||||
* 从工作台进入管理控制台。
|
||||
* 核心逻辑:跳转 `/admin`;无管理员权限时由路由守卫静默回应用管理。
|
||||
* 触发时机:侧栏底部「管理控制台」入口(仅平台管理员渲染)。
|
||||
*/
|
||||
const openAdminPanel = () => {
|
||||
router.push('/admin');
|
||||
};
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* 逻辑:从本地登录态恢复 id/username/role/feature_permissions,供工作台侧栏判断专项权限。
|
||||
*/
|
||||
import { computed, type Ref } from 'vue';
|
||||
import { logoutAuth, getStoredAuthUser } from '@/shared/utils/auth';
|
||||
import { logoutAuth, getStoredAuthUser, isPlatformAdminUser } from '@/shared/utils/auth';
|
||||
import { KB_ACCESS_DENIED_MESSAGE } from '../types/workspace.types';
|
||||
import type { WorkspaceUser } from '../types/workspace.types';
|
||||
import type { WorkspaceDeps } from './workspace.deps';
|
||||
@@ -20,9 +20,7 @@ export function useWorkspaceSession(deps: WorkspaceDeps, options: SessionOptions
|
||||
const { currentUser } = options;
|
||||
|
||||
const isLoggedIn = computed(() => !!currentUser.value && currentUser.value.role !== 'guest');
|
||||
const hasKnowledgeBaseAccess = computed(
|
||||
() => String(currentUser.value?.role || '').trim().toLowerCase() === 'admin',
|
||||
);
|
||||
const hasKnowledgeBaseAccess = computed(() => isPlatformAdminUser(currentUser.value));
|
||||
|
||||
const loadAuthUser = () => {
|
||||
let stored = localStorage.getItem('hxops_user');
|
||||
@@ -55,6 +53,8 @@ export function useWorkspaceSession(deps: WorkspaceDeps, options: SessionOptions
|
||||
id: user.id || 0,
|
||||
username: user.username || '',
|
||||
role: user.role || 'user',
|
||||
role_name: user.role_name,
|
||||
is_platform_admin: user.is_platform_admin,
|
||||
feature_permissions: user.feature_permissions,
|
||||
};
|
||||
} catch {
|
||||
|
||||
@@ -2,14 +2,29 @@
|
||||
/**
|
||||
* features/workspace/pages/ProfilePage.vue
|
||||
* 个人中心:用户资料展示与编辑、语言/主题偏好、修改密码入口。
|
||||
* 依赖:workspace.context、lucide 图标、vue-i18n、isPlatformAdminUser。
|
||||
* 逻辑:角色展示优先用权限组名称;旧会话缺 role_name 时再回退管理员/用户文案。
|
||||
*/
|
||||
import { inject } from 'vue';
|
||||
import { computed, inject } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import {
|
||||
User, Mail, Building, CreditCard, Globe, Save, Palette,
|
||||
} from 'lucide-vue-next';
|
||||
import { WORKSPACE_KEY } from '../composables/workspace.context';
|
||||
import { isPlatformAdminUser } from '@/shared/utils/auth';
|
||||
|
||||
const ws = inject(WORKSPACE_KEY)! as any;
|
||||
const { t } = useI18n();
|
||||
|
||||
/**
|
||||
* 个人中心角色标签。
|
||||
* 核心逻辑:有权限组名称就展示名称;否则按 is_platform_admin 回退内置文案。
|
||||
*/
|
||||
const profileRoleLabel = computed(() => {
|
||||
const user = ws.profileUser || {};
|
||||
if (user.role_name) return user.role_name;
|
||||
return isPlatformAdminUser(user) ? t('profile.roleAdmin') : t('profile.roleUser');
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -38,8 +53,8 @@ const ws = inject(WORKSPACE_KEY)! as any;
|
||||
<div v-if="ws.isMobile" class="text-sm font-medium text-primary truncate">{{ ws.profileUser.department || '-' }}</div>
|
||||
</div>
|
||||
<div>
|
||||
<div :class="ws.isMobile ? 'text-xs text-muted' : 'text-lg font-semibold text-primary'">{{ ws.isMobile ? $t('profile.role') : (ws.profileUser.role === 'admin' ? ($t('profile.roleAdmin') || 'Administrator') : ($t('profile.roleUser') || 'User')) }}</div>
|
||||
<div v-if="ws.isMobile" class="text-sm font-medium text-primary truncate">{{ ws.profileUser.role === 'admin' ? ($t('profile.roleAdmin') || 'Administrator') : ($t('profile.roleUser') || 'User') }}</div>
|
||||
<div :class="ws.isMobile ? 'text-xs text-muted' : 'text-lg font-semibold text-primary'">{{ ws.isMobile ? $t('profile.role') : profileRoleLabel }}</div>
|
||||
<div v-if="ws.isMobile" class="text-sm font-medium text-primary truncate">{{ profileRoleLabel }}</div>
|
||||
</div>
|
||||
<div :class="ws.isMobile ? 'col-span-2' : 'sm:col-span-2'">
|
||||
<div :class="ws.isMobile ? 'text-xs text-muted' : 'break-all text-lg font-semibold text-primary'">{{ ws.isMobile ? $t('profile.email') : (ws.profileUser.email || '-') }}</div>
|
||||
|
||||
@@ -13,13 +13,14 @@ import {
|
||||
resendReceiptReportFile, retryReceiptRpaUnit, type ReceiptReportFile, type ReceiptRpaUnit,
|
||||
} from '../api/receipt-report.api';
|
||||
import { WORKSPACE_KEY } from '../composables/workspace.context';
|
||||
import { isPlatformAdminUser } from '@/shared/utils/auth';
|
||||
|
||||
const files = ref<ReceiptReportFile[]>([]);
|
||||
const failedUnits = ref<ReceiptRpaUnit[]>([]);
|
||||
const loading = ref(false);
|
||||
const { t } = useI18n();
|
||||
const ws = inject(WORKSPACE_KEY);
|
||||
const isAdmin = computed(() => String(ws?.currentUser?.role || '').trim().toLowerCase() === 'admin');
|
||||
const isAdmin = computed(() => isPlatformAdminUser(ws?.currentUser));
|
||||
|
||||
/** 读取当前用户的收料归档,不在前端补充或推断授权范围。 */
|
||||
async function loadFiles(): Promise<void> {
|
||||
|
||||
@@ -11,6 +11,8 @@ export interface WorkspaceUser {
|
||||
id: number;
|
||||
username: string;
|
||||
role: string;
|
||||
role_name?: string;
|
||||
is_platform_admin?: boolean;
|
||||
default_agent_id?: number | null;
|
||||
feature_permissions?: FeaturePermissions;
|
||||
}
|
||||
@@ -84,6 +86,8 @@ export interface WorkspaceProfileForm {
|
||||
phone_number: string;
|
||||
department: string;
|
||||
role: string;
|
||||
role_name?: string;
|
||||
is_platform_admin?: boolean;
|
||||
employee_id: string;
|
||||
language: string;
|
||||
theme_preference: ThemePreference;
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
* 用途:立账凭证检核任务列表——按资料所属期间(年 + 月)查看批次统计,并展示最近一次检核。
|
||||
* 依赖:voucherCheck.api、vue-i18n、useMessage、DeleteConfirmDialog、PaginationBar、formatLocalDateTime、voucherCheck.display、auth。
|
||||
* Chat 嵌入时由 VoucherCheckChatPanel 传入 embedded / activeTab。
|
||||
* 逻辑:独立路由或 Chat 嵌入;进页默认上一个自然月;「最近一次检核」不跟筛选;强制重检仅 admin,进度在本卡轮询。
|
||||
* 逻辑:独立路由或 Chat 嵌入;进页默认上一个自然月;「最近一次检核」不跟筛选;强制重检仅 is_platform_admin,进度在本卡轮询。
|
||||
* 终态用矮指标格;排队/执行中才展开进度条与当前步骤。Chat 嵌入时隐藏页头与内层 Tab。
|
||||
*/
|
||||
import { computed, onMounted, onUnmounted, ref, watch } from 'vue';
|
||||
@@ -14,7 +14,7 @@ import { ChevronDown, Download, Loader2, RotateCcw, Search } from 'lucide-vue-ne
|
||||
import DeleteConfirmDialog from '@/shared/components/DeleteConfirmDialog.vue';
|
||||
import PaginationBar from '@/shared/components/PaginationBar.vue';
|
||||
import { useMessage } from '@/shared/composables/useMessage';
|
||||
import { getStoredAuthUser } from '@/shared/utils/auth';
|
||||
import { getStoredAuthUser, isPlatformAdminUser } from '@/shared/utils/auth';
|
||||
import { formatLocalDateTime } from '@/shared/utils/dateTime';
|
||||
import { WORKSPACE_PATHS } from '../constants/routes';
|
||||
import {
|
||||
@@ -72,7 +72,7 @@ const latestRun = ref<VoucherCheckLatestRun | null>(null);
|
||||
const latestLoading = ref(false);
|
||||
let forcePollTimer: ReturnType<typeof setInterval> | null = null;
|
||||
|
||||
const isAdmin = computed(() => String(getStoredAuthUser()?.role || '').trim().toLowerCase() === 'admin');
|
||||
const isAdmin = computed(() => isPlatformAdminUser(getStoredAuthUser()));
|
||||
const latestInProgress = computed(() => {
|
||||
const cardStatus = latestRun.value?.status;
|
||||
return cardStatus === 'queued' || cardStatus === 'running';
|
||||
|
||||
Reference in new issue
Block a user