作者 yangfu

权限修改

... ... @@ -79,7 +79,7 @@ func DeleteUserDepartment(id int64) (err error) {
func GetUserDepartments(id int64, companyId int64, v interface{}) (err error) {
o := orm.NewOrm()
sql := `
select a.department_id,b.name,b.parent_id,b.managers,b.relation,a.create_time
select a.department_id,b.name,b.parent_id,b.managers,b.relation,b.create_at create_time
from user_department a INNER JOIN department b on a.department_id = b.id
where a.user_company_id =? and a.company_id =? and enable_status =1 and b.delete_at =0`
if _, err = o.Raw(sql, id, companyId).QueryRows(v); err == nil {
... ...
... ... @@ -78,7 +78,7 @@ func DeleteUserPosition(id int) (err error) {
func GetUserPositions(id int64, companyId int64, v interface{}) (err error) {
o := orm.NewOrm()
sql := `
select a.position_id,b.name,b.relation,a.create_at
select a.position_id,b.name,b.relation,b.create_at
from user_position a INNER JOIN position b on a.position_id = b.id
where a.user_company_id =? and a.company_id =? and a.enable_status =1 and b.enable_status =1`
if _, err = o.Raw(sql, id, companyId).QueryRows(v); err == nil {
... ...
... ... @@ -197,26 +197,26 @@ func (p *OptionOpportunity) MergeObject(jsonString string) error {
}
p.CheckMap[obj.Check] = 1
departMap := make(map[int64]*CheckDeparment)
for k := range p.CheckOption.Departments {
i := p.CheckOption.Departments[k].Id
departMap[i] = &p.CheckOption.Departments[k]
for i := range p.CheckOption.Departments {
id := p.CheckOption.Departments[i].Id
departMap[id] = &p.CheckOption.Departments[i]
}
//列表合并
for k := range obj.CheckOption.Departments {
i := obj.CheckOption.Departments[k].Id
if _, ok := departMap[i]; ok {
if obj.CheckOption.Departments[k].OpenAll > departMap[i].OpenAll {
departMap[i].OpenAll = obj.CheckOption.Departments[k].OpenAll
for i := range obj.CheckOption.Departments {
id := obj.CheckOption.Departments[i].Id
if _, ok := departMap[id]; ok {
if obj.CheckOption.Departments[i].OpenAll > departMap[id].OpenAll {
departMap[id].OpenAll = obj.CheckOption.Departments[i].OpenAll
}
if obj.CheckOption.Departments[k].OpenDepart > departMap[i].OpenDepart {
departMap[i].OpenDepart = obj.CheckOption.Departments[k].OpenDepart
if obj.CheckOption.Departments[i].OpenDepart > departMap[id].OpenDepart {
departMap[id].OpenDepart = obj.CheckOption.Departments[i].OpenDepart
}
if obj.CheckOption.Departments[k].Wait > departMap[i].Wait {
departMap[i].Wait = obj.CheckOption.Departments[k].Wait
if obj.CheckOption.Departments[i].Wait > departMap[id].Wait {
departMap[id].Wait = obj.CheckOption.Departments[i].Wait
}
} else {
departMap[i] = &obj.CheckOption.Departments[k]
departMap[id] = &obj.CheckOption.Departments[i]
}
}
... ... @@ -297,7 +297,6 @@ func getUserPermission(userCompanyid int64) (map[string]PermissionOptionObject,
} else {
log.Error("未知code:%s", v.Code)
}
}
return objMap, nil
}
... ... @@ -305,7 +304,7 @@ func getUserPermission(userCompanyid int64) (map[string]PermissionOptionObject,
//获取用户权限
func GetUserPermission(userCompanyid int64) (op *OptionOpportunity, err error) {
op = &OptionOpportunity{}
mp, e := getUserPermission(userCompanyid)
mp, e := getUserChancePermission(userCompanyid)
if e != nil {
log.Error(e)
}
... ... @@ -319,3 +318,77 @@ func GetUserPermission(userCompanyid int64) (op *OptionOpportunity, err error) {
}
return
}
//获取用户机会权限
func getUserChancePermission(userCompanyid int64) (map[string]PermissionOptionObject, error) {
type CodeOpptionData struct {
Code string `orm:"column(code)"`
Opption string `orm:"column(opption)"`
}
var datasql string = fmt.Sprintf(`SELECT a.code,a.opption,c.id role_id
FROM role_menu AS a
JOIN user_role AS b ON a.role_id = b.role_id
JOIN role AS c ON a.role_id = c.id
WHERE a.code='%v' AND b.user_company_id=? AND c.delete_at =0`, M_SYSTEM_OPPORTUNITY)
var (
data []CodeOpptionData
err error
)
err = utils.ExecuteQueryAll(&data, datasql, userCompanyid)
if err != nil {
e := fmt.Errorf("EXCUTE SQL ERR:%s", err)
return nil, e
}
var list []OptionOpportunity
for _, v := range data {
tmp := OptionOpportunity{}
if err = json.Unmarshal([]byte(v.Opption), &tmp); err != nil {
log.Debug("解析权限配置option 失败", v.Opption, err)
}
list = append(list, tmp)
}
return getPermissionMap(list)
}
//获取机会权限map
func getPermissionMap(list []OptionOpportunity) (map[string]PermissionOptionObject, error) {
var (
objMap = make(map[string]PermissionOptionObject)
obj = &OptionOpportunity{}
)
if len(list) == 0 {
obj.Check = OpportunityCheckLv4
}
checkEnable := func(old, new int) int {
if old == 0 && new == 1 {
return 1
}
return old
}
specialDepIds := make(map[int64]CheckDeparment) //特定部门
for i := range list {
tmp := list[i]
if tmp.Check > obj.Check {
obj.Check = tmp.Check
}
if tmp.Check == obj.Check && obj.Check == OpportunityCheckLv3 { //当前是特定部门时 合并特定部门的部门列表
for i := range tmp.CheckOption.Departments { //合并特殊部门
d := tmp.CheckOption.Departments[i]
if _, ok := specialDepIds[d.Id]; !ok {
specialDepIds[d.Id] = d
}
}
}
obj.EditChance = checkEnable(obj.EditChance, tmp.EditChance)
obj.EditSorce = checkEnable(obj.EditSorce, tmp.EditSorce)
obj.EditPublicStatus = checkEnable(obj.EditPublicStatus, tmp.EditPublicStatus)
}
if obj.Check == OpportunityCheckLv3 { //合并特殊部门
for _, v := range specialDepIds {
obj.CheckOption.Departments = append(obj.CheckOption.Departments, v)
}
}
objMap[M_SYSTEM_OPPORTUNITY] = obj
return objMap, nil
}
... ...
package agg
import (
"gitlab.fjmaimaimai.com/mmm-go/gocomm/common"
"testing"
)
func Test_getPermissionMap(t *testing.T) {
input := []OptionOpportunity{
{
Check: 1,
EditSorce: 1,
EditChance: 1,
EditPublicStatus: 0,
},
{
Check: 2,
EditSorce: 0,
EditChance: 1,
EditPublicStatus: 0,
},
{
Check: 3,
EditSorce: 0,
EditChance: 1,
EditPublicStatus: 0,
CheckOption: CheckOpp{
Departments: []CheckDeparment{{Id: 1}, {Id: 3}, {Id: 5}},
},
},
{
Check: 3,
EditSorce: 0,
EditChance: 1,
EditPublicStatus: 1,
CheckOption: CheckOpp{
Departments: []CheckDeparment{{Id: 1}, {Id: 4}, {Id: 2}},
},
},
{
Check: 4,
EditSorce: 1,
EditChance: 1,
EditPublicStatus: 0,
},
}
out, _ := getPermissionMap(input)
t.Log(common.AssertJson(out))
}
... ...
... ... @@ -1923,6 +1923,10 @@ func Permission(header *protocol.RequestHeader, request *protocol.PermissionRequ
rsp.EditChance = 0
}
return
} else {
if chance.ReviewStatus == protocol.ReviewStatusReturn { //退回的机会不可编辑
rsp.EditChance = 0
}
}
//他人
... ...
... ... @@ -29,7 +29,8 @@ func Init() {
Filename: "app.log",
Level: "7", //7 单元test时 可以把级别设置低一点 减少日志
})
err := redis.InitWithDb(100, beego.AppConfig.String("redis_add_port"), beego.AppConfig.String("redis_auth"), "0")
redisSource := fmt.Sprintf("%v:%v", beego.AppConfig.String("redis_add"), beego.AppConfig.String("redis_add_port"))
err := redis.InitWithDb(100, redisSource, beego.AppConfig.String("redis_auth"), "0")
if err != nil {
log.Fatal(err)
panic(err)
... ...