Skip to content

Commit e1ff073

Browse files
committed
fix: conflict
2 parents 52e1b8b + e3151c1 commit e1ff073

File tree

13 files changed

+118
-40
lines changed

13 files changed

+118
-40
lines changed

i18n/en_US.yaml

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,8 @@ backend:
235235
other: No permission to update.
236236
content_cannot_empty:
237237
other: Content cannot be empty.
238+
content_less_than_minumum:
239+
other: Not enough content entered.
238240
rank:
239241
fail_to_meet_the_condition:
240242
other: Reputation rank fail to meet the condition.
@@ -1161,6 +1163,9 @@ ui:
11611163
label: Body
11621164
msg:
11631165
empty: Body cannot be empty.
1166+
hint:
1167+
optional_body: Share what the question is about.
1168+
minimum_characters: "Share what the question is about, at least {{min_content_length}} characters are required."
11641169
tags:
11651170
label: Tags
11661171
msg:
@@ -1182,9 +1187,9 @@ ui:
11821187
add_btn: Add tag
11831188
create_btn: Create new tag
11841189
search_tag: Search tag
1185-
hint: "Describe what your content is about, at least one tag is required."
1186-
hint_zero_tags: " Describe what your content is about."
1187-
hint_more_than_one_tag: "Describe what your content is about, at least {{ min_tags_number }} tags are required."
1190+
hint: Describe what your content is about, at least one tag is required.
1191+
hint_zero_tags: Describe what your content is about.
1192+
hint_more_than_one_tag: "Describe what your content is about, at least {{min_tags_number}} tags are required."
11881193
no_result: No tags matched
11891194
tag_required_text: Required tag (at least one)
11901195
header:
@@ -2125,13 +2130,16 @@ ui:
21252130
ask_before_display: Ask before displaying external content
21262131
write:
21272132
page_title: Write
2133+
min_content:
2134+
label: Minimum question body length
2135+
text: Minimum allowed question body length in characters.
21282136
restrict_answer:
21292137
title: Answer write
21302138
label: Each user can only write one answer for the same question
21312139
text: "Turn off to allow users to write multiple answers to the same question, which may cause answers to be unfocused."
21322140
min_tags:
21332141
label: "Minimum tags per question"
2134-
text: "Minimum number of tags required in a question"
2142+
text: "Minimum number of tags required in a question."
21352143
recommend_tags:
21362144
label: Recommend tags
21372145
text: "Recommend tags will show in the dropdown list by default."

internal/base/reason/reason.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ const (
4747
QuestionAlreadyDeleted = "error.question.already_deleted"
4848
QuestionUnderReview = "error.question.under_review"
4949
QuestionContentCannotEmpty = "error.question.content_cannot_empty"
50+
QuestionContentLessThanMinimum = "error.question.content_less_than_minumum"
5051
AnswerNotFound = "error.answer.not_found"
5152
AnswerCannotDeleted = "error.answer.cannot_deleted"
5253
AnswerCannotUpdate = "error.answer.cannot_update"

internal/migrations/init.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ func (m *Mentor) initSiteInfoPrivilegeRank() {
289289

290290
func (m *Mentor) initSiteInfoWrite() {
291291
writeData := map[string]interface{}{
292+
"min_content": 6,
292293
"restrict_answer": true,
293294
"min_tags": 1,
294295
"required_tag": false,

internal/migrations/v28.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ func addOptionalTags(ctx context.Context, x *xorm.Engine) error {
4141
}
4242
if exist {
4343
type OldSiteWriteReq struct {
44+
MinimumContent int `json:"min_content"`
4445
RestrictAnswer bool `json:"restrict_answer"`
4546
MinimumTags int `json:"min_tags"`
4647
RequiredTag bool `json:"required_tag"`
@@ -55,6 +56,7 @@ func addOptionalTags(ctx context.Context, x *xorm.Engine) error {
5556
content := &OldSiteWriteReq{}
5657
_ = json.Unmarshal([]byte(writeSiteInfo.Content), content)
5758
content.MinimumTags = 1
59+
content.MinimumContent = 6
5860
data, _ := json.Marshal(content)
5961
writeSiteInfo.Content = string(data)
6062
_, err = x.Context(ctx).ID(writeSiteInfo.ID).Cols("content").Update(writeSiteInfo)

internal/schema/question_schema.go

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ type QuestionAdd struct {
7979
// question title
8080
Title string `validate:"required,notblank,gte=6,lte=150" json:"title"`
8181
// content
82-
Content string `validate:"required,notblank,gte=6,lte=65535" json:"content"`
82+
Content string `validate:"gte=0,lte=65535" json:"content"`
8383
// html
8484
HTML string `json:"-"`
8585
// tags
@@ -100,20 +100,14 @@ func (req *QuestionAdd) Check() (errFields []*validator.FormErrorField, err erro
100100
tag.ParsedText = converter.Markdown2HTML(tag.OriginalText)
101101
}
102102
}
103-
if req.HTML == "" {
104-
return append(errFields, &validator.FormErrorField{
105-
ErrorField: "content",
106-
ErrorMsg: reason.QuestionContentCannotEmpty,
107-
}), errors.BadRequest(reason.QuestionContentCannotEmpty)
108-
}
109103
return nil, nil
110104
}
111105

112106
type QuestionAddByAnswer struct {
113107
// question title
114108
Title string `validate:"required,notblank,gte=6,lte=150" json:"title"`
115109
// content
116-
Content string `validate:"required,notblank,gte=6,lte=65535" json:"content"`
110+
Content string `validate:"gte=0,lte=65535" json:"content"`
117111
// html
118112
HTML string `json:"-"`
119113
AnswerContent string `validate:"required,notblank,gte=6,lte=65535" json:"answer_content"`
@@ -138,19 +132,11 @@ func (req *QuestionAddByAnswer) Check() (errFields []*validator.FormErrorField,
138132
tag.ParsedText = converter.Markdown2HTML(tag.OriginalText)
139133
}
140134
}
141-
if req.HTML == "" {
142-
errFields = append(errFields, &validator.FormErrorField{
143-
ErrorField: "content",
144-
ErrorMsg: reason.QuestionContentCannotEmpty,
145-
})
146-
}
147135
if req.AnswerHTML == "" {
148136
errFields = append(errFields, &validator.FormErrorField{
149137
ErrorField: "answer_content",
150138
ErrorMsg: reason.AnswerContentCannotEmpty,
151139
})
152-
}
153-
if req.HTML == "" || req.AnswerHTML == "" {
154140
return errFields, errors.BadRequest(reason.QuestionContentCannotEmpty)
155141
}
156142
return nil, nil
@@ -195,7 +181,7 @@ type QuestionUpdate struct {
195181
// question title
196182
Title string `validate:"required,notblank,gte=6,lte=150" json:"title"`
197183
// content
198-
Content string `validate:"required,notblank,gte=6,lte=65535" json:"content"`
184+
Content string `validate:"gte=0,lte=65535" json:"content"`
199185
// html
200186
HTML string `json:"-"`
201187
InviteUser []string `validate:"omitempty" json:"invite_user"`
@@ -227,12 +213,6 @@ type QuestionUpdateInviteUser struct {
227213

228214
func (req *QuestionUpdate) Check() (errFields []*validator.FormErrorField, err error) {
229215
req.HTML = converter.Markdown2HTML(req.Content)
230-
if req.HTML == "" {
231-
return append(errFields, &validator.FormErrorField{
232-
ErrorField: "content",
233-
ErrorMsg: reason.QuestionContentCannotEmpty,
234-
}), errors.BadRequest(reason.QuestionContentCannotEmpty)
235-
}
236216
return nil, nil
237217
}
238218

internal/schema/siteinfo_schema.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ type SiteBrandingReq struct {
7575

7676
// SiteWriteReq site write request
7777
type SiteWriteReq struct {
78+
MinimumContent int `validate:"omitempty,min=0" json:"min_content"`
7879
RestrictAnswer bool `validate:"omitempty" json:"restrict_answer"`
7980
MinimumTags int `validate:"omitempty" json:"min_tags"`
8081
RequiredTag bool `validate:"omitempty" json:"required_tag"`

internal/service/content/question_service.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,19 @@ func (qs *QuestionService) CheckAddQuestion(ctx context.Context, req *schema.Que
242242
err = errors.BadRequest(reason.TagMinCount)
243243
return errorlist, err
244244
}
245+
minimumContentLength, err := qs.questioncommon.GetMinimumContentLength(ctx)
246+
if err != nil {
247+
return
248+
}
249+
if len(req.Content) < minimumContentLength {
250+
errorlist := make([]*validator.FormErrorField, 0)
251+
errorlist = append(errorlist, &validator.FormErrorField{
252+
ErrorField: "content",
253+
ErrorMsg: translator.Tr(handler.GetLangByCtx(ctx), reason.QuestionContentLessThanMinimum),
254+
})
255+
err = errors.BadRequest(reason.QuestionContentLessThanMinimum)
256+
return errorlist, err
257+
}
245258
recommendExist, err := qs.tagCommon.ExistRecommend(ctx, req.Tags)
246259
if err != nil {
247260
return
@@ -301,6 +314,19 @@ func (qs *QuestionService) AddQuestion(ctx context.Context, req *schema.Question
301314
err = errors.BadRequest(reason.TagMinCount)
302315
return errorlist, err
303316
}
317+
minimumContentLength, err := qs.questioncommon.GetMinimumContentLength(ctx)
318+
if err != nil {
319+
return
320+
}
321+
if len(req.Content) < minimumContentLength {
322+
errorlist := make([]*validator.FormErrorField, 0)
323+
errorlist = append(errorlist, &validator.FormErrorField{
324+
ErrorField: "content",
325+
ErrorMsg: translator.Tr(handler.GetLangByCtx(ctx), reason.QuestionContentLessThanMinimum),
326+
})
327+
err = errors.BadRequest(reason.QuestionContentLessThanMinimum)
328+
return errorlist, err
329+
}
304330
recommendExist, err := qs.tagCommon.ExistRecommend(ctx, req.Tags)
305331
if err != nil {
306332
return
@@ -907,6 +933,20 @@ func (qs *QuestionService) UpdateQuestion(ctx context.Context, req *schema.Quest
907933
question.UserID = dbinfo.UserID
908934
question.LastEditUserID = req.UserID
909935

936+
minimumContentLength, err := qs.questioncommon.GetMinimumContentLength(ctx)
937+
if err != nil {
938+
return
939+
}
940+
if len(req.Content) < minimumContentLength {
941+
errorlist := make([]*validator.FormErrorField, 0)
942+
errorlist = append(errorlist, &validator.FormErrorField{
943+
ErrorField: "content",
944+
ErrorMsg: translator.Tr(handler.GetLangByCtx(ctx), reason.QuestionContentLessThanMinimum),
945+
})
946+
err = errors.BadRequest(reason.QuestionContentLessThanMinimum)
947+
return errorlist, err
948+
}
949+
910950
oldTags, tagerr := qs.tagCommon.GetObjectEntityTag(ctx, question.ID)
911951
if tagerr != nil {
912952
return questionInfo, tagerr

internal/service/question_common/question.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -899,3 +899,11 @@ func (qs *QuestionCommon) tryToGetQuestionIDFromMsg(ctx context.Context, closeMs
899899
questionID = uid.DeShortID(questionID)
900900
return questionID
901901
}
902+
903+
func (qs *QuestionCommon) GetMinimumContentLength(ctx context.Context) (int, error) {
904+
siteInfo, err := qs.siteInfoService.GetSiteWrite(ctx)
905+
if err != nil {
906+
return 6, err
907+
}
908+
return siteInfo.MinimumContent, nil
909+
}

ui/src/common/interface.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,7 @@ export interface AdminSettingsLegal {
440440
export interface AdminSettingsWrite {
441441
restrict_answer?: boolean;
442442
min_tags?: number;
443+
min_content?: number;
443444
recommend_tags?: Tag[];
444445
required_tag?: boolean;
445446
reserved_tags?: Tag[];

ui/src/components/TagSelector/index.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -304,10 +304,9 @@ const TagSelector: FC<IProps> = ({
304304
return t('hint');
305305
}
306306

307-
const str = t('hint_more_than_one_tag', {
308-
min_content_length: writeInfo.min_tags,
307+
return t(`hint_more_than_one_tag`, {
308+
min_tags_number: writeInfo.min_tags,
309309
});
310-
return str;
311310
};
312311

313312
useEffect(() => {

0 commit comments

Comments
 (0)