权限相关问题修复

This commit is contained in:
linwenxiang committed 2021-02-22 22:00:34 +08:00
1 parent e9617ec677
commit da347e095f
9 files changed
+140 -34

No files matched your search

+6 -2
View File
@@ -126,6 +126,9 @@ func (e *SysRole) InsertSysRole(c *gin.Context) {
} }
// 设置创建人 // 设置创建人
object.CreateBy = tools.GetUserId(c) object.CreateBy = tools.GetUserId(c)
if object.Status == "" {
object.Status = "2"
}
s := service.SysRole{} s := service.SysRole{}
s.Orm = db s.Orm = db
@@ -195,10 +198,10 @@ func (e *SysRole) UpdateSysRole(c *gin.Context) {
// @Summary 删除用户角色 // @Summary 删除用户角色
// @Description 删除数据 // @Description 删除数据
// @Tags 角色/Role // @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": 200, "message": "删除成功"}"
// @Success 200 {string} string "{"code": -1, "message": "删除失败"}" // @Success 200 {string} string "{"code": -1, "message": "删除失败"}"
// @Router /api/v1/role/{roleId} [delete] // @Router /api/v1/role [delete]
// @Security Bearer // @Security Bearer
func (e *SysRole) DeleteSysRole(c *gin.Context) { func (e *SysRole) DeleteSysRole(c *gin.Context) {
control := new(dto.SysRoleById) control := new(dto.SysRoleById)
@@ -223,6 +226,7 @@ func (e *SysRole) DeleteSysRole(c *gin.Context) {
err = s.RemoveSysRole(control) err = s.RemoveSysRole(control)
if err != nil { if err != nil {
log.Error(err) log.Error(err)
e.Error(c, http.StatusInternalServerError, err, "")
return return
} }
_, err = global.LoadPolicy(c) _, err = global.LoadPolicy(c)
+1 -1
View File
@@ -26,6 +26,6 @@ func registerSysConfigRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMidd
r1 := v1.Group("/configKey").Use(authMiddleware.MiddlewareFunc()).Use(middleware.AuthCheckRole()) r1 := v1.Group("/configKey").Use(authMiddleware.MiddlewareFunc()).Use(middleware.AuthCheckRole())
{ {
api := &sys_config.SysConfig{} api := &sys_config.SysConfig{}
r1.POST("", api.GetSysConfigByKEYForService) r1.GET("/:configKey", api.GetSysConfigByKEYForService)
} }
} }
+1 -1
View File
@@ -20,7 +20,7 @@ func registerSysRoleRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddle
r.GET("/:id", api.GetSysRole) r.GET("/:id", api.GetSysRole)
r.POST("", api.InsertSysRole) r.POST("", api.InsertSysRole)
r.PUT("/:id", api.UpdateSysRole) r.PUT("/:id", api.UpdateSysRole)
r.DELETE("/:id", api.DeleteSysRole) r.DELETE("", api.DeleteSysRole)
} }
v1.PUT("/roledatascope", api.UpdateRoleDataScope) v1.PUT("/roledatascope", api.UpdateRoleDataScope)
} }
+2 -2
View File
@@ -167,14 +167,14 @@ func registerDictRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddlewar
dicts.GET("/data/:dictCode", dataApi.GetSysDictData) dicts.GET("/data/:dictCode", dataApi.GetSysDictData)
dicts.POST("/data", dataApi.InsertSysDictData) dicts.POST("/data", dataApi.InsertSysDictData)
dicts.PUT("/data/:dictCode", dataApi.UpdateSysDictData) 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-option-select", dictApi.GetSysDictTypeAll)
dicts.GET("/type", dictApi.GetSysDictTypeList) dicts.GET("/type", dictApi.GetSysDictTypeList)
dicts.GET("/type/:id", dictApi.GetSysDictType) dicts.GET("/type/:id", dictApi.GetSysDictType)
dicts.POST("/type", dictApi.InsertSysDictType) dicts.POST("/type", dictApi.InsertSysDictType)
dicts.PUT("/type/:id", dictApi.UpdateSysDictType) dicts.PUT("/type/:id", dictApi.UpdateSysDictType)
dicts.DELETE("/type/:id", dictApi.DeleteSysDictType) dicts.DELETE("/type", dictApi.DeleteSysDictType)
} }
} }
+1 -1
View File
@@ -37,7 +37,7 @@ func (m *SysConfigSearch) Bind(ctx *gin.Context) error {
type SysConfigControl struct { type SysConfigControl struct {
ID int `uri:"ID" comment:"编码"` // 编码 ID int `uri:"ID" comment:"编码"` // 编码
ConfigName string `json:"configName" comment:""` ConfigName string `json:"configName" comment:""`
ConfigKey string `json:"configKey" comment:""` ConfigKey string `uri:"configKey" json:"configKey" comment:""`
ConfigValue string `json:"configValue" comment:""` ConfigValue string `json:"configValue" comment:""`
ConfigType string `json:"configType" comment:""` ConfigType string `json:"configType" comment:""`
Remark string `json:"remark" comment:""` Remark string `json:"remark" comment:""`
+1 -16
View File
@@ -98,8 +98,7 @@ func (s *SysRoleControl) GetId() interface{} {
// SysConfigById 获取单个或者删除的结构体 // SysConfigById 获取单个或者删除的结构体
type SysRoleById struct { type SysRoleById struct {
Id int `uri:"id"` dto.ObjectById
Ids []int `json:"ids"`
} }
func (s *SysRoleById) Generate() *SysRoleById { func (s *SysRoleById) Generate() *SysRoleById {
@@ -111,20 +110,6 @@ func (s *SysRoleById) GetId() interface{} {
return s.Id 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) { func (s *SysRoleById) GenerateM() (*models.SysRole, error) {
return &models.SysRole{}, nil return &models.SysRole{}, nil
} }
+11 -9
View File
@@ -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 { if db.Error != nil {
err = db.Error err = db.Error
log.Errorf("MsgID[%s] Delete error: %s", msgID, err) log.Errorf("MsgID[%s] Delete error: %s", msgID, err)
@@ -165,14 +175,6 @@ func (e *SysRole) RemoveSysRole(d *dto.SysRoleById) error {
err = errors.New("无权删除该数据") err = errors.New("无权删除该数据")
return err 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 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
View File
@@ -12,16 +12,27 @@ type ObjectById struct {
} }
func (s *ObjectById) Bind(ctx *gin.Context) error { 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 { if ctx.Request.Method == http.MethodDelete {
err := ctx.ShouldBind(&s.Ids) err = ctx.ShouldBind(&s.Ids)
if err != nil { if err != nil {
return err return err
} }
if len(s.Ids) > 0 { if len(s.Ids) > 0 {
return nil 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{} { func (s *ObjectById) GetId() interface{} {