32 lines
1.1 KiB
Python
32 lines
1.1 KiB
Python
"""Shared helpers for skill endpoints."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from enum import Enum
|
|
|
|
from fastapi import HTTPException, status
|
|
|
|
from ....schemas.skill import SkillTagResponse
|
|
from ....services.auth import has_any_role
|
|
|
|
|
|
def skill_tag_to_response(tag) -> SkillTagResponse:
|
|
return SkillTagResponse(
|
|
id=str(tag.id),
|
|
tenant_id=tag.tenant_id,
|
|
name=tag.name,
|
|
slug=tag.slug,
|
|
category=tag.category,
|
|
description=tag.description,
|
|
is_system=tag.is_system,
|
|
sort_order=tag.sort_order,
|
|
created_at=tag.created_at.isoformat() if tag.created_at else None,
|
|
updated_at=tag.updated_at.isoformat() if tag.updated_at else None,
|
|
)
|
|
|
|
|
|
def ensure_self_or_admin(*, current_user, target_user_id: int, detail: str) -> None:
|
|
current_role = current_user.role.value if isinstance(current_user.role, Enum) else current_user.role
|
|
if current_user.id != target_user_id and not has_any_role(str(current_role), ["OWNER", "REVIEWER"]):
|
|
raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail=detail)
|