API Schnittstelle V1.0 #62
No files matched your search
@@ -291,6 +291,7 @@ CONTEXT_VISIBILITIES = {
|
|||||||
"platform": ("official", "private"),
|
"platform": ("official", "private"),
|
||||||
"club": ("club", "private"),
|
"club": ("club", "private"),
|
||||||
"personal": ("private",),
|
"personal": ("private",),
|
||||||
|
"user": ("official", "club", "private"),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+149
-20
@@ -868,6 +868,7 @@ def resolve_bearer(cur, token: str) -> dict:
|
|||||||
cur.execute(
|
cur.execute(
|
||||||
"""
|
"""
|
||||||
SELECT k.secret_hash, k.expires_at, k.revoked_at, k.objects, k.visibilities,
|
SELECT k.secret_hash, k.expires_at, k.revoked_at, k.objects, k.visibilities,
|
||||||
|
k.context_kind, k.context_profile_id, k.context_club_id, k.club_ids,
|
||||||
b.id AS binding_id, b.status AS binding_status,
|
b.id AS binding_id, b.status AS binding_status,
|
||||||
b.recipient_id, r.status AS recipient_status
|
b.recipient_id, r.status AS recipient_status
|
||||||
FROM distribution_keys k
|
FROM distribution_keys k
|
||||||
@@ -900,6 +901,10 @@ def resolve_bearer(cur, token: str) -> dict:
|
|||||||
"hits": allowed,
|
"hits": allowed,
|
||||||
"objects": list(row.get("objects") or ["exercise"]),
|
"objects": list(row.get("objects") or ["exercise"]),
|
||||||
"visibilities": list(row.get("visibilities") or ["official", "club", "private"]),
|
"visibilities": list(row.get("visibilities") or ["official", "club", "private"]),
|
||||||
|
"context_kind": row.get("context_kind"),
|
||||||
|
"context_profile_id": row.get("context_profile_id"),
|
||||||
|
"context_club_id": row.get("context_club_id"),
|
||||||
|
"club_ids": [int(item) for item in (row.get("club_ids") or [])],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -960,7 +965,58 @@ def assert_visibility_scope(visibilities, visibility: Optional[str]) -> None:
|
|||||||
raise HTTPException(status_code=404, detail={"code": "not_found", "message": "Paket nicht gefunden."})
|
raise HTTPException(status_code=404, detail={"code": "not_found", "message": "Paket nicht gefunden."})
|
||||||
|
|
||||||
|
|
||||||
def list_changes(cur, recipient_id: str, cursor_seq: int, limit: int) -> dict:
|
def grant_allows(cur, binding: dict, exercise: dict) -> bool:
|
||||||
|
"""Auslieferung folgt den Schlüsselrechten und den Rollen, die der Inhaber jetzt noch hat."""
|
||||||
|
vis = (exercise.get("visibility") or "private").strip().lower()
|
||||||
|
visibilities = list(binding.get("visibilities") or ["official", "club", "private"])
|
||||||
|
if vis not in visibilities:
|
||||||
|
return False
|
||||||
|
kind = binding.get("context_kind")
|
||||||
|
owner = binding.get("context_profile_id")
|
||||||
|
if kind != "user" or not owner:
|
||||||
|
legacy_club = binding.get("context_club_id")
|
||||||
|
if vis == "club" and legacy_club is not None and int(legacy_club) != int(exercise.get("club_id") or 0):
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
cur.execute("SELECT role FROM profiles WHERE id = %s", (int(owner),))
|
||||||
|
role = ((_one(cur) or {}).get("role") or "")
|
||||||
|
if vis == "official":
|
||||||
|
return is_superadmin(role)
|
||||||
|
if vis == "private":
|
||||||
|
created = exercise.get("created_by")
|
||||||
|
return created is not None and int(created) == int(owner)
|
||||||
|
if vis == "club":
|
||||||
|
club_id = exercise.get("club_id")
|
||||||
|
clubs = {int(item) for item in (binding.get("club_ids") or [])}
|
||||||
|
if binding.get("context_club_id") is not None:
|
||||||
|
clubs.add(int(binding["context_club_id"]))
|
||||||
|
if club_id is None or int(club_id) not in clubs:
|
||||||
|
return False
|
||||||
|
if not has_club_role(cur, int(owner), int(club_id), "club_admin"):
|
||||||
|
return False
|
||||||
|
return _api_enabled(cur, int(club_id))
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def assert_current_grant(cur, binding: Optional[dict], source_id: str) -> None:
|
||||||
|
if not binding or binding.get("context_kind") != "user":
|
||||||
|
assert_visibility_scope(
|
||||||
|
None if not binding else binding.get("visibilities"),
|
||||||
|
_source_visibility(cur, source_id),
|
||||||
|
)
|
||||||
|
return
|
||||||
|
cur.execute(
|
||||||
|
"SELECT visibility, club_id, created_by FROM exercises WHERE public_id = %s",
|
||||||
|
(str(source_id),),
|
||||||
|
)
|
||||||
|
exercise = _one(cur)
|
||||||
|
if exercise is None:
|
||||||
|
return
|
||||||
|
if not grant_allows(cur, binding, exercise):
|
||||||
|
raise HTTPException(status_code=404, detail={"code": "not_found", "message": "Paket nicht gefunden."})
|
||||||
|
|
||||||
|
|
||||||
|
def list_changes(cur, recipient_id: str, cursor_seq: int, limit: int, binding: Optional[dict] = None) -> dict:
|
||||||
cur.execute(
|
cur.execute(
|
||||||
"""
|
"""
|
||||||
SELECT seq, body FROM distribution_events
|
SELECT seq, body FROM distribution_events
|
||||||
@@ -983,6 +1039,8 @@ def list_changes(cur, recipient_id: str, cursor_seq: int, limit: int) -> dict:
|
|||||||
body = json.loads(body)
|
body = json.loads(body)
|
||||||
events.append(order_event(body))
|
events.append(order_event(body))
|
||||||
last_seq = int(item["seq"])
|
last_seq = int(item["seq"])
|
||||||
|
if binding and binding.get("context_kind") == "user":
|
||||||
|
events = _events_still_granted(cur, binding, events)
|
||||||
from distribution_contract import cursor_secret, encode_cursor
|
from distribution_contract import cursor_secret, encode_cursor
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -992,7 +1050,29 @@ def list_changes(cur, recipient_id: str, cursor_seq: int, limit: int) -> dict:
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def load_availability(cur, recipient_id: str, source_id: str, visibilities=None) -> dict:
|
def _events_still_granted(cur, binding: dict, events: list[dict]) -> list[dict]:
|
||||||
|
ids = [str(event.get("release_id")) for event in events if event.get("release_id")]
|
||||||
|
if not ids:
|
||||||
|
return events
|
||||||
|
placeholders = ", ".join(["%s"] * len(ids))
|
||||||
|
cur.execute(
|
||||||
|
f"""
|
||||||
|
SELECT dr.release_id, e.visibility, e.club_id, e.created_by
|
||||||
|
FROM distribution_releases dr
|
||||||
|
LEFT JOIN exercises e ON e.public_id = dr.source_id
|
||||||
|
WHERE dr.release_id IN ({placeholders})
|
||||||
|
""",
|
||||||
|
tuple(ids),
|
||||||
|
)
|
||||||
|
allowed = set()
|
||||||
|
for row in _rows(cur):
|
||||||
|
item = r2d(row)
|
||||||
|
if item.get("visibility") is None or grant_allows(cur, binding, item):
|
||||||
|
allowed.add(str(item["release_id"]))
|
||||||
|
return [event for event in events if str(event.get("release_id")) in allowed]
|
||||||
|
|
||||||
|
|
||||||
|
def load_availability(cur, recipient_id: str, source_id: str, visibilities=None, binding: Optional[dict] = None) -> dict:
|
||||||
import json
|
import json
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
@@ -1015,7 +1095,10 @@ def load_availability(cur, recipient_id: str, source_id: str, visibilities=None)
|
|||||||
status_code=404,
|
status_code=404,
|
||||||
detail={"code": "not_found", "message": "Für diesen Empfänger liegt keine Freigabe dieser Übung vor."},
|
detail={"code": "not_found", "message": "Für diesen Empfänger liegt keine Freigabe dieser Übung vor."},
|
||||||
)
|
)
|
||||||
cur.execute("SELECT status, visibility FROM exercises WHERE public_id = %s", (str(source_id),))
|
cur.execute(
|
||||||
|
"SELECT status, visibility, club_id, created_by FROM exercises WHERE public_id = %s",
|
||||||
|
(str(source_id),),
|
||||||
|
)
|
||||||
source = _one(cur)
|
source = _one(cur)
|
||||||
releases = []
|
releases = []
|
||||||
for row in rows:
|
for row in rows:
|
||||||
@@ -1057,8 +1140,12 @@ def load_availability(cur, recipient_id: str, source_id: str, visibilities=None)
|
|||||||
[item["package"] for item in releases],
|
[item["package"] for item in releases],
|
||||||
)
|
)
|
||||||
visibility = (source.get("visibility") if source else None)
|
visibility = (source.get("visibility") if source else None)
|
||||||
in_scope = visibility is None or key_covers(
|
in_scope = visibility is None or (
|
||||||
["exercise"], visibilities, resource="exercise", visibility=(visibility or "private").strip().lower()
|
grant_allows(cur, binding, source)
|
||||||
|
if binding and binding.get("context_kind") == "user"
|
||||||
|
else key_covers(
|
||||||
|
["exercise"], visibilities, resource="exercise", visibility=(visibility or "private").strip().lower()
|
||||||
|
)
|
||||||
)
|
)
|
||||||
return {
|
return {
|
||||||
"source_id": str(source_id),
|
"source_id": str(source_id),
|
||||||
@@ -1069,7 +1156,7 @@ def load_availability(cur, recipient_id: str, source_id: str, visibilities=None)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def load_manifest(cur, recipient_id: str, release_id: str, visibilities=None) -> bytes:
|
def load_manifest(cur, recipient_id: str, release_id: str, visibilities=None, binding: Optional[dict] = None) -> bytes:
|
||||||
cur.execute(
|
cur.execute(
|
||||||
"""
|
"""
|
||||||
SELECT release_id, recipient_id, publisher_id, source_id, fetch_blocked, manifest_text
|
SELECT release_id, recipient_id, publisher_id, source_id, fetch_blocked, manifest_text
|
||||||
@@ -1080,14 +1167,14 @@ def load_manifest(cur, recipient_id: str, release_id: str, visibilities=None) ->
|
|||||||
row = _one(cur)
|
row = _one(cur)
|
||||||
if not row or str(row["recipient_id"]) != str(recipient_id):
|
if not row or str(row["recipient_id"]) != str(recipient_id):
|
||||||
raise HTTPException(status_code=404, detail={"code": "not_found", "message": "Paket nicht gefunden."})
|
raise HTTPException(status_code=404, detail={"code": "not_found", "message": "Paket nicht gefunden."})
|
||||||
assert_visibility_scope(visibilities, _source_visibility(cur, str(row["source_id"])))
|
assert_current_grant(cur, binding, str(row["source_id"]))
|
||||||
enforce_expiry(cur, row)
|
enforce_expiry(cur, row)
|
||||||
if row.get("fetch_blocked"):
|
if row.get("fetch_blocked"):
|
||||||
raise HTTPException(status_code=410, detail={"code": "withdrawn", "message": "Paket zurückgezogen."})
|
raise HTTPException(status_code=410, detail={"code": "withdrawn", "message": "Paket zurückgezogen."})
|
||||||
return row["manifest_text"].encode("utf-8")
|
return row["manifest_text"].encode("utf-8")
|
||||||
|
|
||||||
|
|
||||||
def load_asset(cur, recipient_id: str, release_id: str, asset_id: str, visibilities=None) -> tuple[Path, str]:
|
def load_asset(cur, recipient_id: str, release_id: str, asset_id: str, visibilities=None, binding: Optional[dict] = None) -> tuple[Path, str]:
|
||||||
cur.execute(
|
cur.execute(
|
||||||
"""
|
"""
|
||||||
SELECT r.recipient_id, r.fetch_blocked, r.manifest_text, r.release_id, r.publisher_id, r.source_id,
|
SELECT r.recipient_id, r.fetch_blocked, r.manifest_text, r.release_id, r.publisher_id, r.source_id,
|
||||||
@@ -1101,7 +1188,7 @@ def load_asset(cur, recipient_id: str, release_id: str, asset_id: str, visibilit
|
|||||||
row = _one(cur)
|
row = _one(cur)
|
||||||
if not row or str(row["recipient_id"]) != str(recipient_id):
|
if not row or str(row["recipient_id"]) != str(recipient_id):
|
||||||
raise HTTPException(status_code=404, detail={"code": "not_found", "message": "Medium nicht gefunden."})
|
raise HTTPException(status_code=404, detail={"code": "not_found", "message": "Medium nicht gefunden."})
|
||||||
assert_visibility_scope(visibilities, _source_visibility(cur, str(row["source_id"])))
|
assert_current_grant(cur, binding, str(row["source_id"]))
|
||||||
enforce_expiry(cur, row)
|
enforce_expiry(cur, row)
|
||||||
if row.get("fetch_blocked"):
|
if row.get("fetch_blocked"):
|
||||||
raise HTTPException(status_code=410, detail={"code": "withdrawn", "message": "Medium zurückgezogen."})
|
raise HTTPException(status_code=410, detail={"code": "withdrawn", "message": "Medium zurückgezogen."})
|
||||||
@@ -1188,6 +1275,8 @@ def _ensure_relationship(cur, publisher_id: str, recipient_id: str) -> None:
|
|||||||
|
|
||||||
def _key_visible(item: dict, profile_id: int, role: str, admin_ids: set[int]) -> bool:
|
def _key_visible(item: dict, profile_id: int, role: str, admin_ids: set[int]) -> bool:
|
||||||
kind = item.get("context_kind")
|
kind = item.get("context_kind")
|
||||||
|
if kind == "user":
|
||||||
|
return int(item.get("context_profile_id") or 0) == int(profile_id)
|
||||||
if kind == "platform":
|
if kind == "platform":
|
||||||
return is_superadmin(role)
|
return is_superadmin(role)
|
||||||
if kind == "personal":
|
if kind == "personal":
|
||||||
@@ -1237,7 +1326,8 @@ def access_home(cur, profile_id: int, role: str) -> dict:
|
|||||||
cur.execute(
|
cur.execute(
|
||||||
"""
|
"""
|
||||||
SELECT k.id, k.label, k.key_prefix, k.objects, k.visibilities, k.context_kind,
|
SELECT k.id, k.label, k.key_prefix, k.objects, k.visibilities, k.context_kind,
|
||||||
k.context_club_id, k.context_profile_id, k.created_at, c.name AS club_name
|
k.context_club_id, k.context_profile_id, k.created_at, k.token_value, k.club_ids,
|
||||||
|
c.name AS club_name
|
||||||
FROM distribution_keys k
|
FROM distribution_keys k
|
||||||
LEFT JOIN clubs c ON c.id = k.context_club_id
|
LEFT JOIN clubs c ON c.id = k.context_club_id
|
||||||
WHERE k.revoked_at IS NULL
|
WHERE k.revoked_at IS NULL
|
||||||
@@ -1259,7 +1349,9 @@ def access_home(cur, profile_id: int, role: str) -> dict:
|
|||||||
"visibilities": list(item.get("visibilities") or []),
|
"visibilities": list(item.get("visibilities") or []),
|
||||||
"context_kind": item.get("context_kind"),
|
"context_kind": item.get("context_kind"),
|
||||||
"club_id": item.get("context_club_id"),
|
"club_id": item.get("context_club_id"),
|
||||||
|
"club_ids": [int(value) for value in (item.get("club_ids") or [])],
|
||||||
"club_name": item.get("club_name"),
|
"club_name": item.get("club_name"),
|
||||||
|
"token": item.get("token_value") or "",
|
||||||
"created_at": format_utc(created) if created and not isinstance(created, str) else created,
|
"created_at": format_utc(created) if created and not isinstance(created, str) else created,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -1288,19 +1380,35 @@ def create_named_key(
|
|||||||
club_id: Optional[int],
|
club_id: Optional[int],
|
||||||
profile_id: int,
|
profile_id: int,
|
||||||
role: str,
|
role: str,
|
||||||
|
club_ids: Optional[list[int]] = None,
|
||||||
) -> dict:
|
) -> dict:
|
||||||
denial = scope_denial(context_kind, objects, visibilities)
|
denial = scope_denial(context_kind, objects, visibilities)
|
||||||
if denial:
|
if denial:
|
||||||
raise HTTPException(status_code=400, detail=denial)
|
raise HTTPException(status_code=400, detail=denial)
|
||||||
owner_profile = None
|
owner_profile = None
|
||||||
stored_club = None
|
stored_club = None
|
||||||
if context_kind == "platform":
|
stored_clubs: list[int] = []
|
||||||
|
if context_kind == "user":
|
||||||
|
owner_profile = int(profile_id)
|
||||||
|
if "official" in visibilities and not is_superadmin(role):
|
||||||
|
raise HTTPException(status_code=403, detail="Globale Übungen darf nur ein Superadmin auf einen Schlüssel legen.")
|
||||||
|
if "club" in visibilities:
|
||||||
|
stored_clubs = sorted({int(item) for item in (club_ids or [])})
|
||||||
|
if not stored_clubs:
|
||||||
|
raise HTTPException(status_code=400, detail="Wähle mindestens einen Verein.")
|
||||||
|
for chosen in stored_clubs:
|
||||||
|
if not has_club_role(cur, profile_id, chosen, "club_admin"):
|
||||||
|
raise HTTPException(status_code=403, detail="Du bist nicht Vereinsadmin dieses Vereins.")
|
||||||
|
if not _api_enabled(cur, chosen):
|
||||||
|
raise HTTPException(status_code=403, detail="Die API-Schnittstelle ist für diesen Verein nicht freigegeben.")
|
||||||
|
elif context_kind == "platform":
|
||||||
if not is_superadmin(role):
|
if not is_superadmin(role):
|
||||||
raise HTTPException(status_code=403, detail="Plattform-Schlüssel legt ein Superadmin an.")
|
raise HTTPException(status_code=403, detail="Plattform-Schlüssel legt ein Superadmin an.")
|
||||||
elif context_kind == "club":
|
elif context_kind == "club":
|
||||||
if club_id is None:
|
if club_id is None:
|
||||||
raise HTTPException(status_code=400, detail="Verein fehlt.")
|
raise HTTPException(status_code=400, detail="Verein fehlt.")
|
||||||
stored_club = int(club_id)
|
stored_club = int(club_id)
|
||||||
|
stored_clubs = [stored_club]
|
||||||
if not has_club_role(cur, profile_id, stored_club, "club_admin"):
|
if not has_club_role(cur, profile_id, stored_club, "club_admin"):
|
||||||
raise HTTPException(status_code=403, detail="Nur ein Vereinsadmin legt Schlüssel für den Verein an.")
|
raise HTTPException(status_code=403, detail="Nur ein Vereinsadmin legt Schlüssel für den Verein an.")
|
||||||
if not _api_enabled(cur, stored_club):
|
if not _api_enabled(cur, stored_club):
|
||||||
@@ -1320,12 +1428,13 @@ def create_named_key(
|
|||||||
binding_id = str(_one(cur)["id"])
|
binding_id = str(_one(cur)["id"])
|
||||||
if "official" in visibilities:
|
if "official" in visibilities:
|
||||||
_ensure_relationship(cur, _ensure_publisher(cur, "platform", None, "Plattform"), recipient_id)
|
_ensure_relationship(cur, _ensure_publisher(cur, "platform", None, "Plattform"), recipient_id)
|
||||||
if "club" in visibilities and stored_club is not None:
|
if "club" in visibilities:
|
||||||
cur.execute("SELECT name FROM clubs WHERE id = %s", (stored_club,))
|
for chosen in stored_clubs:
|
||||||
club = _one(cur) or {}
|
cur.execute("SELECT name FROM clubs WHERE id = %s", (chosen,))
|
||||||
_ensure_relationship(
|
club = _one(cur) or {}
|
||||||
cur, _ensure_publisher(cur, "club", stored_club, club.get("name") or "Verein"), recipient_id
|
_ensure_relationship(
|
||||||
)
|
cur, _ensure_publisher(cur, "club", chosen, club.get("name") or "Verein"), recipient_id
|
||||||
|
)
|
||||||
if "private" in visibilities:
|
if "private" in visibilities:
|
||||||
_ensure_relationship(cur, _ensure_publisher(cur, "own", None, "Eigener Bestand"), recipient_id)
|
_ensure_relationship(cur, _ensure_publisher(cur, "own", None, "Eigener Bestand"), recipient_id)
|
||||||
|
|
||||||
@@ -1337,8 +1446,8 @@ def create_named_key(
|
|||||||
"""
|
"""
|
||||||
INSERT INTO distribution_keys (
|
INSERT INTO distribution_keys (
|
||||||
id, binding_id, key_prefix, secret_hash, label, objects, visibilities,
|
id, binding_id, key_prefix, secret_hash, label, objects, visibilities,
|
||||||
context_kind, context_club_id, context_profile_id
|
context_kind, context_club_id, context_profile_id, token_value, club_ids
|
||||||
) VALUES (%s, %s, %s, %s, %s, %s::text[], %s::text[], %s, %s, %s)
|
) VALUES (%s, %s, %s, %s, %s, %s::text[], %s::text[], %s, %s, %s, %s, %s::int[])
|
||||||
""",
|
""",
|
||||||
(
|
(
|
||||||
new_id(),
|
new_id(),
|
||||||
@@ -1351,6 +1460,8 @@ def create_named_key(
|
|||||||
context_kind,
|
context_kind,
|
||||||
stored_club,
|
stored_club,
|
||||||
owner_profile,
|
owner_profile,
|
||||||
|
token,
|
||||||
|
_pg_text_array([str(item) for item in stored_clubs]) if stored_clubs else "{}",
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
return {"token": token, "prefix": prefix, "label": label}
|
return {"token": token, "prefix": prefix, "label": label}
|
||||||
@@ -1374,10 +1485,28 @@ def revoke_named_key(cur, key_id: str, profile_id: int, role: str) -> dict:
|
|||||||
return {"ok": True}
|
return {"ok": True}
|
||||||
|
|
||||||
|
|
||||||
|
def _granted_club_ids(item: dict) -> set[int]:
|
||||||
|
clubs = {int(value) for value in (item.get("club_ids") or [])}
|
||||||
|
if item.get("context_club_id") is not None:
|
||||||
|
clubs.add(int(item["context_club_id"]))
|
||||||
|
return clubs
|
||||||
|
|
||||||
|
|
||||||
def _key_matches_exercise(item: dict, exercise: dict, profile_id: int, role: str, admin_ids: set[int], member_ids: set[int]) -> bool:
|
def _key_matches_exercise(item: dict, exercise: dict, profile_id: int, role: str, admin_ids: set[int], member_ids: set[int]) -> bool:
|
||||||
vis = (exercise.get("visibility") or "private").strip().lower()
|
vis = (exercise.get("visibility") or "private").strip().lower()
|
||||||
kind = item.get("context_kind")
|
kind = item.get("context_kind")
|
||||||
club_id = item.get("context_club_id")
|
club_id = item.get("context_club_id")
|
||||||
|
if kind == "user":
|
||||||
|
if int(item.get("context_profile_id") or 0) != int(profile_id):
|
||||||
|
return False
|
||||||
|
if vis == "official":
|
||||||
|
return is_superadmin(role)
|
||||||
|
if vis == "club":
|
||||||
|
exercise_club = int(exercise.get("club_id") or 0)
|
||||||
|
return exercise_club in _granted_club_ids(item) and exercise_club in admin_ids
|
||||||
|
if vis == "private":
|
||||||
|
return True
|
||||||
|
return False
|
||||||
if vis == "official":
|
if vis == "official":
|
||||||
return kind == "platform" and is_superadmin(role)
|
return kind == "platform" and is_superadmin(role)
|
||||||
if vis == "club":
|
if vis == "club":
|
||||||
@@ -1411,7 +1540,7 @@ def release_keys_for_exercise(cur, exercise: dict, profile_id: int, role: str) -
|
|||||||
return [], "Die API-Schnittstelle ist für diesen Verein nicht freigegeben."
|
return [], "Die API-Schnittstelle ist für diesen Verein nicht freigegeben."
|
||||||
cur.execute(
|
cur.execute(
|
||||||
"""
|
"""
|
||||||
SELECT k.id, k.label, k.context_kind, k.context_club_id, k.context_profile_id,
|
SELECT k.id, k.label, k.context_kind, k.context_club_id, k.context_profile_id, k.club_ids,
|
||||||
b.recipient_id, c.distribution_api_enabled AS api_enabled
|
b.recipient_id, c.distribution_api_enabled AS api_enabled
|
||||||
FROM distribution_keys k
|
FROM distribution_keys k
|
||||||
JOIN distribution_bindings b ON b.id = k.binding_id
|
JOIN distribution_bindings b ON b.id = k.binding_id
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
-- Ein Schlüssel kann mehrere Vereine und Sichtbarkeiten tragen. Der Wert bleibt für den Inhaber kopierbar.
|
||||||
|
|
||||||
|
ALTER TABLE distribution_keys
|
||||||
|
ADD COLUMN IF NOT EXISTS token_value TEXT;
|
||||||
|
|
||||||
|
ALTER TABLE distribution_keys
|
||||||
|
ADD COLUMN IF NOT EXISTS club_ids INT[] NOT NULL DEFAULT ARRAY[]::int[];
|
||||||
@@ -126,8 +126,9 @@ class AccessKeyBody(BaseModel):
|
|||||||
name: str = Field(min_length=1, max_length=200)
|
name: str = Field(min_length=1, max_length=200)
|
||||||
objects: list[str]
|
objects: list[str]
|
||||||
visibilities: list[str]
|
visibilities: list[str]
|
||||||
context_kind: str
|
context_kind: str = "user"
|
||||||
club_id: Optional[int] = None
|
club_id: Optional[int] = None
|
||||||
|
club_ids: list[int] = []
|
||||||
|
|
||||||
|
|
||||||
class ClubApiBody(BaseModel):
|
class ClubApiBody(BaseModel):
|
||||||
@@ -168,7 +169,7 @@ def get_changes(
|
|||||||
raise exc
|
raise exc
|
||||||
with get_db() as conn:
|
with get_db() as conn:
|
||||||
cur = get_cursor(conn)
|
cur = get_cursor(conn)
|
||||||
payload = list_changes(cur, binding["recipient_id"], seq, limit)
|
payload = list_changes(cur, binding["recipient_id"], seq, limit, binding)
|
||||||
return Response(
|
return Response(
|
||||||
content=__import__("json").dumps(payload, ensure_ascii=False, separators=(",", ":")),
|
content=__import__("json").dumps(payload, ensure_ascii=False, separators=(",", ":")),
|
||||||
media_type="application/json",
|
media_type="application/json",
|
||||||
@@ -185,7 +186,9 @@ def get_availability(source_id: str, authorization: Optional[str] = Header(defau
|
|||||||
cur = get_cursor(conn)
|
cur = get_cursor(conn)
|
||||||
try:
|
try:
|
||||||
assert_exercise_object(binding.get("objects"))
|
assert_exercise_object(binding.get("objects"))
|
||||||
payload = load_availability(cur, binding["recipient_id"], source_id, binding.get("visibilities"))
|
payload = load_availability(
|
||||||
|
cur, binding["recipient_id"], source_id, binding.get("visibilities"), binding
|
||||||
|
)
|
||||||
except HTTPException as exc:
|
except HTTPException as exc:
|
||||||
held = exc
|
held = exc
|
||||||
if held is not None:
|
if held is not None:
|
||||||
@@ -207,7 +210,7 @@ def get_release(release_id: str, authorization: Optional[str] = Header(default=N
|
|||||||
cur = get_cursor(conn)
|
cur = get_cursor(conn)
|
||||||
try:
|
try:
|
||||||
assert_exercise_object(binding.get("objects"))
|
assert_exercise_object(binding.get("objects"))
|
||||||
body = load_manifest(cur, binding["recipient_id"], release_id, binding.get("visibilities"))
|
body = load_manifest(cur, binding["recipient_id"], release_id, binding.get("visibilities"), binding)
|
||||||
except HTTPException as exc:
|
except HTTPException as exc:
|
||||||
held = exc
|
held = exc
|
||||||
if held is not None:
|
if held is not None:
|
||||||
@@ -227,7 +230,7 @@ def get_asset(release_id: str, asset_id: str, authorization: Optional[str] = Hea
|
|||||||
try:
|
try:
|
||||||
assert_exercise_object(binding.get("objects"))
|
assert_exercise_object(binding.get("objects"))
|
||||||
path, media_type = load_asset(
|
path, media_type = load_asset(
|
||||||
cur, binding["recipient_id"], release_id, asset_id, binding.get("visibilities")
|
cur, binding["recipient_id"], release_id, asset_id, binding.get("visibilities"), binding
|
||||||
)
|
)
|
||||||
except HTTPException as exc:
|
except HTTPException as exc:
|
||||||
held = exc
|
held = exc
|
||||||
@@ -524,6 +527,7 @@ def post_access_key(body: AccessKeyBody, tenant: TenantContext = Depends(get_ten
|
|||||||
visibilities=body.visibilities,
|
visibilities=body.visibilities,
|
||||||
context_kind=body.context_kind,
|
context_kind=body.context_kind,
|
||||||
club_id=body.club_id,
|
club_id=body.club_id,
|
||||||
|
club_ids=body.club_ids,
|
||||||
profile_id=tenant.profile_id,
|
profile_id=tenant.profile_id,
|
||||||
role=tenant.global_role or "",
|
role=tenant.global_role or "",
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -102,6 +102,7 @@ def test_replay_keeps_release_id_and_explicit_reconfirm_mints_a_new_one() -> Non
|
|||||||
|
|
||||||
|
|
||||||
def test_key_scope_follows_the_role_context() -> None:
|
def test_key_scope_follows_the_role_context() -> None:
|
||||||
|
assert scope_denial("user", ["exercise"], ["official", "club", "private"]) is None
|
||||||
assert scope_denial("personal", ["exercise"], ["private"]) is None
|
assert scope_denial("personal", ["exercise"], ["private"]) is None
|
||||||
assert scope_denial("personal", ["exercise"], ["official"])
|
assert scope_denial("personal", ["exercise"], ["official"])
|
||||||
assert scope_denial("club", ["exercise", "framework"], ["club", "private"]) is None
|
assert scope_denial("club", ["exercise", "framework"], ["club", "private"]) is None
|
||||||
|
|||||||
+10
-3
@@ -1,8 +1,8 @@
|
|||||||
# Shinkan Jinkendo Version Information
|
# Shinkan Jinkendo Version Information
|
||||||
|
|
||||||
APP_VERSION = "0.8.253"
|
APP_VERSION = "0.8.254"
|
||||||
BUILD_DATE = "2026-11-23"
|
BUILD_DATE = "2026-11-23"
|
||||||
DB_SCHEMA_VERSION = "20261123100"
|
DB_SCHEMA_VERSION = "20261123101"
|
||||||
|
|
||||||
MODULE_VERSIONS = {
|
MODULE_VERSIONS = {
|
||||||
"legal_documents": "1.4.0", # Admin: Live-Vorschau pro Abschnitt + modale Vollvorschau (Editor + Dokumentenliste)
|
"legal_documents": "1.4.0", # Admin: Live-Vorschau pro Abschnitt + modale Vollvorschau (Editor + Dokumentenliste)
|
||||||
@@ -39,7 +39,7 @@ MODULE_VERSIONS = {
|
|||||||
"skill_profiles": "1.0.0", # Phase 3: gewichtetes Fähigkeiten-Profil + skill-discovery/suggestions
|
"skill_profiles": "1.0.0", # Phase 3: gewichtetes Fähigkeiten-Profil + skill-discovery/suggestions
|
||||||
"methods": "0.1.0",
|
"methods": "0.1.0",
|
||||||
"exercises": "2.38.0", # Globale Übungen schreibt und gibt nur superadmin frei
|
"exercises": "2.38.0", # Globale Übungen schreibt und gibt nur superadmin frei
|
||||||
"distribution": "1.2.0", # API-Schlüssel je Mandant: Name, Objekte, Sichtbarkeit; Verein schaltet der Superadmin frei
|
"distribution": "1.3.0", # Ein Schlüssel je Anwendung, Rechte folgen der aktuellen Rolle, Schlüssel bleibt kopierbar
|
||||||
"planning_exercise_suggest": "0.23.8", # Progressionsgraph: Katalog-Kontext (Fokus/Stil/TT/ZG) im Match-Profil
|
"planning_exercise_suggest": "0.23.8", # Progressionsgraph: Katalog-Kontext (Fokus/Stil/TT/ZG) im Match-Profil
|
||||||
"training_units": "0.4.0", # POST .../publish-to-framework: Ablauf aus geplanter Einheit → Rahmen-Slot-Blueprint
|
"training_units": "0.4.0", # POST .../publish-to-framework: Ablauf aus geplanter Einheit → Rahmen-Slot-Blueprint
|
||||||
"training_programs": "0.1.0",
|
"training_programs": "0.1.0",
|
||||||
@@ -55,6 +55,13 @@ MODULE_VERSIONS = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
CHANGELOG = [
|
CHANGELOG = [
|
||||||
|
{
|
||||||
|
"version": "0.8.254",
|
||||||
|
"date": "2026-11-23",
|
||||||
|
"changes": [
|
||||||
|
"Ein API-Schlüssel gehört zu einer Anwendung und kann globale Übungen, mehrere Vereine und eigene Übungen zugleich erlauben. Fällt die Rolle weg, wird dieser Bereich nicht mehr ausgeliefert. Der Schlüssel bleibt kopierbar.",
|
||||||
|
],
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"version": "0.8.253",
|
"version": "0.8.253",
|
||||||
"date": "2026-11-23",
|
"date": "2026-11-23",
|
||||||
|
|||||||
@@ -16,27 +16,27 @@ const OBJECTS = [
|
|||||||
['training_module', 'Trainingsmodul'],
|
['training_module', 'Trainingsmodul'],
|
||||||
]
|
]
|
||||||
|
|
||||||
const VISIBILITY = {
|
function toggleValue(list, value, setter) {
|
||||||
official: 'Global',
|
setter(list.includes(value) ? list.filter((item) => item !== value) : [...list, value])
|
||||||
club: 'Verein',
|
|
||||||
private: 'Eigene',
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function KeyForm({ contextKind, clubId, allowedVisibilities, onCreated }) {
|
function KeyForm({ superadmin, clubs, onCreated }) {
|
||||||
const [name, setName] = useState('')
|
const [name, setName] = useState('')
|
||||||
const [objects, setObjects] = useState(['exercise'])
|
const [objects, setObjects] = useState(['exercise'])
|
||||||
const [visibilities, setVisibilities] = useState(
|
const [globalOn, setGlobalOn] = useState(false)
|
||||||
allowedVisibilities.length === 1 ? allowedVisibilities : [allowedVisibilities[0]]
|
const [privateOn, setPrivateOn] = useState(true)
|
||||||
)
|
const [clubIds, setClubIds] = useState([])
|
||||||
const [busy, setBusy] = useState(false)
|
const [busy, setBusy] = useState(false)
|
||||||
const [error, setError] = useState('')
|
const [error, setError] = useState('')
|
||||||
|
const adminClubs = clubs.filter((club) => club.is_club_admin)
|
||||||
function toggle(list, value, setter) {
|
|
||||||
setter(list.includes(value) ? list.filter((item) => item !== value) : [...list, value])
|
|
||||||
}
|
|
||||||
|
|
||||||
async function submit(event) {
|
async function submit(event) {
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
|
const visibilities = [
|
||||||
|
...(globalOn ? ['official'] : []),
|
||||||
|
...(clubIds.length ? ['club'] : []),
|
||||||
|
...(privateOn ? ['private'] : []),
|
||||||
|
]
|
||||||
setBusy(true)
|
setBusy(true)
|
||||||
setError('')
|
setError('')
|
||||||
try {
|
try {
|
||||||
@@ -44,8 +44,8 @@ function KeyForm({ contextKind, clubId, allowedVisibilities, onCreated }) {
|
|||||||
name: name.trim(),
|
name: name.trim(),
|
||||||
objects,
|
objects,
|
||||||
visibilities,
|
visibilities,
|
||||||
context_kind: contextKind,
|
context_kind: 'user',
|
||||||
club_id: clubId || null,
|
club_ids: clubIds,
|
||||||
})
|
})
|
||||||
setName('')
|
setName('')
|
||||||
onCreated(result)
|
onCreated(result)
|
||||||
@@ -56,59 +56,96 @@ function KeyForm({ contextKind, clubId, allowedVisibilities, onCreated }) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const visibilitiesChosen = globalOn || privateOn || clubIds.length > 0
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<form onSubmit={submit}>
|
<form onSubmit={submit}>
|
||||||
<label className="form-label">
|
<label className="form-label">
|
||||||
Name
|
Name der Anwendung
|
||||||
<input className="form-input" value={name} onChange={(event) => setName(event.target.value)} required />
|
<input className="form-input" value={name} onChange={(event) => setName(event.target.value)} required />
|
||||||
</label>
|
</label>
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<legend>Inhalte</legend>
|
<legend>Inhalte</legend>
|
||||||
{OBJECTS.map(([value, label]) => (
|
{OBJECTS.map(([value, label]) => (
|
||||||
<label key={value} style={{ display: 'inline-flex', gap: 6, marginRight: 12 }}>
|
<label key={value} style={{ display: 'inline-flex', gap: 6, marginRight: 12 }}>
|
||||||
<input
|
<input type="checkbox" checked={objects.includes(value)} onChange={() => toggleValue(objects, value, setObjects)} />
|
||||||
type="checkbox"
|
|
||||||
checked={objects.includes(value)}
|
|
||||||
onChange={() => toggle(objects, value, setObjects)}
|
|
||||||
/>
|
|
||||||
{label}
|
{label}
|
||||||
</label>
|
</label>
|
||||||
))}
|
))}
|
||||||
</fieldset>
|
</fieldset>
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<legend>Sichtbarkeit</legend>
|
<legend>Rechte</legend>
|
||||||
{allowedVisibilities.map((value) => (
|
{superadmin ? (
|
||||||
<label key={value} style={{ display: 'inline-flex', gap: 6, marginRight: 12 }}>
|
<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
|
<input
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
checked={visibilities.includes(value)}
|
checked={clubIds.includes(club.id)}
|
||||||
disabled={allowedVisibilities.length === 1}
|
disabled={!club.api_enabled}
|
||||||
onChange={() => toggle(visibilities, value, setVisibilities)}
|
onChange={() => toggleValue(clubIds, club.id, setClubIds)}
|
||||||
/>
|
/>
|
||||||
{VISIBILITY[value]}
|
{club.name}
|
||||||
|
{club.api_enabled ? '' : ' (Schnittstelle noch nicht frei)'}
|
||||||
</label>
|
</label>
|
||||||
))}
|
))}
|
||||||
|
<label style={{ display: 'flex', gap: 8, alignItems: 'center' }}>
|
||||||
|
<input type="checkbox" checked={privateOn} onChange={(event) => setPrivateOn(event.target.checked)} />
|
||||||
|
Eigene Übungen
|
||||||
|
</label>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
{error ? <p role="alert">{error}</p> : null}
|
{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
|
Schlüssel erzeugen
|
||||||
</button>
|
</button>
|
||||||
</form>
|
</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>
|
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 (
|
return (
|
||||||
<ul>
|
<ul style={{ paddingLeft: 18 }}>
|
||||||
{keys.map((item) => (
|
{keys.map((item) => (
|
||||||
<li key={item.id} style={{ marginBottom: 8 }}>
|
<li key={item.id} style={{ marginBottom: 16 }}>
|
||||||
<strong>{item.label}</strong>
|
<strong>{item.label}</strong>
|
||||||
{' · '}
|
<div style={{ color: 'var(--text2)', fontSize: 13 }}>
|
||||||
{item.objects.map((object) => OBJECTS.find(([value]) => value === object)?.[1] || object).join(', ')}
|
{item.objects.map((object) => OBJECTS.find(([value]) => value === object)?.[1] || object).join(', ')}
|
||||||
{' · '}
|
{rights(item) ? ` · ${rights(item)}` : ''}
|
||||||
{item.visibilities.map((value) => VISIBILITY[value] || value).join(', ')}
|
</div>
|
||||||
<button type="button" className="btn btn-secondary" style={{ marginLeft: 8 }} onClick={() => onRevoke(item.id)}>
|
{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
|
Widerrufen
|
||||||
</button>
|
</button>
|
||||||
</li>
|
</li>
|
||||||
@@ -122,7 +159,6 @@ export default function AdminDistributionPage() {
|
|||||||
const superadmin = user?.role === 'superadmin'
|
const superadmin = user?.role === 'superadmin'
|
||||||
const [home, setHome] = useState(null)
|
const [home, setHome] = useState(null)
|
||||||
const [error, setError] = useState('')
|
const [error, setError] = useState('')
|
||||||
const [token, setToken] = useState('')
|
|
||||||
|
|
||||||
const load = useCallback(async () => {
|
const load = useCallback(async () => {
|
||||||
try {
|
try {
|
||||||
@@ -157,11 +193,6 @@ export default function AdminDistributionPage() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function created(result) {
|
|
||||||
setToken(result.token)
|
|
||||||
load()
|
|
||||||
}
|
|
||||||
|
|
||||||
const keys = home?.keys || []
|
const keys = home?.keys || []
|
||||||
const clubs = home?.clubs || []
|
const clubs = home?.clubs || []
|
||||||
|
|
||||||
@@ -169,31 +200,23 @@ export default function AdminDistributionPage() {
|
|||||||
<div style={{ padding: 16, maxWidth: 880 }}>
|
<div style={{ padding: 16, maxWidth: 880 }}>
|
||||||
{superadmin ? <AdminPageNav /> : <p><Link to="/settings">Zurück zu Einstellungen</Link></p>}
|
{superadmin ? <AdminPageNav /> : <p><Link to="/settings">Zurück zu Einstellungen</Link></p>}
|
||||||
<h1>API-Schnittstelle</h1>
|
<h1>API-Schnittstelle</h1>
|
||||||
<p style={{ color: 'var(--text2)', maxWidth: 68 * 8 }}>
|
<p style={{ color: 'var(--text2)', maxWidth: '68ch' }}>
|
||||||
Ein Schlüssel hat einen Namen und legt fest, welche Inhalte und welche Sichtbarkeit ein externes Programm abrufen darf.
|
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.
|
Trainingsplan, Rahmenprogramm und Trainingsmodul können schon erlaubt werden. Ausgeliefert werden derzeit Übungen.
|
||||||
</p>
|
</p>
|
||||||
{error ? <p role="alert">{error}</p> : null}
|
{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}
|
{!home ? <p>Wird geladen …</p> : null}
|
||||||
|
|
||||||
{superadmin ? (
|
{superadmin ? (
|
||||||
<section className="card" style={{ marginBottom: 16 }}>
|
<section className="card" style={{ marginBottom: 16 }}>
|
||||||
<h2>Vereine</h2>
|
<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>
|
<ul>
|
||||||
{clubs.map((club) => (
|
{clubs.map((club) => (
|
||||||
<li key={club.id} style={{ marginBottom: 8 }}>
|
<li key={club.id} style={{ marginBottom: 8 }}>
|
||||||
<label style={{ display: 'flex', gap: 8, alignItems: 'center' }}>
|
<label style={{ display: 'flex', gap: 8, alignItems: 'center' }}>
|
||||||
<input
|
<input type="checkbox" checked={club.api_enabled} onChange={(event) => toggleClub(club, event.target.checked)} />
|
||||||
type="checkbox"
|
|
||||||
checked={club.api_enabled}
|
|
||||||
onChange={(event) => toggleClub(club, event.target.checked)}
|
|
||||||
/>
|
|
||||||
{club.name}
|
{club.name}
|
||||||
</label>
|
</label>
|
||||||
</li>
|
</li>
|
||||||
@@ -202,36 +225,13 @@ export default function AdminDistributionPage() {
|
|||||||
</section>
|
</section>
|
||||||
) : null}
|
) : null}
|
||||||
|
|
||||||
{superadmin ? (
|
{home ? (
|
||||||
<section className="card" style={{ marginBottom: 16 }}>
|
<section className="card">
|
||||||
<h2>Plattform</h2>
|
<h2>Schlüssel</h2>
|
||||||
<p>Für globale Übungen und eigene Übungen des Superadmins.</p>
|
<KeyForm superadmin={superadmin} clubs={clubs} onCreated={() => load()} />
|
||||||
<KeyForm contextKind="platform" allowedVisibilities={['official', 'private']} onCreated={created} />
|
<KeyList keys={keys} clubs={clubs} onRevoke={revoke} />
|
||||||
<KeyList keys={keys.filter((item) => item.context_kind === 'platform')} onRevoke={revoke} />
|
|
||||||
</section>
|
</section>
|
||||||
) : null}
|
) : 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>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user