fix(rbac-ui): identify org owner row by tenant_id, not user_id

Plan 3 (#1303) lifted Org membership from per-user to per-tenant, and
40fdb978 pinned the org's owner tenant in DB as organizations.owner_tenant_id.
The OrganizationSettingsModal members list, however, still decided
"which row is the owner" by comparing member.user_id against
orgInfo.owner_id. After Plan 3 the members list is keyed on tenant_id,
so the user-id check is structurally wrong: the representative user of
the owner tenant happens to be the owner today, but if that user is
moved to another tenant — or a different user of the owner tenant
becomes the representative — the modal would either lose the "(owner)"
tag, or re-tag a non-owner row, and would offer the role-select /
remove-button affordances on what is in fact the owner tenant row.

This change:

  - Adds OwnerTenantID to OrganizationResponse and populates it in
    toOrgResponse from the persisted column. IsOwner now compares the
    caller's current tenant against owner_tenant_id (with a user-id
    fallback for legacy rows where owner_tenant_id == 0).

  - Adds owner_tenant_id to the frontend Organization type and a small
    isOwnerMember(member) helper in OrganizationSettingsModal, which
    tenant-matches by default and falls back to user-id only on
    pre-000046 rows. The role <select>, role tag suffix, and the
    delete button on member rows now all use the helper.

The "is-me" CSS class and the me-tag in the member name still match
on user_id — that one really is a per-user marker ("this row's user is
me, the signed-in user").
This commit is contained in:
wizardchen
2026-05-15 23:51:04 +08:00
committed by lyingbug
parent 7e20b9a57e
commit cf6c28fe7e
4 changed files with 58 additions and 17 deletions
+9
View File
@@ -7,6 +7,15 @@ export interface Organization {
description: string
avatar?: string
owner_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: number
invite_code?: string
invite_code_expires_at?: string | null
invite_code_validity_days?: number
@@ -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-button
variant="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}`