def put(self, request, roomId, memberId, *args, **kwargs): user = fetch_user(request) if memberId != user.strId: return errors.PERMISSION_DENIED room = Room.find_by_id(str(roomId)).raise_if_cannot_join(user) user.enter_room(room).save() return OKResponse()
def delete(self, request, roomId, memberId, *args, **kwargs): user = fetch_user(request) if memberId != user.strId: return errors.PERMISSION_DENIED room = Room.find_by_id(str(roomId)) user.exit_room(room).save() room.destroy_if_created_by(user) return OKResponse()
def get(self, request, roomId, *args, **kwargs): includeCreatorProfile = request.GET.get('creator-profile', False) includeMemberProfile = request.GET.get('member-profile', False) includeMembers = includeMemberProfile or request.GET.get('members', False) room = Room.find_by_id(str(roomId)) return OKResponse(room.to_dict( includeCreatorProfile = includeCreatorProfile, includeMembers = includeMembers, includeMemberProfile = includeMemberProfile))
def put(self, request, roomId, memberId, *args, **kwargs): returnRoom = getBooleanParam(request, "return-room") if validate_master_key(request): user = User.find_by_id(memberId) else: user = fetch_user(request) if memberId != user.strId: return errors.PERMISSION_DENIED room = Room.find_by_id(str(roomId)).raise_if_cannot_join(user) user.enter_room(room).save() if not returnRoom: return OKResponse() else: return OKResponse( Room.find_by_id(str(roomId)).to_dict( includeCreatorProfile=True, includeMembers=True, includeMemberProfile=True ) )
def delete(self, request, roomId, memberId, *args, **kwargs): returnRoom = getBooleanParam(request, "return-room") if validate_master_key(request): user = User.find_by_id(memberId) else: user = fetch_user(request) if memberId != user.strId: return errors.PERMISSION_DENIED room = Room.find_by_id(str(roomId)) user.exit_room(room).save() if room.roomId is None or not returnRoom: # room.roomId is None only if exit_room deletes the room return OKResponse() else: return OKResponse( Room.find_by_id(str(roomId)).to_dict( includeCreatorProfile=True, includeMembers=True, includeMemberProfile=True ) )
def get(self, request, roomId, *args, **kwargs): includeCreatorProfile = getBooleanParam(request, "creator-profile") includeMemberProfile = getBooleanParam(request, "member-profile") includeMembers = includeMemberProfile or getBooleanParam(request, "members") room = Room.find_by_id(str(roomId)) return OKResponse( room.to_dict( includeCreatorProfile=includeCreatorProfile, includeMembers=includeMembers, includeMemberProfile=includeMemberProfile, ) )
def put(self, request, roomId, *args, **kwargs): """ If argument 'status' is playing, requires a 'proposer'. If argument 'status' is waiting, just ends the game blindly. """ if not validate_master_key(request): return errors.PERMISSION_DENIED args = sanitize_dict(parse_json(request.body), {"status": int}, {"proposer": basestring}) status, proposerId = args.get("status"), args.get("proposer") room = Room.find_by_id(roomId) print( "Room {} is created by {} and proposed to start by {}".format(room.roomId, room.creator.strId, proposerId) ) if status == STATUS_PLAYING and room.creator.strId != proposerId: return errors.PERMISSION_DENIED room.switch_status(status).save() return OKResponse()
def get(self, request, roomId, *args, **kwargs): includeMemberProfile = getBooleanParam(request, "member-profile") room = Room.find_by_id(str(roomId)) return OKResponse(room.to_dict(membersOnly=True, includeMemberProfile=includeMemberProfile))
def get(self, request, roomId, *args, **kwargs): includeMemberProfile = request.GET.get('member-profile', False) room = Room.find_by_id(str(roomId)) return OKResponse(room.to_dict( membersOnly = True, includeMemberProfile = includeMemberProfile));