A Q&A platform software for teams at any scales. Whether it's a community forum, help center, or knowledge management platform, you can always count on Apache Answer.
feat: support setting config for check latest answer version
hgaol2a828c93c103
diff --git a/i18n/en_US.yaml b/i18n/en_US.yamlindex 484d62d1..18312e5e 100644--- a/i18n/en_US.yaml+++ b/i18n/en_US.yaml@@ -1595,6 +1595,9 @@ ui:msg: Contact email cannot be empty.validate: Contact email is not valid.text: Email address of key contact responsible for this site.+ check_update:+ label: Software updates+ text: Automatically check for updatesinterface:page_title: Interfacelanguage:diff --git a/i18n/zh_CN.yaml b/i18n/zh_CN.yamlindex f204860a..01bc07b9 100644--- a/i18n/zh_CN.yaml+++ b/i18n/zh_CN.yaml@@ -1550,6 +1550,9 @@ ui:msg: 联系人邮箱不能为空。validate: 联系人邮箱无效。text: 本网站的主要联系邮箱地址。+ check_update:+ label: 软件更新+ text: 自动检查软件更新interface:page_title: 界面language:diff --git a/internal/schema/siteinfo_schema.go b/internal/schema/siteinfo_schema.goindex 2953b944..ea19d046 100644--- a/internal/schema/siteinfo_schema.go+++ b/internal/schema/siteinfo_schema.go@@ -40,6 +40,7 @@ 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() {diff --git a/internal/service/dashboard/dashboard_service.go b/internal/service/dashboard/dashboard_service.goindex c9b6efe1..0d36cd6a 100644--- a/internal/service/dashboard/dashboard_service.go+++ b/internal/service/dashboard/dashboard_service.go@@ -23,11 +23,12 @@ import ("context""encoding/json""fmt"- "github.com/apache/incubator-answer/pkg/converter""io""net/http""net/url""time"++ "github.com/apache/incubator-answer/pkg/converter""xorm.io/xorm/schemas""github.com/apache/incubator-answer/internal/base/constant"@@ -101,7 +102,14 @@ func (ds *dashboardService) Statistical(ctx context.Context) (*schema.DashboardIdashboardInfo.ReportCount = ds.reportCount(ctx)dashboardInfo.VoteCount = ds.voteCount(ctx)dashboardInfo.OccupyingStorageSpace = ds.calculateStorage()- dashboardInfo.VersionInfo.RemoteVersion = ds.remoteVersion(ctx)+ general, err := ds.siteInfoService.GetSiteGeneral(ctx)+ if err != nil {+ log.Errorf("get general site info failed: %s", err)+ return dashboardInfo, nil+ }+ if general.CheckUpdate {+ dashboardInfo.VersionInfo.RemoteVersion = ds.remoteVersion(ctx)+ }dashboardInfo.DatabaseVersion = ds.getDatabaseInfo()dashboardInfo.DatabaseSize = ds.GetDatabaseSize()}diff --git a/internal/service/siteinfo_common/siteinfo_service.go b/internal/service/siteinfo_common/siteinfo_service.goindex e37fb7b1..2036ec6e 100644--- a/internal/service/siteinfo_common/siteinfo_service.go+++ b/internal/service/siteinfo_common/siteinfo_service.go@@ -66,7 +66,7 @@ func NewSiteInfoCommonService(siteInfoRepo SiteInfoRepo) SiteInfoCommonService {// GetSiteGeneral get site info generalfunc (s *siteInfoCommonService) GetSiteGeneral(ctx context.Context) (resp *schema.SiteGeneralResp, err error) {- resp = &schema.SiteGeneralResp{}+ resp = &schema.SiteGeneralResp{CheckUpdate: true}if err = s.GetSiteInfoByType(ctx, constant.SiteTypeGeneral, resp); err != nil {return nil, err}diff --git a/ui/src/common/interface.ts b/ui/src/common/interface.tsindex 71b14080..65117ae1 100644--- a/ui/src/common/interface.ts+++ b/ui/src/common/interface.ts@@ -347,6 +347,8 @@ export interface AdminSettingsGeneral {description: string;site_url: string;contact_email: string;+ check_update: boolean;+ permalink?: number;}export interface HelmetBase {diff --git a/ui/src/pages/Admin/Dashboard/components/HealthStatus/index.tsx b/ui/src/pages/Admin/Dashboard/components/HealthStatus/index.tsxindex c77f0bb1..64122669 100644--- a/ui/src/pages/Admin/Dashboard/components/HealthStatus/index.tsx+++ b/ui/src/pages/Admin/Dashboard/components/HealthStatus/index.tsx@@ -23,6 +23,7 @@ import { useTranslation } from 'react-i18next';import { Link } from 'react-router-dom';import type * as Type from '@/common/interface';+import { siteInfoStore } from '@/stores';const { gt, gte } = require('semver');@@ -33,6 +34,7 @@ interface IProps {const HealthStatus: FC<IProps> = ({ data }) => {const { t } = useTranslation('translation', { keyPrefix: 'admin.dashboard' });const { version, remote_version } = data.version_info || {};+ const { siteInfo } = siteInfoStore();let isLatest = false;let hasNewerVersion = false;if (version && remote_version) {@@ -65,7 +67,7 @@ const HealthStatus: FC<IProps> = ({ data }) => {{t('update_to')} {remote_version}</a>)}- {!isLatest && !remote_version && (+ {!isLatest && !remote_version && siteInfo.check_update && (<aclassName="ms-1 badge rounded-pill text-bg-danger"target="_blank"diff --git a/ui/src/pages/Admin/General/index.tsx b/ui/src/pages/Admin/General/index.tsxindex 158236a5..3b4d4ef3 100644--- a/ui/src/pages/Admin/General/index.tsx+++ b/ui/src/pages/Admin/General/index.tsx@@ -69,6 +69,10 @@ const General: FC = () => {title: t('contact_email.label'),description: t('contact_email.text'),},+ check_update: {+ type: 'boolean',+ title: t('check_update.label'),+ },},};const uiSchema: UISchema = {@@ -107,6 +111,12 @@ const General: FC = () => {},},},+ check_update: {+ 'ui:widget': 'switch',+ 'ui:options': {+ label: t('check_update.text'),+ },+ },};const [formData, setFormData] = useState<Type.FormDataType>(initFormData(schema),@@ -121,6 +131,7 @@ const General: FC = () => {short_description: formData.short_description.value,site_url: formData.site_url.value,contact_email: formData.contact_email.value,+ check_update: formData.check_update.value,};updateGeneralSetting(reqParams)@@ -135,6 +146,7 @@ const General: FC = () => {formData.short_description.value = res.short_description;formData.site_url.value = res.site_url;formData.contact_email.value = res.contact_email;+ formData.check_update.value = res.check_update;}setFormData({ ...formData });@@ -156,10 +168,12 @@ const General: FC = () => {Object.keys(formData).forEach((k) => {formMeta[k] = { ...formData[k], value: setting[k] };});+ console.log(formMeta);setFormData({ ...formData, ...formMeta });}, [setting]);const handleOnChange = (data) => {+ console.table(data);setFormData(data);};diff --git a/ui/src/stores/siteInfo.ts b/ui/src/stores/siteInfo.tsindex 69469d2a..b7f31406 100644--- a/ui/src/stores/siteInfo.ts+++ b/ui/src/stores/siteInfo.ts@@ -50,6 +50,7 @@ const siteInfo = create<SiteInfoType>((set) => ({short_description: '',site_url: '',contact_email: '',+ check_update: true,permalink: 1,},users: defaultUsersConf,