mirror of
https://github.com/hanzoai/base.git
synced 2026-10-21 03:41:50 +00:00
Base's own registry was already org-native in every method — OrgDB(orgID), HasOrg(orgID), orgDir(orgID) — and only the type names said tenant. So this is the vocabulary catching up with the code, not a change of behaviour. TenantRegistry -> Bases app.Bases().OrgDB(org) TenantConfig -> BasesConfig MultiTenant -> PerOrg it enables per-org databases; say that MULTI_TENANT -> MULTI_BASE core/tenant.go -> core/bases.go Tenant was the wrong noun twice over: it is the multi-tenancy word, and this product's unit is the thing a customer creates per org — a Base. Identity here is org, user, project, and nothing else. The UI never said it; this was Go-side only. 64 packages green. One test was collateral and is fixed rather than renamed: TestToHTTPHeader asserts a pure snake_case-to-Header-Case transform, so rewriting its EXPECTED value while its input stayed "tenant_id" made it assert something false. The case is dropped — org_id already covers that transform.
37 lines
1.2 KiB
Go
37 lines
1.2 KiB
Go
package migrations
|
|
|
|
import "github.com/hanzoai/base/core"
|
|
|
|
// Per-org identity: expose the caller's IAM org on the auth record so
|
|
// collection rules can scope by base (`@request.auth.org_id = org`).
|
|
//
|
|
// resolveJWKSToken (apis/middlewares.go) already stamps the JWT `owner` claim
|
|
// onto the ephemeral auth record as `org_id`, but ONLY when the auth collection
|
|
// declares that field; the rule engine likewise resolves `@request.auth.org_id`
|
|
// from the record's PublicExport, which serializes SCHEMA fields only. Both need
|
|
// `org_id` to be a real field on `users`. Idempotent. `_superusers` is skipped —
|
|
// superusers bypass record rules, so org on the admin record is irrelevant.
|
|
func init() {
|
|
core.SystemMigrations.Register(func(txApp core.App) error {
|
|
c, err := txApp.FindCollectionByNameOrId("users")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if c.Fields.GetByName("org_id") == nil {
|
|
c.Fields.Add(&core.TextField{Name: "org_id"})
|
|
return txApp.Save(c)
|
|
}
|
|
return nil
|
|
}, func(txApp core.App) error {
|
|
c, err := txApp.FindCollectionByNameOrId("users")
|
|
if err != nil {
|
|
return nil
|
|
}
|
|
if c.Fields.GetByName("org_id") != nil {
|
|
c.Fields.RemoveByName("org_id")
|
|
return txApp.Save(c)
|
|
}
|
|
return nil
|
|
})
|
|
}
|