fix
This commit is contained in:
parent
ceece7c8f6
commit
5b7aa513a2
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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),
|
||||
},
|
||||
},
|
||||
)
|
||||
}
|
||||
|
|
|
@ -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, "添加成功")
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
// }
|
|
@ -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, "添加用户成功")
|
||||
}
|
||||
|
|
|
@ -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, "删除成功")
|
||||
}
|
||||
|
|
|
@ -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, "删除用户成功")
|
||||
}
|
||||
|
|
|
@ -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 必须重新处理
|
||||
|
|
|
@ -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, "移除成员成功")
|
||||
}
|
||||
|
|
|
@ -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, "更新成功")
|
||||
}
|
||||
|
|
|
@ -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, "更新用户成功")
|
||||
}
|
||||
|
|
|
@ -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 (
|
||||
|
|
Loading…
Reference in New Issue
Block a user