Skip to content

Commit

Permalink
added check for full game are accessible
Browse files Browse the repository at this point in the history
  • Loading branch information
ychebyshev committed Mar 14, 2024
1 parent e264b6f commit c3b8e2f
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions shvatka/core/games/interactors.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from shvatka.core.interfaces.clients.file_storage import FileGateway
from shvatka.core.interfaces.dal.complex import GameFileLoader
from shvatka.core.models import dto
from shvatka.core.rules.game import check_can_read
from shvatka.core.services.scenario.files import check_file_meta_can_read
from shvatka.core.utils import exceptions

Expand All @@ -13,18 +14,19 @@ def __init__(self, dao: GameFileLoader, file_gateway: FileGateway):
self.dao = dao

async def __call__(self, guid: str, game_id: int, user: dto.User) -> BinaryIO:
author = await self.dao.get_by_user(user)
player = await self.dao.get_by_user(user)
game = await self.dao.get_full(game_id)
check_can_read(game, player)
if guid not in game.get_guids():
raise exceptions.FileNotFound(
text=f"There is no file with uuid {guid} associated with game id {game_id}",
game_id=game_id,
game=game,
user_id=user.db_id,
user=user,
player_id=author.id,
player=author,
player_id=player.id,
player=player,
)
meta = await self.dao.get_by_guid(guid)
check_file_meta_can_read(author, meta, game)
check_file_meta_can_read(player, meta, game)
return await self.file_gateway.get(meta)

0 comments on commit c3b8e2f

Please sign in to comment.