This commit is contained in:
1 parent
9d4092bc7f
commit
78e9787793
11 files changed
+489
-85
No files matched your search
@@ -147,8 +147,10 @@ func (h *Handler) requireRoles(c *gin.Context, allowed ...string) (ok bool) {
|
||||
|
||||
// callerIsSuperAdmin 超级管理员判定:持有「超级管理员」职称角色(super_admin,
|
||||
// 配置中心可配、组织架构「设置角色」可分配)或空间 Owner 兜底;空间 Admin 不放行。
|
||||
// 已确认需求/已审核课程/已发布计划这类终态数据的删除仅对超级管理员开放,其余
|
||||
// 角色仍按原状态规则拦截,前端删除按钮同口径仅超级管理员可见。
|
||||
// 用于终态数据删除(已确认需求/已审核课程/已发布计划)、课程跨部门审核与需求
|
||||
// 核验确认的跨部门放行(000163);发布、查看及课程审核外的常规审批不经本函数,
|
||||
// 由 super_admin 继承全部权限组经 ExpandRoles 展开后在各 requireRoles/数据范围
|
||||
// 判定自动放行,前端删除/确认按钮按同口径放开。
|
||||
func (h *Handler) callerIsSuperAdmin(c *gin.Context) bool {
|
||||
if callerRole := types.TenantRoleFromContext(c.Request.Context()); callerRole.IsValid() &&
|
||||
callerRole == types.TenantRoleOwner {
|
||||
@@ -651,6 +653,10 @@ func (h *Handler) ListPosts(c *gin.Context) {
|
||||
// 部门口径(000158):全部行必须为导入人本人部门(org_employees.dept_id,全员
|
||||
// 严格,人事也不例外);部门列留空视为默认导入人部门,其余任一行不符即整批
|
||||
// 拒绝。导入人无部门档案时阻断,先由人事在组织中心维护。
|
||||
// 000163 权限调整:超级管理员放开跨部门导入 —— 无部门档案亦不阻断,行部门
|
||||
// 照实落库(自动匹配/新增的课程管理条目按行部门归属;部门列留空的行保持空
|
||||
// 部门,列表提示「未指定部门」,超管可后续补全/确认),与需求跨部门核验确认
|
||||
// 同口径。
|
||||
func (h *Handler) ImportDemands(c *gin.Context) {
|
||||
ctx := c.Request.Context()
|
||||
if !h.requireRoles(c, types.TrainingRoleHR, types.TrainingRoleSupervisor) {
|
||||
@@ -669,41 +675,50 @@ func (h *Handler) ImportDemands(c *gin.Context) {
|
||||
_ = c.Error(err)
|
||||
return
|
||||
}
|
||||
if member == nil || trimSpace(member.DeptID) == "" {
|
||||
_ = c.Error(errors.NewBadRequestError("未找到您的部门档案,请联系人事在组织中心维护部门后再导入"))
|
||||
return
|
||||
}
|
||||
// 整批部门预检:任一行部门与导入人不符即拒绝,不做部分导入。
|
||||
// 通过口径:行部门 id 与本人一致,或部门列全空(默认导入人部门)。
|
||||
myDeptName := h.deptNameOf(ctx, tenantID, member.DeptID)
|
||||
violations := make([]string, 0, len(req.Demands))
|
||||
for i, item := range req.Demands {
|
||||
deptID, deptName := trimSpace(item.DeptID), trimSpace(item.DeptName)
|
||||
if deptID == "" && deptName == "" {
|
||||
continue
|
||||
// 000163:超级管理员不限部门,跳过本人部门档案校验与整批部门预检。
|
||||
bySuperAdmin := h.callerIsSuperAdmin(c)
|
||||
if !bySuperAdmin {
|
||||
if member == nil || trimSpace(member.DeptID) == "" {
|
||||
_ = c.Error(errors.NewBadRequestError("未找到您的部门档案,请联系人事在组织中心维护部门后再导入"))
|
||||
return
|
||||
}
|
||||
if deptID == member.DeptID {
|
||||
continue
|
||||
// 整批部门预检:任一行部门与导入人不符即拒绝,不做部分导入。
|
||||
// 通过口径:行部门 id 与本人一致,或部门列全空(默认导入人部门)。
|
||||
myDeptName := h.deptNameOf(ctx, tenantID, member.DeptID)
|
||||
violations := make([]string, 0, len(req.Demands))
|
||||
for i, item := range req.Demands {
|
||||
deptID, deptName := trimSpace(item.DeptID), trimSpace(item.DeptName)
|
||||
if deptID == "" && deptName == "" {
|
||||
continue
|
||||
}
|
||||
if deptID == member.DeptID {
|
||||
continue
|
||||
}
|
||||
if deptName == "" {
|
||||
deptName = h.deptNameOf(ctx, tenantID, deptID)
|
||||
}
|
||||
if deptName == "" {
|
||||
deptName = deptID
|
||||
}
|
||||
violations = append(violations, fmt.Sprintf("第%d行(%s)", i+1, deptName))
|
||||
}
|
||||
if deptName == "" {
|
||||
deptName = h.deptNameOf(ctx, tenantID, deptID)
|
||||
if len(violations) > 0 {
|
||||
_ = c.Error(errors.NewBadRequestError(fmt.Sprintf(
|
||||
"导入失败:第%s行部门与您所在部门(%s)不一致,仅可导入本人部门的需求表",
|
||||
strings.Join(violations, "、"), myDeptName)))
|
||||
return
|
||||
}
|
||||
if deptName == "" {
|
||||
deptName = deptID
|
||||
}
|
||||
violations = append(violations, fmt.Sprintf("第%d行(%s)", i+1, deptName))
|
||||
}
|
||||
if len(violations) > 0 {
|
||||
_ = c.Error(errors.NewBadRequestError(fmt.Sprintf(
|
||||
"导入失败:第%s行部门与您所在部门(%s)不一致,仅可导入本人部门的需求表",
|
||||
strings.Join(violations, "、"), myDeptName)))
|
||||
return
|
||||
}
|
||||
demands := make([]*types.TrainingDemand, 0, len(req.Demands))
|
||||
for _, item := range req.Demands {
|
||||
// 部门口径:非超管强制为导入人本人部门(部门列留空的行在此默认,其余已
|
||||
// 通过预检);超管按行部门照实落库,留空行保持空部门。
|
||||
deptID := trimSpace(item.DeptID)
|
||||
if !bySuperAdmin {
|
||||
deptID = member.DeptID
|
||||
}
|
||||
demands = append(demands, &types.TrainingDemand{
|
||||
// 部门强制为导入人本人部门:部门列留空的行在此默认,其余已通过预检。
|
||||
Year: item.Year, DeptID: member.DeptID, CourseName: item.CourseName,
|
||||
Year: item.Year, DeptID: deptID, CourseName: item.CourseName,
|
||||
Plant: item.Plant, Category: item.Category, SessionCount: item.SessionCount,
|
||||
Location: item.Location, PostScope: item.PostScope, LecturerID: item.LecturerID,
|
||||
LecturerExternal: trimSpace(item.LecturerExternal), TrainType: trimSpace(item.TrainType),
|
||||
@@ -747,7 +762,9 @@ const demandConfirmDenied = "暂无权限,请联系部门经理~"
|
||||
|
||||
// ConfirmDemand POST /training/demands/:id/confirm — 经理核验确认(部门+角色双校验)。
|
||||
// 仅「需求归属部门的成员且职称角色为经理」可核验(000154 收窄:人事/空间管理员/
|
||||
// 其他部门经理一律拒绝),统一提示「暂无权限,请联系部门经理~」;
|
||||
// 其他部门经理一律拒绝),统一提示「暂无权限,请联系部门经理~」;000163 权限调整:
|
||||
// 超级管理员(职称角色 super_admin/空间 Owner 兜底)放开跨部门,可确认全部部门
|
||||
// (含未补全部门)的需求,与课程跨部门审核/终态删除同口径。
|
||||
// 部门校验先于确认落库,避免越权时已改状态。
|
||||
func (h *Handler) ConfirmDemand(c *gin.Context) {
|
||||
ctx := c.Request.Context()
|
||||
@@ -761,8 +778,11 @@ func (h *Handler) ConfirmDemand(c *gin.Context) {
|
||||
_ = c.Error(errors.NewForbiddenError(demandConfirmDenied))
|
||||
return
|
||||
}
|
||||
// 000163:超级管理员不限部门(职称角色经 ExpandRoles 命中 super_admin,空间
|
||||
// Owner 兜底),跳过下方角色与部门双校验,与课程跨部门审核同一口径。
|
||||
bySuperAdmin := h.callerIsSuperAdmin(c)
|
||||
roles := h.svc.ExpandTrainingRoles(ctx, tenantID, member.TrainingRoleList())
|
||||
if !types.HasTrainingRole(roles, types.TrainingRoleManager) {
|
||||
if !bySuperAdmin && !types.HasTrainingRole(roles, types.TrainingRoleManager) {
|
||||
_ = c.Error(errors.NewForbiddenError(demandConfirmDenied))
|
||||
return
|
||||
}
|
||||
@@ -771,8 +791,9 @@ func (h *Handler) ConfirmDemand(c *gin.Context) {
|
||||
_ = c.Error(err)
|
||||
return
|
||||
}
|
||||
// 本部门口径:仅可核验本部门需求(部门缺失的需求先由人事/提报人补全部门)。
|
||||
if existing.DeptID == "" || existing.DeptID != member.DeptID {
|
||||
// 本部门口径:仅可核验本部门需求(部门缺失的需求先由人事/提报人补全部门);
|
||||
// 超级管理员不限部门(含部门缺失的需求)。
|
||||
if !bySuperAdmin && (existing.DeptID == "" || existing.DeptID != member.DeptID) {
|
||||
_ = c.Error(errors.NewForbiddenError(demandConfirmDenied))
|
||||
return
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user