Enhance Club Feature Consumption Logic and Update Versioning
Deploy Development / deploy (push) Successful in 42s
Test Suite / pytest-backend (push) Successful in 47s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 14s
Test Suite / k6 /health Baseline (push) Successful in 34s
Test Suite / playwright-tests (push) Successful in 1m40s

- Introduced the `consume_club_feature_with_usage` function to standardize feature consumption across endpoints, improving code reusability and clarity.
- Implemented `merge_feature_usage_into_response` to embed feature usage data in API responses, streamlining frontend integration.
- Updated various backend routers to utilize the new consumption logic, ensuring consistent feature usage tracking during AI-related actions.
- Enhanced tests to validate the new consumption and logging behavior.
- Incremented application version to 0.8.199 and updated module version for 'club_features' to 1.6.0 to reflect these changes.
This commit is contained in:
Lars committed 2026-06-07 10:32:49 +02:00
1 parent 40641594ac
commit b68185842e
9 files changed
+323 -16

No files matched your search

+41 -1
View File
@@ -4,10 +4,23 @@ import {
getDefaultClubIdForGovernanceForms,
getResolvedActiveClubIdForUi,
} from '../utils/activeClub'
import {
registerFeatureUsageSyncHandler,
unregisterFeatureUsageSyncHandler,
} from '../utils/featureUsageSync'
import { useAuth } from './AuthContext'
const EntitlementsContext = createContext(null)
function mergeFeatureUsage(entitlements, featureUsage) {
if (!entitlements || !featureUsage) return entitlements
const features = { ...entitlements.features }
for (const [fid, row] of Object.entries(featureUsage)) {
if (row) features[fid] = { ...features[fid], ...row }
}
return { ...entitlements, features }
}
export function EntitlementsProvider({ children }) {
const { user, isAuthenticated, loading: authLoading } = useAuth()
const [entitlements, setEntitlements] = useState(null)
@@ -38,6 +51,32 @@ export function EntitlementsProvider({ children }) {
}
}, [isAuthenticated, clubId])
const refreshEntitlementsQuiet = useCallback(async () => {
if (!isAuthenticated) return null
try {
const data = await getMeEntitlements(clubId)
setEntitlements(data)
return data
} catch {
return null
}
}, [isAuthenticated, clubId])
const applyFeatureUsageFromResponse = useCallback(
async (apiResponse) => {
if (apiResponse?.feature_usage) {
setEntitlements((prev) => mergeFeatureUsage(prev, apiResponse.feature_usage))
}
return refreshEntitlementsQuiet()
},
[refreshEntitlementsQuiet],
)
useEffect(() => {
registerFeatureUsageSyncHandler(applyFeatureUsageFromResponse)
return () => unregisterFeatureUsageSyncHandler()
}, [applyFeatureUsageFromResponse])
useEffect(() => {
if (authLoading) return
refreshEntitlements()
@@ -49,10 +88,11 @@ export function EntitlementsProvider({ children }) {
loading,
error,
refreshEntitlements,
refreshEntitlementsQuiet,
hasCapability: (capId) => Boolean(entitlements?.capabilities?.[capId]),
getFeature: (featureId) => entitlements?.features?.[featureId] ?? null,
}),
[entitlements, loading, error, refreshEntitlements],
[entitlements, loading, error, refreshEntitlements, refreshEntitlementsQuiet],
)
return (