Commit 11fe848
authored
fix(knowledge): list knowledge bases on the same authority that creates them (#6770)
* fix(knowledge): list a workspace's bases on the same authority that creates them
GET /api/knowledge authorizes the session against the canonical workspace and
then re-derives access inside the row query from a `permissions` join. Those two
no longer agree: workspace `admin` can come from an organization role alone, with
no workspace permission row behind it. Such a caller passes authorization, creates
a knowledge base, and then sees an empty list forever — the row is filtered out by
the join. Tables and files carry no equivalent join, which is why only knowledge
is affected.
Read the workspace's own rows through `getWorkspaceKnowledgeBases` once the
operation is authorized. The caller-scoped query stays only on the path with no
workspace to authorize against.
* refactor(knowledge): stop re-deriving workspace access inside the list query
The module resolves workspace authority one way everywhere — an explicit
permission row OR an organization admin role — except in the listing query,
which joined `permissions` and required a row. Both list surfaces authorized the
caller and then contradicted that authorization: an org admin could create a
knowledge base through /api/knowledge or /api/v1/knowledge and never see it
listed. Tables and files carry no such join.
Replace the caller-scoped query with `getLegacyPersonalKnowledgeBases`, which
answers only for workspace-less bases whose creator IS their only authority, and
have both surfaces read the workspace's own rows through
`getWorkspaceKnowledgeBases` after authorizing. The legacy rows keep riding along
so they stay reachable. The permissions join now appears nowhere in the module,
and the duplicated connector projection collapses onto the shared helper that
enforces the row cap.
* refactor(knowledge): clean up the module's client layer and fix two state bugs
Cleanup pass over the knowledge module — effects, state, memo, callback, React
Query, url-state, emcn, and comments — keeping the fixes that change behavior for
the better and leaving the ones that would change how the UI feels.
Bugs found and fixed:
- Opening a document flashed "Document not ready" for a frame. The chunk-row
builder rendered the loading state as a status claim: with no document loaded
yet it fell through to the branch that reports a missing processing status.
- A partial upload failure skipped every cache invalidation, because the throw
jumped past them, so the list stayed missing rows the server had already
created. Admission failures create nothing and still skip the refetch.
- The document and chunk context menus captured the row they opened on, so the
Enable/Disable label went stale under the list's own polling. They hold an id
and resolve against live data now.
- The action bar's "Select all"/"Clear" links were painted with `--brand-primary`,
which is defined nowhere: the links fell back to `currentColor` and were
indistinguishable from the text beside them.
Consistency and weight:
- Mutations no longer invalidate `detail` non-exactly for writes that touch one
document: that key is the parent of every documents page, chunk page, tag
definition, and connector row cached for the base.
- Dead hook surface removed (five exports with no consumer, a query instantiated
only to reach a cache helper, a `goToPage` that only range-checked), unused
parameters dropped, `getErrorMessage` replacing hand-rolled instanceof checks.
- `page` joins the document list's param group, so a search resets pagination in
the same debounced write instead of writing the URL on every keystroke.
- Icons import from `@sim/emcn/icons`, the action bar composes
`chipFilledFillTokens` instead of restating it three times, chunk cells use the
canonical content-label chrome, and the icon-only buttons have accessible names.
* refactor(knowledge): one row reader, one visible-list composition
Follow-up from the quality pass. The two list queries had grown into near-copies
of each other — same 14-column projection, same document join, same cap check,
same row mapping — and the workspace-plus-legacy composition was pasted into both
the internal use case and the v1 route, one of which is a surface adapter that
should not be composing domain reads at all.
Both queries now read through one private projection, so a column added to one
list cannot go missing from the other half of the same rendered list, and
`listWorkspaceAndLegacyKnowledgeBases` owns the composition both surfaces call.
That merge also projects connector types once over the merged set instead of once
per source, and skips the copy-and-sort entirely when there are no legacy rows —
the common case.
Also from the review: the chunk-row memo depends on the two primitives it reads
rather than the whole polled document object, the selected chunk resolves in one
scan instead of two, an aborted chunk-search pagination throws instead of caching
a truncated result as complete, upload cache reconciliation no longer delays the
rejected promise, the key-hierarchy rule is stated once on the key factory rather
than six times at its call sites, and `TagDefinition` has one declaration.
* fix(knowledge): refresh the document list pages after a document write
Review caught a regression in the invalidation narrowing: `documents` (the list
pages) and `document` (one row) are SIBLINGS under `detail`, not parent and
child, so scoping a write to the row key left every list rendering the filename,
status, tags, `tokenCount`, and `chunkCount` it had just changed.
The key factory now exposes a `documentLists` prefix and all six document-scoped
mutations invalidate it alongside the row — the chunk mutations included, since
every chunk write moves the parent document's `tokenCount`. `detail` stays
`exact: true` where only the base's own totals move.
Also repoints the shared list-convention test at `getWorkspaceKnowledgeBases`;
it exercised the caller-scoped query this branch removed.1 parent ad83796 commit 11fe848
37 files changed
Lines changed: 719 additions & 737 deletions
File tree
- apps/sim
- app
- api/v1/knowledge
- workspace/[workspaceId]/knowledge
- [id]
- [documentId]
- components/document-tags-modal
- components
- action-bar
- add-documents-modal
- base-tags-modal
- connector-selector-field
- connectors-section
- components
- create-base-modal
- edit-knowledge-base-modal
- hooks
- hooks
- kb
- queries
- kb
- utils
- lib
- api
- knowledge
- application
- chunks
- documents
- search
- tags
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
| 13 | + | |
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
46 | | - | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
47 | 49 | | |
48 | 50 | | |
49 | 51 | | |
| |||
Lines changed: 2 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
18 | 17 | | |
| 18 | + | |
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| |||
378 | 378 | | |
379 | 379 | | |
380 | 380 | | |
381 | | - | |
382 | | - | |
383 | | - | |
384 | | - | |
385 | | - | |
| 381 | + | |
386 | 382 | | |
387 | 383 | | |
388 | 384 | | |
| |||
Lines changed: 78 additions & 92 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
5 | | - | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
6 | 15 | | |
7 | 16 | | |
8 | 17 | | |
| |||
204 | 213 | | |
205 | 214 | | |
206 | 215 | | |
207 | | - | |
208 | 216 | | |
209 | 217 | | |
210 | 218 | | |
| |||
292 | 300 | | |
293 | 301 | | |
294 | 302 | | |
295 | | - | |
296 | | - | |
297 | | - | |
298 | | - | |
299 | | - | |
300 | | - | |
301 | | - | |
302 | | - | |
303 | | - | |
304 | | - | |
305 | | - | |
| 303 | + | |
306 | 304 | | |
307 | 305 | | |
308 | 306 | | |
309 | 307 | | |
310 | 308 | | |
311 | 309 | | |
312 | | - | |
313 | 310 | | |
314 | | - | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
315 | 319 | | |
316 | 320 | | |
317 | 321 | | |
| |||
351 | 355 | | |
352 | 356 | | |
353 | 357 | | |
354 | | - | |
355 | | - | |
356 | | - | |
357 | | - | |
358 | | - | |
359 | | - | |
360 | | - | |
361 | | - | |
362 | | - | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
363 | 362 | | |
364 | 363 | | |
365 | 364 | | |
| |||
402 | 401 | | |
403 | 402 | | |
404 | 403 | | |
405 | | - | |
| 404 | + | |
406 | 405 | | |
407 | 406 | | |
408 | 407 | | |
409 | 408 | | |
410 | | - | |
| 409 | + | |
411 | 410 | | |
412 | | - | |
| 411 | + | |
413 | 412 | | |
414 | 413 | | |
415 | 414 | | |
| |||
419 | 418 | | |
420 | 419 | | |
421 | 420 | | |
422 | | - | |
| 421 | + | |
423 | 422 | | |
424 | 423 | | |
425 | 424 | | |
| |||
646 | 645 | | |
647 | 646 | | |
648 | 647 | | |
649 | | - | |
650 | 648 | | |
651 | 649 | | |
652 | 650 | | |
| |||
681 | 679 | | |
682 | 680 | | |
683 | 681 | | |
684 | | - | |
685 | | - | |
686 | | - | |
687 | | - | |
| 682 | + | |
| 683 | + | |
688 | 684 | | |
689 | 685 | | |
690 | 686 | | |
| |||
724 | 720 | | |
725 | 721 | | |
726 | 722 | | |
727 | | - | |
| 723 | + | |
728 | 724 | | |
729 | 725 | | |
730 | 726 | | |
| |||
746 | 742 | | |
747 | 743 | | |
748 | 744 | | |
749 | | - | |
750 | | - | |
751 | | - | |
752 | | - | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
753 | 748 | | |
754 | | - | |
755 | | - | |
756 | | - | |
757 | | - | |
758 | | - | |
759 | | - | |
760 | | - | |
761 | | - | |
762 | | - | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
| 752 | + | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
763 | 756 | | |
764 | | - | |
765 | | - | |
766 | | - | |
767 | | - | |
768 | | - | |
769 | | - | |
770 | | - | |
771 | | - | |
772 | | - | |
773 | | - | |
| 757 | + | |
| 758 | + | |
| 759 | + | |
| 760 | + | |
774 | 761 | | |
775 | 762 | | |
776 | 763 | | |
| |||
780 | 767 | | |
781 | 768 | | |
782 | 769 | | |
783 | | - | |
784 | 770 | | |
785 | 771 | | |
786 | 772 | | |
| |||
863 | 849 | | |
864 | 850 | | |
865 | 851 | | |
866 | | - | |
867 | | - | |
868 | | - | |
869 | | - | |
870 | | - | |
871 | | - | |
872 | | - | |
873 | | - | |
| 852 | + | |
| 853 | + | |
| 854 | + | |
| 855 | + | |
| 856 | + | |
| 857 | + | |
874 | 858 | | |
875 | | - | |
876 | | - | |
| 859 | + | |
877 | 860 | | |
878 | 861 | | |
879 | 862 | | |
| |||
890 | 873 | | |
891 | 874 | | |
892 | 875 | | |
893 | | - | |
| 876 | + | |
894 | 877 | | |
895 | 878 | | |
896 | 879 | | |
| |||
902 | 885 | | |
903 | 886 | | |
904 | 887 | | |
905 | | - | |
906 | | - | |
907 | | - | |
908 | | - | |
909 | | - | |
910 | | - | |
911 | | - | |
| 888 | + | |
| 889 | + | |
| 890 | + | |
| 891 | + | |
912 | 892 | | |
913 | | - | |
| 893 | + | |
914 | 894 | | |
915 | | - | |
916 | | - | |
| 895 | + | |
| 896 | + | |
917 | 897 | | |
918 | 898 | | |
919 | 899 | | |
| |||
955 | 935 | | |
956 | 936 | | |
957 | 937 | | |
| 938 | + | |
| 939 | + | |
| 940 | + | |
958 | 941 | | |
| 942 | + | |
| 943 | + | |
| 944 | + | |
| 945 | + | |
| 946 | + | |
| 947 | + | |
| 948 | + | |
959 | 949 | | |
960 | 950 | | |
961 | 951 | | |
| |||
966 | 956 | | |
967 | 957 | | |
968 | 958 | | |
969 | | - | |
970 | | - | |
971 | | - | |
972 | | - | |
973 | | - | |
974 | | - | |
| 959 | + | |
| 960 | + | |
| 961 | + | |
| 962 | + | |
975 | 963 | | |
976 | 964 | | |
977 | 965 | | |
| |||
992 | 980 | | |
993 | 981 | | |
994 | 982 | | |
995 | | - | |
| 983 | + | |
996 | 984 | | |
997 | 985 | | |
998 | 986 | | |
999 | 987 | | |
1000 | 988 | | |
1001 | 989 | | |
1002 | | - | |
1003 | | - | |
1004 | | - | |
| 990 | + | |
1005 | 991 | | |
1006 | 992 | | |
1007 | 993 | | |
| |||
1017 | 1003 | | |
1018 | 1004 | | |
1019 | 1005 | | |
1020 | | - | |
| 1006 | + | |
1021 | 1007 | | |
1022 | 1008 | | |
1023 | 1009 | | |
| |||
1232 | 1218 | | |
1233 | 1219 | | |
1234 | 1220 | | |
1235 | | - | |
| 1221 | + | |
1236 | 1222 | | |
1237 | 1223 | | |
1238 | 1224 | | |
| |||
Lines changed: 1 addition & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
4 | | - | |
| 3 | + | |
5 | 4 | | |
6 | 5 | | |
7 | 6 | | |
| |||
0 commit comments