Merge branch 'dev' of http://gitlab.fjmaimaimai.com/mmm-go/oppmg into dev
正在显示
11 个修改的文件
包含
135 行增加
和
44 行删除
| @@ -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 | +} |
| @@ -175,6 +175,9 @@ func BulletinList(uid, companyId int64, request *protocol.BulletinListRequest) ( | @@ -175,6 +175,9 @@ func BulletinList(uid, companyId int64, request *protocol.BulletinListRequest) ( | ||
| 175 | list []*models.Bulletin | 175 | list []*models.Bulletin |
| 176 | total int | 176 | total int |
| 177 | ) | 177 | ) |
| 178 | + rsp = &protocol.BulletinListResponse{ | ||
| 179 | + List: make([]*protocol.BulletinItem, 0), | ||
| 180 | + } | ||
| 178 | if request.PageIndex == 0 { | 181 | if request.PageIndex == 0 { |
| 179 | request.PageIndex += 1 | 182 | request.PageIndex += 1 |
| 180 | } | 183 | } |
| @@ -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() |
| @@ -149,7 +149,7 @@ func PositionEdit(param protocol.RequestPositionEdit) (*protocol.ResponsePositio | @@ -149,7 +149,7 @@ func PositionEdit(param protocol.RequestPositionEdit) (*protocol.ResponsePositio | ||
| 149 | if err != nil { | 149 | if err != nil { |
| 150 | e := fmt.Errorf("positionRelationUpdate err:%s", err) | 150 | e := fmt.Errorf("positionRelationUpdate err:%s", err) |
| 151 | log.Error(e.Error()) | 151 | log.Error(e.Error()) |
| 152 | - return nil, protocol.NewErrWithMessage("1", e) | 152 | + return nil, err |
| 153 | } | 153 | } |
| 154 | } | 154 | } |
| 155 | positioninfo = &protocol.ResponsePositionInfo{ | 155 | positioninfo = &protocol.ResponsePositionInfo{ |
| @@ -217,12 +217,12 @@ func positionRelationUpdate(positionUpdate *models.Position, newparent *models.P | @@ -217,12 +217,12 @@ func positionRelationUpdate(positionUpdate *models.Position, newparent *models.P | ||
| 217 | } | 217 | } |
| 218 | //重建关系树 | 218 | //重建关系树 |
| 219 | s := strings.TrimPrefix(positionSubset[i].Relation, oldRelation) | 219 | s := strings.TrimPrefix(positionSubset[i].Relation, oldRelation) |
| 220 | - rs := strings.Split(s, "/") | ||
| 221 | - if len(rs) >= 10 { //层级不能超过10级 | 220 | + positionSubset[i].Relation = strings.TrimSpace(fmt.Sprintf("%s%s", newRelation, s)) |
| 221 | + rs := strings.Split(positionSubset[i].Relation, "/") | ||
| 222 | + if len(rs) > 10 { //层级不能超过10级 | ||
| 222 | o.Rollback() | 223 | o.Rollback() |
| 223 | return protocol.NewErrWithMessage("10012") | 224 | return protocol.NewErrWithMessage("10012") |
| 224 | } | 225 | } |
| 225 | - positionSubset[i].Relation = strings.TrimSpace(fmt.Sprintf("%s%s", newRelation, s)) | ||
| 226 | err = utils.ExecuteSQLWithOrmer(o, dataSql2, positionSubset[i].Relation, positionSubset[i].Id) | 226 | err = utils.ExecuteSQLWithOrmer(o, dataSql2, positionSubset[i].Relation, positionSubset[i].Id) |
| 227 | if err != nil { | 227 | if err != nil { |
| 228 | o.Rollback() | 228 | o.Rollback() |
| @@ -526,7 +526,9 @@ func UserList(param protocol.RequestUserList) (protocol.ResponseUserList, error) | @@ -526,7 +526,9 @@ func UserList(param protocol.RequestUserList) (protocol.ResponseUserList, error) | ||
| 526 | result []protocol.UserListItem | 526 | result []protocol.UserListItem |
| 527 | pageInfo protocol.ResponsePageInfo | 527 | pageInfo protocol.ResponsePageInfo |
| 528 | err error | 528 | err error |
| 529 | - responseData protocol.ResponseUserList | 529 | + responseData = protocol.ResponseUserList{ |
| 530 | + List: make([]protocol.UserListItem, 0), | ||
| 531 | + } | ||
| 530 | ) | 532 | ) |
| 531 | p := utils.NewQueryDataByPage(countSql+whereString, datasql+whereString) | 533 | p := utils.NewQueryDataByPage(countSql+whereString, datasql+whereString) |
| 532 | p.AddParam(cond...) | 534 | p.AddParam(cond...) |
| @@ -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.CompanyId) | ||
| 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 |
| @@ -23,8 +23,8 @@ const ( | @@ -23,8 +23,8 @@ const ( | ||
| 23 | ) | 23 | ) |
| 24 | 24 | ||
| 25 | type PermissionOptionObject interface { | 25 | type PermissionOptionObject interface { |
| 26 | - // StringUnmarshal(string) error | ||
| 27 | - // ObjectMarshal() string | 26 | + StringUnmarshal(string) error |
| 27 | + ObjectMarshal() string | ||
| 28 | GetValidFunc(string) bool | 28 | GetValidFunc(string) bool |
| 29 | MergeObject(string) error | 29 | MergeObject(string) error |
| 30 | } | 30 | } |
| @@ -56,20 +56,20 @@ func (p *PermissionOptionBase) MergeObject(jsonString string) error { | @@ -56,20 +56,20 @@ func (p *PermissionOptionBase) MergeObject(jsonString string) error { | ||
| 56 | return nil | 56 | return nil |
| 57 | } | 57 | } |
| 58 | 58 | ||
| 59 | -// //StringUnmarshal PermissionOptionBase 接口实现 | ||
| 60 | -// func (p *PermissionOptionBase) StringUnmarshal(s string) error { | ||
| 61 | -// err := json.Unmarshal([]byte(s), p) | ||
| 62 | -// return err | ||
| 63 | -// } | ||
| 64 | - | ||
| 65 | -// //ObjectMarshal PermissionOptionBase 接口实现 | ||
| 66 | -// func (p *PermissionOptionBase) ObjectMarshal() string { | ||
| 67 | -// bt, err := json.Marshal(p) | ||
| 68 | -// if err != nil { | ||
| 69 | -// return "" | ||
| 70 | -// } | ||
| 71 | -// return string(bt) | ||
| 72 | -// } | 59 | +//StringUnmarshal PermissionOptionBase 接口实现 |
| 60 | +func (p *PermissionOptionBase) StringUnmarshal(s string) error { | ||
| 61 | + err := json.Unmarshal([]byte(s), p) | ||
| 62 | + return err | ||
| 63 | +} | ||
| 64 | + | ||
| 65 | +//ObjectMarshal PermissionOptionBase 接口实现 | ||
| 66 | +func (p *PermissionOptionBase) ObjectMarshal() string { | ||
| 67 | + bt, err := json.Marshal(p) | ||
| 68 | + if err != nil { | ||
| 69 | + return "" | ||
| 70 | + } | ||
| 71 | + return string(bt) | ||
| 72 | +} | ||
| 73 | 73 | ||
| 74 | /* | 74 | /* |
| 75 | 机会管理模块 | 75 | 机会管理模块 |
| @@ -233,17 +233,17 @@ func (p *OptionOpportunity) ValidCloseChance() bool { | @@ -233,17 +233,17 @@ func (p *OptionOpportunity) ValidCloseChance() bool { | ||
| 233 | return false | 233 | return false |
| 234 | } | 234 | } |
| 235 | 235 | ||
| 236 | -// //StringUnmarshal PermissionOptionBase 接口实现 | ||
| 237 | -// func (p *OptionOpportunity) StringUnmarshal(s string) error { | ||
| 238 | -// err := json.Unmarshal([]byte(s), p) | ||
| 239 | -// return err | ||
| 240 | -// } | ||
| 241 | - | ||
| 242 | -// //ObjectMarshal PermissionOptionBase 接口实现 | ||
| 243 | -// func (p *OptionOpportunity) ObjectMarshal() string { | ||
| 244 | -// bt, err := json.Marshal(p) | ||
| 245 | -// if err != nil { | ||
| 246 | -// return "" | ||
| 247 | -// } | ||
| 248 | -// return string(bt) | ||
| 249 | -// } | 236 | +//StringUnmarshal PermissionOptionBase 接口实现 |
| 237 | +func (p *OptionOpportunity) StringUnmarshal(s string) error { | ||
| 238 | + err := json.Unmarshal([]byte(s), p) | ||
| 239 | + return err | ||
| 240 | +} | ||
| 241 | + | ||
| 242 | +//ObjectMarshal PermissionOptionBase 接口实现 | ||
| 243 | +func (p *OptionOpportunity) ObjectMarshal() string { | ||
| 244 | + bt, err := json.Marshal(p) | ||
| 245 | + if err != nil { | ||
| 246 | + return "" | ||
| 247 | + } | ||
| 248 | + return string(bt) | ||
| 249 | +} |
| @@ -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 { |
| @@ -148,11 +148,21 @@ func ExistUserPermission(userid int64) bool { | @@ -148,11 +148,21 @@ func ExistUserPermission(userid int64) bool { | ||
| 148 | func GetUserPermissionAll(userid int64) (map[string]rbac.PermissionOptionObject, error) { | 148 | func GetUserPermissionAll(userid int64) (map[string]rbac.PermissionOptionObject, error) { |
| 149 | key := GetKeyUserPermission(userid) | 149 | key := GetKeyUserPermission(userid) |
| 150 | client := redis.GetRedis() | 150 | client := redis.GetRedis() |
| 151 | - str, err := client.Get(key).Result() | 151 | + strMap, err := client.HGetAll(key).Result() |
| 152 | if err != nil { | 152 | if err != nil { |
| 153 | return nil, err | 153 | return nil, err |
| 154 | } | 154 | } |
| 155 | permissionObj := make(map[string]rbac.PermissionOptionObject) | 155 | permissionObj := make(map[string]rbac.PermissionOptionObject) |
| 156 | - err = json.Unmarshal([]byte(str), &permissionObj) | 156 | + for k, v := range strMap { |
| 157 | + fn, ok := rbac.CodePermissionObject[k] | ||
| 158 | + if !ok { | ||
| 159 | + continue | ||
| 160 | + } | ||
| 161 | + obj := fn() | ||
| 162 | + if err := obj.StringUnmarshal(v); err == nil { | ||
| 163 | + permissionObj[k] = obj | ||
| 164 | + } | ||
| 165 | + | ||
| 166 | + } | ||
| 157 | return permissionObj, err | 167 | return permissionObj, err |
| 158 | } | 168 | } |
-
请 注册 或 登录 后发表评论