add question actions

This commit is contained in:
aichy126 2023-04-13 14:39:27 +08:00
parent b0d2cdc4a0
commit 990e749743
5 changed files with 26 additions and 2 deletions

View File

@ -191,6 +191,8 @@ func (qc *QuestionController) GetQuestion(ctx *gin.Context) {
permission.QuestionDelete, permission.QuestionDelete,
permission.QuestionClose, permission.QuestionClose,
permission.QuestionReopen, permission.QuestionReopen,
permission.QuestionPin,
permission.QuestionHide,
}) })
if err != nil { if err != nil {
handler.HandleResponse(ctx, err, nil) handler.HandleResponse(ctx, err, nil)
@ -202,6 +204,8 @@ func (qc *QuestionController) GetQuestion(ctx *gin.Context) {
req.CanDelete = canList[1] req.CanDelete = canList[1]
req.CanClose = canList[2] req.CanClose = canList[2]
req.CanReopen = canList[3] req.CanReopen = canList[3]
req.CanPin = canList[4]
req.CanHide = canList[5]
info, err := qc.questionService.GetQuestionAndAddPV(ctx, id, userID, req) info, err := qc.questionService.GetQuestionAndAddPV(ctx, id, userID, req)
if err != nil { if err != nil {

View File

@ -113,6 +113,10 @@ type QuestionPermission struct {
CanClose bool `json:"-"` CanClose bool `json:"-"`
// whether user can reopen it // whether user can reopen it
CanReopen bool `json:"-"` 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 // whether user can use reserved it
CanUseReservedTag bool `json:"-"` CanUseReservedTag bool `json:"-"`
} }

View File

@ -45,4 +45,6 @@ const (
deleteActionName = "action.delete" deleteActionName = "action.delete"
closeActionName = "action.close" closeActionName = "action.close"
reopenActionName = "action.reopen" reopenActionName = "action.reopen"
pinActionName = "action.pin"
hideActionName = "action.hide"
) )

View File

@ -10,7 +10,7 @@ import (
// GetQuestionPermission get question permission // GetQuestionPermission get question permission
func GetQuestionPermission(ctx context.Context, userID string, creatorUserID string, func GetQuestionPermission(ctx context.Context, userID string, creatorUserID string,
canEdit, canDelete, canClose, canReopen bool) ( canEdit, canDelete, canClose, canReopen, canPin, canHide 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)
@ -42,6 +42,20 @@ func GetQuestionPermission(ctx context.Context, userID string, creatorUserID str
Type: "confirm", 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 { if canDelete || userID == creatorUserID {
actions = append(actions, &schema.PermissionMemberAction{ actions = append(actions, &schema.PermissionMemberAction{
Action: "delete", Action: "delete",

View File

@ -641,7 +641,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.CanEdit, per.CanDelete, per.CanClose, per.CanReopen, per.CanPin, per.CanHide)
return question, nil return question, nil
} }