Open-source LLM knowledge platform: turn raw documents into a queryable RAG, an autonomous reasoning agent, and a self-maintaining Wiki.
Go agentagenticaichatbotdsh-pluginembeddingsevaluationgenerative-aigolangknowledge-basellmmulti-tenantollamaopenaiquestion-answeringragrerankingsemantic-searchvector-searchwiki
fix(frontend): correct optimistic organization state after review and detail loads
wizardchene0b6a7150375
diff --git a/frontend/src/stores/organization.ts b/frontend/src/stores/organization.tsindex 838926cd4..f70943522 100644--- a/frontend/src/stores/organization.ts+++ b/frontend/src/stores/organization.ts@@ -44,7 +44,12 @@ import {requestRoleUpgrade as requestRoleUpgradeApi} from '@/api/organization'import { createVersionedRequestCoordinator } from './versionedRequest'-import { applyOrganizationResourceDelta, upsertById } from './organizationState'+import {+ applyOrganizationResourceDelta,+ upsertById,+ mergeById,+ reviewMemberCountDelta+} from './organizationState'export const useOrganizationStore = defineStore('organization', () => {// State@@ -148,6 +153,19 @@ export const useOrganizationStore = defineStore('organization', () => {}}+ /**+ * Merge a detail payload (which may omit list-only aggregate fields) onto the+ * existing card instead of replacing it, so badges like share_count survive.+ */+ function mergeOrganizationDetail(organization: Organization) {+ organizationsRequest.invalidate()+ organizationsLoadedAt = 0+ const next = mergeById(organizations.value, organization)+ organizations.value = next+ currentOrganization.value =+ next.find(org => org.id === organization.id) ?? organization+ }+function adjustOrganizationResourceCount(organizationId: string,resource: 'knowledge_bases' | 'agents',@@ -685,13 +703,16 @@ export const useOrganizationStore = defineStore('organization', () => {async function reviewOrganizationJoinRequest(organizationId: string,requestId: string,- request: ReviewJoinRequestRequest+ request: ReviewJoinRequestRequest,+ options?: { requestType?: 'join' | 'upgrade' }): Promise<ApiResponse<void>> {const response = await reviewJoinRequestApi(organizationId, requestId, request)if (response.success) {const organization = organizations.value.find(org => org.id === organizationId)patchOrganization(organizationId, {- member_count: (organization?.member_count ?? 0) + (request.approved ? 1 : 0),+ member_count:+ (organization?.member_count ?? 0) ++ reviewMemberCountDelta(request.approved, options?.requestType),pending_join_request_count: Math.max(0,(organization?.pending_join_request_count ?? 0) - 1@@ -719,7 +740,7 @@ export const useOrganizationStore = defineStore('organization', () => {*/function setCurrentOrganization(org: Organization | null) {if (org) {- upsertOrganization(org)+ mergeOrganizationDetail(org)void fetchOrganizations({ force: true })} else {currentOrganization.value = nulldiff --git a/frontend/src/stores/organizationState.test.ts b/frontend/src/stores/organizationState.test.tsindex 6447d6295..0cb54fbc4 100644--- a/frontend/src/stores/organizationState.test.ts+++ b/frontend/src/stores/organizationState.test.ts@@ -2,7 +2,9 @@ import assert from 'node:assert/strict'import test from 'node:test'import {applyOrganizationResourceDelta,- upsertById+ upsertById,+ mergeById,+ reviewMemberCountDelta} from './organizationState.ts'test('upsert adds a newly joined organization to the front', () => {@@ -54,3 +56,36 @@ test('resource counts never become negative when a share is removed', () => {assert.equal(result.organizations[0].agent_share_count, 0)assert.equal(result.resourceCounts?.agents.by_organization['space-1'], 0)})++test('merge keeps list-only aggregate fields when a detail payload omits them', () => {+ const result = mergeById(+ [{ id: 'space-1', name: 'Old name', share_count: 5, agent_share_count: 2 }],+ { id: 'space-1', name: 'New name' }+ )++ assert.deepEqual(result, [+ { id: 'space-1', name: 'New name', share_count: 5, agent_share_count: 2 }+ ])+})++test('merge inserts a brand-new organization at the front', () => {+ const result = mergeById(+ [{ id: 'existing', name: 'Existing' }],+ { id: 'new', name: 'New' }+ )++ assert.deepEqual(result.map(organization => organization.id), ['new', 'existing'])+})++test('approving a new join request adds one member', () => {+ assert.equal(reviewMemberCountDelta(true, 'join'), 1)+})++test('approving a role upgrade does not change member_count', () => {+ assert.equal(reviewMemberCountDelta(true, 'upgrade'), 0)+})++test('rejecting any request does not change member_count', () => {+ assert.equal(reviewMemberCountDelta(false, 'join'), 0)+ assert.equal(reviewMemberCountDelta(false, 'upgrade'), 0)+})diff --git a/frontend/src/stores/organizationState.ts b/frontend/src/stores/organizationState.tsindex e3ee0fee0..d475db284 100644--- a/frontend/src/stores/organizationState.ts+++ b/frontend/src/stores/organizationState.ts@@ -5,6 +5,33 @@ export function upsertById<T extends { id: string }>(items: T[], item: T): T[] {: [item, ...items]}+/**+ * Merge a (possibly partial) organization payload onto the existing card.+ *+ * Detail endpoints (e.g. GET /organizations/:id) may omit list-only aggregate+ * fields such as share_count / agent_share_count / pending_join_request_count.+ * A plain replace would blank those badges until the background refresh lands,+ * so when a card already exists we shallow-merge instead of overwriting it.+ */+export function mergeById<T extends { id: string }>(items: T[], item: T): T[] {+ const existing = items.find(entry => entry.id === item.id)+ const merged = existing ? { ...existing, ...item } : item+ return upsertById(items, merged)+}++/**+ * How much a join-request review changes the organization's member_count.+ *+ * Only brand-new "join" approvals add a member. Approving an "upgrade" request+ * (an existing member asking for a higher role) must not change member_count.+ */+export function reviewMemberCountDelta(+ approved: boolean,+ requestType: 'join' | 'upgrade' | undefined+): number {+ return approved && requestType !== 'upgrade' ? 1 : 0+}+interface OrganizationResourceCounts {knowledge_bases: { by_organization: Record<string, number> }agents: { by_organization: Record<string, number> }diff --git a/frontend/src/views/organization/OrganizationSettingsModal.vue b/frontend/src/views/organization/OrganizationSettingsModal.vueindex a0a78e80e..06d50bcb0 100644--- a/frontend/src/views/organization/OrganizationSettingsModal.vue+++ b/frontend/src/views/organization/OrganizationSettingsModal.vue@@ -1447,7 +1447,8 @@ const handleApproveRequest = async (req: JoinRequestResponse, assignRole: 'vieweconst res = await orgStore.reviewOrganizationJoinRequest(props.orgId,req.id,- { approved: true, role: assignRole }+ { approved: true, role: assignRole },+ { requestType: req.request_type })if (res.success) {MessagePlugin.success(t('organization.settings.approveSuccess'))@@ -1472,7 +1473,8 @@ const handleRejectRequest = async (req: JoinRequestResponse) => {const res = await orgStore.reviewOrganizationJoinRequest(props.orgId,req.id,- { approved: false }+ { approved: false },+ { requestType: req.request_type })if (res.success) {MessagePlugin.success(t('organization.settings.rejectSuccess'))@@ -1871,6 +1873,11 @@ watch(() => props.visible, (newVal) => {inviteCode.value = ''inviteCodeExpiresAt.value = null} else if (props.orgId) {+ // 清空上一个组织的详情上下文,避免在 fetchOrgDetail 返回前短暂显示旧组织信息+ if (orgStore.currentOrganization?.id !== props.orgId) {+ orgStore.clearCurrentOrganizationContext()+ sharedKnowledgeBases.value = []+ }fetchOrgDetail()fetchMembers()fetchSharedKBs()