diff --git a/i18n/en_US.yaml b/i18n/en_US.yaml index 09042df7..5f6ea524 100644 --- a/i18n/en_US.yaml +++ b/i18n/en_US.yaml @@ -34,6 +34,8 @@ backend: other: Unpin show: other: List + invite_someone_to_answer: + other: Edit role: name: user: diff --git a/internal/controller/question_controller.go b/internal/controller/question_controller.go index 77e85535..b7e254a9 100644 --- a/internal/controller/question_controller.go +++ b/internal/controller/question_controller.go @@ -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 { diff --git a/internal/schema/question_schema.go b/internal/schema/question_schema.go index 3f0b518c..859dde54 100644 --- a/internal/schema/question_schema.go +++ b/internal/schema/question_schema.go @@ -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 diff --git a/internal/service/notification/notification_service.go b/internal/service/notification/notification_service.go index 3f23be3e..6402f395 100644 --- a/internal/service/notification/notification_service.go +++ b/internal/service/notification/notification_service.go @@ -123,9 +123,12 @@ func (ns *NotificationService) GetNotificationPage(ctx context.Context, searchCo if !ok { return pager.NewPageModel(0, resp), nil } - searchInboxType, ok := schema.NotificationInboxType[searchCond.InboxTypeStr] - if !ok { - return pager.NewPageModel(0, resp), nil + searchInboxType := schema.NotificationInboxTypeAll + if searchType == schema.NotificationTypeInbox { + searchInboxType, ok = schema.NotificationInboxType[searchCond.InboxTypeStr] + if !ok { + return pager.NewPageModel(0, resp), nil + } } searchCond.Type = searchType searchCond.InboxType = searchInboxType diff --git a/internal/service/permission/permission_name.go b/internal/service/permission/permission_name.go index 2857b8d7..c892e782 100644 --- a/internal/service/permission/permission_name.go +++ b/internal/service/permission/permission_name.go @@ -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" ) diff --git a/internal/service/permission/question_permission.go b/internal/service/permission/question_permission.go index 6f4d126f..8f9c631d 100644 --- a/internal/service/permission/question_permission.go +++ b/internal/service/permission/question_permission.go @@ -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 +} diff --git a/internal/service/question_service.go b/internal/service/question_service.go index a2ae66ba..3c738485 100644 --- a/internal/service/question_service.go +++ b/internal/service/question_service.go @@ -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 }