From 963940c367f0101d328029ee58612348bbabe334 Mon Sep 17 00:00:00 2001 From: eson <9673575+githubcontent@user.noreply.gitee.com> Date: Fri, 24 Nov 2023 11:40:36 +0800 Subject: [PATCH 01/12] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20profile?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- model/gmodel/fs_user_info_logic.go | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/model/gmodel/fs_user_info_logic.go b/model/gmodel/fs_user_info_logic.go index 17ba0982..f2667011 100644 --- a/model/gmodel/fs_user_info_logic.go +++ b/model/gmodel/fs_user_info_logic.go @@ -9,6 +9,7 @@ import ( "fusenapi/utils/fssql" "fusenapi/utils/handlers" + "github.com/tidwall/gjson" "gorm.io/gorm" ) @@ -113,26 +114,18 @@ func (m *FsUserInfoModel) GetProfile(ctx context.Context, pkey string, userId in return m.getDefaultProfile(ctx, tname) } - if logoSelected, ok := info["logo_selected"]; ok { - if version, ok := logoSelected.(map[string]any)["version"]; ok { - if ver, ok := version.(string); ok { - if ver != versionML { - defaultUserInfo, err := m.getDefaultProfile(ctx, tname) - if err != nil { - return nil, err - } - info["logo_selected"] = defaultUserInfo["logo_selected"] - } - } + if logoSelected := gjson.Get(v, "logo_selected"); logoSelected.Exists() { + if ver := logoSelected.Get("version"); ver.Exists() && ver.String() == versionML { + return info, nil } - } else { - defaultUserInfo, err := m.getDefaultProfile(ctx, tname) - if err != nil { - return nil, err - } - info["logo_selected"] = defaultUserInfo["logo_selected"] } + defaultUserInfo, err := m.getDefaultProfile(ctx, tname) + if err != nil { + return nil, err + } + info["logo_selected"] = defaultUserInfo["logo_selected"] + return info, nil } From 8c45de4d258fb162e17fea0e008d32e8303ce65e Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Fri, 24 Nov 2023 11:45:56 +0800 Subject: [PATCH 02/12] fix --- .../logic/createldaporganizationlogic.go | 1 + .../logic/getldaporganizationslogic.go | 37 +++++++++++++++++-- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/server/ldap-admin/internal/logic/createldaporganizationlogic.go b/server/ldap-admin/internal/logic/createldaporganizationlogic.go index c662e47f..05b535fe 100644 --- a/server/ldap-admin/internal/logic/createldaporganizationlogic.go +++ b/server/ldap-admin/internal/logic/createldaporganizationlogic.go @@ -57,6 +57,7 @@ func (l *CreateLdapOrganizationLogic) CreateLdapOrganization(req *types.CreateLd organizationDN := "ou=" + req.OrganizationEnName + "," + req.ParentOrganizationDN err := l.svcCtx.Ldap.Create(organizationDN, map[string][]string{ "objectClass": {"top", "groupOfUniqueNames"}, + "owner": {""}, //负责人DN "cn": {req.OrganizationEnName}, "ou": {req.OrganizationEnName}, "businessCategory": {req.BusinessCategory}, diff --git a/server/ldap-admin/internal/logic/getldaporganizationslogic.go b/server/ldap-admin/internal/logic/getldaporganizationslogic.go index 80da8855..b138e6a5 100644 --- a/server/ldap-admin/internal/logic/getldaporganizationslogic.go +++ b/server/ldap-admin/internal/logic/getldaporganizationslogic.go @@ -1,6 +1,7 @@ package logic import ( + "fmt" "fusenapi/utils/basic" "github.com/go-ldap/ldap/v3" "net/http" @@ -35,6 +36,8 @@ func NewGetLdapOrganizationsLogic(ctx context.Context, svcCtx *svc.ServiceContex type DNItem struct { Attribute map[string]interface{} `json:"attribute"` MemberCount int `json:"member_count"` + OwnerName string `json:"owner_name"` + OwnerDN string `json:"owner_dn"` Level int `json:"level"` DN string `json:"dn"` ParentDN string `json:"parent_dn"` @@ -57,14 +60,16 @@ func (l *GetLdapOrganizationsLogic) GetLdapOrganizations(req *types.Request, r * return resp.SetStatusWithMessage(basic.CodeServiceErr, "基础用户组的DN未配置") } filter := "(&(objectClass=groupOfUniqueNames)(objectClass=top))" - fields := []string{"businessCategory", "dn", "uniqueMember"} + fields := []string{"businessCategory", "owner", "dn", "uniqueMember"} searchResult, 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()) } mapDN := make(map[string]*DNItem) sortNum := 0 + ownerFilterBuilder := strings.Builder{} //每个DN存入map + ownerDN := "" for _, v := range searchResult.Entries { sortNum++ attribute := make(map[string]interface{}) @@ -72,22 +77,48 @@ func (l *GetLdapOrganizationsLogic) GetLdapOrganizations(req *types.Request, r * for _, attr := range v.Attributes { //判断是否有成员(不包含root用户所以判断大于1) if attr.Name == "uniqueMember" { - memberCount = len(attr.Values) + memberCount = len(attr.Values) - 1 //不包含root用户 continue } + if attr.Name == "owner" && len(attr.Values) != 0 { //负责人 + ownerDN = attr.Values[0] + //解析用户DN,只需要提取cn + userCn := strings.Split(attr.Values[0], ",")[0] + ownerFilterBuilder.WriteString(fmt.Sprintf("(%s)", userCn)) + } 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{ + data := &DNItem{ DN: v.DN, ParentDN: "", Level: level, MemberCount: memberCount, Attribute: attribute, + OwnerDN: ownerDN, Sort: sortNum, Child: make([]*DNItem, 0, 100), } + mapDN[v.DN] = data + } + ownerFilters := ownerFilterBuilder.String() + if ownerFilters != "" { + ownerFilters = "(|" + ownerFilterBuilder.String() + ")" + //获取负责人列表信息 + ldapOwnerList, err := l.svcCtx.Ldap.GetLdapBaseTeamUsersByParams(ownerFilters) + if err != nil { + logx.Error(err) + return resp.SetStatusWithMessage(basic.CodeServiceErr, "获取部门负责人失败,"+err.Error()) + } + //把负责人塞到对应部门中 + for _, v := range mapDN { + for _, owner := range ldapOwnerList { + if v.OwnerDN == owner.UserDN { + v.OwnerName = owner.UserName + } + } + } } //组织树形层级关系 minLevel := 0 From dbf39e30579bb71df65593963a9678d0dfb4e470 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Fri, 24 Nov 2023 12:05:09 +0800 Subject: [PATCH 03/12] fix --- .../logic/createldaporganizationlogic.go | 12 +++- .../logic/getldaporganizationslogic.go | 56 ++++++++++--------- server/ldap-admin/internal/types/types.go | 3 +- server_api/ldap-admin.api | 9 +-- 4 files changed, 47 insertions(+), 33 deletions(-) diff --git a/server/ldap-admin/internal/logic/createldaporganizationlogic.go b/server/ldap-admin/internal/logic/createldaporganizationlogic.go index 05b535fe..7560f3ce 100644 --- a/server/ldap-admin/internal/logic/createldaporganizationlogic.go +++ b/server/ldap-admin/internal/logic/createldaporganizationlogic.go @@ -3,6 +3,7 @@ package logic import ( "fusenapi/utils/basic" "fusenapi/utils/chinese_to_pinyin" + "fusenapi/utils/email" "net/http" "strings" @@ -53,15 +54,22 @@ func (l *CreateLdapOrganizationLogic) CreateLdapOrganization(req *types.CreateLd if req.BusinessCategory == "" { return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "参数错误,组织分类名不能为空") } + if len(req.OwnerDN) <= 3 || req.OwnerDN[:3] != "cn=" { + return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "无效的用户DN") + } + cnEmail := strings.Split(req.OwnerDN, ",")[0][3:] + if !email.IsEmailValid(cnEmail) { + return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "错误的用户cn") + } //组装organization dn organizationDN := "ou=" + req.OrganizationEnName + "," + req.ParentOrganizationDN err := l.svcCtx.Ldap.Create(organizationDN, map[string][]string{ "objectClass": {"top", "groupOfUniqueNames"}, - "owner": {""}, //负责人DN + "owner": {req.OwnerDN}, //负责人DN "cn": {req.OrganizationEnName}, "ou": {req.OrganizationEnName}, "businessCategory": {req.BusinessCategory}, - "uniqueMember": {l.svcCtx.Config.Ldap.RootDN}, //创建groupOfUniqueNames对象类型需要至少一个member,把root加进去 + "uniqueMember": {req.OwnerDN}, //必须有一个初始的成员 }) if err != nil { logx.Error(err) diff --git a/server/ldap-admin/internal/logic/getldaporganizationslogic.go b/server/ldap-admin/internal/logic/getldaporganizationslogic.go index b138e6a5..e746b31e 100644 --- a/server/ldap-admin/internal/logic/getldaporganizationslogic.go +++ b/server/ldap-admin/internal/logic/getldaporganizationslogic.go @@ -34,15 +34,16 @@ 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"` - MemberCount int `json:"member_count"` - OwnerName string `json:"owner_name"` - OwnerDN string `json:"owner_dn"` - Level int `json:"level"` - 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"` + BusinessCategory string `json:"business_category"` + OwnerName string `json:"owner_name"` + OwnerDN string `json:"owner_dn"` + Level int `json:"level"` + DepartmentDN string `json:"department_dn"` + DepartmentParentDN string `json:"department_parent_dn"` + Sort int `json:"sort"` + Child []*DNItem `json:"child"` } func (l *GetLdapOrganizationsLogic) GetLdapOrganizations(req *types.Request, r *http.Request) (resp *basic.Response) { @@ -73,32 +74,35 @@ func (l *GetLdapOrganizationsLogic) GetLdapOrganizations(req *types.Request, r * for _, v := range searchResult.Entries { sortNum++ attribute := make(map[string]interface{}) - memberCount := 0 + memberCount := 0 //成员数 + businessCategory := "" //部门名称 for _, attr := range v.Attributes { - //判断是否有成员(不包含root用户所以判断大于1) - if attr.Name == "uniqueMember" { - memberCount = len(attr.Values) - 1 //不包含root用户 - continue - } - if attr.Name == "owner" && len(attr.Values) != 0 { //负责人 + switch attr.Name { + case "uniqueMember": + memberCount = len(attr.Values) + case "owner": + if len(attr.Values) == 0 { + continue + } ownerDN = attr.Values[0] //解析用户DN,只需要提取cn userCn := strings.Split(attr.Values[0], ",")[0] ownerFilterBuilder.WriteString(fmt.Sprintf("(%s)", userCn)) + case "businessCategory": + businessCategory = strings.Join(attr.Values, ",") } - attribute[attr.Name] = strings.Join(attr.Values, ",") } dnSlice := strings.ReplaceAll(v.DN, ","+l.svcCtx.Config.Ldap.BaseDN, "") //把最顶级的组织去掉 level := len(strings.Split(dnSlice, ",")) data := &DNItem{ - DN: v.DN, - ParentDN: "", - Level: level, - MemberCount: memberCount, - Attribute: attribute, - OwnerDN: ownerDN, - Sort: sortNum, - Child: make([]*DNItem, 0, 100), + DepartmentDN: v.DN, + BusinessCategory: businessCategory, + Level: level, + MemberCount: memberCount, + Attribute: attribute, + OwnerDN: ownerDN, + Sort: sortNum, + Child: make([]*DNItem, 0, 100), } mapDN[v.DN] = data } @@ -135,7 +139,7 @@ func (l *GetLdapOrganizationsLogic) GetLdapOrganizations(req *types.Request, r * //有父级 parentDN := strings.Join(sl[1:], ",") if parent, ok := mapDN[parentDN]; ok { - v.ParentDN = parentDN + v.DepartmentParentDN = parentDN parent.Child = append(parent.Child, v) //排序 sort.Slice(parent.Child, func(i, j int) bool { diff --git a/server/ldap-admin/internal/types/types.go b/server/ldap-admin/internal/types/types.go index 8a119fe8..58a757e7 100644 --- a/server/ldap-admin/internal/types/types.go +++ b/server/ldap-admin/internal/types/types.go @@ -134,8 +134,9 @@ type MenuItem struct { type CreateLdapOrganizationReq struct { OrganizationEnName string `json:"organization_en_name"` //组织英文名 - BusinessCategory string `json:"business_category"` //组织类别 + BusinessCategory string `json:"business_category"` //组织类别名称 ParentOrganizationDN string `json:"parent_organization_dn"` //父级dn + OwnerDN string `json:"owner_dn"` //负责人dn } type DeleteLdapOrganizationReq struct { diff --git a/server_api/ldap-admin.api b/server_api/ldap-admin.api index 8e5c3dfd..c949371a 100644 --- a/server_api/ldap-admin.api +++ b/server_api/ldap-admin.api @@ -22,11 +22,11 @@ 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); - + //权限组授权用户 @handler SetLdapGroupUserHandler post /api/ldap-admin/set_ldap_group_user(SetLdapGroupUserReq) returns (response); @@ -39,7 +39,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); @@ -222,8 +222,9 @@ type MenuItem { //增加ldap组织 type CreateLdapOrganizationReq { OrganizationEnName string `json:"organization_en_name"` //组织英文名 - BusinessCategory string `json:"business_category"` //组织类别 + BusinessCategory string `json:"business_category"` //组织类别名称 ParentOrganizationDN string `json:"parent_organization_dn"` //父级dn + OwnerDN string `json:"owner_dn"` //负责人dn } //删除ldap组织 type DeleteLdapOrganizationReq { From 681ec8269c0b6bce926648b75dfe1b0fa4208f92 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Fri, 24 Nov 2023 12:06:00 +0800 Subject: [PATCH 04/12] fix --- .../logic/getldaporganizationslogic.go | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/server/ldap-admin/internal/logic/getldaporganizationslogic.go b/server/ldap-admin/internal/logic/getldaporganizationslogic.go index e746b31e..3b00a804 100644 --- a/server/ldap-admin/internal/logic/getldaporganizationslogic.go +++ b/server/ldap-admin/internal/logic/getldaporganizationslogic.go @@ -34,16 +34,15 @@ 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"` - MemberCount int `json:"member_count"` - BusinessCategory string `json:"business_category"` - OwnerName string `json:"owner_name"` - OwnerDN string `json:"owner_dn"` - Level int `json:"level"` - DepartmentDN string `json:"department_dn"` - DepartmentParentDN string `json:"department_parent_dn"` - Sort int `json:"sort"` - Child []*DNItem `json:"child"` + MemberCount int `json:"member_count"` + BusinessCategory string `json:"business_category"` + OwnerName string `json:"owner_name"` + OwnerDN string `json:"owner_dn"` + Level int `json:"level"` + DepartmentDN string `json:"department_dn"` + DepartmentParentDN string `json:"department_parent_dn"` + Sort int `json:"sort"` + Child []*DNItem `json:"child"` } func (l *GetLdapOrganizationsLogic) GetLdapOrganizations(req *types.Request, r *http.Request) (resp *basic.Response) { @@ -73,7 +72,6 @@ func (l *GetLdapOrganizationsLogic) GetLdapOrganizations(req *types.Request, r * ownerDN := "" for _, v := range searchResult.Entries { sortNum++ - attribute := make(map[string]interface{}) memberCount := 0 //成员数 businessCategory := "" //部门名称 for _, attr := range v.Attributes { @@ -99,7 +97,6 @@ func (l *GetLdapOrganizationsLogic) GetLdapOrganizations(req *types.Request, r * BusinessCategory: businessCategory, Level: level, MemberCount: memberCount, - Attribute: attribute, OwnerDN: ownerDN, Sort: sortNum, Child: make([]*DNItem, 0, 100), From ca91a6f3ceb92b485e56e96866eaf331a339757e Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Fri, 24 Nov 2023 12:21:00 +0800 Subject: [PATCH 05/12] fix --- .../logic/createldaporganizationlogic.go | 23 ++++++------------- server/ldap-admin/internal/types/types.go | 3 +-- server_api/ldap-admin.api | 7 +++--- 3 files changed, 11 insertions(+), 22 deletions(-) diff --git a/server/ldap-admin/internal/logic/createldaporganizationlogic.go b/server/ldap-admin/internal/logic/createldaporganizationlogic.go index 7560f3ce..b576111c 100644 --- a/server/ldap-admin/internal/logic/createldaporganizationlogic.go +++ b/server/ldap-admin/internal/logic/createldaporganizationlogic.go @@ -2,7 +2,6 @@ package logic import ( "fusenapi/utils/basic" - "fusenapi/utils/chinese_to_pinyin" "fusenapi/utils/email" "net/http" "strings" @@ -38,22 +37,14 @@ func (l *CreateLdapOrganizationLogic) CreateLdapOrganization(req *types.CreateLd if !l.svcCtx.Ldap.VerifyAuthority(r) { return resp.SetStatusWithMessage(basic.CodeUnAuth, "无权限,请联系管理员开通") } - req.OrganizationEnName = strings.Trim(req.OrganizationEnName, " ") req.ParentOrganizationDN = strings.Trim(req.ParentOrganizationDN, " ") - req.BusinessCategory = strings.Trim(req.BusinessCategory, " ") - if len(strings.Split(req.OrganizationEnName, ",")) != 1 { - return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "参数错误,组织英文名不符合规范") - } - //转拼音比较下 - if req.OrganizationEnName != chinese_to_pinyin.ChineseToPinyin(req.OrganizationEnName) { - return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "参数错误,组织英文名不能包含中文") + req.OrganizationName = strings.Trim(req.OrganizationName, " ") + if req.OrganizationName == "" { + return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "组织名不能为空") } if req.ParentOrganizationDN == "" { req.ParentOrganizationDN = l.svcCtx.Config.Ldap.BaseDN //不传则是第一层级 } - if req.BusinessCategory == "" { - return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "参数错误,组织分类名不能为空") - } if len(req.OwnerDN) <= 3 || req.OwnerDN[:3] != "cn=" { return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "无效的用户DN") } @@ -62,13 +53,13 @@ func (l *CreateLdapOrganizationLogic) CreateLdapOrganization(req *types.CreateLd return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "错误的用户cn") } //组装organization dn - organizationDN := "ou=" + req.OrganizationEnName + "," + req.ParentOrganizationDN + organizationDN := "ou=" + req.OrganizationName + "," + req.ParentOrganizationDN err := l.svcCtx.Ldap.Create(organizationDN, map[string][]string{ "objectClass": {"top", "groupOfUniqueNames"}, "owner": {req.OwnerDN}, //负责人DN - "cn": {req.OrganizationEnName}, - "ou": {req.OrganizationEnName}, - "businessCategory": {req.BusinessCategory}, + "cn": {req.OrganizationName}, + "ou": {req.OrganizationName}, + "businessCategory": {req.OrganizationName}, "uniqueMember": {req.OwnerDN}, //必须有一个初始的成员 }) if err != nil { diff --git a/server/ldap-admin/internal/types/types.go b/server/ldap-admin/internal/types/types.go index 58a757e7..1c0d46f6 100644 --- a/server/ldap-admin/internal/types/types.go +++ b/server/ldap-admin/internal/types/types.go @@ -133,8 +133,7 @@ type MenuItem struct { } type CreateLdapOrganizationReq struct { - OrganizationEnName string `json:"organization_en_name"` //组织英文名 - BusinessCategory string `json:"business_category"` //组织类别名称 + OrganizationName string `json:"organization_name"` //组织名 ParentOrganizationDN string `json:"parent_organization_dn"` //父级dn OwnerDN string `json:"owner_dn"` //负责人dn } diff --git a/server_api/ldap-admin.api b/server_api/ldap-admin.api index c949371a..dd86aa6e 100644 --- a/server_api/ldap-admin.api +++ b/server_api/ldap-admin.api @@ -221,10 +221,9 @@ type MenuItem { } //增加ldap组织 type CreateLdapOrganizationReq { - OrganizationEnName string `json:"organization_en_name"` //组织英文名 - BusinessCategory string `json:"business_category"` //组织类别名称 - ParentOrganizationDN string `json:"parent_organization_dn"` //父级dn - OwnerDN string `json:"owner_dn"` //负责人dn + OrganizationName string `json:"organization_name"` //组织名 + ParentOrganizationDN string `json:"parent_organization_dn,optional"` //父级dn + OwnerDN string `json:"owner_dn,optional"` //负责人dn } //删除ldap组织 type DeleteLdapOrganizationReq { From 95b19c4522bb651b808a0ee5953e3b17b7a0d46f Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Fri, 24 Nov 2023 12:24:40 +0800 Subject: [PATCH 06/12] fix --- .../internal/logic/createldaporganizationlogic.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/server/ldap-admin/internal/logic/createldaporganizationlogic.go b/server/ldap-admin/internal/logic/createldaporganizationlogic.go index b576111c..28569849 100644 --- a/server/ldap-admin/internal/logic/createldaporganizationlogic.go +++ b/server/ldap-admin/internal/logic/createldaporganizationlogic.go @@ -2,6 +2,7 @@ package logic import ( "fusenapi/utils/basic" + "fusenapi/utils/chinese_to_pinyin" "fusenapi/utils/email" "net/http" "strings" @@ -52,13 +53,14 @@ func (l *CreateLdapOrganizationLogic) CreateLdapOrganization(req *types.CreateLd if !email.IsEmailValid(cnEmail) { return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "错误的用户cn") } + organizationNamePinyin := chinese_to_pinyin.ChineseToPinyin(req.OrganizationName) //组装organization dn organizationDN := "ou=" + req.OrganizationName + "," + req.ParentOrganizationDN err := l.svcCtx.Ldap.Create(organizationDN, map[string][]string{ "objectClass": {"top", "groupOfUniqueNames"}, "owner": {req.OwnerDN}, //负责人DN - "cn": {req.OrganizationName}, - "ou": {req.OrganizationName}, + "cn": {organizationNamePinyin}, + "ou": {organizationNamePinyin}, "businessCategory": {req.OrganizationName}, "uniqueMember": {req.OwnerDN}, //必须有一个初始的成员 }) From c9d0ab7e9a41424295e45d5144db53029c3951e6 Mon Sep 17 00:00:00 2001 From: eson <9673575+githubcontent@user.noreply.gitee.com> Date: Fri, 24 Nov 2023 12:29:25 +0800 Subject: [PATCH 07/12] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- model/gmodel/fs_user_info_logic.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/model/gmodel/fs_user_info_logic.go b/model/gmodel/fs_user_info_logic.go index f2667011..39bff739 100644 --- a/model/gmodel/fs_user_info_logic.go +++ b/model/gmodel/fs_user_info_logic.go @@ -8,6 +8,7 @@ import ( "fmt" "fusenapi/utils/fssql" "fusenapi/utils/handlers" + "log" "github.com/tidwall/gjson" "gorm.io/gorm" @@ -115,7 +116,9 @@ func (m *FsUserInfoModel) GetProfile(ctx context.Context, pkey string, userId in } if logoSelected := gjson.Get(v, "logo_selected"); logoSelected.Exists() { + log.Println(logoSelected) if ver := logoSelected.Get("version"); ver.Exists() && ver.String() == versionML { + log.Println(ver) return info, nil } } From de89d8442cf2de51a778e0bbc6d29defd3711836 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Fri, 24 Nov 2023 12:31:13 +0800 Subject: [PATCH 08/12] fix --- .../logic/getldaporganizationslogic.go | 30 +++++++++---------- .../logic/updateldaporganizationlogic.go | 2 +- server/ldap-admin/internal/types/types.go | 8 ++--- server_api/ldap-admin.api | 4 +-- 4 files changed, 22 insertions(+), 22 deletions(-) diff --git a/server/ldap-admin/internal/logic/getldaporganizationslogic.go b/server/ldap-admin/internal/logic/getldaporganizationslogic.go index 3b00a804..2fc516b7 100644 --- a/server/ldap-admin/internal/logic/getldaporganizationslogic.go +++ b/server/ldap-admin/internal/logic/getldaporganizationslogic.go @@ -34,15 +34,15 @@ func NewGetLdapOrganizationsLogic(ctx context.Context, svcCtx *svc.ServiceContex // func (l *GetLdapOrganizationsLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) { // } type DNItem struct { - MemberCount int `json:"member_count"` - BusinessCategory string `json:"business_category"` - OwnerName string `json:"owner_name"` - OwnerDN string `json:"owner_dn"` - Level int `json:"level"` - DepartmentDN string `json:"department_dn"` - DepartmentParentDN string `json:"department_parent_dn"` - Sort int `json:"sort"` - Child []*DNItem `json:"child"` + MemberCount int `json:"member_count"` + OrganizationName string `json:"organization_name"` + OwnerName string `json:"owner_name"` + OwnerDN string `json:"owner_dn"` + Level int `json:"level"` + OrganizationDN string `json:"organization_dn"` + ParentOrganizationDN string `json:"parent_organization_dn"` + Sort int `json:"sort"` + Child []*DNItem `json:"child"` } func (l *GetLdapOrganizationsLogic) GetLdapOrganizations(req *types.Request, r *http.Request) (resp *basic.Response) { @@ -72,8 +72,8 @@ func (l *GetLdapOrganizationsLogic) GetLdapOrganizations(req *types.Request, r * ownerDN := "" for _, v := range searchResult.Entries { sortNum++ - memberCount := 0 //成员数 - businessCategory := "" //部门名称 + memberCount := 0 //成员数 + departmentName := "" //部门名称 for _, attr := range v.Attributes { switch attr.Name { case "uniqueMember": @@ -87,14 +87,14 @@ func (l *GetLdapOrganizationsLogic) GetLdapOrganizations(req *types.Request, r * userCn := strings.Split(attr.Values[0], ",")[0] ownerFilterBuilder.WriteString(fmt.Sprintf("(%s)", userCn)) case "businessCategory": - businessCategory = strings.Join(attr.Values, ",") + departmentName = strings.Join(attr.Values, ",") } } dnSlice := strings.ReplaceAll(v.DN, ","+l.svcCtx.Config.Ldap.BaseDN, "") //把最顶级的组织去掉 level := len(strings.Split(dnSlice, ",")) data := &DNItem{ - DepartmentDN: v.DN, - BusinessCategory: businessCategory, + OrganizationDN: v.DN, + OrganizationName: departmentName, Level: level, MemberCount: memberCount, OwnerDN: ownerDN, @@ -136,7 +136,7 @@ func (l *GetLdapOrganizationsLogic) GetLdapOrganizations(req *types.Request, r * //有父级 parentDN := strings.Join(sl[1:], ",") if parent, ok := mapDN[parentDN]; ok { - v.DepartmentParentDN = parentDN + v.ParentOrganizationDN = parentDN parent.Child = append(parent.Child, v) //排序 sort.Slice(parent.Child, func(i, j int) bool { diff --git a/server/ldap-admin/internal/logic/updateldaporganizationlogic.go b/server/ldap-admin/internal/logic/updateldaporganizationlogic.go index 623940b2..1ed13404 100644 --- a/server/ldap-admin/internal/logic/updateldaporganizationlogic.go +++ b/server/ldap-admin/internal/logic/updateldaporganizationlogic.go @@ -44,7 +44,7 @@ func (l *UpdateLdapOrganizationLogic) UpdateLdapOrganization(req *types.UpdateLd return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "参数错误,无效的组织DN") } if err := l.svcCtx.Ldap.Update(req.OrganizationDN, map[string][]string{ - "businessCategory": {req.BusinessCategory}, + "businessCategory": {req.OrganizationName}, }); err != nil { logx.Error(err) return resp.SetStatusWithMessage(basic.CodeServiceErr, "更新ldap组织失败,"+err.Error()) diff --git a/server/ldap-admin/internal/types/types.go b/server/ldap-admin/internal/types/types.go index 1c0d46f6..d26328de 100644 --- a/server/ldap-admin/internal/types/types.go +++ b/server/ldap-admin/internal/types/types.go @@ -133,9 +133,9 @@ type MenuItem struct { } type CreateLdapOrganizationReq struct { - OrganizationName string `json:"organization_name"` //组织名 - ParentOrganizationDN string `json:"parent_organization_dn"` //父级dn - OwnerDN string `json:"owner_dn"` //负责人dn + OrganizationName string `json:"organization_name"` //组织名 + ParentOrganizationDN string `json:"parent_organization_dn,optional"` //父级dn + OwnerDN string `json:"owner_dn,optional"` //负责人dn } type DeleteLdapOrganizationReq struct { @@ -144,7 +144,7 @@ type DeleteLdapOrganizationReq struct { type UpdateLdapOrganizationReq struct { OrganizationDN string `json:"organization_dn"` //组织dn - BusinessCategory string `json:"business_category"` //组织分类名称 + OrganizationName string `json:"organization_name"` //组织分类名称 } type CreateLdapUserReq struct { diff --git a/server_api/ldap-admin.api b/server_api/ldap-admin.api index dd86aa6e..152a1828 100644 --- a/server_api/ldap-admin.api +++ b/server_api/ldap-admin.api @@ -221,7 +221,7 @@ type MenuItem { } //增加ldap组织 type CreateLdapOrganizationReq { - OrganizationName string `json:"organization_name"` //组织名 + OrganizationName string `json:"organization_name"` //组织名 ParentOrganizationDN string `json:"parent_organization_dn,optional"` //父级dn OwnerDN string `json:"owner_dn,optional"` //负责人dn } @@ -232,7 +232,7 @@ type DeleteLdapOrganizationReq { //修改ldap组织 type UpdateLdapOrganizationReq { OrganizationDN string `json:"organization_dn"` //组织dn - BusinessCategory string `json:"business_category"` //组织分类名称 + OrganizationName string `json:"organization_name"` //组织分类名称 } //添加ldap用户帐号 type CreateLdapUserReq { From b9c611f23512af453845dda696020fbf38af3e75 Mon Sep 17 00:00:00 2001 From: eson <9673575+githubcontent@user.noreply.gitee.com> Date: Fri, 24 Nov 2023 13:07:55 +0800 Subject: [PATCH 09/12] fix --- model/gmodel/fs_user_info_logic.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/model/gmodel/fs_user_info_logic.go b/model/gmodel/fs_user_info_logic.go index 39bff739..37fa47a1 100644 --- a/model/gmodel/fs_user_info_logic.go +++ b/model/gmodel/fs_user_info_logic.go @@ -115,8 +115,9 @@ func (m *FsUserInfoModel) GetProfile(ctx context.Context, pkey string, userId in return m.getDefaultProfile(ctx, tname) } + log.Println(userId, guestId, v) if logoSelected := gjson.Get(v, "logo_selected"); logoSelected.Exists() { - log.Println(logoSelected) + log.Println(userId, guestId, logoSelected) if ver := logoSelected.Get("version"); ver.Exists() && ver.String() == versionML { log.Println(ver) return info, nil From eb06aca1ae4399a7eaf74a20aa7179b866a7e15d Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Fri, 24 Nov 2023 13:11:45 +0800 Subject: [PATCH 10/12] fix --- server/ldap-admin/internal/logic/createldaporganizationlogic.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/ldap-admin/internal/logic/createldaporganizationlogic.go b/server/ldap-admin/internal/logic/createldaporganizationlogic.go index 28569849..6d0d86ad 100644 --- a/server/ldap-admin/internal/logic/createldaporganizationlogic.go +++ b/server/ldap-admin/internal/logic/createldaporganizationlogic.go @@ -55,7 +55,7 @@ func (l *CreateLdapOrganizationLogic) CreateLdapOrganization(req *types.CreateLd } organizationNamePinyin := chinese_to_pinyin.ChineseToPinyin(req.OrganizationName) //组装organization dn - organizationDN := "ou=" + req.OrganizationName + "," + req.ParentOrganizationDN + organizationDN := "ou=" + organizationNamePinyin + "," + req.ParentOrganizationDN err := l.svcCtx.Ldap.Create(organizationDN, map[string][]string{ "objectClass": {"top", "groupOfUniqueNames"}, "owner": {req.OwnerDN}, //负责人DN From 747adc64ca45ba92e473d16a7af18318f104b3c5 Mon Sep 17 00:00:00 2001 From: eson <9673575+githubcontent@user.noreply.gitee.com> Date: Fri, 24 Nov 2023 13:15:26 +0800 Subject: [PATCH 11/12] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- model/gmodel/a_test.go | 23 +++++++++++++++++++++++ model/gmodel/fs_user_info_logic.go | 4 +--- 2 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 model/gmodel/a_test.go diff --git a/model/gmodel/a_test.go b/model/gmodel/a_test.go new file mode 100644 index 00000000..def666f6 --- /dev/null +++ b/model/gmodel/a_test.go @@ -0,0 +1,23 @@ +package gmodel + +import ( + "log" + "testing" + + "github.com/tidwall/gjson" +) + +func TestCase1(t *testing.T) { + v := `{"base": {"mobile": "18588505404", "company": "fusen", "last_name": "sm", "first_name": "h", "resetaurant": "boy"}, "sub_status": {"notification_email": {"newseleter": false, "order_update": false}, "notification_phone": {"newseleter": true, "order_update": false}}, "logo_selected": {"logo_url": "https://fusenstorage.s3.us-east-2.amazonaws.com/d163cba052dc03e7684a4fa8574a17c629e08b6cd0f47f9c239866949365f807", "logo_selected_id": 5018, "merchant_category": 10, "template_tag_selected": {"color": [["#25211F"], ["#1E1916"]], "version": "2", "template_tag": "C6", "selected_index": 0}}}` + + // log.Println(userId, guestId, v) + if logoSelected := gjson.Get(v, "logo_selected"); logoSelected.Exists() { + log.Println(logoSelected) + log.Println(logoSelected.Get("version")) + if ver := logoSelected.Get("version"); ver.Exists() && ver.String() == versionML { + log.Println(ver) + } + } + + // gjson.Get(content, "logo_selected") +} diff --git a/model/gmodel/fs_user_info_logic.go b/model/gmodel/fs_user_info_logic.go index 37fa47a1..bb4eeaed 100644 --- a/model/gmodel/fs_user_info_logic.go +++ b/model/gmodel/fs_user_info_logic.go @@ -115,10 +115,8 @@ func (m *FsUserInfoModel) GetProfile(ctx context.Context, pkey string, userId in return m.getDefaultProfile(ctx, tname) } - log.Println(userId, guestId, v) if logoSelected := gjson.Get(v, "logo_selected"); logoSelected.Exists() { - log.Println(userId, guestId, logoSelected) - if ver := logoSelected.Get("version"); ver.Exists() && ver.String() == versionML { + if ver := logoSelected.Get("template_tag_selected.version"); ver.Exists() && ver.String() == versionML { log.Println(ver) return info, nil } From eebdc0f384d6da159194be4912dfa893942bc1ff Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Fri, 24 Nov 2023 14:11:06 +0800 Subject: [PATCH 12/12] fix --- server/ldap-admin/internal/logic/getldapuserslogic.go | 7 ++++++- server/ldap-admin/internal/types/types.go | 1 + server_api/ldap-admin.api | 1 + utils/ldap_lib/ldap_user.go | 4 ++-- 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/server/ldap-admin/internal/logic/getldapuserslogic.go b/server/ldap-admin/internal/logic/getldapuserslogic.go index 195f98d3..ebf1f3e1 100644 --- a/server/ldap-admin/internal/logic/getldapuserslogic.go +++ b/server/ldap-admin/internal/logic/getldapuserslogic.go @@ -38,7 +38,12 @@ func (l *GetLdapUsersLogic) GetLdapUsers(req *types.GetLdapUsersReq, r *http.Req } req.PageCookie = strings.Trim(req.PageCookie, " ") pageSize := uint32(20) - list, cookie, err := l.svcCtx.Ldap.GetLdapBaseTeamUserList(pageSize, req.PageCookie) + filter := "(objectClass=person)" + //有关键词就模糊搜索 + if req.UserName != "" { + filter = "(&(objectClass=person)(sn=*" + req.UserName + "*))" + } + list, cookie, err := l.svcCtx.Ldap.GetLdapBaseTeamUserList(pageSize, filter, req.PageCookie) if err != nil { logx.Error(err) return resp.SetStatusWithMessage(basic.CodeServiceErr, "查询用户列表报错,"+err.Error()) diff --git a/server/ldap-admin/internal/types/types.go b/server/ldap-admin/internal/types/types.go index d26328de..deffe809 100644 --- a/server/ldap-admin/internal/types/types.go +++ b/server/ldap-admin/internal/types/types.go @@ -224,6 +224,7 @@ type GetLdapOrganizationMembersItem struct { type GetLdapUsersReq struct { PageCookie string `form:"page_cookie,optional"` //下一页分页游标,传空/不传就是第一页 + UserName string `form:"user_name,optional"` //用户名用于模糊搜索 } type GetLdapUsersRsp struct { diff --git a/server_api/ldap-admin.api b/server_api/ldap-admin.api index 152a1828..82eace84 100644 --- a/server_api/ldap-admin.api +++ b/server_api/ldap-admin.api @@ -309,6 +309,7 @@ type GetLdapOrganizationMembersItem { //获取基础用户组中成员列表 type GetLdapUsersReq { PageCookie string `form:"page_cookie,optional"` //下一页分页游标,传空/不传就是第一页 + UserName string `form:"user_name,optional"` //用户名用于模糊搜索 } type GetLdapUsersRsp { List []GetLdapUsersItem `json:"list"` diff --git a/utils/ldap_lib/ldap_user.go b/utils/ldap_lib/ldap_user.go index 3e61fe90..a245d8f7 100644 --- a/utils/ldap_lib/ldap_user.go +++ b/utils/ldap_lib/ldap_user.go @@ -84,12 +84,12 @@ func (l *Ldap) GetLdapUserInfo(userDN string) (*LdapUserInfo, error) { } // 获取基础组用户列表 -func (l *Ldap) GetLdapBaseTeamUserList(pageSize uint32, pageCookie string) ([]LdapUserInfo, string, error) { +func (l *Ldap) GetLdapBaseTeamUserList(pageSize uint32, filter, pageCookie string) ([]LdapUserInfo, string, error) { pageCookieBytes, err := hex.DecodeString(pageCookie) if err != nil { return nil, "", err } - result, err := l.SearchWithPaging(l.peopleGroupDN, ldap.ScopeWholeSubtree, "(objectClass=person)", nil, pageSize, string(pageCookieBytes)) + result, err := l.SearchWithPaging(l.peopleGroupDN, ldap.ScopeWholeSubtree, filter, nil, pageSize, string(pageCookieBytes)) if err != nil { return nil, "", err }