Commit f76d3676 authored by shajiaiming's avatar shajiaiming

fix

parent 2d784dc8
......@@ -24,7 +24,7 @@ func AddAdminRole(c *gin.Context) {
}
}
roleService := role_service.AdminRole{
roleService := casbin_service.AdminRole{
Uid: role.Uid,
RoleId: role.RoleId,
}
......
......@@ -28,14 +28,14 @@ func GetRoles(c *gin.Context) {
group := user.UserInfo.Group
platform_id := user.UserInfo.PlatformId
roleService := role_service.Role{}
roleService := casbin_service.Role{}
if ("administrator" == group) {
if arg := c.Query("platform_id"); arg != "" {
platform_id = com.StrTo(c.Query("platform_id")).MustInt()
}
}
roleService = role_service.Role{
roleService = casbin_service.Role{
RoleName: role_name,
Description: description,
PlatformId: int64(platform_id),
......@@ -65,7 +65,7 @@ func AddRole(c *gin.Context) {
user, _ := util.ParseToken(token)
platform_id := int64(user.UserInfo.PlatformId)
roleService := role_service.Role{
roleService := casbin_service.Role{
RoleName: role.RoleName,
Description: role.Description,
PlatformId: platform_id,
......@@ -90,7 +90,7 @@ func EditRole(c *gin.Context) {
}
}
roleService := role_service.Role{Id: role_tmp.Id}
roleService := casbin_service.Role{Id: role_tmp.Id}
role, err := roleService.GetRole()
if err != nil {
handler.SendResponse(c, errno.ErrRoleNotFound, nil)
......@@ -103,7 +103,7 @@ func EditRole(c *gin.Context) {
handler.SendResponse(c, errno.ErrUpdateRole, nil)
return
}
roleService = role_service.Role{
roleService = casbin_service.Role{
Id: role_tmp.Id,
RoleName: role_tmp.RoleName,
Description: role_tmp.Description,
......@@ -124,7 +124,7 @@ func DeleteRole(c *gin.Context) {
return
}
roleService := role_service.Role{Id: id}
roleService := casbin_service.Role{Id: id}
role, err := roleService.GetRole()
if err != nil {
......
package role_service
package casbin_service
import (
"bwallet/models"
......
package casbin_service
import (
"bwallet/models"
)
type CasbinRole struct {
Id int
Ptype string
V0 string
V1 string
V2 string
V3 string
V4 string
V5 string
}
func (r *CasbinRole) GetAllRolesRelation() ([]*models.Role, error) {
roles, err := models.GetRoles(r.getMaps())
if err != nil {
return nil, err
}
return roles, nil
}
func (r *CasbinRole) AddRoleRelation() error {
role := map[string]interface{}{
"ptype": r.Ptype,
"v0": r.V0,
"v1": r.V1,
"v2": r.V2,
}
if err := models.AddRuleRelation(role); err != nil {
return err
}
return nil
}
func (r *CasbinRole) getMaps() (map[string]interface{}) {
maps := make(map[string]interface{})
if r.Id != 0 {
maps["id"] = r.Id
}
if r.Ptype != "" {
maps["ptype"] = r.Ptype
}
if r.V0 != "" {
maps["v0"] = r.V0
}
if r.V1 != "" {
maps["v1"] = r.V1
}
return maps
}
package role_service
package casbin_service
import (
"bwallet/models"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment