Let each tenant create named API keys with content and visibility scope.
Deploy Development / deploy (push) Failing after 32s
Test Suite / pytest-backend (push) Failing after 26s
Test Suite / lint-backend (push) Successful in 1s
Test Suite / build-frontend (push) Failing after 6s
Test Suite / k6 /health Baseline (push) Successful in 34s
Test Suite / playwright-tests (push) Canceled after 1m34s
Deploy Development / deploy (push) Failing after 32s
Test Suite / pytest-backend (push) Failing after 26s
Test Suite / lint-backend (push) Successful in 1s
Test Suite / build-frontend (push) Failing after 6s
Test Suite / k6 /health Baseline (push) Successful in 34s
Test Suite / playwright-tests (push) Canceled after 1m34s
Superadmins enable a club for the interface. Club admins and members create the keys. Exercise release lives on its own tab and picks one of those keys. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
fe3633ba8b
commit
1527a430b9
14 files changed
+842
-290
No files matched your search
@@ -21,9 +21,12 @@ from distribution_contract import (
|
||||
distribution_enabled,
|
||||
)
|
||||
from distribution_service import (
|
||||
access_home,
|
||||
assert_exercise_object,
|
||||
backlog_count,
|
||||
confirm_draft,
|
||||
create_draft,
|
||||
create_named_key,
|
||||
issue_key,
|
||||
list_changes,
|
||||
load_asset,
|
||||
@@ -32,6 +35,9 @@ from distribution_service import (
|
||||
overview,
|
||||
resolve_bearer,
|
||||
retire_release,
|
||||
revoke_named_key,
|
||||
set_club_api,
|
||||
target_for_key,
|
||||
update_draft,
|
||||
withdraw_release,
|
||||
)
|
||||
@@ -110,11 +116,24 @@ class SuspendBody(BaseModel):
|
||||
|
||||
|
||||
class DraftBody(BaseModel):
|
||||
publisher_id: str
|
||||
recipient_id: str
|
||||
publisher_id: Optional[str] = None
|
||||
recipient_id: Optional[str] = None
|
||||
key_id: Optional[str] = None
|
||||
cut: Optional[dict] = None
|
||||
|
||||
|
||||
class AccessKeyBody(BaseModel):
|
||||
name: str = Field(min_length=1, max_length=200)
|
||||
objects: list[str]
|
||||
visibilities: list[str]
|
||||
context_kind: str
|
||||
club_id: Optional[int] = None
|
||||
|
||||
|
||||
class ClubApiBody(BaseModel):
|
||||
enabled: bool
|
||||
|
||||
|
||||
class CutBody(BaseModel):
|
||||
cut: dict
|
||||
|
||||
@@ -142,6 +161,11 @@ def get_changes(
|
||||
detail={"code": "invalid_cursor", "message": "Cursor ungültig."},
|
||||
headers=NO_STORE,
|
||||
)
|
||||
try:
|
||||
assert_exercise_object(binding.get("objects"))
|
||||
except HTTPException as exc:
|
||||
exc.headers = {**(exc.headers or {}), **NO_STORE}
|
||||
raise exc
|
||||
with get_db() as conn:
|
||||
cur = get_cursor(conn)
|
||||
payload = list_changes(cur, binding["recipient_id"], seq, limit)
|
||||
@@ -160,7 +184,8 @@ def get_availability(source_id: str, authorization: Optional[str] = Header(defau
|
||||
with get_db() as conn:
|
||||
cur = get_cursor(conn)
|
||||
try:
|
||||
payload = load_availability(cur, binding["recipient_id"], source_id)
|
||||
assert_exercise_object(binding.get("objects"))
|
||||
payload = load_availability(cur, binding["recipient_id"], source_id, binding.get("visibilities"))
|
||||
except HTTPException as exc:
|
||||
held = exc
|
||||
if held is not None:
|
||||
@@ -181,7 +206,8 @@ def get_release(release_id: str, authorization: Optional[str] = Header(default=N
|
||||
with get_db() as conn:
|
||||
cur = get_cursor(conn)
|
||||
try:
|
||||
body = load_manifest(cur, binding["recipient_id"], release_id)
|
||||
assert_exercise_object(binding.get("objects"))
|
||||
body = load_manifest(cur, binding["recipient_id"], release_id, binding.get("visibilities"))
|
||||
except HTTPException as exc:
|
||||
held = exc
|
||||
if held is not None:
|
||||
@@ -199,7 +225,10 @@ def get_asset(release_id: str, asset_id: str, authorization: Optional[str] = Hea
|
||||
with get_db() as conn:
|
||||
cur = get_cursor(conn)
|
||||
try:
|
||||
path, media_type = load_asset(cur, binding["recipient_id"], release_id, asset_id)
|
||||
assert_exercise_object(binding.get("objects"))
|
||||
path, media_type = load_asset(
|
||||
cur, binding["recipient_id"], release_id, asset_id, binding.get("visibilities")
|
||||
)
|
||||
except HTTPException as exc:
|
||||
held = exc
|
||||
if held is not None:
|
||||
@@ -222,11 +251,19 @@ def post_draft(exercise_id: int, body: DraftBody, tenant: TenantContext = Depend
|
||||
from routers.exercises import _assert_can_edit_exercise
|
||||
|
||||
_assert_can_edit_exercise(cur, exercise_id, tenant)
|
||||
if body.key_id:
|
||||
publisher_id, recipient_id = target_for_key(
|
||||
cur, exercise_id, body.key_id, tenant.profile_id, tenant.global_role or ""
|
||||
)
|
||||
elif body.publisher_id and body.recipient_id:
|
||||
publisher_id, recipient_id = body.publisher_id, body.recipient_id
|
||||
else:
|
||||
raise HTTPException(status_code=400, detail="Wähle einen API-Schlüssel.")
|
||||
result = create_draft(
|
||||
cur,
|
||||
exercise_id,
|
||||
body.publisher_id,
|
||||
body.recipient_id,
|
||||
publisher_id,
|
||||
recipient_id,
|
||||
tenant.profile_id,
|
||||
tenant.global_role or "",
|
||||
body.cut,
|
||||
@@ -458,3 +495,46 @@ def get_backlog(tenant: TenantContext = Depends(get_tenant_context)):
|
||||
with get_db() as conn:
|
||||
cur = get_cursor(conn)
|
||||
return {"count": backlog_count(cur)}
|
||||
|
||||
|
||||
@editorial.get("/api/distribution/access")
|
||||
def get_access(tenant: TenantContext = Depends(get_tenant_context)):
|
||||
with get_db() as conn:
|
||||
cur = get_cursor(conn)
|
||||
return access_home(cur, tenant.profile_id, tenant.global_role or "")
|
||||
|
||||
|
||||
@editorial.put("/api/distribution/access/clubs/{club_id}")
|
||||
def put_club_api(club_id: int, body: ClubApiBody, tenant: TenantContext = Depends(get_tenant_context)):
|
||||
with get_db() as conn:
|
||||
cur = get_cursor(conn)
|
||||
result = set_club_api(cur, club_id, body.enabled, tenant.global_role or "")
|
||||
conn.commit()
|
||||
return result
|
||||
|
||||
|
||||
@editorial.post("/api/distribution/access/keys")
|
||||
def post_access_key(body: AccessKeyBody, tenant: TenantContext = Depends(get_tenant_context)):
|
||||
with get_db() as conn:
|
||||
cur = get_cursor(conn)
|
||||
result = create_named_key(
|
||||
cur,
|
||||
name=body.name,
|
||||
objects=body.objects,
|
||||
visibilities=body.visibilities,
|
||||
context_kind=body.context_kind,
|
||||
club_id=body.club_id,
|
||||
profile_id=tenant.profile_id,
|
||||
role=tenant.global_role or "",
|
||||
)
|
||||
conn.commit()
|
||||
return result
|
||||
|
||||
|
||||
@editorial.post("/api/distribution/access/keys/{key_id}/revoke")
|
||||
def post_revoke_named(key_id: str, tenant: TenantContext = Depends(get_tenant_context)):
|
||||
with get_db() as conn:
|
||||
cur = get_cursor(conn)
|
||||
result = revoke_named_key(cur, key_id, tenant.profile_id, tenant.global_role or "")
|
||||
conn.commit()
|
||||
return result
|
||||
Reference in new issue
Block a user