Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 删除路由改写为事务,并且先判断是否删除RBAC能否成功 #24

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
server:
port: 8899
address: 127.0.0.1
name: go-easy-admin
# # 生产环境建议使用 release,debug:可以使用debug模式
model: release
adminUser: admin
adminPwd: 25285442ebc7d3a0c20047e01d341c31

# 数据库配置
mysql:
DbHost: 47.92.196.70
DbPort: 3306
# 数据库名称 需要提前创建好
DbName: go_easy_admin
DbUser: root
DbPwd: v|+(ah@bF3dyN
MaxIdleConns: 10
MaxOpenConns: 100
# 是否开启debug,1 开启 0 关闭
ActiveDebug: 0

# 密码加密
aes:
key: go-easy-admin

jwt:
realm: go-easy-admin
# jwt加密因子
key: anruo
# jwt token过期时间 单位为小时
timeout: 100
# jwt token刷新时间 单位为小时
maxRefresh: 1
15 changes: 10 additions & 5 deletions pkg/controller/system/apis.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ package system

import (
"context"

"github.com/jinzhu/copier"
"gorm.io/gorm"

reqSystem "go-easy-admin/internal/model/request/system"
"go-easy-admin/internal/model/system"
Expand Down Expand Up @@ -51,10 +51,15 @@ func (sa *sysApis) Delete(id int) error {
if err != nil {
return err
}
if err = global.GORM.WithContext(sa.ctx).Delete(&api).Error; err != nil {
return global.DeleteErr(sa.tips, err)
}
return NewSysRBAC(sa.ctx).DeleteByAPIsID(id)

err = global.GORM.WithContext(sa.ctx).Transaction(func(tx *gorm.DB) error {
if err = NewSysRBAC(sa.ctx).DeleteByAPIsID(id); err != nil {
return global.DeleteErr(sa.tips, err)
} else {
return global.GORM.WithContext(sa.ctx).Delete(&api).Error
}
})
return err
}

func (sa *sysApis) Update(id int, req *reqSystem.UpdateAPIsReq) error {
Expand Down
1 change: 0 additions & 1 deletion pkg/controller/system/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ package system
import (
"context"
"errors"

"github.com/jinzhu/copier"
"gorm.io/gorm"

Expand Down