作者 yangfu

权限修改

@@ -79,7 +79,7 @@ func DeleteUserDepartment(id int64) (err error) { @@ -79,7 +79,7 @@ func DeleteUserDepartment(id int64) (err error) {
79 func GetUserDepartments(id int64, companyId int64, v interface{}) (err error) { 79 func GetUserDepartments(id int64, companyId int64, v interface{}) (err error) {
80 o := orm.NewOrm() 80 o := orm.NewOrm()
81 sql := ` 81 sql := `
82 -select a.department_id,b.name,b.parent_id,b.managers,b.relation,a.create_time 82 +select a.department_id,b.name,b.parent_id,b.managers,b.relation,b.create_at create_time
83 from user_department a INNER JOIN department b on a.department_id = b.id 83 from user_department a INNER JOIN department b on a.department_id = b.id
84 where a.user_company_id =? and a.company_id =? and enable_status =1 and b.delete_at =0` 84 where a.user_company_id =? and a.company_id =? and enable_status =1 and b.delete_at =0`
85 if _, err = o.Raw(sql, id, companyId).QueryRows(v); err == nil { 85 if _, err = o.Raw(sql, id, companyId).QueryRows(v); err == nil {
@@ -78,7 +78,7 @@ func DeleteUserPosition(id int) (err error) { @@ -78,7 +78,7 @@ func DeleteUserPosition(id int) (err error) {
78 func GetUserPositions(id int64, companyId int64, v interface{}) (err error) { 78 func GetUserPositions(id int64, companyId int64, v interface{}) (err error) {
79 o := orm.NewOrm() 79 o := orm.NewOrm()
80 sql := ` 80 sql := `
81 -select a.position_id,b.name,b.relation,a.create_at 81 +select a.position_id,b.name,b.relation,b.create_at
82 from user_position a INNER JOIN position b on a.position_id = b.id 82 from user_position a INNER JOIN position b on a.position_id = b.id
83 where a.user_company_id =? and a.company_id =? and a.enable_status =1 and b.enable_status =1` 83 where a.user_company_id =? and a.company_id =? and a.enable_status =1 and b.enable_status =1`
84 if _, err = o.Raw(sql, id, companyId).QueryRows(v); err == nil { 84 if _, err = o.Raw(sql, id, companyId).QueryRows(v); err == nil {
@@ -197,26 +197,26 @@ func (p *OptionOpportunity) MergeObject(jsonString string) error { @@ -197,26 +197,26 @@ func (p *OptionOpportunity) MergeObject(jsonString string) error {
197 } 197 }
198 p.CheckMap[obj.Check] = 1 198 p.CheckMap[obj.Check] = 1
199 departMap := make(map[int64]*CheckDeparment) 199 departMap := make(map[int64]*CheckDeparment)
200 - for k := range p.CheckOption.Departments {  
201 - i := p.CheckOption.Departments[k].Id  
202 - departMap[i] = &p.CheckOption.Departments[k] 200 + for i := range p.CheckOption.Departments {
  201 + id := p.CheckOption.Departments[i].Id
  202 + departMap[id] = &p.CheckOption.Departments[i]
203 } 203 }
204 //列表合并 204 //列表合并
205 - for k := range obj.CheckOption.Departments {  
206 - i := obj.CheckOption.Departments[k].Id  
207 - if _, ok := departMap[i]; ok {  
208 - if obj.CheckOption.Departments[k].OpenAll > departMap[i].OpenAll {  
209 - departMap[i].OpenAll = obj.CheckOption.Departments[k].OpenAll 205 + for i := range obj.CheckOption.Departments {
  206 + id := obj.CheckOption.Departments[i].Id
  207 + if _, ok := departMap[id]; ok {
  208 + if obj.CheckOption.Departments[i].OpenAll > departMap[id].OpenAll {
  209 + departMap[id].OpenAll = obj.CheckOption.Departments[i].OpenAll
210 } 210 }
211 - if obj.CheckOption.Departments[k].OpenDepart > departMap[i].OpenDepart {  
212 - departMap[i].OpenDepart = obj.CheckOption.Departments[k].OpenDepart 211 + if obj.CheckOption.Departments[i].OpenDepart > departMap[id].OpenDepart {
  212 + departMap[id].OpenDepart = obj.CheckOption.Departments[i].OpenDepart
213 } 213 }
214 - if obj.CheckOption.Departments[k].Wait > departMap[i].Wait {  
215 - departMap[i].Wait = obj.CheckOption.Departments[k].Wait 214 + if obj.CheckOption.Departments[i].Wait > departMap[id].Wait {
  215 + departMap[id].Wait = obj.CheckOption.Departments[i].Wait
216 } 216 }
217 } else { 217 } else {
218 218
219 - departMap[i] = &obj.CheckOption.Departments[k] 219 + departMap[id] = &obj.CheckOption.Departments[i]
220 220
221 } 221 }
222 } 222 }
@@ -297,7 +297,6 @@ func getUserPermission(userCompanyid int64) (map[string]PermissionOptionObject, @@ -297,7 +297,6 @@ func getUserPermission(userCompanyid int64) (map[string]PermissionOptionObject,
297 } else { 297 } else {
298 log.Error("未知code:%s", v.Code) 298 log.Error("未知code:%s", v.Code)
299 } 299 }
300 -  
301 } 300 }
302 return objMap, nil 301 return objMap, nil
303 } 302 }
@@ -305,7 +304,7 @@ func getUserPermission(userCompanyid int64) (map[string]PermissionOptionObject, @@ -305,7 +304,7 @@ func getUserPermission(userCompanyid int64) (map[string]PermissionOptionObject,
305 //获取用户权限 304 //获取用户权限
306 func GetUserPermission(userCompanyid int64) (op *OptionOpportunity, err error) { 305 func GetUserPermission(userCompanyid int64) (op *OptionOpportunity, err error) {
307 op = &OptionOpportunity{} 306 op = &OptionOpportunity{}
308 - mp, e := getUserPermission(userCompanyid) 307 + mp, e := getUserChancePermission(userCompanyid)
309 if e != nil { 308 if e != nil {
310 log.Error(e) 309 log.Error(e)
311 } 310 }
@@ -319,3 +318,77 @@ func GetUserPermission(userCompanyid int64) (op *OptionOpportunity, err error) { @@ -319,3 +318,77 @@ func GetUserPermission(userCompanyid int64) (op *OptionOpportunity, err error) {
319 } 318 }
320 return 319 return
321 } 320 }
  321 +
  322 +//获取用户机会权限
  323 +func getUserChancePermission(userCompanyid int64) (map[string]PermissionOptionObject, error) {
  324 + type CodeOpptionData struct {
  325 + Code string `orm:"column(code)"`
  326 + Opption string `orm:"column(opption)"`
  327 + }
  328 + var datasql string = fmt.Sprintf(`SELECT a.code,a.opption,c.id role_id
  329 + FROM role_menu AS a
  330 + JOIN user_role AS b ON a.role_id = b.role_id
  331 + JOIN role AS c ON a.role_id = c.id
  332 + WHERE a.code='%v' AND b.user_company_id=? AND c.delete_at =0`, M_SYSTEM_OPPORTUNITY)
  333 +
  334 + var (
  335 + data []CodeOpptionData
  336 + err error
  337 + )
  338 + err = utils.ExecuteQueryAll(&data, datasql, userCompanyid)
  339 + if err != nil {
  340 + e := fmt.Errorf("EXCUTE SQL ERR:%s", err)
  341 + return nil, e
  342 + }
  343 + var list []OptionOpportunity
  344 + for _, v := range data {
  345 + tmp := OptionOpportunity{}
  346 + if err = json.Unmarshal([]byte(v.Opption), &tmp); err != nil {
  347 + log.Debug("解析权限配置option 失败", v.Opption, err)
  348 + }
  349 + list = append(list, tmp)
  350 + }
  351 + return getPermissionMap(list)
  352 +}
  353 +
  354 +//获取机会权限map
  355 +func getPermissionMap(list []OptionOpportunity) (map[string]PermissionOptionObject, error) {
  356 + var (
  357 + objMap = make(map[string]PermissionOptionObject)
  358 + obj = &OptionOpportunity{}
  359 + )
  360 + if len(list) == 0 {
  361 + obj.Check = OpportunityCheckLv4
  362 + }
  363 + checkEnable := func(old, new int) int {
  364 + if old == 0 && new == 1 {
  365 + return 1
  366 + }
  367 + return old
  368 + }
  369 + specialDepIds := make(map[int64]CheckDeparment) //特定部门
  370 + for i := range list {
  371 + tmp := list[i]
  372 + if tmp.Check > obj.Check {
  373 + obj.Check = tmp.Check
  374 + }
  375 + if tmp.Check == obj.Check && obj.Check == OpportunityCheckLv3 { //当前是特定部门时 合并特定部门的部门列表
  376 + for i := range tmp.CheckOption.Departments { //合并特殊部门
  377 + d := tmp.CheckOption.Departments[i]
  378 + if _, ok := specialDepIds[d.Id]; !ok {
  379 + specialDepIds[d.Id] = d
  380 + }
  381 + }
  382 + }
  383 + obj.EditChance = checkEnable(obj.EditChance, tmp.EditChance)
  384 + obj.EditSorce = checkEnable(obj.EditSorce, tmp.EditSorce)
  385 + obj.EditPublicStatus = checkEnable(obj.EditPublicStatus, tmp.EditPublicStatus)
  386 + }
  387 + if obj.Check == OpportunityCheckLv3 { //合并特殊部门
  388 + for _, v := range specialDepIds {
  389 + obj.CheckOption.Departments = append(obj.CheckOption.Departments, v)
  390 + }
  391 + }
  392 + objMap[M_SYSTEM_OPPORTUNITY] = obj
  393 + return objMap, nil
  394 +}
  1 +package agg
  2 +
  3 +import (
  4 + "gitlab.fjmaimaimai.com/mmm-go/gocomm/common"
  5 + "testing"
  6 +)
  7 +
  8 +func Test_getPermissionMap(t *testing.T) {
  9 + input := []OptionOpportunity{
  10 + {
  11 + Check: 1,
  12 + EditSorce: 1,
  13 + EditChance: 1,
  14 + EditPublicStatus: 0,
  15 + },
  16 + {
  17 + Check: 2,
  18 + EditSorce: 0,
  19 + EditChance: 1,
  20 + EditPublicStatus: 0,
  21 + },
  22 + {
  23 + Check: 3,
  24 + EditSorce: 0,
  25 + EditChance: 1,
  26 + EditPublicStatus: 0,
  27 + CheckOption: CheckOpp{
  28 + Departments: []CheckDeparment{{Id: 1}, {Id: 3}, {Id: 5}},
  29 + },
  30 + },
  31 + {
  32 + Check: 3,
  33 + EditSorce: 0,
  34 + EditChance: 1,
  35 + EditPublicStatus: 1,
  36 + CheckOption: CheckOpp{
  37 + Departments: []CheckDeparment{{Id: 1}, {Id: 4}, {Id: 2}},
  38 + },
  39 + },
  40 + {
  41 + Check: 4,
  42 + EditSorce: 1,
  43 + EditChance: 1,
  44 + EditPublicStatus: 0,
  45 + },
  46 + }
  47 + out, _ := getPermissionMap(input)
  48 + t.Log(common.AssertJson(out))
  49 +}
@@ -1923,6 +1923,10 @@ func Permission(header *protocol.RequestHeader, request *protocol.PermissionRequ @@ -1923,6 +1923,10 @@ func Permission(header *protocol.RequestHeader, request *protocol.PermissionRequ
1923 rsp.EditChance = 0 1923 rsp.EditChance = 0
1924 } 1924 }
1925 return 1925 return
  1926 + } else {
  1927 + if chance.ReviewStatus == protocol.ReviewStatusReturn { //退回的机会不可编辑
  1928 + rsp.EditChance = 0
  1929 + }
1926 } 1930 }
1927 1931
1928 //他人 1932 //他人
@@ -29,7 +29,8 @@ func Init() { @@ -29,7 +29,8 @@ func Init() {
29 Filename: "app.log", 29 Filename: "app.log",
30 Level: "7", //7 单元test时 可以把级别设置低一点 减少日志 30 Level: "7", //7 单元test时 可以把级别设置低一点 减少日志
31 }) 31 })
32 - err := redis.InitWithDb(100, beego.AppConfig.String("redis_add_port"), beego.AppConfig.String("redis_auth"), "0") 32 + redisSource := fmt.Sprintf("%v:%v", beego.AppConfig.String("redis_add"), beego.AppConfig.String("redis_add_port"))
  33 + err := redis.InitWithDb(100, redisSource, beego.AppConfig.String("redis_auth"), "0")
33 if err != nil { 34 if err != nil {
34 log.Fatal(err) 35 log.Fatal(err)
35 panic(err) 36 panic(err)