Merge pull request #3750 from betagouv/dev

2019-04-04-01
This commit is contained in:
Pierre de La Morinerie 2019-04-04 15:11:41 +02:00 committed by GitHub
commit 746dbff3b4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 94 additions and 34 deletions

View file

@ -105,6 +105,10 @@
margin-top: $default-padding;
}
.answer-body p:not(:last-of-type) {
margin-bottom: $default-padding;
}
.avis-icon {
margin-right: $default-spacer;
}

View file

@ -195,7 +195,7 @@ class ApplicationController < ActionController::Base
def sentry_user
user = logged_user
{ id: user&.id, role: user&.class&.name || 'Guest' }.compact
{ id: user ? "#{user.class.name}##{user.id}" : 'Guest' }
end
def sentry_config
@ -205,6 +205,7 @@ class ApplicationController < ActionController::Base
key: sentry[:client_key],
enabled: sentry[:enabled],
environment: sentry[:environment],
browser: { modern: browser.modern? },
user: sentry_user
}
end

View file

@ -4,38 +4,39 @@ module Users
def commencer
@procedure = Procedure.publiees.find_by(path: params[:path])
if @procedure.blank?
flash.alert = "La démarche est inconnue, ou la création de nouveaux dossiers pour cette démarche est terminée."
return redirect_to root_path
end
return procedure_not_found if @procedure.blank?
render 'commencer/show'
end
def commencer_test
@procedure = Procedure.brouillons.find_by(path: params[:path])
if @procedure.blank?
flash.alert = "La démarche est inconnue, ou cette démarche nest maintenant plus en test."
return redirect_to root_path
end
return procedure_not_found if @procedure.blank?
render 'commencer/show'
end
def sign_in
store_user_location!
@procedure = Procedure.find_by(path: params[:path])
return procedure_not_found if @procedure.blank?
store_user_location!(@procedure)
redirect_to new_user_session_path
end
def sign_up
store_user_location!
@procedure = Procedure.find_by(path: params[:path])
return procedure_not_found if @procedure.blank?
store_user_location!(@procedure)
redirect_to new_user_registration_path
end
def france_connect
store_user_location!
@procedure = Procedure.find_by(path: params[:path])
return procedure_not_found if @procedure.blank?
store_user_location!(@procedure)
redirect_to france_connect_particulier_path
end
@ -45,8 +46,21 @@ module Users
private
def store_user_location!
def procedure_not_found
procedure = Procedure.find_by(path: params[:path])
if procedure&.archivee?
flash.alert = t('errors.messages.procedure_archived')
elsif procedure&.publiee?
flash.alert = t('errors.messages.procedure_not_draft')
else
flash.alert = t('errors.messages.procedure_not_found')
end
return redirect_to root_path
end
def store_user_location!(procedure)
store_location_for(:user, helpers.procedure_lien(procedure))
end
end

View file

@ -60,6 +60,12 @@ module ApplicationHelper
# rubocop:enable Rails/OutputSafety
end
def show_element(selector)
# rubocop:disable Rails/OutputSafety
raw("document.querySelector('#{selector}').classList.remove('hidden');")
# rubocop:enable Rails/OutputSafety
end
def disable_element(selector)
# rubocop:disable Rails/OutputSafety
raw("document.querySelector('#{selector}').disabled = true;")

View file

@ -1,14 +1,13 @@
import * as Sentry from '@sentry/browser';
const { key, enabled, user, environment } = gon.sentry || {};
const { key, enabled, user, environment, browser } = gon.sentry || {};
// We need to check for key presence here as we do not have a dsn for browser yet
if (enabled && key) {
Sentry.init({ dsn: key, environment });
if (user.email) {
Sentry.configureScope(scope => {
scope.setUser(user);
});
}
Sentry.configureScope(scope => {
scope.setUser(user);
scope.setExtra('browser', browser.modern ? 'modern' : 'legacy');
});
}

View file

@ -29,4 +29,5 @@
- else
%span.waiting En attente de réponse
= render partial: 'shared/piece_jointe/pj_link', locals: { object: avis, pj: avis.piece_justificative_file }
%p= avis.answer
.answer-body
= simple_format(avis.answer)

View file

@ -1,5 +1,3 @@
<%= render_flash(timeout: 5000, sticky: true) %>
<%= remove_element("#piece_justificative_#{@champ.id}") %>
let fileInputSelector = '<%= "#champs_#{@champ.id}" %>';
document.querySelector(fileInputSelector).classList.remove('hidden');
<%= show_element("#champs_#{@champ.id}") %>

View file

@ -188,6 +188,7 @@ fr:
connexion: "Erreur lors de la connexion à France Connect."
extension_white_list_error: "Le format de fichier de la pièce jointe n'est pas valide."
procedure_archived: "Cette démarche en ligne a été fermée, il n'est plus possible de déposer de dossier."
procedure_not_draft: "Cette démarche nest maintenant plus en brouillon."
cadastres_empty:
one: "Aucune parcelle cadastrale sur la zone séléctionnée"
other: "Aucune parcelle cadastrale sur les zones séléctionnées"

View file

@ -34,7 +34,7 @@ describe ApplicationController, type: :controller do
context 'when no one is logged in' do
it do
expect(Raven).to have_received(:user_context)
.with({ role: 'Guest' })
.with({ id: 'Guest' })
end
it do
@ -53,7 +53,7 @@ describe ApplicationController, type: :controller do
it do
expect(Raven).to have_received(:user_context)
.with({ id: current_user.id, role: 'User' })
.with({ id: "User##{current_user.id}" })
end
it do
@ -77,7 +77,7 @@ describe ApplicationController, type: :controller do
it do
expect(Raven).to have_received(:user_context)
.with({ id: current_user.id, role: 'User' })
.with({ id: "User##{current_user.id}" })
end
it do

View file

@ -87,6 +87,14 @@ describe Users::CommencerController, type: :controller do
it { expect(subject).to redirect_to(new_user_session_path) }
end
context 'when the path doesnt exist' do
subject { get :sign_in, params: { path: 'hello' } }
it 'redirects with an error message' do
expect(subject).to redirect_to(root_path)
end
end
end
describe '#sign_up' do
@ -111,6 +119,14 @@ describe Users::CommencerController, type: :controller do
it { expect(subject).to redirect_to(new_user_registration_path) }
end
context 'when the path doesnt exist' do
subject { get :sign_up, params: { path: 'hello' } }
it 'redirects with an error message' do
expect(subject).to redirect_to(root_path)
end
end
end
describe '#france_connect' do
@ -135,5 +151,13 @@ describe Users::CommencerController, type: :controller do
it { expect(subject).to redirect_to(france_connect_particulier_path) }
end
context 'when the path doesnt exist' do
subject { get :france_connect, params: { path: 'hello' } }
it 'redirects with an error message' do
expect(subject).to redirect_to(root_path)
end
end
end
end

View file

@ -19,5 +19,9 @@ FactoryBot.define do
avis.claimant = create :gestionnaire
end
end
trait :with_answer do
answer { "Mon avis se décompose en deux points :\n- La demande semble pertinente\n- Le demandeur remplit les conditions." }
end
end
end

View file

@ -1,3 +1,5 @@
require 'spec_helper'
describe 'gestionnaires/shared/avis/_list.html.haml', type: :view do
before { view.extend DossierHelper }
@ -5,16 +7,22 @@ describe 'gestionnaires/shared/avis/_list.html.haml', type: :view do
let(:gestionnaire) { create(:gestionnaire) }
let(:avis) { [create(:avis, claimant: gestionnaire)] }
let(:seen_at) { avis.first.created_at + 1.hour }
context "with a seen_at after avis created_at" do
let(:seen_at) { avis.first.created_at + 1.hour }
it { is_expected.to have_text(avis.first.introduction) }
it { is_expected.not_to have_css(".highlighted") }
it { is_expected.not_to have_css(".highlighted") }
end
context "with a seen_at after avis created_at" do
context 'with a seen_at before avis created_at' do
let(:seen_at) { avis.first.created_at - 1.hour }
it { is_expected.to have_css(".highlighted") }
end
context 'with an answer' do
let(:avis) { [create(:avis, :with_answer, claimant: gestionnaire)] }
it 'renders the answer formatted with newlines' do
expect(subject).to include(simple_format(avis.first.answer))
end
end
end