Loading running_exercise/lib/team_action_handler.py +7 −5 Original line number Diff line number Diff line Loading @@ -8,6 +8,7 @@ from common_lib.exceptions import ( ) from common_lib.utils import ( has_role, get_model, ) from exercise.models import Team from exercise_definition.models import ( Loading @@ -15,9 +16,9 @@ from exercise_definition.models import ( Response, Content, InjectTypes, Channel, ) from running_exercise.graphql_inputs import UseToolInput from running_exercise.lib.exercise_cache import ExerciseCache from running_exercise.lib.milestone_handler import ( update_milestones, ) Loading @@ -32,7 +33,7 @@ from user.models import User def _parse_selected_tool(team: Team, tool_id: int) -> Tool: tool = ExerciseCache.get_tool(tool_id) tool = get_model(Tool, id=tool_id) if not has_role(team.role, tool.roles.split(" ")): raise RunningExerciseOperationException( Loading Loading @@ -89,7 +90,9 @@ def _handle_chosen_response( user=user, ) channel = ExerciseCache.get_channel(InjectTypes.TOOL, tool.definition_id) channel = get_model( Channel, team.exercise.definition.channels, type=InjectTypes.TOOL ) create_action_log(team, details, channel) Loading @@ -98,8 +101,7 @@ class TeamActionHandler: def perform_action( use_tool_input: UseToolInput, user: Optional[User] = None ) -> None: team = ExerciseCache.get_team(int(use_tool_input.team_id)) team.exercise.refresh_from_db(fields=["running"]) team = get_model(Team, id=int(use_tool_input.team_id)) if not team.exercise.running: raise RunningExerciseOperationException( "Cannot use a tool when the exercise is not running" Loading Loading
running_exercise/lib/team_action_handler.py +7 −5 Original line number Diff line number Diff line Loading @@ -8,6 +8,7 @@ from common_lib.exceptions import ( ) from common_lib.utils import ( has_role, get_model, ) from exercise.models import Team from exercise_definition.models import ( Loading @@ -15,9 +16,9 @@ from exercise_definition.models import ( Response, Content, InjectTypes, Channel, ) from running_exercise.graphql_inputs import UseToolInput from running_exercise.lib.exercise_cache import ExerciseCache from running_exercise.lib.milestone_handler import ( update_milestones, ) Loading @@ -32,7 +33,7 @@ from user.models import User def _parse_selected_tool(team: Team, tool_id: int) -> Tool: tool = ExerciseCache.get_tool(tool_id) tool = get_model(Tool, id=tool_id) if not has_role(team.role, tool.roles.split(" ")): raise RunningExerciseOperationException( Loading Loading @@ -89,7 +90,9 @@ def _handle_chosen_response( user=user, ) channel = ExerciseCache.get_channel(InjectTypes.TOOL, tool.definition_id) channel = get_model( Channel, team.exercise.definition.channels, type=InjectTypes.TOOL ) create_action_log(team, details, channel) Loading @@ -98,8 +101,7 @@ class TeamActionHandler: def perform_action( use_tool_input: UseToolInput, user: Optional[User] = None ) -> None: team = ExerciseCache.get_team(int(use_tool_input.team_id)) team.exercise.refresh_from_db(fields=["running"]) team = get_model(Team, id=int(use_tool_input.team_id)) if not team.exercise.running: raise RunningExerciseOperationException( "Cannot use a tool when the exercise is not running" Loading