作者 yangfu

Merge branch 'dev' of http://gitlab.fjmaimaimai.com/mmm-go/oppmg into dev

... ... @@ -231,9 +231,12 @@ func (c *RbacController) MenuList() {
defer func() {
c.ResposeJson(msg)
}()
userid := c.GetUserId()
companyid := c.GetCompanyId()
list, err := serverbac.GetMenuAll()
menulist := serverbac.FilterMenuByRole(list, userid, companyid)
data := protocol.ResponsePermissionList{
Lists: list,
Lists: menulist,
}
msg = protocol.NewReturnResponse(data, err)
return
... ...
... ... @@ -214,3 +214,30 @@ func GetCompanyDefaultRole(companyid int64) (*Role, error) {
One(r)
return r, err
}
func GetCompanyDefaultRoleGroup(companyid int64) (*Role, error) {
r := &Role{}
o := orm.NewOrm()
err := o.QueryTable(&Role{}).
Filter("company_id", companyid).
Filter("types", ROLETYPES_GROUP).
Filter("is_default", ROLE_DEFAULR).
One(r)
return r, err
}
func GetUserRoleByUser(usecompanyid int64) ([]Role, error) {
sql := `SELECT a.id,a.pid,a.types,a.company_id FROM role AS a
JOIN user_role AS b ON a.id= b.role_id
WHERE a.delete_at=0 AND b.user_company_id =? `
var (
list []Role
err error
)
o := orm.NewOrm()
_, err = o.Raw(sql, usecompanyid).QueryRows(&list)
if err != nil {
return list, err
}
return list, err
}
... ...
... ... @@ -175,6 +175,9 @@ func BulletinList(uid, companyId int64, request *protocol.BulletinListRequest) (
list []*models.Bulletin
total int
)
rsp = &protocol.BulletinListResponse{
List: make([]*protocol.BulletinItem, 0),
}
if request.PageIndex == 0 {
request.PageIndex += 1
}
... ...
... ... @@ -233,15 +233,15 @@ func departmentRelationUpdate(departUpdate *models.Department, newparent *models
log.Error(e.Error())
return protocol.NewErrWithMessage("10042")
}
//确认层级深度
s := strings.TrimPrefix(departSubset[i].Relation, oldRelation)
n := strings.Split(s, "/")
if len(n) >= 10 {
//重建关系树
departSubset[i].Relation = strings.TrimSpace(fmt.Sprintf("%s%s", newRelation, s))
//确认层级深度
n := strings.Split(departSubset[i].Relation, "/")
if len(n) > 10 {
o.Rollback()
return protocol.NewErrWithMessage("10046")
}
//重建关系树
departSubset[i].Relation = strings.TrimSpace(fmt.Sprintf("%s%s", newRelation, s))
err = utils.ExecuteSQLWithOrmer(o, dataSql2, departSubset[i].Relation, departSubset[i].Id)
if err != nil {
o.Rollback()
... ...
... ... @@ -149,7 +149,7 @@ func PositionEdit(param protocol.RequestPositionEdit) (*protocol.ResponsePositio
if err != nil {
e := fmt.Errorf("positionRelationUpdate err:%s", err)
log.Error(e.Error())
return nil, protocol.NewErrWithMessage("1", e)
return nil, err
}
}
positioninfo = &protocol.ResponsePositionInfo{
... ... @@ -217,12 +217,12 @@ func positionRelationUpdate(positionUpdate *models.Position, newparent *models.P
}
//重建关系树
s := strings.TrimPrefix(positionSubset[i].Relation, oldRelation)
rs := strings.Split(s, "/")
if len(rs) >= 10 { //层级不能超过10级
positionSubset[i].Relation = strings.TrimSpace(fmt.Sprintf("%s%s", newRelation, s))
rs := strings.Split(positionSubset[i].Relation, "/")
if len(rs) > 10 { //层级不能超过10级
o.Rollback()
return protocol.NewErrWithMessage("10012")
}
positionSubset[i].Relation = strings.TrimSpace(fmt.Sprintf("%s%s", newRelation, s))
err = utils.ExecuteSQLWithOrmer(o, dataSql2, positionSubset[i].Relation, positionSubset[i].Id)
if err != nil {
o.Rollback()
... ...
... ... @@ -526,7 +526,9 @@ func UserList(param protocol.RequestUserList) (protocol.ResponseUserList, error)
result []protocol.UserListItem
pageInfo protocol.ResponsePageInfo
err error
responseData protocol.ResponseUserList
responseData = protocol.ResponseUserList{
List: make([]protocol.UserListItem, 0),
}
)
p := utils.NewQueryDataByPage(countSql+whereString, datasql+whereString)
p.AddParam(cond...)
... ...
... ... @@ -27,6 +27,51 @@ func GetMenuAll() ([]protocol.PermissionItem, error) {
return list, nil
}
func FilterMenuByRole(allMenu []protocol.PermissionItem, userid int64, companyid int64) []protocol.PermissionItem {
var newMenuList []protocol.PermissionItem
ucompany, err := models.GetUserCompanyBy(userid, companyid)
if err != nil {
log.Error("获取用户数据失败:%s", err)
return allMenu
}
rolegroup, err := models.GetCompanyDefaultRoleGroup(ucompany.CompanyId)
if err != nil {
log.Error("获取默认的角色组失败:%s", err)
return allMenu
}
rolelist, err := models.GetUserRoleByUser(ucompany.Id)
if err != nil {
log.Error("获取用户的角色失败:%s", err)
return allMenu
}
var (
isIn bool = false
)
for i := range rolelist {
if rolelist[i].Pid == rolegroup.Id {
isIn = true
}
}
if isIn {
return allMenu
}
codeMap := map[string]int{
M_ENTERPRISE: 1,
M_ENTERPRISE_PROFILE: 1,
M_ENTERPRISE_ORGANIZATION: 1,
M_ENTERPRISE_EMPLOYEE_POST: 1,
M_ENTERPRISE_EMPLOYEE_ROLE: 1,
M_ENTERPRISE_EMPLOYEE: 1,
}
for i, v := range allMenu {
if _, ok := codeMap[v.Code]; ok {
continue
}
newMenuList = append(newMenuList, allMenu[i])
}
return newMenuList
}
func GetRoleHasMenu(roleid int64, companyid int64) (*protocol.ResponseRoleMenus, error) {
var (
roleData *models.Role
... ...
... ... @@ -23,8 +23,8 @@ const (
)
type PermissionOptionObject interface {
// StringUnmarshal(string) error
// ObjectMarshal() string
StringUnmarshal(string) error
ObjectMarshal() string
GetValidFunc(string) bool
MergeObject(string) error
}
... ...
... ... @@ -56,20 +56,20 @@ func (p *PermissionOptionBase) MergeObject(jsonString string) error {
return nil
}
// //StringUnmarshal PermissionOptionBase 接口实现
// func (p *PermissionOptionBase) StringUnmarshal(s string) error {
// err := json.Unmarshal([]byte(s), p)
// return err
// }
// //ObjectMarshal PermissionOptionBase 接口实现
// func (p *PermissionOptionBase) ObjectMarshal() string {
// bt, err := json.Marshal(p)
// if err != nil {
// return ""
// }
// return string(bt)
// }
//StringUnmarshal PermissionOptionBase 接口实现
func (p *PermissionOptionBase) StringUnmarshal(s string) error {
err := json.Unmarshal([]byte(s), p)
return err
}
//ObjectMarshal PermissionOptionBase 接口实现
func (p *PermissionOptionBase) ObjectMarshal() string {
bt, err := json.Marshal(p)
if err != nil {
return ""
}
return string(bt)
}
/*
机会管理模块
... ... @@ -233,17 +233,17 @@ func (p *OptionOpportunity) ValidCloseChance() bool {
return false
}
// //StringUnmarshal PermissionOptionBase 接口实现
// func (p *OptionOpportunity) StringUnmarshal(s string) error {
// err := json.Unmarshal([]byte(s), p)
// return err
// }
// //ObjectMarshal PermissionOptionBase 接口实现
// func (p *OptionOpportunity) ObjectMarshal() string {
// bt, err := json.Marshal(p)
// if err != nil {
// return ""
// }
// return string(bt)
// }
//StringUnmarshal PermissionOptionBase 接口实现
func (p *OptionOpportunity) StringUnmarshal(s string) error {
err := json.Unmarshal([]byte(s), p)
return err
}
//ObjectMarshal PermissionOptionBase 接口实现
func (p *OptionOpportunity) ObjectMarshal() string {
bt, err := json.Marshal(p)
if err != nil {
return ""
}
return string(bt)
}
... ...
... ... @@ -143,7 +143,7 @@ func RoleEdit(param protocol.RequestRoleEdit) (*protocol.ResponseRoleInfo, error
}
//获取原来的父级
var oldParent *models.Role
oldParent, err = models.GetRoleById(param.Pid)
oldParent, err = models.GetRoleById(roleinfo.Pid)
if err != nil {
log.Error("获取旧父级数据失败;%s", err)
return nil, protocol.NewErrWithMessage("1")
... ... @@ -153,6 +153,7 @@ func RoleEdit(param protocol.RequestRoleEdit) (*protocol.ResponseRoleInfo, error
return nil, protocol.NewErrWithMessage("10082")
}
}
//.....
roleinfo.Pid = param.Pid
if err = models.UpdateRoleById(roleinfo, []string{"Descript", "Name", "Pid"}); err != nil {
... ...
... ... @@ -148,11 +148,21 @@ func ExistUserPermission(userid int64) bool {
func GetUserPermissionAll(userid int64) (map[string]rbac.PermissionOptionObject, error) {
key := GetKeyUserPermission(userid)
client := redis.GetRedis()
str, err := client.Get(key).Result()
strMap, err := client.HGetAll(key).Result()
if err != nil {
return nil, err
}
permissionObj := make(map[string]rbac.PermissionOptionObject)
err = json.Unmarshal([]byte(str), &permissionObj)
for k, v := range strMap {
fn, ok := rbac.CodePermissionObject[k]
if !ok {
continue
}
obj := fn()
if err := obj.StringUnmarshal(v); err == nil {
permissionObj[k] = obj
}
}
return permissionObj, err
}
... ...