Merge branch 'feat/1.1.0/report' of github.com:answerdev/answer into feat/1.1.0/report

This commit is contained in:
aichy126 2023-05-24 15:20:12 +08:00
commit e8265a0ddf
7 changed files with 36 additions and 11 deletions

View File

@ -34,6 +34,8 @@ backend:
other: Unpin
show:
other: List
invite_someone_to_answer:
other: Edit
role:
name:
user:

View File

@ -109,7 +109,7 @@ func (cc *ConnectorController) ConnectorRedirect(connector plugin.Connector) (fn
commonRouterPrefix, ConnectorRedirectRouterPrefix, connector.ConnectorSlugName())
userInfo, err := connector.ConnectorReceiver(ctx, receiverURL)
if err != nil {
log.Errorf("connector received failed: %v", err)
log.Errorf("connector received failed, error info: %v, response data is: %s", err, userInfo.MetaInfo)
ctx.Redirect(http.StatusFound, "/50x")
return
}

View File

@ -196,6 +196,7 @@ func (qc *QuestionController) GetQuestion(ctx *gin.Context) {
permission.QuestionUnPin,
permission.QuestionHide,
permission.QuestionShow,
permission.AnswerInviteSomeoneToAnswer,
})
if err != nil {
handler.HandleResponse(ctx, err, nil)
@ -211,6 +212,7 @@ func (qc *QuestionController) GetQuestion(ctx *gin.Context) {
req.CanUnPin = canList[5]
req.CanHide = canList[6]
req.CanShow = canList[7]
req.CanInviteOtherToAnswer = canList[8]
info, err := qc.questionService.GetQuestionAndAddPV(ctx, id, userID, req)
if err != nil {

View File

@ -122,6 +122,8 @@ type QuestionPermission struct {
CanShow bool `json:"-"`
// whether user can use reserved it
CanUseReservedTag bool `json:"-"`
// whether user can invite other user to answer this question
CanInviteOtherToAnswer bool `json:"-"`
}
type CheckCanQuestionUpdate struct {
@ -211,7 +213,8 @@ type QuestionInfo struct {
IsFollowed bool `json:"is_followed"`
// MemberActions
MemberActions []*PermissionMemberAction `json:"member_actions"`
MemberActions []*PermissionMemberAction `json:"member_actions"`
ExtendsActions []*PermissionMemberAction `json:"extends_actions"`
}
// UpdateQuestionResp update question resp

View File

@ -43,13 +43,14 @@ const (
)
const (
reportActionName = "action.report"
editActionName = "action.edit"
deleteActionName = "action.delete"
closeActionName = "action.close"
reopenActionName = "action.reopen"
pinActionName = "action.pin"
unpinActionName = "action.unpin"
hideActionName = "action.hide"
showActionName = "action.show"
reportActionName = "action.report"
editActionName = "action.edit"
deleteActionName = "action.delete"
closeActionName = "action.close"
reopenActionName = "action.reopen"
pinActionName = "action.pin"
unpinActionName = "action.unpin"
hideActionName = "action.hide"
showActionName = "action.show"
inviteSomeoneToAnswerActionName = "action.invite_someone_to_answer"
)

View File

@ -81,3 +81,19 @@ func GetQuestionPermission(ctx context.Context, userID string, creatorUserID str
}
return actions
}
// GetQuestionExtendsPermission get question extends permission
func GetQuestionExtendsPermission(ctx context.Context, userID string, creatorUserID string,
canInviteOtherToAnswer bool) (
actions []*schema.PermissionMemberAction) {
lang := handler.GetLangByCtx(ctx)
actions = make([]*schema.PermissionMemberAction, 0)
if canInviteOtherToAnswer || userID == creatorUserID {
actions = append(actions, &schema.PermissionMemberAction{
Action: "invite_other_to_answer",
Name: translator.Tr(lang, inviteSomeoneToAnswerActionName),
Type: "confirm",
})
}
return actions
}

View File

@ -859,6 +859,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)
return question, nil
}