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/03/19 10:39:58 UTC
(incubator-answer) branch feat/1.3.0/review updated: feat(review): add reason key and content for review page
This is an automated email from the ASF dual-hosted git repository.
linkinstar pushed a commit to branch feat/1.3.0/review
in repository https://gitbox.apache.org/repos/asf/incubator-answer.git
The following commit(s) were added to refs/heads/feat/1.3.0/review by this push:
new c440b120 feat(review): add reason key and content for review page
c440b120 is described below
commit c440b1201b9ed2b761ebeef125b4a166e9fec574
Author: LinkinStars <li...@foxmail.com>
AuthorDate: Tue Mar 19 18:39:45 2024 +0800
feat(review): add reason key and content for review page
---
docs/docs.go | 21 +++++++++++++--------
docs/swagger.json | 21 +++++++++++++--------
docs/swagger.yaml | 16 +++++++++-------
i18n/en_US.yaml | 4 ++++
internal/base/reason/reason.go | 6 +++---
internal/schema/reason_schema.go | 4 +++-
internal/schema/report_schema.go | 1 +
internal/schema/user_schema.go | 6 ++++++
internal/service/report/report_service.go | 1 +
pkg/checker/url.go | 24 ++++++++++++++++++++++++
10 files changed, 77 insertions(+), 27 deletions(-)
diff --git a/docs/docs.go b/docs/docs.go
index 086d660e..30a8e1bc 100644
--- a/docs/docs.go
+++ b/docs/docs.go
@@ -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"
}
}
},
diff --git a/docs/swagger.json b/docs/swagger.json
index 4c7663de..00b06d9a 100644
--- a/docs/swagger.json
+++ b/docs/swagger.json
@@ -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"
}
}
},
diff --git a/docs/swagger.yaml b/docs/swagger.yaml
index 204c5bce..e9bb895e 100644
--- a/docs/swagger.yaml
+++ b/docs/swagger.yaml
@@ -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:
diff --git a/i18n/en_US.yaml b/i18n/en_US.yaml
index d70850e6..0feac0b8 100644
--- a/i18n/en_US.yaml
+++ b/i18n/en_US.yaml
@@ -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.
diff --git a/internal/base/reason/reason.go b/internal/base/reason/reason.go
index 55f24322..0dbf73ac 100644
--- a/internal/base/reason/reason.go
+++ b/internal/base/reason/reason.go
@@ -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
diff --git a/internal/schema/reason_schema.go b/internal/schema/reason_schema.go
index 82d62743..b408ce9b 100644
--- a/internal/schema/reason_schema.go
+++ b/internal/schema/reason_schema.go
@@ -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)
diff --git a/internal/schema/report_schema.go b/internal/schema/report_schema.go
index a1574722..1f702df4 100644
--- a/internal/schema/report_schema.go
+++ b/internal/schema/report_schema.go
@@ -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
diff --git a/internal/schema/user_schema.go b/internal/schema/user_schema.go
index 7915e40c..a95acfc7 100644
--- a/internal/schema/user_schema.go
+++ b/internal/schema/user_schema.go
@@ -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
}
diff --git a/internal/service/report/report_service.go b/internal/service/report/report_service.go
index a494be9d..a3e07f47 100644
--- a/internal/service/report/report_service.go
+++ b/internal/service/report/report_service.go
@@ -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
diff --git a/pkg/checker/url.go b/pkg/checker/url.go
new file mode 100644
index 00000000..1ec97a59
--- /dev/null
+++ b/pkg/checker/url.go
@@ -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"
+}