fix:移除设置中的演示模式,改为配置文件配置

This commit is contained in:
chengqian committed 2026-06-09 11:28:08 +08:00
1 parent 026d1158c1
commit b4c815ec9d
6 files changed
+25 -25

No files matched your search

@@ -67,10 +67,6 @@ var Registry = []SettingDef{
Label: "预计维护时长", Description: "维护模式预计持续时间,展示给用户", IsPublic: true},
{Key: "api_maintenance_enabled", Type: SettingTypeBool, Default: "false", Category: "general",
Label: "全局 API 维护", Description: "开启后 API 代理返回 503,叠加维护模式使用", IsPublic: true},
{Key: "demo_mode", Type: SettingTypeBool, Default: "false", Category: "general",
Label: "演示模式", Description: "开启后所有写操作被拦截,仅允许只读访问", IsPublic: true},
{Key: "demo_message", Type: SettingTypeString, Default: "演示环境,数据不可修改", Category: "general",
Label: "演示模式提示", Description: "演示模式下返回给用户的提示信息", IsPublic: true},
{Key: "tenant_console_url", Type: SettingTypeString, Default: "", Category: "general",
Label: "租户控制台地址", Description: "租户控制台的完整 URL,如 https://console.example.com,用于生成邀请链接等"},
+9
View File
@@ -3,6 +3,7 @@ package settings
import (
"context"
"github.com/gogf/gf/v2/frame/g"
"github.com/qianfree/team-api/internal/dao"
"github.com/qianfree/team-api/internal/logic/common"
"github.com/qianfree/team-api/internal/service"
@@ -42,6 +43,14 @@ func (s *sSettings) PublicSettingsGet(ctx context.Context, _ *v1.PublicSettingsG
}
}
// Inject demo mode from config file (not database — avoids the self-lock bug)
settings["demo_mode"] = g.Cfg().MustGet(ctx, "demo.enabled").Bool()
demoMsg := g.Cfg().MustGet(ctx, "demo.message").String()
if demoMsg == "" {
demoMsg = "演示环境,数据不可修改"
}
settings["demo_message"] = demoMsg
return &v1.PublicSettingsGetRes{Settings: settings}, nil
}
+4 -3
View File
@@ -3,10 +3,10 @@ package middleware
import (
"strings"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/net/ghttp"
"github.com/qianfree/team-api/internal/consts"
"github.com/qianfree/team-api/internal/logic/common"
"github.com/qianfree/team-api/internal/response"
)
@@ -21,10 +21,11 @@ var demoWhitelistPaths = map[string]bool{
}
// DemoMode blocks all write operations when demo mode is enabled.
// Controlled via config file: demo.enabled = true.
// Read-only requests (GET/HEAD/OPTIONS) and whitelisted paths are allowed.
func DemoMode(r *ghttp.Request) {
ctx := r.Context()
if !common.Config().GetBool(ctx, "demo_mode") {
if !g.Cfg().MustGet(ctx, "demo.enabled").Bool() {
r.Middleware.Next()
return
}
@@ -50,7 +51,7 @@ func DemoMode(r *ghttp.Request) {
return
}
message := common.Config().GetString(ctx, "demo_message")
message := g.Cfg().MustGet(ctx, "demo.message").String()
if message == "" {
message = consts.MsgDemoModeRestricted
}
+6
View File
@@ -65,5 +65,11 @@ email:
password: ""
from: ""
# Demo mode (read-only mode, configured here — not in admin UI)
# Set enabled: true to block all write operations and show a watermark
demo:
enabled: false
message: "演示环境,数据不可修改"
# Channel proxy (for accessing Google/Anthropic etc. from China)
channel_proxy_url: ""
+6
View File
@@ -81,3 +81,9 @@ email:
username: ""
password: ""
from: ""
# 演示模式(通过配置文件控制,不在管理后台设置)
# 开启后所有写操作被拦截,仅允许只读访问,并在控制台显示水印
demo:
enabled: false
message: "演示环境,数据不可修改"
@@ -42,24 +42,6 @@ const values = useFormValues()
</div>
</div>
<!-- 演示模式 -->
<div class="section">
<div class="section-title">演示模式</div>
<div class="switch-row">
<span class="switch-label">启用演示模式</span>
<span class="switch-desc">开启后所有写操作被拦截,仅允许只读访问</span>
<ASwitch
:model-value="values['demo_mode'] === 'true' || values['demo_mode'] === '1'"
@change="(v: string | number | boolean) => values['demo_mode'] = String(v)"
/>
</div>
<div class="section-grid" style="margin-top: 12px">
<AFormItem label="演示模式提示">
<AInput v-model="values['demo_message']" placeholder="演示环境,数据不可修改" />
</AFormItem>
</div>
</div>
<!-- 维护模式 -->
<div class="section">
<div class="section-title">维护模式</div>