Skip to content

A Q&A platform software for teams at any scales. Whether it's a community forum, help center, or knowledge management platform, you can always count on Apache Answer.

fix(answer): the wrong invite user rank limit

LinkinStarsd3f1b5dbe1b7
diff --git a/internal/controller/question_controller.go b/internal/controller/question_controller.go
index aa24fd32..c8c8724b 100644
--- a/internal/controller/question_controller.go
+++ b/internal/controller/question_controller.go
@@ -571,6 +571,10 @@ func (qc *QuestionController) UpdateQuestionInviteUser(ctx *gin.Context) {
if ctx.IsAborted() {
return
}
+ if len(errFields) > 0 {
+ handler.HandleResponse(ctx, errors.BadRequest(reason.RequestFormatError), errFields)
+ return
+ }
req.ID = uid.DeShortID(req.ID)
req.UserID = middleware.GetLoginUserIDFromContext(ctx)
@@ -582,22 +586,13 @@ func (qc *QuestionController) UpdateQuestionInviteUser(ctx *gin.Context) {
return
}
- objectOwner := qc.rankService.CheckOperationObjectOwner(ctx, req.UserID, req.ID)
- req.CanEdit = canList[0] || objectOwner
- if !req.CanEdit {
+ req.CanInviteOtherToAnswer = canList[0]
+ if !req.CanInviteOtherToAnswer {
handler.HandleResponse(ctx, errors.Forbidden(reason.RankFailToMeetTheCondition), nil)
return
}
- if len(errFields) > 0 {
- handler.HandleResponse(ctx, errors.BadRequest(reason.RequestFormatError), errFields)
- return
- }
err = qc.questionService.UpdateQuestionInviteUser(ctx, req)
- if err != nil {
- handler.HandleResponse(ctx, err, nil)
- return
- }
- handler.HandleResponse(ctx, nil, nil)
+ handler.HandleResponse(ctx, err, nil)
}
// SearchByTitleLike add question title like
diff --git a/internal/repo/auth/auth.go b/internal/repo/auth/auth.go
index 5cd808a7..440ec1f8 100644
--- a/internal/repo/auth/auth.go
+++ b/internal/repo/auth/auth.go
@@ -3,12 +3,12 @@ package auth
import (
"context"
"encoding/json"
+ "github.com/answerdev/answer/internal/service/auth"
"github.com/answerdev/answer/internal/base/constant"
"github.com/answerdev/answer/internal/base/data"
"github.com/answerdev/answer/internal/base/reason"
"github.com/answerdev/answer/internal/entity"
- "github.com/answerdev/answer/internal/service/auth"
"github.com/segmentfault/pacman/errors"
"github.com/segmentfault/pacman/log"
)
@@ -18,6 +18,13 @@ type authRepo struct {
data *data.Data
}
+// NewAuthRepo new repository
+func NewAuthRepo(data *data.Data) auth.AuthRepo {
+ return &authRepo{
+ data: data,
+ }
+}
+
// GetUserCacheInfo get user cache info
func (ar *authRepo) GetUserCacheInfo(ctx context.Context, accessToken string) (userInfo *entity.UserCacheInfo, err error) {
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)
}
}
-
-// NewAuthRepo new repository
-func NewAuthRepo(data *data.Data) auth.AuthRepo {
- return &authRepo{
- data: data,
- }
-}
diff --git a/internal/service/permission/question_permission.go b/internal/service/permission/question_permission.go
index 8f9c631d..0bcde13d 100644
--- a/internal/service/permission/question_permission.go
+++ b/internal/service/permission/question_permission.go
@@ -83,12 +83,11 @@ func GetQuestionPermission(ctx context.Context, userID string, creatorUserID str
}
// GetQuestionExtendsPermission get question extends permission
-func GetQuestionExtendsPermission(ctx context.Context, userID string, creatorUserID string,
- canInviteOtherToAnswer bool) (
+func GetQuestionExtendsPermission(ctx context.Context, canInviteOtherToAnswer bool) (
actions []*schema.PermissionMemberAction) {
lang := handler.GetLangByCtx(ctx)
actions = make([]*schema.PermissionMemberAction, 0)
- if canInviteOtherToAnswer || userID == creatorUserID {
+ if canInviteOtherToAnswer {
actions = append(actions, &schema.PermissionMemberAction{
Action: "invite_other_to_answer",
Name: translator.Tr(lang, inviteSomeoneToAnswerActionName),
diff --git a/internal/service/question_service.go b/internal/service/question_service.go
index f8f939b7..6fdd3852 100644
--- a/internal/service/question_service.go
+++ b/internal/service/question_service.go
@@ -883,7 +883,7 @@ func (qs *QuestionService) GetQuestion(ctx context.Context, questionID, userID s
question.Description = htmltext.FetchExcerpt(question.HTML, "...", 240)
question.MemberActions = permission.GetQuestionPermission(ctx, userID, question.UserID,
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
}