mirror of https://gitee.com/answerdev/answer.git
add question actions
This commit is contained in:
parent
b0d2cdc4a0
commit
990e749743
|
@ -191,6 +191,8 @@ func (qc *QuestionController) GetQuestion(ctx *gin.Context) {
|
|||
permission.QuestionDelete,
|
||||
permission.QuestionClose,
|
||||
permission.QuestionReopen,
|
||||
permission.QuestionPin,
|
||||
permission.QuestionHide,
|
||||
})
|
||||
if err != nil {
|
||||
handler.HandleResponse(ctx, err, nil)
|
||||
|
@ -202,6 +204,8 @@ func (qc *QuestionController) GetQuestion(ctx *gin.Context) {
|
|||
req.CanDelete = canList[1]
|
||||
req.CanClose = canList[2]
|
||||
req.CanReopen = canList[3]
|
||||
req.CanPin = canList[4]
|
||||
req.CanHide = canList[5]
|
||||
|
||||
info, err := qc.questionService.GetQuestionAndAddPV(ctx, id, userID, req)
|
||||
if err != nil {
|
||||
|
|
|
@ -113,6 +113,10 @@ type QuestionPermission struct {
|
|||
CanClose bool `json:"-"`
|
||||
// whether user can reopen it
|
||||
CanReopen bool `json:"-"`
|
||||
// whether user can pin it
|
||||
CanPin bool `json:"-"`
|
||||
// whether user can hide it
|
||||
CanHide bool `json:"-"`
|
||||
// whether user can use reserved it
|
||||
CanUseReservedTag bool `json:"-"`
|
||||
}
|
||||
|
|
|
@ -45,4 +45,6 @@ const (
|
|||
deleteActionName = "action.delete"
|
||||
closeActionName = "action.close"
|
||||
reopenActionName = "action.reopen"
|
||||
pinActionName = "action.pin"
|
||||
hideActionName = "action.hide"
|
||||
)
|
||||
|
|
|
@ -10,7 +10,7 @@ import (
|
|||
|
||||
// GetQuestionPermission get question permission
|
||||
func GetQuestionPermission(ctx context.Context, userID string, creatorUserID string,
|
||||
canEdit, canDelete, canClose, canReopen bool) (
|
||||
canEdit, canDelete, canClose, canReopen, canPin, canHide bool) (
|
||||
actions []*schema.PermissionMemberAction) {
|
||||
lang := handler.GetLangByCtx(ctx)
|
||||
actions = make([]*schema.PermissionMemberAction, 0)
|
||||
|
@ -42,6 +42,20 @@ func GetQuestionPermission(ctx context.Context, userID string, creatorUserID str
|
|||
Type: "confirm",
|
||||
})
|
||||
}
|
||||
if canPin {
|
||||
actions = append(actions, &schema.PermissionMemberAction{
|
||||
Action: "pin",
|
||||
Name: translator.Tr(lang, pinActionName),
|
||||
Type: "confirm",
|
||||
})
|
||||
}
|
||||
if canHide {
|
||||
actions = append(actions, &schema.PermissionMemberAction{
|
||||
Action: "hide",
|
||||
Name: translator.Tr(lang, hideActionName),
|
||||
Type: "confirm",
|
||||
})
|
||||
}
|
||||
if canDelete || userID == creatorUserID {
|
||||
actions = append(actions, &schema.PermissionMemberAction{
|
||||
Action: "delete",
|
||||
|
|
|
@ -641,7 +641,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.CanEdit, per.CanDelete, per.CanClose, per.CanReopen, per.CanPin, per.CanHide)
|
||||
return question, nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue