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:
@@ -382,11 +382,17 @@ type UpdateSharePermissionRequest struct {
|
||||
|
||||
// OrganizationResponse represents an organization in API responses
|
||||
type 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 = unlimited
|
||||
MemberCount 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"`
|
||||
|
||||
Reference in New Issue
Block a user