Merge branch 'feat/1.3.0/review' into test

This commit is contained in:
LinkinStars
2024-03-20 11:53:54 +08:00
11 changed files with 84 additions and 27 deletions
+13 -8
View File
@@ -7878,6 +7878,9 @@ const docTemplate = `{
"reason": {
"$ref": "#/definitions/schema.ReasonItem"
},
"reason_content": {
"type": "string"
},
"submit_at": {
"type": "integer"
},
@@ -7915,33 +7918,29 @@ const docTemplate = `{
"schema.GetRevisionResp": {
"type": "object",
"properties": {
"content": {
"description": "content parsed"
},
"content": {},
"create_at": {
"type": "integer"
},
"id": {
"description": "id",
"type": "string"
},
"object_id": {
"description": "object id",
"type": "string"
},
"reason": {
"type": "string"
},
"status": {
"description": "revision status(normal: 1; delete 2)",
"type": "integer"
},
"title": {
"description": "title",
"type": "string"
},
"url_title": {
"type": "string"
},
"use_id": {
"description": "user id",
"type": "string"
},
"user_info": {
@@ -8794,6 +8793,9 @@ const docTemplate = `{
"placeholder": {
"type": "string"
},
"reason_key": {
"type": "string"
},
"reason_type": {
"type": "integer"
}
@@ -9713,6 +9715,9 @@ const docTemplate = `{
},
"title": {
"type": "string"
},
"url_title": {
"type": "string"
}
}
},
+13 -8
View File
@@ -7866,6 +7866,9 @@
"reason": {
"$ref": "#/definitions/schema.ReasonItem"
},
"reason_content": {
"type": "string"
},
"submit_at": {
"type": "integer"
},
@@ -7903,33 +7906,29 @@
"schema.GetRevisionResp": {
"type": "object",
"properties": {
"content": {
"description": "content parsed"
},
"content": {},
"create_at": {
"type": "integer"
},
"id": {
"description": "id",
"type": "string"
},
"object_id": {
"description": "object id",
"type": "string"
},
"reason": {
"type": "string"
},
"status": {
"description": "revision status(normal: 1; delete 2)",
"type": "integer"
},
"title": {
"description": "title",
"type": "string"
},
"url_title": {
"type": "string"
},
"use_id": {
"description": "user id",
"type": "string"
},
"user_info": {
@@ -8782,6 +8781,9 @@
"placeholder": {
"type": "string"
},
"reason_key": {
"type": "string"
},
"reason_type": {
"type": "integer"
}
@@ -9701,6 +9703,9 @@
},
"title": {
"type": "string"
},
"url_title": {
"type": "string"
}
}
},
+9 -7
View File
@@ -855,6 +855,8 @@ definitions:
type: string
reason:
$ref: '#/definitions/schema.ReasonItem'
reason_content:
type: string
submit_at:
type: integer
submitter_user:
@@ -879,26 +881,22 @@ definitions:
type: object
schema.GetRevisionResp:
properties:
content:
description: content parsed
content: {}
create_at:
type: integer
id:
description: id
type: string
object_id:
description: object id
type: string
reason:
type: string
status:
description: 'revision status(normal: 1; delete 2)'
type: integer
title:
description: title
type: string
url_title:
type: string
use_id:
description: user id
type: string
user_info:
$ref: '#/definitions/schema.UserBasicInfo'
@@ -1491,6 +1489,8 @@ definitions:
type: string
placeholder:
type: string
reason_key:
type: string
reason_type:
type: integer
type: object
@@ -2117,6 +2117,8 @@ definitions:
type: array
title:
type: string
url_title:
type: string
type: object
schema.UpdateCommentReq:
properties:
+4
View File
@@ -18,6 +18,7 @@
# The following fields are used for back-end
backend:
base:
success:
other: Success.
@@ -141,6 +142,9 @@ backend:
email_or_password_wrong_error:
other: Email and password do not match.
error:
common:
invalid_url:
other: Invalid URL.
password:
space_invalid:
other: Password cannot contain spaces.
+3 -3
View File
@@ -100,9 +100,9 @@ const (
AdminCannotModifySelfStatus = "error.admin.cannot_modify_self_status"
UserAccessDenied = "error.user.access_denied"
UserPageAccessDenied = "error.user.page_access_denied"
AddBulkUsersFormatError = "error.user.add_bulk_users_format_error"
AddBulkUsersAmountError = "error.user.add_bulk_users_amount_error"
AddBulkUsersFormatError = "error.user.add_bulk_users_format_error"
AddBulkUsersAmountError = "error.user.add_bulk_users_amount_error"
InvalidURLError = "error.common.invalid_url"
)
// user external login reasons
+7
View File
@@ -21,11 +21,18 @@ package migrations
import (
"context"
"fmt"
"github.com/apache/incubator-answer/internal/entity"
"github.com/segmentfault/pacman/log"
"xorm.io/xorm"
)
func addReview(ctx context.Context, x *xorm.Engine) error {
c := &entity.Config{Key: "reason.not_clarity", Value: `{"name":"needs details or clarity","description":"This question currently includes multiple questions in one. It should focus on one problem only."}`}
if _, err := x.Context(ctx).Update(c, &entity.Config{Key: "reason.not_clarity"}); err != nil {
log.Errorf("update %+v config failed: %s", c, err)
return fmt.Errorf("update config failed: %w", err)
}
return x.Context(ctx).Sync(new(entity.Review))
}
+3 -1
View File
@@ -25,6 +25,7 @@ import (
)
type ReasonItem struct {
ReasonKey string `json:"reason_key"`
ReasonType int `json:"reason_type"`
Name string `json:"name"`
Description string `json:"description"`
@@ -52,9 +53,10 @@ func (r *ReasonItem) Translate(keyPrefix string, lang i18n.Language) {
return fieldTr
}
// If i18n key not exists, return fieldData original value
return fieldData + "没翻译"
return fieldData
}
r.ReasonKey = keyPrefix
r.Name = trField("name", r.Name)
r.Description = trField("desc", r.Description)
r.Placeholder = trField("placeholder", r.Placeholder)
+1
View File
@@ -91,6 +91,7 @@ type GetReportListPageResp struct {
SubmitAt int64 `json:"submit_at"`
SubmitterUser UserBasicInfo `json:"submitter_user"`
Reason *ReasonItem `json:"reason"`
ReasonContent string `json:"reason_content"`
}
// GetUnreviewedReportPostPageReq get unreviewed report post page request
+6
View File
@@ -280,6 +280,12 @@ func CustomAvatar(url string) *AvatarInfo {
func (req *UpdateInfoRequest) Check() (errFields []*validator.FormErrorField, err error) {
req.BioHTML = converter.Markdown2BasicHTML(req.Bio)
if len(req.Website) > 0 && !checker.IsURL(req.Website) {
return append(errFields, &validator.FormErrorField{
ErrorField: "website",
ErrorMsg: reason.InvalidURLError,
}), errors.BadRequest(reason.InvalidURLError)
}
return nil, nil
}
@@ -146,6 +146,7 @@ func (rs *ReportService) GetUnreviewedReportPostPage(ctx context.Context, req *s
SubmitAt: report.CreatedAt.Unix(),
ObjectStatus: info.Status,
ObjectShowStatus: info.ShowStatus,
ReasonContent: report.Content,
}
// get user info
+24
View File
@@ -0,0 +1,24 @@
package checker
import (
"net/url"
"strings"
)
func IsURL(str string) bool {
s := strings.ToLower(str)
if len(s) == 0 {
return false
}
u, err := url.Parse(s)
if err != nil || u.Scheme == "" {
return false
}
if u.Host == "" && u.Fragment == "" && u.Opaque == "" {
return false
}
return u.Scheme == "http" || u.Scheme == "https"
}