|
|
package rbac
|
|
|
|
|
|
import (
|
|
|
"encoding/json"
|
|
|
)
|
|
|
|
|
|
//PermissionBase 路由对应的权限
|
|
|
type PermissionBase struct {
|
|
|
CodeName string //模块标识
|
|
|
ActionName string
|
|
|
MethodMap map[string]func()
|
|
|
}
|
|
|
|
|
|
var routerPermission = map[string]PermissionBase{
|
|
|
"/v1/department/list": PermissionBase{CodeName: "OPPMG_DEPARTMENT", ActionName: "check"},
|
|
|
"/v1/department/add": PermissionBase{CodeName: "OPPMG_DEPARTMENT", ActionName: "add"},
|
|
|
"/v1/department/edit": PermissionBase{CodeName: "OPPMG_DEPARTMENT", ActionName: "edit"},
|
|
|
"/v1/department/delete": PermissionBase{CodeName: "OPPMG_DEPARTMENT", ActionName: "delete"},
|
|
|
}
|
|
|
|
|
|
var permissionObject = map[string]interface{}{
|
|
|
"": 0,
|
|
|
}
|
|
|
|
|
|
//模块编号
|
|
|
const (
|
|
|
M_ENTERPRISE string = "ENTERPRISE" //企业基础设置
|
...
|
...
|
@@ -37,56 +15,31 @@ const ( |
|
|
M_SYSTEM_ANNOUNCEMENT string = "SYSTEM_ANNOUNCEMENT" //公告管理
|
|
|
)
|
|
|
|
|
|
type PermissionContentObject interface {
|
|
|
StringUnmarshal(string) error
|
|
|
ObjectMarshal() (string, error)
|
|
|
type PermissionOptionObject interface {
|
|
|
// StringUnmarshal(string) error
|
|
|
// ObjectMarshal() string
|
|
|
GetValidFunc(string) func(UserObject) bool
|
|
|
}
|
|
|
|
|
|
type UserObject struct {
|
|
|
UserId int64 `json:"user_id"`
|
|
|
CompanyId int64 `json:"company_id"`
|
|
|
UserCompanyId int64 `json:"user_company_id"`
|
|
|
}
|
|
|
|
|
|
type PermissionContentBase struct {
|
|
|
Check int8 `json:"check"`
|
|
|
}
|
|
|
|
|
|
func (p *PermissionContentBase) ValidDefault(obj UserObject) bool {
|
|
|
if p.Check == 1 {
|
|
|
return true
|
|
|
}
|
|
|
return false
|
|
|
}
|
|
|
|
|
|
func NewPermissionContentBase() PermissionContentObject {
|
|
|
return &PermissionContentBase{}
|
|
|
}
|
|
|
|
|
|
func (p *PermissionContentBase) StringUnmarshal(s string) error {
|
|
|
err := json.Unmarshal([]byte(s), p)
|
|
|
return err
|
|
|
//PermissionBase 路由对应的权限
|
|
|
type PermissionBase struct {
|
|
|
CodeName string //模块标识
|
|
|
ActionName string
|
|
|
}
|
|
|
|
|
|
func (p *PermissionContentBase) ObjectMarshal() (string, error) {
|
|
|
bt, err := json.Marshal(p)
|
|
|
if err != nil {
|
|
|
return "", err
|
|
|
}
|
|
|
return string(bt), err
|
|
|
}
|
|
|
var routerPermission = map[string]PermissionBase{}
|
|
|
|
|
|
type CodeToObject func() PermissionContentObject
|
|
|
type CodeToObject func() PermissionOptionObject
|
|
|
|
|
|
var CodePermissionObject = map[string]CodeToObject{
|
|
|
M_ENTERPRISE_ORGANIZATION: NewPermissionContentBase, //公司组织架构设置
|
|
|
M_ENTERPRISE_EMPLOYEE_POST: NewPermissionContentBase, //公司职务管理
|
|
|
M_ENTERPRISE_EMPLOYEE_ROLE: NewPermissionContentBase, //员工角色/权限设置
|
|
|
M_ENTERPRISE_EMPLOYEE: NewPermissionContentBase, //公司员工管理
|
|
|
M_ENTERPRISE: NewPermissionContentBase, //企业基础设置(大节点)
|
|
|
M_SYSTEM: NewPermissionContentBase, //系统设置(大节点)
|
|
|
M_ENTERPRISE_PROFILE: NewPermissionContentBase, //企业信息维护
|
|
|
M_SYSTEM_OPPORTUNITY_TEMPLATE: NewPermissionContentBase, //机会模板管理
|
|
|
M_SYSTEM_RATING: NewPermissionContentBase, //评分模式
|
|
|
M_SYSTEM_OPPORTUNITY: NewPermissionContentBase, //机会管理
|
|
|
M_ENTERPRISE_ORGANIZATION: NewPermissionOptionBase, //公司组织架构设置
|
|
|
M_ENTERPRISE_EMPLOYEE_POST: NewPermissionOptionBase, //公司职务管理
|
|
|
M_ENTERPRISE_EMPLOYEE_ROLE: NewPermissionOptionBase, //员工角色/权限设置
|
|
|
M_ENTERPRISE_EMPLOYEE: NewPermissionOptionBase, //公司员工管理
|
|
|
M_ENTERPRISE: NewPermissionOptionBase, //企业基础设置(大节点)
|
|
|
M_SYSTEM: NewPermissionOptionBase, //系统设置(大节点)
|
|
|
M_ENTERPRISE_PROFILE: NewPermissionOptionBase, //企业信息维护
|
|
|
M_SYSTEM_OPPORTUNITY_TEMPLATE: NewPermissionOptionBase, //机会模板管理
|
|
|
M_SYSTEM_RATING: NewPermissionOptionBase, //评分模式
|
|
|
M_SYSTEM_OPPORTUNITY: NewPermissionOptionBase, //机会管理
|
|
|
} |
...
|
...
|
|