Enhance Tenant Context and Access Control Features
Deploy Development / deploy (push) Successful in 43s
Test Suite / pytest-backend (push) Failing after 0s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 14s
Test Suite / k6 /health Baseline (push) Failing after 4m0s
Test Suite / playwright-tests (push) Failing after 3m41s
Deploy Development / deploy (push) Successful in 43s
Test Suite / pytest-backend (push) Failing after 0s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 14s
Test Suite / k6 /health Baseline (push) Failing after 4m0s
Test Suite / playwright-tests (push) Failing after 3m41s
- Introduced `email_verified` and `account_state` attributes in the `TenantContext` to improve user state management. - Updated the `resolve_tenant_context` function to dynamically fetch `email_verified` status from the database and determine `account_state` based on user roles and memberships. - Implemented `assert_min_account_state` checks across various endpoints to enforce access control based on user account status. - Incremented version to 1.1.0 in version.py to reflect these enhancements in tenant context management and access control.
This commit is contained in:
1 parent
7cfbca40bb
commit
30dc30c7aa
21 files changed
+1124
-22
No files matched your search
@@ -0,0 +1,64 @@
|
||||
import { createContext, useCallback, useContext, useEffect, useMemo, useState } from 'react'
|
||||
import { getMeEntitlements } from '../utils/api'
|
||||
import { useAuth } from './AuthContext'
|
||||
|
||||
const EntitlementsContext = createContext(null)
|
||||
|
||||
export function EntitlementsProvider({ children }) {
|
||||
const { user, isAuthenticated, loading: authLoading } = useAuth()
|
||||
const [entitlements, setEntitlements] = useState(null)
|
||||
const [loading, setLoading] = useState(false)
|
||||
const [error, setError] = useState(null)
|
||||
|
||||
const clubId = user?.effective_club_id ?? null
|
||||
|
||||
const refreshEntitlements = useCallback(async () => {
|
||||
if (!isAuthenticated) {
|
||||
setEntitlements(null)
|
||||
setError(null)
|
||||
return null
|
||||
}
|
||||
setLoading(true)
|
||||
setError(null)
|
||||
try {
|
||||
const data = await getMeEntitlements(clubId)
|
||||
setEntitlements(data)
|
||||
return data
|
||||
} catch (e) {
|
||||
setEntitlements(null)
|
||||
setError(e?.message || String(e))
|
||||
return null
|
||||
} finally {
|
||||
setLoading(false)
|
||||
}
|
||||
}, [isAuthenticated, clubId])
|
||||
|
||||
useEffect(() => {
|
||||
if (authLoading) return
|
||||
refreshEntitlements()
|
||||
}, [authLoading, refreshEntitlements])
|
||||
|
||||
const value = useMemo(
|
||||
() => ({
|
||||
entitlements,
|
||||
loading,
|
||||
error,
|
||||
refreshEntitlements,
|
||||
hasCapability: (capId) => Boolean(entitlements?.capabilities?.[capId]),
|
||||
getFeature: (featureId) => entitlements?.features?.[featureId] ?? null,
|
||||
}),
|
||||
[entitlements, loading, error, refreshEntitlements],
|
||||
)
|
||||
|
||||
return (
|
||||
<EntitlementsContext.Provider value={value}>{children}</EntitlementsContext.Provider>
|
||||
)
|
||||
}
|
||||
|
||||
export function useEntitlements() {
|
||||
const ctx = useContext(EntitlementsContext)
|
||||
if (!ctx) {
|
||||
throw new Error('useEntitlements must be used within EntitlementsProvider')
|
||||
}
|
||||
return ctx
|
||||
}
|
||||
Reference in new issue
Block a user