diff --git a/cmd/wire_gen.go b/cmd/wire_gen.go index 8435cf310..5b9990213 100644 --- a/cmd/wire_gen.go +++ b/cmd/wire_gen.go @@ -1,8 +1,28 @@ +//go:build !wireinject +// +build !wireinject + +/* + * 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 Wire. DO NOT EDIT. //go:generate go run github.com/google/wire/cmd/wire -//go:build !wireinject -// +build !wireinject package answercmd @@ -152,29 +172,29 @@ func initApplication(debug bool, serverConf *conf.Server, dbConf *data.Database, tagRepo := tag.NewTagRepo(dataData, uniqueIDRepo) revisionRepo := revision.NewRevisionRepo(dataData, uniqueIDRepo) revisionService := revision_common.NewRevisionService(revisionRepo, userRepo) - v := activityqueue.NewService() - tagCommonService := tag_common2.NewTagCommonService(tagCommonRepo, tagRelRepo, tagRepo, revisionService, siteInfoCommonService, v) + service := activityqueue.NewService() + tagCommonService := tag_common2.NewTagCommonService(tagCommonRepo, tagRelRepo, tagRepo, revisionService, siteInfoCommonService, service) collectionRepo := collection.NewCollectionRepo(dataData, uniqueIDRepo) collectionCommon := collectioncommon.NewCollectionCommon(collectionRepo) answerCommon := answercommon.NewAnswerCommon(answerRepo) metaRepo := meta.NewMetaRepo(dataData) metaCommonService := metacommon.NewMetaCommonService(metaRepo) - questionCommon := questioncommon.NewQuestionCommon(questionRepo, answerRepo, voteRepo, followRepo, tagCommonService, userCommon, collectionCommon, answerCommon, metaCommonService, configService, v, revisionRepo, siteInfoCommonService, dataData) - v2 := eventqueue.NewService() + questionCommon := questioncommon.NewQuestionCommon(questionRepo, answerRepo, voteRepo, followRepo, tagCommonService, userCommon, collectionCommon, answerCommon, metaCommonService, configService, service, revisionRepo, siteInfoCommonService, dataData) + eventqueueService := eventqueue.NewService() fileRecordRepo := file_record.NewFileRecordRepo(dataData) fileRecordService := file_record2.NewFileRecordService(fileRecordRepo, revisionRepo, serviceConf, siteInfoCommonService, userCommon) - userService := content.NewUserService(userRepo, userActiveActivityRepo, activityRepo, emailService, authService, siteInfoCommonService, userRoleRelService, userCommon, userExternalLoginService, userNotificationConfigRepo, userNotificationConfigService, questionCommon, v2, fileRecordService) + userService := content.NewUserService(userRepo, userActiveActivityRepo, activityRepo, emailService, authService, siteInfoCommonService, userRoleRelService, userCommon, userExternalLoginService, userNotificationConfigRepo, userNotificationConfigService, questionCommon, eventqueueService, fileRecordService) captchaRepo := captcha.NewCaptchaRepo(dataData) captchaService := action.NewCaptchaService(captchaRepo) userController := controller.NewUserController(authService, userService, captchaService, emailService, siteInfoCommonService, userNotificationConfigService) commentRepo := comment.NewCommentRepo(dataData, uniqueIDRepo) commentCommonRepo := comment.NewCommentCommonRepo(dataData, uniqueIDRepo) objService := object_info.NewObjService(answerRepo, questionRepo, commentCommonRepo, tagCommonRepo, tagCommonService) - v3 := noticequeue.NewService() - v4 := noticequeue.NewExternalService() + noticequeueService := noticequeue.NewService() + externalService := noticequeue.NewExternalService() reviewRepo := review.NewReviewRepo(dataData) - reviewService := review2.NewReviewService(reviewRepo, objService, userCommon, userRepo, questionRepo, answerRepo, userRoleRelService, v4, tagCommonService, questionCommon, v3, siteInfoCommonService, commentCommonRepo) - commentService := comment2.NewCommentService(commentRepo, commentCommonRepo, userCommon, objService, voteRepo, emailService, userRepo, v3, v4, v, v2, reviewService) + reviewService := review2.NewReviewService(reviewRepo, objService, userCommon, userRepo, questionRepo, answerRepo, userRoleRelService, externalService, tagCommonService, questionCommon, noticequeueService, siteInfoCommonService, commentCommonRepo) + commentService := comment2.NewCommentService(commentRepo, commentCommonRepo, userCommon, objService, voteRepo, emailService, userRepo, noticequeueService, externalService, service, eventqueueService, reviewService) rolePowerRelRepo := role.NewRolePowerRelRepo(dataData) rolePowerRelService := role2.NewRolePowerRelService(rolePowerRelRepo, userRoleRelService) rankService := rank2.NewRankService(userCommon, userRankRepo, objService, userRoleRelService, rolePowerRelService, configService) @@ -182,17 +202,17 @@ 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) - tagService := tag2.NewTagService(tagRepo, tagCommonService, revisionService, followRepo, siteInfoCommonService, v) - answerActivityRepo := activity.NewAnswerActivityRepo(dataData, activityRepo, userRankRepo, v3) + tagService := tag2.NewTagService(tagRepo, tagCommonService, revisionService, followRepo, siteInfoCommonService, service) + answerActivityRepo := activity.NewAnswerActivityRepo(dataData, activityRepo, userRankRepo, noticequeueService) answerActivityService := activity2.NewAnswerActivityService(answerActivityRepo, configService) - externalNotificationService := notification.NewExternalNotificationService(dataData, userNotificationConfigRepo, followRepo, emailService, userRepo, v4, userExternalLoginRepo, siteInfoCommonService) - questionService := content.NewQuestionService(activityRepo, questionRepo, answerRepo, tagCommonService, tagService, questionCommon, userCommon, userRepo, userRoleRelService, revisionService, metaCommonService, collectionCommon, answerActivityService, emailService, v3, v4, v, siteInfoCommonService, externalNotificationService, reviewService, configService, v2, reviewRepo) - answerService := content.NewAnswerService(answerRepo, questionRepo, questionCommon, userCommon, collectionCommon, userRepo, revisionService, answerActivityService, answerCommon, voteRepo, emailService, userRoleRelService, v3, v4, v, reviewService, v2) + externalNotificationService := notification.NewExternalNotificationService(dataData, userNotificationConfigRepo, followRepo, emailService, userRepo, externalService, userExternalLoginRepo, siteInfoCommonService) + questionService := content.NewQuestionService(activityRepo, questionRepo, answerRepo, tagCommonService, tagService, questionCommon, userCommon, userRepo, userRoleRelService, revisionService, metaCommonService, collectionCommon, answerActivityService, emailService, noticequeueService, externalService, service, siteInfoCommonService, externalNotificationService, reviewService, configService, eventqueueService, reviewRepo) + answerService := content.NewAnswerService(answerRepo, questionRepo, questionCommon, userCommon, collectionCommon, userRepo, revisionService, answerActivityService, answerCommon, voteRepo, emailService, userRoleRelService, noticequeueService, externalService, service, reviewService, eventqueueService) reportHandle := report_handle.NewReportHandle(questionService, answerService, commentService) - reportService := report2.NewReportService(reportRepo, objService, userCommon, answerRepo, questionRepo, commentCommonRepo, reportHandle, configService, v2) + reportService := report2.NewReportService(reportRepo, objService, userCommon, answerRepo, questionRepo, commentCommonRepo, reportHandle, configService, eventqueueService) reportController := controller.NewReportController(reportService, rankService, captchaService) - contentVoteRepo := activity.NewVoteRepo(dataData, activityRepo, userRankRepo, v3) - voteService := content.NewVoteService(contentVoteRepo, configService, questionRepo, answerRepo, commentCommonRepo, objService, v2) + contentVoteRepo := activity.NewVoteRepo(dataData, activityRepo, userRankRepo, noticequeueService) + voteService := content.NewVoteService(contentVoteRepo, configService, questionRepo, answerRepo, commentCommonRepo, objService, eventqueueService) voteController := controller.NewVoteController(voteService, rankService, captchaService) tagController := controller.NewTagController(tagService, tagCommonService, rankService) followFollowRepo := activity.NewFollowRepo(dataData, uniqueIDRepo, activityRepo) @@ -208,7 +228,7 @@ func initApplication(debug bool, serverConf *conf.Server, dbConf *data.Database, searchService := content.NewSearchService(searchParser, searchRepo) searchController := controller.NewSearchController(searchService, captchaService) reviewActivityRepo := activity.NewReviewActivityRepo(dataData, activityRepo, userRankRepo, configService) - contentRevisionService := content.NewRevisionService(revisionRepo, userCommon, questionCommon, answerService, objService, questionRepo, answerRepo, tagRepo, tagCommonService, v3, v, reportRepo, reviewService, reviewActivityRepo) + contentRevisionService := content.NewRevisionService(revisionRepo, userCommon, questionCommon, answerService, objService, questionRepo, answerRepo, tagRepo, tagCommonService, noticequeueService, service, reportRepo, reviewService, reviewActivityRepo) revisionController := controller.NewRevisionController(contentRevisionService, rankService) rankController := controller.NewRankController(rankService) userAdminRepo := user.NewUserAdminRepo(dataData, authRepo) @@ -224,7 +244,7 @@ func initApplication(debug bool, serverConf *conf.Server, dbConf *data.Database, siteInfoService := siteinfo.NewSiteInfoService(siteInfoRepo, siteInfoCommonService, emailService, tagCommonService, configService, questionCommon, fileRecordService) siteInfoController := controller_admin.NewSiteInfoController(siteInfoService) controllerSiteInfoController := controller.NewSiteInfoController(siteInfoCommonService) - notificationCommon := notificationcommon.NewNotificationCommon(dataData, notificationRepo, userCommon, activityRepo, followRepo, objService, v3, userExternalLoginRepo, siteInfoCommonService) + notificationCommon := notificationcommon.NewNotificationCommon(dataData, notificationRepo, userCommon, activityRepo, followRepo, objService, noticequeueService, userExternalLoginRepo, siteInfoCommonService) badgeRepo := badge.NewBadgeRepo(dataData, uniqueIDRepo) notificationService := notification.NewNotificationService(dataData, notificationRepo, notificationCommon, revisionService, userRepo, reportRepo, reviewService, badgeRepo) notificationController := controller.NewNotificationController(notificationService, rankService) @@ -233,7 +253,7 @@ func initApplication(debug bool, serverConf *conf.Server, dbConf *data.Database, uploaderService := uploader.NewUploaderService(serviceConf, siteInfoCommonService, fileRecordService) uploadController := controller.NewUploadController(uploaderService) activityActivityRepo := activity.NewActivityRepo(dataData, configService) - activityCommon := activity_common2.NewActivityCommon(activityRepo, v) + activityCommon := activity_common2.NewActivityCommon(activityRepo, service) commentCommonService := comment_common.NewCommentCommonService(commentCommonRepo) activityService := activity2.NewActivityService(activityActivityRepo, userCommon, activityCommon, tagCommonService, objService, commentCommonService, revisionService, metaCommonService, configService) activityController := controller.NewActivityController(activityService) @@ -245,12 +265,12 @@ func initApplication(debug bool, serverConf *conf.Server, dbConf *data.Database, permissionController := controller.NewPermissionController(rankService) userPluginController := controller.NewUserPluginController(pluginCommonService) reviewController := controller.NewReviewController(reviewService, rankService, captchaService) - metaService := meta2.NewMetaService(metaCommonService, userCommon, answerRepo, questionRepo, v2) + metaService := meta2.NewMetaService(metaCommonService, userCommon, answerRepo, questionRepo, eventqueueService) metaController := controller.NewMetaController(metaService) badgeGroupRepo := badge_group.NewBadgeGroupRepo(dataData, uniqueIDRepo) eventRuleRepo := badge.NewEventRuleRepo(dataData) - badgeAwardService := badge2.NewBadgeAwardService(badgeAwardRepo, badgeRepo, userCommon, objService, v3) - badgeEventService := badge2.NewBadgeEventService(dataData, v2, badgeRepo, eventRuleRepo, badgeAwardService) + badgeAwardService := badge2.NewBadgeAwardService(badgeAwardRepo, badgeRepo, userCommon, objService, noticequeueService) + badgeEventService := badge2.NewBadgeEventService(dataData, eventqueueService, badgeRepo, eventRuleRepo, badgeAwardService) badgeService := badge2.NewBadgeService(badgeRepo, badgeGroupRepo, badgeAwardRepo, badgeEventService, siteInfoCommonService) badgeController := controller.NewBadgeController(badgeService, badgeAwardService) controller_adminBadgeController := controller_admin.NewBadgeController(badgeService) @@ -261,7 +281,7 @@ func initApplication(debug bool, serverConf *conf.Server, dbConf *data.Database, avatarMiddleware := middleware.NewAvatarMiddleware(serviceConf, uploaderService) shortIDMiddleware := middleware.NewShortIDMiddleware(siteInfoCommonService) templateRenderController := templaterender.NewTemplateRenderController(questionService, userService, tagService, answerService, commentService, siteInfoCommonService, questionRepo) - templateController := controller.NewTemplateController(templateRenderController, siteInfoCommonService, v2, userService, questionService) + templateController := controller.NewTemplateController(templateRenderController, siteInfoCommonService, eventqueueService, userService, questionService) templateRouter := router.NewTemplateRouter(templateController, templateRenderController, siteInfoController, authUserMiddleware) connectorController := controller.NewConnectorController(siteInfoCommonService, emailService, userExternalLoginService) userCenterLoginService := user_external_login2.NewUserCenterLoginService(userRepo, userCommon, userExternalLoginRepo, userActiveActivityRepo, siteInfoCommonService) diff --git a/docs/docs.go b/docs/docs.go index fc4d9909e..cfe48366f 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -1,3 +1,22 @@ +/* + * 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 docs Code generated by swaggo/swag. DO NOT EDIT package docs @@ -856,6 +875,77 @@ const docTemplate = `{ } } }, + "/answer/admin/api/siteinfo/advanced": { + "get": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "get site advanced setting", + "produces": [ + "application/json" + ], + "tags": [ + "admin" + ], + "summary": "get site advanced setting", + "responses": { + "200": { + "description": "OK", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/handler.RespBody" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/schema.SiteAdvancedResp" + } + } + } + ] + } + } + } + }, + "put": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "update site advanced info", + "produces": [ + "application/json" + ], + "tags": [ + "admin" + ], + "summary": "update site advanced info", + "parameters": [ + { + "description": "advanced settings", + "name": "data", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/schema.SiteAdvancedReq" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/handler.RespBody" + } + } + } + } + }, "/answer/admin/api/siteinfo/branding": { "get": { "security": [ @@ -1096,7 +1186,7 @@ const docTemplate = `{ "type": "object", "properties": { "data": { - "$ref": "#/definitions/schema.SiteInterfaceResp" + "$ref": "#/definitions/schema.SiteInterfaceSettingsResp" } } } @@ -1140,21 +1230,21 @@ const docTemplate = `{ } } }, - "/answer/admin/api/siteinfo/legal": { + "/answer/admin/api/siteinfo/login": { "get": { "security": [ { "ApiKeyAuth": [] } ], - "description": "Set the legal information for the site", + "description": "get site info login config", "produces": [ "application/json" ], "tags": [ "admin" ], - "summary": "Set the legal information for the site", + "summary": "get site info login config", "responses": { "200": { "description": "OK", @@ -1167,7 +1257,7 @@ const docTemplate = `{ "type": "object", "properties": { "data": { - "$ref": "#/definitions/schema.SiteLegalResp" + "$ref": "#/definitions/schema.SiteLoginResp" } } } @@ -1182,22 +1272,22 @@ const docTemplate = `{ "ApiKeyAuth": [] } ], - "description": "update site legal info", + "description": "update site login", "produces": [ "application/json" ], "tags": [ "admin" ], - "summary": "update site legal info", + "summary": "update site login", "parameters": [ { - "description": "write info", + "description": "login info", "name": "data", "in": "body", "required": true, "schema": { - "$ref": "#/definitions/schema.SiteLegalReq" + "$ref": "#/definitions/schema.SiteLoginReq" } } ], @@ -1211,21 +1301,21 @@ const docTemplate = `{ } } }, - "/answer/admin/api/siteinfo/login": { + "/answer/admin/api/siteinfo/polices": { "get": { "security": [ { "ApiKeyAuth": [] } ], - "description": "get site info login config", + "description": "Get the policies information for the site", "produces": [ "application/json" ], "tags": [ "admin" ], - "summary": "get site info login config", + "summary": "Get the policies information for the site", "responses": { "200": { "description": "OK", @@ -1238,7 +1328,7 @@ const docTemplate = `{ "type": "object", "properties": { "data": { - "$ref": "#/definitions/schema.SiteLoginResp" + "$ref": "#/definitions/schema.SitePoliciesResp" } } } @@ -1253,22 +1343,22 @@ const docTemplate = `{ "ApiKeyAuth": [] } ], - "description": "update site login", + "description": "update site policies configuration", "produces": [ "application/json" ], "tags": [ "admin" ], - "summary": "update site login", + "summary": "update site policies configuration", "parameters": [ { - "description": "login info", + "description": "write info", "name": "data", "in": "body", "required": true, "schema": { - "$ref": "#/definitions/schema.SiteLoginReq" + "$ref": "#/definitions/schema.SitePoliciesReq" } } ], @@ -1282,21 +1372,21 @@ const docTemplate = `{ } } }, - "/answer/admin/api/siteinfo/seo": { + "/answer/admin/api/siteinfo/question": { "get": { "security": [ { "ApiKeyAuth": [] } ], - "description": "get site seo information", + "description": "get site questions setting", "produces": [ "application/json" ], "tags": [ "admin" ], - "summary": "get site seo information", + "summary": "get site questions setting", "responses": { "200": { "description": "OK", @@ -1309,7 +1399,7 @@ const docTemplate = `{ "type": "object", "properties": { "data": { - "$ref": "#/definitions/schema.SiteSeoResp" + "$ref": "#/definitions/schema.SiteQuestionsResp" } } } @@ -1324,22 +1414,22 @@ const docTemplate = `{ "ApiKeyAuth": [] } ], - "description": "update site seo information", + "description": "update site question settings", "produces": [ "application/json" ], "tags": [ "admin" ], - "summary": "update site seo information", + "summary": "update site question settings", "parameters": [ { - "description": "seo", + "description": "questions settings", "name": "data", "in": "body", "required": true, "schema": { - "$ref": "#/definitions/schema.SiteSeoReq" + "$ref": "#/definitions/schema.SiteQuestionsReq" } } ], @@ -1353,21 +1443,21 @@ const docTemplate = `{ } } }, - "/answer/admin/api/siteinfo/theme": { + "/answer/admin/api/siteinfo/security": { "get": { "security": [ { "ApiKeyAuth": [] } ], - "description": "get site info theme config", + "description": "Get the security information for the site", "produces": [ "application/json" ], "tags": [ "admin" ], - "summary": "get site info theme config", + "summary": "Get the security information for the site", "responses": { "200": { "description": "OK", @@ -1380,7 +1470,7 @@ const docTemplate = `{ "type": "object", "properties": { "data": { - "$ref": "#/definitions/schema.SiteThemeResp" + "$ref": "#/definitions/schema.SiteSecurityResp" } } } @@ -1395,22 +1485,22 @@ const docTemplate = `{ "ApiKeyAuth": [] } ], - "description": "update site custom css html config", + "description": "update site security configuration", "produces": [ "application/json" ], "tags": [ "admin" ], - "summary": "update site custom css html config", + "summary": "update site security configuration", "parameters": [ { - "description": "login info", + "description": "write info", "name": "data", "in": "body", "required": true, "schema": { - "$ref": "#/definitions/schema.SiteThemeReq" + "$ref": "#/definitions/schema.SiteSecurityReq" } } ], @@ -1424,21 +1514,21 @@ const docTemplate = `{ } } }, - "/answer/admin/api/siteinfo/users": { + "/answer/admin/api/siteinfo/seo": { "get": { "security": [ { "ApiKeyAuth": [] } ], - "description": "get site user config", + "description": "get site seo information", "produces": [ "application/json" ], "tags": [ "admin" ], - "summary": "get site user config", + "summary": "get site seo information", "responses": { "200": { "description": "OK", @@ -1451,7 +1541,7 @@ const docTemplate = `{ "type": "object", "properties": { "data": { - "$ref": "#/definitions/schema.SiteUsersResp" + "$ref": "#/definitions/schema.SiteSeoResp" } } } @@ -1466,22 +1556,22 @@ const docTemplate = `{ "ApiKeyAuth": [] } ], - "description": "update site info config about users", + "description": "update site seo information", "produces": [ "application/json" ], "tags": [ "admin" ], - "summary": "update site info config about users", + "summary": "update site seo information", "parameters": [ { - "description": "users info", + "description": "seo", "name": "data", "in": "body", "required": true, "schema": { - "$ref": "#/definitions/schema.SiteUsersReq" + "$ref": "#/definitions/schema.SiteSeoReq" } } ], @@ -1495,21 +1585,21 @@ const docTemplate = `{ } } }, - "/answer/admin/api/siteinfo/write": { + "/answer/admin/api/siteinfo/tag": { "get": { "security": [ { "ApiKeyAuth": [] } ], - "description": "get site interface", + "description": "get site tags setting", "produces": [ "application/json" ], "tags": [ "admin" ], - "summary": "get site interface", + "summary": "get site tags setting", "responses": { "200": { "description": "OK", @@ -1522,7 +1612,7 @@ const docTemplate = `{ "type": "object", "properties": { "data": { - "$ref": "#/definitions/schema.SiteWriteResp" + "$ref": "#/definitions/schema.SiteTagsResp" } } } @@ -1537,22 +1627,22 @@ const docTemplate = `{ "ApiKeyAuth": [] } ], - "description": "update site write info", + "description": "update site tag settings", "produces": [ "application/json" ], "tags": [ "admin" ], - "summary": "update site write info", + "summary": "update site tag settings", "parameters": [ { - "description": "write info", + "description": "tags settings", "name": "data", "in": "body", "required": true, "schema": { - "$ref": "#/definitions/schema.SiteWriteReq" + "$ref": "#/definitions/schema.SiteTagsReq" } } ], @@ -1566,57 +1656,64 @@ const docTemplate = `{ } } }, - "/answer/admin/api/theme/options": { + "/answer/admin/api/siteinfo/theme": { "get": { "security": [ { "ApiKeyAuth": [] } ], - "description": "Get theme options", + "description": "get site info theme config", "produces": [ "application/json" ], "tags": [ "admin" ], - "summary": "Get theme options", + "summary": "get site info theme config", "responses": { "200": { "description": "OK", "schema": { - "$ref": "#/definitions/handler.RespBody" + "allOf": [ + { + "$ref": "#/definitions/handler.RespBody" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/schema.SiteThemeResp" + } + } + } + ] } } } - } - }, - "/answer/admin/api/user": { - "post": { + }, + "put": { "security": [ { "ApiKeyAuth": [] } ], - "description": "add user", - "consumes": [ - "application/json" - ], + "description": "update site custom css html config", "produces": [ "application/json" ], "tags": [ "admin" ], - "summary": "add user", + "summary": "update site custom css html config", "parameters": [ { - "description": "user", + "description": "login info", "name": "data", "in": "body", "required": true, "schema": { - "$ref": "#/definitions/schema.AddUserReq" + "$ref": "#/definitions/schema.SiteThemeReq" } } ], @@ -1630,30 +1727,21 @@ const docTemplate = `{ } } }, - "/answer/admin/api/user/activation": { + "/answer/admin/api/siteinfo/users": { "get": { "security": [ { "ApiKeyAuth": [] } ], - "description": "get user activation", + "description": "get site user config", "produces": [ "application/json" ], "tags": [ "admin" ], - "summary": "get user activation", - "parameters": [ - { - "type": "string", - "description": "user id", - "name": "user_id", - "in": "query", - "required": true - } - ], + "summary": "get site user config", "responses": { "200": { "description": "OK", @@ -1666,7 +1754,7 @@ const docTemplate = `{ "type": "object", "properties": { "data": { - "$ref": "#/definitions/schema.GetUserActivationResp" + "$ref": "#/definitions/schema.SiteUsersResp" } } } @@ -1674,34 +1762,29 @@ const docTemplate = `{ } } } - } - }, - "/answer/admin/api/user/password": { + }, "put": { "security": [ { "ApiKeyAuth": [] } ], - "description": "update user password", - "consumes": [ - "application/json" - ], + "description": "update site info config about users", "produces": [ "application/json" ], "tags": [ "admin" ], - "summary": "update user password", + "summary": "update site info config about users", "parameters": [ { - "description": "user", + "description": "users info", "name": "data", "in": "body", "required": true, "schema": { - "$ref": "#/definitions/schema.UpdateUserPasswordReq" + "$ref": "#/definitions/schema.SiteUsersReq" } } ], @@ -1715,71 +1798,64 @@ const docTemplate = `{ } } }, - "/answer/admin/api/user/profile": { - "put": { + "/answer/admin/api/siteinfo/users-settings": { + "get": { "security": [ { "ApiKeyAuth": [] } ], - "description": "edit user profile", - "consumes": [ - "application/json" - ], + "description": "get site interface", "produces": [ "application/json" ], "tags": [ "admin" ], - "summary": "edit user profile", - "parameters": [ - { - "description": "user", - "name": "data", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/schema.EditUserProfileReq" - } - } - ], + "summary": "get site interface", "responses": { "200": { "description": "OK", "schema": { - "$ref": "#/definitions/handler.RespBody" + "allOf": [ + { + "$ref": "#/definitions/handler.RespBody" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/schema.SiteUsersSettingsResp" + } + } + } + ] } } } - } - }, - "/answer/admin/api/user/role": { + }, "put": { "security": [ { "ApiKeyAuth": [] } ], - "description": "update user role", - "consumes": [ - "application/json" - ], + "description": "update site info users settings", "produces": [ "application/json" ], "tags": [ "admin" ], - "summary": "update user role", + "summary": "update site info users settings", "parameters": [ { - "description": "user", + "description": "general", "name": "data", "in": "body", "required": true, "schema": { - "$ref": "#/definitions/schema.UpdateUserRoleReq" + "$ref": "#/definitions/schema.SiteUsersSettingsReq" } } ], @@ -1793,35 +1869,21 @@ const docTemplate = `{ } } }, - "/answer/admin/api/user/status": { - "put": { + "/answer/admin/api/theme/options": { + "get": { "security": [ { "ApiKeyAuth": [] } ], - "description": "update user", - "consumes": [ - "application/json" - ], + "description": "Get theme options", "produces": [ "application/json" ], "tags": [ "admin" ], - "summary": "update user", - "parameters": [ - { - "description": "user", - "name": "data", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/schema.UpdateUserStatusReq" - } - } - ], + "summary": "Get theme options", "responses": { "200": { "description": "OK", @@ -1832,7 +1894,248 @@ const docTemplate = `{ } } }, - "/answer/admin/api/users": { + "/answer/admin/api/user": { + "post": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "add user", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "admin" + ], + "summary": "add user", + "parameters": [ + { + "description": "user", + "name": "data", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/schema.AddUserReq" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/handler.RespBody" + } + } + } + } + }, + "/answer/admin/api/user/activation": { + "get": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "get user activation", + "produces": [ + "application/json" + ], + "tags": [ + "admin" + ], + "summary": "get user activation", + "parameters": [ + { + "type": "string", + "description": "user id", + "name": "user_id", + "in": "query", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/handler.RespBody" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/schema.GetUserActivationResp" + } + } + } + ] + } + } + } + } + }, + "/answer/admin/api/user/password": { + "put": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "update user password", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "admin" + ], + "summary": "update user password", + "parameters": [ + { + "description": "user", + "name": "data", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/schema.UpdateUserPasswordReq" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/handler.RespBody" + } + } + } + } + }, + "/answer/admin/api/user/profile": { + "put": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "edit user profile", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "admin" + ], + "summary": "edit user profile", + "parameters": [ + { + "description": "user", + "name": "data", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/schema.EditUserProfileReq" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/handler.RespBody" + } + } + } + } + }, + "/answer/admin/api/user/role": { + "put": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "update user role", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "admin" + ], + "summary": "update user role", + "parameters": [ + { + "description": "user", + "name": "data", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/schema.UpdateUserRoleReq" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/handler.RespBody" + } + } + } + } + }, + "/answer/admin/api/user/status": { + "put": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "update user", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "admin" + ], + "summary": "update user", + "parameters": [ + { + "description": "user", + "name": "data", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/schema.UpdateUserStatusReq" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/handler.RespBody" + } + } + } + } + }, + "/answer/admin/api/users": { "post": { "security": [ { @@ -10478,18 +10781,70 @@ const docTemplate = `{ } } }, - "schema.SiteBrandingReq": { + "schema.SiteAdvancedReq": { "type": "object", "properties": { - "favicon": { - "type": "string", - "maxLength": 512 - }, - "logo": { - "type": "string", - "maxLength": 512 + "authorized_attachment_extensions": { + "type": "array", + "items": { + "type": "string" + } }, - "mobile_logo": { + "authorized_image_extensions": { + "type": "array", + "items": { + "type": "string" + } + }, + "max_attachment_size": { + "type": "integer" + }, + "max_image_megapixel": { + "type": "integer" + }, + "max_image_size": { + "type": "integer" + } + } + }, + "schema.SiteAdvancedResp": { + "type": "object", + "properties": { + "authorized_attachment_extensions": { + "type": "array", + "items": { + "type": "string" + } + }, + "authorized_image_extensions": { + "type": "array", + "items": { + "type": "string" + } + }, + "max_attachment_size": { + "type": "integer" + }, + "max_image_megapixel": { + "type": "integer" + }, + "max_image_size": { + "type": "integer" + } + } + }, + "schema.SiteBrandingReq": { + "type": "object", + "properties": { + "favicon": { + "type": "string", + "maxLength": 512 + }, + "logo": { + "type": "string", + "maxLength": 512 + }, + "mobile_logo": { "type": "string", "maxLength": 512 }, @@ -10578,9 +10933,6 @@ const docTemplate = `{ "site_url" ], "properties": { - "check_update": { - "type": "boolean" - }, "contact_email": { "type": "string", "maxLength": 512 @@ -10611,9 +10963,6 @@ const docTemplate = `{ "site_url" ], "properties": { - "check_update": { - "type": "boolean" - }, "contact_email": { "type": "string", "maxLength": 512 @@ -10649,7 +10998,7 @@ const docTemplate = `{ "$ref": "#/definitions/schema.SiteGeneralResp" }, "interface": { - "$ref": "#/definitions/schema.SiteInterfaceResp" + "$ref": "#/definitions/schema.SiteInterfaceSettingsResp" }, "login": { "$ref": "#/definitions/schema.SiteLoginResp" @@ -10657,21 +11006,33 @@ const docTemplate = `{ "revision": { "type": "string" }, + "site_advanced": { + "$ref": "#/definitions/schema.SiteAdvancedResp" + }, "site_legal": { "$ref": "#/definitions/schema.SiteLegalSimpleResp" }, + "site_questions": { + "$ref": "#/definitions/schema.SiteQuestionsResp" + }, + "site_security": { + "$ref": "#/definitions/schema.SiteSecurityResp" + }, "site_seo": { "$ref": "#/definitions/schema.SiteSeoResp" }, + "site_tags": { + "$ref": "#/definitions/schema.SiteTagsResp" + }, "site_users": { "$ref": "#/definitions/schema.SiteUsersResp" }, - "site_write": { - "$ref": "#/definitions/schema.SiteWriteResp" - }, "theme": { "$ref": "#/definitions/schema.SiteThemeResp" }, + "users_settings": { + "$ref": "#/definitions/schema.SiteUsersSettingsResp" + }, "version": { "type": "string" } @@ -10680,21 +11041,10 @@ const docTemplate = `{ "schema.SiteInterfaceReq": { "type": "object", "required": [ - "default_avatar", "language", "time_zone" ], "properties": { - "default_avatar": { - "type": "string", - "enum": [ - "system", - "gravatar" - ] - }, - "gravatar_base_url": { - "type": "string" - }, "language": { "type": "string", "maxLength": 128 @@ -10705,24 +11055,13 @@ const docTemplate = `{ } } }, - "schema.SiteInterfaceResp": { + "schema.SiteInterfaceSettingsResp": { "type": "object", "required": [ - "default_avatar", "language", "time_zone" ], "properties": { - "default_avatar": { - "type": "string", - "enum": [ - "system", - "gravatar" - ] - }, - "gravatar_base_url": { - "type": "string" - }, "language": { "type": "string", "maxLength": 128 @@ -10733,7 +11072,7 @@ const docTemplate = `{ } } }, - "schema.SiteLegalReq": { + "schema.SiteLegalSimpleResp": { "type": "object", "required": [ "external_content_display" @@ -10745,7 +11084,52 @@ const docTemplate = `{ "always_display", "ask_before_display" ] + } + } + }, + "schema.SiteLoginReq": { + "type": "object", + "properties": { + "allow_email_domains": { + "type": "array", + "items": { + "type": "string" + } + }, + "allow_email_registrations": { + "type": "boolean" + }, + "allow_new_registrations": { + "type": "boolean" + }, + "allow_password_login": { + "type": "boolean" + } + } + }, + "schema.SiteLoginResp": { + "type": "object", + "properties": { + "allow_email_domains": { + "type": "array", + "items": { + "type": "string" + } }, + "allow_email_registrations": { + "type": "boolean" + }, + "allow_new_registrations": { + "type": "boolean" + }, + "allow_password_login": { + "type": "boolean" + } + } + }, + "schema.SitePoliciesReq": { + "type": "object", + "properties": { "privacy_policy_original_text": { "type": "string" }, @@ -10760,19 +11144,9 @@ const docTemplate = `{ } } }, - "schema.SiteLegalResp": { + "schema.SitePoliciesResp": { "type": "object", - "required": [ - "external_content_display" - ], "properties": { - "external_content_display": { - "type": "string", - "enum": [ - "always_display", - "ask_before_display" - ] - }, "privacy_policy_original_text": { "type": "string" }, @@ -10787,61 +11161,78 @@ const docTemplate = `{ } } }, - "schema.SiteLegalSimpleResp": { + "schema.SiteQuestionsReq": { "type": "object", - "required": [ - "external_content_display" - ], "properties": { - "external_content_display": { - "type": "string", - "enum": [ - "always_display", - "ask_before_display" - ] + "min_content": { + "type": "integer", + "maximum": 65535, + "minimum": 0 + }, + "min_tags": { + "type": "integer", + "maximum": 5, + "minimum": 0 + }, + "restrict_answer": { + "type": "boolean" } } }, - "schema.SiteLoginReq": { + "schema.SiteQuestionsResp": { "type": "object", "properties": { - "allow_email_domains": { - "type": "array", - "items": { - "type": "string" - } + "min_content": { + "type": "integer", + "maximum": 65535, + "minimum": 0 }, - "allow_email_registrations": { - "type": "boolean" + "min_tags": { + "type": "integer", + "maximum": 5, + "minimum": 0 }, - "allow_new_registrations": { + "restrict_answer": { "type": "boolean" - }, - "allow_password_login": { + } + } + }, + "schema.SiteSecurityReq": { + "type": "object", + "required": [ + "external_content_display" + ], + "properties": { + "check_update": { "type": "boolean" }, + "external_content_display": { + "type": "string", + "enum": [ + "always_display", + "ask_before_display" + ] + }, "login_required": { "type": "boolean" } } }, - "schema.SiteLoginResp": { + "schema.SiteSecurityResp": { "type": "object", + "required": [ + "external_content_display" + ], "properties": { - "allow_email_domains": { - "type": "array", - "items": { - "type": "string" - } - }, - "allow_email_registrations": { - "type": "boolean" - }, - "allow_new_registrations": { + "check_update": { "type": "boolean" }, - "allow_password_login": { - "type": "boolean" + "external_content_display": { + "type": "string", + "enum": [ + "always_display", + "ask_before_display" + ] }, "login_required": { "type": "boolean" @@ -10882,6 +11273,46 @@ const docTemplate = `{ } } }, + "schema.SiteTagsReq": { + "type": "object", + "properties": { + "recommend_tags": { + "type": "array", + "items": { + "$ref": "#/definitions/schema.SiteWriteTag" + } + }, + "required_tag": { + "type": "boolean" + }, + "reserved_tags": { + "type": "array", + "items": { + "$ref": "#/definitions/schema.SiteWriteTag" + } + } + } + }, + "schema.SiteTagsResp": { + "type": "object", + "properties": { + "recommend_tags": { + "type": "array", + "items": { + "$ref": "#/definitions/schema.SiteWriteTag" + } + }, + "required_tag": { + "type": "boolean" + }, + "reserved_tags": { + "type": "array", + "items": { + "$ref": "#/definitions/schema.SiteWriteTag" + } + } + } + }, "schema.SiteThemeReq": { "type": "object", "required": [ @@ -10995,111 +11426,39 @@ const docTemplate = `{ } } }, - "schema.SiteWriteReq": { + "schema.SiteUsersSettingsReq": { "type": "object", + "required": [ + "default_avatar" + ], "properties": { - "authorized_attachment_extensions": { - "type": "array", - "items": { - "type": "string" - } - }, - "authorized_image_extensions": { - "type": "array", - "items": { - "type": "string" - } - }, - "max_attachment_size": { - "type": "integer" - }, - "max_image_megapixel": { - "type": "integer" - }, - "max_image_size": { - "type": "integer" - }, - "min_content": { - "type": "integer", - "maximum": 65535, - "minimum": 0 - }, - "min_tags": { - "type": "integer", - "maximum": 5, - "minimum": 0 - }, - "recommend_tags": { - "type": "array", - "items": { - "$ref": "#/definitions/schema.SiteWriteTag" - } - }, - "required_tag": { - "type": "boolean" - }, - "reserved_tags": { - "type": "array", - "items": { - "$ref": "#/definitions/schema.SiteWriteTag" - } + "default_avatar": { + "type": "string", + "enum": [ + "system", + "gravatar" + ] }, - "restrict_answer": { - "type": "boolean" + "gravatar_base_url": { + "type": "string" } } }, - "schema.SiteWriteResp": { + "schema.SiteUsersSettingsResp": { "type": "object", + "required": [ + "default_avatar" + ], "properties": { - "authorized_attachment_extensions": { - "type": "array", - "items": { - "type": "string" - } - }, - "authorized_image_extensions": { - "type": "array", - "items": { - "type": "string" - } - }, - "max_attachment_size": { - "type": "integer" - }, - "max_image_megapixel": { - "type": "integer" - }, - "max_image_size": { - "type": "integer" - }, - "min_content": { - "type": "integer", - "maximum": 65535, - "minimum": 0 - }, - "min_tags": { - "type": "integer", - "maximum": 5, - "minimum": 0 - }, - "recommend_tags": { - "type": "array", - "items": { - "$ref": "#/definitions/schema.SiteWriteTag" - } - }, - "required_tag": { - "type": "boolean" - }, - "reserved_tags": { - "type": "array", - "items": { - "$ref": "#/definitions/schema.SiteWriteTag" - } + "default_avatar": { + "type": "string", + "enum": [ + "system", + "gravatar" + ] }, - "restrict_answer": { - "type": "boolean" + "gravatar_base_url": { + "type": "string" } } }, diff --git a/docs/swagger.json b/docs/swagger.json index e0f6378e4..c181109d2 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -848,6 +848,77 @@ } } }, + "/answer/admin/api/siteinfo/advanced": { + "get": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "get site advanced setting", + "produces": [ + "application/json" + ], + "tags": [ + "admin" + ], + "summary": "get site advanced setting", + "responses": { + "200": { + "description": "OK", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/handler.RespBody" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/schema.SiteAdvancedResp" + } + } + } + ] + } + } + } + }, + "put": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "update site advanced info", + "produces": [ + "application/json" + ], + "tags": [ + "admin" + ], + "summary": "update site advanced info", + "parameters": [ + { + "description": "advanced settings", + "name": "data", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/schema.SiteAdvancedReq" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/handler.RespBody" + } + } + } + } + }, "/answer/admin/api/siteinfo/branding": { "get": { "security": [ @@ -1088,7 +1159,7 @@ "type": "object", "properties": { "data": { - "$ref": "#/definitions/schema.SiteInterfaceResp" + "$ref": "#/definitions/schema.SiteInterfaceSettingsResp" } } } @@ -1132,21 +1203,21 @@ } } }, - "/answer/admin/api/siteinfo/legal": { + "/answer/admin/api/siteinfo/login": { "get": { "security": [ { "ApiKeyAuth": [] } ], - "description": "Set the legal information for the site", + "description": "get site info login config", "produces": [ "application/json" ], "tags": [ "admin" ], - "summary": "Set the legal information for the site", + "summary": "get site info login config", "responses": { "200": { "description": "OK", @@ -1159,7 +1230,7 @@ "type": "object", "properties": { "data": { - "$ref": "#/definitions/schema.SiteLegalResp" + "$ref": "#/definitions/schema.SiteLoginResp" } } } @@ -1174,22 +1245,22 @@ "ApiKeyAuth": [] } ], - "description": "update site legal info", + "description": "update site login", "produces": [ "application/json" ], "tags": [ "admin" ], - "summary": "update site legal info", + "summary": "update site login", "parameters": [ { - "description": "write info", + "description": "login info", "name": "data", "in": "body", "required": true, "schema": { - "$ref": "#/definitions/schema.SiteLegalReq" + "$ref": "#/definitions/schema.SiteLoginReq" } } ], @@ -1203,21 +1274,21 @@ } } }, - "/answer/admin/api/siteinfo/login": { + "/answer/admin/api/siteinfo/polices": { "get": { "security": [ { "ApiKeyAuth": [] } ], - "description": "get site info login config", + "description": "Get the policies information for the site", "produces": [ "application/json" ], "tags": [ "admin" ], - "summary": "get site info login config", + "summary": "Get the policies information for the site", "responses": { "200": { "description": "OK", @@ -1230,7 +1301,7 @@ "type": "object", "properties": { "data": { - "$ref": "#/definitions/schema.SiteLoginResp" + "$ref": "#/definitions/schema.SitePoliciesResp" } } } @@ -1245,22 +1316,22 @@ "ApiKeyAuth": [] } ], - "description": "update site login", + "description": "update site policies configuration", "produces": [ "application/json" ], "tags": [ "admin" ], - "summary": "update site login", + "summary": "update site policies configuration", "parameters": [ { - "description": "login info", + "description": "write info", "name": "data", "in": "body", "required": true, "schema": { - "$ref": "#/definitions/schema.SiteLoginReq" + "$ref": "#/definitions/schema.SitePoliciesReq" } } ], @@ -1274,21 +1345,21 @@ } } }, - "/answer/admin/api/siteinfo/seo": { + "/answer/admin/api/siteinfo/question": { "get": { "security": [ { "ApiKeyAuth": [] } ], - "description": "get site seo information", + "description": "get site questions setting", "produces": [ "application/json" ], "tags": [ "admin" ], - "summary": "get site seo information", + "summary": "get site questions setting", "responses": { "200": { "description": "OK", @@ -1301,7 +1372,7 @@ "type": "object", "properties": { "data": { - "$ref": "#/definitions/schema.SiteSeoResp" + "$ref": "#/definitions/schema.SiteQuestionsResp" } } } @@ -1316,22 +1387,22 @@ "ApiKeyAuth": [] } ], - "description": "update site seo information", + "description": "update site question settings", "produces": [ "application/json" ], "tags": [ "admin" ], - "summary": "update site seo information", + "summary": "update site question settings", "parameters": [ { - "description": "seo", + "description": "questions settings", "name": "data", "in": "body", "required": true, "schema": { - "$ref": "#/definitions/schema.SiteSeoReq" + "$ref": "#/definitions/schema.SiteQuestionsReq" } } ], @@ -1345,21 +1416,21 @@ } } }, - "/answer/admin/api/siteinfo/theme": { + "/answer/admin/api/siteinfo/security": { "get": { "security": [ { "ApiKeyAuth": [] } ], - "description": "get site info theme config", + "description": "Get the security information for the site", "produces": [ "application/json" ], "tags": [ "admin" ], - "summary": "get site info theme config", + "summary": "Get the security information for the site", "responses": { "200": { "description": "OK", @@ -1372,7 +1443,7 @@ "type": "object", "properties": { "data": { - "$ref": "#/definitions/schema.SiteThemeResp" + "$ref": "#/definitions/schema.SiteSecurityResp" } } } @@ -1387,22 +1458,22 @@ "ApiKeyAuth": [] } ], - "description": "update site custom css html config", + "description": "update site security configuration", "produces": [ "application/json" ], "tags": [ "admin" ], - "summary": "update site custom css html config", + "summary": "update site security configuration", "parameters": [ { - "description": "login info", + "description": "write info", "name": "data", "in": "body", "required": true, "schema": { - "$ref": "#/definitions/schema.SiteThemeReq" + "$ref": "#/definitions/schema.SiteSecurityReq" } } ], @@ -1416,21 +1487,21 @@ } } }, - "/answer/admin/api/siteinfo/users": { + "/answer/admin/api/siteinfo/seo": { "get": { "security": [ { "ApiKeyAuth": [] } ], - "description": "get site user config", + "description": "get site seo information", "produces": [ "application/json" ], "tags": [ "admin" ], - "summary": "get site user config", + "summary": "get site seo information", "responses": { "200": { "description": "OK", @@ -1443,7 +1514,7 @@ "type": "object", "properties": { "data": { - "$ref": "#/definitions/schema.SiteUsersResp" + "$ref": "#/definitions/schema.SiteSeoResp" } } } @@ -1458,22 +1529,22 @@ "ApiKeyAuth": [] } ], - "description": "update site info config about users", + "description": "update site seo information", "produces": [ "application/json" ], "tags": [ "admin" ], - "summary": "update site info config about users", + "summary": "update site seo information", "parameters": [ { - "description": "users info", + "description": "seo", "name": "data", "in": "body", "required": true, "schema": { - "$ref": "#/definitions/schema.SiteUsersReq" + "$ref": "#/definitions/schema.SiteSeoReq" } } ], @@ -1487,21 +1558,21 @@ } } }, - "/answer/admin/api/siteinfo/write": { + "/answer/admin/api/siteinfo/tag": { "get": { "security": [ { "ApiKeyAuth": [] } ], - "description": "get site interface", + "description": "get site tags setting", "produces": [ "application/json" ], "tags": [ "admin" ], - "summary": "get site interface", + "summary": "get site tags setting", "responses": { "200": { "description": "OK", @@ -1514,7 +1585,7 @@ "type": "object", "properties": { "data": { - "$ref": "#/definitions/schema.SiteWriteResp" + "$ref": "#/definitions/schema.SiteTagsResp" } } } @@ -1529,22 +1600,22 @@ "ApiKeyAuth": [] } ], - "description": "update site write info", + "description": "update site tag settings", "produces": [ "application/json" ], "tags": [ "admin" ], - "summary": "update site write info", + "summary": "update site tag settings", "parameters": [ { - "description": "write info", + "description": "tags settings", "name": "data", "in": "body", "required": true, "schema": { - "$ref": "#/definitions/schema.SiteWriteReq" + "$ref": "#/definitions/schema.SiteTagsReq" } } ], @@ -1558,57 +1629,64 @@ } } }, - "/answer/admin/api/theme/options": { + "/answer/admin/api/siteinfo/theme": { "get": { "security": [ { "ApiKeyAuth": [] } ], - "description": "Get theme options", + "description": "get site info theme config", "produces": [ "application/json" ], "tags": [ "admin" ], - "summary": "Get theme options", + "summary": "get site info theme config", "responses": { "200": { "description": "OK", "schema": { - "$ref": "#/definitions/handler.RespBody" + "allOf": [ + { + "$ref": "#/definitions/handler.RespBody" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/schema.SiteThemeResp" + } + } + } + ] } } } - } - }, - "/answer/admin/api/user": { - "post": { + }, + "put": { "security": [ { "ApiKeyAuth": [] } ], - "description": "add user", - "consumes": [ - "application/json" - ], + "description": "update site custom css html config", "produces": [ "application/json" ], "tags": [ "admin" ], - "summary": "add user", + "summary": "update site custom css html config", "parameters": [ { - "description": "user", + "description": "login info", "name": "data", "in": "body", "required": true, "schema": { - "$ref": "#/definitions/schema.AddUserReq" + "$ref": "#/definitions/schema.SiteThemeReq" } } ], @@ -1622,30 +1700,21 @@ } } }, - "/answer/admin/api/user/activation": { + "/answer/admin/api/siteinfo/users": { "get": { "security": [ { "ApiKeyAuth": [] } ], - "description": "get user activation", + "description": "get site user config", "produces": [ "application/json" ], "tags": [ "admin" ], - "summary": "get user activation", - "parameters": [ - { - "type": "string", - "description": "user id", - "name": "user_id", - "in": "query", - "required": true - } - ], + "summary": "get site user config", "responses": { "200": { "description": "OK", @@ -1658,7 +1727,7 @@ "type": "object", "properties": { "data": { - "$ref": "#/definitions/schema.GetUserActivationResp" + "$ref": "#/definitions/schema.SiteUsersResp" } } } @@ -1666,34 +1735,29 @@ } } } - } - }, - "/answer/admin/api/user/password": { + }, "put": { "security": [ { "ApiKeyAuth": [] } ], - "description": "update user password", - "consumes": [ - "application/json" - ], + "description": "update site info config about users", "produces": [ "application/json" ], "tags": [ "admin" ], - "summary": "update user password", + "summary": "update site info config about users", "parameters": [ { - "description": "user", + "description": "users info", "name": "data", "in": "body", "required": true, "schema": { - "$ref": "#/definitions/schema.UpdateUserPasswordReq" + "$ref": "#/definitions/schema.SiteUsersReq" } } ], @@ -1707,71 +1771,64 @@ } } }, - "/answer/admin/api/user/profile": { - "put": { + "/answer/admin/api/siteinfo/users-settings": { + "get": { "security": [ { "ApiKeyAuth": [] } ], - "description": "edit user profile", - "consumes": [ - "application/json" - ], + "description": "get site interface", "produces": [ "application/json" ], "tags": [ "admin" ], - "summary": "edit user profile", - "parameters": [ - { - "description": "user", - "name": "data", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/schema.EditUserProfileReq" - } - } - ], + "summary": "get site interface", "responses": { "200": { "description": "OK", "schema": { - "$ref": "#/definitions/handler.RespBody" + "allOf": [ + { + "$ref": "#/definitions/handler.RespBody" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/schema.SiteUsersSettingsResp" + } + } + } + ] } } } - } - }, - "/answer/admin/api/user/role": { + }, "put": { "security": [ { "ApiKeyAuth": [] } ], - "description": "update user role", - "consumes": [ - "application/json" - ], + "description": "update site info users settings", "produces": [ "application/json" ], "tags": [ "admin" ], - "summary": "update user role", + "summary": "update site info users settings", "parameters": [ { - "description": "user", + "description": "general", "name": "data", "in": "body", "required": true, "schema": { - "$ref": "#/definitions/schema.UpdateUserRoleReq" + "$ref": "#/definitions/schema.SiteUsersSettingsReq" } } ], @@ -1785,35 +1842,21 @@ } } }, - "/answer/admin/api/user/status": { - "put": { + "/answer/admin/api/theme/options": { + "get": { "security": [ { "ApiKeyAuth": [] } ], - "description": "update user", - "consumes": [ - "application/json" - ], + "description": "Get theme options", "produces": [ "application/json" ], "tags": [ "admin" ], - "summary": "update user", - "parameters": [ - { - "description": "user", - "name": "data", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/schema.UpdateUserStatusReq" - } - } - ], + "summary": "Get theme options", "responses": { "200": { "description": "OK", @@ -1824,7 +1867,248 @@ } } }, - "/answer/admin/api/users": { + "/answer/admin/api/user": { + "post": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "add user", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "admin" + ], + "summary": "add user", + "parameters": [ + { + "description": "user", + "name": "data", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/schema.AddUserReq" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/handler.RespBody" + } + } + } + } + }, + "/answer/admin/api/user/activation": { + "get": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "get user activation", + "produces": [ + "application/json" + ], + "tags": [ + "admin" + ], + "summary": "get user activation", + "parameters": [ + { + "type": "string", + "description": "user id", + "name": "user_id", + "in": "query", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/handler.RespBody" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/schema.GetUserActivationResp" + } + } + } + ] + } + } + } + } + }, + "/answer/admin/api/user/password": { + "put": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "update user password", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "admin" + ], + "summary": "update user password", + "parameters": [ + { + "description": "user", + "name": "data", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/schema.UpdateUserPasswordReq" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/handler.RespBody" + } + } + } + } + }, + "/answer/admin/api/user/profile": { + "put": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "edit user profile", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "admin" + ], + "summary": "edit user profile", + "parameters": [ + { + "description": "user", + "name": "data", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/schema.EditUserProfileReq" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/handler.RespBody" + } + } + } + } + }, + "/answer/admin/api/user/role": { + "put": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "update user role", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "admin" + ], + "summary": "update user role", + "parameters": [ + { + "description": "user", + "name": "data", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/schema.UpdateUserRoleReq" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/handler.RespBody" + } + } + } + } + }, + "/answer/admin/api/user/status": { + "put": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "update user", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "admin" + ], + "summary": "update user", + "parameters": [ + { + "description": "user", + "name": "data", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/schema.UpdateUserStatusReq" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/handler.RespBody" + } + } + } + } + }, + "/answer/admin/api/users": { "post": { "security": [ { @@ -10470,19 +10754,71 @@ } } }, - "schema.SiteBrandingReq": { + "schema.SiteAdvancedReq": { "type": "object", "properties": { - "favicon": { - "type": "string", - "maxLength": 512 - }, - "logo": { - "type": "string", - "maxLength": 512 + "authorized_attachment_extensions": { + "type": "array", + "items": { + "type": "string" + } }, - "mobile_logo": { - "type": "string", + "authorized_image_extensions": { + "type": "array", + "items": { + "type": "string" + } + }, + "max_attachment_size": { + "type": "integer" + }, + "max_image_megapixel": { + "type": "integer" + }, + "max_image_size": { + "type": "integer" + } + } + }, + "schema.SiteAdvancedResp": { + "type": "object", + "properties": { + "authorized_attachment_extensions": { + "type": "array", + "items": { + "type": "string" + } + }, + "authorized_image_extensions": { + "type": "array", + "items": { + "type": "string" + } + }, + "max_attachment_size": { + "type": "integer" + }, + "max_image_megapixel": { + "type": "integer" + }, + "max_image_size": { + "type": "integer" + } + } + }, + "schema.SiteBrandingReq": { + "type": "object", + "properties": { + "favicon": { + "type": "string", + "maxLength": 512 + }, + "logo": { + "type": "string", + "maxLength": 512 + }, + "mobile_logo": { + "type": "string", "maxLength": 512 }, "square_icon": { @@ -10570,9 +10906,6 @@ "site_url" ], "properties": { - "check_update": { - "type": "boolean" - }, "contact_email": { "type": "string", "maxLength": 512 @@ -10603,9 +10936,6 @@ "site_url" ], "properties": { - "check_update": { - "type": "boolean" - }, "contact_email": { "type": "string", "maxLength": 512 @@ -10641,7 +10971,7 @@ "$ref": "#/definitions/schema.SiteGeneralResp" }, "interface": { - "$ref": "#/definitions/schema.SiteInterfaceResp" + "$ref": "#/definitions/schema.SiteInterfaceSettingsResp" }, "login": { "$ref": "#/definitions/schema.SiteLoginResp" @@ -10649,21 +10979,33 @@ "revision": { "type": "string" }, + "site_advanced": { + "$ref": "#/definitions/schema.SiteAdvancedResp" + }, "site_legal": { "$ref": "#/definitions/schema.SiteLegalSimpleResp" }, + "site_questions": { + "$ref": "#/definitions/schema.SiteQuestionsResp" + }, + "site_security": { + "$ref": "#/definitions/schema.SiteSecurityResp" + }, "site_seo": { "$ref": "#/definitions/schema.SiteSeoResp" }, + "site_tags": { + "$ref": "#/definitions/schema.SiteTagsResp" + }, "site_users": { "$ref": "#/definitions/schema.SiteUsersResp" }, - "site_write": { - "$ref": "#/definitions/schema.SiteWriteResp" - }, "theme": { "$ref": "#/definitions/schema.SiteThemeResp" }, + "users_settings": { + "$ref": "#/definitions/schema.SiteUsersSettingsResp" + }, "version": { "type": "string" } @@ -10672,21 +11014,10 @@ "schema.SiteInterfaceReq": { "type": "object", "required": [ - "default_avatar", "language", "time_zone" ], "properties": { - "default_avatar": { - "type": "string", - "enum": [ - "system", - "gravatar" - ] - }, - "gravatar_base_url": { - "type": "string" - }, "language": { "type": "string", "maxLength": 128 @@ -10697,24 +11028,13 @@ } } }, - "schema.SiteInterfaceResp": { + "schema.SiteInterfaceSettingsResp": { "type": "object", "required": [ - "default_avatar", "language", "time_zone" ], "properties": { - "default_avatar": { - "type": "string", - "enum": [ - "system", - "gravatar" - ] - }, - "gravatar_base_url": { - "type": "string" - }, "language": { "type": "string", "maxLength": 128 @@ -10725,7 +11045,7 @@ } } }, - "schema.SiteLegalReq": { + "schema.SiteLegalSimpleResp": { "type": "object", "required": [ "external_content_display" @@ -10737,7 +11057,52 @@ "always_display", "ask_before_display" ] + } + } + }, + "schema.SiteLoginReq": { + "type": "object", + "properties": { + "allow_email_domains": { + "type": "array", + "items": { + "type": "string" + } + }, + "allow_email_registrations": { + "type": "boolean" + }, + "allow_new_registrations": { + "type": "boolean" + }, + "allow_password_login": { + "type": "boolean" + } + } + }, + "schema.SiteLoginResp": { + "type": "object", + "properties": { + "allow_email_domains": { + "type": "array", + "items": { + "type": "string" + } }, + "allow_email_registrations": { + "type": "boolean" + }, + "allow_new_registrations": { + "type": "boolean" + }, + "allow_password_login": { + "type": "boolean" + } + } + }, + "schema.SitePoliciesReq": { + "type": "object", + "properties": { "privacy_policy_original_text": { "type": "string" }, @@ -10752,19 +11117,9 @@ } } }, - "schema.SiteLegalResp": { + "schema.SitePoliciesResp": { "type": "object", - "required": [ - "external_content_display" - ], "properties": { - "external_content_display": { - "type": "string", - "enum": [ - "always_display", - "ask_before_display" - ] - }, "privacy_policy_original_text": { "type": "string" }, @@ -10779,61 +11134,78 @@ } } }, - "schema.SiteLegalSimpleResp": { + "schema.SiteQuestionsReq": { "type": "object", - "required": [ - "external_content_display" - ], "properties": { - "external_content_display": { - "type": "string", - "enum": [ - "always_display", - "ask_before_display" - ] + "min_content": { + "type": "integer", + "maximum": 65535, + "minimum": 0 + }, + "min_tags": { + "type": "integer", + "maximum": 5, + "minimum": 0 + }, + "restrict_answer": { + "type": "boolean" } } }, - "schema.SiteLoginReq": { + "schema.SiteQuestionsResp": { "type": "object", "properties": { - "allow_email_domains": { - "type": "array", - "items": { - "type": "string" - } + "min_content": { + "type": "integer", + "maximum": 65535, + "minimum": 0 }, - "allow_email_registrations": { - "type": "boolean" + "min_tags": { + "type": "integer", + "maximum": 5, + "minimum": 0 }, - "allow_new_registrations": { + "restrict_answer": { "type": "boolean" - }, - "allow_password_login": { + } + } + }, + "schema.SiteSecurityReq": { + "type": "object", + "required": [ + "external_content_display" + ], + "properties": { + "check_update": { "type": "boolean" }, + "external_content_display": { + "type": "string", + "enum": [ + "always_display", + "ask_before_display" + ] + }, "login_required": { "type": "boolean" } } }, - "schema.SiteLoginResp": { + "schema.SiteSecurityResp": { "type": "object", + "required": [ + "external_content_display" + ], "properties": { - "allow_email_domains": { - "type": "array", - "items": { - "type": "string" - } - }, - "allow_email_registrations": { - "type": "boolean" - }, - "allow_new_registrations": { + "check_update": { "type": "boolean" }, - "allow_password_login": { - "type": "boolean" + "external_content_display": { + "type": "string", + "enum": [ + "always_display", + "ask_before_display" + ] }, "login_required": { "type": "boolean" @@ -10874,6 +11246,46 @@ } } }, + "schema.SiteTagsReq": { + "type": "object", + "properties": { + "recommend_tags": { + "type": "array", + "items": { + "$ref": "#/definitions/schema.SiteWriteTag" + } + }, + "required_tag": { + "type": "boolean" + }, + "reserved_tags": { + "type": "array", + "items": { + "$ref": "#/definitions/schema.SiteWriteTag" + } + } + } + }, + "schema.SiteTagsResp": { + "type": "object", + "properties": { + "recommend_tags": { + "type": "array", + "items": { + "$ref": "#/definitions/schema.SiteWriteTag" + } + }, + "required_tag": { + "type": "boolean" + }, + "reserved_tags": { + "type": "array", + "items": { + "$ref": "#/definitions/schema.SiteWriteTag" + } + } + } + }, "schema.SiteThemeReq": { "type": "object", "required": [ @@ -10987,111 +11399,39 @@ } } }, - "schema.SiteWriteReq": { + "schema.SiteUsersSettingsReq": { "type": "object", + "required": [ + "default_avatar" + ], "properties": { - "authorized_attachment_extensions": { - "type": "array", - "items": { - "type": "string" - } - }, - "authorized_image_extensions": { - "type": "array", - "items": { - "type": "string" - } - }, - "max_attachment_size": { - "type": "integer" - }, - "max_image_megapixel": { - "type": "integer" - }, - "max_image_size": { - "type": "integer" - }, - "min_content": { - "type": "integer", - "maximum": 65535, - "minimum": 0 - }, - "min_tags": { - "type": "integer", - "maximum": 5, - "minimum": 0 - }, - "recommend_tags": { - "type": "array", - "items": { - "$ref": "#/definitions/schema.SiteWriteTag" - } - }, - "required_tag": { - "type": "boolean" - }, - "reserved_tags": { - "type": "array", - "items": { - "$ref": "#/definitions/schema.SiteWriteTag" - } + "default_avatar": { + "type": "string", + "enum": [ + "system", + "gravatar" + ] }, - "restrict_answer": { - "type": "boolean" + "gravatar_base_url": { + "type": "string" } } }, - "schema.SiteWriteResp": { + "schema.SiteUsersSettingsResp": { "type": "object", + "required": [ + "default_avatar" + ], "properties": { - "authorized_attachment_extensions": { - "type": "array", - "items": { - "type": "string" - } - }, - "authorized_image_extensions": { - "type": "array", - "items": { - "type": "string" - } - }, - "max_attachment_size": { - "type": "integer" - }, - "max_image_megapixel": { - "type": "integer" - }, - "max_image_size": { - "type": "integer" - }, - "min_content": { - "type": "integer", - "maximum": 65535, - "minimum": 0 - }, - "min_tags": { - "type": "integer", - "maximum": 5, - "minimum": 0 - }, - "recommend_tags": { - "type": "array", - "items": { - "$ref": "#/definitions/schema.SiteWriteTag" - } - }, - "required_tag": { - "type": "boolean" - }, - "reserved_tags": { - "type": "array", - "items": { - "$ref": "#/definitions/schema.SiteWriteTag" - } + "default_avatar": { + "type": "string", + "enum": [ + "system", + "gravatar" + ] }, - "restrict_answer": { - "type": "boolean" + "gravatar_base_url": { + "type": "string" } } }, diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 42df5cbf1..13e9575eb 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -1,3 +1,20 @@ +# 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. + basePath: / definitions: constant.NotificationChannelKey: @@ -2055,6 +2072,40 @@ definitions: required: - user_id type: object + schema.SiteAdvancedReq: + properties: + authorized_attachment_extensions: + items: + type: string + type: array + authorized_image_extensions: + items: + type: string + type: array + max_attachment_size: + type: integer + max_image_megapixel: + type: integer + max_image_size: + type: integer + type: object + schema.SiteAdvancedResp: + properties: + authorized_attachment_extensions: + items: + type: string + type: array + authorized_image_extensions: + items: + type: string + type: array + max_attachment_size: + type: integer + max_image_megapixel: + type: integer + max_image_size: + type: integer + type: object schema.SiteBrandingReq: properties: favicon: @@ -2123,8 +2174,6 @@ definitions: type: object schema.SiteGeneralReq: properties: - check_update: - type: boolean contact_email: maxLength: 512 type: string @@ -2147,8 +2196,6 @@ definitions: type: object schema.SiteGeneralResp: properties: - check_update: - type: boolean contact_email: maxLength: 512 type: string @@ -2178,33 +2225,34 @@ definitions: general: $ref: '#/definitions/schema.SiteGeneralResp' interface: - $ref: '#/definitions/schema.SiteInterfaceResp' + $ref: '#/definitions/schema.SiteInterfaceSettingsResp' login: $ref: '#/definitions/schema.SiteLoginResp' revision: type: string + site_advanced: + $ref: '#/definitions/schema.SiteAdvancedResp' site_legal: $ref: '#/definitions/schema.SiteLegalSimpleResp' + site_questions: + $ref: '#/definitions/schema.SiteQuestionsResp' + site_security: + $ref: '#/definitions/schema.SiteSecurityResp' site_seo: $ref: '#/definitions/schema.SiteSeoResp' + site_tags: + $ref: '#/definitions/schema.SiteTagsResp' site_users: $ref: '#/definitions/schema.SiteUsersResp' - site_write: - $ref: '#/definitions/schema.SiteWriteResp' theme: $ref: '#/definitions/schema.SiteThemeResp' + users_settings: + $ref: '#/definitions/schema.SiteUsersSettingsResp' version: type: string type: object schema.SiteInterfaceReq: properties: - default_avatar: - enum: - - system - - gravatar - type: string - gravatar_base_url: - type: string language: maxLength: 128 type: string @@ -2212,19 +2260,11 @@ definitions: maxLength: 128 type: string required: - - default_avatar - language - time_zone type: object - schema.SiteInterfaceResp: + schema.SiteInterfaceSettingsResp: properties: - default_avatar: - enum: - - system - - gravatar - type: string - gravatar_base_url: - type: string language: maxLength: 128 type: string @@ -2232,17 +2272,47 @@ definitions: maxLength: 128 type: string required: - - default_avatar - language - time_zone type: object - schema.SiteLegalReq: + schema.SiteLegalSimpleResp: properties: external_content_display: enum: - always_display - ask_before_display type: string + required: + - external_content_display + type: object + schema.SiteLoginReq: + properties: + allow_email_domains: + items: + type: string + type: array + allow_email_registrations: + type: boolean + allow_new_registrations: + type: boolean + allow_password_login: + type: boolean + type: object + schema.SiteLoginResp: + properties: + allow_email_domains: + items: + type: string + type: array + allow_email_registrations: + type: boolean + allow_new_registrations: + type: boolean + allow_password_login: + type: boolean + type: object + schema.SitePoliciesReq: + properties: privacy_policy_original_text: type: string privacy_policy_parsed_text: @@ -2251,16 +2321,9 @@ definitions: type: string terms_of_service_parsed_text: type: string - required: - - external_content_display type: object - schema.SiteLegalResp: + schema.SitePoliciesResp: properties: - external_content_display: - enum: - - always_display - - ask_before_display - type: string privacy_policy_original_text: type: string privacy_policy_parsed_text: @@ -2269,48 +2332,60 @@ definitions: type: string terms_of_service_parsed_text: type: string - required: - - external_content_display type: object - schema.SiteLegalSimpleResp: + schema.SiteQuestionsReq: + properties: + min_content: + maximum: 65535 + minimum: 0 + type: integer + min_tags: + maximum: 5 + minimum: 0 + type: integer + restrict_answer: + type: boolean + type: object + schema.SiteQuestionsResp: + properties: + min_content: + maximum: 65535 + minimum: 0 + type: integer + min_tags: + maximum: 5 + minimum: 0 + type: integer + restrict_answer: + type: boolean + type: object + schema.SiteSecurityReq: properties: + check_update: + type: boolean external_content_display: enum: - always_display - ask_before_display type: string - required: - - external_content_display - type: object - schema.SiteLoginReq: - properties: - allow_email_domains: - items: - type: string - type: array - allow_email_registrations: - type: boolean - allow_new_registrations: - type: boolean - allow_password_login: - type: boolean login_required: type: boolean + required: + - external_content_display type: object - schema.SiteLoginResp: + schema.SiteSecurityResp: properties: - allow_email_domains: - items: - type: string - type: array - allow_email_registrations: - type: boolean - allow_new_registrations: - type: boolean - allow_password_login: + check_update: type: boolean + external_content_display: + enum: + - always_display + - ask_before_display + type: string login_required: type: boolean + required: + - external_content_display type: object schema.SiteSeoReq: properties: @@ -2336,6 +2411,32 @@ definitions: - permalink - robots type: object + schema.SiteTagsReq: + properties: + recommend_tags: + items: + $ref: '#/definitions/schema.SiteWriteTag' + type: array + required_tag: + type: boolean + reserved_tags: + items: + $ref: '#/definitions/schema.SiteWriteTag' + type: array + type: object + schema.SiteTagsResp: + properties: + recommend_tags: + items: + $ref: '#/definitions/schema.SiteWriteTag' + type: array + required_tag: + type: boolean + reserved_tags: + items: + $ref: '#/definitions/schema.SiteWriteTag' + type: array + type: object schema.SiteThemeReq: properties: color_scheme: @@ -2412,79 +2513,29 @@ definitions: required: - default_avatar type: object - schema.SiteWriteReq: + schema.SiteUsersSettingsReq: properties: - authorized_attachment_extensions: - items: - type: string - type: array - authorized_image_extensions: - items: - type: string - type: array - max_attachment_size: - type: integer - max_image_megapixel: - type: integer - max_image_size: - type: integer - min_content: - maximum: 65535 - minimum: 0 - type: integer - min_tags: - maximum: 5 - minimum: 0 - type: integer - recommend_tags: - items: - $ref: '#/definitions/schema.SiteWriteTag' - type: array - required_tag: - type: boolean - reserved_tags: - items: - $ref: '#/definitions/schema.SiteWriteTag' - type: array - restrict_answer: - type: boolean + default_avatar: + enum: + - system + - gravatar + type: string + gravatar_base_url: + type: string + required: + - default_avatar type: object - schema.SiteWriteResp: + schema.SiteUsersSettingsResp: properties: - authorized_attachment_extensions: - items: - type: string - type: array - authorized_image_extensions: - items: - type: string - type: array - max_attachment_size: - type: integer - max_image_megapixel: - type: integer - max_image_size: - type: integer - min_content: - maximum: 65535 - minimum: 0 - type: integer - min_tags: - maximum: 5 - minimum: 0 - type: integer - recommend_tags: - items: - $ref: '#/definitions/schema.SiteWriteTag' - type: array - required_tag: - type: boolean - reserved_tags: - items: - $ref: '#/definitions/schema.SiteWriteTag' - type: array - restrict_answer: - type: boolean + default_avatar: + enum: + - system + - gravatar + type: string + gravatar_base_url: + type: string + required: + - default_avatar type: object schema.SiteWriteTag: properties: @@ -3685,6 +3736,47 @@ paths: summary: update smtp config tags: - admin + /answer/admin/api/siteinfo/advanced: + get: + description: get site advanced setting + produces: + - application/json + responses: + "200": + description: OK + schema: + allOf: + - $ref: '#/definitions/handler.RespBody' + - properties: + data: + $ref: '#/definitions/schema.SiteAdvancedResp' + type: object + security: + - ApiKeyAuth: [] + summary: get site advanced setting + tags: + - admin + put: + description: update site advanced info + parameters: + - description: advanced settings + in: body + name: data + required: true + schema: + $ref: '#/definitions/schema.SiteAdvancedReq' + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/handler.RespBody' + security: + - ApiKeyAuth: [] + summary: update site advanced info + tags: + - admin /answer/admin/api/siteinfo/branding: get: description: get site interface @@ -3821,7 +3913,7 @@ paths: - $ref: '#/definitions/handler.RespBody' - properties: data: - $ref: '#/definitions/schema.SiteInterfaceResp' + $ref: '#/definitions/schema.SiteInterfaceSettingsResp' type: object security: - ApiKeyAuth: [] @@ -3849,9 +3941,9 @@ paths: summary: update site info interface tags: - admin - /answer/admin/api/siteinfo/legal: + /answer/admin/api/siteinfo/login: get: - description: Set the legal information for the site + description: get site info login config produces: - application/json responses: @@ -3862,22 +3954,63 @@ paths: - $ref: '#/definitions/handler.RespBody' - properties: data: - $ref: '#/definitions/schema.SiteLegalResp' + $ref: '#/definitions/schema.SiteLoginResp' type: object security: - ApiKeyAuth: [] - summary: Set the legal information for the site + summary: get site info login config tags: - admin put: - description: update site legal info + description: update site login + parameters: + - description: login info + in: body + name: data + required: true + schema: + $ref: '#/definitions/schema.SiteLoginReq' + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/handler.RespBody' + security: + - ApiKeyAuth: [] + summary: update site login + tags: + - admin + /answer/admin/api/siteinfo/polices: + get: + description: Get the policies information for the site + produces: + - application/json + responses: + "200": + description: OK + schema: + allOf: + - $ref: '#/definitions/handler.RespBody' + - properties: + data: + $ref: '#/definitions/schema.SitePoliciesResp' + type: object + security: + - ApiKeyAuth: [] + summary: Get the policies information for the site + tags: + - admin + put: + description: update site policies configuration parameters: - description: write info in: body name: data required: true schema: - $ref: '#/definitions/schema.SiteLegalReq' + $ref: '#/definitions/schema.SitePoliciesReq' produces: - application/json responses: @@ -3887,12 +4020,12 @@ paths: $ref: '#/definitions/handler.RespBody' security: - ApiKeyAuth: [] - summary: update site legal info + summary: update site policies configuration tags: - admin - /answer/admin/api/siteinfo/login: + /answer/admin/api/siteinfo/question: get: - description: get site info login config + description: get site questions setting produces: - application/json responses: @@ -3903,22 +4036,22 @@ paths: - $ref: '#/definitions/handler.RespBody' - properties: data: - $ref: '#/definitions/schema.SiteLoginResp' + $ref: '#/definitions/schema.SiteQuestionsResp' type: object security: - ApiKeyAuth: [] - summary: get site info login config + summary: get site questions setting tags: - admin put: - description: update site login + description: update site question settings parameters: - - description: login info + - description: questions settings in: body name: data required: true schema: - $ref: '#/definitions/schema.SiteLoginReq' + $ref: '#/definitions/schema.SiteQuestionsReq' produces: - application/json responses: @@ -3928,7 +4061,48 @@ paths: $ref: '#/definitions/handler.RespBody' security: - ApiKeyAuth: [] - summary: update site login + summary: update site question settings + tags: + - admin + /answer/admin/api/siteinfo/security: + get: + description: Get the security information for the site + produces: + - application/json + responses: + "200": + description: OK + schema: + allOf: + - $ref: '#/definitions/handler.RespBody' + - properties: + data: + $ref: '#/definitions/schema.SiteSecurityResp' + type: object + security: + - ApiKeyAuth: [] + summary: Get the security information for the site + tags: + - admin + put: + description: update site security configuration + parameters: + - description: write info + in: body + name: data + required: true + schema: + $ref: '#/definitions/schema.SiteSecurityReq' + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/handler.RespBody' + security: + - ApiKeyAuth: [] + summary: update site security configuration tags: - admin /answer/admin/api/siteinfo/seo: @@ -3972,6 +4146,47 @@ paths: summary: update site seo information tags: - admin + /answer/admin/api/siteinfo/tag: + get: + description: get site tags setting + produces: + - application/json + responses: + "200": + description: OK + schema: + allOf: + - $ref: '#/definitions/handler.RespBody' + - properties: + data: + $ref: '#/definitions/schema.SiteTagsResp' + type: object + security: + - ApiKeyAuth: [] + summary: get site tags setting + tags: + - admin + put: + description: update site tag settings + parameters: + - description: tags settings + in: body + name: data + required: true + schema: + $ref: '#/definitions/schema.SiteTagsReq' + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/handler.RespBody' + security: + - ApiKeyAuth: [] + summary: update site tag settings + tags: + - admin /answer/admin/api/siteinfo/theme: get: description: get site info theme config @@ -4054,7 +4269,7 @@ paths: summary: update site info config about users tags: - admin - /answer/admin/api/siteinfo/write: + /answer/admin/api/siteinfo/users-settings: get: description: get site interface produces: @@ -4067,7 +4282,7 @@ paths: - $ref: '#/definitions/handler.RespBody' - properties: data: - $ref: '#/definitions/schema.SiteWriteResp' + $ref: '#/definitions/schema.SiteUsersSettingsResp' type: object security: - ApiKeyAuth: [] @@ -4075,14 +4290,14 @@ paths: tags: - admin put: - description: update site write info + description: update site info users settings parameters: - - description: write info + - description: general in: body name: data required: true schema: - $ref: '#/definitions/schema.SiteWriteReq' + $ref: '#/definitions/schema.SiteUsersSettingsReq' produces: - application/json responses: @@ -4092,7 +4307,7 @@ paths: $ref: '#/definitions/handler.RespBody' security: - ApiKeyAuth: [] - summary: update site write info + summary: update site info users settings tags: - admin /answer/admin/api/theme/options: diff --git a/go.mod b/go.mod index 52d64c738..d24302954 100644 --- a/go.mod +++ b/go.mod @@ -37,6 +37,7 @@ require ( github.com/grokify/html-strip-tags-go v0.1.0 github.com/jinzhu/copier v0.4.0 github.com/jinzhu/now v1.1.5 + github.com/joho/godotenv v1.5.1 github.com/lib/pq v1.10.9 github.com/microcosm-cc/bluemonday v1.0.27 github.com/mozillazg/go-pinyin v0.20.0 @@ -117,7 +118,6 @@ require ( github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect github.com/hashicorp/hcl v1.0.0 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect - github.com/joho/godotenv v1.5.1 // indirect github.com/josharian/intern v1.0.0 // indirect github.com/json-iterator/go v1.1.12 // indirect github.com/klauspost/cpuid/v2 v2.2.8 // indirect diff --git a/internal/base/constant/site_type.go b/internal/base/constant/site_type.go index 65b487c5d..44cd0abd7 100644 --- a/internal/base/constant/site_type.go +++ b/internal/base/constant/site_type.go @@ -20,10 +20,13 @@ package constant const ( - SiteTypeGeneral = "general" - SiteTypeInterface = "interface" - SiteTypeBranding = "branding" - SiteTypeWrite = "write" + SiteTypeGeneral = "general" + // Deprecated: split SiteTypeInterfaceSettings and SiteTypeUsersSettings for better clarity + SiteTypeInterface = "interface" + SiteTypeBranding = "branding" + // Deprecated: use SiteTypeAdvanced, SiteTypeQuestions, and SiteTypeTags instead + SiteTypeWrite = "write" + // Deprecated: use SiteTypePolicies and SiteTypeSecurity instead SiteTypeLegal = "legal" SiteTypeSeo = "seo" SiteTypeLogin = "login" @@ -31,4 +34,14 @@ const ( SiteTypeTheme = "theme" SiteTypePrivileges = "privileges" SiteTypeUsers = "users" + + SiteTypeAdvanced = "advanced" + SiteTypeQuestions = "questions" + SiteTypeTags = "tags" + + SiteTypeUsersSettings = "users_settings" + SiteTypeInterfaceSettings = "interface_settings" + + SiteTypePolicies = "policies" + SiteTypeSecurity = "security" ) diff --git a/internal/base/middleware/auth.go b/internal/base/middleware/auth.go index f21837b60..57bbaae21 100644 --- a/internal/base/middleware/auth.go +++ b/internal/base/middleware/auth.go @@ -80,7 +80,7 @@ func (am *AuthUserMiddleware) Auth() gin.HandlerFunc { func (am *AuthUserMiddleware) EjectUserBySiteInfo() gin.HandlerFunc { return func(ctx *gin.Context) { mustLogin := false - siteInfo, _ := am.siteInfoCommonService.GetSiteLogin(ctx) + siteInfo, _ := am.siteInfoCommonService.GetSiteSecurity(ctx) if siteInfo != nil { mustLogin = siteInfo.LoginRequired } @@ -197,7 +197,7 @@ func (am *AuthUserMiddleware) AdminAuth() gin.HandlerFunc { func (am *AuthUserMiddleware) CheckPrivateMode() gin.HandlerFunc { return func(ctx *gin.Context) { - resp, err := am.siteInfoCommonService.GetSiteLogin(ctx) + resp, err := am.siteInfoCommonService.GetSiteSecurity(ctx) if err != nil { ShowIndexPage(ctx) ctx.Abort() diff --git a/internal/base/middleware/visit_img_auth.go b/internal/base/middleware/visit_img_auth.go index 33b62172f..bfd157a92 100644 --- a/internal/base/middleware/visit_img_auth.go +++ b/internal/base/middleware/visit_img_auth.go @@ -41,11 +41,11 @@ func (am *AuthUserMiddleware) VisitAuth() gin.HandlerFunc { return } - siteLogin, err := am.siteInfoCommonService.GetSiteLogin(ctx) + siteSecurity, err := am.siteInfoCommonService.GetSiteSecurity(ctx) if err != nil { return } - if !siteLogin.LoginRequired { + if !siteSecurity.LoginRequired { ctx.Next() return } diff --git a/internal/controller/answer_controller.go b/internal/controller/answer_controller.go index e76b02ccc..99c89b778 100644 --- a/internal/controller/answer_controller.go +++ b/internal/controller/answer_controller.go @@ -242,7 +242,7 @@ func (ac *AnswerController) AddAnswer(ctx *gin.Context) { return } - write, err := ac.siteInfoCommonService.GetSiteWrite(ctx) + write, err := ac.siteInfoCommonService.GetSiteQuestion(ctx) if err != nil { handler.HandleResponse(ctx, err, nil) return diff --git a/internal/controller/siteinfo_controller.go b/internal/controller/siteinfo_controller.go index a336fb242..320c1b475 100644 --- a/internal/controller/siteinfo_controller.go +++ b/internal/controller/siteinfo_controller.go @@ -60,6 +60,11 @@ func (sc *SiteInfoController) GetSiteInfo(ctx *gin.Context) { log.Error(err) } + resp.UsersSettings, err = sc.siteInfoService.GetSiteUsersSettings(ctx) + if err != nil { + log.Error(err) + } + resp.Branding, err = sc.siteInfoService.GetSiteBranding(ctx) if err != nil { log.Error(err) @@ -87,13 +92,24 @@ func (sc *SiteInfoController) GetSiteInfo(ctx *gin.Context) { if err != nil { log.Error(err) } - resp.Write, err = sc.siteInfoService.GetSiteWrite(ctx) + resp.Questions, err = sc.siteInfoService.GetSiteQuestion(ctx) if err != nil { log.Error(err) } - if legal, err := sc.siteInfoService.GetSiteLegal(ctx); err == nil { + resp.Tags, err = sc.siteInfoService.GetSiteTag(ctx) + if err != nil { + log.Error(err) + } + resp.Advanced, err = sc.siteInfoService.GetSiteAdvanced(ctx) + if err != nil { + log.Error(err) + } + if legal, err := sc.siteInfoService.GetSiteSecurity(ctx); err == nil { resp.Legal = &schema.SiteLegalSimpleResp{ExternalContentDisplay: legal.ExternalContentDisplay} } + if security, err := sc.siteInfoService.GetSiteSecurity(ctx); err == nil { + resp.Security = security + } handler.HandleResponse(ctx, nil, resp) } @@ -111,7 +127,7 @@ func (sc *SiteInfoController) GetSiteLegalInfo(ctx *gin.Context) { if handler.BindAndCheck(ctx, req) { return } - siteLegal, err := sc.siteInfoService.GetSiteLegal(ctx) + siteLegal, err := sc.siteInfoService.GetSitePolicies(ctx) if err != nil { handler.HandleResponse(ctx, err, nil) return diff --git a/internal/controller/template_controller.go b/internal/controller/template_controller.go index e6b94f4f2..31cc5152a 100644 --- a/internal/controller/template_controller.go +++ b/internal/controller/template_controller.go @@ -656,7 +656,7 @@ func (tc *TemplateController) SitemapPage(ctx *gin.Context) { } func (tc *TemplateController) checkPrivateMode(ctx *gin.Context) bool { - resp, err := tc.siteInfoService.GetSiteLogin(ctx) + resp, err := tc.siteInfoService.GetSiteSecurity(ctx) if err != nil { log.Error(err) return false diff --git a/internal/controller_admin/siteinfo_controller.go b/internal/controller_admin/siteinfo_controller.go index 8a92daba3..339d2caa2 100644 --- a/internal/controller_admin/siteinfo_controller.go +++ b/internal/controller_admin/siteinfo_controller.go @@ -62,13 +62,26 @@ func (sc *SiteInfoController) GetGeneral(ctx *gin.Context) { // @Security ApiKeyAuth // @Tags admin // @Produce json -// @Success 200 {object} handler.RespBody{data=schema.SiteInterfaceResp} +// @Success 200 {object} handler.RespBody{data=schema.SiteInterfaceSettingsResp} // @Router /answer/admin/api/siteinfo/interface [get] func (sc *SiteInfoController) GetInterface(ctx *gin.Context) { resp, err := sc.siteInfoService.GetSiteInterface(ctx) handler.HandleResponse(ctx, err, resp) } +// GetUsersSettings get site interface +// @Summary get site interface +// @Description get site interface +// @Security ApiKeyAuth +// @Tags admin +// @Produce json +// @Success 200 {object} handler.RespBody{data=schema.SiteUsersSettingsResp} +// @Router /answer/admin/api/siteinfo/users-settings [get] +func (sc *SiteInfoController) GetUsersSettings(ctx *gin.Context) { + resp, err := sc.siteInfoService.GetSiteUsersSettings(ctx) + handler.HandleResponse(ctx, err, resp) +} + // GetSiteBranding get site interface // @Summary get site interface // @Description get site interface @@ -82,29 +95,68 @@ func (sc *SiteInfoController) GetSiteBranding(ctx *gin.Context) { handler.HandleResponse(ctx, err, resp) } -// GetSiteWrite get site interface -// @Summary get site interface -// @Description get site interface +// GetSiteTag get site tags setting +// @Summary get site tags setting +// @Description get site tags setting // @Security ApiKeyAuth // @Tags admin // @Produce json -// @Success 200 {object} handler.RespBody{data=schema.SiteWriteResp} -// @Router /answer/admin/api/siteinfo/write [get] -func (sc *SiteInfoController) GetSiteWrite(ctx *gin.Context) { - resp, err := sc.siteInfoService.GetSiteWrite(ctx) +// @Success 200 {object} handler.RespBody{data=schema.SiteTagsResp} +// @Router /answer/admin/api/siteinfo/tag [get] +func (sc *SiteInfoController) GetSiteTag(ctx *gin.Context) { + resp, err := sc.siteInfoService.GetSiteTag(ctx) handler.HandleResponse(ctx, err, resp) } -// GetSiteLegal Set the legal information for the site -// @Summary Set the legal information for the site -// @Description Set the legal information for the site +// GetSiteQuestion get site questions setting +// @Summary get site questions setting +// @Description get site questions setting // @Security ApiKeyAuth // @Tags admin // @Produce json -// @Success 200 {object} handler.RespBody{data=schema.SiteLegalResp} -// @Router /answer/admin/api/siteinfo/legal [get] -func (sc *SiteInfoController) GetSiteLegal(ctx *gin.Context) { - resp, err := sc.siteInfoService.GetSiteLegal(ctx) +// @Success 200 {object} handler.RespBody{data=schema.SiteQuestionsResp} +// @Router /answer/admin/api/siteinfo/question [get] +func (sc *SiteInfoController) GetSiteQuestion(ctx *gin.Context) { + resp, err := sc.siteInfoService.GetSiteQuestion(ctx) + handler.HandleResponse(ctx, err, resp) +} + +// GetSiteAdvanced get site advanced setting +// @Summary get site advanced setting +// @Description get site advanced setting +// @Security ApiKeyAuth +// @Tags admin +// @Produce json +// @Success 200 {object} handler.RespBody{data=schema.SiteAdvancedResp} +// @Router /answer/admin/api/siteinfo/advanced [get] +func (sc *SiteInfoController) GetSiteAdvanced(ctx *gin.Context) { + resp, err := sc.siteInfoService.GetSiteAdvanced(ctx) + handler.HandleResponse(ctx, err, resp) +} + +// GetSitePolicies Get the policies information for the site +// @Summary Get the policies information for the site +// @Description Get the policies information for the site +// @Security ApiKeyAuth +// @Tags admin +// @Produce json +// @Success 200 {object} handler.RespBody{data=schema.SitePoliciesResp} +// @Router /answer/admin/api/siteinfo/polices [get] +func (sc *SiteInfoController) GetSitePolicies(ctx *gin.Context) { + resp, err := sc.siteInfoService.GetSitePolicies(ctx) + handler.HandleResponse(ctx, err, resp) +} + +// GetSiteSecurity Get the security information for the site +// @Summary Get the security information for the site +// @Description Get the security information for the site +// @Security ApiKeyAuth +// @Tags admin +// @Produce json +// @Success 200 {object} handler.RespBody{data=schema.SiteSecurityResp} +// @Router /answer/admin/api/siteinfo/security [get] +func (sc *SiteInfoController) GetSiteSecurity(ctx *gin.Context) { + resp, err := sc.siteInfoService.GetSiteSecurity(ctx) handler.HandleResponse(ctx, err, resp) } @@ -261,6 +313,24 @@ func (sc *SiteInfoController) UpdateInterface(ctx *gin.Context) { handler.HandleResponse(ctx, err, nil) } +// UpdateUsersSettings update users settings +// @Summary update site info users settings +// @Description update site info users settings +// @Security ApiKeyAuth +// @Tags admin +// @Produce json +// @Param data body schema.SiteUsersSettingsReq true "general" +// @Success 200 {object} handler.RespBody{} +// @Router /answer/admin/api/siteinfo/users-settings [put] +func (sc *SiteInfoController) UpdateUsersSettings(ctx *gin.Context) { + req := schema.SiteUsersSettingsReq{} + if handler.BindAndCheck(ctx, &req) { + return + } + err := sc.siteInfoService.SaveSiteUsersSettings(ctx, req) + handler.HandleResponse(ctx, err, nil) +} + // UpdateBranding update site branding // @Summary update site info branding // @Description update site info branding @@ -288,41 +358,97 @@ func (sc *SiteInfoController) UpdateBranding(ctx *gin.Context) { handler.HandleResponse(ctx, saveErr, nil) } -// UpdateSiteWrite update site write info -// @Summary update site write info -// @Description update site write info +// UpdateSiteQuestion update site question settings +// @Summary update site question settings +// @Description update site question settings +// @Security ApiKeyAuth +// @Tags admin +// @Produce json +// @Param data body schema.SiteQuestionsReq true "questions settings" +// @Success 200 {object} handler.RespBody{} +// @Router /answer/admin/api/siteinfo/question [put] +func (sc *SiteInfoController) UpdateSiteQuestion(ctx *gin.Context) { + req := &schema.SiteQuestionsReq{} + if handler.BindAndCheck(ctx, req) { + return + } + + resp, err := sc.siteInfoService.SaveSiteQuestions(ctx, req) + handler.HandleResponse(ctx, err, resp) +} + +// UpdateSiteTag update site tag settings +// @Summary update site tag settings +// @Description update site tag settings // @Security ApiKeyAuth // @Tags admin // @Produce json -// @Param data body schema.SiteWriteReq true "write info" +// @Param data body schema.SiteTagsReq true "tags settings" // @Success 200 {object} handler.RespBody{} -// @Router /answer/admin/api/siteinfo/write [put] -func (sc *SiteInfoController) UpdateSiteWrite(ctx *gin.Context) { - req := &schema.SiteWriteReq{} +// @Router /answer/admin/api/siteinfo/tag [put] +func (sc *SiteInfoController) UpdateSiteTag(ctx *gin.Context) { + req := &schema.SiteTagsReq{} if handler.BindAndCheck(ctx, req) { return } req.UserID = middleware.GetLoginUserIDFromContext(ctx) - resp, err := sc.siteInfoService.SaveSiteWrite(ctx, req) + resp, err := sc.siteInfoService.SaveSiteTags(ctx, req) handler.HandleResponse(ctx, err, resp) } -// UpdateSiteLegal update site legal info -// @Summary update site legal info -// @Description update site legal info +// UpdateSiteAdvanced update site advanced info +// @Summary update site advanced info +// @Description update site advanced info +// @Security ApiKeyAuth +// @Tags admin +// @Produce json +// @Param data body schema.SiteAdvancedReq true "advanced settings" +// @Success 200 {object} handler.RespBody{} +// @Router /answer/admin/api/siteinfo/advanced [put] +func (sc *SiteInfoController) UpdateSiteAdvanced(ctx *gin.Context) { + req := &schema.SiteAdvancedReq{} + if handler.BindAndCheck(ctx, req) { + return + } + + resp, err := sc.siteInfoService.SaveSiteAdvanced(ctx, req) + handler.HandleResponse(ctx, err, resp) +} + +// UpdateSitePolices update site policies configuration +// @Summary update site policies configuration +// @Description update site policies configuration +// @Security ApiKeyAuth +// @Tags admin +// @Produce json +// @Param data body schema.SitePoliciesReq true "write info" +// @Success 200 {object} handler.RespBody{} +// @Router /answer/admin/api/siteinfo/polices [put] +func (sc *SiteInfoController) UpdateSitePolices(ctx *gin.Context) { + req := &schema.SitePoliciesReq{} + if handler.BindAndCheck(ctx, req) { + return + } + err := sc.siteInfoService.SaveSitePolicies(ctx, req) + handler.HandleResponse(ctx, err, nil) +} + +// UpdateSiteSecurity update site security configuration +// @Summary update site security configuration +// @Description update site security configuration // @Security ApiKeyAuth // @Tags admin // @Produce json -// @Param data body schema.SiteLegalReq true "write info" +// @Param data body schema.SiteSecurityReq true "write info" // @Success 200 {object} handler.RespBody{} -// @Router /answer/admin/api/siteinfo/legal [put] -func (sc *SiteInfoController) UpdateSiteLegal(ctx *gin.Context) { - req := &schema.SiteLegalReq{} +// @Router /answer/admin/api/siteinfo/security [put] +func (sc *SiteInfoController) UpdateSiteSecurity(ctx *gin.Context) { + req := &schema.SiteSecurityReq{} if handler.BindAndCheck(ctx, req) { return } - err := sc.siteInfoService.SaveSiteLegal(ctx, req) + err := sc.siteInfoService.SaveSiteSecurity(ctx, req) handler.HandleResponse(ctx, err, nil) } diff --git a/internal/migrations/init.go b/internal/migrations/init.go index 5ffb37711..ae2eeb9a3 100644 --- a/internal/migrations/init.go +++ b/internal/migrations/init.go @@ -74,14 +74,17 @@ func (m *Mentor) InitDB() error { m.do("init role power rel", m.initRolePowerRel) m.do("init admin user role rel", m.initAdminUserRoleRel) m.do("init site info interface", m.initSiteInfoInterface) + m.do("init site info users settings", m.initSiteInfoUsersSettings) m.do("init site info general config", m.initSiteInfoGeneralData) m.do("init site info login config", m.initSiteInfoLoginConfig) m.do("init site info theme config", m.initSiteInfoThemeConfig) m.do("init site info seo config", m.initSiteInfoSEOConfig) m.do("init site info user config", m.initSiteInfoUsersConfig) m.do("init site info privilege rank", m.initSiteInfoPrivilegeRank) - m.do("init site info write", m.initSiteInfoWrite) - m.do("init site info legal", m.initSiteInfoLegalConfig) + m.do("init site info write", m.initSiteInfoAdvanced) + m.do("init site info write", m.initSiteInfoQuestions) + m.do("init site info write", m.initSiteInfoTags) + m.do("init site info security", m.initSiteInfoSecurityConfig) m.do("init default content", m.initDefaultContent) m.do("init default badges", m.initDefaultBadges) return m.err @@ -181,19 +184,30 @@ func (m *Mentor) initSiteInfoInterface() { } interfaceData := map[string]string{ - "language": m.userData.Language, - "time_zone": localTimezone, - "default_avatar": "gravatar", - "gravatar_base_url": "https://www.gravatar.com/avatar/", + "language": m.userData.Language, + "time_zone": localTimezone, } interfaceDataBytes, _ := json.Marshal(interfaceData) _, m.err = m.engine.Context(m.ctx).Insert(&entity.SiteInfo{ - Type: "interface", + Type: "interface_settings", Content: string(interfaceDataBytes), Status: 1, }) } +func (m *Mentor) initSiteInfoUsersSettings() { + usersSettings := map[string]any{ + "default_avatar": "gravatar", + "gravatar_base_url": "https://www.gravatar.com/avatar/", + } + usersSettingsDataBytes, _ := json.Marshal(usersSettings) + _, m.err = m.engine.Context(m.ctx).Insert(&entity.SiteInfo{ + Type: "users_settings", + Content: string(usersSettingsDataBytes), + Status: 1, + }) +} + func (m *Mentor) initSiteInfoGeneralData() { generalData := map[string]string{ "name": m.userData.SiteName, @@ -213,7 +227,6 @@ func (m *Mentor) initSiteInfoLoginConfig() { "allow_new_registrations": true, "allow_email_registrations": true, "allow_password_login": true, - "login_required": m.userData.LoginRequired, } loginConfigDataBytes, _ := json.Marshal(loginConfig) _, m.err = m.engine.Context(m.ctx).Insert(&entity.SiteInfo{ @@ -223,14 +236,16 @@ func (m *Mentor) initSiteInfoLoginConfig() { }) } -func (m *Mentor) initSiteInfoLegalConfig() { - legalConfig := map[string]any{ +func (m *Mentor) initSiteInfoSecurityConfig() { + securityConfig := map[string]any{ + "login_required": m.userData.LoginRequired, "external_content_display": m.userData.ExternalContentDisplay, + "check_update": true, } - legalConfigDataBytes, _ := json.Marshal(legalConfig) + securityConfigDataBytes, _ := json.Marshal(securityConfig) _, m.err = m.engine.Context(m.ctx).Insert(&entity.SiteInfo{ - Type: "legal", - Content: string(legalConfigDataBytes), + Type: "security", + Content: string(securityConfigDataBytes), Status: 1, }) } @@ -288,24 +303,46 @@ func (m *Mentor) initSiteInfoPrivilegeRank() { }) } -func (m *Mentor) initSiteInfoWrite() { - writeData := map[string]any{ - "min_content": 6, - "restrict_answer": true, - "min_tags": 1, - "required_tag": false, - "recommend_tags": []string{}, - "reserved_tags": []string{}, +func (m *Mentor) initSiteInfoAdvanced() { + advancedData := map[string]any{ "max_image_size": 4, "max_attachment_size": 8, "max_image_megapixel": 40, "authorized_image_extensions": []string{"jpg", "jpeg", "png", "gif", "webp"}, "authorized_attachment_extensions": []string{}, } - writeDataBytes, _ := json.Marshal(writeData) + advancedDataBytes, _ := json.Marshal(advancedData) + _, m.err = m.engine.Context(m.ctx).Insert(&entity.SiteInfo{ + Type: "advanced", + Content: string(advancedDataBytes), + Status: 1, + }) +} + +func (m *Mentor) initSiteInfoQuestions() { + questionsData := map[string]any{ + "min_tags": 1, + "min_content": 6, + "restrict_answer": true, + } + questionsDataBytes, _ := json.Marshal(questionsData) + _, m.err = m.engine.Context(m.ctx).Insert(&entity.SiteInfo{ + Type: "questions", + Content: string(questionsDataBytes), + Status: 1, + }) +} + +func (m *Mentor) initSiteInfoTags() { + tagsData := map[string]any{ + "required_tag": false, + "recommend_tags": []string{}, + "reserved_tags": []string{}, + } + tagsDataBytes, _ := json.Marshal(tagsData) _, m.err = m.engine.Context(m.ctx).Insert(&entity.SiteInfo{ - Type: "write", - Content: string(writeDataBytes), + Type: "tags", + Content: string(tagsDataBytes), Status: 1, }) } diff --git a/internal/migrations/migrations.go b/internal/migrations/migrations.go index 9fda8c34d..783332df9 100644 --- a/internal/migrations/migrations.go +++ b/internal/migrations/migrations.go @@ -105,6 +105,7 @@ var migrations = []Migration{ NewMigration("v1.6.0", "move user config to interface", moveUserConfigToInterface, true), NewMigration("v1.7.0", "add optional tags", addOptionalTags, true), NewMigration("v1.7.2", "expand avatar column length", expandAvatarColumnLength, false), + NewMigration("v1.8.0", "change admin menu", updateAdminMenuSettings, true), } func GetMigrations() []Migration { diff --git a/internal/migrations/v30.go b/internal/migrations/v30.go new file mode 100644 index 000000000..aa2f48b36 --- /dev/null +++ b/internal/migrations/v30.go @@ -0,0 +1,396 @@ +/* + * 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 migrations + +import ( + "context" + "encoding/json" + + "github.com/apache/answer/internal/base/constant" + "github.com/apache/answer/internal/base/reason" + "github.com/apache/answer/internal/entity" + "github.com/apache/answer/internal/schema" + "github.com/segmentfault/pacman/errors" + "xorm.io/builder" + "xorm.io/xorm" +) + +func updateAdminMenuSettings(ctx context.Context, x *xorm.Engine) (err error) { + err = splitWriteMenu(ctx, x) + if err != nil { + return + } + + err = splitInterfaceMenu(ctx, x) + if err != nil { + return + } + + err = splitLegalMenu(ctx, x) + if err != nil { + return + } + return +} + +// splitWriteMenu splits the site write settings into advanced, questions, and tags settings +func splitWriteMenu(ctx context.Context, x *xorm.Engine) error { + var ( + siteInfo = &entity.SiteInfo{} + siteInfoAdvanced = &entity.SiteInfo{} + siteInfoQuestions = &entity.SiteInfo{} + siteInfoTags = &entity.SiteInfo{} + ) + exist, err := x.Context(ctx).Where(builder.Eq{"type": constant.SiteTypeWrite}).Get(siteInfo) + if err != nil { + err = errors.InternalServer(reason.DatabaseError).WithError(err).WithStack() + return err + } + if !exist { + return nil + } + siteWrite := &schema.SiteWriteResp{} + if err := json.Unmarshal([]byte(siteInfo.Content), siteWrite); err != nil { + return err + } + // site advanced settings + siteAdvanced := &schema.SiteAdvancedResp{ + MaxImageSize: siteWrite.MaxImageSize, + MaxAttachmentSize: siteWrite.MaxAttachmentSize, + MaxImageMegapixel: siteWrite.MaxImageMegapixel, + AuthorizedImageExtensions: siteWrite.AuthorizedImageExtensions, + AuthorizedAttachmentExtensions: siteWrite.AuthorizedAttachmentExtensions, + } + // site questions settings + siteQuestions := &schema.SiteQuestionsResp{ + MinimumTags: siteWrite.MinimumTags, + MinimumContent: siteWrite.MinimumContent, + RestrictAnswer: siteWrite.RestrictAnswer, + } + // site tags settings + siteTags := &schema.SiteTagsResp{ + ReservedTags: siteWrite.ReservedTags, + RecommendTags: siteWrite.RecommendTags, + RequiredTag: siteWrite.RequiredTag, + } + + // save site settings + // save advanced settings + existsAdvanced, err := x.Context(ctx).Where(builder.Eq{"type": constant.SiteTypeWrite}).Get(siteInfoAdvanced) + if err != nil { + return err + } + advancedContent, err := json.Marshal(siteAdvanced) + if err != nil { + return err + } + if !existsAdvanced { + _, err = x.Context(ctx).Insert(&entity.SiteInfo{ + Type: constant.SiteTypeAdvanced, + Content: string(advancedContent), + Status: 1, + }) + if err != nil { + return err + } + } + + // save questions settings + existsQuestions, err := x.Context(ctx).Where(builder.Eq{"type": constant.SiteTypeQuestions}).Get(siteInfoQuestions) + if err != nil { + return err + } + questionsContent, err := json.Marshal(siteQuestions) + if err != nil { + return err + } + if !existsQuestions { + _, err = x.Context(ctx).Insert(&entity.SiteInfo{ + Type: constant.SiteTypeQuestions, + Content: string(questionsContent), + Status: 1, + }) + if err != nil { + return err + } + } + + // save tags settings + existsTags, err := x.Context(ctx).Where(builder.Eq{"type": constant.SiteTypeTags}).Get(siteInfoTags) + if err != nil { + return err + } + tagsContent, err := json.Marshal(siteTags) + if err != nil { + return err + } + if !existsTags { + _, err = x.Context(ctx).Insert(&entity.SiteInfo{ + Type: constant.SiteTypeTags, + Content: string(tagsContent), + Status: 1, + }) + if err != nil { + return err + } + } + + return nil +} + +// splitInterfaceMenu splits the site interface settings into interface and user settings +func splitInterfaceMenu(ctx context.Context, x *xorm.Engine) error { + var ( + siteInfo = &entity.SiteInfo{} + siteInfoInterface = &entity.SiteInfo{} + siteInfoUsers = &entity.SiteInfo{} + ) + type SiteInterface struct { + Language string `validate:"required,gt=1,lte=128" form:"language" json:"language"` + TimeZone string `validate:"required,gt=1,lte=128" form:"time_zone" json:"time_zone"` + DefaultAvatar string `validate:"required,oneof=system gravatar" json:"default_avatar"` + GravatarBaseURL string `validate:"omitempty" json:"gravatar_base_url"` + } + + exist, err := x.Context(ctx).Where(builder.Eq{"type": constant.SiteTypeInterface}).Get(siteInfo) + if err != nil { + err = errors.InternalServer(reason.DatabaseError).WithError(err).WithStack() + return err + } + if !exist { + return nil + } + oldSiteInterface := &SiteInterface{} + if err := json.Unmarshal([]byte(siteInfo.Content), oldSiteInterface); err != nil { + return err + } + siteUser := &schema.SiteUsersSettingsResp{ + DefaultAvatar: oldSiteInterface.DefaultAvatar, + GravatarBaseURL: oldSiteInterface.GravatarBaseURL, + } + siteInterface := &schema.SiteInterfaceResp{ + Language: oldSiteInterface.Language, + TimeZone: oldSiteInterface.TimeZone, + } + + // save settings + // save user settings + existsUsers, err := x.Context(ctx).Where(builder.Eq{"type": constant.SiteTypeUsersSettings}).Get(siteInfoUsers) + if err != nil { + return err + } + userContent, err := json.Marshal(siteUser) + if err != nil { + return err + } + if !existsUsers { + _, err = x.Context(ctx).Insert(&entity.SiteInfo{ + Type: constant.SiteTypeUsersSettings, + Content: string(userContent), + Status: 1, + }) + if err != nil { + return err + } + } + + // save interface settings + existsInterface, err := x.Context(ctx).Where(builder.Eq{"type": constant.SiteTypeInterfaceSettings}).Get(siteInfoInterface) + if err != nil { + return err + } + interfaceContent, err := json.Marshal(siteInterface) + if err != nil { + return err + } + if !existsInterface { + _, err = x.Context(ctx).Insert(&entity.SiteInfo{ + Type: constant.SiteTypeInterfaceSettings, + Content: string(interfaceContent), + Status: 1, + }) + if err != nil { + return err + } + } + + return nil +} + +// splitLegalMenu splits the site legal settings into policies and security settings +func splitLegalMenu(ctx context.Context, x *xorm.Engine) error { + var ( + siteInfo = &entity.SiteInfo{} + siteInfoPolices = &entity.SiteInfo{} + siteInfoSecurity = &entity.SiteInfo{} + siteInfoLogin = &entity.SiteInfo{} + siteInfoGeneral = &entity.SiteInfo{} + ) + + type SiteLogin struct { + AllowNewRegistrations bool `json:"allow_new_registrations"` + AllowEmailRegistrations bool `json:"allow_email_registrations"` + AllowPasswordLogin bool `json:"allow_password_login"` + LoginRequired bool `json:"login_required"` + AllowEmailDomains []string `json:"allow_email_domains"` + } + + type SiteGeneral struct { + Name string `validate:"required,sanitizer,gt=1,lte=128" form:"name" json:"name"` + ShortDescription string `validate:"omitempty,sanitizer,gt=3,lte=255" form:"short_description" json:"short_description"` + Description string `validate:"omitempty,sanitizer,gt=3,lte=2000" form:"description" json:"description"` + SiteUrl string `validate:"required,sanitizer,gt=1,lte=512,url" form:"site_url" json:"site_url"` + ContactEmail string `validate:"required,sanitizer,gt=1,lte=512,email" form:"contact_email" json:"contact_email"` + CheckUpdate bool `validate:"omitempty,sanitizer" form:"check_update" json:"check_update"` + } + + // find old site legal settings + exist, err := x.Context(ctx).Where(builder.Eq{"type": constant.SiteTypeLegal}).Get(siteInfo) + if err != nil { + err = errors.InternalServer(reason.DatabaseError).WithError(err).WithStack() + return err + } + if !exist { + return nil + } + oldSiteLegal := &schema.SiteLegalResp{} + if err := json.Unmarshal([]byte(siteInfo.Content), oldSiteLegal); err != nil { + return err + } + + // find old site login settings + existsLogin, err := x.Context(ctx).Where(builder.Eq{"type": constant.SiteTypeLogin}).Get(siteInfoLogin) + if err != nil { + return err + } + oldSiteLogin := &SiteLogin{} + if err := json.Unmarshal([]byte(siteInfoLogin.Content), oldSiteLogin); err != nil { + return err + } + + // find old site general settings + existGeneral, err := x.Context(ctx).Where(builder.Eq{"type": constant.SiteTypeGeneral}).Get(siteInfoGeneral) + if err != nil { + return err + } + oldSiteGeneral := &SiteGeneral{} + if err := json.Unmarshal([]byte(siteInfoLogin.Content), oldSiteGeneral); err != nil { + return err + } + + sitePolicies := &schema.SitePoliciesResp{ + TermsOfServiceOriginalText: oldSiteLegal.TermsOfServiceOriginalText, + TermsOfServiceParsedText: oldSiteLegal.TermsOfServiceParsedText, + PrivacyPolicyOriginalText: oldSiteLegal.PrivacyPolicyOriginalText, + PrivacyPolicyParsedText: oldSiteLegal.PrivacyPolicyParsedText, + } + siteLogin := &schema.SiteLoginResp{ + AllowNewRegistrations: oldSiteLogin.AllowNewRegistrations, + AllowEmailRegistrations: oldSiteLogin.AllowEmailRegistrations, + AllowPasswordLogin: oldSiteLogin.AllowPasswordLogin, + AllowEmailDomains: oldSiteLogin.AllowEmailDomains, + } + siteGeneral := &schema.SiteGeneralReq{ + Name: oldSiteGeneral.Name, + ShortDescription: oldSiteGeneral.ShortDescription, + Description: oldSiteGeneral.Description, + SiteUrl: oldSiteGeneral.SiteUrl, + ContactEmail: oldSiteGeneral.ContactEmail, + } + siteSecurity := &schema.SiteSecurityResp{ + LoginRequired: oldSiteLogin.LoginRequired, + ExternalContentDisplay: oldSiteLegal.ExternalContentDisplay, + CheckUpdate: oldSiteGeneral.CheckUpdate, + } + if !existsLogin { + siteSecurity.LoginRequired = false + } + if !existGeneral { + siteSecurity.CheckUpdate = true + } + + // save settings + // save policies settings + existsPolicies, err := x.Context(ctx).Where(builder.Eq{"type": constant.SiteTypePolicies}).Get(siteInfoPolices) + if err != nil { + return err + } + policiesContent, err := json.Marshal(sitePolicies) + if err != nil { + return err + } + if !existsPolicies { + _, err = x.Context(ctx).Insert(&entity.SiteInfo{ + Type: constant.SiteTypePolicies, + Content: string(policiesContent), + Status: 1, + }) + if err != nil { + return err + } + } + + // save security settings + existsSecurity, err := x.Context(ctx).Where(builder.Eq{"type": constant.SiteTypeSecurity}).Get(siteInfoSecurity) + if err != nil { + return err + } + securityContent, err := json.Marshal(siteSecurity) + if err != nil { + return err + } + if !existsSecurity { + _, err = x.Context(ctx).Insert(&entity.SiteInfo{ + Type: constant.SiteTypeSecurity, + Content: string(securityContent), + Status: 1, + }) + if err != nil { + return err + } + } + + // save login settings + if existsLogin { + loginContent, err := json.Marshal(siteLogin) + _, err = x.Context(ctx).ID(siteInfoLogin.ID).Update(&entity.SiteInfo{ + Type: constant.SiteTypeLogin, + Content: string(loginContent), + Status: 1, + }) + if err != nil { + return err + } + } + + // save general settings + if existGeneral { + generalContent, err := json.Marshal(siteGeneral) + _, err = x.Context(ctx).ID(siteInfoGeneral.ID).Update(&entity.SiteInfo{ + Type: constant.SiteTypeGeneral, + Content: string(generalContent), + Status: 1, + }) + if err != nil { + return err + } + } + return nil +} diff --git a/internal/router/answer_api_router.go b/internal/router/answer_api_router.go index 1191492b9..1fe8bdb14 100644 --- a/internal/router/answer_api_router.go +++ b/internal/router/answer_api_router.go @@ -343,14 +343,27 @@ func (a *AnswerAPIRouter) RegisterAnswerAdminAPIRouter(r *gin.RouterGroup) { // siteinfo r.GET("/siteinfo/general", a.adminSiteInfoController.GetGeneral) r.PUT("/siteinfo/general", a.adminSiteInfoController.UpdateGeneral) + r.GET("/siteinfo/interface", a.adminSiteInfoController.GetInterface) r.PUT("/siteinfo/interface", a.adminSiteInfoController.UpdateInterface) + r.GET("/siteinfo/users-settings", a.adminSiteInfoController.GetUsersSettings) + r.PUT("/siteinfo/users-settings", a.adminSiteInfoController.UpdateUsersSettings) + r.GET("/siteinfo/branding", a.adminSiteInfoController.GetSiteBranding) r.PUT("/siteinfo/branding", a.adminSiteInfoController.UpdateBranding) - r.GET("/siteinfo/write", a.adminSiteInfoController.GetSiteWrite) - r.PUT("/siteinfo/write", a.adminSiteInfoController.UpdateSiteWrite) - r.GET("/siteinfo/legal", a.adminSiteInfoController.GetSiteLegal) - r.PUT("/siteinfo/legal", a.adminSiteInfoController.UpdateSiteLegal) + + r.GET("/siteinfo/question", a.adminSiteInfoController.GetSiteQuestion) + r.PUT("/siteinfo/question", a.adminSiteInfoController.UpdateSiteQuestion) + r.GET("/siteinfo/tag", a.adminSiteInfoController.GetSiteTag) + r.PUT("/siteinfo/tag", a.adminSiteInfoController.UpdateSiteTag) + r.GET("/siteinfo/advanced", a.adminSiteInfoController.GetSiteAdvanced) + r.PUT("/siteinfo/advanced", a.adminSiteInfoController.UpdateSiteAdvanced) + + r.GET("/siteinfo/polices", a.adminSiteInfoController.GetSitePolicies) + r.PUT("/siteinfo/polices", a.adminSiteInfoController.UpdateSitePolices) + r.GET("/siteinfo/security", a.adminSiteInfoController.GetSiteSecurity) + r.PUT("/siteinfo/security", a.adminSiteInfoController.UpdateSiteSecurity) + r.GET("/siteinfo/seo", a.adminSiteInfoController.GetSeo) r.PUT("/siteinfo/seo", a.adminSiteInfoController.UpdateSeo) r.GET("/siteinfo/login", a.adminSiteInfoController.GetSiteLogin) diff --git a/internal/schema/siteinfo_schema.go b/internal/schema/siteinfo_schema.go index 9eb919a0c..bf1c7713e 100644 --- a/internal/schema/siteinfo_schema.go +++ b/internal/schema/siteinfo_schema.go @@ -42,7 +42,6 @@ type SiteGeneralReq struct { Description string `validate:"omitempty,sanitizer,gt=3,lte=2000" form:"description" json:"description"` SiteUrl string `validate:"required,sanitizer,gt=1,lte=512,url" form:"site_url" json:"site_url"` ContactEmail string `validate:"required,sanitizer,gt=1,lte=512,email" form:"contact_email" json:"contact_email"` - CheckUpdate bool `validate:"omitempty,sanitizer" form:"check_update" json:"check_update"` } func (r *SiteGeneralReq) FormatSiteUrl() { @@ -59,12 +58,29 @@ func (r *SiteGeneralReq) FormatSiteUrl() { // SiteInterfaceReq site interface request type SiteInterfaceReq struct { - Language string `validate:"required,gt=1,lte=128" form:"language" json:"language"` - TimeZone string `validate:"required,gt=1,lte=128" form:"time_zone" json:"time_zone"` + Language string `validate:"required,gt=1,lte=128" form:"language" json:"language"` + TimeZone string `validate:"required,gt=1,lte=128" form:"time_zone" json:"time_zone"` + // Deperecated: use SiteUsersSettingsReq instead + DefaultAvatar string `validate:"omitempty" json:"-"` + // Deperecated: use SiteUsersSettingsReq instead + GravatarBaseURL string `validate:"omitempty" json:"-"` +} + +// SiteInterfaceSettingsReq site interface settings request +type SiteInterfaceSettingsReq struct { + Language string `validate:"required,gt=1,lte=128" json:"language"` + TimeZone string `validate:"required,gt=1,lte=128" json:"time_zone"` +} + +type SiteInterfaceSettingsResp SiteInterfaceSettingsReq + +type SiteUsersSettingsReq struct { DefaultAvatar string `validate:"required,oneof=system gravatar" json:"default_avatar"` GravatarBaseURL string `validate:"omitempty" json:"gravatar_base_url"` } +type SiteUsersSettingsResp SiteUsersSettingsReq + // SiteBrandingReq site branding request type SiteBrandingReq struct { Logo string `validate:"omitempty,gt=0,lte=512" form:"logo" json:"logo"` @@ -74,6 +90,7 @@ type SiteBrandingReq struct { } // SiteWriteReq site write request +// Deprecated: use SiteQuestionsReq, SiteAdvancedReq and SiteTagsReq instead type SiteWriteReq struct { MinimumContent int `validate:"omitempty,gte=0,lte=65535" json:"min_content"` RestrictAnswer bool `validate:"omitempty" json:"restrict_answer"` @@ -89,21 +106,47 @@ type SiteWriteReq struct { UserID string `json:"-"` } -func (s *SiteWriteResp) GetMaxImageSize() int64 { +type SiteWriteResp SiteWriteReq + +// SiteQuestionsReq site questions settings request +type SiteQuestionsReq struct { + MinimumTags int `validate:"omitempty,gte=0,lte=5" json:"min_tags"` + MinimumContent int `validate:"omitempty,gte=0,lte=65535" json:"min_content"` + RestrictAnswer bool `validate:"omitempty" json:"restrict_answer"` +} + +// SiteAdvancedReq site advanced settings request +type SiteAdvancedReq struct { + MaxImageSize int `validate:"omitempty,gt=0" json:"max_image_size"` + MaxAttachmentSize int `validate:"omitempty,gt=0" json:"max_attachment_size"` + MaxImageMegapixel int `validate:"omitempty,gt=0" json:"max_image_megapixel"` + AuthorizedImageExtensions []string `validate:"omitempty" json:"authorized_image_extensions"` + AuthorizedAttachmentExtensions []string `validate:"omitempty" json:"authorized_attachment_extensions"` +} + +// SiteTagsReq site tags settings request +type SiteTagsReq struct { + ReservedTags []*SiteWriteTag `validate:"omitempty,dive" json:"reserved_tags"` + RecommendTags []*SiteWriteTag `validate:"omitempty,dive" json:"recommend_tags"` + RequiredTag bool `validate:"omitempty" json:"required_tag"` + UserID string `json:"-"` +} + +func (s *SiteAdvancedResp) GetMaxImageSize() int64 { if s.MaxImageSize <= 0 { return constant.DefaultMaxImageSize } return int64(s.MaxImageSize) * 1024 * 1024 } -func (s *SiteWriteResp) GetMaxAttachmentSize() int64 { +func (s *SiteAdvancedResp) GetMaxAttachmentSize() int64 { if s.MaxAttachmentSize <= 0 { return constant.DefaultMaxAttachmentSize } return int64(s.MaxAttachmentSize) * 1024 * 1024 } -func (s *SiteWriteResp) GetMaxImageMegapixel() int { +func (s *SiteAdvancedResp) GetMaxImageMegapixel() int { if s.MaxImageMegapixel <= 0 { return constant.DefaultMaxImageMegapixel } @@ -117,6 +160,7 @@ type SiteWriteTag struct { } // SiteLegalReq site branding request +// Deprecated: use SitePoliciesReq and SiteSecurityReq instead type SiteLegalReq struct { TermsOfServiceOriginalText string `json:"terms_of_service_original_text"` TermsOfServiceParsedText string `json:"terms_of_service_parsed_text"` @@ -125,6 +169,22 @@ type SiteLegalReq struct { ExternalContentDisplay string `validate:"required,oneof=always_display ask_before_display" json:"external_content_display"` } +type SitePoliciesReq struct { + TermsOfServiceOriginalText string `json:"terms_of_service_original_text"` + TermsOfServiceParsedText string `json:"terms_of_service_parsed_text"` + PrivacyPolicyOriginalText string `json:"privacy_policy_original_text"` + PrivacyPolicyParsedText string `json:"privacy_policy_parsed_text"` +} + +type SiteSecurityReq struct { + LoginRequired bool `json:"login_required"` + ExternalContentDisplay string `validate:"required,oneof=always_display ask_before_display" json:"external_content_display"` + CheckUpdate bool `validate:"omitempty,sanitizer" form:"check_update" json:"check_update"` +} + +type SitePoliciesResp SitePoliciesReq +type SiteSecurityResp SiteSecurityReq + // GetSiteLegalInfoReq site site legal request type GetSiteLegalInfoReq struct { InfoType string `validate:"required,oneof=tos privacy" form:"info_type"` @@ -163,7 +223,6 @@ type SiteLoginReq struct { AllowNewRegistrations bool `json:"allow_new_registrations"` AllowEmailRegistrations bool `json:"allow_email_registrations"` AllowPasswordLogin bool `json:"allow_password_login"` - LoginRequired bool `json:"login_required"` AllowEmailDomains []string `json:"allow_email_domains"` } @@ -238,10 +297,12 @@ type ThemeOption struct { Value string `json:"value"` } -// SiteWriteResp site write response -type SiteWriteResp SiteWriteReq +type SiteQuestionsResp SiteQuestionsReq +type SiteAdvancedResp SiteAdvancedReq +type SiteTagsResp SiteTagsReq // SiteLegalResp site write response +// Deprecated: use SitePoliciesResp and SiteSecurityResp instead type SiteLegalResp SiteLegalReq // SiteLegalSimpleResp site write response @@ -254,25 +315,30 @@ type SiteSeoResp SiteSeoReq // SiteInfoResp get site info response type SiteInfoResp struct { - General *SiteGeneralResp `json:"general"` - Interface *SiteInterfaceResp `json:"interface"` - Branding *SiteBrandingResp `json:"branding"` - Login *SiteLoginResp `json:"login"` - Theme *SiteThemeResp `json:"theme"` - CustomCssHtml *SiteCustomCssHTMLResp `json:"custom_css_html"` - SiteSeo *SiteSeoResp `json:"site_seo"` - SiteUsers *SiteUsersResp `json:"site_users"` - Write *SiteWriteResp `json:"site_write"` - Legal *SiteLegalSimpleResp `json:"site_legal"` - Version string `json:"version"` - Revision string `json:"revision"` + General *SiteGeneralResp `json:"general"` + Interface *SiteInterfaceSettingsResp `json:"interface"` + UsersSettings *SiteUsersSettingsResp `json:"users_settings"` + Branding *SiteBrandingResp `json:"branding"` + Login *SiteLoginResp `json:"login"` + Theme *SiteThemeResp `json:"theme"` + CustomCssHtml *SiteCustomCssHTMLResp `json:"custom_css_html"` + SiteSeo *SiteSeoResp `json:"site_seo"` + SiteUsers *SiteUsersResp `json:"site_users"` + Advanced *SiteAdvancedResp `json:"site_advanced"` + Questions *SiteQuestionsResp `json:"site_questions"` + Tags *SiteTagsResp `json:"site_tags"` + Legal *SiteLegalSimpleResp `json:"site_legal"` + Security *SiteSecurityResp `json:"site_security"` + Version string `json:"version"` + Revision string `json:"revision"` } + type TemplateSiteInfoResp struct { - General *SiteGeneralResp `json:"general"` - Interface *SiteInterfaceResp `json:"interface"` - Branding *SiteBrandingResp `json:"branding"` - SiteSeo *SiteSeoResp `json:"site_seo"` - CustomCssHtml *SiteCustomCssHTMLResp `json:"custom_css_html"` + General *SiteGeneralResp `json:"general"` + Interface *SiteInterfaceSettingsResp `json:"interface"` + Branding *SiteBrandingResp `json:"branding"` + SiteSeo *SiteSeoResp `json:"site_seo"` + CustomCssHtml *SiteCustomCssHTMLResp `json:"custom_css_html"` Title string Year string Canonical string diff --git a/internal/service/dashboard/dashboard_service.go b/internal/service/dashboard/dashboard_service.go index 8b08ba02f..a6ac76e63 100644 --- a/internal/service/dashboard/dashboard_service.go +++ b/internal/service/dashboard/dashboard_service.go @@ -101,6 +101,12 @@ type DashboardService interface { func (ds *dashboardService) Statistical(ctx context.Context) (*schema.DashboardInfo, error) { dashboardInfo := ds.getFromCache(ctx) + security, err := ds.siteInfoService.GetSiteSecurity(ctx) + if err != nil { + log.Errorf("get general site info failed: %s", err) + return dashboardInfo, nil + } + if dashboardInfo == nil { dashboardInfo = &schema.DashboardInfo{} dashboardInfo.AnswerCount = ds.answerCount(ctx) @@ -108,12 +114,7 @@ func (ds *dashboardService) Statistical(ctx context.Context) (*schema.DashboardI dashboardInfo.UserCount = ds.userCount(ctx) dashboardInfo.VoteCount = ds.voteCount(ctx) dashboardInfo.OccupyingStorageSpace = ds.calculateStorage() - general, err := ds.siteInfoService.GetSiteGeneral(ctx) - if err != nil { - log.Errorf("get general site info failed: %s", err) - return dashboardInfo, nil - } - if general.CheckUpdate { + if security.CheckUpdate { dashboardInfo.VersionInfo.RemoteVersion = ds.remoteVersion(ctx) } dashboardInfo.DatabaseVersion = ds.getDatabaseInfo() @@ -141,9 +142,7 @@ func (ds *dashboardService) Statistical(ctx context.Context) (*schema.DashboardI dashboardInfo.VersionInfo.Version = constant.Version dashboardInfo.VersionInfo.Revision = constant.Revision dashboardInfo.GoVersion = constant.GoVersion - if siteLogin, err := ds.siteInfoService.GetSiteLogin(ctx); err == nil { - dashboardInfo.LoginRequired = siteLogin.LoginRequired - } + dashboardInfo.LoginRequired = security.LoginRequired ds.setCache(ctx, dashboardInfo) return dashboardInfo, nil diff --git a/internal/service/mock/siteinfo_repo_mock.go b/internal/service/mock/siteinfo_repo_mock.go index 0a1b31e84..8feb6a27c 100644 --- a/internal/service/mock/siteinfo_repo_mock.go +++ b/internal/service/mock/siteinfo_repo_mock.go @@ -22,7 +22,6 @@ import ( type MockSiteInfoRepo struct { ctrl *gomock.Controller recorder *MockSiteInfoRepoMockRecorder - isgomock struct{} } // MockSiteInfoRepoMockRecorder is the mock recorder for MockSiteInfoRepo. @@ -53,7 +52,7 @@ func (m *MockSiteInfoRepo) GetByType(ctx context.Context, siteType string) (*ent } // GetByType indicates an expected call of GetByType. -func (mr *MockSiteInfoRepoMockRecorder) GetByType(ctx, siteType any) *gomock.Call { +func (mr *MockSiteInfoRepoMockRecorder) GetByType(ctx, siteType interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetByType", reflect.TypeOf((*MockSiteInfoRepo)(nil).GetByType), ctx, siteType) } @@ -68,7 +67,7 @@ func (m *MockSiteInfoRepo) IsBrandingFileUsed(ctx context.Context, filePath stri } // IsBrandingFileUsed indicates an expected call of IsBrandingFileUsed. -func (mr *MockSiteInfoRepoMockRecorder) IsBrandingFileUsed(ctx, filePath any) *gomock.Call { +func (mr *MockSiteInfoRepoMockRecorder) IsBrandingFileUsed(ctx, filePath interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsBrandingFileUsed", reflect.TypeOf((*MockSiteInfoRepo)(nil).IsBrandingFileUsed), ctx, filePath) } @@ -82,7 +81,7 @@ func (m *MockSiteInfoRepo) SaveByType(ctx context.Context, siteType string, data } // SaveByType indicates an expected call of SaveByType. -func (mr *MockSiteInfoRepoMockRecorder) SaveByType(ctx, siteType, data any) *gomock.Call { +func (mr *MockSiteInfoRepoMockRecorder) SaveByType(ctx, siteType, data interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SaveByType", reflect.TypeOf((*MockSiteInfoRepo)(nil).SaveByType), ctx, siteType, data) } @@ -91,7 +90,6 @@ func (mr *MockSiteInfoRepoMockRecorder) SaveByType(ctx, siteType, data any) *gom type MockSiteInfoCommonService struct { ctrl *gomock.Controller recorder *MockSiteInfoCommonServiceMockRecorder - isgomock struct{} } // MockSiteInfoCommonServiceMockRecorder is the mock recorder for MockSiteInfoCommonService. @@ -120,7 +118,7 @@ func (m *MockSiteInfoCommonService) FormatAvatar(ctx context.Context, originalAv } // FormatAvatar indicates an expected call of FormatAvatar. -func (mr *MockSiteInfoCommonServiceMockRecorder) FormatAvatar(ctx, originalAvatarData, email, userStatus any) *gomock.Call { +func (mr *MockSiteInfoCommonServiceMockRecorder) FormatAvatar(ctx, originalAvatarData, email, userStatus interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FormatAvatar", reflect.TypeOf((*MockSiteInfoCommonService)(nil).FormatAvatar), ctx, originalAvatarData, email, userStatus) } @@ -134,11 +132,26 @@ func (m *MockSiteInfoCommonService) FormatListAvatar(ctx context.Context, userLi } // FormatListAvatar indicates an expected call of FormatListAvatar. -func (mr *MockSiteInfoCommonServiceMockRecorder) FormatListAvatar(ctx, userList any) *gomock.Call { +func (mr *MockSiteInfoCommonServiceMockRecorder) FormatListAvatar(ctx, userList interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FormatListAvatar", reflect.TypeOf((*MockSiteInfoCommonService)(nil).FormatListAvatar), ctx, userList) } +// GetSiteAdvanced mocks base method. +func (m *MockSiteInfoCommonService) GetSiteAdvanced(ctx context.Context) (*schema.SiteAdvancedResp, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetSiteAdvanced", ctx) + ret0, _ := ret[0].(*schema.SiteAdvancedResp) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetSiteAdvanced indicates an expected call of GetSiteAdvanced. +func (mr *MockSiteInfoCommonServiceMockRecorder) GetSiteAdvanced(ctx interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetSiteAdvanced", reflect.TypeOf((*MockSiteInfoCommonService)(nil).GetSiteAdvanced), ctx) +} + // GetSiteBranding mocks base method. func (m *MockSiteInfoCommonService) GetSiteBranding(ctx context.Context) (*schema.SiteBrandingResp, error) { m.ctrl.T.Helper() @@ -149,7 +162,7 @@ func (m *MockSiteInfoCommonService) GetSiteBranding(ctx context.Context) (*schem } // GetSiteBranding indicates an expected call of GetSiteBranding. -func (mr *MockSiteInfoCommonServiceMockRecorder) GetSiteBranding(ctx any) *gomock.Call { +func (mr *MockSiteInfoCommonServiceMockRecorder) GetSiteBranding(ctx interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetSiteBranding", reflect.TypeOf((*MockSiteInfoCommonService)(nil).GetSiteBranding), ctx) } @@ -164,7 +177,7 @@ func (m *MockSiteInfoCommonService) GetSiteCustomCssHTML(ctx context.Context) (* } // GetSiteCustomCssHTML indicates an expected call of GetSiteCustomCssHTML. -func (mr *MockSiteInfoCommonServiceMockRecorder) GetSiteCustomCssHTML(ctx any) *gomock.Call { +func (mr *MockSiteInfoCommonServiceMockRecorder) GetSiteCustomCssHTML(ctx interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetSiteCustomCssHTML", reflect.TypeOf((*MockSiteInfoCommonService)(nil).GetSiteCustomCssHTML), ctx) } @@ -179,7 +192,7 @@ func (m *MockSiteInfoCommonService) GetSiteGeneral(ctx context.Context) (*schema } // GetSiteGeneral indicates an expected call of GetSiteGeneral. -func (mr *MockSiteInfoCommonServiceMockRecorder) GetSiteGeneral(ctx any) *gomock.Call { +func (mr *MockSiteInfoCommonServiceMockRecorder) GetSiteGeneral(ctx interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetSiteGeneral", reflect.TypeOf((*MockSiteInfoCommonService)(nil).GetSiteGeneral), ctx) } @@ -193,54 +206,84 @@ func (m *MockSiteInfoCommonService) GetSiteInfoByType(ctx context.Context, siteT } // GetSiteInfoByType indicates an expected call of GetSiteInfoByType. -func (mr *MockSiteInfoCommonServiceMockRecorder) GetSiteInfoByType(ctx, siteType, resp any) *gomock.Call { +func (mr *MockSiteInfoCommonServiceMockRecorder) GetSiteInfoByType(ctx, siteType, resp interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetSiteInfoByType", reflect.TypeOf((*MockSiteInfoCommonService)(nil).GetSiteInfoByType), ctx, siteType, resp) } // GetSiteInterface mocks base method. -func (m *MockSiteInfoCommonService) GetSiteInterface(ctx context.Context) (*schema.SiteInterfaceResp, error) { +func (m *MockSiteInfoCommonService) GetSiteInterface(ctx context.Context) (*schema.SiteInterfaceSettingsResp, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetSiteInterface", ctx) - ret0, _ := ret[0].(*schema.SiteInterfaceResp) + ret0, _ := ret[0].(*schema.SiteInterfaceSettingsResp) ret1, _ := ret[1].(error) return ret0, ret1 } // GetSiteInterface indicates an expected call of GetSiteInterface. -func (mr *MockSiteInfoCommonServiceMockRecorder) GetSiteInterface(ctx any) *gomock.Call { +func (mr *MockSiteInfoCommonServiceMockRecorder) GetSiteInterface(ctx interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetSiteInterface", reflect.TypeOf((*MockSiteInfoCommonService)(nil).GetSiteInterface), ctx) } -// GetSiteLegal mocks base method. -func (m *MockSiteInfoCommonService) GetSiteLegal(ctx context.Context) (*schema.SiteLegalResp, error) { +// GetSiteLogin mocks base method. +func (m *MockSiteInfoCommonService) GetSiteLogin(ctx context.Context) (*schema.SiteLoginResp, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetSiteLegal", ctx) - ret0, _ := ret[0].(*schema.SiteLegalResp) + ret := m.ctrl.Call(m, "GetSiteLogin", ctx) + ret0, _ := ret[0].(*schema.SiteLoginResp) ret1, _ := ret[1].(error) return ret0, ret1 } -// GetSiteLegal indicates an expected call of GetSiteLegal. -func (mr *MockSiteInfoCommonServiceMockRecorder) GetSiteLegal(ctx any) *gomock.Call { +// GetSiteLogin indicates an expected call of GetSiteLogin. +func (mr *MockSiteInfoCommonServiceMockRecorder) GetSiteLogin(ctx interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetSiteLegal", reflect.TypeOf((*MockSiteInfoCommonService)(nil).GetSiteLegal), ctx) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetSiteLogin", reflect.TypeOf((*MockSiteInfoCommonService)(nil).GetSiteLogin), ctx) } -// GetSiteLogin mocks base method. -func (m *MockSiteInfoCommonService) GetSiteLogin(ctx context.Context) (*schema.SiteLoginResp, error) { +// GetSitePolicies mocks base method. +func (m *MockSiteInfoCommonService) GetSitePolicies(ctx context.Context) (*schema.SitePoliciesResp, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetSiteLogin", ctx) - ret0, _ := ret[0].(*schema.SiteLoginResp) + ret := m.ctrl.Call(m, "GetSitePolicies", ctx) + ret0, _ := ret[0].(*schema.SitePoliciesResp) ret1, _ := ret[1].(error) return ret0, ret1 } -// GetSiteLogin indicates an expected call of GetSiteLogin. -func (mr *MockSiteInfoCommonServiceMockRecorder) GetSiteLogin(ctx any) *gomock.Call { +// GetSitePolicies indicates an expected call of GetSitePolicies. +func (mr *MockSiteInfoCommonServiceMockRecorder) GetSitePolicies(ctx interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetSiteLogin", reflect.TypeOf((*MockSiteInfoCommonService)(nil).GetSiteLogin), ctx) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetSitePolicies", reflect.TypeOf((*MockSiteInfoCommonService)(nil).GetSitePolicies), ctx) +} + +// GetSiteQuestion mocks base method. +func (m *MockSiteInfoCommonService) GetSiteQuestion(ctx context.Context) (*schema.SiteQuestionsResp, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetSiteQuestion", ctx) + ret0, _ := ret[0].(*schema.SiteQuestionsResp) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetSiteQuestion indicates an expected call of GetSiteQuestion. +func (mr *MockSiteInfoCommonServiceMockRecorder) GetSiteQuestion(ctx interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetSiteQuestion", reflect.TypeOf((*MockSiteInfoCommonService)(nil).GetSiteQuestion), ctx) +} + +// GetSiteSecurity mocks base method. +func (m *MockSiteInfoCommonService) GetSiteSecurity(ctx context.Context) (*schema.SiteSecurityResp, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetSiteSecurity", ctx) + ret0, _ := ret[0].(*schema.SiteSecurityResp) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetSiteSecurity indicates an expected call of GetSiteSecurity. +func (mr *MockSiteInfoCommonServiceMockRecorder) GetSiteSecurity(ctx interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetSiteSecurity", reflect.TypeOf((*MockSiteInfoCommonService)(nil).GetSiteSecurity), ctx) } // GetSiteSeo mocks base method. @@ -253,11 +296,26 @@ func (m *MockSiteInfoCommonService) GetSiteSeo(ctx context.Context) (*schema.Sit } // GetSiteSeo indicates an expected call of GetSiteSeo. -func (mr *MockSiteInfoCommonServiceMockRecorder) GetSiteSeo(ctx any) *gomock.Call { +func (mr *MockSiteInfoCommonServiceMockRecorder) GetSiteSeo(ctx interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetSiteSeo", reflect.TypeOf((*MockSiteInfoCommonService)(nil).GetSiteSeo), ctx) } +// GetSiteTag mocks base method. +func (m *MockSiteInfoCommonService) GetSiteTag(ctx context.Context) (*schema.SiteTagsResp, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetSiteTag", ctx) + ret0, _ := ret[0].(*schema.SiteTagsResp) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetSiteTag indicates an expected call of GetSiteTag. +func (mr *MockSiteInfoCommonServiceMockRecorder) GetSiteTag(ctx interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetSiteTag", reflect.TypeOf((*MockSiteInfoCommonService)(nil).GetSiteTag), ctx) +} + // GetSiteTheme mocks base method. func (m *MockSiteInfoCommonService) GetSiteTheme(ctx context.Context) (*schema.SiteThemeResp, error) { m.ctrl.T.Helper() @@ -268,7 +326,7 @@ func (m *MockSiteInfoCommonService) GetSiteTheme(ctx context.Context) (*schema.S } // GetSiteTheme indicates an expected call of GetSiteTheme. -func (mr *MockSiteInfoCommonServiceMockRecorder) GetSiteTheme(ctx any) *gomock.Call { +func (mr *MockSiteInfoCommonServiceMockRecorder) GetSiteTheme(ctx interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetSiteTheme", reflect.TypeOf((*MockSiteInfoCommonService)(nil).GetSiteTheme), ctx) } @@ -283,11 +341,26 @@ func (m *MockSiteInfoCommonService) GetSiteUsers(ctx context.Context) (*schema.S } // GetSiteUsers indicates an expected call of GetSiteUsers. -func (mr *MockSiteInfoCommonServiceMockRecorder) GetSiteUsers(ctx any) *gomock.Call { +func (mr *MockSiteInfoCommonServiceMockRecorder) GetSiteUsers(ctx interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetSiteUsers", reflect.TypeOf((*MockSiteInfoCommonService)(nil).GetSiteUsers), ctx) } +// GetSiteUsersSettings mocks base method. +func (m *MockSiteInfoCommonService) GetSiteUsersSettings(ctx context.Context) (*schema.SiteUsersSettingsResp, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetSiteUsersSettings", ctx) + ret0, _ := ret[0].(*schema.SiteUsersSettingsResp) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetSiteUsersSettings indicates an expected call of GetSiteUsersSettings. +func (mr *MockSiteInfoCommonServiceMockRecorder) GetSiteUsersSettings(ctx interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetSiteUsersSettings", reflect.TypeOf((*MockSiteInfoCommonService)(nil).GetSiteUsersSettings), ctx) +} + // GetSiteWrite mocks base method. func (m *MockSiteInfoCommonService) GetSiteWrite(ctx context.Context) (*schema.SiteWriteResp, error) { m.ctrl.T.Helper() @@ -298,7 +371,7 @@ func (m *MockSiteInfoCommonService) GetSiteWrite(ctx context.Context) (*schema.S } // GetSiteWrite indicates an expected call of GetSiteWrite. -func (mr *MockSiteInfoCommonServiceMockRecorder) GetSiteWrite(ctx any) *gomock.Call { +func (mr *MockSiteInfoCommonServiceMockRecorder) GetSiteWrite(ctx interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetSiteWrite", reflect.TypeOf((*MockSiteInfoCommonService)(nil).GetSiteWrite), ctx) } @@ -312,7 +385,7 @@ func (m *MockSiteInfoCommonService) IsBrandingFileUsed(ctx context.Context, file } // IsBrandingFileUsed indicates an expected call of IsBrandingFileUsed. -func (mr *MockSiteInfoCommonServiceMockRecorder) IsBrandingFileUsed(ctx, filePath any) *gomock.Call { +func (mr *MockSiteInfoCommonServiceMockRecorder) IsBrandingFileUsed(ctx, filePath interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsBrandingFileUsed", reflect.TypeOf((*MockSiteInfoCommonService)(nil).IsBrandingFileUsed), ctx, filePath) } diff --git a/internal/service/question_common/question.go b/internal/service/question_common/question.go index 557a5db15..3a7306342 100644 --- a/internal/service/question_common/question.go +++ b/internal/service/question_common/question.go @@ -900,7 +900,7 @@ func (qs *QuestionCommon) tryToGetQuestionIDFromMsg(ctx context.Context, closeMs } func (qs *QuestionCommon) GetMinimumContentLength(ctx context.Context) (int, error) { - siteInfo, err := qs.siteInfoService.GetSiteWrite(ctx) + siteInfo, err := qs.siteInfoService.GetSiteQuestion(ctx) if err != nil { return 6, err } diff --git a/internal/service/siteinfo/siteinfo_service.go b/internal/service/siteinfo/siteinfo_service.go index 1eb187067..cc0cb5997 100644 --- a/internal/service/siteinfo/siteinfo_service.go +++ b/internal/service/siteinfo/siteinfo_service.go @@ -89,10 +89,15 @@ func (s *SiteInfoService) GetSiteGeneral(ctx context.Context) (resp *schema.Site } // GetSiteInterface get site info interface -func (s *SiteInfoService) GetSiteInterface(ctx context.Context) (resp *schema.SiteInterfaceResp, err error) { +func (s *SiteInfoService) GetSiteInterface(ctx context.Context) (resp *schema.SiteInterfaceSettingsResp, err error) { return s.siteInfoCommonService.GetSiteInterface(ctx) } +// GetSiteUsersSettings get site info users settings +func (s *SiteInfoService) GetSiteUsersSettings(ctx context.Context) (resp *schema.SiteUsersSettingsResp, err error) { + return s.siteInfoCommonService.GetSiteUsersSettings(ctx) +} + // GetSiteBranding get site info branding func (s *SiteInfoService) GetSiteBranding(ctx context.Context) (resp *schema.SiteBrandingResp, err error) { return s.siteInfoCommonService.GetSiteBranding(ctx) @@ -103,17 +108,14 @@ func (s *SiteInfoService) GetSiteUsers(ctx context.Context) (resp *schema.SiteUs return s.siteInfoCommonService.GetSiteUsers(ctx) } -// GetSiteWrite get site info write -func (s *SiteInfoService) GetSiteWrite(ctx context.Context) (resp *schema.SiteWriteResp, err error) { - resp = &schema.SiteWriteResp{} - siteInfo, exist, err := s.siteInfoRepo.GetByType(ctx, constant.SiteTypeWrite) +// GetSiteTag get site info write +func (s *SiteInfoService) GetSiteTag(ctx context.Context) (resp *schema.SiteTagsResp, err error) { + resp = &schema.SiteTagsResp{} + resp, err = s.siteInfoCommonService.GetSiteTag(ctx) if err != nil { log.Error(err) return resp, nil } - if exist { - _ = json.Unmarshal([]byte(siteInfo.Content), resp) - } resp.RecommendTags, err = s.tagCommonService.GetSiteWriteRecommendTag(ctx) if err != nil { @@ -126,9 +128,24 @@ func (s *SiteInfoService) GetSiteWrite(ctx context.Context) (resp *schema.SiteWr return resp, nil } -// GetSiteLegal get site legal info -func (s *SiteInfoService) GetSiteLegal(ctx context.Context) (resp *schema.SiteLegalResp, err error) { - return s.siteInfoCommonService.GetSiteLegal(ctx) +// GetSiteQuestion get site questions settings +func (s *SiteInfoService) GetSiteQuestion(ctx context.Context) (resp *schema.SiteQuestionsResp, err error) { + return s.siteInfoCommonService.GetSiteQuestion(ctx) +} + +// GetSiteAdvanced get site advanced settings +func (s *SiteInfoService) GetSiteAdvanced(ctx context.Context) (resp *schema.SiteAdvancedResp, err error) { + return s.siteInfoCommonService.GetSiteAdvanced(ctx) +} + +// GetSitePolicies get site legal info +func (s *SiteInfoService) GetSitePolicies(ctx context.Context) (resp *schema.SitePoliciesResp, err error) { + return s.siteInfoCommonService.GetSitePolicies(ctx) +} + +// GetSiteSecurity get site security info +func (s *SiteInfoService) GetSiteSecurity(ctx context.Context) (resp *schema.SiteSecurityResp, err error) { + return s.siteInfoCommonService.GetSiteSecurity(ctx) } // GetSiteLogin get site login info @@ -165,10 +182,20 @@ func (s *SiteInfoService) SaveSiteInterface(ctx context.Context, req schema.Site content, _ := json.Marshal(req) data := entity.SiteInfo{ - Type: constant.SiteTypeInterface, + Type: constant.SiteTypeInterfaceSettings, Content: string(content), } - return s.siteInfoRepo.SaveByType(ctx, constant.SiteTypeInterface, &data) + return s.siteInfoRepo.SaveByType(ctx, constant.SiteTypeInterfaceSettings, &data) +} + +// SaveSiteUsersSettings save site users settings +func (s *SiteInfoService) SaveSiteUsersSettings(ctx context.Context, req schema.SiteUsersSettingsReq) (err error) { + content, _ := json.Marshal(req) + data := entity.SiteInfo{ + Type: constant.SiteTypeInterfaceSettings, + Content: string(content), + } + return s.siteInfoRepo.SaveByType(ctx, constant.SiteTypeUsersSettings, &data) } // SaveSiteBranding save site branding information @@ -182,8 +209,30 @@ func (s *SiteInfoService) SaveSiteBranding(ctx context.Context, req *schema.Site return s.siteInfoRepo.SaveByType(ctx, constant.SiteTypeBranding, data) } -// SaveSiteWrite save site configuration about write -func (s *SiteInfoService) SaveSiteWrite(ctx context.Context, req *schema.SiteWriteReq) (resp any, err error) { +// SaveSiteAdvanced save site advanced configuration +func (s *SiteInfoService) SaveSiteAdvanced(ctx context.Context, req *schema.SiteAdvancedReq) (resp any, err error) { + content, _ := json.Marshal(req) + data := &entity.SiteInfo{ + Type: constant.SiteTypeAdvanced, + Content: string(content), + Status: 1, + } + return nil, s.siteInfoRepo.SaveByType(ctx, constant.SiteTypeAdvanced, data) +} + +// SaveSiteQuestions save site questions configuration +func (s *SiteInfoService) SaveSiteQuestions(ctx context.Context, req *schema.SiteQuestionsReq) (resp any, err error) { + content, _ := json.Marshal(req) + data := &entity.SiteInfo{ + Type: constant.SiteTypeQuestions, + Content: string(content), + Status: 1, + } + return nil, s.siteInfoRepo.SaveByType(ctx, constant.SiteTypeQuestions, data) +} + +// SaveSiteTags save site tags configuration +func (s *SiteInfoService) SaveSiteTags(ctx context.Context, req *schema.SiteTagsReq) (resp any, err error) { recommendTags, reservedTags := make([]string, 0), make([]string, 0) recommendTagMapping, reservedTagMapping := make(map[string]bool), make(map[string]bool) for _, tag := range req.ReservedTags { @@ -210,22 +259,33 @@ func (s *SiteInfoService) SaveSiteWrite(ctx context.Context, req *schema.SiteWri content, _ := json.Marshal(req) data := &entity.SiteInfo{ - Type: constant.SiteTypeWrite, + Type: constant.SiteTypeTags, + Content: string(content), + Status: 1, + } + return nil, s.siteInfoRepo.SaveByType(ctx, constant.SiteTypeTags, data) +} + +// SaveSitePolicies save site policies configuration +func (s *SiteInfoService) SaveSitePolicies(ctx context.Context, req *schema.SitePoliciesReq) (err error) { + content, _ := json.Marshal(req) + data := &entity.SiteInfo{ + Type: constant.SiteTypePolicies, Content: string(content), Status: 1, } - return nil, s.siteInfoRepo.SaveByType(ctx, constant.SiteTypeWrite, data) + return s.siteInfoRepo.SaveByType(ctx, constant.SiteTypePolicies, data) } -// SaveSiteLegal save site legal configuration -func (s *SiteInfoService) SaveSiteLegal(ctx context.Context, req *schema.SiteLegalReq) (err error) { +// SaveSiteSecurity save site security configuration +func (s *SiteInfoService) SaveSiteSecurity(ctx context.Context, req *schema.SiteSecurityReq) (err error) { content, _ := json.Marshal(req) data := &entity.SiteInfo{ - Type: constant.SiteTypeLegal, + Type: constant.SiteTypeSecurity, Content: string(content), Status: 1, } - return s.siteInfoRepo.SaveByType(ctx, constant.SiteTypeLegal, data) + return s.siteInfoRepo.SaveByType(ctx, constant.SiteTypeSecurity, data) } // SaveSiteLogin save site legal configuration @@ -320,13 +380,13 @@ func (s *SiteInfoService) GetSeo(ctx context.Context) (resp *schema.SiteSeoReq, if err = s.siteInfoCommonService.GetSiteInfoByType(ctx, constant.SiteTypeSeo, resp); err != nil { return resp, err } - loginConfig, err := s.GetSiteLogin(ctx) + siteSecurity, err := s.GetSiteSecurity(ctx) if err != nil { log.Error(err) return resp, nil } // If the site is set to privacy mode, prohibit crawling any page. - if loginConfig.LoginRequired { + if siteSecurity.LoginRequired { resp.Robots = "User-agent: *\nDisallow: /" return resp, nil } diff --git a/internal/service/siteinfo_common/siteinfo_service.go b/internal/service/siteinfo_common/siteinfo_service.go index 8a4b13669..2f2efb799 100644 --- a/internal/service/siteinfo_common/siteinfo_service.go +++ b/internal/service/siteinfo_common/siteinfo_service.go @@ -45,13 +45,18 @@ type siteInfoCommonService struct { type SiteInfoCommonService interface { GetSiteGeneral(ctx context.Context) (resp *schema.SiteGeneralResp, err error) - GetSiteInterface(ctx context.Context) (resp *schema.SiteInterfaceResp, err error) + GetSiteInterface(ctx context.Context) (resp *schema.SiteInterfaceSettingsResp, err error) + GetSiteUsersSettings(ctx context.Context) (resp *schema.SiteUsersSettingsResp, err error) GetSiteBranding(ctx context.Context) (resp *schema.SiteBrandingResp, err error) GetSiteUsers(ctx context.Context) (resp *schema.SiteUsersResp, err error) FormatAvatar(ctx context.Context, originalAvatarData, email string, userStatus int) *schema.AvatarInfo FormatListAvatar(ctx context.Context, userList []*entity.User) (userID2AvatarMapping map[string]*schema.AvatarInfo) GetSiteWrite(ctx context.Context) (resp *schema.SiteWriteResp, err error) - GetSiteLegal(ctx context.Context) (resp *schema.SiteLegalResp, err error) + GetSiteAdvanced(ctx context.Context) (resp *schema.SiteAdvancedResp, err error) + GetSiteQuestion(ctx context.Context) (resp *schema.SiteQuestionsResp, err error) + GetSiteTag(ctx context.Context) (resp *schema.SiteTagsResp, err error) + GetSitePolicies(ctx context.Context) (resp *schema.SitePoliciesResp, err error) + GetSiteSecurity(ctx context.Context) (resp *schema.SiteSecurityResp, err error) GetSiteLogin(ctx context.Context) (resp *schema.SiteLoginResp, err error) GetSiteCustomCssHTML(ctx context.Context) (resp *schema.SiteCustomCssHTMLResp, err error) GetSiteTheme(ctx context.Context) (resp *schema.SiteThemeResp, err error) @@ -69,7 +74,7 @@ func NewSiteInfoCommonService(siteInfoRepo SiteInfoRepo) SiteInfoCommonService { // GetSiteGeneral get site info general func (s *siteInfoCommonService) GetSiteGeneral(ctx context.Context) (resp *schema.SiteGeneralResp, err error) { - resp = &schema.SiteGeneralResp{CheckUpdate: true} + resp = &schema.SiteGeneralResp{} if err = s.GetSiteInfoByType(ctx, constant.SiteTypeGeneral, resp); err != nil { return nil, err } @@ -78,9 +83,18 @@ func (s *siteInfoCommonService) GetSiteGeneral(ctx context.Context) (resp *schem } // GetSiteInterface get site info interface -func (s *siteInfoCommonService) GetSiteInterface(ctx context.Context) (resp *schema.SiteInterfaceResp, err error) { - resp = &schema.SiteInterfaceResp{} - if err = s.GetSiteInfoByType(ctx, constant.SiteTypeInterface, resp); err != nil { +func (s *siteInfoCommonService) GetSiteInterface(ctx context.Context) (resp *schema.SiteInterfaceSettingsResp, err error) { + resp = &schema.SiteInterfaceSettingsResp{} + if err = s.GetSiteInfoByType(ctx, constant.SiteTypeInterfaceSettings, resp); err != nil { + return nil, err + } + return resp, nil +} + +// GetSiteUsersSettings get site info interface +func (s *siteInfoCommonService) GetSiteUsersSettings(ctx context.Context) (resp *schema.SiteUsersSettingsResp, err error) { + resp = &schema.SiteUsersSettingsResp{} + if err = s.GetSiteInfoByType(ctx, constant.SiteTypeUsersSettings, resp); err != nil { return nil, err } return resp, nil @@ -123,7 +137,7 @@ func (s *siteInfoCommonService) FormatListAvatar(ctx context.Context, userList [ func (s *siteInfoCommonService) getAvatarDefaultConfig(ctx context.Context) (string, string) { gravatarBaseURL, defaultAvatar := constant.DefaultGravatarBaseURL, constant.DefaultAvatar - usersConfig, err := s.GetSiteInterface(ctx) + usersConfig, err := s.GetSiteUsersSettings(ctx) if err != nil { log.Error(err) } @@ -167,10 +181,46 @@ func (s *siteInfoCommonService) GetSiteWrite(ctx context.Context) (resp *schema. return resp, nil } -// GetSiteLegal get site info write -func (s *siteInfoCommonService) GetSiteLegal(ctx context.Context) (resp *schema.SiteLegalResp, err error) { - resp = &schema.SiteLegalResp{} - if err = s.GetSiteInfoByType(ctx, constant.SiteTypeLegal, resp); err != nil { +// GetSiteAdvanced get site info advanced +func (s *siteInfoCommonService) GetSiteAdvanced(ctx context.Context) (resp *schema.SiteAdvancedResp, err error) { + resp = &schema.SiteAdvancedResp{} + if err = s.GetSiteInfoByType(ctx, constant.SiteTypeAdvanced, resp); err != nil { + return nil, err + } + return resp, nil +} + +// GetSiteQuestion get site info question +func (s *siteInfoCommonService) GetSiteQuestion(ctx context.Context) (resp *schema.SiteQuestionsResp, err error) { + resp = &schema.SiteQuestionsResp{} + if err = s.GetSiteInfoByType(ctx, constant.SiteTypeQuestions, resp); err != nil { + return nil, err + } + return resp, nil +} + +// GetSiteTag get site info tag +func (s *siteInfoCommonService) GetSiteTag(ctx context.Context) (resp *schema.SiteTagsResp, err error) { + resp = &schema.SiteTagsResp{} + if err = s.GetSiteInfoByType(ctx, constant.SiteTypeTags, resp); err != nil { + return nil, err + } + return resp, nil +} + +// GetSitePolicies get site info policies +func (s *siteInfoCommonService) GetSitePolicies(ctx context.Context) (resp *schema.SitePoliciesResp, err error) { + resp = &schema.SitePoliciesResp{} + if err = s.GetSiteInfoByType(ctx, constant.SiteTypePolicies, resp); err != nil { + return nil, err + } + return resp, nil +} + +// GetSiteSecurity get site security config +func (s *siteInfoCommonService) GetSiteSecurity(ctx context.Context) (resp *schema.SiteSecurityResp, err error) { + resp = &schema.SiteSecurityResp{CheckUpdate: true} + if err = s.GetSiteInfoByType(ctx, constant.SiteTypeSecurity, resp); err != nil { return nil, err } return resp, nil diff --git a/internal/service/tag_common/tag_common.go b/internal/service/tag_common/tag_common.go index 9ca8e100f..87b53f396 100644 --- a/internal/service/tag_common/tag_common.go +++ b/internal/service/tag_common/tag_common.go @@ -270,7 +270,7 @@ func (ts *TagCommonService) GetTagListByNames(ctx context.Context, tagNames []st } func (ts *TagCommonService) ExistRecommend(ctx context.Context, tags []*schema.TagItem) (bool, error) { - taginfo, err := ts.siteInfoService.GetSiteWrite(ctx) + taginfo, err := ts.siteInfoService.GetSiteTag(ctx) if err != nil { return false, err } @@ -295,7 +295,7 @@ func (ts *TagCommonService) ExistRecommend(ctx context.Context, tags []*schema.T } func (ts *TagCommonService) GetMinimumTags(ctx context.Context) (int, error) { - siteInfo, err := ts.siteInfoService.GetSiteWrite(ctx) + siteInfo, err := ts.siteInfoService.GetSiteQuestion(ctx) if err != nil { return 1, err } @@ -469,7 +469,7 @@ func (ts *TagCommonService) TagsFormatRecommendAndReserved(ctx context.Context, if len(tagList) == 0 { return } - tagConfig, err := ts.siteInfoService.GetSiteWrite(ctx) + tagConfig, err := ts.siteInfoService.GetSiteTag(ctx) if err != nil { log.Error(err) return @@ -485,7 +485,7 @@ func (ts *TagCommonService) tagFormatRecommendAndReserved(ctx context.Context, t if tag == nil { return } - tagConfig, err := ts.siteInfoService.GetSiteWrite(ctx) + tagConfig, err := ts.siteInfoService.GetSiteTag(ctx) if err != nil { log.Error(err) return diff --git a/internal/service/uploader/upload.go b/internal/service/uploader/upload.go index 8dea746ce..58f808468 100644 --- a/internal/service/uploader/upload.go +++ b/internal/service/uploader/upload.go @@ -109,12 +109,12 @@ func (us *uploaderService) UploadAvatarFile(ctx *gin.Context, userID string) (ur return url, nil } - siteWrite, err := us.siteInfoService.GetSiteWrite(ctx) + siteAdvanced, err := us.siteInfoService.GetSiteAdvanced(ctx) if err != nil { return "", err } - ctx.Request.Body = http.MaxBytesReader(ctx.Writer, ctx.Request.Body, siteWrite.GetMaxImageSize()) + ctx.Request.Body = http.MaxBytesReader(ctx.Writer, ctx.Request.Body, siteAdvanced.GetMaxImageSize()) file, fileHeader, err := ctx.Request.FormFile("file") if err != nil { return "", errors.BadRequest(reason.RequestFormatError).WithError(err) @@ -201,12 +201,12 @@ func (us *uploaderService) UploadPostFile(ctx *gin.Context, userID string) ( return url, nil } - siteWrite, err := us.siteInfoService.GetSiteWrite(ctx) + siteAdvanced, err := us.siteInfoService.GetSiteAdvanced(ctx) if err != nil { return "", err } - ctx.Request.Body = http.MaxBytesReader(ctx.Writer, ctx.Request.Body, siteWrite.GetMaxImageSize()) + ctx.Request.Body = http.MaxBytesReader(ctx.Writer, ctx.Request.Body, siteAdvanced.GetMaxImageSize()) file, fileHeader, err := ctx.Request.FormFile("file") if err != nil { return "", errors.BadRequest(reason.RequestFormatError).WithError(err) @@ -214,7 +214,7 @@ func (us *uploaderService) UploadPostFile(ctx *gin.Context, userID string) ( defer func() { _ = file.Close() }() - if checker.IsUnAuthorizedExtension(fileHeader.Filename, siteWrite.AuthorizedImageExtensions) { + if checker.IsUnAuthorizedExtension(fileHeader.Filename, siteAdvanced.AuthorizedImageExtensions) { return "", errors.BadRequest(reason.RequestFormatError).WithError(err) } @@ -239,7 +239,7 @@ func (us *uploaderService) UploadPostAttachment(ctx *gin.Context, userID string) return url, nil } - resp, err := us.siteInfoService.GetSiteWrite(ctx) + resp, err := us.siteInfoService.GetSiteAdvanced(ctx) if err != nil { return "", err } @@ -277,12 +277,12 @@ func (us *uploaderService) UploadBrandingFile(ctx *gin.Context, userID string) ( return url, nil } - siteWrite, err := us.siteInfoService.GetSiteWrite(ctx) + siteAdvanced, err := us.siteInfoService.GetSiteAdvanced(ctx) if err != nil { return "", err } - ctx.Request.Body = http.MaxBytesReader(ctx.Writer, ctx.Request.Body, siteWrite.GetMaxImageSize()) + ctx.Request.Body = http.MaxBytesReader(ctx.Writer, ctx.Request.Body, siteAdvanced.GetMaxImageSize()) file, fileHeader, err := ctx.Request.FormFile("file") if err != nil { return "", errors.BadRequest(reason.RequestFormatError).WithError(err) @@ -311,7 +311,7 @@ func (us *uploaderService) uploadImageFile(ctx *gin.Context, file *multipart.Fil if err != nil { return "", err } - siteWrite, err := us.siteInfoService.GetSiteWrite(ctx) + siteAdvanced, err := us.siteInfoService.GetSiteAdvanced(ctx) if err != nil { return "", err } @@ -328,7 +328,7 @@ func (us *uploaderService) uploadImageFile(ctx *gin.Context, file *multipart.Fil _ = src.Close() }() - if !checker.DecodeAndCheckImageFile(filePath, siteWrite.GetMaxImageMegapixel()) { + if !checker.DecodeAndCheckImageFile(filePath, siteAdvanced.GetMaxImageMegapixel()) { return "", errors.BadRequest(reason.UploadFileUnsupportedFileFormat) } @@ -364,17 +364,17 @@ func (us *uploaderService) uploadAttachmentFile(ctx *gin.Context, file *multipar func (us *uploaderService) tryToUploadByPlugin(ctx *gin.Context, source plugin.UploadSource) ( url string, err error) { - siteWrite, err := us.siteInfoService.GetSiteWrite(ctx) + siteAdvanced, err := us.siteInfoService.GetSiteAdvanced(ctx) if err != nil { return "", err } cond := plugin.UploadFileCondition{ Source: source, - MaxImageSize: siteWrite.MaxImageSize, - MaxAttachmentSize: siteWrite.MaxAttachmentSize, - MaxImageMegapixel: siteWrite.MaxImageMegapixel, - AuthorizedImageExtensions: siteWrite.AuthorizedImageExtensions, - AuthorizedAttachmentExtensions: siteWrite.AuthorizedAttachmentExtensions, + MaxImageSize: siteAdvanced.MaxImageSize, + MaxAttachmentSize: siteAdvanced.MaxAttachmentSize, + MaxImageMegapixel: siteAdvanced.MaxImageMegapixel, + AuthorizedImageExtensions: siteAdvanced.AuthorizedImageExtensions, + AuthorizedAttachmentExtensions: siteAdvanced.AuthorizedAttachmentExtensions, } _ = plugin.CallStorage(func(fn plugin.Storage) error { resp := fn.UploadFile(ctx, cond)