Skip to content

A Q&A platform software for teams at any scales. Whether it's a community forum, help center, or knowledge management platform, you can always count on Apache Answer.

update question

aichy1260c174599655e
diff --git a/i18n/en_US.yaml b/i18n/en_US.yaml
index 2171e55a..333e75fe 100644
--- a/i18n/en_US.yaml
+++ b/i18n/en_US.yaml
@@ -27,6 +27,10 @@ backend:
other: pin
hide:
other: hide
+ unpin:
+ other: unpin
+ show:
+ other: show
role:
name:
user:
diff --git a/i18n/zh_CN.yaml b/i18n/zh_CN.yaml
index b47ced41..5fd46710 100644
--- a/i18n/zh_CN.yaml
+++ b/i18n/zh_CN.yaml
@@ -26,6 +26,10 @@ backend:
other: 置顶
hide:
other: 隐藏
+ unpin:
+ other: 取消置顶
+ show:
+ other: 显示
role:
name:
user:
diff --git a/internal/base/constant/acticity.go b/internal/base/constant/acticity.go
index b0db1f46..334d8e6d 100644
--- a/internal/base/constant/acticity.go
+++ b/internal/base/constant/acticity.go
@@ -14,6 +14,10 @@ const (
ActFollow = "follow"
ActAccepted = "accepted"
ActAccept = "accept"
+ ActPin = "pin"
+ ActUnPin = "unpin"
+ ActShow = "show"
+ ActHide = "hide"
)
const (
diff --git a/internal/controller/question_controller.go b/internal/controller/question_controller.go
index 5c9d2e25..6b474670 100644
--- a/internal/controller/question_controller.go
+++ b/internal/controller/question_controller.go
@@ -89,7 +89,9 @@ func (qc *QuestionController) OperationQuestion(ctx *gin.Context) {
req.UserID = middleware.GetLoginUserIDFromContext(ctx)
canList, err := qc.rankService.CheckOperationPermissions(ctx, req.UserID, []string{
permission.QuestionPin,
+ permission.QuestionUnPin,
permission.QuestionHide,
+ permission.QuestionShow,
})
if err != nil {
handler.HandleResponse(ctx, err, nil)
@@ -192,7 +194,9 @@ func (qc *QuestionController) GetQuestion(ctx *gin.Context) {
permission.QuestionClose,
permission.QuestionReopen,
permission.QuestionPin,
+ permission.QuestionUnPin,
permission.QuestionHide,
+ permission.QuestionShow,
})
if err != nil {
handler.HandleResponse(ctx, err, nil)
@@ -205,7 +209,9 @@ func (qc *QuestionController) GetQuestion(ctx *gin.Context) {
req.CanClose = canList[2]
req.CanReopen = canList[3]
req.CanPin = canList[4]
- req.CanHide = canList[5]
+ req.CanUnPin = canList[5]
+ req.CanHide = canList[6]
+ req.CanShow = canList[7]
info, err := qc.questionService.GetQuestionAndAddPV(ctx, id, userID, req)
if err != nil {
diff --git a/internal/migrations/v8.go b/internal/migrations/v8.go
index dd46a558..090651fa 100644
--- a/internal/migrations/v8.go
+++ b/internal/migrations/v8.go
@@ -1,18 +1,22 @@
package migrations
import (
+ "fmt"
"time"
"github.com/answerdev/answer/internal/entity"
"github.com/answerdev/answer/internal/service/permission"
+ "github.com/segmentfault/pacman/log"
"xorm.io/xorm"
)
func addRolePinAndHideFeatures(x *xorm.Engine) error {
powers := []*entity.Power{
- {ID: 34, Name: "question pin", PowerType: permission.QuestionPin, Description: "Top or untop the question"},
- {ID: 35, Name: "question hide", PowerType: permission.QuestionHide, Description: "hide or show the question"},
+ {ID: 34, Name: "question pin", PowerType: permission.QuestionPin, Description: "top the question"},
+ {ID: 35, Name: "question hide", PowerType: permission.QuestionHide, Description: "hide the question"},
+ {ID: 36, Name: "question unpin", PowerType: permission.QuestionUnPin, Description: "untop the question"},
+ {ID: 37, Name: "question show", PowerType: permission.QuestionShow, Description: "show the question"},
}
// insert default powers
for _, power := range powers {
@@ -34,9 +38,13 @@ func addRolePinAndHideFeatures(x *xorm.Engine) error {
{RoleID: 2, PowerType: permission.QuestionPin},
{RoleID: 2, PowerType: permission.QuestionHide},
+ {RoleID: 2, PowerType: permission.QuestionUnPin},
+ {RoleID: 2, PowerType: permission.QuestionShow},
{RoleID: 3, PowerType: permission.QuestionPin},
{RoleID: 3, PowerType: permission.QuestionHide},
+ {RoleID: 3, PowerType: permission.QuestionUnPin},
+ {RoleID: 3, PowerType: permission.QuestionShow},
}
// insert default powers
@@ -53,6 +61,31 @@ func addRolePinAndHideFeatures(x *xorm.Engine) error {
return err
}
}
+
+ defaultConfigTable := []*entity.Config{
+ {ID: 119, Key: "question.pin", Value: `0`},
+ {ID: 120, Key: "question.unpin", Value: `0`},
+ {ID: 121, Key: "question.show", Value: `0`},
+ {ID: 122, Key: "question.hide", Value: `0`},
+ }
+ for _, c := range defaultConfigTable {
+ exist, err := x.Get(&entity.Config{ID: c.ID, Key: c.Key})
+ if err != nil {
+ return fmt.Errorf("get config failed: %w", err)
+ }
+ if exist {
+ if _, err = x.Update(c, &entity.Config{ID: c.ID, Key: c.Key}); err != nil {
+ log.Errorf("update %+v config failed: %s", c, err)
+ return fmt.Errorf("update config failed: %w", err)
+ }
+ continue
+ }
+ if _, err = x.Insert(&entity.Config{ID: c.ID, Key: c.Key, Value: c.Value}); err != nil {
+ log.Errorf("insert %+v config failed: %s", c, err)
+ return fmt.Errorf("add config failed: %w", err)
+ }
+ }
+
type Question struct {
ID string `xorm:"not null pk BIGINT(20) id"`
CreatedAt time.Time `xorm:"not null default CURRENT_TIMESTAMP TIMESTAMP created_at"`
diff --git a/internal/schema/question_schema.go b/internal/schema/question_schema.go
index 9284ba9c..b86dcff9 100644
--- a/internal/schema/question_schema.go
+++ b/internal/schema/question_schema.go
@@ -114,9 +114,11 @@ type QuestionPermission struct {
// whether user can reopen it
CanReopen bool `json:"-"`
// whether user can pin it
- CanPin bool `json:"-"`
+ CanPin bool `json:"-"`
+ CanUnPin bool `json:"-"`
// whether user can hide it
CanHide bool `json:"-"`
+ CanShow bool `json:"-"`
// whether user can use reserved it
CanUseReservedTag bool `json:"-"`
}
diff --git a/internal/service/permission/permission_name.go b/internal/service/permission/permission_name.go
index 783e3b49..1d49ce3f 100644
--- a/internal/service/permission/permission_name.go
+++ b/internal/service/permission/permission_name.go
@@ -10,8 +10,10 @@ const (
QuestionReopen = "question.reopen"
QuestionVoteUp = "question.vote_up"
QuestionVoteDown = "question.vote_down"
- QuestionPin = "question.pin" //Top or untop the question
- QuestionHide = "question.hide" //hide or show the question
+ QuestionPin = "question.pin" //Top the question
+ QuestionUnPin = "question.unpin" //untop the question
+ QuestionHide = "question.hide" //hide the question
+ QuestionShow = "question.show" //show the question
AnswerAdd = "answer.add"
AnswerEdit = "answer.edit"
AnswerEditWithoutReview = "answer.edit_without_review"
@@ -46,5 +48,7 @@ const (
closeActionName = "action.close"
reopenActionName = "action.reopen"
pinActionName = "action.pin"
+ unpinActionName = "action.unpin"
hideActionName = "action.hide"
+ showActionName = "action.show"
)
diff --git a/internal/service/permission/question_permission.go b/internal/service/permission/question_permission.go
index a295f7ff..6f4d126f 100644
--- a/internal/service/permission/question_permission.go
+++ b/internal/service/permission/question_permission.go
@@ -10,7 +10,7 @@ import (
// GetQuestionPermission get question permission
func GetQuestionPermission(ctx context.Context, userID string, creatorUserID string,
- canEdit, canDelete, canClose, canReopen, canPin, canHide bool) (
+ canEdit, canDelete, canClose, canReopen, canPin, canHide, CanUnPin, canShow bool) (
actions []*schema.PermissionMemberAction) {
lang := handler.GetLangByCtx(ctx)
actions = make([]*schema.PermissionMemberAction, 0)
@@ -56,6 +56,22 @@ func GetQuestionPermission(ctx context.Context, userID string, creatorUserID str
Type: "confirm",
})
}
+
+ if CanUnPin {
+ actions = append(actions, &schema.PermissionMemberAction{
+ Action: "unpin",
+ Name: translator.Tr(lang, unpinActionName),
+ Type: "confirm",
+ })
+ }
+
+ if canShow {
+ actions = append(actions, &schema.PermissionMemberAction{
+ Action: "show",
+ Name: translator.Tr(lang, showActionName),
+ Type: "confirm",
+ })
+ }
if canDelete || userID == creatorUserID {
actions = append(actions, &schema.PermissionMemberAction{
Action: "delete",
diff --git a/internal/service/question_service.go b/internal/service/question_service.go
index b59e97d5..dfcdff3d 100644
--- a/internal/service/question_service.go
+++ b/internal/service/question_service.go
@@ -685,6 +685,20 @@ func (qs *QuestionService) GetQuestion(ctx context.Context, questionID, userID s
if question.Status == entity.QuestionStatusClosed {
per.CanClose = false
}
+ if question.Pin == entity.QuestionPin {
+ per.CanPin = false
+ per.CanHide = false
+ }
+ if question.Pin == entity.QuestionUnPin {
+ per.CanUnPin = false
+ }
+ if question.Show == entity.QuestionShow {
+ per.CanShow = false
+ }
+ if question.Show == entity.QuestionHide {
+ per.CanHide = false
+ per.CanPin = false
+ }
if question.Status == entity.QuestionStatusDeleted {
operation := &schema.Operation{}
operation.Msg = translator.Tr(handler.GetLangByCtx(ctx), reason.QuestionAlreadyDeleted)
@@ -694,7 +708,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.CanEdit, per.CanDelete, per.CanClose, per.CanReopen, per.CanPin, per.CanHide, per.CanUnPin, per.CanShow)
return question, nil
}