Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed get_avatar_id_from_user_id() to get_avatar_id_from_user() #779

Merged
merged 5 commits into from
Sep 3, 2018
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions aimmo/game_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""

from django.shortcuts import render, get_object_or_404
from django.contrib.auth.models import User
from aimmo import app_settings, exceptions
from models import Game

Expand Down Expand Up @@ -55,19 +56,18 @@ def _connection_on_k8s_mode(game_port):
return game_port == 0


def get_avatar_id_from_user_id(user_id, game_id):
def get_avatar_id_from_user(user, game_id):
"""
A helper function which will return an avatar ID that is assigned to a
particular django user owner in a game.
:param user_id: A django user ID taken from the request.
:param user: A django user object taken from the request.
:param game_id: The game ID in which the avatar is being requested from.
:return: An integer containing the avatar_ID.
"""
game = get_object_or_404(Game, id=game_id)

if not game.can_user_play(user_id):
if not game.can_user_play(user):
raise exceptions.UserCannotPlayGameException

avatar = game.avatar_set.get(owner=user_id)
avatar = game.avatar_set.get(owner=user.id)

return avatar.id
1 change: 0 additions & 1 deletion aimmo/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ def test_current_avatar_api_for_non_existant_game(self):

def test_current_avatar_api_for_unauthorised_games(self):
self.game.public = False
self.game.can_play = [self.user]
self.game.save()
c = self.login()
response = c.get(reverse('aimmo/current_avatar_in_game', kwargs={'game_id': 1}))
Expand Down
4 changes: 2 additions & 2 deletions aimmo/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def connection_parameters(request, game_id):
env_connection_settings = game_renderer.get_environment_connection_settings(game_id)

try:
avatar_id = game_renderer.get_avatar_id_from_user_id(user_id=request.user.id,
avatar_id = game_renderer.get_avatar_id_from_user(user=request.user,
game_id=game_id)
except UserCannotPlayGameException:
LOGGER.warning('HTTP 401 returned. User {} unauthorised to play.'.format(request.user.id))
Expand Down Expand Up @@ -196,7 +196,7 @@ def add_game(request):
def current_avatar_in_game(request, game_id):

try:
avatar_id = game_renderer.get_avatar_id_from_user_id(user_id=request.user.id,
avatar_id = game_renderer.get_avatar_id_from_user(user=request.user,
game_id=game_id)
except UserCannotPlayGameException:
LOGGER.warning('HTTP 401 returned. User {} unauthorised to play.'.format(request.user.id))
Expand Down