作者 唐旭辉

bug 修复

... ... @@ -23,8 +23,8 @@ const (
)
type PermissionOptionObject interface {
// StringUnmarshal(string) error
// ObjectMarshal() string
StringUnmarshal(string) error
ObjectMarshal() string
GetValidFunc(string) bool
MergeObject(string) error
}
... ...
... ... @@ -56,20 +56,20 @@ func (p *PermissionOptionBase) MergeObject(jsonString string) error {
return nil
}
// //StringUnmarshal PermissionOptionBase 接口实现
// func (p *PermissionOptionBase) StringUnmarshal(s string) error {
// err := json.Unmarshal([]byte(s), p)
// return err
// }
// //ObjectMarshal PermissionOptionBase 接口实现
// func (p *PermissionOptionBase) ObjectMarshal() string {
// bt, err := json.Marshal(p)
// if err != nil {
// return ""
// }
// return string(bt)
// }
//StringUnmarshal PermissionOptionBase 接口实现
func (p *PermissionOptionBase) StringUnmarshal(s string) error {
err := json.Unmarshal([]byte(s), p)
return err
}
//ObjectMarshal PermissionOptionBase 接口实现
func (p *PermissionOptionBase) ObjectMarshal() string {
bt, err := json.Marshal(p)
if err != nil {
return ""
}
return string(bt)
}
/*
机会管理模块
... ... @@ -233,17 +233,17 @@ func (p *OptionOpportunity) ValidCloseChance() bool {
return false
}
// //StringUnmarshal PermissionOptionBase 接口实现
// func (p *OptionOpportunity) StringUnmarshal(s string) error {
// err := json.Unmarshal([]byte(s), p)
// return err
// }
// //ObjectMarshal PermissionOptionBase 接口实现
// func (p *OptionOpportunity) ObjectMarshal() string {
// bt, err := json.Marshal(p)
// if err != nil {
// return ""
// }
// return string(bt)
// }
//StringUnmarshal PermissionOptionBase 接口实现
func (p *OptionOpportunity) StringUnmarshal(s string) error {
err := json.Unmarshal([]byte(s), p)
return err
}
//ObjectMarshal PermissionOptionBase 接口实现
func (p *OptionOpportunity) ObjectMarshal() string {
bt, err := json.Marshal(p)
if err != nil {
return ""
}
return string(bt)
}
... ...
... ... @@ -148,11 +148,21 @@ func ExistUserPermission(userid int64) bool {
func GetUserPermissionAll(userid int64) (map[string]rbac.PermissionOptionObject, error) {
key := GetKeyUserPermission(userid)
client := redis.GetRedis()
str, err := client.Get(key).Result()
strMap, err := client.HGetAll(key).Result()
if err != nil {
return nil, err
}
permissionObj := make(map[string]rbac.PermissionOptionObject)
err = json.Unmarshal([]byte(str), &permissionObj)
for k, v := range strMap {
fn, ok := rbac.CodePermissionObject[k]
if !ok {
continue
}
obj := fn()
if err := obj.StringUnmarshal(v); err == nil {
permissionObj[k] = obj
}
}
return permissionObj, err
}
... ...