后台授权模块调整
This commit is contained in:
parent
de05d258ef
commit
64f3547858
@ -8,6 +8,7 @@ import (
|
|||||||
// ldap_group 权限组表
|
// ldap_group 权限组表
|
||||||
type LdapGroup struct {
|
type LdapGroup struct {
|
||||||
Id int64 `gorm:"primary_key;default:0;auto_increment;" json:"id"` //
|
Id int64 `gorm:"primary_key;default:0;auto_increment;" json:"id"` //
|
||||||
|
Type *string `gorm:"default:'';" json:"type"` //
|
||||||
Name *string `gorm:"default:'';" json:"name"` //
|
Name *string `gorm:"default:'';" json:"name"` //
|
||||||
Keyword *string `gorm:"default:'';" json:"keyword"` //
|
Keyword *string `gorm:"default:'';" json:"keyword"` //
|
||||||
Remark *string `gorm:"default:'';" json:"remark"` //
|
Remark *string `gorm:"default:'';" json:"remark"` //
|
||||||
@ -16,7 +17,6 @@ type LdapGroup struct {
|
|||||||
Metadata *[]byte `gorm:"default:'';" json:"metadata"` //
|
Metadata *[]byte `gorm:"default:'';" json:"metadata"` //
|
||||||
Ctime *time.Time `gorm:"default:'0000-00-00 00:00:00';" json:"ctime"` //
|
Ctime *time.Time `gorm:"default:'0000-00-00 00:00:00';" json:"ctime"` //
|
||||||
Utime *time.Time `gorm:"default:'0000-00-00 00:00:00';" json:"utime"` //
|
Utime *time.Time `gorm:"default:'0000-00-00 00:00:00';" json:"utime"` //
|
||||||
Type *string `gorm:"default:'';" json:"type"` // 类型:people=个人
|
|
||||||
}
|
}
|
||||||
type LdapGroupModel struct {
|
type LdapGroupModel struct {
|
||||||
db *gorm.DB
|
db *gorm.DB
|
||||||
|
@ -1,19 +0,0 @@
|
|||||||
package gmodel
|
|
||||||
|
|
||||||
import (
|
|
||||||
"gorm.io/gorm"
|
|
||||||
)
|
|
||||||
|
|
||||||
// ldap_user_group 用户权限分组表
|
|
||||||
type LdapUserGroup struct {
|
|
||||||
GroupId *int64 `gorm:"default:0;" json:"group_id"` //
|
|
||||||
UserId *int64 `gorm:"default:0;" json:"user_id"` //
|
|
||||||
}
|
|
||||||
type LdapUserGroupModel struct {
|
|
||||||
db *gorm.DB
|
|
||||||
name string
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewLdapUserGroupModel(db *gorm.DB) *LdapUserGroupModel {
|
|
||||||
return &LdapUserGroupModel{db: db, name: "ldap_user_group"}
|
|
||||||
}
|
|
@ -1,2 +0,0 @@
|
|||||||
package gmodel
|
|
||||||
// TODO: 使用model的属性做你想做的
|
|
@ -10,6 +10,10 @@ func (u *LdapUserModel) Update(ctx context.Context, userDN string, data *LdapUse
|
|||||||
return u.db.WithContext(ctx).Model(&LdapUser{}).Where("user_dn = ?", userDN).Updates(&data).Error
|
return u.db.WithContext(ctx).Model(&LdapUser{}).Where("user_dn = ?", userDN).Updates(&data).Error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (u *LdapUserModel) UpdateById(ctx context.Context, id int64, data *LdapUser) error {
|
||||||
|
return u.db.WithContext(ctx).Model(&LdapUser{}).Where("id = ?", id).Updates(&data).Error
|
||||||
|
}
|
||||||
|
|
||||||
func (u *LdapUserModel) Delete(ctx context.Context, id int64) error {
|
func (u *LdapUserModel) Delete(ctx context.Context, id int64) error {
|
||||||
return u.db.WithContext(ctx).Model(&LdapUser{}).Where("id = ?", id).Delete(&LdapUser{}).Error
|
return u.db.WithContext(ctx).Model(&LdapUser{}).Where("id = ?", id).Delete(&LdapUser{}).Error
|
||||||
}
|
}
|
||||||
|
@ -113,7 +113,6 @@ type AllModelsGen struct {
|
|||||||
LdapGroup *LdapGroupModel // ldap_group 权限组表
|
LdapGroup *LdapGroupModel // ldap_group 权限组表
|
||||||
LdapMenus *LdapMenusModel // ldap_menus 菜单表
|
LdapMenus *LdapMenusModel // ldap_menus 菜单表
|
||||||
LdapUser *LdapUserModel // ldap_user ldap_用户id递增表
|
LdapUser *LdapUserModel // ldap_user ldap_用户id递增表
|
||||||
LdapUserGroup *LdapUserGroupModel // ldap_user_group 用户权限分组表
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -228,7 +227,6 @@ func NewAllModels(gdb *gorm.DB) *AllModelsGen {
|
|||||||
LdapGroup: NewLdapGroupModel(gdb),
|
LdapGroup: NewLdapGroupModel(gdb),
|
||||||
LdapMenus: NewLdapMenusModel(gdb),
|
LdapMenus: NewLdapMenusModel(gdb),
|
||||||
LdapUser: NewLdapUserModel(gdb),
|
LdapUser: NewLdapUserModel(gdb),
|
||||||
LdapUserGroup: NewLdapUserGroupModel(gdb),
|
|
||||||
}
|
}
|
||||||
return models
|
return models
|
||||||
}
|
}
|
||||||
|
@ -51,10 +51,6 @@ func (l *DeleteLdapGroupLogic) DeleteLdapGroup(req *types.DeleteLdapGroupReq, us
|
|||||||
if resLdapGroupDel.Error != nil {
|
if resLdapGroupDel.Error != nil {
|
||||||
return resLdapGroupDel.Error
|
return resLdapGroupDel.Error
|
||||||
}
|
}
|
||||||
resLdapUserGroupDel := tx.Where("group_id IN ?", req.Ids).Delete(&gmodel.LdapUserGroup{})
|
|
||||||
if resLdapUserGroupDel.Error != nil {
|
|
||||||
return resLdapUserGroupDel.Error
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
if txErr != nil {
|
if txErr != nil {
|
||||||
|
@ -52,6 +52,9 @@ func (l *SaveLdapGroupLogic) SaveLdapGroup(req *types.SaveLdapGroupReq, userinfo
|
|||||||
if req.Name != "" {
|
if req.Name != "" {
|
||||||
updateMap["name"] = req.Name
|
updateMap["name"] = req.Name
|
||||||
}
|
}
|
||||||
|
if req.Type != "" {
|
||||||
|
updateMap["type"] = req.Type
|
||||||
|
}
|
||||||
if req.Keyword != "" {
|
if req.Keyword != "" {
|
||||||
updateMap["keyword"] = req.Keyword
|
updateMap["keyword"] = req.Keyword
|
||||||
}
|
}
|
||||||
@ -67,6 +70,7 @@ func (l *SaveLdapGroupLogic) SaveLdapGroup(req *types.SaveLdapGroupReq, userinfo
|
|||||||
err1 = l.svcCtx.AllModels.LdapGroup.UpdateOne(l.ctx, resOne, updateMap)
|
err1 = l.svcCtx.AllModels.LdapGroup.UpdateOne(l.ctx, resOne, updateMap)
|
||||||
} else {
|
} else {
|
||||||
err1 = l.svcCtx.AllModels.LdapGroup.InsertOne(l.ctx, gmodel.LdapGroup{
|
err1 = l.svcCtx.AllModels.LdapGroup.InsertOne(l.ctx, gmodel.LdapGroup{
|
||||||
|
Type: &req.Type,
|
||||||
Name: &req.Name,
|
Name: &req.Name,
|
||||||
Keyword: &req.Keyword,
|
Keyword: &req.Keyword,
|
||||||
Remark: &req.Remark,
|
Remark: &req.Remark,
|
||||||
|
@ -36,7 +36,7 @@ func NewSetLdapGroupUserLogic(ctx context.Context, svcCtx *svc.ServiceContext) *
|
|||||||
func (l *SetLdapGroupUserLogic) SetLdapGroupUser(req *types.SetLdapGroupUserReq, userinfo *auth.UserInfo) (resp *basic.Response) {
|
func (l *SetLdapGroupUserLogic) SetLdapGroupUser(req *types.SetLdapGroupUserReq, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||||
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
|
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
|
||||||
// userinfo 传入值时, 一定不为null
|
// userinfo 传入值时, 一定不为null
|
||||||
resLdapGroupInfo, err := l.svcCtx.AllModels.LdapGroup.FindOneById(l.ctx, req.GroupId)
|
_, err := l.svcCtx.AllModels.LdapGroup.FindOneById(l.ctx, req.GroupId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||||
basic.CodeServiceErr.Message = "权限组记录不存在"
|
basic.CodeServiceErr.Message = "权限组记录不存在"
|
||||||
@ -45,11 +45,10 @@ func (l *SetLdapGroupUserLogic) SetLdapGroupUser(req *types.SetLdapGroupUserReq,
|
|||||||
}
|
}
|
||||||
return resp.SetStatus(basic.CodeServiceErr)
|
return resp.SetStatus(basic.CodeServiceErr)
|
||||||
}
|
}
|
||||||
resCreateInBatches := l.svcCtx.MysqlConn.WithContext(l.ctx).Create(gmodel.LdapUserGroup{
|
err = l.svcCtx.AllModels.LdapUser.UpdateById(l.ctx, req.UserId, &gmodel.LdapUser{
|
||||||
GroupId: &resLdapGroupInfo.Id,
|
GroupId: &req.GroupId,
|
||||||
UserId: &req.UserId,
|
|
||||||
})
|
})
|
||||||
if resCreateInBatches.Error != nil {
|
if err != nil {
|
||||||
basic.CodeServiceErr.Message = "系统出错"
|
basic.CodeServiceErr.Message = "系统出错"
|
||||||
return resp.SetStatus(basic.CodeServiceErr)
|
return resp.SetStatus(basic.CodeServiceErr)
|
||||||
}
|
}
|
||||||
|
@ -33,6 +33,7 @@ type GetLdapGroupsReq struct {
|
|||||||
|
|
||||||
type SaveLdapGroupReq struct {
|
type SaveLdapGroupReq struct {
|
||||||
Id int64 `json:"id"` //id
|
Id int64 `json:"id"` //id
|
||||||
|
Type string `json:"type"` //类型
|
||||||
Name string `json:"name"` //名称
|
Name string `json:"name"` //名称
|
||||||
Keyword string `json:"keyword"` //关键词
|
Keyword string `json:"keyword"` //关键词
|
||||||
Remark string `json:"remark"` // 备注
|
Remark string `json:"remark"` // 备注
|
||||||
|
@ -126,6 +126,7 @@ type (
|
|||||||
}
|
}
|
||||||
SaveLdapGroupReq {
|
SaveLdapGroupReq {
|
||||||
Id int64 `json:"id"` //id
|
Id int64 `json:"id"` //id
|
||||||
|
Type string `json:"type"` //类型
|
||||||
Name string `json:"name"` //名称
|
Name string `json:"name"` //名称
|
||||||
Keyword string `json:"keyword"` //关键词
|
Keyword string `json:"keyword"` //关键词
|
||||||
Remark string `json:"remark"` // 备注
|
Remark string `json:"remark"` // 备注
|
||||||
|
Loading…
x
Reference in New Issue
Block a user