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
@@ -8,6 +8,7 @@ import {
|
||||
Outlet,
|
||||
} from 'react-router-dom'
|
||||
import { AuthProvider, useAuth } from './context/AuthContext'
|
||||
import { EntitlementsProvider } from './context/EntitlementsContext'
|
||||
import { FormEditorActionsProvider, FormEditorBottomSlot } from './context/FormEditorActionsContext'
|
||||
import { ToastProvider } from './context/ToastContext'
|
||||
import { OrgInboxProvider, useOrgInbox } from './context/OrgInboxContext'
|
||||
@@ -345,11 +346,13 @@ const appRouter = createBrowserRouter([
|
||||
function App() {
|
||||
return (
|
||||
<AuthProvider>
|
||||
<ToastProvider>
|
||||
<Suspense fallback={<AppRouteFallback />}>
|
||||
<RouterProvider router={appRouter} />
|
||||
</Suspense>
|
||||
</ToastProvider>
|
||||
<EntitlementsProvider>
|
||||
<ToastProvider>
|
||||
<Suspense fallback={<AppRouteFallback />}>
|
||||
<RouterProvider router={appRouter} />
|
||||
</Suspense>
|
||||
</ToastProvider>
|
||||
</EntitlementsProvider>
|
||||
</AuthProvider>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
import { useEntitlements } from '../context/EntitlementsContext'
|
||||
|
||||
/**
|
||||
* Zeigt Vereins-Kontingent für ein Feature (M4 UsageBadge).
|
||||
* Unbegrenzt (limit null) → nichts rendern.
|
||||
*/
|
||||
export default function FeatureUsageBadge({ featureId = 'ai_calls', label = 'KI-Kontingent' }) {
|
||||
const { entitlements, loading, getFeature } = useEntitlements()
|
||||
const feat = getFeature(featureId)
|
||||
|
||||
if (loading && !feat) {
|
||||
return (
|
||||
<span className="feature-usage-badge muted" style={{ fontSize: '0.8rem' }}>
|
||||
{label}: …
|
||||
</span>
|
||||
)
|
||||
}
|
||||
|
||||
if (!feat) return null
|
||||
|
||||
const { used = 0, limit, remaining, allowed } = feat
|
||||
if (limit == null) return null
|
||||
|
||||
const tone = !allowed || remaining === 0 ? 'var(--danger)' : 'var(--text2)'
|
||||
|
||||
return (
|
||||
<span
|
||||
className="feature-usage-badge"
|
||||
style={{ fontSize: '0.8rem', color: tone }}
|
||||
title={
|
||||
entitlements?.plan_id
|
||||
? `Plan: ${entitlements.plan_id}`
|
||||
: undefined
|
||||
}
|
||||
>
|
||||
{label}: {used}/{limit}
|
||||
{remaining != null ? ` (${remaining} übrig)` : ''}
|
||||
</span>
|
||||
)
|
||||
}
|
||||
@@ -19,6 +19,7 @@ import { stripHtmlToText } from '../../utils/htmlUtils'
|
||||
import ExerciseCatalogAssocEditor from './ExerciseCatalogAssocEditor'
|
||||
import ExerciseSkillsEditor from './ExerciseSkillsEditor'
|
||||
import { useAuth } from '../../context/AuthContext'
|
||||
import FeatureUsageBadge from '../FeatureUsageBadge'
|
||||
import { useToast } from '../../context/ToastContext'
|
||||
import {
|
||||
activeClubMemberships,
|
||||
@@ -1653,15 +1654,18 @@ function ExerciseFormPageRoot() {
|
||||
<label className="form-label" style={{ marginBottom: 0 }}>
|
||||
Kurzbeschreibung
|
||||
</label>
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-secondary"
|
||||
style={{ fontSize: '12px' }}
|
||||
disabled={aiSuggestBusy}
|
||||
onClick={() => runExerciseAiSuggestion('summary')}
|
||||
>
|
||||
KI: Kurzfassung
|
||||
</button>
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: '8px', flexWrap: 'wrap' }}>
|
||||
<FeatureUsageBadge featureId="ai_calls" />
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-secondary"
|
||||
style={{ fontSize: '12px' }}
|
||||
disabled={aiSuggestBusy}
|
||||
onClick={() => runExerciseAiSuggestion('summary')}
|
||||
>
|
||||
KI: Kurzfassung
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<RichTextEditor
|
||||
value={formData.summary}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
@@ -40,6 +40,15 @@ export async function getCurrentProfile() {
|
||||
return request('/api/profiles/me')
|
||||
}
|
||||
|
||||
/** Effektive Capabilities + Feature-Kontingente (M4). */
|
||||
export async function getMeEntitlements(clubId = null) {
|
||||
const q =
|
||||
clubId != null && clubId !== ''
|
||||
? `?club_id=${encodeURIComponent(String(clubId))}`
|
||||
: ''
|
||||
return request(`/api/me/entitlements${q}`)
|
||||
}
|
||||
|
||||
/** Liste aller Profile – nur für Plattform-Admins (Vereinsanlage). */
|
||||
export async function listProfiles() {
|
||||
return request('/api/profiles')
|
||||
@@ -850,6 +859,7 @@ export const api = {
|
||||
register,
|
||||
logout,
|
||||
getCurrentProfile,
|
||||
getMeEntitlements,
|
||||
listProfiles,
|
||||
listAdminUsers,
|
||||
getAdminUserContentMeta,
|
||||
|
||||
Reference in new issue
Block a user