正在显示
5 个修改的文件
包含
83 行增加
和
7 行删除
@@ -231,9 +231,12 @@ func (c *RbacController) MenuList() { | @@ -231,9 +231,12 @@ func (c *RbacController) MenuList() { | ||
231 | defer func() { | 231 | defer func() { |
232 | c.ResposeJson(msg) | 232 | c.ResposeJson(msg) |
233 | }() | 233 | }() |
234 | + userid := c.GetUserId() | ||
235 | + companyid := c.GetCompanyId() | ||
234 | list, err := serverbac.GetMenuAll() | 236 | list, err := serverbac.GetMenuAll() |
237 | + menulist := serverbac.FilterMenuByRole(list, userid, companyid) | ||
235 | data := protocol.ResponsePermissionList{ | 238 | data := protocol.ResponsePermissionList{ |
236 | - Lists: list, | 239 | + Lists: menulist, |
237 | } | 240 | } |
238 | msg = protocol.NewReturnResponse(data, err) | 241 | msg = protocol.NewReturnResponse(data, err) |
239 | return | 242 | return |
@@ -214,3 +214,30 @@ func GetCompanyDefaultRole(companyid int64) (*Role, error) { | @@ -214,3 +214,30 @@ func GetCompanyDefaultRole(companyid int64) (*Role, error) { | ||
214 | One(r) | 214 | One(r) |
215 | return r, err | 215 | return r, err |
216 | } | 216 | } |
217 | + | ||
218 | +func GetCompanyDefaultRoleGroup(companyid int64) (*Role, error) { | ||
219 | + r := &Role{} | ||
220 | + o := orm.NewOrm() | ||
221 | + err := o.QueryTable(&Role{}). | ||
222 | + Filter("company_id", companyid). | ||
223 | + Filter("types", ROLETYPES_GROUP). | ||
224 | + Filter("is_default", ROLE_DEFAULR). | ||
225 | + One(r) | ||
226 | + return r, err | ||
227 | +} | ||
228 | + | ||
229 | +func GetUserRoleByUser(usecompanyid int64) ([]Role, error) { | ||
230 | + sql := `SELECT a.id,a.pid,a.types,a.company_id FROM role AS a | ||
231 | + JOIN user_role AS b ON a.id= b.role_id | ||
232 | + WHERE a.delete_at=0 AND b.user_company_id =? ` | ||
233 | + var ( | ||
234 | + list []Role | ||
235 | + err error | ||
236 | + ) | ||
237 | + o := orm.NewOrm() | ||
238 | + _, err = o.Raw(sql, usecompanyid).QueryRows(&list) | ||
239 | + if err != nil { | ||
240 | + return list, err | ||
241 | + } | ||
242 | + return list, err | ||
243 | +} |
@@ -233,15 +233,15 @@ func departmentRelationUpdate(departUpdate *models.Department, newparent *models | @@ -233,15 +233,15 @@ func departmentRelationUpdate(departUpdate *models.Department, newparent *models | ||
233 | log.Error(e.Error()) | 233 | log.Error(e.Error()) |
234 | return protocol.NewErrWithMessage("10042") | 234 | return protocol.NewErrWithMessage("10042") |
235 | } | 235 | } |
236 | - //确认层级深度 | ||
237 | s := strings.TrimPrefix(departSubset[i].Relation, oldRelation) | 236 | s := strings.TrimPrefix(departSubset[i].Relation, oldRelation) |
238 | - n := strings.Split(s, "/") | ||
239 | - if len(n) >= 10 { | 237 | + //重建关系树 |
238 | + departSubset[i].Relation = strings.TrimSpace(fmt.Sprintf("%s%s", newRelation, s)) | ||
239 | + //确认层级深度 | ||
240 | + n := strings.Split(departSubset[i].Relation, "/") | ||
241 | + if len(n) > 10 { | ||
240 | o.Rollback() | 242 | o.Rollback() |
241 | return protocol.NewErrWithMessage("10046") | 243 | return protocol.NewErrWithMessage("10046") |
242 | } | 244 | } |
243 | - //重建关系树 | ||
244 | - departSubset[i].Relation = strings.TrimSpace(fmt.Sprintf("%s%s", newRelation, s)) | ||
245 | err = utils.ExecuteSQLWithOrmer(o, dataSql2, departSubset[i].Relation, departSubset[i].Id) | 245 | err = utils.ExecuteSQLWithOrmer(o, dataSql2, departSubset[i].Relation, departSubset[i].Id) |
246 | if err != nil { | 246 | if err != nil { |
247 | o.Rollback() | 247 | o.Rollback() |
@@ -27,6 +27,51 @@ func GetMenuAll() ([]protocol.PermissionItem, error) { | @@ -27,6 +27,51 @@ func GetMenuAll() ([]protocol.PermissionItem, error) { | ||
27 | return list, nil | 27 | return list, nil |
28 | } | 28 | } |
29 | 29 | ||
30 | +func FilterMenuByRole(allMenu []protocol.PermissionItem, userid int64, companyid int64) []protocol.PermissionItem { | ||
31 | + var newMenuList []protocol.PermissionItem | ||
32 | + ucompany, err := models.GetUserCompanyBy(userid, companyid) | ||
33 | + if err != nil { | ||
34 | + log.Error("获取用户数据失败:%s", err) | ||
35 | + return allMenu | ||
36 | + } | ||
37 | + rolegroup, err := models.GetCompanyDefaultRoleGroup(ucompany.Id) | ||
38 | + if err != nil { | ||
39 | + log.Error("获取默认的角色组失败:%s", err) | ||
40 | + return allMenu | ||
41 | + } | ||
42 | + rolelist, err := models.GetUserRoleByUser(ucompany.Id) | ||
43 | + if err != nil { | ||
44 | + log.Error("获取用户的角色失败:%s", err) | ||
45 | + return allMenu | ||
46 | + } | ||
47 | + var ( | ||
48 | + isIn bool = false | ||
49 | + ) | ||
50 | + for i := range rolelist { | ||
51 | + if rolelist[i].Pid == rolegroup.Id { | ||
52 | + isIn = true | ||
53 | + } | ||
54 | + } | ||
55 | + if isIn { | ||
56 | + return allMenu | ||
57 | + } | ||
58 | + codeMap := map[string]int{ | ||
59 | + M_ENTERPRISE: 1, | ||
60 | + M_ENTERPRISE_PROFILE: 1, | ||
61 | + M_ENTERPRISE_ORGANIZATION: 1, | ||
62 | + M_ENTERPRISE_EMPLOYEE_POST: 1, | ||
63 | + M_ENTERPRISE_EMPLOYEE_ROLE: 1, | ||
64 | + M_ENTERPRISE_EMPLOYEE: 1, | ||
65 | + } | ||
66 | + for i, v := range allMenu { | ||
67 | + if _, ok := codeMap[v.Code]; ok { | ||
68 | + continue | ||
69 | + } | ||
70 | + newMenuList = append(newMenuList, allMenu[i]) | ||
71 | + } | ||
72 | + return newMenuList | ||
73 | +} | ||
74 | + | ||
30 | func GetRoleHasMenu(roleid int64, companyid int64) (*protocol.ResponseRoleMenus, error) { | 75 | func GetRoleHasMenu(roleid int64, companyid int64) (*protocol.ResponseRoleMenus, error) { |
31 | var ( | 76 | var ( |
32 | roleData *models.Role | 77 | roleData *models.Role |
@@ -143,7 +143,7 @@ func RoleEdit(param protocol.RequestRoleEdit) (*protocol.ResponseRoleInfo, error | @@ -143,7 +143,7 @@ func RoleEdit(param protocol.RequestRoleEdit) (*protocol.ResponseRoleInfo, error | ||
143 | } | 143 | } |
144 | //获取原来的父级 | 144 | //获取原来的父级 |
145 | var oldParent *models.Role | 145 | var oldParent *models.Role |
146 | - oldParent, err = models.GetRoleById(param.Pid) | 146 | + oldParent, err = models.GetRoleById(roleinfo.Pid) |
147 | if err != nil { | 147 | if err != nil { |
148 | log.Error("获取旧父级数据失败;%s", err) | 148 | log.Error("获取旧父级数据失败;%s", err) |
149 | return nil, protocol.NewErrWithMessage("1") | 149 | return nil, protocol.NewErrWithMessage("1") |
@@ -153,6 +153,7 @@ func RoleEdit(param protocol.RequestRoleEdit) (*protocol.ResponseRoleInfo, error | @@ -153,6 +153,7 @@ func RoleEdit(param protocol.RequestRoleEdit) (*protocol.ResponseRoleInfo, error | ||
153 | return nil, protocol.NewErrWithMessage("10082") | 153 | return nil, protocol.NewErrWithMessage("10082") |
154 | } | 154 | } |
155 | } | 155 | } |
156 | + //..... | ||
156 | roleinfo.Pid = param.Pid | 157 | roleinfo.Pid = param.Pid |
157 | 158 | ||
158 | if err = models.UpdateRoleById(roleinfo, []string{"Descript", "Name", "Pid"}); err != nil { | 159 | if err = models.UpdateRoleById(roleinfo, []string{"Descript", "Name", "Pid"}); err != nil { |
-
请 注册 或 登录 后发表评论