feat(优化):年培训计划:已确认行的删除按钮、勾选框、批量删除均仅超级管理员可见/可用;提示文案随角色变化
deploy-hxtesting / build-and-deploy (push) Successful in 1m14s
deploy-hxtesting / build-and-deploy (push) Successful in 1m14s
课程管理:canDeleteCourse 超管不限状态/部门(已审核/已发布行可删,确认弹窗文案区分);批量删除按钮超管可见 月培训计划:已发布行的「删除」仅超管可见(普通维护角色仍只能删未发布计划),行内确认弹窗替代原 window.confirm,失败时透出后端文案 Training.vue:canManageTabs 加入 super_admin,纯超管(未兼其他角色)也能进入这三个页面执行删除
This commit is contained in:
1 parent
a448598df5
commit
2f1cda34da
19 files changed
+589
-278
No files matched your search
@@ -0,0 +1,34 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"academy/internal/types/interfaces"
|
||||
)
|
||||
|
||||
// TestCourseLibraryPermissionCondBalanced 2026-11-26 复测根因:权限 SQL 括号不配平
|
||||
// (少一个右括号)导致 scope=catalog / PermFilter 查询整体 500
|
||||
// 「syntax error at end of input」,前端 catch 后和信课程恒为空。
|
||||
// 本测试锁定:生成 SQL 括号必须配平,占位符数量与参数数量必须一致。
|
||||
func TestCourseLibraryPermissionCondBalanced(t *testing.T) {
|
||||
q := &interfaces.TrainingListQuery{
|
||||
PermFilter: true,
|
||||
PermDeptID: "dept-1",
|
||||
PermUserID: "user-1",
|
||||
CatalogDeptID: "dept-1",
|
||||
CatalogDeptName: "资讯组",
|
||||
PermIncludeCreator: true,
|
||||
}
|
||||
cond, args := courseLibraryPermissionCond(q)
|
||||
opens := strings.Count(cond, "(")
|
||||
closes := strings.Count(cond, ")")
|
||||
if opens != closes {
|
||||
t.Fatalf("括号不配平: '('=%d ')'=%d\nSQL=%s", opens, closes, cond)
|
||||
}
|
||||
placeholders := strings.Count(cond, "?")
|
||||
if placeholders != len(args) {
|
||||
t.Fatalf("占位符(%d)与参数(%d)数量不一致\nSQL=%s", placeholders, len(args), cond)
|
||||
}
|
||||
t.Logf("OK opens=%d closes=%d placeholders=%d args=%d", opens, closes, placeholders, len(args))
|
||||
}
|
||||
@@ -31,7 +31,7 @@ const courseLibraryPermissionMatchSQL = "(tr_course_library.perm_dept_ids <> ''
|
||||
"tr_course_library.suitable_members = ? " +
|
||||
"OR (? <> '' AND ? = ANY(string_to_array(replace(replace(replace(replace(tr_course_library.suitable_members, ',', '、'), ',', '、'), ';', '、'), ';', '、'), '、'))) " +
|
||||
"OR (tr_course_library.suitable_members = '' AND (tr_course_library.owner_dept_id = '' " +
|
||||
"OR (? <> '' AND tr_course_library.owner_dept_id = ?))))"
|
||||
"OR (? <> '' AND tr_course_library.owner_dept_id = ?)))))"
|
||||
|
||||
// courseLibraryPermissionCond 组装课程权限匹配条件与参数(000163;handler 注入
|
||||
// 调用方部门 id/部门名/用户 id,PermIncludeCreator 时创建人/讲师放行)。
|
||||
|
||||
@@ -599,13 +599,14 @@ func (s *trainingService) ConfirmDemand(ctx context.Context, tenantID uint64, id
|
||||
}
|
||||
|
||||
// DeleteDemand soft-deletes one unconfirmed demand.
|
||||
// 状态「已确认」的需求不可删除,避免误删已纳入年度排期的口径。
|
||||
func (s *trainingService) DeleteDemand(ctx context.Context, tenantID uint64, id string) error {
|
||||
// 状态「已确认」的需求不可删除,避免误删已纳入年度排期的口径;仅超级管理员
|
||||
// (bySuperAdmin:super_admin 职称角色或空间 Owner 兜底)放开终态删除。
|
||||
func (s *trainingService) DeleteDemand(ctx context.Context, tenantID uint64, id string, bySuperAdmin bool) error {
|
||||
demand, err := s.repo.GetDemand(ctx, tenantID, id)
|
||||
if err != nil {
|
||||
return errors.NewNotFoundError("需求不存在")
|
||||
}
|
||||
if demand.Status == types.TrainingDemandConfirmed {
|
||||
if demand.Status == types.TrainingDemandConfirmed && !bySuperAdmin {
|
||||
return errors.NewBadRequestError("已确认的需求不可删除")
|
||||
}
|
||||
return s.repo.DeleteDemand(ctx, tenantID, id)
|
||||
|
||||
@@ -422,7 +422,16 @@ func courseTypeLabel(t string) string {
|
||||
}
|
||||
|
||||
// DeleteCourse soft-deletes one course.
|
||||
func (s *trainingService) DeleteCourse(ctx context.Context, tenantID uint64, id string) error {
|
||||
// 已发布计划不可普通删除(避免误删已排期/已通知的计划);仅超级管理员
|
||||
// (bySuperAdmin:super_admin 职称角色或空间 Owner 兜底)放开终态删除。
|
||||
func (s *trainingService) DeleteCourse(ctx context.Context, tenantID uint64, id string, bySuperAdmin bool) error {
|
||||
course, err := s.GetCourse(ctx, tenantID, id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if course.Status == types.TrainingCoursePublished && !bySuperAdmin {
|
||||
return errors.NewBadRequestError("已发布的培训计划不可删除,仅超级管理员可删除")
|
||||
}
|
||||
return s.repo.DeleteCourse(ctx, tenantID, id)
|
||||
}
|
||||
|
||||
|
||||
@@ -202,14 +202,15 @@ func (s *trainingService) SaveCourseLibraryItem(ctx context.Context, tenantID ui
|
||||
|
||||
// DeleteCourseLibraryItem 软删课程管理条目(月培训计划已创建的历史计划不受影响)。
|
||||
// 000157 收紧:仅「待核验」状态可删(已确认课程须走核验流程,不可绕过);
|
||||
// deptScope 非空(课长/经理)时仅可删除本部门课程。
|
||||
func (s *trainingService) DeleteCourseLibraryItem(ctx context.Context, tenantID uint64, id, deptScope string) error {
|
||||
// deptScope 非空(课长/经理)时仅可删除本部门课程。bySuperAdmin(超级管理员
|
||||
// 职称角色/空间 Owner 兜底)放开终态:已审核/已发布课程与跨部门均可删。
|
||||
func (s *trainingService) DeleteCourseLibraryItem(ctx context.Context, tenantID uint64, id, deptScope string, bySuperAdmin bool) error {
|
||||
item, err := s.repo.GetCourseLibraryItem(ctx, tenantID, id)
|
||||
if err != nil || item == nil {
|
||||
return werrors.NewNotFoundError("课程不存在")
|
||||
}
|
||||
if item.VerifyStatus != types.CourseLibraryVerifyPending {
|
||||
return werrors.NewBadRequestError("仅待核验状态的课程可删除,已确认课程不可删除")
|
||||
if item.VerifyStatus != types.CourseLibraryVerifyPending && !bySuperAdmin {
|
||||
return werrors.NewBadRequestError("仅待审核状态的课程可删除,已审核课程仅超级管理员可删除")
|
||||
}
|
||||
if deptScope != "" && item.OwnerDeptID != deptScope {
|
||||
return werrors.NewForbiddenError("仅可删除本部门的课程")
|
||||
|
||||
Reference in new issue
Block a user