<commit_before>module Manager
  class ProceduresController < Manager::ApplicationController
    #
    # Administrate overrides
    #

    # Override this if you have certain roles that require a subset
    # this will be used to set the records shown on the `index` action.
    def scoped_resource
      if unfiltered_list?
        # Don't display discarded demarches in the unfiltered list…
        Procedure.kept
      else
        # … but allow them to be searched and displayed.
        Procedure.with_discarded
      end
    end

    def whitelist
      procedure.whitelist!
      flash[:notice] = "Démarche whitelistée."
      redirect_to manager_procedure_path(procedure)
    end

    def discard
      procedure.discard_and_keep_track!(current_administration)

      logger.info("La démarche #{procedure.id} est supprimée par #{current_administration.email}")
      flash[:notice] = "La démarche #{procedure.id} a été supprimée."

      redirect_to manager_procedure_path(procedure)
    end

    def restore
      procedure.restore(current_administration)

      flash[:notice] = "La démarche #{procedure.id} a été restauré."

      redirect_to manager_procedure_path(procedure)
    end

    def export_mail_brouillons
      dossiers = procedure.dossiers.state_brouillon
      emails = dossiers.map { |d| d.user.email }.sort
      date = Time.zone.now.strftime('%d-%m-%Y')
      send_data(emails.join("\n"), :filename => "brouillons-#{procedure.id}-au-#{date}.csv")
    end

    def add_administrateur
      administrateur = Administrateur.by_email(params[:email])
      if administrateur
        procedure.administrateurs << administrateur
        flash[:notice] = "L'administrateur \"#{params[:email]}\" est ajouté à la démarche."
      else
        flash[:alert] = "L'administrateur \"#{params[:email]}\" est introuvable."
      end
      redirect_to manager_procedure_path(procedure)
    end
<commit_msg>unique emails + remove n+1<commit_after>module Manager
  class ProceduresController < Manager::ApplicationController
    #
    # Administrate overrides
    #

    # Override this if you have certain roles that require a subset
    # this will be used to set the records shown on the `index` action.
    def scoped_resource
      if unfiltered_list?
        # Don't display discarded demarches in the unfiltered list…
        Procedure.kept
      else
        # … but allow them to be searched and displayed.
        Procedure.with_discarded
      end
    end

    def whitelist
      procedure.whitelist!
      flash[:notice] = "Démarche whitelistée."
      redirect_to manager_procedure_path(procedure)
    end

    def discard
      procedure.discard_and_keep_track!(current_administration)

      logger.info("La démarche #{procedure.id} est supprimée par #{current_administration.email}")
      flash[:notice] = "La démarche #{procedure.id} a été supprimée."

      redirect_to manager_procedure_path(procedure)
    end

    def restore
      procedure.restore(current_administration)

      flash[:notice] = "La démarche #{procedure.id} a été restauré."

      redirect_to manager_procedure_path(procedure)
    end

    def export_mail_brouillons
      dossiers = procedure.dossiers.state_brouillon.includes(:user)
      emails = dossiers.map { |d| d.user.email }.sort.uniq
      date = Time.zone.now.strftime('%d-%m-%Y')
      send_data(emails.join("\n"), :filename => "brouillons-#{procedure.id}-au-#{date}.csv")
    end

    def add_administrateur
      administrateur = Administrateur.by_email(params[:email])
      if administrateur
        procedure.administrateurs << administrateur
        flash[:notice] = "L'administrateur \"#{params[:email]}\" est ajouté à la démarche."
      else
        flash[:alert] = "L'administrateur \"#{params[:email]}\" est introuvable."
      end
      redirect_to manager_procedure_path(procedure)
    end

{'fraction_non_alphanumeric': 0.09389549922400414, 'fraction_numerical': 0.0002586652871184687, 'mean_word_length': 3.092063492063492, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1453323', 'n_tokens_mistral': 1171, 'n_tokens_neox': 1120, 'n_words': 283}