Merge branch 'feat/1.1.1/state' into test

# Conflicts:
#	internal/controller/question_controller.go
This commit is contained in:
LinkinStars 2023-07-28 16:06:02 +08:00
commit d20acbabff
4 changed files with 17 additions and 19 deletions

View File

@ -621,6 +621,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)
isAdmin := middleware.GetUserIsAdminModerator(ctx)
@ -644,16 +648,11 @@ 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)

View File

@ -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,
}
}

View File

@ -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),

View File

@ -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
}