feat(models): let system admins edit builtin model config

Allow platform system administrators to update builtin model parameters
and credentials from the management UI while keeping secrets masked in API
responses. UI edits clear YAML ownership so startup reconciliation no
longer overwrites runtime overrides.
This commit is contained in:
wizardchen
2026-07-14 15:51:32 +08:00
committed by lyingbug
parent f409bd756b
commit e1572b71b9
20 changed files with 328 additions and 35 deletions
+28
View File
@@ -10,6 +10,7 @@ import (
"github.com/Tencent/WeKnora/internal/config"
"github.com/Tencent/WeKnora/internal/types"
"github.com/gin-gonic/gin"
"github.com/stretchr/testify/assert"
)
// rbacTestHarness builds a tiny gin engine with the RBAC middleware in
@@ -80,6 +81,33 @@ func TestRequireRole_RejectsBelowMin(t *testing.T) {
}
}
func TestRequireRoleOrSystemAdmin_AllowsSystemAdminBelowTenantRole(t *testing.T) {
gin.SetMode(gin.TestMode)
router := gin.New()
router.Use(func(c *gin.Context) {
ctx := context.WithValue(c.Request.Context(), types.TenantRoleContextKey, types.TenantRoleViewer)
ctx = context.WithValue(ctx, types.SystemAdminContextKey, true)
c.Request = c.Request.WithContext(ctx)
c.Next()
})
router.GET("/protected",
RequireRoleOrSystemAdmin(types.TenantRoleAdmin, cfgRBAC(true)),
func(c *gin.Context) { c.Status(http.StatusOK) },
)
w := httptest.NewRecorder()
router.ServeHTTP(w, httptest.NewRequest(http.MethodGet, "/protected", nil))
assert.Equal(t, http.StatusOK, w.Code)
}
func TestRequireRoleOrSystemAdmin_RejectsOrdinaryViewer(t *testing.T) {
w := rbacTestHarness(types.TenantRoleViewer, "u1",
RequireRoleOrSystemAdmin(types.TenantRoleAdmin, cfgRBAC(true)))
if w.Code != http.StatusForbidden {
t.Fatalf("ordinary Viewer must not clear Admin-or-SystemAdmin gate, got %d", w.Code)
}
}
func TestRequireRole_FailOpenWhenRBACDisabled(t *testing.T) {
// EnableRBAC=false: the middleware should log but not block, so the
// downstream handler still runs. This is the rollout-safety guarantee.