You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@answer.apache.org by li...@apache.org on 2024/01/16 08:36:40 UTC
(incubator-answer) 01/08: developing
This is an automated email from the ASF dual-hosted git repository.
linkinstar pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/incubator-answer.git
commit e51f438e1976c93079ae0ca3682aef6373792517
Author: hgaol <dh...@hotmail.com>
AuthorDate: Fri Jan 5 22:24:33 2024 +0800
developing
---
i18n/en_US.yaml | 3 +++
internal/schema/siteinfo_schema.go | 3 ++-
internal/service/siteinfo/siteinfo_service.go | 10 +++++++---
3 files changed, 12 insertions(+), 4 deletions(-)
diff --git a/i18n/en_US.yaml b/i18n/en_US.yaml
index e99d99bc..45e85f83 100644
--- a/i18n/en_US.yaml
+++ b/i18n/en_US.yaml
@@ -83,6 +83,9 @@ backend:
level_3:
description:
other: Level 3 (high reputation required for mature community)
+ level_custom:
+ description:
+ other: Custom Level
rank_question_add_label:
other: Ask question
rank_answer_add_label:
diff --git a/internal/schema/siteinfo_schema.go b/internal/schema/siteinfo_schema.go
index fc56bf5a..b03261ae 100644
--- a/internal/schema/siteinfo_schema.go
+++ b/internal/schema/siteinfo_schema.go
@@ -313,7 +313,8 @@ type PrivilegeOption struct {
// UpdatePrivilegesConfigReq update privileges config request
type UpdatePrivilegesConfigReq struct {
- Level PrivilegeLevel `validate:"required,min=1,max=3" json:"level"`
+ Level PrivilegeLevel `validate:"required,min=1,max=3" json:"level"`
+ Custom *PrivilegeOption `json:"custom"`
}
var (
diff --git a/internal/service/siteinfo/siteinfo_service.go b/internal/service/siteinfo/siteinfo_service.go
index 7f609e6c..660a25b6 100644
--- a/internal/service/siteinfo/siteinfo_service.go
+++ b/internal/service/siteinfo/siteinfo_service.go
@@ -311,8 +311,12 @@ func (s *SiteInfoService) GetPrivilegesConfig(ctx context.Context) (resp *schema
if err = s.siteInfoCommonService.GetSiteInfoByType(ctx, constant.SiteTypePrivileges, privilege); err != nil {
return nil, err
}
+ privilegeOptions := schema.DefaultPrivilegeOptions
+ if privilege.Custom != nil {
+ privilegeOptions = append(privilegeOptions, privilege.Custom)
+ }
resp = &schema.GetPrivilegesConfigResp{
- Options: s.translatePrivilegeOptions(ctx),
+ Options: s.translatePrivilegeOptions(ctx, privilegeOptions),
SelectedLevel: schema.PrivilegeLevel3,
}
if privilege != nil && privilege.Level > 0 {
@@ -321,9 +325,9 @@ func (s *SiteInfoService) GetPrivilegesConfig(ctx context.Context) (resp *schema
return resp, nil
}
-func (s *SiteInfoService) translatePrivilegeOptions(ctx context.Context) (options []*schema.PrivilegeOption) {
+func (s *SiteInfoService) translatePrivilegeOptions(ctx context.Context, privilegeOptions []*schema.PrivilegeOption) (options []*schema.PrivilegeOption) {
la := handler.GetLangByCtx(ctx)
- for _, option := range schema.DefaultPrivilegeOptions {
+ for _, option := range privilegeOptions {
op := &schema.PrivilegeOption{
Level: option.Level,
LevelDesc: translator.Tr(la, option.LevelDesc),