作者 唐旭辉

角色列表调整

... ... @@ -175,9 +175,7 @@ func (c *RbacController) RoleGroupUpdate() {
msg = protocol.BadRequestParam("10081")
return
}
param.Pid = 0
param.Types = models.ROLETYPES_GROUP
roleinfo, err := serverbac.RoleEdit(param)
roleinfo, err := serverbac.RoleGroupEdit(param.ID, param.Name)
msg = protocol.NewReturnResponse(roleinfo, err)
return
}
... ...
... ... @@ -46,6 +46,7 @@ type RoleInfo struct {
Name string `json:"name" orm:"column(name)"`
IsDefault int8 `json:"is_default" orm:"column(is_default)"`
Pid int64 `json:"groupId" orm:"column(pid)"`
Types int8 `json:"types" orm:"column(types)"`
}
type RoleGroup struct {
... ...
... ... @@ -137,6 +137,30 @@ func RoleEdit(param protocol.RequestRoleEdit) (*protocol.ResponseRoleInfo, error
return r, nil
}
func RoleGroupEdit(id int64, name string) (*protocol.ResponseRoleInfo, error) {
var (
err error
roleinfo *models.Role
)
roleinfo, err = models.GetRoleById(id)
if err != nil {
log.Error("获取角色数据失败:%s", err)
return nil, protocol.NewErrWithMessage("1")
}
if roleinfo.Types != models.ROLETYPES_GROUP {
log.Error("不是角色组")
return nil, protocol.NewErrWithMessage("1")
}
roleinfo.Name = name
models.UpdateRoleById(roleinfo, []string{"Name"})
r := &protocol.ResponseRoleInfo{
ID: roleinfo.Id,
Name: roleinfo.Name,
Types: roleinfo.Types,
}
return r, nil
}
func RoleGroupDelete(param protocol.RequestRoleDelete) error {
var (
roleinfo *models.Role
... ... @@ -219,7 +243,7 @@ func GetRoleList(adminid int64, companyId int64) ([]protocol.RoleGroup, error) {
func getRoleInfoByPid(companyid int64, pid int64) ([]protocol.RoleInfo, error) {
const (
dataSql string = `SELECT id,name,is_default,pid FROM role WHERE company_id=? AND pid=? and delete_at=0 `
dataSql string = `SELECT id,name,is_default,pid,types FROM role WHERE company_id=? AND pid=? and delete_at=0 `
)
var (
err error
... ... @@ -231,7 +255,7 @@ func getRoleInfoByPid(companyid int64, pid int64) ([]protocol.RoleInfo, error) {
func getRoleGroupByCompany(companyid int64) ([]protocol.RoleInfo, error) {
const (
datasql string = `SELECT id,name,is_default FROM role WHERE company_id=? AND types=? AND delete_at=0 `
datasql string = `SELECT id,name,is_default,types FROM role WHERE company_id=? AND types=? AND delete_at=0 `
)
var (
err error
... ...