Skip to content

Commit

Permalink
Merge pull request #3314 from betagouv/lucien/changer-sujet
Browse files Browse the repository at this point in the history
Permet de changer le sujet d'un besoin depuis une sollicitation
  • Loading branch information
clairezed authored Jan 29, 2024
2 parents 97df73f + 27f7abc commit 97c268b
Show file tree
Hide file tree
Showing 18 changed files with 152 additions and 40 deletions.
6 changes: 5 additions & 1 deletion app/controllers/conseiller/diagnoses/steps_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ def update_needs
diagnosis_params = params_for_needs
diagnosis_params[:step] = :matches
if @diagnosis.update(diagnosis_params)
redirect_to action: :matches
if params[:diagnosis][:submit] == 'return_solicitation_page'
redirect_to conseiller_solicitation_path(@diagnosis.solicitation)
else
redirect_to action: :matches
end
else
@themes = Theme.ordered_for_interview
flash.alert = @diagnosis.errors.full_messages.to_sentence
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/emails/solicitations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ class Emails::SolicitationsController < ApplicationController

def send_generic_email
email_type = ActionController::Base.helpers.sanitize(params[:email_type])
processor = CancelSolicitationWithEmail.new(@solicitation, email_type)
processor = SendSolicitationGenericEmail.new(@solicitation, email_type)
if processor.valid?
processor.cancel
processor.send_email
flash.notice = t('emails.sent')
else
flash.alert = t('emails.not_sent')
Expand Down
15 changes: 10 additions & 5 deletions app/front/stylesheets/utilities.sass
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,6 @@
.text-center
text-align: center

.bottom_actions
display: flex
justify-content: space-between

.justify-around
display: flex
justify-content: space-around
Expand Down Expand Up @@ -140,4 +136,13 @@ button.link
--underline-hover-width: var(--underline-max-width)

.fr-ml-auto-imp
margin-left: auto !important
margin-left: auto !important

.height-fit-content
height: fit-content

.bottom_actions
display: flex
justify-content: flex-end
&.space-between
justify-content: space-between
26 changes: 17 additions & 9 deletions app/helpers/solicitation_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,11 @@ def status_action_link(solicitation, new_status, classes = %w[])
end
end

def subject_tag(solicitation, classes = %[])
landing_subject = solicitation.landing_subject
if landing_subject.present?
title_components = {}
subject = landing_subject.subject
title_components[t('attributes.subject')] = subject
title = "#{t('attributes.subject')} : #{subject}"
path = new_solicitation_path(solicitation.landing.slug, solicitation.landing_subject.slug, anchor: 'section-breadcrumbs')
link_to landing_subject.title, path, class: classes, title: title
def subject_button(solicitation, classes = %[])
if solicitation.diagnosis.present? && solicitation.diagnosis.needs.present?
button_for_editable_subject(solicitation.diagnosis.needs.first, classes)
else
button_for_non_editable_subject(solicitation, classes)
end
end

Expand Down Expand Up @@ -75,4 +71,16 @@ def display_region(region, territory_params)
t('helpers.solicitation.localisation_html', region: region.name)
end
end

private

def button_for_editable_subject(need, classes)
title = t('helpers.solicitation.modify_subject', subject: need.subject)
path = needs_conseiller_diagnosis_path(need.diagnosis)
link_to need.subject.label, path, class: classes + ' fr-icon-settings-5-fill fr-btn--icon-right ', title: title
end

def button_for_non_editable_subject(solicitation, classes)
tag.button(class: classes, disabled: 'disabled') { solicitation.landing_subject.title }
end
end
3 changes: 3 additions & 0 deletions app/mailers/solicitation_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ class SolicitationMailer < ApplicationMailer

def bad_quality(solicitation)
@solicitation = solicitation
@landing_subject = LandingSubject.joins(landing_theme: :landings).find_by(subject: @solicitation.needs&.first&.subject, landings: [@solicitation.landing])
@landing_subject = @solicitation.landing_subject if @landing_subject.nil?

mail(to: solicitation.email, subject: t('mailers.solicitation.subject'))
end

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class CancelSolicitationWithEmail
class SendSolicitationGenericEmail
def initialize(solicitation, email_type)
@solicitation = solicitation
@email_type = email_type
Expand All @@ -8,7 +8,7 @@ def valid?
@email_type.present? && @solicitation.present? && Solicitation::GENERIC_EMAILS_TYPES.include?(@email_type.to_sym)
end

def cancel
def send_email
raise StandardError, I18n.t('errors.cancel_solicitation_with_email') unless valid?
@solicitation.update(badge_ids: @solicitation.badge_ids + [email_type_to_badge_id])
@solicitation.cancel!
Expand Down
6 changes: 2 additions & 4 deletions app/views/conseiller/diagnoses/steps/_next_step.haml
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
.text-right
= diagnosis_form.button :submit, class: 'fr-btn btn-green' do
= t('next_step')
%span.btn-icon.ri-arrow-right-s-line{ 'aria-hidden': 'true' }
= diagnosis_form.button :submit, class: 'fr-btn btn-green fr-btn--icon-right fr-icon-arrow-right-line' do
= t('next_step')
2 changes: 1 addition & 1 deletion app/views/conseiller/diagnoses/steps/contact.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@
.fr-input-wrap
= diagnosis_form.date_field(:happened_on, placeholder: t('.date_placeholder'), required: true, class: 'fr-input')

.bottom_actions.flex
.bottom_actions
= render 'next_step', diagnosis_form: diagnosis_form
2 changes: 1 addition & 1 deletion app/views/conseiller/diagnoses/steps/matches.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
.fr-callout
%p.fr-callout__text= t('.before_sending_emails')

.bottom_actions.flex
.bottom_actions.space-between
= link_to needs_conseiller_diagnosis_path(@diagnosis), class: 'fr-btn btn-blue fr-btn--icon-left', data: { turbo: false } do
%span.ri-arrow-left-line.fr-mr-1w{ 'aria-hidden': 'true' }
= t('previous_step')
Expand Down
14 changes: 8 additions & 6 deletions app/views/conseiller/diagnoses/steps/needs.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#needs-app
= form_with model: @diagnosis,
url: update_needs_conseiller_diagnosis_path,
data: { checkboxes_require_one_with: t(".select_at_least_one_need"), controller: "diagnosis-needs-step" },
data: { turbo: 'false', checkboxes_require_one_with: t(".select_at_least_one_need"), controller: "diagnosis-needs-step" },
local: true do |diagnosis_form|

%h1.fr-h2= Diagnosis.human_attribute_value(:step, :needs)
Expand Down Expand Up @@ -51,12 +51,14 @@
= filter_form.label :filter_value, I18n.t('false', scope: [:activerecord, :attributes, :additional_subject_questions, key], default: t('no').titleize), value: false, class: 'fr-label'
= need_form.text_area :content, placeholder: t('.need_content_placeholder'), rows: 2, class: 'fr-input'

.fr-mt-2w
.fr-mt-2w.bottom_actions
= render 'next_step', diagnosis_form: diagnosis_form

.bottom_actions.fr-mt-10v
= link_to contact_conseiller_diagnosis_path, class: 'fr-btn btn-blue fr-btn--icon-left', data: { turbo: false } do
.bottom_actions.space-between.fr-mt-10v
= link_to contact_conseiller_diagnosis_path, class: 'fr-btn fr-btn--icon-left height-fit-content', data: { turbo: false } do
%span.ri-arrow-left-line.fr-mr-1w{ 'aria-hidden': 'true' }
= t('previous_step')

= render 'next_step', diagnosis_form: diagnosis_form
.fr-btns-group--right.fr-btns-group--inline-md
= diagnosis_form.button :submit, value: 'return_solicitation_page', class: 'fr-btn fr-btn--secondary fr-btn-green fr-btn--icon-right fr-icon-arrow-go-back-line' do
= t('.save_and_return_solicitation_page')
= render 'next_step', diagnosis_form: diagnosis_form
2 changes: 1 addition & 1 deletion app/views/conseiller/solicitations/_solicitation.haml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
- if solicitation.landing_subject.present?
.item
= t('.landing_subjects')
= subject_tag(solicitation, "fr-badge fr-badge--blue-ecume")
= subject_button(solicitation, "fr-btn fr-btn--secondary fr-btn--sm")
= display_region(solicitation.region, params[:territory])

.card__meta
Expand Down
6 changes: 3 additions & 3 deletions app/views/mailers/solicitation_mailer/bad_quality.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

%p= t('mailers.hello')

%p= t('.intro_html', link_to_root: link_to(t('app_name'), root_url), solicitation_subject: @solicitation.landing_subject.title)
%p= t('.intro_html', link_to_root: link_to(t('app_name'), root_url), subject_title: @landing_subject.title)

%p= t('.for_better_taking_care_html')

- if @solicitation.landing_subject.description_explanation.present?
= @solicitation.landing_subject.description_explanation.html_safe
- if @landing_subject.description_explanation.present?
= @landing_subject.description_explanation.html_safe
- else
%ul
%li= t('.treasury_html')
Expand Down
2 changes: 1 addition & 1 deletion app/views/pages/_cta_button.haml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
= link_to '#scroll-section', class: 'fr-btn fr-btn--lg' do
= link_to '#scroll-section', 'data-turbo': 'false', class: 'fr-btn fr-btn--lg' do
%span.ri-phone-fill.fr-mr-1v{ 'aria-hidden': 'true' }
= t('cta_button')
2 changes: 1 addition & 1 deletion config/locales/mailers.fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ fr:
bad_quality:
complete_solicitation_html: "<a href='%{redirect_link}' target='_blank' class='response-btn'>Compléter ma demande</a>"
for_better_taking_care_html: 'Pour pouvoir vous aider, les conseillers ont impérativement besoin d’éléments de contexte :'
intro_html: Vous avez récemment déposé une demande sur le service public %{link_to_root} (ou un site partenaire) pour <strong>"%{solicitation_subject}"</strong>.
intro_html: Vous avez récemment déposé une demande sur le service public %{link_to_root} (ou un site partenaire) pour <strong>"%{subject_title}"</strong>.
investment_html: "<strong>pour votre projet d’investissement :</strong> type d’investissement, but et montant du besoin"
recruitment_html: "<strong>pour votre projet de recrutement :</strong> contexte du recrutement et type de contrat"
treasury_html: "<strong>pour votre problème de trésorerie :</strong> contexte des difficultés et montant du besoin"
Expand Down
2 changes: 2 additions & 0 deletions config/locales/views.fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ fr:
diagnosis_content_placeholder: 'Entrez des informations complémentaires concernant cette entreprise :'
diagnosis_content_subtitle: Informations générales sur cette entreprise
need_content_placeholder: Plus d’infos sur ce besoin
save_and_return_solicitation_page: Enregistrer et revenir à la sollicitation
select_at_least_one_need: Cochez au minimum un besoin identifié.
sitemap:
sitemap:
Expand Down Expand Up @@ -382,6 +383,7 @@ fr:
solicitation:
analysis_in_progress: Analyse en cours (%{step})
localisation_html: 'Localisation : <strong>%{region}</strong>'
modify_subject: 'Modifier le sujet : %{subject}'
uncategorisable_label: Inclassables
uncategorisable_value: uncategorisable
view_completed_analysis: Voir l’analyse réalisée
Expand Down
57 changes: 57 additions & 0 deletions spec/controllers/conseiller/diagnoses/steps_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,63 @@
end
end

describe 'POST #update_needs' do
let(:diagnosis) { create :diagnosis }
let(:need) { create(:need, diagnosis: diagnosis) }
let(:new_subject) { create(:subject) }

context 'normal workflow' do
let(:params) do
{
id: diagnosis.id,
diagnosis: {
needs_attributes: [
{
id: need.id,
subject_id: new_subject.id,
description: 'description'
}
]
}
}
end

it 'updates subject and redirect to matches step' do
post :update_needs, params: params
diagnosis.reload
expect(diagnosis.step).to eq 'matches'
expect(diagnosis.needs.first.subject).to eq new_subject
expect(response).to redirect_to matches_conseiller_diagnosis_path(diagnosis)
end
end

context 'Changes subject from solicitation page' do
let(:params) do
{
id: diagnosis.id,
diagnosis: {
submit: 'return_solicitation_page',
needs_attributes: [
{
id: need.id,
subject_id: new_subject.id,
description: 'description'
}
]
}
}
end

it 'updates the subject and redirect to solicitations page' do
post :update_needs, params: params
diagnosis.reload
expect(diagnosis.step).to eq 'matches'
expect(diagnosis.needs.first.subject).to eq new_subject
expect(response).to redirect_to conseiller_solicitation_path(diagnosis.solicitation)
end
end
end

describe 'GET #matches' do
subject(:request) { get :matches, params: { id: diagnosis.id } }

Expand Down
33 changes: 33 additions & 0 deletions spec/mailers/solicitation_mailer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,37 @@
it { expect(mail.header[:to].value).to eq solicitation.email }
end
end

describe '#bad_quality' do
let(:landing) { create :landing }
let!(:initial_subject) { create :subject }
let!(:initial_landing_theme) { create :landing_theme, landings: [landing] }
let!(:initial_landing_subject) { create :landing_subject, subject: initial_subject, description_explanation: "initial description", landing_theme: initial_landing_theme }
let!(:solicitation) { create :solicitation, landing_subject: initial_landing_subject, landing: landing }

subject(:mail) { described_class.bad_quality(solicitation).deliver_now }

context 'when need has been changed' do
let!(:second_landing_theme) { create :landing_theme, landings: [landing] }
let!(:second_landing_subject) { create :landing_subject, subject: second_subject, description_explanation: "second description", landing_theme: second_landing_theme }
let!(:second_subject) { create :subject }
let!(:need) { create :need_with_matches, solicitation: solicitation, subject: second_subject }

it_behaves_like 'an email'

it 'include new subject title and description' do
expect(mail.body.parts.first.body).not_to include initial_landing_subject.description_explanation
expect(mail.body.parts.first.body).not_to include initial_landing_subject.title
expect(mail.body.parts.first.body).to include second_landing_subject.description_explanation
expect(mail.body.parts.first.body).to include second_landing_subject.title
end
end

context 'when solicitation has no diagnosis' do
it 'include initial subject title and description' do
expect(mail.body.parts.first.body).to include initial_landing_subject.description_explanation
expect(mail.body.parts.first.body).to include initial_landing_subject.title
end
end
end
end
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# frozen_string_literal: true

require 'rails_helper'
describe CancelSolicitationWithEmail do
describe SendSolicitationGenericEmail do
before { ENV['APPLICATION_EMAIL'] = 'contact@mailrandom.fr' }

describe '#cancel' do
context 'with valid params' do
let(:solicitation) { create :solicitation, status: 'in_progress' }
let(:email_type) { :siret }

before { described_class.new(solicitation, email_type).cancel }
before { described_class.new(solicitation, email_type).send_email }

it do
expect(solicitation.badges.size).to eq 1
Expand All @@ -25,7 +25,7 @@
let(:email_type) { :tatayoyo }

it do
expect { described_class.new(solicitation, email_type).cancel }.to raise_error StandardError
expect { described_class.new(solicitation, email_type).send_email }.to raise_error StandardError
end
end
end
Expand Down

0 comments on commit 97c268b

Please sign in to comment.