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.

feat(rank): add permission and privilege reputation

LinkinStarsba5aadf31b0e
diff --git a/i18n/en_US.yaml b/i18n/en_US.yaml
index 0271ce76..ff9fd7ca 100644
--- a/i18n/en_US.yaml
+++ b/i18n/en_US.yaml
@@ -79,6 +79,8 @@ backend:
other: Downvote question
rank_answer_vote_down_label:
other: Downvote answer
+ rank_invite_someone_to_answer_label:
+ other: Invite someone to answer
rank_tag_add_label:
other: Create new tag
rank_tag_edit_label:
diff --git a/i18n/zh_CN.yaml b/i18n/zh_CN.yaml
index 84036e10..ca2edf49 100644
--- a/i18n/zh_CN.yaml
+++ b/i18n/zh_CN.yaml
@@ -75,6 +75,8 @@ backend:
other: 问题点踩
rank_answer_vote_down_label:
other: 答案点踩
+ rank_invite_someone_to_answer_label:
+ other: 邀请回答
rank_tag_add_label:
other: 创建新标签
rank_tag_edit_label:
diff --git a/internal/base/constant/rank.go b/internal/base/constant/rank.go
index f1cbf255..adf9ccd9 100644
--- a/internal/base/constant/rank.go
+++ b/internal/base/constant/rank.go
@@ -20,6 +20,7 @@ const (
RankAnswerAcceptKey = "rank.answer.accept"
RankAnswerVoteUpKey = "rank.answer.vote_up"
RankAnswerVoteDownKey = "rank.answer.vote_down"
+ RankInviteSomeoneToAnswerKey = "rank.answer.invite_someone_to_answer"
RankCommentAddKey = "rank.comment.add"
RankCommentEditKey = "rank.comment.edit"
RankCommentDeleteKey = "rank.comment.delete"
@@ -55,6 +56,7 @@ var (
{Label: reason.RankAnswerVoteUpLabel, Key: RankAnswerVoteUpKey},
{Label: reason.RankQuestionVoteDownLabel, Key: RankQuestionVoteDownKey},
{Label: reason.RankAnswerVoteDownLabel, Key: RankAnswerVoteDownKey},
+ {Label: reason.RankInviteSomeoneToAnswerLabel, Key: RankInviteSomeoneToAnswerKey},
{Label: reason.RankTagAddLabel, Key: RankTagAddKey},
{Label: reason.RankTagEditLabel, Key: RankTagEditKey},
{Label: reason.RankQuestionEditLabel, Key: RankQuestionEditKey},
diff --git a/internal/base/reason/privilege.go b/internal/base/reason/privilege.go
index 76d4e7bb..c4741663 100644
--- a/internal/base/reason/privilege.go
+++ b/internal/base/reason/privilege.go
@@ -15,6 +15,7 @@ const (
RankAnswerVoteUpLabel = "privilege.rank_answer_vote_up_label"
RankQuestionVoteDownLabel = "privilege.rank_question_vote_down_label"
RankAnswerVoteDownLabel = "privilege.rank_answer_vote_down_label"
+ RankInviteSomeoneToAnswerLabel = "privilege.rank_invite_someone_to_answer_label"
RankTagAddLabel = "privilege.rank_tag_add_label"
RankTagEditLabel = "privilege.rank_tag_edit_label"
RankQuestionEditLabel = "privilege.rank_question_edit_label"
diff --git a/internal/migrations/init.go b/internal/migrations/init.go
index 5ecf1d04..0df92b56 100644
--- a/internal/migrations/init.go
+++ b/internal/migrations/init.go
@@ -375,6 +375,7 @@ func initConfigTable(engine *xorm.Engine) error {
{ID: 124, Key: "rank.question.unpin", Value: `-1`},
{ID: 125, Key: "rank.question.show", Value: `-1`},
{ID: 126, Key: "rank.question.hide", Value: `-1`},
+ {ID: 127, Key: "rank.answer.invite_someone_to_answer", Value: `1000`},
}
_, err := engine.Insert(defaultConfigTable)
return err
@@ -429,6 +430,7 @@ func initRolePower(engine *xorm.Engine) (err error) {
{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"},
+ {ID: 38, Name: "invite someone to answer", PowerType: permission.AnswerInviteSomeoneToAnswer, Description: "invite someone to answer"},
}
_, err = engine.Insert(powers)
if err != nil {
@@ -474,6 +476,7 @@ func initRolePower(engine *xorm.Engine) (err error) {
{RoleID: 2, PowerType: permission.QuestionHide},
{RoleID: 2, PowerType: permission.QuestionUnPin},
{RoleID: 2, PowerType: permission.QuestionShow},
+ {RoleID: 2, PowerType: permission.AnswerInviteSomeoneToAnswer},
{RoleID: 3, PowerType: permission.QuestionAdd},
{RoleID: 3, PowerType: permission.QuestionEdit},
@@ -512,6 +515,7 @@ func initRolePower(engine *xorm.Engine) (err error) {
{RoleID: 3, PowerType: permission.QuestionHide},
{RoleID: 3, PowerType: permission.QuestionUnPin},
{RoleID: 3, PowerType: permission.QuestionShow},
+ {RoleID: 3, PowerType: permission.AnswerInviteSomeoneToAnswer},
}
_, err = engine.Insert(rolePowerRels)
if err != nil {
diff --git a/internal/migrations/v13.go b/internal/migrations/v13.go
index 278b1826..2e3767f5 100644
--- a/internal/migrations/v13.go
+++ b/internal/migrations/v13.go
@@ -7,6 +7,7 @@ import (
"github.com/answerdev/answer/internal/base/constant"
"github.com/answerdev/answer/internal/entity"
"github.com/answerdev/answer/internal/schema"
+ "github.com/answerdev/answer/internal/service/permission"
"xorm.io/xorm"
)
@@ -30,5 +31,60 @@ func addGravatarBaseURL(x *xorm.Engine) error {
return fmt.Errorf("update site info failed: %w", err)
}
}
+
+ // add rank for invite to answer
+ powers := []*entity.Power{
+ {ID: 38, Name: "invite someone to answer", PowerType: permission.AnswerInviteSomeoneToAnswer, Description: "invite someone to answer"},
+ }
+ for _, power := range powers {
+ exist, err := x.Get(&entity.Power{PowerType: power.PowerType})
+ if err != nil {
+ return err
+ }
+ if exist {
+ _, err = x.ID(power.ID).Update(power)
+ } else {
+ _, err = x.Insert(power)
+ }
+ if err != nil {
+ return err
+ }
+ }
+ rolePowerRels := []*entity.RolePowerRel{
+ {RoleID: 2, PowerType: permission.AnswerInviteSomeoneToAnswer},
+ {RoleID: 3, PowerType: permission.AnswerInviteSomeoneToAnswer},
+ }
+ for _, rel := range rolePowerRels {
+ exist, err := x.Get(&entity.RolePowerRel{RoleID: rel.RoleID, PowerType: rel.PowerType})
+ if err != nil {
+ return err
+ }
+ if exist {
+ continue
+ }
+ _, err = x.Insert(rel)
+ if err != nil {
+ return err
+ }
+ }
+
+ defaultConfigTable := []*entity.Config{
+ {ID: 127, Key: "rank.answer.invite_someone_to_answer", Value: `1000`},
+ }
+ for _, c := range defaultConfigTable {
+ exist, err := x.Get(&entity.Config{ID: c.ID})
+ if err != nil {
+ return fmt.Errorf("get config failed: %w", err)
+ }
+ if exist {
+ if _, err = x.Update(c, &entity.Config{ID: c.ID}); err != nil {
+ 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 {
+ return fmt.Errorf("add config failed: %w", err)
+ }
+ }
return nil
}
diff --git a/internal/schema/siteinfo_schema.go b/internal/schema/siteinfo_schema.go
index 6f8557fc..119420cf 100644
--- a/internal/schema/siteinfo_schema.go
+++ b/internal/schema/siteinfo_schema.go
@@ -297,6 +297,7 @@ var (
constant.RankAnswerVoteUpKey: {1, 1, 15},
constant.RankQuestionVoteDownKey: {125, 125, 125},
constant.RankAnswerVoteDownKey: {125, 125, 125},
+ constant.RankInviteSomeoneToAnswerKey: {1, 500, 1000},
constant.RankTagAddKey: {1, 750, 1500},
constant.RankTagEditKey: {1, 50, 100},
constant.RankQuestionEditKey: {1, 100, 200},
diff --git a/internal/service/permission/permission_name.go b/internal/service/permission/permission_name.go
index 9262e569..2857b8d7 100644
--- a/internal/service/permission/permission_name.go
+++ b/internal/service/permission/permission_name.go
@@ -1,44 +1,45 @@
package permission
const (
- AdminAccess = "admin.access"
- QuestionAdd = "question.add"
- QuestionEdit = "question.edit"
- QuestionEditWithoutReview = "question.edit_without_review"
- QuestionDelete = "question.delete"
- QuestionClose = "question.close"
- QuestionReopen = "question.reopen"
- QuestionVoteUp = "question.vote_up"
- QuestionVoteDown = "question.vote_down"
- QuestionPin = "question.pin"
- QuestionUnPin = "question.unpin"
- QuestionHide = "question.hide"
- QuestionShow = "question.show"
- AnswerAdd = "answer.add"
- AnswerEdit = "answer.edit"
- AnswerEditWithoutReview = "answer.edit_without_review"
- AnswerDelete = "answer.delete"
- AnswerAccept = "answer.accept"
- AnswerVoteUp = "answer.vote_up"
- AnswerVoteDown = "answer.vote_down"
- CommentAdd = "comment.add"
- CommentEdit = "comment.edit"
- CommentDelete = "comment.delete"
- CommentVoteUp = "comment.vote_up"
- CommentVoteDown = "comment.vote_down"
- ReportAdd = "report.add"
- TagAdd = "tag.add"
- TagEdit = "tag.edit"
- TagEditSlugName = "tag.edit_slug_name"
- TagEditWithoutReview = "tag.edit_without_review"
- TagDelete = "tag.delete"
- TagSynonym = "tag.synonym"
- LinkUrlLimit = "link.url_limit"
- VoteDetail = "vote.detail"
- AnswerAudit = "answer.audit"
- QuestionAudit = "question.audit"
- TagAudit = "tag.audit"
- TagUseReservedTag = "tag.use_reserved_tag"
+ AdminAccess = "admin.access"
+ QuestionAdd = "question.add"
+ QuestionEdit = "question.edit"
+ QuestionEditWithoutReview = "question.edit_without_review"
+ QuestionDelete = "question.delete"
+ QuestionClose = "question.close"
+ QuestionReopen = "question.reopen"
+ QuestionVoteUp = "question.vote_up"
+ QuestionVoteDown = "question.vote_down"
+ QuestionPin = "question.pin"
+ QuestionUnPin = "question.unpin"
+ QuestionHide = "question.hide"
+ QuestionShow = "question.show"
+ AnswerAdd = "answer.add"
+ AnswerEdit = "answer.edit"
+ AnswerEditWithoutReview = "answer.edit_without_review"
+ AnswerDelete = "answer.delete"
+ AnswerAccept = "answer.accept"
+ AnswerVoteUp = "answer.vote_up"
+ AnswerVoteDown = "answer.vote_down"
+ AnswerInviteSomeoneToAnswer = "answer.invite_someone_to_answer"
+ CommentAdd = "comment.add"
+ CommentEdit = "comment.edit"
+ CommentDelete = "comment.delete"
+ CommentVoteUp = "comment.vote_up"
+ CommentVoteDown = "comment.vote_down"
+ ReportAdd = "report.add"
+ TagAdd = "tag.add"
+ TagEdit = "tag.edit"
+ TagEditSlugName = "tag.edit_slug_name"
+ TagEditWithoutReview = "tag.edit_without_review"
+ TagDelete = "tag.delete"
+ TagSynonym = "tag.synonym"
+ LinkUrlLimit = "link.url_limit"
+ VoteDetail = "vote.detail"
+ AnswerAudit = "answer.audit"
+ QuestionAudit = "question.audit"
+ TagAudit = "tag.audit"
+ TagUseReservedTag = "tag.use_reserved_tag"
)
const (