区域配置入口改为区域统计,五列表按当前通讯录整支人员去重;调岗依当前归属、零分母未知、最近真实提问时间和父行收起不重算。仅读治理正式总表,后台单并发/请求合并/60秒缓存,目录与配置版本隔离,客户端失败不伪零。 保留区域自定义目录与预览/双版本锁保存,父部门勾选联选全后代,取消子支清除祖先整支选择,避免隐式覆盖未选子级;允许删除无引用区域,已有引用不静默孤立。统计页与设置共享选择,统计支持累计与北京时间自然月;不新增迁移,不改DobotAI生产、代理、原问答、历史趋势或已有AI任务。 验证已执行:完整make verify退出0,705 Go/340前端通过、120项声明的可选集成跳过且必需0跳过;镜像全量隔离PG race退出0;新增去重/调岗/空分母、后台缓存/并发、HTTP授权/严格请求、真PG目录与配置失效、树选择/收起、五列与删除保护均先红后绿。旧导航测试按新名称更新后全量通过。上线前治理库备份与真实恢复72表/29张QA内容哈希一致,匹配独立主密钥受限备份。 当前尚待精确SHA CI、同镜像真实数据浏览器与正式读回,不把源码验证称为已上线。公司真实区域映射不在本轮擅改;只在隔离库验证保存。
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
package httpapi
|
||||
|
||||
import (
|
||||
"context"
|
||||
"knowledge-governance/internal/dobotaiops"
|
||||
"knowledge-governance/internal/qaopsmirror"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
type departmentStatisticsReader interface {
|
||||
ReadDepartmentStatistics(context.Context, qaopsmirror.DepartmentStatisticsQuery, time.Time) (qaopsmirror.DepartmentStatisticsResult, error)
|
||||
}
|
||||
|
||||
func qaDepartmentStatistics(w http.ResponseWriter, r *http.Request, c Config) {
|
||||
if !authorizeQAOps(w, r) || !authorizeQAIntent(w, r, "qa-department-statistics") {
|
||||
return
|
||||
}
|
||||
var q qaopsmirror.DepartmentStatisticsQuery
|
||||
if r.URL.RawQuery != "" || decodeQualityJSON(w, r, &q, "period") != nil {
|
||||
qaOpsError(w, dobotaiops.ErrInvalidQuery)
|
||||
return
|
||||
}
|
||||
now := c.Now()
|
||||
if _, _, e := q.Bounds(now); e != nil {
|
||||
qaOpsError(w, e)
|
||||
return
|
||||
}
|
||||
reader, ok := c.QAOps.(departmentStatisticsReader)
|
||||
if !ok || c.QAOpsTenantKey == "" {
|
||||
qaOpsError(w, dobotaiops.ErrUnavailable)
|
||||
return
|
||||
}
|
||||
data, e := reader.ReadDepartmentStatistics(r.Context(), q, now)
|
||||
if e != nil {
|
||||
qaOpsError(w, e)
|
||||
return
|
||||
}
|
||||
status := http.StatusOK
|
||||
if data.State == "pending" {
|
||||
status = http.StatusAccepted
|
||||
w.Header().Set("Retry-After", "1")
|
||||
}
|
||||
writeJSON(w, status, map[string]any{"data": data})
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package httpapi
|
||||
|
||||
import (
|
||||
"context"
|
||||
"knowledge-governance/internal/qaopsmirror"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
type departmentStatisticsFixture struct {
|
||||
masterFixtureReader
|
||||
reads int
|
||||
}
|
||||
|
||||
func (f *departmentStatisticsFixture) ReadDepartmentStatistics(context.Context, qaopsmirror.DepartmentStatisticsQuery, time.Time) (qaopsmirror.DepartmentStatisticsResult, error) {
|
||||
f.reads++
|
||||
return qaopsmirror.DepartmentStatisticsResult{State: "pending", RetryAfter: 1}, nil
|
||||
}
|
||||
func TestDepartmentStatisticsRouteIsAsynchronousStrictAndAdminOnly(t *testing.T) {
|
||||
auth := newFakeAuthStore()
|
||||
auth.sessions["dept-fixture-admin"] = "usr-boss"
|
||||
auth.sessions["dept-fixture-viewer"] = "usr-eye"
|
||||
reader := &departmentStatisticsFixture{}
|
||||
h, e := NewHandler(Config{Store: &fakeJobStore{}, Auth: &AuthConfig{Store: auth}, QAOps: reader, QAOpsTenantKey: "fixture-tenant", Now: func() time.Time { return time.Date(2026, 10, 19, 0, 0, 0, 0, time.UTC) }})
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
for _, c := range []struct {
|
||||
body, token, intent, site string
|
||||
want int
|
||||
}{
|
||||
{`{"period":"all"}`, "dept-fixture-admin", "qa-department-statistics", "", 202},
|
||||
{`{"period":"month","month":"2026-10"}`, "dept-fixture-admin", "qa-department-statistics", "same-origin", 202},
|
||||
{`{"period":"all"}`, "", "qa-department-statistics", "", 401},
|
||||
{`{"period":"all"}`, "dept-fixture-viewer", "qa-department-statistics", "", 403},
|
||||
{`{"period":"all"}`, "dept-fixture-admin", "", "", 403},
|
||||
{`{"period":"all"}`, "dept-fixture-admin", "qa-department-statistics", "cross-site", 403},
|
||||
{`{"period":"all","tenant":"other"}`, "dept-fixture-admin", "qa-department-statistics", "", 400},
|
||||
{`{"period":"all","period":"all"}`, "dept-fixture-admin", "qa-department-statistics", "", 400},
|
||||
{`null`, "dept-fixture-admin", "qa-department-statistics", "", 400},
|
||||
{`{"period":"month","month":"2027-01"}`, "dept-fixture-admin", "qa-department-statistics", "", 400},
|
||||
{`{"period":"all","month":"2026-10"}`, "dept-fixture-admin", "qa-department-statistics", "", 400},
|
||||
} {
|
||||
r := httptest.NewRequest("POST", "/api/v1/qa-ops/departments/statistics", strings.NewReader(c.body))
|
||||
if c.token != "" {
|
||||
r.AddCookie(&http.Cookie{Name: sessionCookieName, Value: c.token})
|
||||
}
|
||||
if c.intent != "" {
|
||||
r.Header.Set("X-Governance-Action", c.intent)
|
||||
}
|
||||
if c.site != "" {
|
||||
r.Header.Set("Sec-Fetch-Site", c.site)
|
||||
}
|
||||
w := httptest.NewRecorder()
|
||||
h.ServeHTTP(w, r)
|
||||
if w.Code != c.want {
|
||||
t.Fatalf("department statistics got %d want %d", w.Code, c.want)
|
||||
}
|
||||
if w.Header().Get("Cache-Control") != "no-store" {
|
||||
t.Fatal("employee department stats became publicly cacheable")
|
||||
}
|
||||
}
|
||||
if reader.reads != 2 {
|
||||
t.Fatal("malformed or unauthorized request reached aggregation", reader.reads)
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
|
||||
func masterNoStore(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if strings.HasPrefix(r.URL.Path, "/api/v1/qa-ops/master/") {
|
||||
if strings.HasPrefix(r.URL.Path, "/api/v1/qa-ops/master/") || strings.HasPrefix(r.URL.Path, "/api/v1/qa-ops/departments/") {
|
||||
w.Header().Set("Cache-Control", "no-store")
|
||||
w.Header().Set("Pragma", "no-cache")
|
||||
}
|
||||
|
||||
@@ -181,6 +181,7 @@ func NewHandler(config Config) (http.Handler, error) {
|
||||
}
|
||||
mux := http.NewServeMux()
|
||||
registerQAAIRoutes(mux, config)
|
||||
mux.HandleFunc("POST /api/v1/qa-ops/departments/statistics", func(w http.ResponseWriter, r *http.Request) { qaDepartmentStatistics(w, r, config) })
|
||||
mux.HandleFunc("POST /api/v1/qa-ops/dashboard", func(w http.ResponseWriter, r *http.Request) { qaOperationsDashboard(w, r, config) })
|
||||
mux.HandleFunc("POST /api/v1/qa-ops/quality/query", func(w http.ResponseWriter, r *http.Request) { qaQualityQuery(w, r, config) })
|
||||
mux.HandleFunc("POST /api/v1/qa-ops/records/{id}/reviews", func(w http.ResponseWriter, r *http.Request) { qaQualityReview(w, r, config) })
|
||||
|
||||
Reference in New Issue
Block a user