正在显示
7 个修改的文件
包含
230 行增加
和
137 行删除
@@ -215,11 +215,11 @@ func (c *AuthController) Me() { | @@ -215,11 +215,11 @@ func (c *AuthController) Me() { | ||
215 | } | 215 | } |
216 | menus, err := serveauth.GetUserHasMenu(userid, companyid) | 216 | menus, err := serveauth.GetUserHasMenu(userid, companyid) |
217 | if err != nil { | 217 | if err != nil { |
218 | - log.Error("获取用户菜单") | 218 | + log.Error("获取用户菜单失败") |
219 | } | 219 | } |
220 | companys, err := serveauth.UserHasCompanys(userid) | 220 | companys, err := serveauth.UserHasCompanys(userid) |
221 | if err != nil { | 221 | if err != nil { |
222 | - log.Error("获取用户的公司") | 222 | + log.Error("获取用户的公司失败") |
223 | } | 223 | } |
224 | data := map[string]interface{}{ | 224 | data := map[string]interface{}{ |
225 | "user": userinfo, | 225 | "user": userinfo, |
@@ -261,18 +261,6 @@ func (c *RbacController) RoleHasMenu() { | @@ -261,18 +261,6 @@ func (c *RbacController) RoleHasMenu() { | ||
261 | return | 261 | return |
262 | } | 262 | } |
263 | 263 | ||
264 | -//TODO | ||
265 | -func (c *RbacController) GetRoleMenuAll() { | ||
266 | - var msg *protocol.ResponseMessage | ||
267 | - defer func() { | ||
268 | - c.ResposeJson(msg) | ||
269 | - }() | ||
270 | - log.Info("====>") | ||
271 | - list, err := serverbac.GetRoleHasMenuAll(1, 1) | ||
272 | - msg = protocol.NewReturnResponse(list, err) | ||
273 | - return | ||
274 | -} | ||
275 | - | ||
276 | //RoleMenuEdit 设置角色的菜单 | 264 | //RoleMenuEdit 设置角色的菜单 |
277 | //@router /role/menu/edit | 265 | //@router /role/menu/edit |
278 | func (c *RbacController) RoleMenuEdit() { | 266 | func (c *RbacController) RoleMenuEdit() { |
@@ -64,20 +64,6 @@ func AddUserRole(m *UserRole, om ...orm.Ormer) (id int64, err error) { | @@ -64,20 +64,6 @@ func AddUserRole(m *UserRole, om ...orm.Ormer) (id int64, err error) { | ||
64 | return | 64 | return |
65 | } | 65 | } |
66 | 66 | ||
67 | -func GetUserRole(userid, companyid int64) ([]*UserRole, error) { | ||
68 | - o := orm.NewOrm() | ||
69 | - var ( | ||
70 | - err error | ||
71 | - result []*UserRole | ||
72 | - ) | ||
73 | - _, err = o.QueryTable(&UserRole{}). | ||
74 | - Filter("user_id", userid). | ||
75 | - Filter("company_id", companyid). | ||
76 | - Filter("enable_status", 1). | ||
77 | - All(&result) | ||
78 | - return result, err | ||
79 | -} | ||
80 | - | ||
81 | func CountUserRoleByRole(roleid int64) (int64, error) { | 67 | func CountUserRoleByRole(roleid int64) (int64, error) { |
82 | var ( | 68 | var ( |
83 | cnt int64 | 69 | cnt int64 |
@@ -329,10 +329,50 @@ func UserHasCompanys(userid int64) ([]protocol.MeCompany, error) { | @@ -329,10 +329,50 @@ func UserHasCompanys(userid int64) ([]protocol.MeCompany, error) { | ||
329 | } | 329 | } |
330 | 330 | ||
331 | func GetUserHasMenu(userid, companyid int64) ([]protocol.PermissionItem, error) { | 331 | func GetUserHasMenu(userid, companyid int64) ([]protocol.PermissionItem, error) { |
332 | + var ( | ||
333 | + list = make([]protocol.PermissionItem, 0) | ||
334 | + err error | ||
335 | + companyinfo *models.Company | ||
336 | + ucompany *models.UserCompany | ||
337 | + ) | ||
338 | + companyinfo, err = models.GetCompanyById(companyid) | ||
339 | + if companyinfo.AdminId == userid { | ||
340 | + return getAdminHasMenu() | ||
341 | + } | ||
342 | + //非主管人员 | ||
343 | + ucompany, err = models.GetUserCompanyBy(userid, companyid) | ||
344 | + if err != nil { | ||
345 | + log.Error("user_company数据获取失败:%s", err) | ||
346 | + return list, protocol.NewErrWithMessage("1") | ||
347 | + } | ||
348 | + const datasql string = `SELECT DISTINCT(a.menu_id) | ||
349 | + FROM role_menu AS a | ||
350 | + JOIN user_role AS b ON a.role_id = b.role_id | ||
351 | + JOIN role AS c ON a.role_id = c.id | ||
352 | + WHERE b.user_company_id=? AND c.delete_at =0 ` | ||
353 | + var menuids []string | ||
354 | + err = utils.ExecuteQueryAll(&menuids, datasql, ucompany.Id) | ||
355 | + if err != nil { | ||
356 | + log.Error("EXECUTE SQL err:%s", err) | ||
357 | + return nil, protocol.NewErrWithMessage("1") | ||
358 | + } | ||
359 | + datasql2 := `SELECT id,name,icon,parent_id,senior_status,sort,code | ||
360 | + FROM menu WHERE enabled=1 AND id in(%s) ORDER BY sort` | ||
361 | + datasql2 = fmt.Sprintf(datasql2, strings.Join(menuids, ",")) | ||
362 | + err = utils.ExecuteQueryAll(&list, datasql2) | ||
363 | + if err != nil { | ||
364 | + log.Error("EXECUTE SQL err:%s", err) | ||
365 | + return nil, protocol.NewErrWithMessage("1") | ||
366 | + } | ||
367 | + return list, nil | ||
368 | +} | ||
369 | + | ||
370 | +//主管拥有全部的菜单 | ||
371 | +func getAdminHasMenu() ([]protocol.PermissionItem, error) { | ||
332 | const datasql string = `SELECT id,name,icon,parent_id,senior_status,sort,code | 372 | const datasql string = `SELECT id,name,icon,parent_id,senior_status,sort,code |
333 | FROM menu WHERE enabled=1 ORDER BY sort ` | 373 | FROM menu WHERE enabled=1 ORDER BY sort ` |
334 | var ( | 374 | var ( |
335 | - list []protocol.PermissionItem | 375 | + list = make([]protocol.PermissionItem, 0) |
336 | err error | 376 | err error |
337 | ) | 377 | ) |
338 | err = utils.ExecuteQueryAll(&list, datasql) | 378 | err = utils.ExecuteQueryAll(&list, datasql) |
1 | package rbac | 1 | package rbac |
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | + "encoding/json" | ||
4 | "fmt" | 5 | "fmt" |
5 | "oppmg/common/log" | 6 | "oppmg/common/log" |
6 | "oppmg/models" | 7 | "oppmg/models" |
@@ -65,46 +66,46 @@ func GetRoleHasMenu(roleid int64, companyid int64) (*protocol.ResponseRoleMenus, | @@ -65,46 +66,46 @@ func GetRoleHasMenu(roleid int64, companyid int64) (*protocol.ResponseRoleMenus, | ||
65 | return data, nil | 66 | return data, nil |
66 | } | 67 | } |
67 | 68 | ||
68 | -func GetRoleHasMenuAll(roleid int64, companyid int64) (map[string]PermissionContentObject, error) { | ||
69 | - var ( | ||
70 | - roleData *models.Role | ||
71 | - err error | ||
72 | - ) | ||
73 | - roleData, err = models.GetRoleById(roleid) | ||
74 | - if err != nil { | ||
75 | - log.Error("获取角色数据失败:%s", err) | ||
76 | - return nil, err | ||
77 | - } | ||
78 | - if roleData.Types != models.ROLETYPES_ROLE { | ||
79 | - log.Error("角色类型错误") | ||
80 | - return nil, protocol.NewErrWithMessage("1") | ||
81 | - } | ||
82 | - if roleData.CompanyId != companyid { | ||
83 | - log.Error("角色的公司id不匹配") | ||
84 | - return nil, protocol.NewErrWithMessage("1") | ||
85 | - } | ||
86 | - var ( | ||
87 | - rolemenu []models.RoleMenu | ||
88 | - returnList = make(map[string]PermissionContentObject) | ||
89 | - ) | ||
90 | - rolemenu, err = models.GetRoleMenuByRole(roleid) | ||
91 | - if err != nil { | ||
92 | - log.Error("获取角色下的菜单数据失败:%s", err) | ||
93 | - return nil, protocol.NewErrWithMessage("1") | ||
94 | - } | ||
95 | - for _, v := range rolemenu { | ||
96 | - if fn, ok := CodePermissionObject[v.Code]; ok { | ||
97 | - obj := fn() | ||
98 | - err := obj.StringUnmarshal(v.Opption) | ||
99 | - if err != nil { | ||
100 | - log.Error("解析权限规则失败", err) | ||
101 | - continue | ||
102 | - } | ||
103 | - returnList[v.Code] = obj | ||
104 | - } | ||
105 | - } | ||
106 | - return returnList, nil | ||
107 | -} | 69 | +// func GetRoleHasMenuAll(roleid int64, companyid int64) (map[string]PermissionOptionObject, error) { |
70 | +// var ( | ||
71 | +// roleData *models.Role | ||
72 | +// err error | ||
73 | +// ) | ||
74 | +// roleData, err = models.GetRoleById(roleid) | ||
75 | +// if err != nil { | ||
76 | +// log.Error("获取角色数据失败:%s", err) | ||
77 | +// return nil, err | ||
78 | +// } | ||
79 | +// if roleData.Types != models.ROLETYPES_ROLE { | ||
80 | +// log.Error("角色类型错误") | ||
81 | +// return nil, protocol.NewErrWithMessage("1") | ||
82 | +// } | ||
83 | +// if roleData.CompanyId != companyid { | ||
84 | +// log.Error("角色的公司id不匹配") | ||
85 | +// return nil, protocol.NewErrWithMessage("1") | ||
86 | +// } | ||
87 | +// var ( | ||
88 | +// rolemenu []models.RoleMenu | ||
89 | +// returnList = make(map[string]PermissionOptionObject) | ||
90 | +// ) | ||
91 | +// rolemenu, err = models.GetRoleMenuByRole(roleid) | ||
92 | +// if err != nil { | ||
93 | +// log.Error("获取角色下的菜单数据失败:%s", err) | ||
94 | +// return nil, protocol.NewErrWithMessage("1") | ||
95 | +// } | ||
96 | +// for _, v := range rolemenu { | ||
97 | +// if fn, ok := CodePermissionObject[v.Code]; ok { | ||
98 | +// obj := fn() | ||
99 | +// err := json.Unmarshal([]byte(v.Opption), obj) | ||
100 | +// if err != nil { | ||
101 | +// log.Error("解析权限规则失败", err) | ||
102 | +// continue | ||
103 | +// } | ||
104 | +// returnList[v.Code] = obj | ||
105 | +// } | ||
106 | +// } | ||
107 | +// return returnList, nil | ||
108 | +// } | ||
108 | 109 | ||
109 | func RoleMenuEdit(companyid int64, roleId int64, menuids []int64) error { | 110 | func RoleMenuEdit(companyid int64, roleId int64, menuids []int64) error { |
110 | roleMenus, err := GetRoleHasMenu(roleId, companyid) | 111 | roleMenus, err := GetRoleHasMenu(roleId, companyid) |
@@ -140,12 +141,13 @@ func RoleMenuEdit(companyid int64, roleId int64, menuids []int64) error { | @@ -140,12 +141,13 @@ func RoleMenuEdit(companyid int64, roleId int64, menuids []int64) error { | ||
140 | return protocol.NewErrWithMessage("1") | 141 | return protocol.NewErrWithMessage("1") |
141 | } | 142 | } |
142 | } | 143 | } |
144 | + opptionbt, _ := json.Marshal(&PermissionOptionBase{Check: 1}) | ||
143 | for _, v := range addMenu { | 145 | for _, v := range addMenu { |
144 | m := models.RoleMenu{ | 146 | m := models.RoleMenu{ |
145 | RoleId: roleId, | 147 | RoleId: roleId, |
146 | MenuId: v.Id, | 148 | MenuId: v.Id, |
147 | Code: v.Code, | 149 | Code: v.Code, |
148 | - Opption: "{}", | 150 | + Opption: string(opptionbt), |
149 | } | 151 | } |
150 | if _, err = o.Insert(&m); err != nil { | 152 | if _, err = o.Insert(&m); err != nil { |
151 | log.Error("添加角色和菜单关系失败:%s", err) | 153 | log.Error("添加角色和菜单关系失败:%s", err) |
1 | package rbac | 1 | package rbac |
2 | 2 | ||
3 | -import ( | ||
4 | - "encoding/json" | ||
5 | -) | ||
6 | - | ||
7 | -//PermissionBase 路由对应的权限 | ||
8 | -type PermissionBase struct { | ||
9 | - CodeName string //模块标识 | ||
10 | - ActionName string | ||
11 | - MethodMap map[string]func() | ||
12 | -} | ||
13 | - | ||
14 | -var routerPermission = map[string]PermissionBase{ | ||
15 | - "/v1/department/list": PermissionBase{CodeName: "OPPMG_DEPARTMENT", ActionName: "check"}, | ||
16 | - "/v1/department/add": PermissionBase{CodeName: "OPPMG_DEPARTMENT", ActionName: "add"}, | ||
17 | - "/v1/department/edit": PermissionBase{CodeName: "OPPMG_DEPARTMENT", ActionName: "edit"}, | ||
18 | - "/v1/department/delete": PermissionBase{CodeName: "OPPMG_DEPARTMENT", ActionName: "delete"}, | ||
19 | -} | ||
20 | - | ||
21 | -var permissionObject = map[string]interface{}{ | ||
22 | - "": 0, | ||
23 | -} | ||
24 | - | ||
25 | //模块编号 | 3 | //模块编号 |
26 | const ( | 4 | const ( |
27 | M_ENTERPRISE string = "ENTERPRISE" //企业基础设置 | 5 | M_ENTERPRISE string = "ENTERPRISE" //企业基础设置 |
@@ -37,56 +15,31 @@ const ( | @@ -37,56 +15,31 @@ const ( | ||
37 | M_SYSTEM_ANNOUNCEMENT string = "SYSTEM_ANNOUNCEMENT" //公告管理 | 15 | M_SYSTEM_ANNOUNCEMENT string = "SYSTEM_ANNOUNCEMENT" //公告管理 |
38 | ) | 16 | ) |
39 | 17 | ||
40 | -type PermissionContentObject interface { | ||
41 | - StringUnmarshal(string) error | ||
42 | - ObjectMarshal() (string, error) | 18 | +type PermissionOptionObject interface { |
19 | + // StringUnmarshal(string) error | ||
20 | + // ObjectMarshal() string | ||
21 | + GetValidFunc(string) func(UserObject) bool | ||
43 | } | 22 | } |
44 | 23 | ||
45 | -type UserObject struct { | ||
46 | - UserId int64 `json:"user_id"` | ||
47 | - CompanyId int64 `json:"company_id"` | ||
48 | - UserCompanyId int64 `json:"user_company_id"` | ||
49 | -} | ||
50 | - | ||
51 | -type PermissionContentBase struct { | ||
52 | - Check int8 `json:"check"` | ||
53 | -} | ||
54 | - | ||
55 | -func (p *PermissionContentBase) ValidDefault(obj UserObject) bool { | ||
56 | - if p.Check == 1 { | ||
57 | - return true | ||
58 | - } | ||
59 | - return false | ||
60 | -} | ||
61 | - | ||
62 | -func NewPermissionContentBase() PermissionContentObject { | ||
63 | - return &PermissionContentBase{} | ||
64 | -} | ||
65 | - | ||
66 | -func (p *PermissionContentBase) StringUnmarshal(s string) error { | ||
67 | - err := json.Unmarshal([]byte(s), p) | ||
68 | - return err | 24 | +//PermissionBase 路由对应的权限 |
25 | +type PermissionBase struct { | ||
26 | + CodeName string //模块标识 | ||
27 | + ActionName string | ||
69 | } | 28 | } |
70 | 29 | ||
71 | -func (p *PermissionContentBase) ObjectMarshal() (string, error) { | ||
72 | - bt, err := json.Marshal(p) | ||
73 | - if err != nil { | ||
74 | - return "", err | ||
75 | - } | ||
76 | - return string(bt), err | ||
77 | -} | 30 | +var routerPermission = map[string]PermissionBase{} |
78 | 31 | ||
79 | -type CodeToObject func() PermissionContentObject | 32 | +type CodeToObject func() PermissionOptionObject |
80 | 33 | ||
81 | var CodePermissionObject = map[string]CodeToObject{ | 34 | var CodePermissionObject = map[string]CodeToObject{ |
82 | - M_ENTERPRISE_ORGANIZATION: NewPermissionContentBase, //公司组织架构设置 | ||
83 | - M_ENTERPRISE_EMPLOYEE_POST: NewPermissionContentBase, //公司职务管理 | ||
84 | - M_ENTERPRISE_EMPLOYEE_ROLE: NewPermissionContentBase, //员工角色/权限设置 | ||
85 | - M_ENTERPRISE_EMPLOYEE: NewPermissionContentBase, //公司员工管理 | ||
86 | - M_ENTERPRISE: NewPermissionContentBase, //企业基础设置(大节点) | ||
87 | - M_SYSTEM: NewPermissionContentBase, //系统设置(大节点) | ||
88 | - M_ENTERPRISE_PROFILE: NewPermissionContentBase, //企业信息维护 | ||
89 | - M_SYSTEM_OPPORTUNITY_TEMPLATE: NewPermissionContentBase, //机会模板管理 | ||
90 | - M_SYSTEM_RATING: NewPermissionContentBase, //评分模式 | ||
91 | - M_SYSTEM_OPPORTUNITY: NewPermissionContentBase, //机会管理 | 35 | + M_ENTERPRISE_ORGANIZATION: NewPermissionOptionBase, //公司组织架构设置 |
36 | + M_ENTERPRISE_EMPLOYEE_POST: NewPermissionOptionBase, //公司职务管理 | ||
37 | + M_ENTERPRISE_EMPLOYEE_ROLE: NewPermissionOptionBase, //员工角色/权限设置 | ||
38 | + M_ENTERPRISE_EMPLOYEE: NewPermissionOptionBase, //公司员工管理 | ||
39 | + M_ENTERPRISE: NewPermissionOptionBase, //企业基础设置(大节点) | ||
40 | + M_SYSTEM: NewPermissionOptionBase, //系统设置(大节点) | ||
41 | + M_ENTERPRISE_PROFILE: NewPermissionOptionBase, //企业信息维护 | ||
42 | + M_SYSTEM_OPPORTUNITY_TEMPLATE: NewPermissionOptionBase, //机会模板管理 | ||
43 | + M_SYSTEM_RATING: NewPermissionOptionBase, //评分模式 | ||
44 | + M_SYSTEM_OPPORTUNITY: NewPermissionOptionBase, //机会管理 | ||
92 | } | 45 | } |
services/rbac/permission_obj.go
0 → 100644
1 | +package rbac | ||
2 | + | ||
3 | +import "encoding/json" | ||
4 | + | ||
5 | +type UserObject struct { | ||
6 | + UserId int64 `json:"user_id"` | ||
7 | + CompanyId int64 `json:"company_id"` | ||
8 | + UserCompanyId int64 `json:"user_company_id"` | ||
9 | +} | ||
10 | + | ||
11 | +//PermissionOptionBase 基本权限 | ||
12 | +type PermissionOptionBase struct { | ||
13 | + Check int8 `json:"check"` | ||
14 | +} | ||
15 | + | ||
16 | +var ( | ||
17 | + _ PermissionOptionObject = &PermissionOptionBase{} | ||
18 | +) | ||
19 | + | ||
20 | +func NewPermissionOptionBase() PermissionOptionObject { | ||
21 | + return &PermissionOptionBase{} | ||
22 | +} | ||
23 | + | ||
24 | +func (p *PermissionOptionBase) ValidDefault(obj UserObject) bool { | ||
25 | + if p.Check == 1 { | ||
26 | + return true | ||
27 | + } | ||
28 | + return false | ||
29 | +} | ||
30 | + | ||
31 | +//GetValidFunc PermissionOptionBase 接口实现 | ||
32 | +func (p *PermissionOptionBase) GetValidFunc(k string) func(UserObject) bool { | ||
33 | + m := map[string]func(UserObject) bool{ | ||
34 | + "default": p.ValidDefault, | ||
35 | + } | ||
36 | + if _, ok := m[k]; ok { | ||
37 | + return m[k] | ||
38 | + } | ||
39 | + return nil | ||
40 | +} | ||
41 | + | ||
42 | +//StringUnmarshal PermissionOptionBase 接口实现 | ||
43 | +func (p *PermissionOptionBase) StringUnmarshal(s string) error { | ||
44 | + err := json.Unmarshal([]byte(s), p) | ||
45 | + return err | ||
46 | +} | ||
47 | + | ||
48 | +//ObjectMarshal PermissionOptionBase 接口实现 | ||
49 | +func (p *PermissionOptionBase) ObjectMarshal() string { | ||
50 | + bt, err := json.Marshal(p) | ||
51 | + if err != nil { | ||
52 | + return "" | ||
53 | + } | ||
54 | + return string(bt) | ||
55 | +} | ||
56 | + | ||
57 | +/* | ||
58 | +机会管理模块 | ||
59 | +CheckOpp | ||
60 | +CheckDeparment | ||
61 | +OptionOpportunity | ||
62 | +*/ | ||
63 | +//CheckOpp 特殊的查看条件设定 | ||
64 | +type CheckOpp struct { | ||
65 | + Departments []CheckDeparment `json:"departments"` | ||
66 | +} | ||
67 | + | ||
68 | +//CheckDeparment 特殊的查看条件设定中关于部门的设定 | ||
69 | +type CheckDeparment struct { | ||
70 | + Id int64 `json:"id"` | ||
71 | + Wait int `json:"wail"` | ||
72 | + OpenAll int `json:"open_all"` | ||
73 | + OpenDepart int `json:"open_depart"` | ||
74 | +} | ||
75 | + | ||
76 | +//OptionOpportunity 机会管理 高级权限设置 | ||
77 | +type OptionOpportunity struct { | ||
78 | + Check int `json:"check"` | ||
79 | + CheckOption CheckOpp | ||
80 | + EditSorce int `json:"edit_sorce"` | ||
81 | + EditPublicStatus int `json:"edit_public_status"` | ||
82 | + CloseChance int `json:"close_chance"` | ||
83 | +} | ||
84 | + | ||
85 | +var ( | ||
86 | + _ PermissionOptionObject = &OptionOpportunity{} | ||
87 | +) | ||
88 | + | ||
89 | +func NewOptionOpportunity() PermissionOptionObject { | ||
90 | + return &OptionOpportunity{} | ||
91 | +} | ||
92 | + | ||
93 | +func (p *OptionOpportunity) ValidDefault(obj UserObject) bool { | ||
94 | + if p.Check == 1 { | ||
95 | + return true | ||
96 | + } | ||
97 | + return false | ||
98 | +} | ||
99 | + | ||
100 | +//GetValidFunc PermissionOptionBase 接口实现 | ||
101 | +func (p *OptionOpportunity) GetValidFunc(k string) func(UserObject) bool { | ||
102 | + m := map[string]func(UserObject) bool{ | ||
103 | + "default": p.ValidDefault, | ||
104 | + } | ||
105 | + if _, ok := m[k]; ok { | ||
106 | + return m[k] | ||
107 | + } | ||
108 | + return nil | ||
109 | +} | ||
110 | + | ||
111 | +//StringUnmarshal PermissionOptionBase 接口实现 | ||
112 | +func (p *OptionOpportunity) StringUnmarshal(s string) error { | ||
113 | + err := json.Unmarshal([]byte(s), p) | ||
114 | + return err | ||
115 | +} | ||
116 | + | ||
117 | +//ObjectMarshal PermissionOptionBase 接口实现 | ||
118 | +func (p *OptionOpportunity) ObjectMarshal() string { | ||
119 | + bt, err := json.Marshal(p) | ||
120 | + if err != nil { | ||
121 | + return "" | ||
122 | + } | ||
123 | + return string(bt) | ||
124 | +} |
-
请 注册 或 登录 后发表评论