feat(tenant_context): enhance effective_club_id resolution for platform admins without header
Deploy Development / deploy (push) Successful in 34s
Test Suite / pytest-backend (push) Successful in 24s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 7s
Test Suite / playwright-tests (push) Successful in 31s
Deploy Development / deploy (push) Successful in 34s
Test Suite / pytest-backend (push) Successful in 24s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 7s
Test Suite / playwright-tests (push) Successful in 31s
- Updated resolve_tenant_context to use stored active_club_id if the club exists when no header is provided. - Adjusted comments for clarity regarding platform admin behavior. - Added unit tests to verify new behavior for platform admins in test_access_layer.py. version bump to 1.0.5 for tenant_context module.
This commit is contained in:
1 parent
d3055f6f2f
commit
3ff47779e0
7 files changed
+121
-14
No files matched your search
@@ -1,4 +1,5 @@
|
||||
import { useAuth } from '../context/AuthContext'
|
||||
import { getResolvedActiveClubIdForUi } from '../utils/activeClub'
|
||||
|
||||
/**
|
||||
* Zeigt einen Vereins-Umschalter, wenn der Nutzer mehreren Vereinen zugeordnet ist.
|
||||
@@ -9,10 +10,7 @@ export default function ActiveClubSwitcher({ variant = 'sidebar' }) {
|
||||
const clubs = user?.clubs || []
|
||||
if (clubs.length <= 1) return null
|
||||
|
||||
const selectClubId =
|
||||
user?.active_club_id != null && clubs.some((c) => c.id === user.active_club_id)
|
||||
? user.active_club_id
|
||||
: clubs[0]?.id
|
||||
const selectClubId = getResolvedActiveClubIdForUi(user)
|
||||
|
||||
const isMobile = variant === 'mobile'
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { Link, useLocation, useNavigate } from 'react-router-dom'
|
||||
import { useAuth } from '../context/AuthContext'
|
||||
import { getResolvedActiveClubIdForUi } from '../utils/activeClub'
|
||||
|
||||
function Navigation() {
|
||||
const location = useLocation()
|
||||
@@ -7,10 +8,7 @@ function Navigation() {
|
||||
const { user, logout, setActiveClub } = useAuth()
|
||||
|
||||
const clubs = user?.clubs || []
|
||||
const selectClubId =
|
||||
user?.active_club_id != null && clubs.some((c) => c.id === user.active_club_id)
|
||||
? user.active_club_id
|
||||
: clubs[0]?.id
|
||||
const selectClubId = getResolvedActiveClubIdForUi(user)
|
||||
|
||||
const handleLogout = async () => {
|
||||
await logout()
|
||||
|
||||
@@ -64,11 +64,25 @@ export function AuthProvider({ children }) {
|
||||
const uid = userRef.current?.id
|
||||
if (!Number.isFinite(cid) || cid < 1 || !uid) return
|
||||
localStorage.setItem(ACTIVE_CLUB_STORAGE_KEY, String(cid))
|
||||
setUser((prev) => (prev?.id ? { ...prev, active_club_id: cid } : prev))
|
||||
setUser((prev) =>
|
||||
prev?.id
|
||||
? { ...prev, active_club_id: cid, effective_club_id: cid }
|
||||
: prev
|
||||
)
|
||||
try {
|
||||
await api.updateProfile(uid, { active_club_id: cid })
|
||||
const profile = await api.getCurrentProfile()
|
||||
syncStoredActiveClub(profile)
|
||||
setUser(profile)
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
try {
|
||||
const profile = await api.getCurrentProfile()
|
||||
syncStoredActiveClub(profile)
|
||||
setUser(profile)
|
||||
} catch {
|
||||
/* ignore */
|
||||
}
|
||||
}
|
||||
}, [])
|
||||
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
import { ACTIVE_CLUB_STORAGE_KEY } from './api'
|
||||
|
||||
/**
|
||||
* Einheitliche Anzeige des aktiven Vereins: Abgleich mit effective_club_id, active_club_id,
|
||||
* LocalStorage (Request-Header-Quelle), sonst erster Verein der Liste.
|
||||
*/
|
||||
export function getResolvedActiveClubIdForUi(user) {
|
||||
const clubs = user?.clubs || []
|
||||
if (!clubs.length) return null
|
||||
|
||||
const idInClubs = (id) =>
|
||||
id != null &&
|
||||
id !== '' &&
|
||||
clubs.some((c) => Number(c.id) === Number(id))
|
||||
|
||||
const eff = user?.effective_club_id
|
||||
if (idInClubs(eff)) return Number(eff)
|
||||
|
||||
const ac = user?.active_club_id
|
||||
if (idInClubs(ac)) return Number(ac)
|
||||
|
||||
try {
|
||||
const ls = localStorage.getItem(ACTIVE_CLUB_STORAGE_KEY)
|
||||
if (ls && /^\d+$/.test(ls.trim()) && clubs.some((c) => String(c.id) === ls.trim())) {
|
||||
return Number(ls.trim())
|
||||
}
|
||||
} catch {
|
||||
/* ignore */
|
||||
}
|
||||
|
||||
return Number(clubs[0].id)
|
||||
}
|
||||
Reference in new issue
Block a user