feat(org): 组织架构新增「收编到本空间」,批量修正成员登录默认落点
deploy-hxtesting / build-and-deploy (push) Successful in 1m13s
deploy-hxtesting / build-and-deploy (push) Successful in 1m13s
员工首登自动开通个人空间(create_personal 默认)后,归属空间(users.tenant_id)
与「最近活跃租户」偏好停在个人空间,登录后看到的是个人空间里那份空的组织
架构/培训数据,模板下载也没有部门下拉。空间 Owner 现可一键收编:
1. GET /org/employees/adoptable 收编预览:归属空间不在本空间的活跃成员
(COALESCE 兜底 NULL 归属,联查名册标记与归属空间名供确认);
2. POST /org/employees/adopt-home 批量收编:逐条校验不整批失败,非本空间
成员/停用/跨空间账号/已归属本空间逐条跳过并回传原因;归属指针与最近
活跃租户偏好一起改指本空间(登录路径优先读偏好,只改归属会被旧偏好
拉回),成员关系/角色/个人空间数据不动,可经空间切换器改回,非破坏性;
3. 收编成功者补跑自动入册(EnsureEmployeesForUsers 仅补空幂等),
同步部门自动匹配进名册;
4. 单条 rbac.member_home_adopted 审计(best-effort);路由 g.Owner() 限定,
与成员批量导入/Casdoor 同步同权限级别;
5. 收编依赖只引 repository 层(UserRepository/TenantMemberRepository),
避开 tenantMemberService→OrgCenterService→userService→memberService
的 DI 环;
6. 前端组织架构页新增「收编到本空间」入口(仅 hasRole('owner') 可见)+
预览确认弹窗(与 OA 同步弹窗同两段式交互);顺手补齐
OrgEmployee.wecom_userid 缺失的存量类型缺口(type-check 阻断项)。
测试:服务层新增收编落点+偏好/六类跳过/守卫 3 例;仓库层 sqlite 用例覆盖
NULL 归属兜底与停用/已归属排除;既有 org/member/casdoor/培训模板用例无回归。
This commit is contained in:
1 parent
8f225ecea9
commit
448fbcdaff
13 files changed
+750
-37
No files matched your search
@@ -2,6 +2,7 @@ package orgcenter
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
@@ -199,6 +200,69 @@ func (h *Handler) ListPlatformUsers(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{"success": true, "data": users})
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// 归属空间收编(登录默认落点;路由层 Owner 限定,与成员批量导入同权限级别)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
// orgAdoptMaxUsers 单次收编人数上限(与成员批量导入行数上限同量级,防超大批次)。
|
||||
const orgAdoptMaxUsers = 2000
|
||||
|
||||
// ListAdoptableUsers GET /org/employees/adoptable — 收编预览:归属空间不在
|
||||
// 本空间的活跃成员(员工首登开了个人空间时,登录会落进个人空间看不到本空间
|
||||
// 维护的组织架构,管理员用收编把默认落点改回本空间)。
|
||||
func (h *Handler) ListAdoptableUsers(c *gin.Context) {
|
||||
users, err := h.svc.ListAdoptableUsers(c.Request.Context(), callerTenantID(c))
|
||||
if err != nil {
|
||||
_ = c.Error(err)
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"success": true, "data": users})
|
||||
}
|
||||
|
||||
// adoptHomeTenantRequest is the body of POST /org/employees/adopt-home.
|
||||
type adoptHomeTenantRequest struct {
|
||||
UserIDs []string `json:"user_ids" binding:"required,min=1"`
|
||||
}
|
||||
|
||||
// AdoptHomeTenant POST /org/employees/adopt-home — 批量收编归属空间到本空间。
|
||||
// 只改成员的登录默认落点(users.tenant_id + 最近活跃租户偏好),不动成员关系
|
||||
// 与个人空间数据;逐条跳过非本空间成员等情形并回传原因。
|
||||
func (h *Handler) AdoptHomeTenant(c *gin.Context) {
|
||||
ctx := c.Request.Context()
|
||||
var req adoptHomeTenantRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
_ = c.Error(errors.NewBadRequestError("请求参数不合法").WithDetails(err.Error()))
|
||||
return
|
||||
}
|
||||
if len(req.UserIDs) > orgAdoptMaxUsers {
|
||||
_ = c.Error(errors.NewBadRequestError(fmt.Sprintf("单次最多收编 %d 名成员", orgAdoptMaxUsers)))
|
||||
return
|
||||
}
|
||||
// 去重保序:重复/空 id 只收编一次,统计口径不重复计数。
|
||||
seen := make(map[string]struct{}, len(req.UserIDs))
|
||||
userIDs := make([]string, 0, len(req.UserIDs))
|
||||
for _, id := range req.UserIDs {
|
||||
if id == "" {
|
||||
continue
|
||||
}
|
||||
if _, dup := seen[id]; dup {
|
||||
continue
|
||||
}
|
||||
seen[id] = struct{}{}
|
||||
userIDs = append(userIDs, id)
|
||||
}
|
||||
if len(userIDs) == 0 {
|
||||
_ = c.Error(errors.NewBadRequestError("请选择要收编的成员"))
|
||||
return
|
||||
}
|
||||
result, err := h.svc.AdoptHomeTenant(ctx, callerTenantID(c), userIDs)
|
||||
if err != nil {
|
||||
_ = c.Error(err)
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"success": true, "data": result})
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// 模块角色绑定
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -216,8 +280,8 @@ func (h *Handler) ListModuleMembers(c *gin.Context) {
|
||||
|
||||
// putModuleMemberRequest is the body of PUT /org/modules/:module_key/members/:employee_id.
|
||||
type putModuleMemberRequest struct {
|
||||
Roles []string `json:"roles"`
|
||||
Extra map[string]any `json:"extra"`
|
||||
Roles []string `json:"roles"`
|
||||
Extra map[string]any `json:"extra"`
|
||||
}
|
||||
|
||||
// PutModuleMember PUT /org/modules/:module_key/members/:employee_id
|
||||
|
||||
Reference in new issue
Block a user