mirror of https://gitee.com/answerdev/answer.git
fix(answer): the wrong invite user rank limit
This commit is contained in:
parent
bf50c8971c
commit
d3f1b5dbe1
|
@ -571,6 +571,10 @@ func (qc *QuestionController) UpdateQuestionInviteUser(ctx *gin.Context) {
|
||||||
if ctx.IsAborted() {
|
if ctx.IsAborted() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if len(errFields) > 0 {
|
||||||
|
handler.HandleResponse(ctx, errors.BadRequest(reason.RequestFormatError), errFields)
|
||||||
|
return
|
||||||
|
}
|
||||||
req.ID = uid.DeShortID(req.ID)
|
req.ID = uid.DeShortID(req.ID)
|
||||||
req.UserID = middleware.GetLoginUserIDFromContext(ctx)
|
req.UserID = middleware.GetLoginUserIDFromContext(ctx)
|
||||||
|
|
||||||
|
@ -582,22 +586,13 @@ func (qc *QuestionController) UpdateQuestionInviteUser(ctx *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
objectOwner := qc.rankService.CheckOperationObjectOwner(ctx, req.UserID, req.ID)
|
req.CanInviteOtherToAnswer = canList[0]
|
||||||
req.CanEdit = canList[0] || objectOwner
|
if !req.CanInviteOtherToAnswer {
|
||||||
if !req.CanEdit {
|
|
||||||
handler.HandleResponse(ctx, errors.Forbidden(reason.RankFailToMeetTheCondition), nil)
|
handler.HandleResponse(ctx, errors.Forbidden(reason.RankFailToMeetTheCondition), nil)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if len(errFields) > 0 {
|
|
||||||
handler.HandleResponse(ctx, errors.BadRequest(reason.RequestFormatError), errFields)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
err = qc.questionService.UpdateQuestionInviteUser(ctx, req)
|
err = qc.questionService.UpdateQuestionInviteUser(ctx, req)
|
||||||
if err != nil {
|
handler.HandleResponse(ctx, err, nil)
|
||||||
handler.HandleResponse(ctx, err, nil)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
handler.HandleResponse(ctx, nil, nil)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// SearchByTitleLike add question title like
|
// SearchByTitleLike add question title like
|
||||||
|
|
|
@ -3,12 +3,12 @@ package auth
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"github.com/answerdev/answer/internal/service/auth"
|
||||||
|
|
||||||
"github.com/answerdev/answer/internal/base/constant"
|
"github.com/answerdev/answer/internal/base/constant"
|
||||||
"github.com/answerdev/answer/internal/base/data"
|
"github.com/answerdev/answer/internal/base/data"
|
||||||
"github.com/answerdev/answer/internal/base/reason"
|
"github.com/answerdev/answer/internal/base/reason"
|
||||||
"github.com/answerdev/answer/internal/entity"
|
"github.com/answerdev/answer/internal/entity"
|
||||||
"github.com/answerdev/answer/internal/service/auth"
|
|
||||||
"github.com/segmentfault/pacman/errors"
|
"github.com/segmentfault/pacman/errors"
|
||||||
"github.com/segmentfault/pacman/log"
|
"github.com/segmentfault/pacman/log"
|
||||||
)
|
)
|
||||||
|
@ -18,6 +18,13 @@ type authRepo struct {
|
||||||
data *data.Data
|
data *data.Data
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewAuthRepo new repository
|
||||||
|
func NewAuthRepo(data *data.Data) auth.AuthRepo {
|
||||||
|
return &authRepo{
|
||||||
|
data: data,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// GetUserCacheInfo get user cache info
|
// GetUserCacheInfo get user cache info
|
||||||
func (ar *authRepo) GetUserCacheInfo(ctx context.Context, accessToken string) (userInfo *entity.UserCacheInfo, err error) {
|
func (ar *authRepo) GetUserCacheInfo(ctx context.Context, accessToken string) (userInfo *entity.UserCacheInfo, err error) {
|
||||||
userInfoCache, err := ar.data.Cache.GetString(ctx, constant.UserTokenCacheKey+accessToken)
|
userInfoCache, err := ar.data.Cache.GetString(ctx, constant.UserTokenCacheKey+accessToken)
|
||||||
|
@ -174,10 +181,3 @@ func (ar *authRepo) RemoveUserTokens(ctx context.Context, userID string, remainT
|
||||||
log.Error(err)
|
log.Error(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewAuthRepo new repository
|
|
||||||
func NewAuthRepo(data *data.Data) auth.AuthRepo {
|
|
||||||
return &authRepo{
|
|
||||||
data: data,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -83,12 +83,11 @@ func GetQuestionPermission(ctx context.Context, userID string, creatorUserID str
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetQuestionExtendsPermission get question extends permission
|
// GetQuestionExtendsPermission get question extends permission
|
||||||
func GetQuestionExtendsPermission(ctx context.Context, userID string, creatorUserID string,
|
func GetQuestionExtendsPermission(ctx context.Context, canInviteOtherToAnswer bool) (
|
||||||
canInviteOtherToAnswer bool) (
|
|
||||||
actions []*schema.PermissionMemberAction) {
|
actions []*schema.PermissionMemberAction) {
|
||||||
lang := handler.GetLangByCtx(ctx)
|
lang := handler.GetLangByCtx(ctx)
|
||||||
actions = make([]*schema.PermissionMemberAction, 0)
|
actions = make([]*schema.PermissionMemberAction, 0)
|
||||||
if canInviteOtherToAnswer || userID == creatorUserID {
|
if canInviteOtherToAnswer {
|
||||||
actions = append(actions, &schema.PermissionMemberAction{
|
actions = append(actions, &schema.PermissionMemberAction{
|
||||||
Action: "invite_other_to_answer",
|
Action: "invite_other_to_answer",
|
||||||
Name: translator.Tr(lang, inviteSomeoneToAnswerActionName),
|
Name: translator.Tr(lang, inviteSomeoneToAnswerActionName),
|
||||||
|
|
|
@ -883,7 +883,7 @@ func (qs *QuestionService) GetQuestion(ctx context.Context, questionID, userID s
|
||||||
question.Description = htmltext.FetchExcerpt(question.HTML, "...", 240)
|
question.Description = htmltext.FetchExcerpt(question.HTML, "...", 240)
|
||||||
question.MemberActions = permission.GetQuestionPermission(ctx, userID, question.UserID,
|
question.MemberActions = permission.GetQuestionPermission(ctx, userID, question.UserID,
|
||||||
per.CanEdit, per.CanDelete, per.CanClose, per.CanReopen, per.CanPin, per.CanHide, per.CanUnPin, per.CanShow)
|
per.CanEdit, per.CanDelete, per.CanClose, per.CanReopen, per.CanPin, per.CanHide, per.CanUnPin, per.CanShow)
|
||||||
question.ExtendsActions = permission.GetQuestionExtendsPermission(ctx, userID, question.UserID, per.CanInviteOtherToAnswer)
|
question.ExtendsActions = permission.GetQuestionExtendsPermission(ctx, per.CanInviteOtherToAnswer)
|
||||||
return question, nil
|
return question, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue