fix
This commit is contained in:
parent
86216a6456
commit
648e200d87
@ -3,6 +3,7 @@ package logic
|
|||||||
import (
|
import (
|
||||||
"fusenapi/utils/auth"
|
"fusenapi/utils/auth"
|
||||||
"fusenapi/utils/basic"
|
"fusenapi/utils/basic"
|
||||||
|
"fusenapi/utils/chinese_to_pinyin"
|
||||||
"fusenapi/utils/ldap_lib"
|
"fusenapi/utils/ldap_lib"
|
||||||
"strings"
|
"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) {
|
func (l *CreateLdapOrganizationLogic) CreateLdapOrganization(req *types.CreateLdapOrganizationReq, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||||
req.OrganizationEnName = strings.Trim(req.OrganizationEnName, " ")
|
req.OrganizationEnName = strings.Trim(req.OrganizationEnName, " ")
|
||||||
req.ParentOrganizationDN = strings.Trim(req.ParentOrganizationDN, " ")
|
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 {
|
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 == "" {
|
if req.ParentOrganizationDN == "" {
|
||||||
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "参数错误,父级DN不能为空")
|
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "参数错误,父级DN不能为空")
|
||||||
}
|
}
|
||||||
if req.BusinessCategory == "" {
|
if req.OrganizationName == "" {
|
||||||
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "参数错误,分类名不能为空")
|
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "参数错误,组织中文名不能为空")
|
||||||
}
|
}
|
||||||
//组装organization dn
|
//组装organization dn
|
||||||
organizationDN := "ou=" + req.OrganizationEnName + "," + req.ParentOrganizationDN
|
organizationDN := "ou=" + req.OrganizationEnName + "," + req.ParentOrganizationDN
|
||||||
ldapServer := ldap_lib.NewLdap(l.svcCtx.Ldap, l.svcCtx.Config.Ldap.BaseDN, l.svcCtx.Config.Ldap.RootDN)
|
ldapServer := ldap_lib.NewLdap(l.svcCtx.Ldap, l.svcCtx.Config.Ldap.BaseDN, l.svcCtx.Config.Ldap.RootDN)
|
||||||
err := ldapServer.Create(organizationDN, map[string][]string{
|
err := ldapServer.Create(organizationDN, map[string][]string{
|
||||||
"objectClass": {"top", "groupOfUniqueNames"},
|
"objectClass": {"top", "groupOfUniqueNames"},
|
||||||
"cn": {req.BusinessCategory},
|
"cn": {req.OrganizationName},
|
||||||
"ou": {req.OrganizationEnName},
|
"ou": {req.OrganizationEnName},
|
||||||
"businessCategory": {req.BusinessCategory},
|
"businessCategory": {req.OrganizationName},
|
||||||
"uniqueMember": {l.svcCtx.Config.Ldap.RootDN}, //创建groupOfUniqueNames对象类型需要至少一个member,把root加进去
|
"uniqueMember": {l.svcCtx.Config.Ldap.RootDN}, //创建groupOfUniqueNames对象类型需要至少一个member,把root加进去
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -108,7 +108,7 @@ type MenuItem struct {
|
|||||||
|
|
||||||
type CreateLdapOrganizationReq struct {
|
type CreateLdapOrganizationReq struct {
|
||||||
OrganizationEnName string `json:"organization_en_name"` //组织英文名
|
OrganizationEnName string `json:"organization_en_name"` //组织英文名
|
||||||
BusinessCategory string `json:"business_category"` //组织分类名称
|
OrganizationName string `json:"organization_name"` //组织中文名称
|
||||||
ParentOrganizationDN string `json:"parent_organization_dn"` //父级dn
|
ParentOrganizationDN string `json:"parent_organization_dn"` //父级dn
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -179,7 +179,7 @@ type MenuItem {
|
|||||||
//增加ldap组织
|
//增加ldap组织
|
||||||
type CreateLdapOrganizationReq {
|
type CreateLdapOrganizationReq {
|
||||||
OrganizationEnName string `json:"organization_en_name"` //组织英文名
|
OrganizationEnName string `json:"organization_en_name"` //组织英文名
|
||||||
BusinessCategory string `json:"business_category"` //组织分类名称
|
OrganizationName string `json:"organization_name"` //组织中文名称
|
||||||
ParentOrganizationDN string `json:"parent_organization_dn"` //父级dn
|
ParentOrganizationDN string `json:"parent_organization_dn"` //父级dn
|
||||||
}
|
}
|
||||||
//删除ldap组织
|
//删除ldap组织
|
||||||
|
Loading…
x
Reference in New Issue
Block a user