后台权限组详情/授权菜单接口等等
This commit is contained in:
parent
62e0c55939
commit
6ed88bb607
|
@ -45,7 +45,7 @@ func (l *GetLdapGroupDetailLogic) GetLdapGroupDetail(req *types.GetLdapGroupDeta
|
|||
}
|
||||
return resp.SetStatus(basic.CodeServiceErr)
|
||||
}
|
||||
var metadata []GroupAuth
|
||||
var metadata []types.GroupAuth
|
||||
if resOne.Metadata != nil {
|
||||
err := json.Unmarshal(*resOne.Metadata, &metadata)
|
||||
if err != nil {
|
||||
|
@ -64,13 +64,6 @@ func (l *GetLdapGroupDetailLogic) GetLdapGroupDetail(req *types.GetLdapGroupDeta
|
|||
})
|
||||
}
|
||||
|
||||
type GroupAuth struct {
|
||||
Id int64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Type string `json:"type"`
|
||||
Metadata *GroupAuth `json:"metadata"`
|
||||
}
|
||||
|
||||
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理
|
||||
// func (l *GetLdapGroupDetailLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
|
||||
// // httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
|
|
|
@ -5,10 +5,11 @@ import (
|
|||
"fusenapi/model/gmodel"
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
"gorm.io/gorm"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"gorm.io/gorm"
|
||||
|
||||
"context"
|
||||
|
||||
"fusenapi/server/ldap-admin/internal/svc"
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package logic
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
|
||||
|
@ -10,6 +12,7 @@ import (
|
|||
"fusenapi/server/ldap-admin/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type SetLdapGroupAuthLogic struct {
|
||||
|
@ -33,7 +36,51 @@ func NewSetLdapGroupAuthLogic(ctx context.Context, svcCtx *svc.ServiceContext) *
|
|||
func (l *SetLdapGroupAuthLogic) SetLdapGroupAuth(req *types.SetLdapGroupAuthReq, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
|
||||
// userinfo 传入值时, 一定不为null
|
||||
resOne, err := l.svcCtx.AllModels.LdapGroup.FindOneById(l.ctx, req.GroupId)
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
basic.CodeServiceErr.Message = "记录不存在"
|
||||
} else {
|
||||
basic.CodeServiceErr.Message = "系统出错"
|
||||
}
|
||||
return resp.SetStatus(basic.CodeServiceErr)
|
||||
}
|
||||
|
||||
var metadata []types.GroupAuth
|
||||
if resOne.Metadata != nil {
|
||||
err := json.Unmarshal(*resOne.Metadata, &metadata)
|
||||
if err != nil {
|
||||
basic.CodeServiceErr.Message = "系统出错"
|
||||
return resp.SetStatus(basic.CodeServiceErr)
|
||||
}
|
||||
}
|
||||
var groupAuth = types.GroupAuth{
|
||||
Id: req.GroupAuth.Id,
|
||||
Type: req.GroupAuth.Type,
|
||||
Name: req.GroupAuth.Name,
|
||||
Metadata: req.GroupAuth.Metadata,
|
||||
}
|
||||
var status = 0
|
||||
if len(metadata) > 0 {
|
||||
for k, v := range metadata {
|
||||
if v.Type == groupAuth.Type && v.Id == groupAuth.Id {
|
||||
status = 1
|
||||
metadata[k] = groupAuth
|
||||
}
|
||||
}
|
||||
}
|
||||
if status == 0 {
|
||||
metadata = append(metadata, groupAuth)
|
||||
}
|
||||
// 更新metadata
|
||||
metadataByte, _ := json.Marshal(metadata)
|
||||
err = l.svcCtx.AllModels.LdapGroup.UpdateOne(l.ctx, resOne, map[string]interface{}{
|
||||
"metadata": string(metadataByte),
|
||||
})
|
||||
if err != nil {
|
||||
basic.CodeServiceErr.Message = "系统出错"
|
||||
return resp.SetStatus(basic.CodeServiceErr)
|
||||
}
|
||||
return resp.SetStatus(basic.CodeOK)
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ import (
|
|||
)
|
||||
|
||||
type GetLdapGroupDetailReq struct {
|
||||
Id int64 `json:"id"`
|
||||
Id int64 `form:"id"`
|
||||
}
|
||||
|
||||
type SetLdapGroupAuthReq struct {
|
||||
|
@ -15,10 +15,10 @@ type SetLdapGroupAuthReq struct {
|
|||
}
|
||||
|
||||
type GroupAuth struct {
|
||||
Id int64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Type string `json:"type"`
|
||||
Metadata string `json:"metadata,optional"`
|
||||
Id int64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Type string `json:"type"`
|
||||
Metadata []*GroupAuth `json:"metadata,optional"`
|
||||
}
|
||||
|
||||
type GetLdapGroupsReq struct {
|
||||
|
|
|
@ -101,7 +101,7 @@ service ldap-admin {
|
|||
|
||||
type (
|
||||
GetLdapGroupDetailReq {
|
||||
Id int64 `json:"id"`
|
||||
Id int64 `form:"id"`
|
||||
}
|
||||
|
||||
SetLdapGroupAuthReq {
|
||||
|
@ -109,10 +109,10 @@ type (
|
|||
GroupAuth GroupAuth `json:"group_auth"`
|
||||
}
|
||||
GroupAuth {
|
||||
Id int64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Type string `json:"type"`
|
||||
Metadata string `json:"metadata,optional"`
|
||||
Id int64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Type string `json:"type"`
|
||||
Metadata []*GroupAuth `json:"metadata,optional"`
|
||||
}
|
||||
|
||||
GetLdapGroupsReq {
|
||||
|
|
Loading…
Reference in New Issue
Block a user