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(review): add reason key and content for review page
LinkinStarsc440b1201b9e
diff --git a/docs/docs.go b/docs/docs.goindex 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.jsonindex 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.yamlindex 204c5bce..e9bb895e 100644--- a/docs/swagger.yaml+++ b/docs/swagger.yaml@@ -855,6 +855,8 @@ definitions:type: stringreason:$ref: '#/definitions/schema.ReasonItem'+ reason_content:+ type: stringsubmit_at:type: integersubmitter_user:@@ -879,26 +881,22 @@ definitions:type: objectschema.GetRevisionResp:properties:- content:- description: content parsed+ content: {}create_at:type: integerid:- description: idtype: stringobject_id:- description: object idtype: stringreason:type: stringstatus:- description: 'revision status(normal: 1; delete 2)'type: integertitle:- description: title+ type: string+ url_title:type: stringuse_id:- description: user idtype: stringuser_info:$ref: '#/definitions/schema.UserBasicInfo'@@ -1491,6 +1489,8 @@ definitions:type: stringplaceholder:type: string+ reason_key:+ type: stringreason_type:type: integertype: object@@ -2117,6 +2117,8 @@ definitions:type: arraytitle:type: string+ url_title:+ type: stringtype: objectschema.UpdateCommentReq:properties:diff --git a/i18n/en_US.yaml b/i18n/en_US.yamlindex d70850e6..0feac0b8 100644--- a/i18n/en_US.yaml+++ b/i18n/en_US.yaml@@ -18,6 +18,7 @@# The following fields are used for back-endbackend:+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.goindex 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 reasonsdiff --git a/internal/schema/reason_schema.go b/internal/schema/reason_schema.goindex 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 = keyPrefixr.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.goindex 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 requestdiff --git a/internal/schema/user_schema.go b/internal/schema/user_schema.goindex 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.goindex 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 *sSubmitAt: report.CreatedAt.Unix(),ObjectStatus: info.Status,ObjectShowStatus: info.ShowStatus,+ ReasonContent: report.Content,}// get user infodiff --git a/pkg/checker/url.go b/pkg/checker/url.gonew file mode 100644index 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"+}