From 7b3755655dd4be5643dca259abebee50294e2ee5 Mon Sep 17 00:00:00 2001 From: Burathar Date: Wed, 29 Jul 2020 16:30:35 +0200 Subject: [PATCH] resole issue #19: make sure game keeps at least one owner --- app/main/routes_player.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/main/routes_player.py b/app/main/routes_player.py index 3cf4ca6..7620a58 100644 --- a/app/main/routes_player.py +++ b/app/main/routes_player.py @@ -43,6 +43,10 @@ def add_player(game_name): def remove_player(game_name, username): game = get_game_if_owner(game_name) 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) if not user.last_login: db.session.delete(user) @@ -69,7 +73,7 @@ def game_player(game_name, username): print(form.role.data) db.session.commit() return redirect(url_for('main.game_dashboard', game_name=game.name)) - return render_template('game_player.html', title=f'{user.name} in {game_name}', + return render_template('game_player.html', title=f'{user.name} in {game_name}', player=player, form=form, json=json, location_encoder=LocationEncoder) @bp.route('/game//catch_bunny', methods=['GET', 'POST'])