权限相关问题修复
This commit is contained in:
1 parent
e9617ec677
commit
da347e095f
9 files changed
+140
-34
No files matched your search
@@ -126,6 +126,9 @@ func (e *SysRole) InsertSysRole(c *gin.Context) {
|
||||
}
|
||||
// 设置创建人
|
||||
object.CreateBy = tools.GetUserId(c)
|
||||
if object.Status == "" {
|
||||
object.Status = "2"
|
||||
}
|
||||
|
||||
s := service.SysRole{}
|
||||
s.Orm = db
|
||||
@@ -195,10 +198,10 @@ func (e *SysRole) UpdateSysRole(c *gin.Context) {
|
||||
// @Summary 删除用户角色
|
||||
// @Description 删除数据
|
||||
// @Tags 角色/Role
|
||||
// @Param roleId path int true "roleId"
|
||||
// @Param data body dto.SysRoleById true "body"
|
||||
// @Success 200 {string} string "{"code": 200, "message": "删除成功"}"
|
||||
// @Success 200 {string} string "{"code": -1, "message": "删除失败"}"
|
||||
// @Router /api/v1/role/{roleId} [delete]
|
||||
// @Router /api/v1/role [delete]
|
||||
// @Security Bearer
|
||||
func (e *SysRole) DeleteSysRole(c *gin.Context) {
|
||||
control := new(dto.SysRoleById)
|
||||
@@ -223,6 +226,7 @@ func (e *SysRole) DeleteSysRole(c *gin.Context) {
|
||||
err = s.RemoveSysRole(control)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
e.Error(c, http.StatusInternalServerError, err, "")
|
||||
return
|
||||
}
|
||||
_, err = global.LoadPolicy(c)
|
||||
|
||||
@@ -26,6 +26,6 @@ func registerSysConfigRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMidd
|
||||
r1 := v1.Group("/configKey").Use(authMiddleware.MiddlewareFunc()).Use(middleware.AuthCheckRole())
|
||||
{
|
||||
api := &sys_config.SysConfig{}
|
||||
r1.POST("", api.GetSysConfigByKEYForService)
|
||||
r1.GET("/:configKey", api.GetSysConfigByKEYForService)
|
||||
}
|
||||
}
|
||||
@@ -20,7 +20,7 @@ func registerSysRoleRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddle
|
||||
r.GET("/:id", api.GetSysRole)
|
||||
r.POST("", api.InsertSysRole)
|
||||
r.PUT("/:id", api.UpdateSysRole)
|
||||
r.DELETE("/:id", api.DeleteSysRole)
|
||||
r.DELETE("", api.DeleteSysRole)
|
||||
}
|
||||
v1.PUT("/roledatascope", api.UpdateRoleDataScope)
|
||||
}
|
||||
@@ -167,14 +167,14 @@ func registerDictRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddlewar
|
||||
dicts.GET("/data/:dictCode", dataApi.GetSysDictData)
|
||||
dicts.POST("/data", dataApi.InsertSysDictData)
|
||||
dicts.PUT("/data/:dictCode", dataApi.UpdateSysDictData)
|
||||
dicts.DELETE("/data/:dictCode", dataApi.DeleteSysDictData)
|
||||
dicts.DELETE("/data", dataApi.DeleteSysDictData)
|
||||
|
||||
dicts.GET("/type-option-select", dictApi.GetSysDictTypeAll)
|
||||
dicts.GET("/type", dictApi.GetSysDictTypeList)
|
||||
dicts.GET("/type/:id", dictApi.GetSysDictType)
|
||||
dicts.POST("/type", dictApi.InsertSysDictType)
|
||||
dicts.PUT("/type/:id", dictApi.UpdateSysDictType)
|
||||
dicts.DELETE("/type/:id", dictApi.DeleteSysDictType)
|
||||
dicts.DELETE("/type", dictApi.DeleteSysDictType)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ func (m *SysConfigSearch) Bind(ctx *gin.Context) error {
|
||||
type SysConfigControl struct {
|
||||
ID int `uri:"ID" comment:"编码"` // 编码
|
||||
ConfigName string `json:"configName" comment:""`
|
||||
ConfigKey string `json:"configKey" comment:""`
|
||||
ConfigKey string `uri:"configKey" json:"configKey" comment:""`
|
||||
ConfigValue string `json:"configValue" comment:""`
|
||||
ConfigType string `json:"configType" comment:""`
|
||||
Remark string `json:"remark" comment:""`
|
||||
|
||||
@@ -98,8 +98,7 @@ func (s *SysRoleControl) GetId() interface{} {
|
||||
|
||||
// SysConfigById 获取单个或者删除的结构体
|
||||
type SysRoleById struct {
|
||||
Id int `uri:"id"`
|
||||
Ids []int `json:"ids"`
|
||||
dto.ObjectById
|
||||
}
|
||||
|
||||
func (s *SysRoleById) Generate() *SysRoleById {
|
||||
@@ -111,20 +110,6 @@ func (s *SysRoleById) GetId() interface{} {
|
||||
return s.Id
|
||||
}
|
||||
|
||||
func (s *SysRoleById) Bind(ctx *gin.Context) error {
|
||||
msgID := tools.GenerateMsgIDFromContext(ctx)
|
||||
err := ctx.ShouldBindUri(s)
|
||||
if err != nil {
|
||||
log.Debugf("MsgID[%s] ShouldBindUri error: %s", msgID, err.Error())
|
||||
return err
|
||||
}
|
||||
err = ctx.ShouldBind(s)
|
||||
if err != nil {
|
||||
log.Debugf("MsgID[%s] ShouldBind error: %#v", msgID, err.Error())
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *SysRoleById) GenerateM() (*models.SysRole, error) {
|
||||
return &models.SysRole{}, nil
|
||||
}
|
||||
|
||||
@@ -155,7 +155,17 @@ func (e *SysRole) RemoveSysRole(d *dto.SysRoleById) error {
|
||||
}
|
||||
}()
|
||||
|
||||
db := tx.Model(&data).Delete(&data, d.GetId())
|
||||
s := SysRoleMenu{}
|
||||
s.Orm = tx
|
||||
s.MsgID = msgID
|
||||
for _, roleId := range d.Ids {
|
||||
err = s.DeleteRoleMenu(tx, roleId)
|
||||
if err != nil {
|
||||
log.Errorf("msgID[%s] insert role menu error, %", msgID, err.Error())
|
||||
return err
|
||||
}
|
||||
}
|
||||
db := tx.Model(&data).Delete(&data, d.Ids)
|
||||
if db.Error != nil {
|
||||
err = db.Error
|
||||
log.Errorf("MsgID[%s] Delete error: %s", msgID, err)
|
||||
@@ -165,14 +175,6 @@ func (e *SysRole) RemoveSysRole(d *dto.SysRoleById) error {
|
||||
err = errors.New("无权删除该数据")
|
||||
return err
|
||||
}
|
||||
s := SysRoleMenu{}
|
||||
s.Orm = db
|
||||
s.MsgID = msgID
|
||||
err = s.DeleteRoleMenu(tx, d.Id)
|
||||
if err != nil {
|
||||
log.Errorf("msgID[%s] insert role menu error, %", msgID, err.Error())
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
package version
|
||||
|
||||
import (
|
||||
"go-admin/app/admin/models"
|
||||
//"go-admin/app/admin/models"
|
||||
"gorm.io/gorm"
|
||||
"runtime"
|
||||
|
||||
"go-admin/cmd/migrate/migration"
|
||||
common "go-admin/common/models"
|
||||
)
|
||||
|
||||
func init() {
|
||||
_, fileName, _, _ := runtime.Caller(0)
|
||||
migration.Migrate.SetVersion(migration.GetFilename(fileName), _1613998164781Test)
|
||||
}
|
||||
|
||||
func _1613998164781Test(db *gorm.DB, version string) error {
|
||||
return db.Transaction(func(tx *gorm.DB) error {
|
||||
|
||||
err := tx.Model(&models.Menu{}).Where("path = ?", "/api/v1/deptList").Update("path", "/api/v1/dept").Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = tx.Model(&models.Menu{}).Where("path = ?", "/api/v1/roleList").Update("path", "/api/v1/role").Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = tx.Model(&models.Menu{}).Where("path = ?", "/api/v1/menuList").Update("path", "/api/v1/menu").Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = tx.Model(&models.Menu{}).Where("path = ?", "/api/v1/postList").Update("path", "/api/v1/post").Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = tx.Model(&models.Menu{}).Where("path = ?", "/api/v1/dict/typelist").Update("path", "/api/v1/dict/type").Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = tx.Model(&models.Menu{}).Where("path = ?", "/api/v1/dict/datalist").Update("path", "/api/v1/dict/data").Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = tx.Model(&models.Menu{}).Where("path like ?", "/api/v1/dict/data").
|
||||
Where("action = ?", "PUT").Update("path", "/api/v1/dict/data/:id").Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = tx.Model(&models.Menu{}).Where("path like ?", "/api/v1/dict/data/:id").
|
||||
Where("action = ?", "DELETE").Update("path", "/api/v1/dict/data").Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = tx.Model(&models.Menu{}).Where("path like ?", "/api/v1/dict/type").
|
||||
Where("action = ?", "PUT").Update("path", "/api/v1/dict/type/:id").Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = tx.Model(&models.Menu{}).Where("path like ?", "/api/v1/dict/type/:id").
|
||||
Where("action = ?", "DELETE").Update("path", "/api/v1/dict/type").Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = tx.Model(&models.Menu{}).Where("path = ?", "/api/v1/operloglist").Update("path", "/api/v1/sys-opera-log").Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = tx.Model(&models.Menu{}).Where("path = ?", "/api/v1/loginloglist").Update("path", "/api/v1/sys-login-log").Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = tx.Model(&models.Menu{}).Where("path = ?", "/api/v1/loginlog/:id").Where("action = ?", "DELETE").Update("path", "/api/v1/sys-opera-log").Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = tx.Model(&models.Menu{}).Where("path like ?", "/api/v1/operloglist%").Where("action = ?", "DELETE").Update("path", "/api/v1/sys-opera-log").Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = tx.Model(&models.Menu{}).Where("path like ?", "/api/v1/role/:id").Where("action = ?", "DELETE").Update("path", "/api/v1/role").Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return tx.Create(&common.Migration{
|
||||
Version: version,
|
||||
}).Error
|
||||
})
|
||||
}
|
||||
+13
-2
@@ -12,16 +12,27 @@ type ObjectById struct {
|
||||
}
|
||||
|
||||
func (s *ObjectById) Bind(ctx *gin.Context) error {
|
||||
var err error
|
||||
err = ctx.ShouldBindUri(s)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if ctx.Request.Method == http.MethodDelete {
|
||||
err := ctx.ShouldBind(&s.Ids)
|
||||
err = ctx.ShouldBind(&s.Ids)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(s.Ids) > 0 {
|
||||
return nil
|
||||
}
|
||||
if s.Ids == nil {
|
||||
s.Ids = make([]int, 0)
|
||||
}
|
||||
if s.Id != 0 {
|
||||
s.Ids = append(s.Ids, s.Id)
|
||||
}
|
||||
}
|
||||
return ctx.ShouldBindUri(s)
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *ObjectById) GetId() interface{} {
|
||||
|
||||
Reference in new issue
Block a user