增加删除部门接口

This commit is contained in:
laodaming 2023-11-16 14:37:02 +08:00
parent 8ce1f61611
commit 67ef0ae547
2 changed files with 15 additions and 3 deletions

View File

@ -37,6 +37,9 @@ func (l *DeleteLdapOrginationLogic) DeleteLdapOrgination(req *types.DeleteLdapOr
if req.OrginationDN == "" {
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "组织DN不能为空")
}
if len(req.OrginationDN) <= 3 || req.OrginationDN[:3] != "ou=" {
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "无效的组织DN")
}
ldapServer := ldap_lib.NewLdap(l.svcCtx.Ldap, l.svcCtx.Config.Ldap.BaseDN, l.svcCtx.Config.Ldap.RootDN)
if err := ldapServer.Delete(req.OrginationDN); err != nil {
logx.Error(err)

View File

@ -3,6 +3,8 @@ package logic
import (
"fusenapi/utils/auth"
"fusenapi/utils/basic"
"fusenapi/utils/ldap_lib"
"strings"
"context"
@ -31,9 +33,16 @@ func NewUpdateLdapOrginationLogic(ctx context.Context, svcCtx *svc.ServiceContex
// }
func (l *UpdateLdapOrginationLogic) UpdateLdapOrgination(req *types.UpdateLdapOrginationReq, userinfo *auth.UserInfo) (resp *basic.Response) {
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
// userinfo 传入值时, 一定不为null
req.OrginationDN = strings.Trim(req.OrginationDN, " ")
if req.OrginationDN == "" {
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "组织DN不能为空")
}
ldapServer := ldap_lib.NewLdap(l.svcCtx.Ldap, l.svcCtx.Config.Ldap.BaseDN, l.svcCtx.Config.Ldap.RootDN)
if err := ldapServer.Delete(req.OrginationDN); err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeServiceErr, "删除ldap组织失败,", err.Error())
}
return resp.SetStatusWithMessage(basic.CodeOK, "删除成功")
return resp.SetStatus(basic.CodeOK)
}