Let one API key carry every area the holder may still grant.
Deploy Development / deploy (push) Successful in 53s
Test Suite / pytest-backend (push) Failing after 29s
Test Suite / lint-backend (push) Successful in 1s
Test Suite / build-frontend (push) Successful in 17s
Test Suite / k6 /health Baseline (push) Successful in 35s
Test Suite / playwright-tests (push) Failing after 7m49s
Deploy Development / deploy (push) Successful in 53s
Test Suite / pytest-backend (push) Failing after 29s
Test Suite / lint-backend (push) Successful in 1s
Test Suite / build-frontend (push) Successful in 17s
Test Suite / k6 /health Baseline (push) Successful in 35s
Test Suite / playwright-tests (push) Failing after 7m49s
A key belongs to one application and can include global exercises, several clubs, and the holder's own exercises. Lost roles stop that area from being delivered, and the key stays copyable. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
c08c7c65b5
commit
b824115e9b
7 files changed
+260
-111
No files matched your search
@@ -16,27 +16,27 @@ const OBJECTS = [
|
||||
['training_module', 'Trainingsmodul'],
|
||||
]
|
||||
|
||||
const VISIBILITY = {
|
||||
official: 'Global',
|
||||
club: 'Verein',
|
||||
private: 'Eigene',
|
||||
function toggleValue(list, value, setter) {
|
||||
setter(list.includes(value) ? list.filter((item) => item !== value) : [...list, value])
|
||||
}
|
||||
|
||||
function KeyForm({ contextKind, clubId, allowedVisibilities, onCreated }) {
|
||||
function KeyForm({ superadmin, clubs, onCreated }) {
|
||||
const [name, setName] = useState('')
|
||||
const [objects, setObjects] = useState(['exercise'])
|
||||
const [visibilities, setVisibilities] = useState(
|
||||
allowedVisibilities.length === 1 ? allowedVisibilities : [allowedVisibilities[0]]
|
||||
)
|
||||
const [globalOn, setGlobalOn] = useState(false)
|
||||
const [privateOn, setPrivateOn] = useState(true)
|
||||
const [clubIds, setClubIds] = useState([])
|
||||
const [busy, setBusy] = useState(false)
|
||||
const [error, setError] = useState('')
|
||||
|
||||
function toggle(list, value, setter) {
|
||||
setter(list.includes(value) ? list.filter((item) => item !== value) : [...list, value])
|
||||
}
|
||||
const adminClubs = clubs.filter((club) => club.is_club_admin)
|
||||
|
||||
async function submit(event) {
|
||||
event.preventDefault()
|
||||
const visibilities = [
|
||||
...(globalOn ? ['official'] : []),
|
||||
...(clubIds.length ? ['club'] : []),
|
||||
...(privateOn ? ['private'] : []),
|
||||
]
|
||||
setBusy(true)
|
||||
setError('')
|
||||
try {
|
||||
@@ -44,8 +44,8 @@ function KeyForm({ contextKind, clubId, allowedVisibilities, onCreated }) {
|
||||
name: name.trim(),
|
||||
objects,
|
||||
visibilities,
|
||||
context_kind: contextKind,
|
||||
club_id: clubId || null,
|
||||
context_kind: 'user',
|
||||
club_ids: clubIds,
|
||||
})
|
||||
setName('')
|
||||
onCreated(result)
|
||||
@@ -56,59 +56,96 @@ function KeyForm({ contextKind, clubId, allowedVisibilities, onCreated }) {
|
||||
}
|
||||
}
|
||||
|
||||
const visibilitiesChosen = globalOn || privateOn || clubIds.length > 0
|
||||
|
||||
return (
|
||||
<form onSubmit={submit}>
|
||||
<label className="form-label">
|
||||
Name
|
||||
Name der Anwendung
|
||||
<input className="form-input" value={name} onChange={(event) => setName(event.target.value)} required />
|
||||
</label>
|
||||
<fieldset>
|
||||
<legend>Inhalte</legend>
|
||||
{OBJECTS.map(([value, label]) => (
|
||||
<label key={value} style={{ display: 'inline-flex', gap: 6, marginRight: 12 }}>
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={objects.includes(value)}
|
||||
onChange={() => toggle(objects, value, setObjects)}
|
||||
/>
|
||||
<input type="checkbox" checked={objects.includes(value)} onChange={() => toggleValue(objects, value, setObjects)} />
|
||||
{label}
|
||||
</label>
|
||||
))}
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<legend>Sichtbarkeit</legend>
|
||||
{allowedVisibilities.map((value) => (
|
||||
<label key={value} style={{ display: 'inline-flex', gap: 6, marginRight: 12 }}>
|
||||
<legend>Rechte</legend>
|
||||
{superadmin ? (
|
||||
<label style={{ display: 'flex', gap: 8, alignItems: 'center' }}>
|
||||
<input type="checkbox" checked={globalOn} onChange={(event) => setGlobalOn(event.target.checked)} />
|
||||
Globale Übungen
|
||||
</label>
|
||||
) : null}
|
||||
{adminClubs.map((club) => (
|
||||
<label key={club.id} style={{ display: 'flex', gap: 8, alignItems: 'center' }}>
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={visibilities.includes(value)}
|
||||
disabled={allowedVisibilities.length === 1}
|
||||
onChange={() => toggle(visibilities, value, setVisibilities)}
|
||||
checked={clubIds.includes(club.id)}
|
||||
disabled={!club.api_enabled}
|
||||
onChange={() => toggleValue(clubIds, club.id, setClubIds)}
|
||||
/>
|
||||
{VISIBILITY[value]}
|
||||
{club.name}
|
||||
{club.api_enabled ? '' : ' (Schnittstelle noch nicht frei)'}
|
||||
</label>
|
||||
))}
|
||||
<label style={{ display: 'flex', gap: 8, alignItems: 'center' }}>
|
||||
<input type="checkbox" checked={privateOn} onChange={(event) => setPrivateOn(event.target.checked)} />
|
||||
Eigene Übungen
|
||||
</label>
|
||||
</fieldset>
|
||||
{error ? <p role="alert">{error}</p> : null}
|
||||
<button type="submit" className="btn btn-primary" disabled={busy || !name.trim() || !objects.length || !visibilities.length}>
|
||||
<button type="submit" className="btn btn-primary" disabled={busy || !name.trim() || !objects.length || !visibilitiesChosen}>
|
||||
Schlüssel erzeugen
|
||||
</button>
|
||||
</form>
|
||||
)
|
||||
}
|
||||
|
||||
function KeyList({ keys, onRevoke }) {
|
||||
function KeyList({ keys, clubs, onRevoke }) {
|
||||
const [copied, setCopied] = useState('')
|
||||
if (!keys.length) return <p style={{ color: 'var(--text2)' }}>Noch kein Schlüssel.</p>
|
||||
|
||||
function rights(item) {
|
||||
const names = []
|
||||
if (item.visibilities.includes('official')) names.push('Global')
|
||||
for (const clubId of item.club_ids || []) {
|
||||
names.push(clubs.find((club) => club.id === clubId)?.name || `Verein ${clubId}`)
|
||||
}
|
||||
if (!item.club_ids?.length && item.club_name && item.visibilities.includes('club')) names.push(item.club_name)
|
||||
if (item.visibilities.includes('private')) names.push('Eigene')
|
||||
return names.join(', ')
|
||||
}
|
||||
|
||||
async function copy(token, id) {
|
||||
await navigator.clipboard.writeText(token)
|
||||
setCopied(id)
|
||||
}
|
||||
|
||||
return (
|
||||
<ul>
|
||||
<ul style={{ paddingLeft: 18 }}>
|
||||
{keys.map((item) => (
|
||||
<li key={item.id} style={{ marginBottom: 8 }}>
|
||||
<li key={item.id} style={{ marginBottom: 16 }}>
|
||||
<strong>{item.label}</strong>
|
||||
{' · '}
|
||||
{item.objects.map((object) => OBJECTS.find(([value]) => value === object)?.[1] || object).join(', ')}
|
||||
{' · '}
|
||||
{item.visibilities.map((value) => VISIBILITY[value] || value).join(', ')}
|
||||
<button type="button" className="btn btn-secondary" style={{ marginLeft: 8 }} onClick={() => onRevoke(item.id)}>
|
||||
<div style={{ color: 'var(--text2)', fontSize: 13 }}>
|
||||
{item.objects.map((object) => OBJECTS.find(([value]) => value === object)?.[1] || object).join(', ')}
|
||||
{rights(item) ? ` · ${rights(item)}` : ''}
|
||||
</div>
|
||||
{item.token ? (
|
||||
<div style={{ display: 'flex', gap: 8, marginTop: 6 }}>
|
||||
<input className="form-input" readOnly value={item.token} aria-label={`Schlüssel ${item.label}`} />
|
||||
<button type="button" className="btn btn-secondary" onClick={() => copy(item.token, item.id)}>
|
||||
{copied === item.id ? 'Kopiert' : 'Kopieren'}
|
||||
</button>
|
||||
</div>
|
||||
) : (
|
||||
<p style={{ color: 'var(--text3)', fontSize: 13 }}>Dieser ältere Schlüssel kann nicht erneut angezeigt werden.</p>
|
||||
)}
|
||||
<button type="button" className="btn btn-secondary" style={{ marginTop: 6 }} onClick={() => onRevoke(item.id)}>
|
||||
Widerrufen
|
||||
</button>
|
||||
</li>
|
||||
@@ -122,7 +159,6 @@ export default function AdminDistributionPage() {
|
||||
const superadmin = user?.role === 'superadmin'
|
||||
const [home, setHome] = useState(null)
|
||||
const [error, setError] = useState('')
|
||||
const [token, setToken] = useState('')
|
||||
|
||||
const load = useCallback(async () => {
|
||||
try {
|
||||
@@ -157,11 +193,6 @@ export default function AdminDistributionPage() {
|
||||
}
|
||||
}
|
||||
|
||||
function created(result) {
|
||||
setToken(result.token)
|
||||
load()
|
||||
}
|
||||
|
||||
const keys = home?.keys || []
|
||||
const clubs = home?.clubs || []
|
||||
|
||||
@@ -169,31 +200,23 @@ export default function AdminDistributionPage() {
|
||||
<div style={{ padding: 16, maxWidth: 880 }}>
|
||||
{superadmin ? <AdminPageNav /> : <p><Link to="/settings">Zurück zu Einstellungen</Link></p>}
|
||||
<h1>API-Schnittstelle</h1>
|
||||
<p style={{ color: 'var(--text2)', maxWidth: 68 * 8 }}>
|
||||
Ein Schlüssel hat einen Namen und legt fest, welche Inhalte und welche Sichtbarkeit ein externes Programm abrufen darf.
|
||||
<p style={{ color: 'var(--text2)', maxWidth: '68ch' }}>
|
||||
Ein Schlüssel gehört zu einer Anwendung. Du weist ihm die Bereiche zu, die diese Anwendung abrufen darf.
|
||||
Fällt dir eine Rolle weg, liefert der Schlüssel diesen Bereich nicht mehr aus.
|
||||
Trainingsplan, Rahmenprogramm und Trainingsmodul können schon erlaubt werden. Ausgeliefert werden derzeit Übungen.
|
||||
</p>
|
||||
{error ? <p role="alert">{error}</p> : null}
|
||||
{token ? (
|
||||
<p>
|
||||
Schlüssel, nur jetzt sichtbar: <code>{token}</code>
|
||||
</p>
|
||||
) : null}
|
||||
{!home ? <p>Wird geladen …</p> : null}
|
||||
|
||||
{superadmin ? (
|
||||
<section className="card" style={{ marginBottom: 16 }}>
|
||||
<h2>Vereine</h2>
|
||||
<p>Ein Verein legt seine Schlüssel selbst an, sobald die Schnittstelle für ihn frei ist.</p>
|
||||
<p>Ein Verein kann auf Schlüssel gelegt werden, sobald die Schnittstelle für ihn frei ist.</p>
|
||||
<ul>
|
||||
{clubs.map((club) => (
|
||||
<li key={club.id} style={{ marginBottom: 8 }}>
|
||||
<label style={{ display: 'flex', gap: 8, alignItems: 'center' }}>
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={club.api_enabled}
|
||||
onChange={(event) => toggleClub(club, event.target.checked)}
|
||||
/>
|
||||
<input type="checkbox" checked={club.api_enabled} onChange={(event) => toggleClub(club, event.target.checked)} />
|
||||
{club.name}
|
||||
</label>
|
||||
</li>
|
||||
@@ -202,36 +225,13 @@ export default function AdminDistributionPage() {
|
||||
</section>
|
||||
) : null}
|
||||
|
||||
{superadmin ? (
|
||||
<section className="card" style={{ marginBottom: 16 }}>
|
||||
<h2>Plattform</h2>
|
||||
<p>Für globale Übungen und eigene Übungen des Superadmins.</p>
|
||||
<KeyForm contextKind="platform" allowedVisibilities={['official', 'private']} onCreated={created} />
|
||||
<KeyList keys={keys.filter((item) => item.context_kind === 'platform')} onRevoke={revoke} />
|
||||
{home ? (
|
||||
<section className="card">
|
||||
<h2>Schlüssel</h2>
|
||||
<KeyForm superadmin={superadmin} clubs={clubs} onCreated={() => load()} />
|
||||
<KeyList keys={keys} clubs={clubs} onRevoke={revoke} />
|
||||
</section>
|
||||
) : null}
|
||||
|
||||
{clubs.filter((club) => club.is_club_admin).map((club) => (
|
||||
<section className="card" key={club.id} style={{ marginBottom: 16 }}>
|
||||
<h2>{club.name}</h2>
|
||||
{club.api_enabled ? (
|
||||
<>
|
||||
<p>Schlüssel dieses Vereins. Sichtbar sind Vereinsübungen und, wenn angekreuzt, eigene Übungen der Mitglieder.</p>
|
||||
<KeyForm contextKind="club" clubId={club.id} allowedVisibilities={['club', 'private']} onCreated={created} />
|
||||
<KeyList keys={keys.filter((item) => item.context_kind === 'club' && item.club_id === club.id)} onRevoke={revoke} />
|
||||
</>
|
||||
) : (
|
||||
<p>Die Schnittstelle ist für diesen Verein noch nicht freigegeben.</p>
|
||||
)}
|
||||
</section>
|
||||
))}
|
||||
|
||||
<section className="card">
|
||||
<h2>Eigene Übungen</h2>
|
||||
<p>Dieser Schlüssel gilt nur für Übungen, die dir gehören.</p>
|
||||
<KeyForm contextKind="personal" allowedVisibilities={['private']} onCreated={created} />
|
||||
<KeyList keys={keys.filter((item) => item.context_kind === 'personal')} onRevoke={revoke} />
|
||||
</section>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Reference in new issue
Block a user