Skip to content

Commit

Permalink
Merge branch 'dev' into test
Browse files Browse the repository at this point in the history
  • Loading branch information
LinkinStars committed Dec 25, 2024
2 parents 86cf384 + 0df7bec commit be8098a
Show file tree
Hide file tree
Showing 28 changed files with 456 additions and 43 deletions.
55 changes: 55 additions & 0 deletions docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,45 @@ const docTemplate = `{
}
}
},
"/answer/admin/api/delete/permanently": {
"delete": {
"security": [
{
"ApiKeyAuth": []
}
],
"description": "delete permanently",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"admin"
],
"summary": "delete permanently",
"parameters": [
{
"description": "DeletePermanentlyReq",
"name": "data",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/schema.DeletePermanentlyReq"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/handler.RespBody"
}
}
}
}
},
"/answer/admin/api/language/options": {
"get": {
"description": "Get language options",
Expand Down Expand Up @@ -8158,6 +8197,22 @@ const docTemplate = `{
}
}
},
"schema.DeletePermanentlyReq": {
"type": "object",
"required": [
"type"
],
"properties": {
"type": {
"type": "string",
"enum": [
"users",
"questions",
"answers"
]
}
}
},
"schema.EditUserProfileReq": {
"type": "object",
"required": [
Expand Down
55 changes: 55 additions & 0 deletions docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,45 @@
}
}
},
"/answer/admin/api/delete/permanently": {
"delete": {
"security": [
{
"ApiKeyAuth": []
}
],
"description": "delete permanently",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"admin"
],
"summary": "delete permanently",
"parameters": [
{
"description": "DeletePermanentlyReq",
"name": "data",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/schema.DeletePermanentlyReq"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/handler.RespBody"
}
}
}
}
},
"/answer/admin/api/language/options": {
"get": {
"description": "Get language options",
Expand Down Expand Up @@ -8131,6 +8170,22 @@
}
}
},
"schema.DeletePermanentlyReq": {
"type": "object",
"required": [
"type"
],
"properties": {
"type": {
"type": "string",
"enum": [
"users",
"questions",
"answers"
]
}
}
},
"schema.EditUserProfileReq": {
"type": "object",
"required": [
Expand Down
35 changes: 35 additions & 0 deletions docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,17 @@ definitions:
name:
type: string
type: object
schema.DeletePermanentlyReq:
properties:
type:
enum:
- users
- questions
- answers
type: string
required:
- type
type: object
schema.EditUserProfileReq:
properties:
display_name:
Expand Down Expand Up @@ -3106,6 +3117,30 @@ paths:
summary: DashboardInfo
tags:
- admin
/answer/admin/api/delete/permanently:
delete:
consumes:
- application/json
description: delete permanently
parameters:
- description: DeletePermanentlyReq
in: body
name: data
required: true
schema:
$ref: '#/definitions/schema.DeletePermanentlyReq'
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/handler.RespBody'
security:
- ApiKeyAuth: []
summary: delete permanently
tags:
- admin
/answer/admin/api/language/options:
get:
description: Get language options
Expand Down
15 changes: 13 additions & 2 deletions i18n/en_US.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,17 @@ backend:
other: No permission to update.
question_closed_cannot_add:
other: Questions are closed and cannot be added.
content_cannot_empty:
other: Answer content cannot be empty.
comment:
edit_without_permission:
other: Comment are not allowed to edit.
not_found:
other: Comment not found.
cannot_edit_after_deadline:
other: The comment time has been too long to modify.
content_cannot_empty:
other: Comment content cannot be empty.
email:
duplicate:
other: Email already exists.
Expand Down Expand Up @@ -225,6 +229,8 @@ backend:
other: No permission to close.
cannot_update:
other: No permission to update.
content_cannot_empty:
other: Content cannot be empty.
rank:
fail_to_meet_the_condition:
other: Reputation rank fail to meet the condition.
Expand Down Expand Up @@ -1498,6 +1504,7 @@ ui:
normal: Normal
closed: Closed
deleted: Deleted
deleted_permanently: Deleted permanently
pending: Pending
more: More
view: View
Expand Down Expand Up @@ -1536,6 +1543,9 @@ ui:
cannot_vote_for_self: You can't vote for your own post.
modal_confirm:
title: Error...
delete_permanently:
title: Delete permanently
content: Are you sure you want to delete permanently?
account_result:
success: Your new account is confirmed; you will be redirected to the home page.
link: Continue to homepage
Expand Down Expand Up @@ -2294,5 +2304,6 @@ ui:
user_deleted: This user has been deleted.
badge_activated: This badge has been activated.
badge_inactivated: This badge has been inactivated.


users_deleted: These users have been deleted.
posts_deleted: These questions have been deleted.
answers_deleted: These answers have been deleted.
15 changes: 13 additions & 2 deletions i18n/zh_CN.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,17 @@ backend:
other: 没有更新权限。
question_closed_cannot_add:
other: 问题已关闭,无法添加。
content_cannot_empty:
other: 回答内容不能为空。
comment:
edit_without_permission:
other: 不允许编辑评论。
not_found:
other: 评论未找到。
cannot_edit_after_deadline:
other: 评论时间太久,无法修改。
content_cannot_empty:
other: 评论内容不能为空。
email:
duplicate:
other: 邮箱已存在。
Expand Down Expand Up @@ -224,6 +228,8 @@ backend:
other: 没有关闭权限。
cannot_update:
other: 没有更新权限。
content_cannot_empty:
other: 内容不能为空。
rank:
fail_to_meet_the_condition:
other: 声望值未达到要求。
Expand Down Expand Up @@ -1226,6 +1232,9 @@ ui:
modal_content: 该电子邮件地址已经注册。你确定要连接到已有账户吗?
modal_cancel: 更改邮箱
modal_confirm: 连接到已有账户
delete_permanently:
title: 永久删除
content: 你确定要永久删除吗?
password_reset:
page_title: 密码重置
btn_name: 重置我的密码
Expand Down Expand Up @@ -1465,6 +1474,7 @@ ui:
normal: 正常
closed: 已关闭
deleted: 已删除
deleted_permanently: 永久删除
pending: 等待处理
more: 更多
view: 视图
Expand Down Expand Up @@ -2256,5 +2266,6 @@ ui:
user_deleted: 此用户已被删除
badge_activated: 此徽章已被激活。
badge_inactivated: 此徽章已被禁用。


users_deleted: 这些用户已被删除。
posts_deleted: 这些帖子已被删除。
answers_deleted: 这些回答已被删除。
6 changes: 6 additions & 0 deletions internal/base/constant/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ const (
EmailStatusToBeVerified = 2
)

const (
DeletePermanentlyUsers = "users"
DeletePermanentlyQuestions = "questions"
DeletePermanentlyAnswers = "answers"
)

func ConvertUserStatus(status, mailStatus int) string {
switch status {
case 1:
Expand Down
34 changes: 15 additions & 19 deletions internal/base/middleware/accept_language.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,36 +22,32 @@ package middleware
import (
"github.com/apache/incubator-answer/internal/base/constant"
"github.com/apache/incubator-answer/internal/base/handler"
"github.com/apache/incubator-answer/internal/base/translator"
"github.com/gin-gonic/gin"
"github.com/segmentfault/pacman/i18n"
)

var (
langMapping = map[i18n.Language]bool{
i18n.LanguageChinese: true,
i18n.LanguageChineseTraditional: true,
i18n.LanguageEnglish: true,
i18n.LanguageGerman: true,
i18n.LanguageSpanish: true,
i18n.LanguageFrench: true,
i18n.LanguageItalian: true,
i18n.LanguageJapanese: true,
i18n.LanguageKorean: true,
i18n.LanguagePortuguese: true,
i18n.LanguageRussian: true,
i18n.LanguageVietnamese: true,
}
"golang.org/x/text/language"
"strings"
)

// ExtractAndSetAcceptLanguage extract accept language from header and set to context
func ExtractAndSetAcceptLanguage(ctx *gin.Context) {
// The language of our front-end configuration, like en_US
lang := handler.GetLang(ctx)
if langMapping[lang] {
ctx.Set(constant.AcceptLanguageFlag, lang)
tag, _, err := language.ParseAcceptLanguage(string(lang))
if err != nil || len(tag) == 0 {
ctx.Set(constant.AcceptLanguageFlag, i18n.LanguageEnglish)
return
}

acceptLang := strings.ReplaceAll(tag[0].String(), "-", "_")

for _, option := range translator.LanguageOptions {
if option.Value == acceptLang {
ctx.Set(constant.AcceptLanguageFlag, i18n.Language(acceptLang))
return
}
}

// default language
ctx.Set(constant.AcceptLanguageFlag, i18n.LanguageEnglish)
}
3 changes: 3 additions & 0 deletions internal/base/reason/reason.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,15 @@ const (
QuestionCannotUpdate = "error.question.cannot_update"
QuestionAlreadyDeleted = "error.question.already_deleted"
QuestionUnderReview = "error.question.under_review"
QuestionContentCannotEmpty = "error.question.content_cannot_empty"
AnswerNotFound = "error.answer.not_found"
AnswerCannotDeleted = "error.answer.cannot_deleted"
AnswerCannotUpdate = "error.answer.cannot_update"
AnswerCannotAddByClosedQuestion = "error.answer.question_closed_cannot_add"
AnswerRestrictAnswer = "error.answer.restrict_answer"
AnswerContentCannotEmpty = "error.answer.content_cannot_empty"
CommentEditWithoutPermission = "error.comment.edit_without_permission"
CommentContentCannotEmpty = "error.comment.content_cannot_empty"
DisallowVote = "error.object.disallow_vote"
DisallowFollow = "error.object.disallow_follow"
DisallowVoteYourSelf = "error.object.disallow_vote_your_self"
Expand Down
20 changes: 20 additions & 0 deletions internal/controller_admin/user_backyard_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,3 +242,23 @@ func (uc *UserAdminController) SendUserActivation(ctx *gin.Context) {
err := uc.userService.SendUserActivation(ctx, req)
handler.HandleResponse(ctx, err, nil)
}

// DeletePermanently delete permanently
// @Summary delete permanently
// @Description delete permanently
// @Security ApiKeyAuth
// @Tags admin
// @Accept json
// @Produce json
// @Param data body schema.DeletePermanentlyReq true "DeletePermanentlyReq"
// @Success 200 {object} handler.RespBody
// @Router /answer/admin/api/delete/permanently [delete]
func (uc *UserAdminController) DeletePermanently(ctx *gin.Context) {
req := &schema.DeletePermanentlyReq{}
if handler.BindAndCheck(ctx, req) {
return
}

err := uc.userService.DeletePermanently(ctx, req)
handler.HandleResponse(ctx, err, nil)
}
Loading

0 comments on commit be8098a

Please sign in to comment.