|
|
@ -43,6 +43,10 @@ def add_player(game_name): |
|
|
|
def remove_player(game_name, username): |
|
|
|
def remove_player(game_name, username): |
|
|
|
game = get_game_if_owner(game_name) |
|
|
|
game = get_game_if_owner(game_name) |
|
|
|
user = User.query.filter(and_(User.name == username, User.games.contains(game))).first_or_404() |
|
|
|
user = User.query.filter(and_(User.name == username, User.games.contains(game))).first_or_404() |
|
|
|
|
|
|
|
if user.role_in_game(game) == Role.owner: |
|
|
|
|
|
|
|
if len([player for player in game.players if player.role == Role.owner]) < 2: |
|
|
|
|
|
|
|
flash("Can't remove only owner from game") |
|
|
|
|
|
|
|
return redirect(url_for('main.game_dashboard', game_name=game.name)) |
|
|
|
game.users.remove(user) |
|
|
|
game.users.remove(user) |
|
|
|
if not user.last_login: |
|
|
|
if not user.last_login: |
|
|
|
db.session.delete(user) |
|
|
|
db.session.delete(user) |
|
|
|