fix
This commit is contained in:
parent
9c97414597
commit
82db686b05
|
@ -48,7 +48,7 @@ func (l *CreateLdapOrganizationLogic) CreateLdapOrganization(req *types.CreateLd
|
|||
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "参数错误,组织英文名不能包含中文")
|
||||
}
|
||||
if req.ParentOrganizationDN == "" {
|
||||
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "参数错误,父级DN不能为空")
|
||||
req.ParentOrganizationDN = l.svcCtx.Config.Ldap.BaseDN //不传则是第一层级
|
||||
}
|
||||
if req.BusinessCategory == "" {
|
||||
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "参数错误,组织分类名不能为空")
|
||||
|
|
|
@ -33,12 +33,13 @@ func NewGetLdapOrganizationsLogic(ctx context.Context, svcCtx *svc.ServiceContex
|
|||
// func (l *GetLdapOrganizationsLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
|
||||
// }
|
||||
type DNItem struct {
|
||||
Attribute map[string]interface{} `json:"attribute"`
|
||||
HasMember bool `json:"has_member"` //是否有成员
|
||||
DN string `json:"dn"`
|
||||
ParentDN string `json:"parent_dn"`
|
||||
Sort int `json:"sort"`
|
||||
Child []*DNItem `json:"child"`
|
||||
Attribute map[string]interface{} `json:"attribute"`
|
||||
MemberCount int `json:"member_count"`
|
||||
Level int `json:"level"`
|
||||
DN string `json:"dn"`
|
||||
ParentDN string `json:"parent_dn"`
|
||||
Sort int `json:"sort"`
|
||||
Child []*DNItem `json:"child"`
|
||||
}
|
||||
|
||||
func (l *GetLdapOrganizationsLogic) GetLdapOrganizations(req *types.Request, r *http.Request) (resp *basic.Response) {
|
||||
|
@ -55,7 +56,7 @@ func (l *GetLdapOrganizationsLogic) GetLdapOrganizations(req *types.Request, r *
|
|||
if len(peopleDNSlice) <= 1 {
|
||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "基础用户组的DN未配置")
|
||||
}
|
||||
filter := "(|(&(objectClass=groupOfUniqueNames)(objectClass=top))(objectClass=organization))"
|
||||
filter := "(&(objectClass=groupOfUniqueNames)(objectClass=top))"
|
||||
fields := []string{"businessCategory", "dn", "uniqueMember"}
|
||||
searchResult, err := l.svcCtx.Ldap.Search(l.svcCtx.Config.Ldap.BaseDN, ldap.ScopeWholeSubtree, filter, fields, nil)
|
||||
if err != nil {
|
||||
|
@ -67,22 +68,25 @@ func (l *GetLdapOrganizationsLogic) GetLdapOrganizations(req *types.Request, r *
|
|||
for _, v := range searchResult.Entries {
|
||||
sortNum++
|
||||
attribute := make(map[string]interface{})
|
||||
hasMember := false
|
||||
memberCount := 0
|
||||
for _, attr := range v.Attributes {
|
||||
//判断是否有成员(不包含root用户所以判断大于1)
|
||||
if attr.Name == "uniqueMember" && len(attr.Values) > 1 {
|
||||
hasMember = true
|
||||
if attr.Name == "uniqueMember" {
|
||||
memberCount = len(attr.Values) - 1 //不要包含原始用户
|
||||
continue
|
||||
}
|
||||
attribute[attr.Name] = strings.Join(attr.Values, ",")
|
||||
}
|
||||
dnSlice := strings.ReplaceAll(v.DN, ","+l.svcCtx.Config.Ldap.BaseDN, "") //把最顶级的组织去掉
|
||||
level := len(strings.Split(dnSlice, ","))
|
||||
mapDN[v.DN] = &DNItem{
|
||||
DN: v.DN,
|
||||
ParentDN: "",
|
||||
HasMember: hasMember,
|
||||
Attribute: attribute,
|
||||
Sort: sortNum,
|
||||
Child: make([]*DNItem, 0, 100),
|
||||
DN: v.DN,
|
||||
ParentDN: "",
|
||||
Level: level,
|
||||
MemberCount: memberCount,
|
||||
Attribute: attribute,
|
||||
Sort: sortNum,
|
||||
Child: make([]*DNItem, 0, 100),
|
||||
}
|
||||
}
|
||||
//组织树形层级关系
|
||||
|
|
Loading…
Reference in New Issue
Block a user