作者 yangfu

机会权限

... ... @@ -179,3 +179,24 @@ func (this *UserController) UserStatistics() {
header := controllers.GetRequestHeader(this.Ctx)
msg = protocol.NewReturnResponse(user.UserStatistics(header, request))
}
//Permission 用户权限
//@router /permission [post]
func (this *UserController) Permission() {
var msg *protocol.ResponseMessage
defer func() {
this.Resp(msg)
}()
var request *protocol.PermissionRequest
if err := json.Unmarshal(this.ByteBody, &request); err != nil {
log.Error(err)
msg = protocol.BadRequestParam(1)
return
}
if b, m := this.Valid(request); !b {
msg = m
return
}
header := controllers.GetRequestHeader(this.Ctx)
msg = protocol.NewReturnResponse(user.Permission(header, request))
}
... ...
... ... @@ -103,3 +103,13 @@ type TypeTotalItem struct {
Total int `json:"total"` //总数
HaveUpdate int `json:"haveUpdate"` //是否含有更新(0无更新,1有更新)
}
/*Permission 用户权限*/
type PermissionRequest struct {
}
type PermissionResponse struct {
EditSorce int `json:"editSorce"` //修改评分 1:允许 0:不允许
EditPublicStatus int `json:"editPublicStatus"` //修改公开状态 1:允许 0:不允许
CloseChance int `json:"closeChance"` //关闭机会 1:允许 0:不允许
EditChance int `json:"editChance"` //编辑机会 1:允许 0:不允许
}
... ...
... ... @@ -441,6 +441,14 @@ func init() {
beego.GlobalControllerRouter["opp/controllers/v1:UserController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:UserController"],
beego.ControllerComments{
Method: "Permission",
Router: `/permission`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:UserController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:UserController"],
beego.ControllerComments{
Method: "ResetPassword",
Router: `/resetPassword`,
AllowHTTPMethods: []string{"post"},
... ...
... ... @@ -256,7 +256,7 @@ func (p *OptionOpportunity) ValidEditPublicStatus(obj UserObject) bool {
return false
}
func GetUserPermission(userCompanyid int64) (map[string]PermissionOptionObject, error) {
func getUserPermission(userCompanyid int64) (map[string]PermissionOptionObject, error) {
type CodeOpptionData struct {
Code string `orm:"column(code)"`
Opption string `orm:"column(opption)"`
... ... @@ -265,13 +265,13 @@ func GetUserPermission(userCompanyid int64) (map[string]PermissionOptionObject,
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 b.user_company_id=? AND c.delete_at =0`
WHERE a.code=? AND b.user_company_id=? AND c.delete_at =0`
var (
data []CodeOpptionData
err error
objMap = make(map[string]PermissionOptionObject)
)
err = utils.ExecuteQueryAll(&data, datasql, userCompanyid)
err = utils.ExecuteQueryAll(&data, datasql, M_SYSTEM_OPPORTUNITY, userCompanyid)
if err != nil {
e := fmt.Errorf("EXCUTE SQL ERR:%s", err)
return nil, e
... ... @@ -287,7 +287,7 @@ func GetUserPermission(userCompanyid int64) (map[string]PermissionOptionObject,
if fn, ok := CodePermissionObject[v.Code]; ok {
obj := fn()
if err = json.Unmarshal([]byte(v.Opption), obj); err != nil {
log.Debug("解析权限配置option 失败%s", err)
log.Debug("解析权限配置option 失败", v.Opption, err)
}
objMap[v.Code] = obj
} else {
... ... @@ -297,3 +297,21 @@ func GetUserPermission(userCompanyid int64) (map[string]PermissionOptionObject,
}
return objMap, nil
}
//获取用户权限
func GetUserPermission(userCompanyid int64) (op *OptionOpportunity, err error) {
op = &OptionOpportunity{}
mp, e := getUserPermission(userCompanyid)
if e != nil {
log.Error(e)
}
if len(mp) == 0 {
return
}
if v, ok := mp[M_SYSTEM_OPPORTUNITY]; ok {
if op, ok = v.(*OptionOpportunity); ok {
return
}
}
return
}
... ...
... ... @@ -447,3 +447,18 @@ func UserStatistics(header *protocol.RequestHeader, request *protocol.UserStatis
//log.Debug(buf.String())
return
}
//用户权限
func Permission(header *protocol.RequestHeader, request *protocol.PermissionRequest) (rsp *protocol.PermissionResponse, err error) {
var (
op *agg.OptionOpportunity
)
rsp = &protocol.PermissionResponse{}
if op, err = agg.GetUserPermission(header.UserId); err == nil {
rsp.EditChance = op.EditChance
//rsp.CloseChance = op.CloseChance
rsp.EditPublicStatus = op.EditPublicStatus
rsp.EditSorce = op.EditSorce
}
return
}
... ...