Merge branch 'develop' of gitee.com:fusenpack/fusenapi into develop

This commit is contained in:
momo 2023-11-24 11:01:11 +08:00
commit ce006803c1
5 changed files with 32 additions and 24 deletions

View File

@ -8,7 +8,6 @@ import (
"fmt"
"fusenapi/utils/fssql"
"fusenapi/utils/handlers"
"log"
"gorm.io/gorm"
)
@ -101,7 +100,7 @@ func (m *FsUserInfoModel) GetProfile(ctx context.Context, pkey string, userId in
if !ok {
return m.getDefaultProfile(ctx, tname)
}
log.Println(v, guestId, userId)
var info map[string]any
err = json.Unmarshal([]byte(v), &info)
if err != nil {

View File

@ -1,7 +1,6 @@
package handler
import (
"log"
"net/http"
"reflect"
@ -21,8 +20,6 @@ func UserGetProfileHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return
}
log.Println(userinfo)
// 创建一个业务逻辑层实例
l := logic.NewUserGetProfileLogic(r.Context(), svcCtx)

View File

@ -3,7 +3,6 @@ package logic
import (
"fusenapi/utils/auth"
"fusenapi/utils/basic"
"log"
"context"
@ -35,12 +34,21 @@ func (l *UserGetProfileLogic) UserGetProfile(req *types.QueryProfileRequest, use
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
// userinfo 传入值时, 一定不为null
log.Println(userinfo)
profileBase, err := l.svcCtx.AllModels.FsUserInfo.GetProfile(l.ctx, req.TopKey, userinfo.UserId, userinfo.GuestId)
if err != nil {
return resp.SetStatusWithMessage(basic.CodeApiErr, err.Error())
}
user, err := l.svcCtx.AllModels.FsUser.FindUserById(context.TODO(), userinfo.UserId)
if err != nil {
logx.Error(err) // 日志记录错误
return resp.SetStatus(basic.CodeDbSqlErr, err) // 返回数据库创建错误
}
if bmap, ok := profileBase["base"].(map[string]any); ok {
bmap["email"] = *user.Email
}
return resp.SetStatus(basic.CodeOK, profileBase)
}

View File

@ -48,7 +48,7 @@ func (l *CreateLdapOrganizationLogic) CreateLdapOrganization(req *types.CreateLd
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "参数错误,组织英文名不能包含中文")
}
if req.ParentOrganizationDN == "" {
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "参数错误,父级DN不能为空")
req.ParentOrganizationDN = l.svcCtx.Config.Ldap.BaseDN //不传则是第一层级
}
if req.BusinessCategory == "" {
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "参数错误,组织分类名不能为空")

View File

@ -33,12 +33,13 @@ func NewGetLdapOrganizationsLogic(ctx context.Context, svcCtx *svc.ServiceContex
// func (l *GetLdapOrganizationsLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
// }
type DNItem struct {
Attribute map[string]interface{} `json:"attribute"`
HasMember bool `json:"has_member"` //是否有成员
DN string `json:"dn"`
ParentDN string `json:"parent_dn"`
Sort int `json:"sort"`
Child []*DNItem `json:"child"`
Attribute map[string]interface{} `json:"attribute"`
MemberCount int `json:"member_count"`
Level int `json:"level"`
DN string `json:"dn"`
ParentDN string `json:"parent_dn"`
Sort int `json:"sort"`
Child []*DNItem `json:"child"`
}
func (l *GetLdapOrganizationsLogic) GetLdapOrganizations(req *types.Request, r *http.Request) (resp *basic.Response) {
@ -55,7 +56,7 @@ func (l *GetLdapOrganizationsLogic) GetLdapOrganizations(req *types.Request, r *
if len(peopleDNSlice) <= 1 {
return resp.SetStatusWithMessage(basic.CodeServiceErr, "基础用户组的DN未配置")
}
filter := "(|(&(objectClass=groupOfUniqueNames)(objectClass=top))(objectClass=organization))"
filter := "(&(objectClass=groupOfUniqueNames)(objectClass=top))"
fields := []string{"businessCategory", "dn", "uniqueMember"}
searchResult, err := l.svcCtx.Ldap.Search(l.svcCtx.Config.Ldap.BaseDN, ldap.ScopeWholeSubtree, filter, fields, nil)
if err != nil {
@ -67,22 +68,25 @@ func (l *GetLdapOrganizationsLogic) GetLdapOrganizations(req *types.Request, r *
for _, v := range searchResult.Entries {
sortNum++
attribute := make(map[string]interface{})
hasMember := false
memberCount := 0
for _, attr := range v.Attributes {
//判断是否有成员(不包含root用户所以判断大于1)
if attr.Name == "uniqueMember" && len(attr.Values) > 1 {
hasMember = true
if attr.Name == "uniqueMember" {
memberCount = len(attr.Values)
continue
}
attribute[attr.Name] = strings.Join(attr.Values, ",")
}
dnSlice := strings.ReplaceAll(v.DN, ","+l.svcCtx.Config.Ldap.BaseDN, "") //把最顶级的组织去掉
level := len(strings.Split(dnSlice, ","))
mapDN[v.DN] = &DNItem{
DN: v.DN,
ParentDN: "",
HasMember: hasMember,
Attribute: attribute,
Sort: sortNum,
Child: make([]*DNItem, 0, 100),
DN: v.DN,
ParentDN: "",
Level: level,
MemberCount: memberCount,
Attribute: attribute,
Sort: sortNum,
Child: make([]*DNItem, 0, 100),
}
}
//组织树形层级关系