Skip to content

Instantly share code, notes, and snippets.

@cosminstefanxp
Created December 18, 2014 15:38
Show Gist options
  • Save cosminstefanxp/bd882baa5eb902d5eb2b to your computer and use it in GitHub Desktop.
Save cosminstefanxp/bd882baa5eb902d5eb2b to your computer and use it in GitHub Desktop.
Index: api.py
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- api.py (date 1418894206000)
+++ api.py (revision )
@@ -135,8 +135,8 @@
with_layout=False), 200
@post('/games/<int:id>/cancel', is_player_required=True)
- def cancel_challenge(player, session, id):
- game = session.query(Game).get(id)
+ def cancel_game(player, session, id):
+ game = session.query(Game).with_lockmode("update").get(id)
if game is None:
raise GameDoesNotExist
if game.finished_by:
@@ -145,9 +145,9 @@
if game.player != player:
logger.error('cancel notchallenger g#%d p#%d' % (game.id, player.id))
raise InvalidArgumentError('you\'re not the challenger')
- if game.kind != 'invited':
- logger.error('cancel notachallenge g#%d p#%d' % (game.id, player.id))
- raise InvalidArgumentError('this game is not a challenge')
+ if game.kind != 'invited' and game.opponent_id is not None:
+ logger.error('cancel notopengame g#%d p#%d' % (game.id, player.id))
+ raise InvalidArgumentError('this game is not a challenge or an open game')
if game.acceptedness == "cancelled":
logger.error('cancel alreadycancelled g#%d p#%d' % (game.id, player.id))
raise InvalidArgumentError('this game is already cancelled')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment