feat: disallow non-members to list team members
This commit is contained in:
parent
11f3f9f440
commit
81d6a02229
@ -145,8 +145,22 @@ async def list_all_players():
|
|||||||
return session.exec(select(P)).all()
|
return session.exec(select(P)).all()
|
||||||
|
|
||||||
|
|
||||||
async def list_players(team_id: int):
|
async def list_players(
|
||||||
|
team_id: int, user: Annotated[Player, Depends(get_current_active_user)]
|
||||||
|
):
|
||||||
with Session(engine) as session:
|
with Session(engine) as session:
|
||||||
|
current_user = session.exec(
|
||||||
|
select(P)
|
||||||
|
.join(PlayerTeamLink)
|
||||||
|
.join(Team)
|
||||||
|
.where(Team.id == team_id, P.disabled == False, P.id == user.id)
|
||||||
|
).one_or_none()
|
||||||
|
if not current_user:
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=status.HTTP_400_BAD_REQUEST,
|
||||||
|
detail="you're not in this team",
|
||||||
|
)
|
||||||
|
|
||||||
players = session.exec(
|
players = session.exec(
|
||||||
select(P)
|
select(P)
|
||||||
.join(PlayerTeamLink)
|
.join(PlayerTeamLink)
|
||||||
@ -187,7 +201,6 @@ player_router.add_api_route(
|
|||||||
"/{team_id}/list",
|
"/{team_id}/list",
|
||||||
endpoint=list_players,
|
endpoint=list_players,
|
||||||
methods=["GET"],
|
methods=["GET"],
|
||||||
dependencies=[Depends(get_current_active_user)],
|
|
||||||
)
|
)
|
||||||
player_router.add_api_route(
|
player_router.add_api_route(
|
||||||
"/list",
|
"/list",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user