getOrgEntitlements method
- String orgId
Fetch the entitlements for a specific organization — not the caller's user-level entitlements.
Used by org-scoped feature screens (SSO, webhooks, learning paths, etc.) to determine whether the CURRENT ORG has the feature, regardless of whether the caller happens to belong to a different enterprise org.
Calls the org_entitlements() Postgres function from migration 053.
Returns null on failure so the UI can fall back to a safe default
(typically: show the upgrade prompt).
Implementation
Future<Map<String, dynamic>?> getOrgEntitlements(String orgId) async {
try {
final raw = await _client.rpc(
'org_entitlements',
params: {'p_org_id': orgId},
);
if (raw == null) return null;
if (raw is Map<String, dynamic>) return raw;
if (raw is Map) return Map<String, dynamic>.from(raw);
return null;
} catch (e, stack) {
dev.log(
'getOrgEntitlements($orgId) failed: $e',
name: 'EntitlementDatasource',
error: e,
stackTrace: stack,
);
return null;
}
}