def delete(self, spreadsheet_id): spreadsheet = self._get_object(spreadsheet_id) db.delete(spreadsheet) current_app.logger.debug( "The qualifiers spreadsheet {0} has been deleted successfully.". format(spreadsheet_id)) return {}, 204
def wrapper_is_authorized(*args, **kwargs): if request.remote_addr == "127.0.0.1": if local: return func(*args, **kwargs) else: raise exceptions.Forbidden() session_token = request.headers.get("Authorization") if not session_token: raise exceptions.Unauthorized() token = db.query(Token).where( Token.session_token == session_token).first() if not token: raise exceptions.Unauthorized() if int(token.expiry_date) < int(time.time()): db.delete(token) current_app.logger.debug( "Token of the user {0} has expired".format( token.discord_user_id)) raise exceptions.Unauthorized() refresh_token_if_needed(token) g.token = token if user and token.token_type == "user": return exec_func_if_user_can_access_resource( func, *args, **kwargs) if client and token.token_type == "client": return func(*args, **kwargs) raise exceptions.Forbidden()
def delete(self, tournament_id, allowed_reschedule_id): if allowed_reschedule_id is None: return self.delete_all(tournament_id) allowed_reschedule = self._get_object(tournament_id, allowed_reschedule_id) db.delete(allowed_reschedule) current_app.logger.debug( "The allowed reschedule {0} for match id {1} has been deleted successfully." .format(allowed_reschedule_id, allowed_reschedule.match_id)) return {}, 204
def delete_all(self, tournament_id): try: allowed_reschedules = (db.query(AllowedReschedule).where( AllowedReschedule.tournament_id == tournament_id).where( **request.args.to_dict()).all()) except AttributeError: raise exceptions.BadRequest() for allowed_reschedule in allowed_reschedules: db.delete(allowed_reschedule) current_app.logger.debug( "The allowed reschedule {0} for match id {1} has been deleted successfully." .format(allowed_reschedule.id, allowed_reschedule.match_id)) return {}, 204
def _get_object(self, tournament_id, allowed_reschedule_id): allowed_reschedule = (db.query(AllowedReschedule).where( AllowedReschedule.tournament_id == tournament_id).where( AllowedReschedule.id == allowed_reschedule_id).first()) if not allowed_reschedule: raise exceptions.NotFound() now = datetime.datetime.utcnow() max_allowed_date = datetime.datetime.fromtimestamp( allowed_reschedule.created_at) + datetime.timedelta( hours=allowed_reschedule.allowed_hours) if now >= max_allowed_date: db.delete(allowed_reschedule) raise exceptions.NotFound() return allowed_reschedule
def delete_bracket_and_associated_spreadsheets(bracket): for spreadsheet_type, spreadsheet_class in Bracket.get_spreadsheet_types( ).items(): spreadsheet_id = getattr(bracket, spreadsheet_type + "_spreadsheet_id") if spreadsheet_id > 0: spreadsheet = db.query(spreadsheet_class).where( id=spreadsheet_id).first() if spreadsheet: db.delete(spreadsheet) current_app.logger.debug( "The {0} spreadsheet {1} has been deleted successfully.". format(spreadsheet_type.replace("_", " "), spreadsheet_id)) db.delete(bracket) current_app.logger.debug( "The bracket {0} has been deleted successfully.".format(bracket.id))
def delete(self, tournament_id): tournament = self._get_object(tournament_id) brackets = db.query(Bracket).where( Bracket.tournament_id == tournament_id).all() for bracket in brackets: delete_bracket_and_associated_spreadsheets(bracket) allowed_reschedules = db.query(AllowedReschedule).where( AllowedReschedule.tournament_id == tournament_id).all() for allowed_reschedule in allowed_reschedules: current_app.logger.debug( "The allowed reschedule {0} for the match id {1} has been deleted successfully." .format(allowed_reschedule.id, allowed_reschedule.match_id)) db.delete(allowed_reschedule) db.delete(tournament) current_app.logger.debug( "The tournament {0} has been deleted successfully.".format( tournament_id)) return {}, 204
def get_all(self, tournament_id): allowed_reschedules = (db.query(AllowedReschedule).where( AllowedReschedule.tournament_id == tournament_id).where( **request.args.to_dict()).all()) real_allowed_reschedules = [] now = datetime.datetime.utcnow() for allowed_reschedule in allowed_reschedules: max_allowed_date = datetime.datetime.fromtimestamp( allowed_reschedule.created_at) + datetime.timedelta( hours=allowed_reschedule.allowed_hours) if now >= max_allowed_date: db.delete(allowed_reschedule) else: real_allowed_reschedules.append(allowed_reschedule) return { "allowed_reschedules": [ allowed_reschedule.get_api_dict() for allowed_reschedule in real_allowed_reschedules ] }
def delete(self, user_id): user = self._get_object(user_id) db.delete(user) current_app.logger.debug( "The user {0} has been deleted successfully.".format(user_id)) return {}, 204
def delete(self, guild_id): guild = self._get_object(guild_id) db.delete(guild) current_app.logger.debug( "The guild {0} has been deleted successfully.".format(guild_id)) return {}, 204