97 lines
4.6 KiB
Transact-SQL
97 lines
4.6 KiB
Transact-SQL
/* ============================================================================
|
||
工作流权限点注册(s_power / s_user_power)
|
||
|
||
依据文档:FMS工作流与审批设计.md §10.1 / §10.2(动作权限 action.{模块}.{动作})、
|
||
§14.4(审批中心四页与流程管理的菜单授权)
|
||
|
||
说明:
|
||
1. 运行侧服务是白名单语义:s_power 里没有对应权限点、或用户没被授权,一律拒绝
|
||
(WorkflowRuntimeService.requireAction)。所以流程上线前必须先把权限点补上。
|
||
2. 菜单权限点:menu.{菜单编码},b_object_type='menu',b_action='access'。
|
||
3. 动作权限点按「已配置流程绑定的模块」批量生成,共 11 个动作
|
||
(submit / approve / reject / return / withdraw / transfer / delegate / reassign /
|
||
add_approver / urge / workflow_admin)。
|
||
4. g3soft 是管理员账号(后端已提权),这里仍显式授权,便于在用户权限页看到。
|
||
5. 脚本幂等,可重复执行。
|
||
============================================================================ */
|
||
|
||
SET NOCOUNT ON;
|
||
GO
|
||
|
||
/* ----------------------------------------------------------------------------
|
||
1. 菜单权限点
|
||
---------------------------------------------------------------------------- */
|
||
|
||
declare @menus table (b_id varchar(150), b_name nvarchar(200), b_menu_id varchar(50), b_xh int);
|
||
|
||
insert into @menus (b_id, b_name, b_menu_id, b_xh)
|
||
values
|
||
('menu.workflow', N'流程管理', 'workflow', 10),
|
||
('menu.approval', N'审批中心', 'approval', 20),
|
||
('menu.approval_todo', N'我的待办', 'approval_todo', 30),
|
||
('menu.approval_initiated', N'我发起的', 'approval_initiated', 40),
|
||
('menu.approval_done', N'我已处理', 'approval_done', 50),
|
||
('menu.approval_cc', N'抄送我的', 'approval_cc', 60);
|
||
|
||
insert into dbo.s_power (b_id, b_name, b_type, b_object_type, b_object_id, b_action, b_canuse, b_xh)
|
||
select m.b_id, m.b_name, 'menu', 'menu', m.b_menu_id, 'access', 1, m.b_xh
|
||
from @menus m
|
||
where exists (select 1 from dbo.s_menu s where s.b_id = m.b_menu_id)
|
||
and not exists (select 1 from dbo.s_power p where p.b_id = m.b_id);
|
||
GO
|
||
|
||
/* ----------------------------------------------------------------------------
|
||
2. 动作权限点:按已配置绑定的模块生成
|
||
---------------------------------------------------------------------------- */
|
||
|
||
declare @actions table (b_action varchar(30), b_name nvarchar(200), b_xh int);
|
||
|
||
insert into @actions (b_action, b_name, b_xh)
|
||
values
|
||
('submit', N'送审', 10),
|
||
('approve', N'通过', 20),
|
||
('reject', N'驳回', 30),
|
||
('return', N'退回', 40),
|
||
('withdraw', N'撤回', 50),
|
||
('transfer', N'转交', 60),
|
||
('delegate', N'委托', 70),
|
||
('reassign', N'转派', 80),
|
||
('add_approver', N'加签', 90),
|
||
('urge', N'催办', 100),
|
||
('workflow_admin', N'流程管理员', 110);
|
||
|
||
insert into dbo.s_power (b_id, b_name, b_type, b_object_type, b_object_id, b_action, b_canuse, b_xh)
|
||
select 'action.' + b.b_module_id + '.' + a.b_action,
|
||
isnull(m.b_name, b.b_module_id) + N' - ' + a.b_name,
|
||
'action', 'module', b.b_module_id, a.b_action, 1, a.b_xh
|
||
from (select distinct b_module_id from dbo.wf_binding where b_canuse = 1) b
|
||
left join dbo.s_module m on m.b_id = b.b_module_id
|
||
cross join @actions a
|
||
where not exists (
|
||
select 1 from dbo.s_power p
|
||
where p.b_id = 'action.' + b.b_module_id + '.' + a.b_action);
|
||
GO
|
||
|
||
/* ----------------------------------------------------------------------------
|
||
3. 管理员显式授权(后端对 g3soft 已提权,这里只是为了在权限页可见)
|
||
---------------------------------------------------------------------------- */
|
||
|
||
insert into dbo.s_user_power (b_user_id, b_power_id, b_canuse, b_created_by, b_created_at, b_updated_by, b_updated_at)
|
||
select u.b_id, p.b_id, 1, 'system', sysutcdatetime(), 'system', sysutcdatetime()
|
||
from dbo.b_user u
|
||
cross join dbo.s_power p
|
||
where u.b_id = 'g3soft'
|
||
and (p.b_id like 'menu.%' or p.b_id like 'action.%')
|
||
and not exists (
|
||
select 1 from dbo.s_user_power up where up.b_user_id = u.b_id and up.b_power_id = p.b_id);
|
||
GO
|
||
|
||
/* ----------------------------------------------------------------------------
|
||
4. 自检
|
||
---------------------------------------------------------------------------- */
|
||
|
||
select '菜单权限点' as 项目, count(1) as 数量 from dbo.s_power where b_id like 'menu.%'
|
||
union all
|
||
select '动作权限点', count(1) from dbo.s_power where b_id like 'action.%';
|
||
GO
|