def cancel_banned_bookings() -> None: logger.info("[CANCEL BANNED BOOKINGS] START") bookings_to_update = get_bookings_banned_and_sent() bookings_in_error = [] updated_bookings = [] for booking in bookings_to_update: booking.isCancelled = True booking.isUsed = False booking.dateUsed = None try: repository.save(booking) updated_bookings.append(booking.id) except ApiErrors as error: logger.exception("%s for booking %s", error.errors, booking.id) bookings_in_error.append(booking.id) logger.info("%i BOOKINGS UPDATED", len(updated_bookings)) logger.info("LIST OF UPDATED BOOKINGS") logger.info(updated_bookings) if len(bookings_in_error) > 0: logger.error("LIST OF BOOKINGS IN ERROR") logger.error(bookings_in_error) logger.info("[CANCEL BANNED BOOKINGS] END")
def retrieve_authenticated_user(*args, **kwargs): # type: ignore email = get_jwt_identity() user = find_user_by_email(email) if user is None or not user.isActive: logger.error("Authenticated user with email %s not found or inactive", email) raise ForbiddenError({"email": ["Utilisateur introuvable"]}) return route_function(user, *args, **kwargs)
def _delete_user_offerers_from_rows(csv_rows: Iterable) -> None: user_offerers_successful = [] user_offerers_in_error = [] csv_rows_iterable = iter(csv_rows) headers = next(csv_rows_iterable) for row in csv_rows_iterable: if _is_blank_row(row): continue row = dict(zip(headers, row)) user_id = row[USER_ID_COLUMN_HEADER] offerer_id = row[OFFERER_ID_COLUMN_HEADER] user_offerer = find_one_or_none_by_user_id_and_offerer_id( int(user_id), int(offerer_id)) if user_offerer is None: continue user_offerer_id = user_offerer.id logger.info( "[DELETE USER_OFFERERS FROM FILE] Suppression du rattachement pour le user d'id %s et l'offerer " "d'id %s est lancée", user_id, offerer_id, ) try: repository.delete(user_offerer) logger.info( "[DELETE USER_OFFERERS FROM FILE] Suppression du rattachement pour le user d'id %s et l'offerer " "d'id %s réussie", user_id, offerer_id, ) user_offerers_successful.append(user_offerer_id) except ApiErrors as error: logger.exception( "[DELETE USER_OFFERERS FROM FILE] %s pour le rattachement avec le user d'id %s et l'offerer d'id %s", error.errors, user_id, offerer_id, ) user_offerers_in_error.append(user_offerer_id) logger.info("[DELETE USER_OFFERERS FROM FILE] %i RATTACHEMENT SUPPRIMES", len(user_offerers_successful)) logger.info( "[DELETE USER_OFFERERS FROM FILE] LISTE DES RATTACHEMENT SUPPRIMES") logger.info(user_offerers_successful) if len(user_offerers_in_error) > 0: logger.error( "[DELETE USER_OFFERERS FROM FILE] LISTE DES RATTACHEMENTS EN ERREUR" ) logger.error(user_offerers_in_error)
def restize_internal_error(ie): if "check_stock" in str(ie.orig): if "quantity_too_low" in str(ie.orig): return ["quantity", "Le stock total ne peut être inférieur au nombre de réservations"] if "bookingLimitDatetime_too_late" in str(ie.orig): return [ "bookingLimitDatetime", "La date limite de réservation pour cette offre est postérieure à la date de début de l'évènement", ] logger.error("Unexpected error in patch stocks: %s", ie) return PcObject.restize_internal_error(ie)
def _process_error(error_messages: List[str], application_id: int, procedure_id: int) -> None: error = f"Le dossier {application_id} contient des erreurs et a été ignoré - Procedure {procedure_id}" logger.error("[BATCH][REMOTE IMPORT BENEFICIARIES] %s", error) error_messages.append(error) save_beneficiary_import_with_status( ImportStatus.ERROR, application_id, source=BeneficiaryImportSources.demarches_simplifiees, source_id=procedure_id, detail=error, )
def request_password_reset(user: User) -> None: if not user or not user.isActive: return reset_password_token = create_reset_password_token(user) is_email_sent = user_emails.send_reset_password_email_to_native_app_user( user.email, reset_password_token.value, reset_password_token.expirationDate ) if not is_email_sent: logger.error("Email service failure when user requested password reset for email '%s'", user.email) raise exceptions.EmailNotSent()
def _cancel_bookings_of_offers_from_rows(csv_rows: Iterable) -> None: offers_successful = [] offers_in_error = [] for row in csv_rows: if _is_header_or_blank_row(row): continue if _is_not_flagged_for_cancellation(row): continue offer_id = row[OFFER_ID_COLUMN_INDEX] offer_name = row[OFFER_NAME_COLUMN_INDEX] bookings_to_cancel = _get_bookings_from_offer(int(offer_id)) logger.info( "[CANCEL BOOKINGS OF EVENTS FROM FILE] Annulation des réservations de l'offre '%s' d'id %s lancée", offer_name, offer_id, ) for booking in bookings_to_cancel: booking.isCancelled = True booking.isUsed = False booking.dateUsed = None try: repository.save(*bookings_to_cancel) logger.info( "[CANCEL BOOKINGS OF EVENTS FROM FILE] Annulation des réservations de l'offre '%s' d'id %s réussie", offer_name, offer_id, ) offers_successful.append(offer_id) except ApiErrors as error: logger.exception( "[CANCEL BOOKINGS OF EVENTS FROM FILE] %s pour l'offre d'id %s", error.errors, offer_id) offers_in_error.append(offer_id) logger.info("[CANCEL BOOKINGS OF EVENTS FROM FILE] %i OFFRES ANNULÉES", len(offers_successful)) logger.info( "[CANCEL BOOKINGS OF EVENTS FROM FILE] LISTE DES OFFRES MISES À JOUR") logger.info(offers_successful) if len(offers_in_error) > 0: logger.error( "[CANCEL BOOKINGS OF EVENTS FROM FILE] LISTE DES OFFRES EN ERREUR") logger.error(offers_in_error)