feat: update application version to 0.8.36 and enhance profile creation process
Deploy Development / deploy (push) Successful in 35s
Test Suite / pytest-backend (push) Successful in 7s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 6s
Test Suite / playwright-tests (push) Failing after 37s
Deploy Development / deploy (push) Successful in 35s
Test Suite / pytest-backend (push) Successful in 7s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 6s
Test Suite / playwright-tests (push) Failing after 37s
- Bumped application version to 0.8.36 in both backend and frontend files. - Updated the ProfileCreate model to require name and email fields, ensuring schema compliance. - Implemented a new POST /api/profiles endpoint restricted to platform admins, utilizing a random PIN for user setup. - Added integration tests for profile creation, including checks for unauthorized access and duplicate email handling. - Enhanced changelog to reflect the new version and changes made in this release.
This commit is contained in:
1 parent
caab9f2863
commit
35b14fe1a6
5 files changed
+124
-18
No files matched your search
+45
-11
@@ -3,14 +3,14 @@ Profile Management Endpoints for Mitai Jinkendo
|
||||
|
||||
Handles profile CRUD operations for both admin and current user.
|
||||
"""
|
||||
import uuid
|
||||
import secrets
|
||||
from typing import Optional
|
||||
from datetime import datetime
|
||||
|
||||
from fastapi import APIRouter, HTTPException, Header, Depends
|
||||
|
||||
from db import get_db, get_cursor, r2d
|
||||
from auth import require_auth
|
||||
from auth import require_auth, hash_pin
|
||||
from club_tenancy import assert_club_member, memberships_with_roles, is_platform_admin
|
||||
from tenant_context import resolve_tenant_context, TenantContext, get_tenant_context
|
||||
from models import ProfileCreate, ProfileUpdate
|
||||
@@ -87,17 +87,51 @@ def list_profiles(session=Depends(require_auth)):
|
||||
|
||||
@router.post("/profiles")
|
||||
def create_profile(p: ProfileCreate, session=Depends(require_auth)):
|
||||
"""Create new profile (admin)."""
|
||||
pid = str(uuid.uuid4())
|
||||
"""
|
||||
Neues Profil anlegen — nur Plattform-Admin.
|
||||
|
||||
Nutzt gleiches Kernschema wie Registrierung (SERIAL id); PIN wird zufällig gesetzt — Nutzer
|
||||
setzt das Passwort über „Passwort vergessen“ oder ein späteres Admin-Tool.
|
||||
"""
|
||||
role = session.get("role") or ""
|
||||
if not is_platform_admin(role):
|
||||
raise HTTPException(
|
||||
status_code=403,
|
||||
detail="Nur Plattform-Administratoren dürfen Profile anlegen",
|
||||
)
|
||||
|
||||
email_norm = str(p.email).strip().lower()
|
||||
name_s = (p.name or "").strip()
|
||||
|
||||
pin_hash = hash_pin(secrets.token_urlsafe(24))
|
||||
|
||||
with get_db() as conn:
|
||||
cur = get_cursor(conn)
|
||||
cur.execute("""INSERT INTO profiles (id,name,avatar_color,sex,dob,height,goal_weight,goal_bf_pct,created,updated)
|
||||
VALUES (%s,%s,%s,%s,%s,%s,%s,%s,CURRENT_TIMESTAMP,CURRENT_TIMESTAMP)""",
|
||||
(pid,p.name,p.avatar_color,p.sex,p.dob,p.height,p.goal_weight,p.goal_bf_pct))
|
||||
with get_db() as conn:
|
||||
cur = get_cursor(conn)
|
||||
cur.execute("SELECT * FROM profiles WHERE id=%s", (pid,))
|
||||
return r2d(cur.fetchone())
|
||||
cur.execute(
|
||||
"SELECT id FROM profiles WHERE email IS NOT NULL AND lower(trim(email)) = %s",
|
||||
(email_norm,),
|
||||
)
|
||||
if cur.fetchone():
|
||||
raise HTTPException(status_code=409, detail="E-Mail bereits registriert")
|
||||
|
||||
cur.execute(
|
||||
"""
|
||||
INSERT INTO profiles (
|
||||
name, email, pin_hash, auth_type, role, tier,
|
||||
email_verified, created_at, updated_at
|
||||
)
|
||||
VALUES (%s, %s, %s, 'email', 'user', 'free', TRUE,
|
||||
CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)
|
||||
RETURNING id
|
||||
""",
|
||||
(name_s, email_norm, pin_hash),
|
||||
)
|
||||
row = cur.fetchone()
|
||||
new_id = row["id"] if row else None
|
||||
if new_id is None:
|
||||
raise HTTPException(status_code=500, detail="Profil konnte nicht angelegt werden")
|
||||
|
||||
return profile_document(str(new_id))
|
||||
|
||||
|
||||
def profile_document(pid: str) -> dict:
|
||||
|
||||
Reference in new issue
Block a user