作者 yangfu

机会权限过滤

... ... @@ -151,7 +151,7 @@ from audit_flow_process where uid=? and enable_status =1 and review_status in (%
func GetChanceCollect(uid int64, lastId int64, pageSize int, v interface{}) (total int, err error) {
sql := fmt.Sprintf(`select a.*,b.images,b.speechs,b.videos from (
select a.*,b.user_id,b.id,b.create_at,b.source_content,b.enable_status,b.review_status,b.audit_template_id,b.chance_type_id,comment_total,zan_total,view_total from (
select a.*,b.user_id,b.id,b.create_at,b.source_content,b.enable_status,b.review_status,b.audit_template_id,b.chance_type_id,comment_total,zan_total,view_total,b.publish_status from (
select id collect_id,source_id,create_at collect_time,chance_id from chance_favorite where (0=? or id<?) and user_id =? and enable_status=1
and source_type=1
and (mark_flag&2)>0
... ... @@ -174,7 +174,7 @@ limit ?`)
func GetChanceThumbUp(uid int64, lastId int64, pageSize int, v interface{}) (total int, err error) {
sql := fmt.Sprintf(`select a.*,b.images,b.speechs,b.videos from (
select a.*,b.user_id,b.id,b.create_at,b.source_content,b.enable_status,b.review_status,b.audit_template_id,b.chance_type_id,comment_total,zan_total,view_total from (
select a.*,b.user_id,b.id,b.create_at,b.source_content,b.enable_status,b.review_status,b.audit_template_id,b.chance_type_id,comment_total,zan_total,view_total,b.publish_status from (
select id collect_id,source_id,create_at collect_time from chance_favorite where (0=? or id<?) and user_id =? and enable_status=1
and source_type=1
and (mark_flag&1)>0
... ... @@ -209,7 +209,7 @@ func GetChanceComment(uid int64, lastId int64, pageSize int, v interface{}) (tot
sql := fmt.Sprintf(`select a.*,b.content commented_content,b.create_at commented_time,b.user_id commented_user_id
from (
select a.*,b.images,b.speechs,b.videos from (
select a.*,b.source_content,b.enable_status,b.user_id chance_user_id,b.create_at,b.review_status,b.approve_data from (
select a.*,b.source_content,b.enable_status,b.user_id chance_user_id,b.create_at,b.review_status,b.approve_data,b.publish_status from (
select id,content,view_total,zan_total,comment_total,source_type,source_id,create_at comment_time from comment
where user_id =? and (?=0 or id<?)
)a left outer join chance b on a.source_id = b.id and source_type=1
... ... @@ -599,3 +599,36 @@ select count(0) from (
}
return
}
//是否存在按发布机会部门编号查询
func ExitsChanceByDeparmentIds(chanceId int64, departmentIds []int64) (v *Chance, err error) {
sql := fmt.Sprintf(`select id from chance where id=%v and department_id in (%v)`,
chanceId, utils.JoinInt64s(departmentIds, ","))
o := orm.NewOrm()
if err = o.Raw(sql).QueryRow(&v); err != nil {
return
}
return
}
//是否存在发布机会的部门编号查询
func ExitsChanceByPublicDeparmentIds(chanceId int64, departmentIds []int64) (v *Chance, err error) {
sql := fmt.Sprintf(`select chance_id from chance_department where chance_id=%v and department_id in (%v)`,
chanceId, utils.JoinInt64s(departmentIds, ","))
o := orm.NewOrm()
if err = o.Raw(sql).QueryRow(&v); err != nil {
return
}
return
}
//是否存在机会 - 审核人
func ExitsChanceByAuditUser(chanceId int64, auditUserId int64) (v *Chance, err error) {
sql := fmt.Sprintf(`select * from audit_flow_process where chance_id =%v and uid =%v and enable_status=1 limit 1`,
chanceId, auditUserId)
o := orm.NewOrm()
if err = o.Raw(sql).QueryRow(&v); err != nil {
return
}
return
}
... ...
... ... @@ -237,8 +237,8 @@ type MyCollectChanceRequest struct {
PageSize int `json:"pageSize" valid:"Required"`
}
type MyCollectChanceResponse struct {
List []CommonListItem `json:"list"`
Total int `json:"total"`
List []*CommonListItem `json:"list"`
Total int `json:"total"`
}
/*MyThumbUpChance 我点赞的机会*/
... ... @@ -247,8 +247,8 @@ type MyThumbUpChanceRequest struct {
PageSize int `json:"pageSize" valid:"Required"`
}
type MyThumbUpChanceResponse struct {
List []CommonListItem `json:"list"`
Total int `json:"total"`
List []*CommonListItem `json:"list"`
Total int `json:"total"`
}
/*MyComment 我的评论*/
... ... @@ -257,8 +257,8 @@ type MyCommentRequest struct {
PageSize int `json:"pageSize" valid:"Required"`
}
type MyCommentResponse struct {
List []CommonListItem `json:"list"`
Total int `json:"total"`
List []*CommonListItem `json:"list"`
Total int `json:"total"`
}
//机会池列表
... ... @@ -292,6 +292,7 @@ type ChanceCollectItemOrm struct {
Images string `orm:"column(images)"`
Voices string `orm:"column(speechs)"`
Videos string `orm:"column(videos)"`
PublishStatus int `orm:"column(publish_status)"` //公开状态
//ApproveData string `json:"approveData"` //审核数据
TemplateId int `orm:"column(audit_template_id)"`
... ... @@ -319,6 +320,7 @@ type ChanceThumbUpItemOrm struct {
Images string `orm:"column(images)"`
Voices string `orm:"column(speechs)"`
Videos string `orm:"column(videos)"`
PublishStatus int `orm:"column(publish_status)"` //公开状态
//ApproveData string `json:"approveData"` //审核数据
TemplateId int `orm:"column(audit_template_id)"`
... ... @@ -343,6 +345,7 @@ type ChanceCommentItemOrm struct {
Images string `orm:"column(images)"`
Voices string `orm:"column(speechs)"`
Videos string `orm:"column(videos)"`
PublishStatus int `orm:"column(publish_status)"` //公开状态
CommentTotal int `orm:"column(comment_total)"`
ZanTotal int `orm:"column(zan_total)"`
... ... @@ -572,6 +575,7 @@ type ChanceItem struct {
Speechs []Speech `json:"speechs"`
Pictures []Picture `json:"pictures"`
Videos []Video `json:"videos"`
PublicStatus int `json:"public_status"`
}
type ChanceData struct {
ThumbsUpTotal int `json:"thumbsupTotal"` //点赞总数
... ...
... ... @@ -43,13 +43,12 @@ func GetChancePool(uid, cid int64, chanceTypeId int, lastId int64, pageSize int,
return
}
func GetChanceValidPermission(uid, cid int64, chanceTypeId int, lastId int64, pageSize int, items []protocol.CommonListItem) (total int, err error) {
//检查机会权限
func ValidChancePermission(uid, cid int64, items []*protocol.CommonListItem) (err error) {
var (
check int
specialDIds []int64
userDIds []int64
chanceIds []int64
)
if op, e := GetUserPermission(uid); e == nil {
for i := range op.CheckOption.Departments {
... ... @@ -61,27 +60,72 @@ func GetChanceValidPermission(uid, cid int64, chanceTypeId int, lastId int64, pa
specialDIds = append(specialDIds, 0)
}
for i := range items {
chanceIds = append(chanceIds, items[i].Chance.Id) // 机会列表
}
//log.Debug(fmt.Sprintf("user:%v check:%v", uid, check))
for i := range items {
if items[i].ChanceStatus != 0 {
continue
}
if items[i].ChanceId == 0 {
items[i].ChanceStatus = protocol.ChanceStatusClose
continue
}
if items[i].Chance.Provider == nil {
items[i].ChanceStatus = protocol.ChanceStatusClose
continue
}
var chancePublicStatus = items[i].Chance.PublicStatus
var chanceUserId = items[i].Chance.Provider.UserId
var chanceId = items[i].ChanceId
switch check {
case OpportunityCheckLv1:
if items[i].Chance.Provider.UserId == uid {
if chanceUserId == uid {
continue
}
if _, e := models.ExitsChanceByAuditUser(chanceId, uid); e == nil {
continue
}
items[i].ChanceStatus = protocol.ChanceStatusClose
case OpportunityCheckLv2:
if err = models.GetUserDepartmentIds(uid, cid, &userDIds); err != nil {
log.Error(err)
return
if chancePublicStatus == protocol.PublicToCompany {
continue
}
if chanceUserId == uid {
continue
}
if chancePublicStatus == protocol.PublicToDepartment {
if len(userDIds) == 0 {
if e := models.GetUserDepartmentIds(uid, cid, &userDIds); e != nil {
log.Error(e)
return
}
}
if _, e := models.ExitsChanceByPublicDeparmentIds(chanceId, userDIds); e == nil {
continue
}
}
if _, e := models.ExitsChanceByAuditUser(chanceId, uid); e == nil {
continue
}
items[i].ChanceStatus = protocol.ChanceStatusClose
case OpportunityCheckLv3:
case OpportunityCheckLv4:
if chanceUserId == uid {
continue
}
if len(userDIds) == 0 {
if e := models.GetUserDepartmentIds(uid, cid, &userDIds); e != nil {
log.Error(e)
return
}
}
if _, e := models.ExitsChanceByDeparmentIds(chanceId, userDIds); e == nil {
continue
}
if _, e := models.ExitsChanceByAuditUser(chanceId, uid); e == nil {
continue
}
items[i].ChanceStatus = protocol.ChanceStatusClose
case OpportunityCheckLv4: //所有权限 不检查
break
default:
break
}
}
return
... ...
... ... @@ -1436,8 +1436,9 @@ func MyCollectChance(header *protocol.RequestHeader, request *protocol.MyCollect
rsp = &protocol.MyCollectChanceResponse{Total: total}
for i := 0; i < len(myChances); i++ {
chance := myChances[i]
commItem := protocol.CommonListItem{}
commItem := &protocol.CommonListItem{}
commItem.ReviewStatus = chance.ReviewStatus
commItem.ChanceId = chance.ChanceId
if len(chance.SourceContent) == 0 { //机会删除
commItem.ChanceStatus = protocol.ChanceStatusDelete
} else if chance.ChanceEnableStatus == 0 { //机会关闭
... ... @@ -1452,6 +1453,7 @@ func MyCollectChance(header *protocol.RequestHeader, request *protocol.MyCollect
Id: chance.ChanceId,
Provider: provider,
//CreateTime: chance.CreateTime.Unix() * 1000,
PublicStatus: chance.PublishStatus,
}
jsonUnmarshal(chance.SourceContent, &item.FormList)
item.FormList = clearEmptyForm(item.FormList)
... ... @@ -1486,6 +1488,7 @@ func MyCollectChance(header *protocol.RequestHeader, request *protocol.MyCollect
}
rsp.List = append(rsp.List, commItem)
}
agg.ValidChancePermission(header.UserId, header.CompanyId, rsp.List)
return
}
... ... @@ -1507,8 +1510,9 @@ func MyThumbUpChance(header *protocol.RequestHeader, request *protocol.MyThumbUp
rsp = &protocol.MyThumbUpChanceResponse{Total: total}
for i := 0; i < len(myChances); i++ {
chance := myChances[i]
commItem := protocol.CommonListItem{}
commItem := &protocol.CommonListItem{}
commItem.ReviewStatus = chance.ReviewStatus
commItem.ChanceId = chance.ChanceId
if len(chance.SourceContent) == 0 { //机会删除
commItem.ChanceStatus = protocol.ChanceStatusDelete
} else if chance.ChanceEnableStatus == 0 { //机会关闭
... ... @@ -1520,9 +1524,10 @@ func MyThumbUpChance(header *protocol.RequestHeader, request *protocol.MyThumbUp
//return
} else {
item := protocol.ChanceItem{
Id: chance.ChanceId,
Provider: provider,
CreateTime: chance.CreateTime.Unix() * 1000,
Id: chance.ChanceId,
Provider: provider,
CreateTime: chance.CreateTime.Unix() * 1000,
PublicStatus: chance.PublishStatus,
}
jsonUnmarshal(chance.SourceContent, &item.FormList)
item.FormList = clearEmptyForm(item.FormList)
... ... @@ -1556,6 +1561,7 @@ func MyThumbUpChance(header *protocol.RequestHeader, request *protocol.MyThumbUp
}
rsp.List = append(rsp.List, commItem)
}
agg.ValidChancePermission(header.UserId, header.CompanyId, rsp.List)
return
}
... ... @@ -1577,31 +1583,34 @@ func MyComment(header *protocol.RequestHeader, request *protocol.MyCommentReques
rsp = &protocol.MyCommentResponse{Total: total}
for i := 0; i < len(myChances); i++ {
chance := myChances[i]
commItem := protocol.CommonListItem{}
commItem := &protocol.CommonListItem{}
commItem.ChanceId = chance.SourceId
if chance.SourceType == protocol.SourceTypeChance {
commItem.ReviewStatus = chance.ReviewStatus
if len(chance.SourceContent) == 0 { //机会删除
commItem.ChanceStatus = protocol.ChanceStatusDelete
} else if chance.ChanceEnableStatus == 0 { //机会关闭
commItem.ChanceStatus = protocol.ChanceStatusClose
}
if provider, err = agg.GetUserBaseInfo(chance.Uid, header.CompanyId); err != nil {
commItem.ChanceStatus = protocol.ChanceStatusDelete
err = nil
log.Error(err)
commItem.Chance = protocol.ChanceItem{}
//return
} else {
if provider, err = agg.GetUserBaseInfo(chance.Uid, header.CompanyId); err != nil {
commItem.ChanceStatus = protocol.ChanceStatusDelete
log.Error(err)
//return
} else {
item := protocol.ChanceItem{
Id: chance.SourceId,
Provider: provider,
CreateTime: chance.CreateTime.Unix() * 1000,
}
jsonUnmarshal(chance.SourceContent, &item.FormList)
item.FormList = clearEmptyForm(item.FormList)
jsonUnmarshal(chance.Images, &item.Pictures)
jsonUnmarshal(chance.Voices, &item.Speechs)
jsonUnmarshal(chance.Videos, &item.Videos)
commItem.Chance = item
item := protocol.ChanceItem{
Id: chance.SourceId,
Provider: provider,
CreateTime: chance.CreateTime.Unix() * 1000,
PublicStatus: chance.PublishStatus,
}
jsonUnmarshal(chance.SourceContent, &item.FormList)
item.FormList = clearEmptyForm(item.FormList)
jsonUnmarshal(chance.Images, &item.Pictures)
jsonUnmarshal(chance.Voices, &item.Speechs)
jsonUnmarshal(chance.Videos, &item.Videos)
commItem.Chance = item
}
commItem.ReviewStatus = chance.ReviewStatus
//{
... ... @@ -1634,6 +1643,7 @@ func MyComment(header *protocol.RequestHeader, request *protocol.MyCommentReques
commItem.SourceType = chance.SourceType
rsp.List = append(rsp.List, commItem)
}
agg.ValidChancePermission(header.UserId, header.CompanyId, rsp.List)
return
}
... ...