fix
This commit is contained in:
@@ -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,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user