<commit_before>class CommentairesController < ApplicationController
  def index
    @facade = DossierFacades.new(
      params[:dossier_id],
      (current_gestionnaire || current_user).email,
      params[:champs_id]
    )
    render layout: false
  rescue ActiveRecord::RecordNotFound
    flash.alert = t('errors.messages.dossier_not_found')
    redirect_to url_for(controller: '/')
  end

  def create
    @commentaire = Commentaire.new
    @commentaire.champ = @commentaire.dossier.champs.find(params[:champ_id]) if params[:champ_id]

    dossier_id = params['dossier_id']
    if is_gestionnaire?
      @commentaire.email = current_gestionnaire.email
      @commentaire.dossier = current_gestionnaire.dossiers.find_by(id: dossier_id) || current_gestionnaire.avis.find_by!(dossier_id: dossier_id).dossier
      @commentaire.dossier.next_step! 'gestionnaire', 'comment'
    else
      @commentaire.email = current_user.email
      @commentaire.dossier = current_user.dossiers.find_by(id: dossier_id) || current_user.invites.find_by!(dossier_id: dossier_id).dossier
      @commentaire.dossier.next_step! 'user', 'comment' if current_user.email == @commentaire.dossier.user.email
    end

    unless params[:piece_justificative].nil?
      pj = PiecesJustificativesService.upload_one! @commentaire.dossier, current_user, params

      if pj.errors.empty?
        @commentaire.piece_justificative = pj
      else
        flash.alert = pj.errors.full_messages
      end
    end

    @commentaire.body = params['texte_commentaire']
    unless @commentaire.body.blank? && @commentaire.piece_justificative.nil?
      @commentaire.save unless flash.alert
    else
      flash.alert = "Veuillez rédiger un message ou ajouter une pièce jointe."
    end

    if is_gestionnaire?
      unless current_gestionnaire.follow? @commentaire.dossier
        current_gestionnaire.toggle_follow_dossier @commentaire.dossier
      end

      redirect_to url_for(controller: 'backoffice/dossiers', action: :show, id: params['dossier_id'])
    else
      if current_user.email != @commentaire.dossier.user.email
        invite = Invite.where(dossier: @commentaire.dossier, email: current_user.email).first
        redirect_to url_for(controller: 'users/dossiers/invites', action: :show, id: invite.id)
      else
        redirect_to users_dossier_recapitulatif_path(params['dossier_id'])
      end
    end
  end

  def is_gestionnaire?
    false
  end
end
<commit_msg>Follow: use follow instead of toggle_follow_dossier<commit_after>class CommentairesController < ApplicationController
  def index
    @facade = DossierFacades.new(
      params[:dossier_id],
      (current_gestionnaire || current_user).email,
      params[:champs_id]
    )
    render layout: false
  rescue ActiveRecord::RecordNotFound
    flash.alert = t('errors.messages.dossier_not_found')
    redirect_to url_for(controller: '/')
  end

  def create
    @commentaire = Commentaire.new
    @commentaire.champ = @commentaire.dossier.champs.find(params[:champ_id]) if params[:champ_id]

    dossier_id = params['dossier_id']
    if is_gestionnaire?
      @commentaire.email = current_gestionnaire.email
      @commentaire.dossier = current_gestionnaire.dossiers.find_by(id: dossier_id) || current_gestionnaire.avis.find_by!(dossier_id: dossier_id).dossier
      @commentaire.dossier.next_step! 'gestionnaire', 'comment'
    else
      @commentaire.email = current_user.email
      @commentaire.dossier = current_user.dossiers.find_by(id: dossier_id) || current_user.invites.find_by!(dossier_id: dossier_id).dossier
      @commentaire.dossier.next_step! 'user', 'comment' if current_user.email == @commentaire.dossier.user.email
    end

    unless params[:piece_justificative].nil?
      pj = PiecesJustificativesService.upload_one! @commentaire.dossier, current_user, params

      if pj.errors.empty?
        @commentaire.piece_justificative = pj
      else
        flash.alert = pj.errors.full_messages
      end
    end

    @commentaire.body = params['texte_commentaire']
    unless @commentaire.body.blank? && @commentaire.piece_justificative.nil?
      @commentaire.save unless flash.alert
    else
      flash.alert = "Veuillez rédiger un message ou ajouter une pièce jointe."
    end

    if is_gestionnaire?
      current_gestionnaire.follow(@commentaire.dossier)

      redirect_to url_for(controller: 'backoffice/dossiers', action: :show, id: params['dossier_id'])
    else
      if current_user.email != @commentaire.dossier.user.email
        invite = Invite.where(dossier: @commentaire.dossier, email: current_user.email).first
        redirect_to url_for(controller: 'users/dossiers/invites', action: :show, id: invite.id)
      else
        redirect_to users_dossier_recapitulatif_path(params['dossier_id'])
      end
    end
  end

  def is_gestionnaire?
    false
  end
end

{'fraction_non_alphanumeric': 0.09812022309440198, 'fraction_numerical': 0.0, 'mean_word_length': 3.827517447657029, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '120939', 'n_tokens_mistral': 1621, 'n_tokens_neox': 1549, 'n_words': 272}