fix(wiki): clear stale citation chunks on deletion

This commit is contained in:
langcaiye
2026-06-11 19:29:29 +08:00
committed by lyingbug
parent 903b014992
commit a0786b6fe7
4 changed files with 85 additions and 29 deletions
+3 -1
View File
@@ -3,6 +3,7 @@ package middleware
import (
"context"
stderrors "errors"
"strings"
apprepo "github.com/Tencent/WeKnora/internal/application/repository"
"github.com/Tencent/WeKnora/internal/config"
@@ -190,7 +191,8 @@ func KBIDFromChunkIDParam(param string, chunkService ChunkLookup) KBIDResolver {
// before this refactor is useful.
func isResourceNotFound(err error) bool {
return stderrors.Is(err, apprepo.ErrKnowledgeBaseNotFound) ||
stderrors.Is(err, ErrResourceNotFound)
stderrors.Is(err, ErrResourceNotFound) ||
strings.TrimSpace(err.Error()) == "chunk not found"
}
// RequireKBAccess returns a gin.HandlerFunc that resolves KB access
+4
View File
@@ -245,6 +245,10 @@ func TestRequireKBAccess_NotFound_Aborts(t *testing.T) {
require.False(t, ok, "no access should be stashed on failure")
}
func TestIsResourceNotFound_ChunkNotFound(t *testing.T) {
require.True(t, isResourceNotFound(errors.New("chunk not found")))
}
func TestRequireKBAccess_SharedKB_RewritesTenantContext(t *testing.T) {
share := &stubKBShareForGuard{
permission: map[string]types.OrgMemberRole{"kb-shared": types.OrgRoleEditor},