Skip to content

Commit

Permalink
Merge pull request #32 from weiwiegeng/main
Browse files Browse the repository at this point in the history
feat: 1. 去除授权时权限开关限制
  • Loading branch information
xinjiayu authored Mar 18, 2024
2 parents c5bcc5b + d78ed7a commit f6b454e
Show file tree
Hide file tree
Showing 6 changed files with 2,190 additions and 2,167 deletions.
1 change: 0 additions & 1 deletion internal/logic/middleware/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ func (s *sMiddleware) Ctx(r *ghttp.Request) {
func (s *sMiddleware) Auth(r *ghttp.Request) {
userId := service.Context().GetUserId(r.Context())
if userId == 0 {
response.JsonRedirectExit(r, consts.ErrorNotLogged, "未登录或会话已过期,请您登录后再继续", s.LoginUrl)
return
}

Expand Down
11 changes: 11 additions & 0 deletions internal/logic/system/sys_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,7 @@ func (s *sSysApi) ImportApiFile(ctx context.Context) (err error) {
//封装数据、整理入库
//获取所有的接口
var address []string
var tags []string
var apiPathsAll = make(map[string][]map[string]string)
paths := apiJsonContent["paths"].(map[string]interface{})
for key, value := range paths {
Expand Down Expand Up @@ -673,6 +674,7 @@ func (s *sSysApi) ImportApiFile(ctx context.Context) (err error) {
err = dao.SysApi.Transaction(ctx, func(ctx context.Context, tx gdb.TX) (err error) {
//开始入库
for key, value := range apiPathsAll {
tags = append(tags, key)
//获取分组ID
var categoryId int
//判断分组是否存在,不存在则创建分组
Expand Down Expand Up @@ -773,6 +775,15 @@ func (s *sSysApi) ImportApiFile(ctx context.Context) (err error) {
if err != nil {
return
}

//删除不存在的分类
_, err = dao.SysApi.Ctx(ctx).Data(g.Map{
dao.SysApi.Columns().IsDeleted: 1,
dao.SysApi.Columns().Status: 0,
dao.SysApi.Columns().DeletedAt: gtime.Now(),
dao.SysApi.Columns().DeletedBy: service.Context().GetUserId(ctx),
}).WhereNotIn(dao.SysApi.Columns().Name, tags).Where(dao.SysApi.Columns().Types, 1).Update()

return
})
return
Expand Down
134 changes: 48 additions & 86 deletions internal/logic/system/sys_authorize.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,38 +214,6 @@ func (s *sSysAuthorize) Add(ctx context.Context, authorize []*entity.SysAuthoriz
}

func (s *sSysAuthorize) AddAuthorize(ctx context.Context, roleId int, menuIds []string, buttonIds []string, columnIds []string, apiIds []string) (err error) {
//判断是否启用安全控制
var configDataByIsSecurityControlEnabled *entity.SysConfig
configDataByIsSecurityControlEnabled, err = service.ConfigData().GetConfigByKey(ctx, consts.SysIsSecurityControlEnabled)
if err != nil {
return
}
sysColumnSwitch := 0
sysButtonSwitch := 0
sysApiSwitch := 0

if configDataByIsSecurityControlEnabled != nil && strings.EqualFold(configDataByIsSecurityControlEnabled.ConfigValue, "1") {
//获取系统列表开关参数
var sysColumnSwitchConfig *entity.SysConfig
sysColumnSwitchConfig, err = service.ConfigData().GetConfigByKey(ctx, consts.SysColumnSwitch)
if sysColumnSwitchConfig != nil {
sysColumnSwitch = gconv.Int(sysColumnSwitchConfig.ConfigValue)
}
//获取系统按钮开关参数
var sysButtonSwitchConfig *entity.SysConfig
sysButtonSwitchConfig, err = service.ConfigData().GetConfigByKey(ctx, consts.SysButtonSwitch)
if sysButtonSwitchConfig != nil {
sysButtonSwitch = gconv.Int(sysButtonSwitchConfig.ConfigValue)
}

//获取系统API开关参数
var sysApiSwitchConfig *entity.SysConfig
sysApiSwitchConfig, err = service.ConfigData().GetConfigByKey(ctx, consts.SysApiSwitch)
if sysApiSwitchConfig != nil {
sysApiSwitch = gconv.Int(sysApiSwitchConfig.ConfigValue)
}
}

err = g.Try(ctx, func(ctx context.Context) {
//删除原有权限
err = service.SysAuthorize().DelByRoleId(ctx, roleId)
Expand All @@ -271,69 +239,63 @@ func (s *sSysAuthorize) AddAuthorize(ctx context.Context, roleId int, menuIds []
return
}
//封装按钮权限
if sysButtonSwitch == 1 {
for _, id := range buttonIds {
var authorize = new(entity.SysAuthorize)
split := strings.Split(id, "_")
if len(split) < 2 {
isTrue = false
break
}
authorize.ItemsId = gconv.Int(split[0])
authorize.ItemsType = consts.Button
authorize.RoleId = roleId
authorize.IsCheckAll = gconv.Int(split[1])
authorize.IsDeleted = 0
authorizeInfo = append(authorizeInfo, authorize)
}
if !isTrue {
err = gerror.New("按钮权限参数错误")
return
for _, id := range buttonIds {
var authorize = new(entity.SysAuthorize)
split := strings.Split(id, "_")
if len(split) < 2 {
isTrue = false
break
}
authorize.ItemsId = gconv.Int(split[0])
authorize.ItemsType = consts.Button
authorize.RoleId = roleId
authorize.IsCheckAll = gconv.Int(split[1])
authorize.IsDeleted = 0
authorizeInfo = append(authorizeInfo, authorize)
}
if !isTrue {
err = gerror.New("按钮权限参数错误")
return
}

//封装列表权限
if sysColumnSwitch == 1 {
for _, id := range columnIds {
var authorize = new(entity.SysAuthorize)
split := strings.Split(id, "_")
if len(split) < 2 {
isTrue = false
break
}
authorize.ItemsId = gconv.Int(split[0])
authorize.ItemsType = consts.Column
authorize.RoleId = roleId
authorize.IsCheckAll = gconv.Int(split[1])
authorize.IsDeleted = 0
authorizeInfo = append(authorizeInfo, authorize)
}
if !isTrue {
err = gerror.New("列表权限参数错误")
return
for _, id := range columnIds {
var authorize = new(entity.SysAuthorize)
split := strings.Split(id, "_")
if len(split) < 2 {
isTrue = false
break
}
authorize.ItemsId = gconv.Int(split[0])
authorize.ItemsType = consts.Column
authorize.RoleId = roleId
authorize.IsCheckAll = gconv.Int(split[1])
authorize.IsDeleted = 0
authorizeInfo = append(authorizeInfo, authorize)
}
if !isTrue {
err = gerror.New("列表权限参数错误")
return
}

//封装接口权限
if sysApiSwitch == 1 {
for _, id := range apiIds {
var authorize = new(entity.SysAuthorize)
split := strings.Split(id, "_")
if len(split) < 2 {
isTrue = false
break
}
authorize.ItemsId = gconv.Int(split[0])
authorize.ItemsType = consts.Api
authorize.RoleId = roleId
authorize.IsCheckAll = gconv.Int(split[1])
authorize.IsDeleted = 0
authorizeInfo = append(authorizeInfo, authorize)
}
if !isTrue {
err = gerror.New("接口权限参数错误")
return
for _, id := range apiIds {
var authorize = new(entity.SysAuthorize)
split := strings.Split(id, "_")
if len(split) < 2 {
isTrue = false
break
}
authorize.ItemsId = gconv.Int(split[0])
authorize.ItemsType = consts.Api
authorize.RoleId = roleId
authorize.IsCheckAll = gconv.Int(split[1])
authorize.IsDeleted = 0
authorizeInfo = append(authorizeInfo, authorize)
}
if !isTrue {
err = gerror.New("接口权限参数错误")
return
}

err = s.Add(ctx, authorizeInfo)
Expand Down
Binary file modified manifest/docker-compose/iot-open/sagooiot
Binary file not shown.
Loading

0 comments on commit f6b454e

Please sign in to comment.