用户组织下拉接口 (#486)
Co-authored-by: alickliming <alickliming@didi.global.com>
This commit is contained in:
parent
a8008a9418
commit
b3a7d7c9a8
|
@ -42,6 +42,7 @@ func TreeUntilProjectsGetByNid(nid int64) ([]Node, error) {
|
|||
return oks, err
|
||||
}
|
||||
|
||||
// 暂时保留,不知道外部其他组件是否有调用
|
||||
func TreeUntilProjectsGetByUser(user *User) ([]Node, error) {
|
||||
ret, err := UserPermNodes(user)
|
||||
if err != nil {
|
||||
|
@ -105,3 +106,36 @@ func UserPermNodes(me *User) ([]Node, error) {
|
|||
ret, err = PermNodes(nodes)
|
||||
return ret, err
|
||||
}
|
||||
|
||||
func TreeUntilTypGetByUser(user *User, typ string) ([]Node, error) {
|
||||
ret, err := UserPermNodes(user)
|
||||
if err != nil {
|
||||
return ret, err
|
||||
}
|
||||
|
||||
cnt := len(ret)
|
||||
all := make(map[string]Node, cnt)
|
||||
for i := 0; i < cnt; i++ {
|
||||
all[ret[i].Path] = ret[i]
|
||||
}
|
||||
|
||||
// 只取typ(含)以上的部分
|
||||
var oks []Node
|
||||
|
||||
set := make(map[string]struct{})
|
||||
for i := 0; i < cnt; i++ {
|
||||
if ret[i].Cate == typ {
|
||||
paths := Paths(ret[i].Path)
|
||||
for _, path := range paths {
|
||||
if _, has := set[path]; has {
|
||||
continue
|
||||
}
|
||||
|
||||
set[path] = struct{}{}
|
||||
oks = append(oks, all[path])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return oks, err
|
||||
}
|
||||
|
|
|
@ -137,6 +137,7 @@ func Config(r *gin.Engine) {
|
|||
|
||||
userLogin.GET("/tree", treeUntilLeafGets)
|
||||
userLogin.GET("/tree/projs", treeUntilProjectGets)
|
||||
userLogin.GET("/tree/orgs", treeUntilOrganizationGets)
|
||||
|
||||
userLogin.GET("/resources/search", resourceSearchGet)
|
||||
userLogin.PUT("/resources/note", resourceNotePut)
|
||||
|
|
|
@ -144,7 +144,7 @@ func v1treeUntilProjectGetsByNid(c *gin.Context) {
|
|||
// 这个方法,展示的树只到project,节点搜索功能放到前台去
|
||||
func treeUntilProjectGets(c *gin.Context) {
|
||||
me := loginUser(c)
|
||||
oks, err := models.TreeUntilProjectsGetByUser(me)
|
||||
oks, err := models.TreeUntilTypGetByUser(me, "project")
|
||||
|
||||
renderData(c, oks, err)
|
||||
}
|
||||
|
@ -155,7 +155,15 @@ func v1TreeUntilProjectGets(c *gin.Context) {
|
|||
user, err := models.UserGet("username=?", username)
|
||||
dangerous(err)
|
||||
|
||||
oks, err := models.TreeUntilProjectsGetByUser(user)
|
||||
oks, err := models.TreeUntilTypGetByUser(user, "project")
|
||||
|
||||
renderData(c, oks, err)
|
||||
}
|
||||
|
||||
// 这个方法,展示的树只到organization
|
||||
func treeUntilOrganizationGets(c *gin.Context) {
|
||||
me := loginUser(c)
|
||||
oks, err := models.TreeUntilTypGetByUser(me, "organization")
|
||||
|
||||
renderData(c, oks, err)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue