[fix] 查询组织认证权限错误

This commit is contained in:
PandaX
2023-12-06 10:58:03 +08:00
parent dc59c9eeb4
commit 48f1792f32
2 changed files with 8 additions and 17 deletions

View File

@@ -27,10 +27,11 @@ type SysRole struct {
ApiIds []casbin.CasbinRule `json:"apiIds" gorm:"-"`
MenuIds []int64 `json:"menuIds" gorm:"-"`
OrganizationIds []int64 `json:"organizationIds" gorm:"-"`
Org string `json:"org" gorm:"-"`
}
type SysRoleAuth struct {
Org string `json:"org" gorm:"column:org"`
DataScope string `json:"dataScope"`
}
type MenuIdList struct {
MenuId int64 `json:"menuId"`
}

View File

@@ -17,7 +17,7 @@ type (
Delete(roleId []int64)
GetRoleMeunId(data entity.SysRole) []int64
GetRoleOrganizationId(data entity.SysRole) []int64
FindOrganizationsByRoleId(roleId int64) (entity.SysRole, error)
FindOrganizationsByRoleId(roleId int64) (entity.SysRoleAuth, error)
}
sysRoleModel struct {
@@ -132,18 +132,8 @@ func (m *sysRoleModel) GetRoleOrganizationId(data entity.SysRole) []int64 {
return organizationIds
}
func (m *sysRoleModel) FindOrganizationsByRoleId(roleId int64) (entity.SysRole, error) {
var roleData entity.SysRole
db := global.Db.Table(m.table)
if global.Conf.Server.DbType == "mysql" {
db.Select("sys_roles.data_scope, GROUP_CONCAT(sys_role_organizations.organization_id) as org")
} else {
db.Select("sys_roles.data_scope, STRING_AGG(sys_role_organizations.organization_id::text,',') as org")
}
err := db.
Joins("LEFT JOIN sys_role_organizations ON sys_roles.role_id = sys_role_organizations.role_id").
Where("sys_roles.role_id = ?", roleId).
Group("sys_roles.role_id").
First(&roleData).Error
func (m *sysRoleModel) FindOrganizationsByRoleId(roleId int64) (entity.SysRoleAuth, error) {
var roleData entity.SysRoleAuth
err := global.Db.Raw("SELECT sys_roles.data_scope, GROUP_CONCAT(sys_role_organizations.organization_id) as org FROM sys_roles LEFT JOIN sys_role_organizations ON sys_roles.role_id = sys_role_organizations.role_id WHERE sys_roles.role_id = ? GROUP BY sys_roles.role_id", roleId).Scan(&roleData).Error
return roleData, err
}