Skip to content

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(flag): move flag(admin) -> flag(foreground)

kumfofa4782a4dca1
diff --git a/cmd/wire_gen.go b/cmd/wire_gen.go
index 96bdade4..33c943a5 100644
--- a/cmd/wire_gen.go
+++ b/cmd/wire_gen.go
@@ -68,8 +68,7 @@ import (
rank2 "github.com/apache/incubator-answer/internal/service/rank"
reason2 "github.com/apache/incubator-answer/internal/service/reason"
report2 "github.com/apache/incubator-answer/internal/service/report"
- "github.com/apache/incubator-answer/internal/service/report_admin"
- "github.com/apache/incubator-answer/internal/service/report_handle_admin"
+ "github.com/apache/incubator-answer/internal/service/report_handle"
"github.com/apache/incubator-answer/internal/service/revision_common"
role2 "github.com/apache/incubator-answer/internal/service/role"
"github.com/apache/incubator-answer/internal/service/search_parser"
@@ -159,24 +158,25 @@ func initApplication(debug bool, serverConf *conf.Server, dbConf *data.Database,
rateLimitMiddleware := middleware.NewRateLimitMiddleware(limitRepo)
commentController := controller.NewCommentController(commentService, rankService, captchaService, rateLimitMiddleware)
reportRepo := report.NewReportRepo(dataData, uniqueIDRepo)
- reportService := report2.NewReportService(reportRepo, objService)
+ followRepo := activity_common.NewFollowRepo(dataData, uniqueIDRepo, activityRepo)
+ collectionRepo := collection.NewCollectionRepo(dataData, uniqueIDRepo)
+ collectionCommon := collectioncommon.NewCollectionCommon(collectionRepo)
+ answerCommon := answercommon.NewAnswerCommon(answerRepo)
+ metaRepo := meta.NewMetaRepo(dataData)
+ metaService := meta2.NewMetaService(metaRepo)
+ questionCommon := questioncommon.NewQuestionCommon(questionRepo, answerRepo, voteRepo, followRepo, tagCommonService, userCommon, collectionCommon, answerCommon, metaService, configService, activityQueueService, dataData)
+ reportHandle := report_handle.NewReportHandle(questionCommon, commentRepo, configService, notificationQueueService)
+ reportService := report2.NewReportService(reportRepo, objService, userCommon, answerRepo, questionRepo, commentCommonRepo, reportHandle, configService)
reportController := controller.NewReportController(reportService, rankService, captchaService)
serviceVoteRepo := activity.NewVoteRepo(dataData, activityRepo, userRankRepo, notificationQueueService)
voteService := service.NewVoteService(serviceVoteRepo, configService, questionRepo, answerRepo, commentCommonRepo, objService)
voteController := controller.NewVoteController(voteService, rankService, captchaService)
- followRepo := activity_common.NewFollowRepo(dataData, uniqueIDRepo, activityRepo)
tagService := tag2.NewTagService(tagRepo, tagCommonService, revisionService, followRepo, siteInfoCommonService, activityQueueService)
tagController := controller.NewTagController(tagService, tagCommonService, rankService)
followFollowRepo := activity.NewFollowRepo(dataData, uniqueIDRepo, activityRepo)
followService := follow.NewFollowService(followFollowRepo, followRepo, tagCommonRepo)
followController := controller.NewFollowController(followService)
- collectionRepo := collection.NewCollectionRepo(dataData, uniqueIDRepo)
collectionGroupRepo := collection.NewCollectionGroupRepo(dataData)
- collectionCommon := collectioncommon.NewCollectionCommon(collectionRepo)
- answerCommon := answercommon.NewAnswerCommon(answerRepo)
- metaRepo := meta.NewMetaRepo(dataData)
- metaService := meta2.NewMetaService(metaRepo)
- questionCommon := questioncommon.NewQuestionCommon(questionRepo, answerRepo, voteRepo, followRepo, tagCommonService, userCommon, collectionCommon, answerCommon, metaService, configService, activityQueueService, dataData)
collectionService := service.NewCollectionService(collectionRepo, collectionGroupRepo, questionCommon)
collectionController := controller.NewCollectionController(collectionService)
answerActivityRepo := activity.NewAnswerActivityRepo(dataData, activityRepo, userRankRepo, notificationQueueService)
@@ -193,9 +193,6 @@ func initApplication(debug bool, serverConf *conf.Server, dbConf *data.Database,
serviceRevisionService := service.NewRevisionService(revisionRepo, userCommon, questionCommon, answerService, objService, questionRepo, answerRepo, tagRepo, tagCommonService, notificationQueueService, activityQueueService, reportRepo)
revisionController := controller.NewRevisionController(serviceRevisionService, rankService)
rankController := controller.NewRankController(rankService)
- reportHandle := report_handle_admin.NewReportHandle(questionCommon, commentRepo, configService, notificationQueueService)
- reportAdminService := report_admin.NewReportAdminService(reportRepo, userCommon, answerRepo, questionRepo, commentCommonRepo, reportHandle, configService, objService)
- controller_adminReportController := controller_admin.NewReportController(reportAdminService)
userAdminRepo := user.NewUserAdminRepo(dataData, authRepo)
userAdminService := user_admin.NewUserAdminService(userAdminRepo, userRoleRelService, authService, userCommon, userActiveActivityRepo, siteInfoCommonService, emailService, questionRepo, answerRepo, commentCommonRepo)
userAdminController := controller_admin.NewUserAdminController(userAdminService)
@@ -226,7 +223,7 @@ func initApplication(debug bool, serverConf *conf.Server, dbConf *data.Database,
pluginController := controller_admin.NewPluginController(pluginCommonService)
permissionController := controller.NewPermissionController(rankService)
userPluginController := controller.NewUserPluginController(pluginCommonService)
- answerAPIRouter := router.NewAnswerAPIRouter(langController, userController, commentController, reportController, voteController, tagController, followController, collectionController, questionController, answerController, searchController, revisionController, rankController, controller_adminReportController, userAdminController, reasonController, themeController, siteInfoController, controllerSiteInfoController, notificationController, dashboardController, uploadController, activityController, roleController, pluginController, permissionController, userPluginController)
+ answerAPIRouter := router.NewAnswerAPIRouter(langController, userController, commentController, reportController, voteController, tagController, followController, collectionController, questionController, answerController, searchController, revisionController, rankController, userAdminController, reasonController, themeController, siteInfoController, controllerSiteInfoController, notificationController, dashboardController, uploadController, activityController, roleController, pluginController, permissionController, userPluginController)
swaggerRouter := router.NewSwaggerRouter(swaggerConf)
uiRouter := router.NewUIRouter(controllerSiteInfoController, siteInfoCommonService)
authUserMiddleware := middleware.NewAuthUserMiddleware(authService, siteInfoCommonService)
diff --git a/docs/docs.go b/docs/docs.go
index dc56880a..85abcbb8 100644
--- a/docs/docs.go
+++ b/docs/docs.go
@@ -1,24 +1,4 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-// Code generated by swaggo/swag. DO NOT EDIT.
-
+// Package docs Code generated by swaggo/swag. DO NOT EDIT
package docs
import "github.com/swaggo/swag"
@@ -535,117 +515,6 @@ const docTemplate = `{
}
}
},
- "/answer/admin/api/report/": {
- "put": {
- "security": [
- {
- "ApiKeyAuth": []
- },
- {
- "ApiKeyAuth": []
- }
- ],
- "description": "handle flag",
- "consumes": [
- "application/json"
- ],
- "produces": [
- "application/json"
- ],
- "tags": [
- "admin"
- ],
- "summary": "handle flag",
- "parameters": [
- {
- "description": "flag",
- "name": "data",
- "in": "body",
- "required": true,
- "schema": {
- "$ref": "#/definitions/schema.ReportHandleReq"
- }
- }
- ],
- "responses": {
- "200": {
- "description": "OK",
- "schema": {
- "$ref": "#/definitions/handler.RespBody"
- }
- }
- }
- }
- },
- "/answer/admin/api/reports/page": {
- "get": {
- "security": [
- {
- "ApiKeyAuth": []
- },
- {
- "ApiKeyAuth": []
- }
- ],
- "description": "list report records",
- "consumes": [
- "application/json"
- ],
- "produces": [
- "application/json"
- ],
- "tags": [
- "admin"
- ],
- "summary": "list report page",
- "parameters": [
- {
- "enum": [
- "pending",
- "completed"
- ],
- "type": "string",
- "description": "status",
- "name": "status",
- "in": "query",
- "required": true
- },
- {
- "enum": [
- "all",
- "question",
- "answer",
- "comment"
- ],
- "type": "string",
- "description": "object_type",
- "name": "object_type",
- "in": "query",
- "required": true
- },
- {
- "type": "integer",
- "description": "page size",
- "name": "page",
- "in": "query"
- },
- {
- "type": "integer",
- "description": "page size",
- "name": "page_size",
- "in": "query"
- }
- ],
- "responses": {
- "200": {
- "description": "OK",
- "schema": {
- "$ref": "#/definitions/handler.RespBody"
- }
- }
- }
- }
- },
"/answer/admin/api/roles": {
"get": {
"description": "get role list",
@@ -4466,6 +4335,157 @@ const docTemplate = `{
}
}
},
+ "/answer/api/v1/report/": {
+ "put": {
+ "security": [
+ {
+ "ApiKeyAuth": []
+ },
+ {
+ "ApiKeyAuth": []
+ }
+ ],
+ "description": "handle flag",
+ "consumes": [
+ "application/json"
+ ],
+ "produces": [
+ "application/json"
+ ],
+ "tags": [
+ "Report"
+ ],
+ "summary": "handle flag",
+ "parameters": [
+ {
+ "description": "flag",
+ "name": "data",
+ "in": "body",
+ "required": true,
+ "schema": {
+ "$ref": "#/definitions/schema.ReportHandleReq"
+ }
+ }
+ ],
+ "responses": {
+ "200": {
+ "description": "OK",
+ "schema": {
+ "$ref": "#/definitions/handler.RespBody"
+ }
+ }
+ }
+ }
+ },
+ "/answer/api/v1/reports/page": {
+ "get": {
+ "security": [
+ {
+ "ApiKeyAuth": []
+ },
+ {
+ "ApiKeyAuth": []
+ }
+ ],
+ "description": "list report records",
+ "consumes": [
+ "application/json"
+ ],
+ "produces": [
+ "application/json"
+ ],
+ "tags": [
+ "Report"
+ ],
+ "summary": "list report page",
+ "parameters": [
+ {
+ "enum": [
+ "pending",
+ "completed"
+ ],
+ "type": "string",
+ "description": "status",
+ "name": "status",
+ "in": "query",
+ "required": true
+ },
+ {
+ "enum": [
+ "all",
+ "question",
+ "answer",
+ "comment"
+ ],
+ "type": "string",
+ "description": "object_type",
+ "name": "object_type",
+ "in": "query",
+ "required": true
+ },
+ {
+ "type": "integer",
+ "description": "page size",
+ "name": "page",
+ "in": "query"
+ },
+ {
+ "type": "integer",
+ "description": "page size",
+ "name": "page_size",
+ "in": "query"
+ }
+ ],
+ "responses": {
+ "200": {
+ "description": "OK",
+ "schema": {
+ "$ref": "#/definitions/handler.RespBody"
+ }
+ }
+ }
+ }
+ },
+ "/answer/api/v1/reviewing/type": {
+ "get": {
+ "security": [
+ {
+ "ApiKeyAuth": []
+ }
+ ],
+ "description": "get reviewing type",
+ "produces": [
+ "application/json"
+ ],
+ "tags": [
+ "Revision"
+ ],
+ "summary": "get reviewing type",
+ "responses": {
+ "200": {
+ "description": "OK",
+ "schema": {
+ "allOf": [
+ {
+ "$ref": "#/definitions/handler.RespBody"
+ },
+ {
+ "type": "object",
+ "properties": {
+ "data": {
+ "type": "array",
+ "items": {
+ "$ref": "#/definitions/schema.GetReviewingTypeResp"
+ }
+ }
+ }
+ }
+ ]
+ }
+ }
+ }
+ }
+ },
"/answer/api/v1/revisions": {
"get": {
"description": "get revision list",
@@ -6554,7 +6574,8 @@ const docTemplate = `{
"type": "string"
},
"value": {
- "type": "integer"
+ "type": "integer",
+ "minimum": 1
}
}
},
@@ -7094,6 +7115,12 @@ const docTemplate = `{
"action": {
"$ref": "#/definitions/schema.UIOptionAction"
},
+ "class_name": {
+ "type": "string"
+ },
+ "field_class_name": {
+ "type": "string"
+ },
"input_type": {
"type": "string"
},
@@ -7374,6 +7401,10 @@ const docTemplate = `{
"description": "bio html",
"type": "string"
},
+ "color_scheme": {
+ "description": "Color scheme",
+ "type": "string"
+ },
"created_at": {
"description": "create time",
"type": "integer"
@@ -7686,6 +7717,20 @@ const docTemplate = `{
}
}
},
+ "schema.GetReviewingTypeResp": {
+ "type": "object",
+ "properties": {
+ "label": {
+ "type": "string"
+ },
+ "name": {
+ "type": "string"
+ },
+ "todo_amount": {
+ "type": "integer"
+ }
+ }
+ },
"schema.GetRevisionResp": {
"type": "object",
"properties": {
@@ -8161,12 +8206,14 @@ const docTemplate = `{
"enum": [
1,
2,
- 3
+ 3,
+ 99
],
"x-enum-varnames": [
"PrivilegeLevel1",
"PrivilegeLevel2",
- "PrivilegeLevel3"
+ "PrivilegeLevel3",
+ "PrivilegeLevelCustom"
]
},
"schema.PrivilegeOption": {
@@ -9074,6 +9121,10 @@ const docTemplate = `{
"theme"
],
"properties": {
+ "color_scheme": {
+ "type": "string",
+ "maxLength": 100
+ },
"theme": {
"type": "string",
"maxLength": 255
@@ -9087,6 +9138,9 @@ const docTemplate = `{
"schema.SiteThemeResp": {
"type": "object",
"properties": {
+ "color_scheme": {
+ "type": "string"
+ },
"theme": {
"type": "string"
},
@@ -9435,8 +9489,13 @@ const docTemplate = `{
"level"
],
"properties": {
+ "custom_privileges": {
+ "type": "array",
+ "items": {
+ "$ref": "#/definitions/constant.Privilege"
+ }
+ },
"level": {
- "maximum": 3,
"minimum": 1,
"allOf": [
{
@@ -9542,9 +9601,15 @@ const docTemplate = `{
"schema.UpdateUserInterfaceRequest": {
"type": "object",
"required": [
+ "color_scheme",
"language"
],
"properties": {
+ "color_scheme": {
+ "description": "Color scheme",
+ "type": "string",
+ "maxLength": 100
+ },
"language": {
"description": "language",
"type": "string",
@@ -9652,6 +9717,9 @@ const docTemplate = `{
"id": {
"type": "string"
},
+ "language": {
+ "type": "string"
+ },
"location": {
"type": "string"
},
@@ -9757,6 +9825,10 @@ const docTemplate = `{
"description": "bio html",
"type": "string"
},
+ "color_scheme": {
+ "description": "Color scheme",
+ "type": "string"
+ },
"created_at": {
"description": "create time",
"type": "integer"
diff --git a/docs/swagger.json b/docs/swagger.json
index 83bde221..41858d60 100644
--- a/docs/swagger.json
+++ b/docs/swagger.json
@@ -504,117 +504,6 @@
}
}
},
- "/answer/admin/api/report/": {
- "put": {
- "security": [
- {
- "ApiKeyAuth": []
- },
- {
- "ApiKeyAuth": []
- }
- ],
- "description": "handle flag",
- "consumes": [
- "application/json"
- ],
- "produces": [
- "application/json"
- ],
- "tags": [
- "admin"
- ],
- "summary": "handle flag",
- "parameters": [
- {
- "description": "flag",
- "name": "data",
- "in": "body",
- "required": true,
- "schema": {
- "$ref": "#/definitions/schema.ReportHandleReq"
- }
- }
- ],
- "responses": {
- "200": {
- "description": "OK",
- "schema": {
- "$ref": "#/definitions/handler.RespBody"
- }
- }
- }
- }
- },
- "/answer/admin/api/reports/page": {
- "get": {
- "security": [
- {
- "ApiKeyAuth": []
- },
- {
- "ApiKeyAuth": []
- }
- ],
- "description": "list report records",
- "consumes": [
- "application/json"
- ],
- "produces": [
- "application/json"
- ],
- "tags": [
- "admin"
- ],
- "summary": "list report page",
- "parameters": [
- {
- "enum": [
- "pending",
- "completed"
- ],
- "type": "string",
- "description": "status",
- "name": "status",
- "in": "query",
- "required": true
- },
- {
- "enum": [
- "all",
- "question",
- "answer",
- "comment"
- ],
- "type": "string",
- "description": "object_type",
- "name": "object_type",
- "in": "query",
- "required": true
- },
- {
- "type": "integer",
- "description": "page size",
- "name": "page",
- "in": "query"
- },
- {
- "type": "integer",
- "description": "page size",
- "name": "page_size",
- "in": "query"
- }
- ],
- "responses": {
- "200": {
- "description": "OK",
- "schema": {
- "$ref": "#/definitions/handler.RespBody"
- }
- }
- }
- }
- },
"/answer/admin/api/roles": {
"get": {
"description": "get role list",
@@ -4435,6 +4324,157 @@
}
}
},
+ "/answer/api/v1/report/": {
+ "put": {
+ "security": [
+ {
+ "ApiKeyAuth": []
+ },
+ {
+ "ApiKeyAuth": []
+ }
+ ],
+ "description": "handle flag",
+ "consumes": [
+ "application/json"
+ ],
+ "produces": [
+ "application/json"
+ ],
+ "tags": [
+ "Report"
+ ],
+ "summary": "handle flag",
+ "parameters": [
+ {
+ "description": "flag",
+ "name": "data",
+ "in": "body",
+ "required": true,
+ "schema": {
+ "$ref": "#/definitions/schema.ReportHandleReq"
+ }
+ }
+ ],
+ "responses": {
+ "200": {
+ "description": "OK",
+ "schema": {
+ "$ref": "#/definitions/handler.RespBody"
+ }
+ }
+ }
+ }
+ },
+ "/answer/api/v1/reports/page": {
+ "get": {
+ "security": [
+ {
+ "ApiKeyAuth": []
+ },
+ {
+ "ApiKeyAuth": []
+ }
+ ],
+ "description": "list report records",
+ "consumes": [
+ "application/json"
+ ],
+ "produces": [
+ "application/json"
+ ],
+ "tags": [
+ "Report"
+ ],
+ "summary": "list report page",
+ "parameters": [
+ {
+ "enum": [
+ "pending",
+ "completed"
+ ],
+ "type": "string",
+ "description": "status",
+ "name": "status",
+ "in": "query",
+ "required": true
+ },
+ {
+ "enum": [
+ "all",
+ "question",
+ "answer",
+ "comment"
+ ],
+ "type": "string",
+ "description": "object_type",
+ "name": "object_type",
+ "in": "query",
+ "required": true
+ },
+ {
+ "type": "integer",
+ "description": "page size",
+ "name": "page",
+ "in": "query"
+ },
+ {
+ "type": "integer",
+ "description": "page size",
+ "name": "page_size",
+ "in": "query"
+ }
+ ],
+ "responses": {
+ "200": {
+ "description": "OK",
+ "schema": {
+ "$ref": "#/definitions/handler.RespBody"
+ }
+ }
+ }
+ }
+ },
+ "/answer/api/v1/reviewing/type": {
+ "get": {
+ "security": [
+ {
+ "ApiKeyAuth": []
+ }
+ ],
+ "description": "get reviewing type",
+ "produces": [
+ "application/json"
+ ],
+ "tags": [
+ "Revision"
+ ],
+ "summary": "get reviewing type",
+ "responses": {
+ "200": {
+ "description": "OK",
+ "schema": {
+ "allOf": [
+ {
+ "$ref": "#/definitions/handler.RespBody"
+ },
+ {
+ "type": "object",
+ "properties": {
+ "data": {
+ "type": "array",
+ "items": {
+ "$ref": "#/definitions/schema.GetReviewingTypeResp"
+ }
+ }
+ }
+ }
+ ]
+ }
+ }
+ }
+ }
+ },
"/answer/api/v1/revisions": {
"get": {
"description": "get revision list",
@@ -6523,7 +6563,8 @@
"type": "string"
},
"value": {
- "type": "integer"
+ "type": "integer",
+ "minimum": 1
}
}
},
@@ -7063,6 +7104,12 @@
"action": {
"$ref": "#/definitions/schema.UIOptionAction"
},
+ "class_name": {
+ "type": "string"
+ },
+ "field_class_name": {
+ "type": "string"
+ },
"input_type": {
"type": "string"
},
@@ -7343,6 +7390,10 @@
"description": "bio html",
"type": "string"
},
+ "color_scheme": {
+ "description": "Color scheme",
+ "type": "string"
+ },
"created_at": {
"description": "create time",
"type": "integer"
@@ -7655,6 +7706,20 @@
}
}
},
+ "schema.GetReviewingTypeResp": {
+ "type": "object",
+ "properties": {
+ "label": {
+ "type": "string"
+ },
+ "name": {
+ "type": "string"
+ },
+ "todo_amount": {
+ "type": "integer"
+ }
+ }
+ },
"schema.GetRevisionResp": {
"type": "object",
"properties": {
@@ -8130,12 +8195,14 @@
"enum": [
1,
2,
- 3
+ 3,
+ 99
],
"x-enum-varnames": [
"PrivilegeLevel1",
"PrivilegeLevel2",
- "PrivilegeLevel3"
+ "PrivilegeLevel3",
+ "PrivilegeLevelCustom"
]
},
"schema.PrivilegeOption": {
@@ -9043,6 +9110,10 @@
"theme"
],
"properties": {
+ "color_scheme": {
+ "type": "string",
+ "maxLength": 100
+ },
"theme": {
"type": "string",
"maxLength": 255
@@ -9056,6 +9127,9 @@
"schema.SiteThemeResp": {
"type": "object",
"properties": {
+ "color_scheme": {
+ "type": "string"
+ },
"theme": {
"type": "string"
},
@@ -9404,8 +9478,13 @@
"level"
],
"properties": {
+ "custom_privileges": {
+ "type": "array",
+ "items": {
+ "$ref": "#/definitions/constant.Privilege"
+ }
+ },
"level": {
- "maximum": 3,
"minimum": 1,
"allOf": [
{
@@ -9511,9 +9590,15 @@
"schema.UpdateUserInterfaceRequest": {
"type": "object",
"required": [
+ "color_scheme",
"language"
],
"properties": {
+ "color_scheme": {
+ "description": "Color scheme",
+ "type": "string",
+ "maxLength": 100
+ },
"language": {
"description": "language",
"type": "string",
@@ -9621,6 +9706,9 @@
"id": {
"type": "string"
},
+ "language": {
+ "type": "string"
+ },
"location": {
"type": "string"
},
@@ -9726,6 +9814,10 @@
"description": "bio html",
"type": "string"
},
+ "color_scheme": {
+ "description": "Color scheme",
+ "type": "string"
+ },
"created_at": {
"description": "create time",
"type": "integer"
diff --git a/docs/swagger.yaml b/docs/swagger.yaml
index ca78bc49..40331dcf 100644
--- a/docs/swagger.yaml
+++ b/docs/swagger.yaml
@@ -1,20 +1,3 @@
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-
definitions:
constant.NotificationChannelKey:
enum:
@@ -29,6 +12,7 @@ definitions:
label:
type: string
value:
+ minimum: 1
type: integer
type: object
handler.RespBody:
@@ -403,6 +387,10 @@ definitions:
properties:
action:
$ref: '#/definitions/schema.UIOptionAction'
+ class_name:
+ type: string
+ field_class_name:
+ type: string
input_type:
type: string
label:
@@ -603,6 +591,9 @@ definitions:
bio_html:
description: bio html
type: string
+ color_scheme:
+ description: Color scheme
+ type: string
created_at:
description: create time
type: integer
@@ -828,6 +819,15 @@ definitions:
description: url title
type: string
type: object
+ schema.GetReviewingTypeResp:
+ properties:
+ label:
+ type: string
+ name:
+ type: string
+ todo_amount:
+ type: integer
+ type: object
schema.GetRevisionResp:
properties:
content:
@@ -1156,11 +1156,13 @@ definitions:
- 1
- 2
- 3
+ - 99
type: integer
x-enum-varnames:
- PrivilegeLevel1
- PrivilegeLevel2
- PrivilegeLevel3
+ - PrivilegeLevelCustom
schema.PrivilegeOption:
properties:
level:
@@ -1783,6 +1785,9 @@ definitions:
type: object
schema.SiteThemeReq:
properties:
+ color_scheme:
+ maxLength: 100
+ type: string
theme:
maxLength: 255
type: string
@@ -1794,6 +1799,8 @@ definitions:
type: object
schema.SiteThemeResp:
properties:
+ color_scheme:
+ type: string
theme:
type: string
theme_config:
@@ -2030,10 +2037,13 @@ definitions:
type: object
schema.UpdatePrivilegesConfigReq:
properties:
+ custom_privileges:
+ items:
+ $ref: '#/definitions/constant.Privilege'
+ type: array
level:
allOf:
- $ref: '#/definitions/schema.PrivilegeLevel'
- maximum: 3
minimum: 1
required:
- level
@@ -2107,11 +2117,16 @@ definitions:
type: object
schema.UpdateUserInterfaceRequest:
properties:
+ color_scheme:
+ description: Color scheme
+ maxLength: 100
+ type: string
language:
description: language
maxLength: 100
type: string
required:
+ - color_scheme
- language
type: object
schema.UpdateUserNotificationConfigReq:
@@ -2183,6 +2198,8 @@ definitions:
type: string
id:
type: string
+ language:
+ type: string
location:
type: string
rank:
@@ -2257,6 +2274,9 @@ definitions:
bio_html:
description: bio html
type: string
+ color_scheme:
+ description: Color scheme
+ type: string
created_at:
description: create time
type: integer
@@ -2772,76 +2792,6 @@ paths:
summary: get reasons by object type and action
tags:
- reason
- /answer/admin/api/report/:
- put:
- consumes:
- - application/json
- description: handle flag
- parameters:
- - description: flag
- in: body
- name: data
- required: true
- schema:
- $ref: '#/definitions/schema.ReportHandleReq'
- produces:
- - application/json
- responses:
- "200":
- description: OK
- schema:
- $ref: '#/definitions/handler.RespBody'
- security:
- - ApiKeyAuth: []
- - ApiKeyAuth: []
- summary: handle flag
- tags:
- - admin
- /answer/admin/api/reports/page:
- get:
- consumes:
- - application/json
- description: list report records
- parameters:
- - description: status
- enum:
- - pending
- - completed
- in: query
- name: status
- required: true
- type: string
- - description: object_type
- enum:
- - all
- - question
- - answer
- - comment
- in: query
- name: object_type
- required: true
- type: string
- - description: page size
- in: query
- name: page
- type: integer
- - description: page size
- in: query
- name: page_size
- type: integer
- produces:
- - application/json
- responses:
- "200":
- description: OK
- schema:
- $ref: '#/definitions/handler.RespBody'
- security:
- - ApiKeyAuth: []
- - ApiKeyAuth: []
- summary: list report page
- tags:
- - admin
/answer/admin/api/roles:
get:
description: get role list
@@ -5147,6 +5097,98 @@ paths:
summary: add report
tags:
- Report
+ /answer/api/v1/report/:
+ put:
+ consumes:
+ - application/json
+ description: handle flag
+ parameters:
+ - description: flag
+ in: body
+ name: data
+ required: true
+ schema:
+ $ref: '#/definitions/schema.ReportHandleReq'
+ produces:
+ - application/json
+ responses:
+ "200":
+ description: OK
+ schema:
+ $ref: '#/definitions/handler.RespBody'
+ security:
+ - ApiKeyAuth: []
+ - ApiKeyAuth: []
+ summary: handle flag
+ tags:
+ - Report
+ /answer/api/v1/reports/page:
+ get:
+ consumes:
+ - application/json
+ description: list report records
+ parameters:
+ - description: status
+ enum:
+ - pending
+ - completed
+ in: query
+ name: status
+ required: true
+ type: string
+ - description: object_type
+ enum:
+ - all
+ - question
+ - answer
+ - comment
+ in: query
+ name: object_type
+ required: true
+ type: string
+ - description: page size
+ in: query
+ name: page
+ type: integer
+ - description: page size
+ in: query
+ name: page_size
+ type: integer
+ produces:
+ - application/json
+ responses:
+ "200":
+ description: OK
+ schema:
+ $ref: '#/definitions/handler.RespBody'
+ security:
+ - ApiKeyAuth: []
+ - ApiKeyAuth: []
+ summary: list report page
+ tags:
+ - Report
+ /answer/api/v1/reviewing/type:
+ get:
+ description: get reviewing type
+ produces:
+ - application/json
+ responses:
+ "200":
+ description: OK
+ schema:
+ allOf:
+ - $ref: '#/definitions/handler.RespBody'
+ - properties:
+ data:
+ items:
+ $ref: '#/definitions/schema.GetReviewingTypeResp'
+ type: array
+ type: object
+ security:
+ - ApiKeyAuth: []
+ summary: get reviewing type
+ tags:
+ - Revision
/answer/api/v1/revisions:
get:
description: get revision list
diff --git a/internal/controller/report_controller.go b/internal/controller/report_controller.go
index e0765154..a2efbc2d 100644
--- a/internal/controller/report_controller.go
+++ b/internal/controller/report_controller.go
@@ -31,6 +31,7 @@ import (
"github.com/apache/incubator-answer/internal/service/permission"
"github.com/apache/incubator-answer/internal/service/rank"
"github.com/apache/incubator-answer/internal/service/report"
+ "github.com/apache/incubator-answer/pkg/converter"
"github.com/apache/incubator-answer/pkg/uid"
"github.com/gin-gonic/gin"
"github.com/segmentfault/pacman/errors"
@@ -103,3 +104,61 @@ func (rc *ReportController) AddReport(ctx *gin.Context) {
}
handler.HandleResponse(ctx, err, nil)
}
+
+// ListReportPage godoc
+// @Summary list report page
+// @Description list report records
+// @Security ApiKeyAuth
+// @Tags Report
+// @Accept json
+// @Produce json
+// @Security ApiKeyAuth
+// @Param status query string true "status" Enums(pending, completed)
+// @Param object_type query string true "object_type" Enums(all, question,answer,comment)
+// @Param page query int false "page size"
+// @Param page_size query int false "page size"
+// @Success 200 {object} handler.RespBody
+// @Router /answer/api/v1/reports/page [get]
+func (rc *ReportController) ListReportPage(ctx *gin.Context) {
+ var (
+ objectType = ctx.Query("object_type")
+ status = ctx.Query("status")
+ page = converter.StringToInt(ctx.DefaultQuery("page", "1"))
+ pageSize = converter.StringToInt(ctx.DefaultQuery("page_size", "20"))
+ )
+
+ dto := schema.GetReportListPageDTO{
+ ObjectType: objectType,
+ Status: status,
+ Page: page,
+ PageSize: pageSize,
+ }
+
+ resp, err := rc.reportService.ListReportPage(ctx, dto)
+ if err != nil {
+ handler.HandleResponse(ctx, err, schema.ErrTypeModal)
+ } else {
+ handler.HandleResponse(ctx, err, resp)
+ }
+}
+
+// Handle godoc
+// @Summary handle flag
+// @Description handle flag
+// @Security ApiKeyAuth
+// @Tags Report
+// @Accept json
+// @Produce json
+// @Security ApiKeyAuth
+// @Param data body schema.ReportHandleReq true "flag"
+// @Success 200 {object} handler.RespBody
+// @Router /answer/api/v1/report/ [put]
+func (rc *ReportController) Handle(ctx *gin.Context) {
+ req := schema.ReportHandleReq{}
+ if handler.BindAndCheck(ctx, &req) {
+ return
+ }
+
+ err := rc.reportService.HandleReported(ctx, req)
+ handler.HandleResponse(ctx, err, nil)
+}
diff --git a/internal/controller_admin/controller.go b/internal/controller_admin/controller.go
index f51c62a0..de87d105 100644
--- a/internal/controller_admin/controller.go
+++ b/internal/controller_admin/controller.go
@@ -23,7 +23,6 @@ import "github.com/google/wire"
// ProviderSetController is controller providers.
var ProviderSetController = wire.NewSet(
- NewReportController,
NewUserAdminController,
NewThemeController,
NewSiteInfoController,
diff --git a/internal/controller_admin/report_controller.go b/internal/controller_admin/report_controller.go
deleted file mode 100644
index 435b5af8..00000000
--- a/internal/controller_admin/report_controller.go
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package controller_admin
-
-import (
- "github.com/apache/incubator-answer/internal/base/handler"
- "github.com/apache/incubator-answer/internal/schema"
- "github.com/apache/incubator-answer/internal/service/report_admin"
- "github.com/apache/incubator-answer/pkg/converter"
- "github.com/gin-gonic/gin"
-)
-
-// ReportController report controller
-type ReportController struct {
- reportService *report_admin.ReportAdminService
-}
-
-// NewReportController new controller
-func NewReportController(reportService *report_admin.ReportAdminService) *ReportController {
- return &ReportController{reportService: reportService}
-}
-
-// ListReportPage godoc
-// @Summary list report page
-// @Description list report records
-// @Security ApiKeyAuth
-// @Tags admin
-// @Accept json
-// @Produce json
-// @Security ApiKeyAuth
-// @Param status query string true "status" Enums(pending, completed)
-// @Param object_type query string true "object_type" Enums(all, question,answer,comment)
-// @Param page query int false "page size"
-// @Param page_size query int false "page size"
-// @Success 200 {object} handler.RespBody
-// @Router /answer/admin/api/reports/page [get]
-func (rc *ReportController) ListReportPage(ctx *gin.Context) {
- var (
- objectType = ctx.Query("object_type")
- status = ctx.Query("status")
- page = converter.StringToInt(ctx.DefaultQuery("page", "1"))
- pageSize = converter.StringToInt(ctx.DefaultQuery("page_size", "20"))
- )
-
- dto := schema.GetReportListPageDTO{
- ObjectType: objectType,
- Status: status,
- Page: page,
- PageSize: pageSize,
- }
-
- resp, err := rc.reportService.ListReportPage(ctx, dto)
- if err != nil {
- handler.HandleResponse(ctx, err, schema.ErrTypeModal)
- } else {
- handler.HandleResponse(ctx, err, resp)
- }
-}
-
-// Handle godoc
-// @Summary handle flag
-// @Description handle flag
-// @Security ApiKeyAuth
-// @Tags admin
-// @Accept json
-// @Produce json
-// @Security ApiKeyAuth
-// @Param data body schema.ReportHandleReq true "flag"
-// @Success 200 {object} handler.RespBody
-// @Router /answer/admin/api/report/ [put]
-func (rc *ReportController) Handle(ctx *gin.Context) {
- req := schema.ReportHandleReq{}
- if handler.BindAndCheck(ctx, &req) {
- return
- }
-
- err := rc.reportService.HandleReported(ctx, req)
- handler.HandleResponse(ctx, err, nil)
-}
diff --git a/internal/router/answer_api_router.go b/internal/router/answer_api_router.go
index 0469103e..2895d103 100644
--- a/internal/router/answer_api_router.go
+++ b/internal/router/answer_api_router.go
@@ -40,7 +40,6 @@ type AnswerAPIRouter struct {
searchController *controller.SearchController
revisionController *controller.RevisionController
rankController *controller.RankController
- adminReportController *controller_admin.ReportController
adminUserController *controller_admin.UserAdminController
reasonController *controller.ReasonController
themeController *controller_admin.ThemeController
@@ -70,7 +69,6 @@ func NewAnswerAPIRouter(
searchController *controller.SearchController,
revisionController *controller.RevisionController,
rankController *controller.RankController,
- adminReportController *controller_admin.ReportController,
adminUserController *controller_admin.UserAdminController,
reasonController *controller.ReasonController,
themeController *controller_admin.ThemeController,
@@ -99,7 +97,6 @@ func NewAnswerAPIRouter(
searchController: searchController,
revisionController: revisionController,
rankController: rankController,
- adminReportController: adminReportController,
adminUserController: adminUserController,
reasonController: reasonController,
themeController: themeController,
@@ -279,6 +276,10 @@ func (a *AnswerAPIRouter) RegisterAnswerAPIRouter(r *gin.RouterGroup) {
r.GET("/user/plugin/configs", a.userPluginController.GetUserPluginList)
r.GET("/user/plugin/config", a.userPluginController.GetUserPluginConfig)
r.PUT("/user/plugin/config", a.userPluginController.UpdatePluginUserConfig)
+
+ // report
+ r.GET("/reports/page", a.reportController.ListReportPage)
+ r.PUT("/report", a.reportController.Handle)
}
func (a *AnswerAPIRouter) RegisterAnswerAdminAPIRouter(r *gin.RouterGroup) {
@@ -287,10 +288,6 @@ func (a *AnswerAPIRouter) RegisterAnswerAdminAPIRouter(r *gin.RouterGroup) {
r.GET("/answer/page", a.questionController.AdminAnswerPage)
r.PUT("/answer/status", a.answerController.AdminUpdateAnswerStatus)
- // report
- r.GET("/reports/page", a.adminReportController.ListReportPage)
- r.PUT("/report", a.adminReportController.Handle)
-
// user
r.GET("/users/page", a.adminUserController.GetUserPage)
r.PUT("/user/status", a.adminUserController.UpdateUserStatus)
diff --git a/internal/service/provider.go b/internal/service/provider.go
index 38b9cd72..462d2ce4 100644
--- a/internal/service/provider.go
+++ b/internal/service/provider.go
@@ -43,8 +43,7 @@ import (
"github.com/apache/incubator-answer/internal/service/rank"
"github.com/apache/incubator-answer/internal/service/reason"
"github.com/apache/incubator-answer/internal/service/report"
- "github.com/apache/incubator-answer/internal/service/report_admin"
- "github.com/apache/incubator-answer/internal/service/report_handle_admin"
+ "github.com/apache/incubator-answer/internal/service/report_handle"
"github.com/apache/incubator-answer/internal/service/revision_common"
"github.com/apache/incubator-answer/internal/service/role"
"github.com/apache/incubator-answer/internal/service/search_parser"
@@ -89,8 +88,7 @@ var ProviderSetService = wire.NewSet(
NewSearchService,
meta.NewMetaService,
object_info.NewObjService,
- report_handle_admin.NewReportHandle,
- report_admin.NewReportAdminService,
+ report_handle.NewReportHandle,
user_admin.NewUserAdminService,
reason.NewReasonService,
siteinfo_common.NewSiteInfoCommonService,
diff --git a/internal/service/report/report_service.go b/internal/service/report/report_service.go
index 55ac4272..287ad57b 100644
--- a/internal/service/report/report_service.go
+++ b/internal/service/report/report_service.go
@@ -20,11 +20,25 @@
package report
import (
+ "encoding/json"
+ "github.com/apache/incubator-answer/internal/base/handler"
+ "github.com/apache/incubator-answer/internal/base/pager"
+ "github.com/apache/incubator-answer/internal/base/reason"
"github.com/apache/incubator-answer/internal/entity"
"github.com/apache/incubator-answer/internal/schema"
+ answercommon "github.com/apache/incubator-answer/internal/service/answer_common"
+ "github.com/apache/incubator-answer/internal/service/comment_common"
+ "github.com/apache/incubator-answer/internal/service/config"
"github.com/apache/incubator-answer/internal/service/object_info"
+ questioncommon "github.com/apache/incubator-answer/internal/service/question_common"
"github.com/apache/incubator-answer/internal/service/report_common"
+ "github.com/apache/incubator-answer/internal/service/report_handle"
+ usercommon "github.com/apache/incubator-answer/internal/service/user_common"
+ "github.com/apache/incubator-answer/pkg/htmltext"
"github.com/apache/incubator-answer/pkg/obj"
+ "github.com/jinzhu/copier"
+ "github.com/segmentfault/pacman/errors"
+ "github.com/segmentfault/pacman/log"
"golang.org/x/net/context"
)
@@ -32,15 +46,34 @@ import (
type ReportService struct {
reportRepo report_common.ReportRepo
objectInfoService *object_info.ObjService
+ commonUser *usercommon.UserCommon
+ answerRepo answercommon.AnswerRepo
+ questionRepo questioncommon.QuestionRepo
+ commentCommonRepo comment_common.CommentCommonRepo
+ reportHandle *report_handle.ReportHandle
+ configService *config.ConfigService
}
// NewReportService new report service
-func NewReportService(reportRepo report_common.ReportRepo,
+func NewReportService(
+ reportRepo report_common.ReportRepo,
objectInfoService *object_info.ObjService,
+ commonUser *usercommon.UserCommon,
+ answerRepo answercommon.AnswerRepo,
+ questionRepo questioncommon.QuestionRepo,
+ commentCommonRepo comment_common.CommentCommonRepo,
+ reportHandle *report_handle.ReportHandle,
+ configService *config.ConfigService,
) *ReportService {
return &ReportService{
reportRepo: reportRepo,
objectInfoService: objectInfoService,
+ commonUser: commonUser,
+ answerRepo: answerRepo,
+ questionRepo: questionRepo,
+ commentCommonRepo: commentCommonRepo,
+ reportHandle: reportHandle,
+ configService: configService,
}
}
@@ -68,3 +101,119 @@ func (rs *ReportService) AddReport(ctx context.Context, req *schema.AddReportReq
}
return rs.reportRepo.AddReport(ctx, report)
}
+
+// ListReportPage list report pages
+func (rs *ReportService) ListReportPage(ctx context.Context, dto schema.GetReportListPageDTO) (pageModel *pager.PageModel, err error) {
+ var (
+ resp []*schema.GetReportListPageResp
+ flags []entity.Report
+ total int64
+
+ flaggedUserIds,
+ userIds []string
+
+ flaggedUsers,
+ users map[string]*schema.UserBasicInfo
+ )
+
+ flags, total, err = rs.reportRepo.GetReportListPage(ctx, dto)
+ if err != nil {
+ return
+ }
+
+ _ = copier.Copy(&resp, flags)
+ for _, r := range resp {
+ flaggedUserIds = append(flaggedUserIds, r.ReportedUserID)
+ userIds = append(userIds, r.UserID)
+ r.Format()
+ }
+
+ // flagged users
+ flaggedUsers, err = rs.commonUser.BatchUserBasicInfoByID(ctx, flaggedUserIds)
+ if err != nil {
+ return nil, err
+ }
+
+ // flag users
+ users, err = rs.commonUser.BatchUserBasicInfoByID(ctx, userIds)
+ if err != nil {
+ return nil, err
+ }
+ for _, r := range resp {
+ r.ReportedUser = flaggedUsers[r.ReportedUserID]
+ r.ReportUser = users[r.UserID]
+ rs.decorateReportResp(ctx, r)
+ }
+ return pager.NewPageModel(total, resp), nil
+}
+
+// HandleReported handle the reported object
+func (rs *ReportService) HandleReported(ctx context.Context, req schema.ReportHandleReq) (err error) {
+ var (
+ reported *entity.Report
+ handleData = entity.Report{
+ FlaggedContent: req.FlaggedContent,
+ FlaggedType: req.FlaggedType,
+ Status: entity.ReportStatusCompleted,
+ }
+ exist bool
+ )
+
+ reported, exist, err = rs.reportRepo.GetByID(ctx, req.ID)
+ if err != nil {
+ err = errors.BadRequest(reason.ReportHandleFailed).WithError(err).WithStack()
+ return
+ }
+ if !exist {
+ err = errors.NotFound(reason.ReportNotFound)
+ return
+ }
+
+ // check if handle or not
+ if reported.Status != entity.ReportStatusPending {
+ return
+ }
+
+ if err = rs.reportHandle.HandleObject(ctx, reported, req); err != nil {
+ return
+ }
+
+ err = rs.reportRepo.UpdateByID(ctx, reported.ID, handleData)
+ return
+}
+
+func (rs *ReportService) decorateReportResp(ctx context.Context, resp *schema.GetReportListPageResp) {
+ lang := handler.GetLangByCtx(ctx)
+ objectInfo, err := rs.objectInfoService.GetInfo(ctx, resp.ObjectID)
+ if err != nil {
+ log.Error(err)
+ return
+ }
+
+ resp.QuestionID = objectInfo.QuestionID
+ resp.AnswerID = objectInfo.AnswerID
+ resp.CommentID = objectInfo.CommentID
+ resp.Title = objectInfo.Title
+ resp.Excerpt = htmltext.FetchExcerpt(objectInfo.Content, "...", 240)
+
+ if resp.ReportType > 0 {
+ resp.Reason = &schema.ReasonItem{ReasonType: resp.ReportType}
+ cf, err := rs.configService.GetConfigByID(ctx, resp.ReportType)
+ if err != nil {
+ log.Error(err)
+ } else {
+ _ = json.Unmarshal([]byte(cf.Value), resp.Reason)
+ resp.Reason.Translate(cf.Key, lang)
+ }
+ }
+ if resp.FlaggedType > 0 {
+ resp.FlaggedReason = &schema.ReasonItem{ReasonType: resp.FlaggedType}
+ cf, err := rs.configService.GetConfigByID(ctx, resp.FlaggedType)
+ if err != nil {
+ log.Error(err)
+ } else {
+ _ = json.Unmarshal([]byte(cf.Value), resp.Reason)
+ resp.Reason.Translate(cf.Key, lang)
+ }
+ }
+}
diff --git a/internal/service/report_admin/report_backyard.go b/internal/service/report_admin/report_backyard.go
deleted file mode 100644
index 3b141796..00000000
--- a/internal/service/report_admin/report_backyard.go
+++ /dev/null
@@ -1,194 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package report_admin
-
-import (
- "context"
- "encoding/json"
-
- "github.com/apache/incubator-answer/internal/base/handler"
- "github.com/apache/incubator-answer/internal/service/config"
- "github.com/apache/incubator-answer/internal/service/object_info"
- "github.com/apache/incubator-answer/pkg/htmltext"
- "github.com/segmentfault/pacman/log"
-
- "github.com/apache/incubator-answer/internal/base/pager"
- "github.com/apache/incubator-answer/internal/base/reason"
- "github.com/apache/incubator-answer/internal/entity"
- "github.com/apache/incubator-answer/internal/schema"
- answercommon "github.com/apache/incubator-answer/internal/service/answer_common"
- "github.com/apache/incubator-answer/internal/service/comment_common"
- questioncommon "github.com/apache/incubator-answer/internal/service/question_common"
- "github.com/apache/incubator-answer/internal/service/report_common"
- "github.com/apache/incubator-answer/internal/service/report_handle_admin"
- usercommon "github.com/apache/incubator-answer/internal/service/user_common"
- "github.com/jinzhu/copier"
- "github.com/segmentfault/pacman/errors"
-)
-
-// ReportAdminService user service
-type ReportAdminService struct {
- reportRepo report_common.ReportRepo
- commonUser *usercommon.UserCommon
- answerRepo answercommon.AnswerRepo
- questionRepo questioncommon.QuestionRepo
- commentCommonRepo comment_common.CommentCommonRepo
- reportHandle *report_handle_admin.ReportHandle
- configService *config.ConfigService
- objectInfoService *object_info.ObjService
-}
-
-// NewReportAdminService new report service
-func NewReportAdminService(
- reportRepo report_common.ReportRepo,
- commonUser *usercommon.UserCommon,
- answerRepo answercommon.AnswerRepo,
- questionRepo questioncommon.QuestionRepo,
- commentCommonRepo comment_common.CommentCommonRepo,
- reportHandle *report_handle_admin.ReportHandle,
- configService *config.ConfigService,
- objectInfoService *object_info.ObjService) *ReportAdminService {
- return &ReportAdminService{
- reportRepo: reportRepo,
- commonUser: commonUser,
- answerRepo: answerRepo,
- questionRepo: questionRepo,
- commentCommonRepo: commentCommonRepo,
- reportHandle: reportHandle,
- configService: configService,
- objectInfoService: objectInfoService,
- }
-}
-
-// ListReportPage list report pages
-func (rs *ReportAdminService) ListReportPage(ctx context.Context, dto schema.GetReportListPageDTO) (pageModel *pager.PageModel, err error) {
- var (
- resp []*schema.GetReportListPageResp
- flags []entity.Report
- total int64
-
- flaggedUserIds,
- userIds []string
-
- flaggedUsers,
- users map[string]*schema.UserBasicInfo
- )
-
- flags, total, err = rs.reportRepo.GetReportListPage(ctx, dto)
- if err != nil {
- return
- }
-
- _ = copier.Copy(&resp, flags)
- for _, r := range resp {
- flaggedUserIds = append(flaggedUserIds, r.ReportedUserID)
- userIds = append(userIds, r.UserID)
- r.Format()
- }
-
- // flagged users
- flaggedUsers, err = rs.commonUser.BatchUserBasicInfoByID(ctx, flaggedUserIds)
- if err != nil {
- return nil, err
- }
-
- // flag users
- users, err = rs.commonUser.BatchUserBasicInfoByID(ctx, userIds)
- if err != nil {
- return nil, err
- }
- for _, r := range resp {
- r.ReportedUser = flaggedUsers[r.ReportedUserID]
- r.ReportUser = users[r.UserID]
- rs.decorateReportResp(ctx, r)
- }
- return pager.NewPageModel(total, resp), nil
-}
-
-// HandleReported handle the reported object
-func (rs *ReportAdminService) HandleReported(ctx context.Context, req schema.ReportHandleReq) (err error) {
- var (
- reported *entity.Report
- handleData = entity.Report{
- FlaggedContent: req.FlaggedContent,
- FlaggedType: req.FlaggedType,
- Status: entity.ReportStatusCompleted,
- }
- exist bool
- )
-
- reported, exist, err = rs.reportRepo.GetByID(ctx, req.ID)
- if err != nil {
- err = errors.BadRequest(reason.ReportHandleFailed).WithError(err).WithStack()
- return
- }
- if !exist {
- err = errors.NotFound(reason.ReportNotFound)
- return
- }
-
- // check if handle or not
- if reported.Status != entity.ReportStatusPending {
- return
- }
-
- if err = rs.reportHandle.HandleObject(ctx, reported, req); err != nil {
- return
- }
-
- err = rs.reportRepo.UpdateByID(ctx, reported.ID, handleData)
- return
-}
-
-func (rs *ReportAdminService) decorateReportResp(ctx context.Context, resp *schema.GetReportListPageResp) {
- lang := handler.GetLangByCtx(ctx)
- objectInfo, err := rs.objectInfoService.GetInfo(ctx, resp.ObjectID)
- if err != nil {
- log.Error(err)
- return
- }
-
- resp.QuestionID = objectInfo.QuestionID
- resp.AnswerID = objectInfo.AnswerID
- resp.CommentID = objectInfo.CommentID
- resp.Title = objectInfo.Title
- resp.Excerpt = htmltext.FetchExcerpt(objectInfo.Content, "...", 240)
-
- if resp.ReportType > 0 {
- resp.Reason = &schema.ReasonItem{ReasonType: resp.ReportType}
- cf, err := rs.configService.GetConfigByID(ctx, resp.ReportType)
- if err != nil {
- log.Error(err)
- } else {
- _ = json.Unmarshal([]byte(cf.Value), resp.Reason)
- resp.Reason.Translate(cf.Key, lang)
- }
- }
- if resp.FlaggedType > 0 {
- resp.FlaggedReason = &schema.ReasonItem{ReasonType: resp.FlaggedType}
- cf, err := rs.configService.GetConfigByID(ctx, resp.FlaggedType)
- if err != nil {
- log.Error(err)
- } else {
- _ = json.Unmarshal([]byte(cf.Value), resp.Reason)
- resp.Reason.Translate(cf.Key, lang)
- }
- }
-}
diff --git a/internal/service/report_handle_admin/report_handle.go b/internal/service/report_handle/report_handle.go
similarity index 99%
rename from internal/service/report_handle_admin/report_handle.go
rename to internal/service/report_handle/report_handle.go
index 37170396..8b51d7fa 100644
--- a/internal/service/report_handle_admin/report_handle.go
+++ b/internal/service/report_handle/report_handle.go
@@ -17,7 +17,7 @@
* under the License.
*/
-package report_handle_admin
+package report_handle
import (
"context"