后台权限组详情/授权菜单接口等等

This commit is contained in:
momo 2023-11-22 10:56:25 +08:00
parent 62e0c55939
commit 6ed88bb607
5 changed files with 60 additions and 19 deletions

View File

@ -45,7 +45,7 @@ func (l *GetLdapGroupDetailLogic) GetLdapGroupDetail(req *types.GetLdapGroupDeta
} }
return resp.SetStatus(basic.CodeServiceErr) return resp.SetStatus(basic.CodeServiceErr)
} }
var metadata []GroupAuth var metadata []types.GroupAuth
if resOne.Metadata != nil { if resOne.Metadata != nil {
err := json.Unmarshal(*resOne.Metadata, &metadata) err := json.Unmarshal(*resOne.Metadata, &metadata)
if err != nil { 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 必须重新处理 // 处理逻辑后 w,r 如:重定向, resp 必须重新处理
// func (l *GetLdapGroupDetailLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) { // func (l *GetLdapGroupDetailLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
// // httpx.OkJsonCtx(r.Context(), w, resp) // // httpx.OkJsonCtx(r.Context(), w, resp)

View File

@ -5,10 +5,11 @@ import (
"fusenapi/model/gmodel" "fusenapi/model/gmodel"
"fusenapi/utils/auth" "fusenapi/utils/auth"
"fusenapi/utils/basic" "fusenapi/utils/basic"
"gorm.io/gorm"
"strings" "strings"
"time" "time"
"gorm.io/gorm"
"context" "context"
"fusenapi/server/ldap-admin/internal/svc" "fusenapi/server/ldap-admin/internal/svc"

View File

@ -1,6 +1,8 @@
package logic package logic
import ( import (
"encoding/json"
"errors"
"fusenapi/utils/auth" "fusenapi/utils/auth"
"fusenapi/utils/basic" "fusenapi/utils/basic"
@ -10,6 +12,7 @@ import (
"fusenapi/server/ldap-admin/internal/types" "fusenapi/server/ldap-admin/internal/types"
"github.com/zeromicro/go-zero/core/logx" "github.com/zeromicro/go-zero/core/logx"
"gorm.io/gorm"
) )
type SetLdapGroupAuthLogic struct { 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) { func (l *SetLdapGroupAuthLogic) SetLdapGroupAuth(req *types.SetLdapGroupAuthReq, userinfo *auth.UserInfo) (resp *basic.Response) {
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data) // 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
// userinfo 传入值时, 一定不为null // 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) return resp.SetStatus(basic.CodeOK)
} }

View File

@ -6,7 +6,7 @@ import (
) )
type GetLdapGroupDetailReq struct { type GetLdapGroupDetailReq struct {
Id int64 `json:"id"` Id int64 `form:"id"`
} }
type SetLdapGroupAuthReq struct { type SetLdapGroupAuthReq struct {
@ -15,10 +15,10 @@ type SetLdapGroupAuthReq struct {
} }
type GroupAuth struct { type GroupAuth struct {
Id int64 `json:"id"` Id int64 `json:"id"`
Name string `json:"name"` Name string `json:"name"`
Type string `json:"type"` Type string `json:"type"`
Metadata string `json:"metadata,optional"` Metadata []*GroupAuth `json:"metadata,optional"`
} }
type GetLdapGroupsReq struct { type GetLdapGroupsReq struct {

View File

@ -101,7 +101,7 @@ service ldap-admin {
type ( type (
GetLdapGroupDetailReq { GetLdapGroupDetailReq {
Id int64 `json:"id"` Id int64 `form:"id"`
} }
SetLdapGroupAuthReq { SetLdapGroupAuthReq {
@ -109,10 +109,10 @@ type (
GroupAuth GroupAuth `json:"group_auth"` GroupAuth GroupAuth `json:"group_auth"`
} }
GroupAuth { GroupAuth {
Id int64 `json:"id"` Id int64 `json:"id"`
Name string `json:"name"` Name string `json:"name"`
Type string `json:"type"` Type string `json:"type"`
Metadata string `json:"metadata,optional"` Metadata []*GroupAuth `json:"metadata,optional"`
} }
GetLdapGroupsReq { GetLdapGroupsReq {