From 18b27b61acb5864459a6e80096dd40385f3dbeda Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Fri, 17 Nov 2023 11:15:03 +0800 Subject: [PATCH] fix --- .../internal/logic/getldaporganizationslogic.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/server/ldap-admin/internal/logic/getldaporganizationslogic.go b/server/ldap-admin/internal/logic/getldaporganizationslogic.go index 7e3bc261..f546bf48 100644 --- a/server/ldap-admin/internal/logic/getldaporganizationslogic.go +++ b/server/ldap-admin/internal/logic/getldaporganizationslogic.go @@ -35,6 +35,7 @@ func NewGetLdapOrganizationsLogic(ctx context.Context, svcCtx *svc.ServiceContex // } 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"` @@ -53,7 +54,7 @@ func (l *GetLdapOrganizationsLogic) GetLdapOrganizations(req *types.Request, use return resp.SetStatusWithMessage(basic.CodeServiceErr, "基础用户组的DN未配置") } filter := "(|(&(objectClass=groupOfUniqueNames)(objectClass=top))(objectClass=organization))" - fields := []string{"businessCategory", "dn"} + fields := []string{"businessCategory", "dn", "uniqueMember"} searchResult, err := ldapServer.Search(l.svcCtx.Config.Ldap.BaseDN, ldap.ScopeWholeSubtree, filter, fields, nil) if err != nil { return resp.SetStatusWithMessage(basic.CodeServiceErr, "查询失败:"+err.Error()) @@ -64,12 +65,19 @@ func (l *GetLdapOrganizationsLogic) GetLdapOrganizations(req *types.Request, use for _, v := range searchResult.Entries { sortNum++ attribute := make(map[string]interface{}) + hasMember := false for _, attr := range v.Attributes { + //判断是否有成员(不包含root用户所以判断大于1) + if attr.Name == "uniqueMember" && len(attr.Values) > 1 { + hasMember = true + continue + } attribute[attr.Name] = strings.Join(attr.Values, ",") } mapDN[v.DN] = &DNItem{ DN: v.DN, ParentDN: "", + HasMember: hasMember, Attribute: attribute, Sort: sortNum, Child: make([]*DNItem, 0, 100),