From 648e200d87b32fc27cbf669cfa0f770567aa32fe Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Fri, 17 Nov 2023 15:16:34 +0800 Subject: [PATCH] fix --- .../logic/createldaporganizationlogic.go | 17 +++++++++++------ server/ldap-admin/internal/types/types.go | 2 +- server_api/ldap-admin.api | 2 +- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/server/ldap-admin/internal/logic/createldaporganizationlogic.go b/server/ldap-admin/internal/logic/createldaporganizationlogic.go index 71dd47a1..d1046fcf 100644 --- a/server/ldap-admin/internal/logic/createldaporganizationlogic.go +++ b/server/ldap-admin/internal/logic/createldaporganizationlogic.go @@ -3,6 +3,7 @@ package logic import ( "fusenapi/utils/auth" "fusenapi/utils/basic" + "fusenapi/utils/chinese_to_pinyin" "fusenapi/utils/ldap_lib" "strings" @@ -35,24 +36,28 @@ func NewCreateLdapOrganizationLogic(ctx context.Context, svcCtx *svc.ServiceCont func (l *CreateLdapOrganizationLogic) CreateLdapOrganization(req *types.CreateLdapOrganizationReq, userinfo *auth.UserInfo) (resp *basic.Response) { req.OrganizationEnName = strings.Trim(req.OrganizationEnName, " ") req.ParentOrganizationDN = strings.Trim(req.ParentOrganizationDN, " ") - req.BusinessCategory = strings.Trim(req.BusinessCategory, " ") + req.OrganizationName = strings.Trim(req.OrganizationName, " ") if len(strings.Split(req.OrganizationEnName, ",")) != 1 { - return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "参数错误,不合法的组织ou") + return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "参数错误,组织英文名不符合规范") + } + //转拼音比较下 + if req.OrganizationEnName != chinese_to_pinyin.ChineseToPinyin(req.OrganizationEnName) { + return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "参数错误,组织英文名不能包含中文") } if req.ParentOrganizationDN == "" { return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "参数错误,父级DN不能为空") } - if req.BusinessCategory == "" { - return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "参数错误,分类名不能为空") + if req.OrganizationName == "" { + return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "参数错误,组织中文名不能为空") } //组装organization dn organizationDN := "ou=" + req.OrganizationEnName + "," + req.ParentOrganizationDN ldapServer := ldap_lib.NewLdap(l.svcCtx.Ldap, l.svcCtx.Config.Ldap.BaseDN, l.svcCtx.Config.Ldap.RootDN) err := ldapServer.Create(organizationDN, map[string][]string{ "objectClass": {"top", "groupOfUniqueNames"}, - "cn": {req.BusinessCategory}, + "cn": {req.OrganizationName}, "ou": {req.OrganizationEnName}, - "businessCategory": {req.BusinessCategory}, + "businessCategory": {req.OrganizationName}, "uniqueMember": {l.svcCtx.Config.Ldap.RootDN}, //创建groupOfUniqueNames对象类型需要至少一个member,把root加进去 }) if err != nil { diff --git a/server/ldap-admin/internal/types/types.go b/server/ldap-admin/internal/types/types.go index e69efad2..d254450b 100644 --- a/server/ldap-admin/internal/types/types.go +++ b/server/ldap-admin/internal/types/types.go @@ -108,7 +108,7 @@ type MenuItem struct { type CreateLdapOrganizationReq struct { OrganizationEnName string `json:"organization_en_name"` //组织英文名 - BusinessCategory string `json:"business_category"` //组织分类名称 + OrganizationName string `json:"organization_name"` //组织中文名称 ParentOrganizationDN string `json:"parent_organization_dn"` //父级dn } diff --git a/server_api/ldap-admin.api b/server_api/ldap-admin.api index a20c7c01..f9b5b52e 100644 --- a/server_api/ldap-admin.api +++ b/server_api/ldap-admin.api @@ -179,7 +179,7 @@ type MenuItem { //增加ldap组织 type CreateLdapOrganizationReq { OrganizationEnName string `json:"organization_en_name"` //组织英文名 - BusinessCategory string `json:"business_category"` //组织分类名称 + OrganizationName string `json:"organization_name"` //组织中文名称 ParentOrganizationDN string `json:"parent_organization_dn"` //父级dn } //删除ldap组织