From de89d8442cf2de51a778e0bbc6d29defd3711836 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Fri, 24 Nov 2023 12:31:13 +0800 Subject: [PATCH 1/2] fix --- .../logic/getldaporganizationslogic.go | 30 +++++++++---------- .../logic/updateldaporganizationlogic.go | 2 +- server/ldap-admin/internal/types/types.go | 8 ++--- server_api/ldap-admin.api | 4 +-- 4 files changed, 22 insertions(+), 22 deletions(-) diff --git a/server/ldap-admin/internal/logic/getldaporganizationslogic.go b/server/ldap-admin/internal/logic/getldaporganizationslogic.go index 3b00a804..2fc516b7 100644 --- a/server/ldap-admin/internal/logic/getldaporganizationslogic.go +++ b/server/ldap-admin/internal/logic/getldaporganizationslogic.go @@ -34,15 +34,15 @@ func NewGetLdapOrganizationsLogic(ctx context.Context, svcCtx *svc.ServiceContex // func (l *GetLdapOrganizationsLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) { // } type DNItem struct { - MemberCount int `json:"member_count"` - BusinessCategory string `json:"business_category"` - OwnerName string `json:"owner_name"` - OwnerDN string `json:"owner_dn"` - Level int `json:"level"` - DepartmentDN string `json:"department_dn"` - DepartmentParentDN string `json:"department_parent_dn"` - Sort int `json:"sort"` - Child []*DNItem `json:"child"` + MemberCount int `json:"member_count"` + OrganizationName string `json:"organization_name"` + OwnerName string `json:"owner_name"` + OwnerDN string `json:"owner_dn"` + Level int `json:"level"` + OrganizationDN string `json:"organization_dn"` + ParentOrganizationDN string `json:"parent_organization_dn"` + Sort int `json:"sort"` + Child []*DNItem `json:"child"` } func (l *GetLdapOrganizationsLogic) GetLdapOrganizations(req *types.Request, r *http.Request) (resp *basic.Response) { @@ -72,8 +72,8 @@ func (l *GetLdapOrganizationsLogic) GetLdapOrganizations(req *types.Request, r * ownerDN := "" for _, v := range searchResult.Entries { sortNum++ - memberCount := 0 //成员数 - businessCategory := "" //部门名称 + memberCount := 0 //成员数 + departmentName := "" //部门名称 for _, attr := range v.Attributes { switch attr.Name { case "uniqueMember": @@ -87,14 +87,14 @@ func (l *GetLdapOrganizationsLogic) GetLdapOrganizations(req *types.Request, r * userCn := strings.Split(attr.Values[0], ",")[0] ownerFilterBuilder.WriteString(fmt.Sprintf("(%s)", userCn)) case "businessCategory": - businessCategory = strings.Join(attr.Values, ",") + departmentName = strings.Join(attr.Values, ",") } } dnSlice := strings.ReplaceAll(v.DN, ","+l.svcCtx.Config.Ldap.BaseDN, "") //把最顶级的组织去掉 level := len(strings.Split(dnSlice, ",")) data := &DNItem{ - DepartmentDN: v.DN, - BusinessCategory: businessCategory, + OrganizationDN: v.DN, + OrganizationName: departmentName, Level: level, MemberCount: memberCount, OwnerDN: ownerDN, @@ -136,7 +136,7 @@ func (l *GetLdapOrganizationsLogic) GetLdapOrganizations(req *types.Request, r * //有父级 parentDN := strings.Join(sl[1:], ",") if parent, ok := mapDN[parentDN]; ok { - v.DepartmentParentDN = parentDN + v.ParentOrganizationDN = parentDN parent.Child = append(parent.Child, v) //排序 sort.Slice(parent.Child, func(i, j int) bool { diff --git a/server/ldap-admin/internal/logic/updateldaporganizationlogic.go b/server/ldap-admin/internal/logic/updateldaporganizationlogic.go index 623940b2..1ed13404 100644 --- a/server/ldap-admin/internal/logic/updateldaporganizationlogic.go +++ b/server/ldap-admin/internal/logic/updateldaporganizationlogic.go @@ -44,7 +44,7 @@ func (l *UpdateLdapOrganizationLogic) UpdateLdapOrganization(req *types.UpdateLd return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "参数错误,无效的组织DN") } if err := l.svcCtx.Ldap.Update(req.OrganizationDN, map[string][]string{ - "businessCategory": {req.BusinessCategory}, + "businessCategory": {req.OrganizationName}, }); err != nil { logx.Error(err) return resp.SetStatusWithMessage(basic.CodeServiceErr, "更新ldap组织失败,"+err.Error()) diff --git a/server/ldap-admin/internal/types/types.go b/server/ldap-admin/internal/types/types.go index 1c0d46f6..d26328de 100644 --- a/server/ldap-admin/internal/types/types.go +++ b/server/ldap-admin/internal/types/types.go @@ -133,9 +133,9 @@ type MenuItem struct { } type CreateLdapOrganizationReq struct { - OrganizationName string `json:"organization_name"` //组织名 - ParentOrganizationDN string `json:"parent_organization_dn"` //父级dn - OwnerDN string `json:"owner_dn"` //负责人dn + OrganizationName string `json:"organization_name"` //组织名 + ParentOrganizationDN string `json:"parent_organization_dn,optional"` //父级dn + OwnerDN string `json:"owner_dn,optional"` //负责人dn } type DeleteLdapOrganizationReq struct { @@ -144,7 +144,7 @@ type DeleteLdapOrganizationReq struct { type UpdateLdapOrganizationReq struct { OrganizationDN string `json:"organization_dn"` //组织dn - BusinessCategory string `json:"business_category"` //组织分类名称 + OrganizationName string `json:"organization_name"` //组织分类名称 } type CreateLdapUserReq struct { diff --git a/server_api/ldap-admin.api b/server_api/ldap-admin.api index dd86aa6e..152a1828 100644 --- a/server_api/ldap-admin.api +++ b/server_api/ldap-admin.api @@ -221,7 +221,7 @@ type MenuItem { } //增加ldap组织 type CreateLdapOrganizationReq { - OrganizationName string `json:"organization_name"` //组织名 + OrganizationName string `json:"organization_name"` //组织名 ParentOrganizationDN string `json:"parent_organization_dn,optional"` //父级dn OwnerDN string `json:"owner_dn,optional"` //负责人dn } @@ -232,7 +232,7 @@ type DeleteLdapOrganizationReq { //修改ldap组织 type UpdateLdapOrganizationReq { OrganizationDN string `json:"organization_dn"` //组织dn - BusinessCategory string `json:"business_category"` //组织分类名称 + OrganizationName string `json:"organization_name"` //组织分类名称 } //添加ldap用户帐号 type CreateLdapUserReq { From eb06aca1ae4399a7eaf74a20aa7179b866a7e15d Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Fri, 24 Nov 2023 13:11:45 +0800 Subject: [PATCH 2/2] fix --- server/ldap-admin/internal/logic/createldaporganizationlogic.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/ldap-admin/internal/logic/createldaporganizationlogic.go b/server/ldap-admin/internal/logic/createldaporganizationlogic.go index 28569849..6d0d86ad 100644 --- a/server/ldap-admin/internal/logic/createldaporganizationlogic.go +++ b/server/ldap-admin/internal/logic/createldaporganizationlogic.go @@ -55,7 +55,7 @@ func (l *CreateLdapOrganizationLogic) CreateLdapOrganization(req *types.CreateLd } organizationNamePinyin := chinese_to_pinyin.ChineseToPinyin(req.OrganizationName) //组装organization dn - organizationDN := "ou=" + req.OrganizationName + "," + req.ParentOrganizationDN + organizationDN := "ou=" + organizationNamePinyin + "," + req.ParentOrganizationDN err := l.svcCtx.Ldap.Create(organizationDN, map[string][]string{ "objectClass": {"top", "groupOfUniqueNames"}, "owner": {req.OwnerDN}, //负责人DN