fix(vote): check vote permission wrong

This commit is contained in:
LinkinStar 2022-12-08 12:00:10 +08:00
parent e914edd5a0
commit 22aa8e4271
1 changed files with 5 additions and 6 deletions

View File

@ -150,16 +150,10 @@ func (rs *RankService) CheckVotePermission(ctx context.Context, userID, objectID
if !exist {
return can, nil
}
// TODO administrator have all permissions
//if userInfo.IsAdmin {
// return true, nil
//}
objectInfo, err := rs.objectInfoService.GetInfo(ctx, objectID)
if err != nil {
return can, err
}
action := ""
switch objectInfo.ObjectType {
case constant.QuestionObjectType:
@ -181,6 +175,11 @@ func (rs *RankService) CheckVotePermission(ctx context.Context, userID, objectID
action = permission.CommentVoteDown
}
}
powerMapping := rs.getUserPowerMapping(ctx, userID)
if powerMapping[action] {
return true, nil
}
meetRank := rs.checkUserRank(ctx, userInfo.ID, userInfo.Rank, PermissionPrefix+action)
return meetRank, nil
}