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(rbac-ui): identify org owner row by tenant_id, not user_id
wizardchencf6c28fe7ef5
diff --git a/frontend/src/api/organization/index.ts b/frontend/src/api/organization/index.tsindex 43ddbc104..e73ba1957 100644--- a/frontend/src/api/organization/index.ts+++ b/frontend/src/api/organization/index.ts@@ -7,6 +7,15 @@ export interface Organization {description: stringavatar?: stringowner_id: string+ /**+ * Persisted owner tenant of the organization (Plan 3, migration 000046).+ * After Plan 3, member ownership is tenant-keyed: identifying the+ * "owner row" in the members list means matching member.tenant_id+ * against owner_tenant_id (NOT member.user_id against owner_id).+ * May be 0 on pre-000046 legacy rows; in that case fall back to+ * owner_id for display only.+ */+ owner_tenant_id: numberinvite_code?: stringinvite_code_expires_at?: string | nullinvite_code_validity_days?: numberdiff --git a/frontend/src/views/organization/OrganizationSettingsModal.vue b/frontend/src/views/organization/OrganizationSettingsModal.vueindex 80bf28830..e00f6a5e8 100644--- a/frontend/src/views/organization/OrganizationSettingsModal.vue+++ b/frontend/src/views/organization/OrganizationSettingsModal.vue@@ -347,12 +347,12 @@<t-loading :loading="membersLoading"><div class="members-list">- <div- v-for="member in filteredMembers"- :key="member.id"+ <div+ v-for="member in filteredMembers"+ :key="member.id"class="member-item"- :class="{- 'is-owner': member.user_id === orgInfo?.owner_id,+ :class="{+ 'is-owner': isOwnerMember(member),'is-me': member.user_id === authStore.currentUserId}">@@ -369,7 +369,7 @@</div><div class="member-role"><t-select- v-if="isAdmin && member.user_id !== orgInfo?.owner_id"+ v-if="isAdmin && !isOwnerMember(member)"v-model="member.role":options="roleOptions"size="small"@@ -377,10 +377,10 @@/><t-tag v-else size="small" :theme="getRoleTheme(member.role)">{{ $t(`organization.role.${member.role}`) }}- <span v-if="member.user_id === orgInfo?.owner_id">({{ $t('organization.owner') }})</span>+ <span v-if="isOwnerMember(member)">({{ $t('organization.owner') }})</span></t-tag></div>- <div v-if="isAdmin && member.user_id !== orgInfo?.owner_id" class="member-actions">+ <div v-if="isAdmin && !isOwnerMember(member)" class="member-actions"><t-buttonvariant="text"theme="danger"@@ -943,12 +943,26 @@ const roleOptions = computed(() => [const filteredMembers = computed(() => {const query = memberSearchQuery.value.toLowerCase()if (!query) return members.value- return members.value.filter(m =>- m.username.toLowerCase().includes(query) ||+ return members.value.filter(m =>+ m.username.toLowerCase().includes(query) ||m.email.toLowerCase().includes(query))})+// Owner identification is tenant-keyed after Plan 3 (#1303): the org's+// pinned owner_tenant_id (migration 000046) is the authority on which+// row in the per-tenant members list represents the owner. Falling+// back to owner_id (user-id) only matters for legacy rows where+// owner_tenant_id wasn't backfilled — in that case the old per-user+// rule is still better than nothing.+const isOwnerMember = (member: OrganizationMember): boolean => {+ const ownerTenantID = orgInfo.value?.owner_tenant_id+ if (ownerTenantID && ownerTenantID > 0) {+ return member.tenant_id === ownerTenantID+ }+ return member.user_id === orgInfo.value?.owner_id+}+const inviteLink = computed(() => {if (!inviteCode.value) return ''return `${window.location.origin}/join?code=${inviteCode.value}`diff --git a/internal/handler/organization.go b/internal/handler/organization.goindex d00a8a21d..9970d0a53 100644--- a/internal/handler/organization.go+++ b/internal/handler/organization.go@@ -1662,13 +1662,25 @@ func (h *OrganizationHandler) SetSharedAgentDisabledByMe(c *gin.Context) {// toOrgResponse converts an organization to response formatfunc (h *OrganizationHandler) toOrgResponse(ctx context.Context, org *types.Organization, currentUserID string) types.OrganizationResponse {currentTenantID := types.MustTenantIDFromContext(ctx)+ // Post-Plan-3 the canonical "is the caller the owner side?" check+ // is tenant-based: org.OwnerTenantID is the pinned column; legacy+ // rows with OwnerTenantID == 0 (pre-000046, unlikely in prod)+ // fall back to the user-id check so we don't show the wrong tenant+ // as "owner" in those edge cases.+ isOwner := false+ if org.OwnerTenantID != 0 {+ isOwner = org.OwnerTenantID == currentTenantID+ } else {+ isOwner = org.OwnerID == currentUserID+ }resp := types.OrganizationResponse{ID: org.ID,Name: org.Name,Description: org.Description,Avatar: org.Avatar,OwnerID: org.OwnerID,- IsOwner: org.OwnerID == currentUserID,+ OwnerTenantID: org.OwnerTenantID,+ IsOwner: isOwner,RequireApproval: org.RequireApproval,Searchable: org.Searchable,MemberLimit: org.MemberLimit,diff --git a/internal/types/organization.go b/internal/types/organization.goindex 4899942d7..e6a8c8f02 100644--- a/internal/types/organization.go+++ b/internal/types/organization.go@@ -382,11 +382,17 @@ type UpdateSharePermissionRequest struct {// OrganizationResponse represents an organization in API responsestype OrganizationResponse struct {- ID string `json:"id"`- Name string `json:"name"`- Description string `json:"description"`- Avatar string `json:"avatar,omitempty"`- OwnerID string `json:"owner_id"`+ ID string `json:"id"`+ Name string `json:"name"`+ Description string `json:"description"`+ Avatar string `json:"avatar,omitempty"`+ OwnerID string `json:"owner_id"`+ // OwnerTenantID is the persisted owner tenant of the organization+ // (Plan 3, migration 000046). Frontend uses this to identify the+ // "owner row" in the tenant-keyed members list — comparing+ // member.tenant_id against owner_tenant_id is the post-Plan-3+ // equivalent of the old member.user_id == owner_id check.+ OwnerTenantID uint64 `json:"owner_tenant_id"`InviteCode string `json:"invite_code,omitempty"`InviteCodeExpiresAt *time.Time `json:"invite_code_expires_at,omitempty"`InviteCodeValidityDays int `json:"invite_code_validity_days"`@@ -395,7 +401,7 @@ type OrganizationResponse struct {MemberLimit int `json:"member_limit"` // 0 = unlimitedMemberCount int `json:"member_count"`ShareCount int `json:"share_count"` // 共享到该组织的知识库数量- AgentShareCount int `json:"agent_share_count"` // 共享到该组织的智能体数量+ AgentShareCount int `json:"agent_share_count"` // 共享到该组织的智能体数量PendingJoinRequestCount int `json:"pending_join_request_count"` // 待审批加入申请数(仅管理员可见)IsOwner bool `json:"is_owner"`MyRole string `json:"my_role,omitempty"`