feat(auth): support tenantless provisioning and gated self-service workspace creation

Allow deployments to register users without auto-creating a personal tenant, expose creation policy via /auth/me, and guide tenantless accounts through a workspace onboarding flow.
This commit is contained in:
wizardchen
2026-07-13 18:04:14 +08:00
committed by lyingbug
parent 50b8c0a72e
commit ecf2c1fb9b
36 changed files with 1543 additions and 89 deletions
+37
View File
@@ -0,0 +1,37 @@
package handler
import (
"context"
"github.com/Tencent/WeKnora/internal/config"
"github.com/Tencent/WeKnora/internal/types/interfaces"
)
const (
tenantSelfServiceCreationSettingKey = "tenant.self_service_creation_enabled"
tenantSelfServiceCreationEnvName = "WEKNORA_TENANT_SELF_SERVICE_CREATION_ENABLED"
)
// resolveTenantSelfServiceCreationEnabled is the shared policy resolver used
// both by POST /tenants enforcement and /auth/me capability projection. Keeping
// both on one function prevents the UI from advertising a capability that the
// backend would reject.
func resolveTenantSelfServiceCreationEnabled(
ctx context.Context,
cfg *config.Config,
settings interfaces.SystemSettingService,
) bool {
enabled := true
if cfg != nil && cfg.Tenant != nil {
enabled = cfg.Tenant.IsSelfServiceCreationEnabled()
}
if settings == nil {
return enabled
}
return settings.GetBool(
ctx,
tenantSelfServiceCreationSettingKey,
tenantSelfServiceCreationEnvName,
enabled,
)
}