package router import ( "academy/internal/handler/orgcenter" "academy/internal/handler/training" "github.com/gin-gonic/gin" ) // RegisterOrgRoutes registers the org-center routes (/api/v1/org/*). // // 组织中心为租户级共享组织架构(部门/员工档案/模块角色绑定): // - 空间 RBAC 把关:读 Viewer+,写 Contributor+; // - 业务模块语义(职称角色等)由各模块自己的接口细控,本组不感知; // - 不对 API Key 开放(组织数据面向登录用户,默认拒绝)。 // // th 为培训域 handler,可空:职称角色/企微账号维护自培训域迁入组织架构页后, // /org 域提供同名写接口(直接复用培训 handler —— 其 requireRoles 基于 // callerTenantID 做角色细控,与 org 域租户口径一致,且不经培训域的 // TrainingTenantResolution 租户回落,跨空间 HR 在组织架构页操作不会错绑租户)。 func RegisterOrgRoutes(r *gin.RouterGroup, h *orgcenter.Handler, th *training.Handler, g *rbacGuards) { if h == nil { return } orgGroup := r.Group("/org", g.Viewer()) { // ---- 部门 ---- orgGroup.GET("/depts", h.ListDepts) orgGroup.POST("/depts", g.Contributor(), h.SaveDept) orgGroup.DELETE("/depts/:id", g.Contributor(), h.DeleteDept) // ---- 员工档案 ---- orgGroup.GET("/employees", h.ListEmployees) orgGroup.PUT("/employees/:id", g.Contributor(), h.UpdateEmployee) orgGroup.GET("/platform-users", g.Contributor(), h.ListPlatformUsers) orgGroup.POST("/employees/import", g.Contributor(), h.ImportEmployees) // ---- 归属空间收编(登录默认落点) ---- // Owner 限定:改的是账号级登录落点(users.tenant_id + 最近活跃租户偏好), // 与成员批量导入/ Casdoor 同步同权限级别,组织架构页仅 Owner 可见入口。 orgGroup.GET("/employees/adoptable", g.Owner(), h.ListAdoptableUsers) orgGroup.POST("/employees/adopt-home", g.Owner(), h.AdoptHomeTenant) // ---- 职称角色 / 企微账号(培训域语义,handler 内 requireRoles(HR,经理) 细控) ---- // 职称角色页(培训 members 子页)迁入组织架构页后的 /org 域别名路由: // 复用培训 handler,角色绑定仍写 module_key='training' 的 org_module_members。 if th != nil { orgGroup.PUT("/employees/:id/roles", g.Contributor(), th.UpdateMemberRoles) orgGroup.PUT("/employees/:id/wecom-userid", g.Contributor(), th.UpdateMemberWecomUserid) // wecom-userid-sync 从 OA 目录按工号批量拉取企微 userid(预览→写入两段式)。 orgGroup.POST("/employees/wecom-userid-sync/preview", g.Contributor(), th.SyncWecomUseridsPreview) orgGroup.POST("/employees/wecom-userid-sync/apply", g.Contributor(), th.SyncWecomUseridsApply) } // ---- 模块角色绑定 ---- orgGroup.GET("/modules/:module_key/members", h.ListModuleMembers) orgGroup.PUT("/modules/:module_key/members/:employee_id", g.Contributor(), h.PutModuleMember) } }