fix(model):项目权限设置非全部时报错
This commit is contained in:
1 parent
e6a67e0af7
commit
2187bab22f
3 files changed
+19
-6
No files matched your search
@@ -25,13 +25,13 @@ func CheckScope(scope string, relayMode string) bool {
|
||||
case ScopeReadOnly:
|
||||
// read_only 仅允许 GET /models
|
||||
return relayMode == ""
|
||||
case ScopeChatOnly:
|
||||
case ScopeChatOnly, "chat":
|
||||
return relayMode == "chat_completions" || relayMode == "completions" || relayMode == "claude_messages"
|
||||
case ScopeEmbeddingsOnly:
|
||||
case ScopeEmbeddingsOnly, "embedding":
|
||||
return relayMode == "embeddings"
|
||||
case ScopeImagesOnly:
|
||||
case ScopeImagesOnly, "image":
|
||||
return relayMode == "images_generations"
|
||||
case ScopeAudioOnly:
|
||||
case ScopeAudioOnly, "audio":
|
||||
return relayMode == "audio" || relayMode == "tts" || relayMode == "stt"
|
||||
default:
|
||||
// custom scope: 以逗号分隔的模式列表
|
||||
|
||||
@@ -27,6 +27,18 @@ func TestCheckScope(t *testing.T) {
|
||||
{"read_only allows empty mode (models GET)", ScopeReadOnly, "", true},
|
||||
{"audio_only allows audio", ScopeAudioOnly, "audio", true},
|
||||
{"audio_only denies chat", ScopeAudioOnly, "chat_completions", false},
|
||||
// short alias scope names (sent by frontend)
|
||||
{"chat alias allows chat_completions", "chat", "chat_completions", true},
|
||||
{"chat alias allows completions", "chat", "completions", true},
|
||||
{"chat alias allows claude_messages", "chat", "claude_messages", true},
|
||||
{"chat alias denies embeddings", "chat", "embeddings", false},
|
||||
{"embedding alias allows embeddings", "embedding", "embeddings", true},
|
||||
{"embedding alias denies chat", "embedding", "chat_completions", false},
|
||||
{"image alias allows images_generations", "image", "images_generations", true},
|
||||
{"image alias denies chat", "image", "chat_completions", false},
|
||||
{"audio alias allows audio", "audio", "audio", true},
|
||||
{"audio alias allows tts", "audio", "tts", true},
|
||||
{"audio alias denies chat", "audio", "chat_completions", false},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
|
||||
@@ -402,7 +402,8 @@ func (p *DataProviderImpl) RecordAudit(ctx context.Context, record *common.Audit
|
||||
tntReq, tntResp = truncateBody(tntReq, maxBodyLen), truncateBody(tntResp, maxBodyLen)
|
||||
|
||||
// 仅审计级别为 all 时记录请求头和响应头
|
||||
var requestHeadersJSON, responseHeadersJSON string
|
||||
requestHeadersJSON := "null"
|
||||
responseHeadersJSON := "null"
|
||||
if globalLevel == lcommon.AuditLevelFull {
|
||||
if record.RequestHeaders != nil {
|
||||
b, _ := json.Marshal(record.RequestHeaders)
|
||||
@@ -415,7 +416,7 @@ func (p *DataProviderImpl) RecordAudit(ctx context.Context, record *common.Audit
|
||||
}
|
||||
|
||||
// 序列化转发路径追踪
|
||||
var forwardingTraceJSON string
|
||||
forwardingTraceJSON := "null"
|
||||
if record.ForwardingTrace != nil {
|
||||
if b, err := json.Marshal(record.ForwardingTrace); err == nil {
|
||||
forwardingTraceJSON = string(b)
|
||||
|
||||
Reference in new issue
Block a user