fix
This commit is contained in:
parent
663b831ec1
commit
b842216033
|
@ -2,10 +2,12 @@ package logic
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"fusenapi/server/ldap-admin/internal/svc"
|
||||
"fusenapi/server/ldap-admin/internal/types"
|
||||
"fusenapi/utils/basic"
|
||||
"fusenapi/utils/email"
|
||||
"github.com/go-ldap/ldap/v3"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
|
@ -47,17 +49,61 @@ func (l *GetLdapUserInfoLogic) GetLdapUserInfo(req *types.GetLdapUserInfoReq, r
|
|||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, err.Error())
|
||||
}
|
||||
//属于哪些部门
|
||||
filterBuilder := strings.Builder{}
|
||||
for _, v := range user.OrganizationDNList {
|
||||
//提取 ou
|
||||
filterBuilder.WriteString(fmt.Sprintf("(%s)", strings.Split(v, ",")[0]))
|
||||
}
|
||||
for _, v := range user.ManageOrganizationDNList {
|
||||
//提取 ou
|
||||
filterBuilder.WriteString(fmt.Sprintf("(%s)", strings.Split(v, ",")[0]))
|
||||
}
|
||||
//存储map
|
||||
mapOrganization := make(map[string]string)
|
||||
if filterBuilder.Len() > 0 {
|
||||
//查询部门信息
|
||||
filter := "(&(objectClass=groupOfUniqueNames)(objectClass=top)(|" + filterBuilder.String() + "))"
|
||||
fields := []string{"businessCategory", "dn"}
|
||||
organizationsResult, err := l.svcCtx.Ldap.Search(l.svcCtx.Config.Ldap.BaseDN, ldap.ScopeWholeSubtree, filter, fields, nil)
|
||||
if err != nil {
|
||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "查询失败:"+err.Error())
|
||||
}
|
||||
for _, entry := range organizationsResult.Entries {
|
||||
for _, attr := range entry.Attributes {
|
||||
switch attr.Name {
|
||||
case "businessCategory":
|
||||
mapOrganization[entry.DN] = strings.Join(attr.Values, ",")
|
||||
break //结束这层小循环
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
belongOrganizationList := make([]string, 0, len(user.OrganizationDNList))
|
||||
for _, DN := range user.OrganizationDNList {
|
||||
if name, ok := mapOrganization[DN]; ok {
|
||||
belongOrganizationList = append(belongOrganizationList, name)
|
||||
}
|
||||
}
|
||||
manageOrganizationList := make([]string, 0, len(user.ManageOrganizationDNList))
|
||||
for _, DN := range user.ManageOrganizationDNList {
|
||||
if name, ok := mapOrganization[DN]; ok {
|
||||
manageOrganizationList = append(manageOrganizationList, name)
|
||||
}
|
||||
}
|
||||
return resp.SetStatusWithMessage(basic.CodeOK, "success", types.GetLdapUserInfoRsp{
|
||||
UserId: user.UserId,
|
||||
UserDN: user.UserDN,
|
||||
UserName: user.UserName,
|
||||
Email: user.Email,
|
||||
Mobile: user.Mobile,
|
||||
Avatar: user.Avatar,
|
||||
EmployeeTpye: user.EmployeeType,
|
||||
Gender: user.Gender,
|
||||
Birthday: user.Birthday,
|
||||
Status: user.Status,
|
||||
UserId: user.UserId,
|
||||
UserDN: user.UserDN,
|
||||
UserName: user.UserName,
|
||||
Email: user.Email,
|
||||
Mobile: user.Mobile,
|
||||
Avatar: user.Avatar,
|
||||
EmployeeTpye: user.EmployeeType,
|
||||
Gender: user.Gender,
|
||||
Birthday: user.Birthday,
|
||||
BelongOriganization: belongOrganizationList,
|
||||
ManageOriganization: manageOrganizationList,
|
||||
Status: user.Status,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -183,16 +183,18 @@ type GetLdapUserInfoReq struct {
|
|||
}
|
||||
|
||||
type GetLdapUserInfoRsp struct {
|
||||
UserId int64 `json:"user_id"`
|
||||
UserDN string `json:"user_dn"`
|
||||
UserName string `json:"user_name"` //用户名
|
||||
Email string `json:"email"` //邮箱
|
||||
Mobile string `json:"mobile"` //手机号
|
||||
Avatar string `json:"avatar"` //头像地址
|
||||
EmployeeTpye int64 `json:"employee_tpye"` //雇佣类型 1正式 2实习 3外包
|
||||
Gender int64 `json:"gender,options=1|2|3"` //性别 1男 2女 3未知
|
||||
Birthday string `json:"birthday"` //生日
|
||||
Status int64 `json:"status,options=0|1"` //状态 1正常0离职
|
||||
UserId int64 `json:"user_id"`
|
||||
UserDN string `json:"user_dn"`
|
||||
UserName string `json:"user_name"` //用户名
|
||||
Email string `json:"email"` //邮箱
|
||||
Mobile string `json:"mobile"` //手机号
|
||||
Avatar string `json:"avatar"` //头像地址
|
||||
EmployeeTpye int64 `json:"employee_tpye"` //雇佣类型 1正式 2实习 3外包
|
||||
Gender int64 `json:"gender,options=1|2|3"` //性别 1男 2女 3未知
|
||||
Birthday string `json:"birthday"` //生日
|
||||
BelongOriganization []string `json:"belong_origanization"` //属于哪些部门
|
||||
ManageOriganization []string `json:"manage_origanization"` //负责哪些部门
|
||||
Status int64 `json:"status,options=0|1"` //状态 1正常0离职
|
||||
}
|
||||
|
||||
type AddLdapOrganizationMemberReq struct {
|
||||
|
|
|
@ -22,7 +22,7 @@ service ldap-admin {
|
|||
//删除权限组
|
||||
@handler DeleteLdapGroupHandler
|
||||
post /api/ldap-admin/delete_ldap_group(DeleteLdapGroupReq) returns (response);
|
||||
|
||||
|
||||
//权限组授权
|
||||
@handler SetLdapGroupAuthHandler
|
||||
post /api/ldap-admin/set_ldap_group_auth(SetLdapGroupAuthReq) returns (response);
|
||||
|
@ -35,7 +35,7 @@ service ldap-admin {
|
|||
//删除API
|
||||
@handler DeleteApiHandler
|
||||
post /api/ldap-admin/delete_api(DeleteApiReq) returns (response);
|
||||
|
||||
|
||||
//保存菜单
|
||||
@handler SaveMenuHandler
|
||||
post /api/ldap-admin/save_menu(SaveMenuReq) returns (response);
|
||||
|
@ -266,16 +266,18 @@ type GetLdapUserInfoReq {
|
|||
UserDN string `form:"user_dn"` //用户dn
|
||||
}
|
||||
type GetLdapUserInfoRsp {
|
||||
UserId int64 `json:"user_id"`
|
||||
UserDN string `json:"user_dn"`
|
||||
UserName string `json:"user_name"` //用户名
|
||||
Email string `json:"email"` //邮箱
|
||||
Mobile string `json:"mobile"` //手机号
|
||||
Avatar string `json:"avatar"` //头像地址
|
||||
EmployeeTpye int64 `json:"employee_tpye"` //雇佣类型 1正式 2实习 3外包
|
||||
Gender int64 `json:"gender,options=1|2|3"` //性别 1男 2女 3未知
|
||||
Birthday string `json:"birthday"` //生日
|
||||
Status int64 `json:"status,options=0|1"` //状态 1正常0离职
|
||||
UserId int64 `json:"user_id"`
|
||||
UserDN string `json:"user_dn"`
|
||||
UserName string `json:"user_name"` //用户名
|
||||
Email string `json:"email"` //邮箱
|
||||
Mobile string `json:"mobile"` //手机号
|
||||
Avatar string `json:"avatar"` //头像地址
|
||||
EmployeeTpye int64 `json:"employee_tpye"` //雇佣类型 1正式 2实习 3外包
|
||||
Gender int64 `json:"gender,options=1|2|3"` //性别 1男 2女 3未知
|
||||
Birthday string `json:"birthday"` //生日
|
||||
BelongOriganization []string `json:"belong_origanization"` //属于哪些部门
|
||||
ManageOriganization []string `json:"manage_origanization"` //负责哪些部门
|
||||
Status int64 `json:"status,options=0|1"` //状态 1正常0离职
|
||||
}
|
||||
//ldap组织添加成员
|
||||
type AddLdapOrganizationMemberReq {
|
||||
|
|
Loading…
Reference in New Issue
Block a user