feat: enhance role permissions and UI for clubs and training planning
- Updated role permissions to allow trainers and users to create clubs and training groups. - Modified database insertion logic to reflect the correct role for trainers during registration. - Enhanced frontend components to display appropriate messages and buttons based on user roles. - Improved user guidance in the Clubs and Training Planning pages, emphasizing the need for clubs and groups before planning training sessions.
This commit is contained in:
1 parent
1f2a4595cd
commit
69b26fc928
5 files changed
+136
-50
No files matched your search
@@ -14,6 +14,11 @@ from auth import require_auth
|
||||
router = APIRouter(prefix="/api", tags=["training_planning"])
|
||||
|
||||
|
||||
def _has_planning_role(role: Optional[str]) -> bool:
|
||||
"""Kann Trainingseinheiten/Vorlagen anlegen (bis Governance: auch einfacher Account)."""
|
||||
return role in ("admin", "superadmin", "trainer", "user")
|
||||
|
||||
|
||||
def _optional_positive_int(val, field_name: str) -> Optional[int]:
|
||||
if val is None or val == "":
|
||||
return None
|
||||
@@ -50,7 +55,7 @@ def _can_access_group_for_create(cur, group_id: int, profile_id: int, role: str)
|
||||
if not group:
|
||||
raise HTTPException(status_code=404, detail="Trainingsgruppe nicht gefunden")
|
||||
co_trainers = group["co_trainer_ids"] or []
|
||||
if role not in ["admin", "superadmin", "trainer"]:
|
||||
if not _has_planning_role(role):
|
||||
raise HTTPException(status_code=403, detail="Nur Trainer dürfen Trainingseinheiten erstellen")
|
||||
if role not in ["admin", "superadmin"]:
|
||||
if group["trainer_id"] != profile_id and profile_id not in co_trainers:
|
||||
@@ -381,7 +386,7 @@ def get_training_plan_template(template_id: int, session=Depends(require_auth)):
|
||||
def create_training_plan_template(data: dict, session=Depends(require_auth)):
|
||||
profile_id = session["profile_id"]
|
||||
role = session.get("role")
|
||||
if role not in ["admin", "superadmin", "trainer"]:
|
||||
if not _has_planning_role(role):
|
||||
raise HTTPException(status_code=403, detail="Nur Trainer dürfen Vorlagen anlegen")
|
||||
name = (data.get("name") or "").strip()
|
||||
if not name:
|
||||
@@ -787,7 +792,7 @@ def quick_create_training_unit(data: dict, session=Depends(require_auth)):
|
||||
role = session.get("role")
|
||||
co_trainers = group["co_trainer_ids"] or []
|
||||
|
||||
if role not in ["admin", "superadmin", "trainer"]:
|
||||
if not _has_planning_role(role):
|
||||
raise HTTPException(status_code=403, detail="Nur Trainer dürfen Trainingseinheiten erstellen")
|
||||
|
||||
if role not in ["admin", "superadmin"]:
|
||||
|
||||
Reference in new issue
Block a user