From 5b7aa513a2fbc3a0574a08dbff81eead0eff3fe6 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Fri, 17 Nov 2023 16:02:35 +0800 Subject: [PATCH] fix --- .../handler/createldapuserbasegrouphandler.go | 35 +++++++++++++ server/ldap-admin/internal/handler/routes.go | 5 ++ .../logic/addldaporganizationmemberlogic.go | 2 +- .../logic/createldaporganizationlogic.go | 2 +- .../logic/createldapuserbasegrouplogic.go | 51 +++++++++++++++++++ .../internal/logic/createldapuserlogic.go | 2 +- .../logic/deleteldaporganizationlogic.go | 2 +- .../internal/logic/deleteldapuserlogic.go | 2 +- .../logic/getldaporganizationslogic.go | 2 +- .../removeldaporganizationmemberlogic.go | 2 +- .../logic/updateldaporganizationlogic.go | 2 +- .../internal/logic/updateldapuserlogic.go | 2 +- server_api/ldap-admin.api | 3 ++ 13 files changed, 103 insertions(+), 9 deletions(-) create mode 100644 server/ldap-admin/internal/handler/createldapuserbasegrouphandler.go create mode 100644 server/ldap-admin/internal/logic/createldapuserbasegrouplogic.go diff --git a/server/ldap-admin/internal/handler/createldapuserbasegrouphandler.go b/server/ldap-admin/internal/handler/createldapuserbasegrouphandler.go new file mode 100644 index 00000000..ac573e2f --- /dev/null +++ b/server/ldap-admin/internal/handler/createldapuserbasegrouphandler.go @@ -0,0 +1,35 @@ +package handler + +import ( + "net/http" + "reflect" + + "fusenapi/utils/basic" + + "fusenapi/server/ldap-admin/internal/logic" + "fusenapi/server/ldap-admin/internal/svc" + "fusenapi/server/ldap-admin/internal/types" +) + +func CreateLdapUserBaseGroupHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + + var req types.Request + userinfo, err := basic.RequestParse(w, r, svcCtx, &req) + if err != nil { + return + } + + // 创建一个业务逻辑层实例 + l := logic.NewCreateLdapUserBaseGroupLogic(r.Context(), svcCtx) + + rl := reflect.ValueOf(l) + basic.BeforeLogic(w, r, rl) + + resp := l.CreateLdapUserBaseGroup(&req, userinfo) + + if !basic.AfterLogic(w, r, rl, resp) { + basic.NormalAfterLogic(w, r, resp) + } + } +} diff --git a/server/ldap-admin/internal/handler/routes.go b/server/ldap-admin/internal/handler/routes.go index 3e124f42..4f13691d 100644 --- a/server/ldap-admin/internal/handler/routes.go +++ b/server/ldap-admin/internal/handler/routes.go @@ -127,6 +127,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { Path: "/api/ldap-admin/get_ldap_organization_members", Handler: GetLdapOrganizationMembersHandler(serverCtx), }, + { + Method: http.MethodPost, + Path: "/api/ldap-admin/create_ldap_user_base_group", + Handler: CreateLdapUserBaseGroupHandler(serverCtx), + }, }, ) } diff --git a/server/ldap-admin/internal/logic/addldaporganizationmemberlogic.go b/server/ldap-admin/internal/logic/addldaporganizationmemberlogic.go index 52acdaad..fd293f89 100644 --- a/server/ldap-admin/internal/logic/addldaporganizationmemberlogic.go +++ b/server/ldap-admin/internal/logic/addldaporganizationmemberlogic.go @@ -45,7 +45,7 @@ func (l *AddLdapOrganizationMemberLogic) AddLdapOrganizationMember(req *types.Ad err := ldapServer.AddUserToOrganization(req.OrganizationDN, req.UserDN) if err != nil { logx.Error(err) - return resp.SetStatusWithMessage(basic.CodeServiceErr, "添加成员失败,", err.Error()) + return resp.SetStatusWithMessage(basic.CodeServiceErr, "添加成员失败,"+err.Error()) } return resp.SetStatusWithMessage(basic.CodeOK, "添加成功") } diff --git a/server/ldap-admin/internal/logic/createldaporganizationlogic.go b/server/ldap-admin/internal/logic/createldaporganizationlogic.go index d1046fcf..6c8850e9 100644 --- a/server/ldap-admin/internal/logic/createldaporganizationlogic.go +++ b/server/ldap-admin/internal/logic/createldaporganizationlogic.go @@ -62,7 +62,7 @@ func (l *CreateLdapOrganizationLogic) CreateLdapOrganization(req *types.CreateLd }) if err != nil { logx.Error(err) - return resp.SetStatusWithMessage(basic.CodeServiceErr, "ldap服务报错,", err.Error()) + return resp.SetStatusWithMessage(basic.CodeServiceErr, "创建组织失败,"+err.Error()) } return resp.SetStatus(basic.CodeOK) } diff --git a/server/ldap-admin/internal/logic/createldapuserbasegrouplogic.go b/server/ldap-admin/internal/logic/createldapuserbasegrouplogic.go new file mode 100644 index 00000000..90f80fa1 --- /dev/null +++ b/server/ldap-admin/internal/logic/createldapuserbasegrouplogic.go @@ -0,0 +1,51 @@ +package logic + +import ( + "fusenapi/utils/auth" + "fusenapi/utils/basic" + "fusenapi/utils/ldap_lib" + + "context" + + "fusenapi/server/ldap-admin/internal/svc" + "fusenapi/server/ldap-admin/internal/types" + + "github.com/zeromicro/go-zero/core/logx" +) + +type CreateLdapUserBaseGroupLogic struct { + logx.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +func NewCreateLdapUserBaseGroupLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateLdapUserBaseGroupLogic { + return &CreateLdapUserBaseGroupLogic{ + Logger: logx.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +// 处理进入前逻辑w,r +// func (l *CreateLdapUserBaseGroupLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) { +// } + +func (l *CreateLdapUserBaseGroupLogic) CreateLdapUserBaseGroup(req *types.Request, userinfo *auth.UserInfo) (resp *basic.Response) { + ldapServer := ldap_lib.NewLdap(l.svcCtx.Ldap, l.svcCtx.Config.Ldap.BaseDN, l.svcCtx.Config.Ldap.RootDN) + err := ldapServer.Create(l.svcCtx.Config.Ldap.PeopleGroupDN, map[string][]string{ + "objectClass": {"top", "organizationalUnit"}, + "ou": {"FusenTeam"}, + "businessCategory": {"FUSEN团队"}, + }) + if err != nil { + logx.Error(err) + return resp.SetStatusWithMessage(basic.CodeServiceErr, "创建用户基础分组失败,"+err.Error()) + } + return resp.SetStatusWithMessage(basic.CodeServiceErr, "创建用户基础分组成功") +} + +// 处理逻辑后 w,r 如:重定向, resp 必须重新处理 +// func (l *CreateLdapUserBaseGroupLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) { +// // httpx.OkJsonCtx(r.Context(), w, resp) +// } diff --git a/server/ldap-admin/internal/logic/createldapuserlogic.go b/server/ldap-admin/internal/logic/createldapuserlogic.go index a3f03781..f7b4e851 100644 --- a/server/ldap-admin/internal/logic/createldapuserlogic.go +++ b/server/ldap-admin/internal/logic/createldapuserlogic.go @@ -81,7 +81,7 @@ func (l *CreateLdapUserLogic) CreateLdapUser(req *types.CreateLdapUserReq, useri "userPassword": {req.Password}, }); err != nil { logx.Error(err) - return resp.SetStatusWithMessage(basic.CodeServiceErr, "添加用户失败,", err.Error()) + return resp.SetStatusWithMessage(basic.CodeServiceErr, "添加用户失败,"+err.Error()) } return resp.SetStatusWithMessage(basic.CodeOK, "添加用户成功") } diff --git a/server/ldap-admin/internal/logic/deleteldaporganizationlogic.go b/server/ldap-admin/internal/logic/deleteldaporganizationlogic.go index 70f01295..87340301 100644 --- a/server/ldap-admin/internal/logic/deleteldaporganizationlogic.go +++ b/server/ldap-admin/internal/logic/deleteldaporganizationlogic.go @@ -40,7 +40,7 @@ func (l *DeleteLdapOrganizationLogic) DeleteLdapOrganization(req *types.DeleteLd ldapServer := ldap_lib.NewLdap(l.svcCtx.Ldap, l.svcCtx.Config.Ldap.BaseDN, l.svcCtx.Config.Ldap.RootDN) if err := ldapServer.Delete(req.OrganizationDN); err != nil { logx.Error(err) - return resp.SetStatusWithMessage(basic.CodeServiceErr, "删除ldap组织失败,", err.Error()) + return resp.SetStatusWithMessage(basic.CodeServiceErr, "删除ldap组织失败,"+err.Error()) } return resp.SetStatusWithMessage(basic.CodeOK, "删除成功") } diff --git a/server/ldap-admin/internal/logic/deleteldapuserlogic.go b/server/ldap-admin/internal/logic/deleteldapuserlogic.go index 0625cde9..3423182e 100644 --- a/server/ldap-admin/internal/logic/deleteldapuserlogic.go +++ b/server/ldap-admin/internal/logic/deleteldapuserlogic.go @@ -43,7 +43,7 @@ func (l *DeleteLdapUserLogic) DeleteLdapUser(req *types.DeleteLdapUserReq, useri }) if err != nil { logx.Error(err) - return resp.SetStatusWithMessage(basic.CodeServiceErr, "删除用户失败,", err.Error()) + return resp.SetStatusWithMessage(basic.CodeServiceErr, "删除用户失败,"+err.Error()) } return resp.SetStatusWithMessage(basic.CodeOK, "删除用户成功") } diff --git a/server/ldap-admin/internal/logic/getldaporganizationslogic.go b/server/ldap-admin/internal/logic/getldaporganizationslogic.go index f546bf48..d53385fa 100644 --- a/server/ldap-admin/internal/logic/getldaporganizationslogic.go +++ b/server/ldap-admin/internal/logic/getldaporganizationslogic.go @@ -114,7 +114,7 @@ func (l *GetLdapOrganizationsLogic) GetLdapOrganizations(req *types.Request, use list = append(list, v) } } - return resp.SetStatusWithMessage(basic.CodeOK, "", list) + return resp.SetStatusWithMessage(basic.CodeOK, "success", list) } // 处理逻辑后 w,r 如:重定向, resp 必须重新处理 diff --git a/server/ldap-admin/internal/logic/removeldaporganizationmemberlogic.go b/server/ldap-admin/internal/logic/removeldaporganizationmemberlogic.go index 3f300f3e..dee25ad8 100644 --- a/server/ldap-admin/internal/logic/removeldaporganizationmemberlogic.go +++ b/server/ldap-admin/internal/logic/removeldaporganizationmemberlogic.go @@ -45,7 +45,7 @@ func (l *RemoveLdapOrganizationMemberLogic) RemoveLdapOrganizationMember(req *ty err := ldapServer.RemoveUserFromOrganization(req.OrganizationDN, req.UserDN) if err != nil { logx.Error(err) - return resp.SetStatusWithMessage(basic.CodeServiceErr, "移除成员失败,", err.Error()) + return resp.SetStatusWithMessage(basic.CodeServiceErr, "移除成员失败,"+err.Error()) } return resp.SetStatusWithMessage(basic.CodeOK, "移除成员成功") } diff --git a/server/ldap-admin/internal/logic/updateldaporganizationlogic.go b/server/ldap-admin/internal/logic/updateldaporganizationlogic.go index e16bbae0..48c8c43a 100644 --- a/server/ldap-admin/internal/logic/updateldaporganizationlogic.go +++ b/server/ldap-admin/internal/logic/updateldaporganizationlogic.go @@ -46,7 +46,7 @@ func (l *UpdateLdapOrganizationLogic) UpdateLdapOrganization(req *types.UpdateLd "businessCategory": {req.BusinessCategory}, }); err != nil { logx.Error(err) - return resp.SetStatusWithMessage(basic.CodeServiceErr, "更新ldap组织失败,", err.Error()) + return resp.SetStatusWithMessage(basic.CodeServiceErr, "更新ldap组织失败,"+err.Error()) } return resp.SetStatusWithMessage(basic.CodeOK, "更新成功") } diff --git a/server/ldap-admin/internal/logic/updateldapuserlogic.go b/server/ldap-admin/internal/logic/updateldapuserlogic.go index ec2a5473..dee9cdf3 100644 --- a/server/ldap-admin/internal/logic/updateldapuserlogic.go +++ b/server/ldap-admin/internal/logic/updateldapuserlogic.go @@ -64,7 +64,7 @@ func (l *UpdateLdapUserLogic) UpdateLdapUser(req *types.UpdateLdapUserReq, useri }) if err != nil { logx.Error(err) - return resp.SetStatusWithMessage(basic.CodeServiceErr, "更新用户失败,", err.Error()) + return resp.SetStatusWithMessage(basic.CodeServiceErr, "更新用户失败,"+err.Error()) } return resp.SetStatusWithMessage(basic.CodeOK, "更新用户成功") } diff --git a/server_api/ldap-admin.api b/server_api/ldap-admin.api index ee89207a..b5712e91 100644 --- a/server_api/ldap-admin.api +++ b/server_api/ldap-admin.api @@ -79,6 +79,9 @@ service ldap-admin { //获取ldap组织成员列表 @handler GetLdapOrganizationMembersHandler get /api/ldap-admin/get_ldap_organization_members(GetLdapOrganizationMembersReq) returns (response); + //创建用户基础组 + @handler CreateLdapUserBaseGroupHandler + post /api/ldap-admin/create_ldap_user_base_group(request) returns (response); } type (