fix(api): report tenant-scoped role in tenant users list

A user who is admin in one tenant but member in another must read
'admin' for this tenant — use roleForTenant() rather than the global
u.role fallback when building the tenant users list.
This commit is contained in:
Ronni Baslund
2026-05-31 21:30:08 +02:00
parent f8618b2bbc
commit f094158334
@@ -14,7 +14,7 @@ import { PricesService } from '../prices/prices.service.js'
import type { PriceCurrency, PriceCycle, PriceDocument } from '../schemas/price.schema.js' import type { PriceCurrency, PriceCycle, PriceDocument } from '../schemas/price.schema.js'
import { Subscription, SubscriptionDocument } from '../schemas/subscription.schema.js' import { Subscription, SubscriptionDocument } from '../schemas/subscription.schema.js'
import { Tenant, TenantDocument } from '../schemas/tenant.schema.js' import { Tenant, TenantDocument } from '../schemas/tenant.schema.js'
import { User, UserDocument } from '../schemas/user.schema.js' import { User, UserDocument, roleForTenant } from '../schemas/user.schema.js'
import type { PartnerUpdateTenantDto } from '../me/dto/partner-update-tenant.dto.js' import type { PartnerUpdateTenantDto } from '../me/dto/partner-update-tenant.dto.js'
import type { CreateTenantDto } from './dto/create-tenant.dto.js' import type { CreateTenantDto } from './dto/create-tenant.dto.js'
import type { UpdateBillingInfoDto } from './dto/update-billing-info.dto.js' import type { UpdateBillingInfoDto } from './dto/update-billing-info.dto.js'
@@ -341,7 +341,15 @@ export class TenantsService {
enrolled = false enrolled = false
} }
} }
return { id: String(u._id), name: u.name, email: u.email, role: u.role, enrolled } // Tenant-scoped role, not the global fallback — a user who is admin
// here but member elsewhere must read 'admin' in this list.
return {
id: String(u._id),
name: u.name,
email: u.email,
role: roleForTenant(u, tenant._id),
enrolled,
}
}), }),
) )
return { return {