From 6585fecc6a77f405603395cf4daf0987ff74fa46 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Mon, 27 Nov 2023 12:31:53 +0800 Subject: [PATCH] fix --- .../internal/logic/createldapuserlogic.go | 12 ++-- server/ldap-admin/internal/types/types.go | 19 ++--- server_api/ldap-admin.api | 19 ++--- utils/ldap_lib/ldap_user.go | 71 ++++++++++++++++--- 4 files changed, 84 insertions(+), 37 deletions(-) diff --git a/server/ldap-admin/internal/logic/createldapuserlogic.go b/server/ldap-admin/internal/logic/createldapuserlogic.go index fecbfdd8..285477de 100644 --- a/server/ldap-admin/internal/logic/createldapuserlogic.go +++ b/server/ldap-admin/internal/logic/createldapuserlogic.go @@ -88,7 +88,10 @@ func (l *CreateLdapUserLogic) CreateLdapUser(req *types.CreateLdapUserReq, r *ht "mail": {req.Email}, //邮箱 "postalCode": {fmt.Sprintf("%d", req.Status)}, //状态 "roomNumber": {fmt.Sprintf("%d", req.GroupId)}, //权限分组id - "departmentNumber": req.OrganizationDNList, //所属组织部门 + "departmentNumber": {""}, //所属组织部门 + "telexNumber": {""}, //管理的部门 + "st": {fmt.Sprintf("%d", req.Gender)}, //性别 + "title": {req.Birthday}, //生日 "postalAddress": {req.Avatar}, //头像 "mobile": {req.Mobile}, //手机号 "userPassword": {req.Password}, //密码 @@ -97,13 +100,6 @@ func (l *CreateLdapUserLogic) CreateLdapUser(req *types.CreateLdapUserReq, r *ht logx.Error(err) return resp.SetStatusWithMessage(basic.CodeServiceErr, "添加用户失败,"+err.Error()) } - //将用户加入这些部门 - for _, v := range req.OrganizationDNList { - if err = l.svcCtx.Ldap.AddUserToOrganization(v, userDN); err != nil { - logx.Error("加入部门失败:", err) - continue - } - } return resp.SetStatusWithMessage(basic.CodeOK, "添加用户成功") } diff --git a/server/ldap-admin/internal/types/types.go b/server/ldap-admin/internal/types/types.go index 55c589df..e5a6c8c3 100644 --- a/server/ldap-admin/internal/types/types.go +++ b/server/ldap-admin/internal/types/types.go @@ -143,15 +143,16 @@ type UpdateLdapOrganizationReq struct { } type CreateLdapUserReq struct { - UserName string `json:"user_name"` //用户名 - Email string `json:"email"` //邮箱 - Password string `json:"password"` //密码 - Mobile string `json:"mobile"` //手机号 - Avatar string `json:"avatar"` //头像地址 - EmployeeType int64 `json:"employee_type,options=1|2|3"` //1正式 2实习 3外包 - GroupId int64 `json:"group_id,optional"` //授权分组id - OrganizationDNList []string `json:"organization_dn_list"` //属于哪些部门 - Status int64 `json:"status,options=0|1"` //状态 1正常0离职 + UserName string `json:"user_name"` //用户名 + Email string `json:"email"` //邮箱 + Password string `json:"password"` //密码 + Mobile string `json:"mobile"` //手机号 + Avatar string `json:"avatar"` //头像地址 + EmployeeType int64 `json:"employee_type,options=1|2|3"` //1正式 2实习 3外包 + GroupId int64 `json:"group_id,optional"` //授权分组id + Gender int64 `json:"gender,options=1|2|3"` //性别 1男 2女 3未知 + Birthday string `json:"birthday"` //生日 + Status int64 `json:"status,options=0|1"` //状态 1正常0离职 } type UpdateLdapUserReq struct { diff --git a/server_api/ldap-admin.api b/server_api/ldap-admin.api index 93be5c6e..48f9601c 100644 --- a/server_api/ldap-admin.api +++ b/server_api/ldap-admin.api @@ -227,15 +227,16 @@ type UpdateLdapOrganizationReq { } //添加ldap用户帐号 type CreateLdapUserReq { - UserName string `json:"user_name"` //用户名 - Email string `json:"email"` //邮箱 - Password string `json:"password"` //密码 - Mobile string `json:"mobile"` //手机号 - Avatar string `json:"avatar"` //头像地址 - EmployeeType int64 `json:"employee_type,options=1|2|3"` //1正式 2实习 3外包 - GroupId int64 `json:"group_id,optional"` //授权分组id - OrganizationDNList []string `json:"organization_dn_list"` //属于哪些部门 - Status int64 `json:"status,options=0|1"` //状态 1正常0离职 + UserName string `json:"user_name"` //用户名 + Email string `json:"email"` //邮箱 + Password string `json:"password"` //密码 + Mobile string `json:"mobile"` //手机号 + Avatar string `json:"avatar"` //头像地址 + EmployeeType int64 `json:"employee_type,options=1|2|3"` //1正式 2实习 3外包 + GroupId int64 `json:"group_id,optional"` //授权分组id + Gender int64 `json:"gender,options=1|2|3"` //性别 1男 2女 3未知 + Birthday string `json:"birthday"` //生日 + Status int64 `json:"status,options=0|1"` //状态 1正常0离职 } //修改ldap用户信息 type UpdateLdapUserReq { diff --git a/utils/ldap_lib/ldap_user.go b/utils/ldap_lib/ldap_user.go index 13bf2250..f2706fdc 100644 --- a/utils/ldap_lib/ldap_user.go +++ b/utils/ldap_lib/ldap_user.go @@ -9,17 +9,20 @@ import ( ) type LdapUserInfo struct { - UserId int64 `json:"userId"` - UserDN string `json:"user_dn"` - UserName string `json:"user_name"` //用户名 - Password string `json:"password"` //密码 - Email string `json:"email"` //邮箱 - Mobile string `json:"mobile"` //手机号 - Avatar string `json:"avatar"` //头像地址 - EmployeeType int64 `json:"employee_type"` //1正式 2实习 3外包 - GroupId int64 `json:"group_id"` //权限组id - OrganizationDNList []string `json:"organization_dn_list"` //加入的部门 - Status int64 `json:"status,options=0|1"` //状态 1正常0离职 + UserId int64 `json:"userId"` + UserDN string `json:"user_dn"` + UserName string `json:"user_name"` //用户名 + Password string `json:"password"` //密码 + Email string `json:"email"` //邮箱 + Mobile string `json:"mobile"` //手机号 + Avatar string `json:"avatar"` //头像地址 + EmployeeType int64 `json:"employee_type"` //1正式 2实习 3外包 + GroupId int64 `json:"group_id"` //权限组id + OrganizationDNList []string `json:"organization_dn_list"` //加入的部门 + ManageOrganizationDNList []string `json:"manage_organization_dn_list"` //管理的部门 + Gender int64 `json:"gender"` //性别 + Birthday string `json:"birthday"` //生日 + Status int64 `json:"status,options=0|1"` //状态 1正常0离职 } // 获取用户详情 @@ -87,6 +90,18 @@ func (l *Ldap) GetLdapUserInfo(userDN string) (*LdapUserInfo, error) { } case "departmentNumber": //加入的部门dn集合 user.OrganizationDNList = attr.Values + case "telexNumber": //管理的部门dn集合 + user.ManageOrganizationDNList = attr.Values + case "st": //性别 + if len(attr.Values) == 0 { + return nil, errors.New("性别不存在") + } + user.Gender, err = strconv.ParseInt(attr.Values[0], 10, 64) + if err != nil { + return nil, err + } + case "title": //生日 + user.Birthday = strings.Join(attr.Values, ",") } } if user.UserId == 0 { @@ -156,6 +171,18 @@ func (l *Ldap) GetLdapBaseTeamUserList(pageSize uint32, filter, pageCookie strin } case "departmentNumber": //加入的部门dn集合 user.OrganizationDNList = attr.Values + case "telexNumber": //管理的部门dn集合 + user.ManageOrganizationDNList = attr.Values + case "st": //性别 + if len(attr.Values) == 0 { + return nil, "", errors.New("性别不存在") + } + user.Gender, err = strconv.ParseInt(attr.Values[0], 10, 64) + if err != nil { + return nil, "", err + } + case "title": //生日 + user.Birthday = strings.Join(attr.Values, ",") } } list = append(list, user) @@ -219,6 +246,28 @@ func (l *Ldap) GetLdapBaseTeamUsersByParams(filter string) ([]LdapUserInfo, erro if err != nil { return nil, err } + case "roomNumber": //权限组id + if len(attr.Values) == 0 { + return nil, errors.New("权限组id不存在") + } + user.GroupId, err = strconv.ParseInt(attr.Values[0], 10, 64) + if err != nil { + return nil, err + } + case "departmentNumber": //加入的部门dn集合 + user.OrganizationDNList = attr.Values + case "telexNumber": //管理的部门dn集合 + user.ManageOrganizationDNList = attr.Values + case "st": //性别 + if len(attr.Values) == 0 { + return nil, errors.New("性别不存在") + } + user.Gender, err = strconv.ParseInt(attr.Values[0], 10, 64) + if err != nil { + return nil, err + } + case "title": //生日 + user.Birthday = strings.Join(attr.Values, ",") } } list = append(list, user)