fix(权限完善):1.权限优化以下模块按钮查看权限全部归属超级管理员,只有职称角色未超级管理员用户才可以查看进入操作
deploy-hxtesting / build-and-deploy (push) Successful in 1m17s
deploy-hxtesting / build-and-deploy (push) Successful in 1m17s
1)如图一所示点击左下角个人信息弹出框中的“空间设置”、“成员管理“、”模型管理“、”全部设置“、”系统管理“ 2)点击进入”设置“页面中”空间“、”模型“、”发布集成“、”数据与扩展“、”系统管理“这几个大模块相关内容入口 2.成员管理页面增加一个字段”状态“:1-5 在职状态(试用/试用延期/正式/临时/实习)、6离职/7退休(顺便对数据进行清洗,工号首位带字母的都标记为离职其他都标记为正式) 3.检查各业务需求里所有选择员工相关都只能拉取选择正式员工!
This commit is contained in:
1 parent
b762deaf15
commit
7034d93256
49 files changed
+809
-130
No files matched your search
@@ -239,11 +239,11 @@ func TestTenantMemberSearchTreatsLikeWildcardsLiterally(t *testing.T) {
|
||||
seedMember(literalID, "ann_bob", "ann_bob@example.com")
|
||||
seedMember(uuid.New().String(), "annxbob", "annxbob@example.com")
|
||||
|
||||
total, err := repo.CountFilteredByTenant(ctx, tenantID, "ann_bob")
|
||||
total, err := repo.CountFilteredByTenant(ctx, tenantID, "ann_bob", 0)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, int64(1), total, "underscore must match literally, not as a wildcard")
|
||||
|
||||
members, err := repo.ListPagedByTenant(ctx, tenantID, "ann_bob", 0, 20)
|
||||
members, err := repo.ListPagedByTenant(ctx, tenantID, "ann_bob", 0, 0, 20)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, members, 1)
|
||||
assert.Equal(t, literalID, members[0].UserID)
|
||||
|
||||
@@ -77,6 +77,10 @@ func (r *orgCenterRepository) employeeFilter(ctx context.Context, tenantID uint6
|
||||
if q.DeptID != "" {
|
||||
tx = tx.Where("org_employees.dept_id = ?", q.DeptID)
|
||||
}
|
||||
// 在职状态过滤(000167):选人场景(学员/讲师/推送等)按正式员工口径拉取。
|
||||
if q.EmploymentStatus > 0 {
|
||||
tx = tx.Where("u.employment_status = ?", q.EmploymentStatus)
|
||||
}
|
||||
if q.Keyword != "" {
|
||||
// 按姓名/工号/部门名/岗位模糊查找;姓名取真实姓名(display_name)
|
||||
// 回退平台账号(username),与列表展示口径一致。
|
||||
@@ -242,7 +246,9 @@ func (r *orgCenterRepository) ListTenantUsers(ctx context.Context, tenantID uint
|
||||
Joins("JOIN tenant_members tm ON tm.user_id = u.id AND tm.tenant_id = ? "+
|
||||
"AND tm.status = 'active' AND tm.deleted_at IS NULL", tenantID).
|
||||
Joins("LEFT JOIN org_employees m ON m.user_id = u.id AND m.tenant_id = ? AND m.deleted_at IS NULL", tenantID).
|
||||
Where("u.is_active = TRUE AND u.deleted_at IS NULL").
|
||||
// 「从平台用户添加员工档案」属选人场景:仅正式员工(000167)可选入册,
|
||||
// 离职/退休账号不再出现在档案添加下拉。
|
||||
Where("u.is_active = TRUE AND u.deleted_at IS NULL AND u.employment_status = ?", types.EmploymentStatusFormal).
|
||||
Order("u.created_at ASC").
|
||||
Scan(&users).Error
|
||||
return users, err
|
||||
|
||||
@@ -111,32 +111,36 @@ func (r *tenantMemberRepository) ListByTenant(ctx context.Context, tenantID uint
|
||||
}
|
||||
|
||||
// CountFilteredByTenant counts active tenant membership rows, optionally
|
||||
// restricted to users whose email or username matches search.
|
||||
// restricted to users whose email or username matches search. employmentStatus
|
||||
// 非 0 时仅统计该在职状态(users.employment_status,000167)的成员。
|
||||
func (r *tenantMemberRepository) CountFilteredByTenant(
|
||||
ctx context.Context, tenantID uint64, search string,
|
||||
ctx context.Context, tenantID uint64, search string, employmentStatus int,
|
||||
) (int64, error) {
|
||||
search = strings.TrimSpace(search)
|
||||
q := r.db.WithContext(ctx).Model(&types.TenantMember{}).
|
||||
Where("tenant_members.tenant_id = ?", tenantID)
|
||||
var total int64
|
||||
var err error
|
||||
if search == "" {
|
||||
err = q.Count(&total).Error
|
||||
} else {
|
||||
like := "%" + escapeLikePattern(search) + "%"
|
||||
err = q.
|
||||
Joins(`INNER JOIN users ON users.id = tenant_members.user_id AND users.deleted_at IS NULL`).
|
||||
Where(
|
||||
`(LOWER(users.email) LIKE LOWER(?) ESCAPE ? OR LOWER(users.username) LIKE LOWER(?) ESCAPE ?)`,
|
||||
like, likeEscapeChar, like, likeEscapeChar).
|
||||
Count(&total).Error
|
||||
// 搜索与在职状态过滤都依赖 users 表,按需挂一次 JOIN(重复 Joins 会
|
||||
// 生成重复 JOIN 子句)。
|
||||
if search != "" || employmentStatus > 0 {
|
||||
q = q.Joins(`INNER JOIN users ON users.id = tenant_members.user_id AND users.deleted_at IS NULL`)
|
||||
}
|
||||
if search != "" {
|
||||
like := "%" + escapeLikePattern(search) + "%"
|
||||
q = q.Where(
|
||||
`(LOWER(users.email) LIKE LOWER(?) ESCAPE ? OR LOWER(users.username) LIKE LOWER(?) ESCAPE ?)`,
|
||||
like, likeEscapeChar, like, likeEscapeChar)
|
||||
}
|
||||
if employmentStatus > 0 {
|
||||
q = q.Where("users.employment_status = ?", employmentStatus)
|
||||
}
|
||||
var total int64
|
||||
err := q.Count(&total).Error
|
||||
return total, err
|
||||
}
|
||||
|
||||
// ListPagedByTenant lists active memberships with stable sort.
|
||||
func (r *tenantMemberRepository) ListPagedByTenant(
|
||||
ctx context.Context, tenantID uint64, search string, offset, limit int,
|
||||
ctx context.Context, tenantID uint64, search string, employmentStatus int, offset, limit int,
|
||||
) ([]*types.TenantMember, error) {
|
||||
search = strings.TrimSpace(search)
|
||||
var members []*types.TenantMember
|
||||
@@ -146,18 +150,19 @@ func (r *tenantMemberRepository) ListPagedByTenant(
|
||||
Offset(offset).
|
||||
Limit(limit)
|
||||
|
||||
var err error
|
||||
if search == "" {
|
||||
err = q.Find(&members).Error
|
||||
} else {
|
||||
like := "%" + escapeLikePattern(search) + "%"
|
||||
err = q.
|
||||
Joins(`INNER JOIN users ON users.id = tenant_members.user_id AND users.deleted_at IS NULL`).
|
||||
Where(
|
||||
`(LOWER(users.email) LIKE LOWER(?) ESCAPE ? OR LOWER(users.username) LIKE LOWER(?) ESCAPE ?)`,
|
||||
like, likeEscapeChar, like, likeEscapeChar).
|
||||
Find(&members).Error
|
||||
if search != "" || employmentStatus > 0 {
|
||||
q = q.Joins(`INNER JOIN users ON users.id = tenant_members.user_id AND users.deleted_at IS NULL`)
|
||||
}
|
||||
if search != "" {
|
||||
like := "%" + escapeLikePattern(search) + "%"
|
||||
q = q.Where(
|
||||
`(LOWER(users.email) LIKE LOWER(?) ESCAPE ? OR LOWER(users.username) LIKE LOWER(?) ESCAPE ?)`,
|
||||
like, likeEscapeChar, like, likeEscapeChar)
|
||||
}
|
||||
if employmentStatus > 0 {
|
||||
q = q.Where("users.employment_status = ?", employmentStatus)
|
||||
}
|
||||
err := q.Find(&members).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -125,6 +125,10 @@ func (r *trainingRepository) CancelPushTask(ctx context.Context, tenantID uint64
|
||||
// 含未入员工名册的账号,站内通知可达;企微投递时无绑定者自然 skipped)
|
||||
// - dept / post:org_employees 按 dept_id / post 过滤(active 档案)
|
||||
// - user:直接采用指定名单(仍按空间成员口径过滤,防越租户投递)
|
||||
//
|
||||
// 在职状态口径(000167):all/dept/post 三个自动圈定分支仅正式员工
|
||||
// (users.employment_status=3)——离职/退休不再收到培训推送;user 分支为
|
||||
// 历史已保存的指定名单,保持原样不受影响。
|
||||
func (r *trainingRepository) ListManualPushAudience(
|
||||
ctx context.Context, tenantID uint64, mode string, deptIDs, posts, userIDs []string,
|
||||
) ([]string, error) {
|
||||
@@ -152,8 +156,10 @@ func (r *trainingRepository) ListManualPushAudience(
|
||||
}
|
||||
var rows []types.OrgEmployee
|
||||
if err := r.db.WithContext(ctx).
|
||||
Where("tenant_id = ? AND "+column+" IN ? AND status = 'active' AND user_id <> '' AND deleted_at IS NULL",
|
||||
tenantID, values).
|
||||
Joins("JOIN users u ON u.id = org_employees.user_id AND u.deleted_at IS NULL").
|
||||
Where("org_employees.tenant_id = ? AND org_employees."+column+" IN ? AND org_employees.status = 'active'"+
|
||||
" AND org_employees.user_id <> '' AND org_employees.deleted_at IS NULL"+
|
||||
" AND u.employment_status = ?", tenantID, values, types.EmploymentStatusFormal).
|
||||
Find(&rows).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -195,7 +201,8 @@ func (r *trainingRepository) ListManualPushAudience(
|
||||
Select("u.id").
|
||||
Joins("JOIN tenant_members tm ON tm.user_id = u.id AND tm.tenant_id = ? "+
|
||||
"AND tm.status = 'active' AND tm.deleted_at IS NULL", tenantID).
|
||||
Where("u.is_active = TRUE AND u.deleted_at IS NULL").
|
||||
Where("u.is_active = TRUE AND u.deleted_at IS NULL AND u.employment_status = ?",
|
||||
types.EmploymentStatusFormal).
|
||||
Order("u.created_at ASC").
|
||||
Scan(&rows).Error; err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -148,7 +148,8 @@ func (r *trainingRepository) DeleteDemand(ctx context.Context, tenantID uint64,
|
||||
// ListLecturers returns the lecturer roster (user_id + 姓名) for pickers.
|
||||
// 讲师角色存于组织中心模块绑定表(module_key='training'),按 roles 文本包含判定;
|
||||
// 姓名取 display_name 优先(工号型 IdP 的 username 为工号,真实姓名在 display_name),
|
||||
// 与年度收集模板「培训讲师」下拉展示口径一致。
|
||||
// 与年度收集模板「培训讲师」下拉展示口径一致。讲师下拉属选人场景:仅正式员工
|
||||
// (users.employment_status=3,000167),离职/退休讲师不再出现。
|
||||
func (r *trainingRepository) ListLecturers(ctx context.Context, tenantID uint64) ([]*types.TrainingLecturerOption, error) {
|
||||
var rows []*types.TrainingLecturerOption
|
||||
err := r.db.WithContext(ctx).
|
||||
@@ -159,6 +160,7 @@ func (r *trainingRepository) ListLecturers(ctx context.Context, tenantID uint64)
|
||||
" AND mm.module_key = 'training' AND mm.deleted_at IS NULL").
|
||||
Where("m.tenant_id = ? AND m.deleted_at IS NULL AND m.status = 'active'"+
|
||||
" AND mm.roles::text LIKE '%\"lecturer\"%'", tenantID).
|
||||
Where("u.employment_status = ?", types.EmploymentStatusFormal).
|
||||
Order("name ASC").
|
||||
Scan(&rows).Error
|
||||
return rows, err
|
||||
|
||||
@@ -141,6 +141,22 @@ func (r *userRepository) UpdateUser(ctx context.Context, user *types.User) error
|
||||
return r.db.WithContext(ctx).Omit("is_active").Save(user).Error
|
||||
}
|
||||
|
||||
// UpdateEmploymentStatus updates users.employment_status (000167 在职状态).
|
||||
// Explicit column update avoids the zero-value pitfalls of struct Save; the
|
||||
// RowsAffected check maps a missing user to ErrUserNotFound.
|
||||
func (r *userRepository) UpdateEmploymentStatus(ctx context.Context, userID string, status int) error {
|
||||
res := r.db.WithContext(ctx).Model(&types.User{}).
|
||||
Where("id = ?", userID).
|
||||
UpdateColumn("employment_status", status)
|
||||
if res.Error != nil {
|
||||
return res.Error
|
||||
}
|
||||
if res.RowsAffected == 0 {
|
||||
return ErrUserNotFound
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// DeleteUser deletes a user
|
||||
func (r *userRepository) DeleteUser(ctx context.Context, id string) error {
|
||||
return r.db.WithContext(ctx).Where("id = ?", id).Delete(&types.User{}).Error
|
||||
|
||||
@@ -311,11 +311,13 @@ func (s *tenantMemberService) ListByTenant(ctx context.Context, tenantID uint64)
|
||||
|
||||
// ListMembersPage returns a slice plus total matching query (handlers parse
|
||||
// page/page_size; defensive clamps here mirror list handler limits).
|
||||
// employmentStatus 非 0 时仅返回该在职状态(users.employment_status)的成员。
|
||||
func (s *tenantMemberService) ListMembersPage(
|
||||
ctx context.Context,
|
||||
tenantID uint64,
|
||||
query string,
|
||||
page, pageSize int,
|
||||
employmentStatus int,
|
||||
) ([]*types.TenantMember, int64, error) {
|
||||
query = strings.TrimSpace(query)
|
||||
if page < 1 {
|
||||
@@ -327,12 +329,12 @@ func (s *tenantMemberService) ListMembersPage(
|
||||
if pageSize > listMembersMaxPageSize {
|
||||
pageSize = listMembersMaxPageSize
|
||||
}
|
||||
total, err := s.repo.CountFilteredByTenant(ctx, tenantID, query)
|
||||
total, err := s.repo.CountFilteredByTenant(ctx, tenantID, query, employmentStatus)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
offset := (page - 1) * pageSize
|
||||
members, err := s.repo.ListPagedByTenant(ctx, tenantID, query, offset, pageSize)
|
||||
members, err := s.repo.ListPagedByTenant(ctx, tenantID, query, employmentStatus, offset, pageSize)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
@@ -132,13 +132,13 @@ func (r *fakeTenantMemberRepo) filterTenantRows(tenantID uint64, search string)
|
||||
}
|
||||
|
||||
func (r *fakeTenantMemberRepo) CountFilteredByTenant(
|
||||
ctx context.Context, tenantID uint64, search string,
|
||||
ctx context.Context, tenantID uint64, search string, employmentStatus int,
|
||||
) (int64, error) {
|
||||
return int64(len(r.filterTenantRows(tenantID, search))), nil
|
||||
}
|
||||
|
||||
func (r *fakeTenantMemberRepo) ListPagedByTenant(
|
||||
ctx context.Context, tenantID uint64, search string, offset, limit int,
|
||||
ctx context.Context, tenantID uint64, search string, employmentStatus int, offset, limit int,
|
||||
) ([]*types.TenantMember, error) {
|
||||
all := r.filterTenantRows(tenantID, search)
|
||||
if offset >= len(all) {
|
||||
@@ -317,6 +317,9 @@ func (r *cleanupUserRepo) ListSystemAdmins(context.Context, int, int) ([]*types.
|
||||
func (r *cleanupUserRepo) RevokeSystemAdmin(context.Context, string, string) (*types.User, error) {
|
||||
return nil, nil
|
||||
}
|
||||
func (r *cleanupUserRepo) UpdateEmploymentStatus(context.Context, string, int) error {
|
||||
return nil
|
||||
}
|
||||
func (r *cleanupUserRepo) SearchUsers(context.Context, string, int) ([]*types.User, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
@@ -185,6 +185,8 @@ func (s *trainingService) ListMembers(ctx context.Context, tenantID uint64, q *i
|
||||
if q != nil {
|
||||
oq.DeptID = q.DeptID
|
||||
oq.Keyword = q.Keyword
|
||||
// 在职状态过滤(000167):选人场景按正式员工口径拉取。
|
||||
oq.EmploymentStatus = q.EmploymentStatus
|
||||
oq.Page = q.Page
|
||||
oq.PageSize = q.PageSize
|
||||
}
|
||||
|
||||
@@ -199,8 +199,11 @@ func (s *userService) Register(ctx context.Context, req *types.RegisterRequest)
|
||||
PasswordHash: string(hashedPassword),
|
||||
TenantID: 0,
|
||||
IsActive: true,
|
||||
CreatedAt: time.Now(),
|
||||
UpdatedAt: time.Now(),
|
||||
// 在职状态随工号规则落库(首位字母→离职,否则→正式,000167):
|
||||
// Excel 批量导入 / CASDOOR 同步 / 管理员开户都经此漏斗,一处生效。
|
||||
EmploymentStatus: types.EmploymentStatusFromUsername(req.Username),
|
||||
CreatedAt: time.Now(),
|
||||
UpdatedAt: time.Now(),
|
||||
}
|
||||
if createdTenant != nil {
|
||||
user.TenantID = createdTenant.ID
|
||||
@@ -906,6 +909,15 @@ func (s *userService) RevokeSystemAdmin(ctx context.Context, userID, actorID str
|
||||
// UpdateUserPreferences applies a partial update over the user's
|
||||
// preferences blob. PATCH semantics: only keys present in `patch`
|
||||
// (non-nil pointer fields) replace the existing value; everything else
|
||||
// UpdateEmploymentStatus 修改人员在册在职状态(000167)。调用方(成员管理
|
||||
// handler,Owner+)已校验 1-7;此处仅做兜底校验后直写 users 列。
|
||||
func (s *userService) UpdateEmploymentStatus(ctx context.Context, userID string, status int) error {
|
||||
if !types.IsValidEmploymentStatus(status) {
|
||||
return errors.New("employment_status must be one of 1-7")
|
||||
}
|
||||
return s.userRepo.UpdateEmploymentStatus(ctx, userID, status)
|
||||
}
|
||||
|
||||
// is preserved. This lets the front-end PUT only the preference that
|
||||
// changed without having to read-modify-write the whole struct, and
|
||||
// also makes the endpoint forward-compatible — older clients that
|
||||
|
||||
@@ -79,6 +79,9 @@ type stubUserRepoForAuth struct {
|
||||
}
|
||||
|
||||
func (s *stubUserRepoForAuth) CreateUser(context.Context, *types.User) error { return nil }
|
||||
func (s *stubUserRepoForAuth) UpdateEmploymentStatus(context.Context, string, int) error {
|
||||
return nil
|
||||
}
|
||||
func (s *stubUserRepoForAuth) GetUserByID(_ context.Context, id string) (*types.User, error) {
|
||||
user, ok := s.users[id]
|
||||
if !ok {
|
||||
|
||||
Reference in new issue
Block a user