Merge branch 'dev'

This commit is contained in:
gregoirenovel 2018-06-19 16:46:25 +02:00
commit cee12a1081
34 changed files with 348 additions and 147 deletions

View file

@ -111,3 +111,11 @@ $auth-breakpoint: $two-columns-breakpoint;
}
}
}
.identity-form {
@media (max-width: $two-columns-breakpoint) {
input[type=submit] {
margin-bottom: 2 * $default-padding;
}
}
}

View file

@ -23,6 +23,16 @@ h1 {
font-weight: bold;
}
h2 {
font-size: 30px;
margin-bottom: 15px;
border-bottom: 1px solid $border-grey;
}
strong {
font-weight: bold;
}
a {
color: $blue;
}

View file

@ -254,9 +254,11 @@
.send-wrapper {
text-align: right;
margin-top: 2 * $default-padding;
margin-bottom: 2 * $default-padding;
.send {
margin-bottom: $default-padding;
.button {
margin-bottom: 0;
}
}

View file

@ -4,13 +4,21 @@
@import "placeholders";
footer {
@include vertical-padding(72px);
background-color: $light-grey;
border-top: 1px solid $border-grey;
bottom: 0;
width: 100%;
}
.landing-footer {
@include vertical-padding(72px);
}
.dossier-footer {
@include vertical-padding(48px);
line-height: 24px;
}
.footer-columns {
@extend %horizontal-list;
justify-content: flex-start;
@ -36,6 +44,12 @@ footer {
margin: 0;
}
.footer-header {
font-size: 14px;
font-weight: bold;
margin-bottom: 10px;
}
.footer-link {
margin-bottom: 14px;
@ -79,3 +93,10 @@ footer {
text-decoration: none;
}
}
.footer-bottom-line {
margin-top: 30px;
margin-bottom: -30px;
text-align: center;
font-size: small;
}

View file

@ -7,82 +7,21 @@ class Champ < ApplicationRecord
delegate :libelle, :type_champ, :order_place, :mandatory?, :description, :drop_down_list, to: :type_de_champ
before_save :format_date_to_iso, if: Proc.new { type_champ == 'date' }
before_save :format_datetime, if: Proc.new { type_champ == 'datetime' }
before_save :multiple_select_to_string, if: Proc.new { type_champ == 'multiple_drop_down_list' }
scope :updated_since?, -> (date) { where('champs.updated_at > ?', date) }
scope :public_only, -> { where(private: false) }
scope :private_only, -> { where(private: true) }
PIECE_JUSTIFICATIVE_FILE_MAX_SIZE = 200.megabytes
PIECE_JUSTIFICATIVE_FILE_ACCEPTED_FORMATS = [
"application/pdf",
"application/msword",
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
"application/vnd.ms-excel",
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
"application/vnd.ms-powerpoint",
"application/vnd.openxmlformats-officedocument.presentationml.presentation",
"application/vnd.oasis.opendocument.text",
"application/vnd.oasis.opendocument.presentation",
"application/vnd.oasis.opendocument.spreadsheet",
"image/png",
"image/jpeg"
]
def public?
!private?
end
def same_hour?(num)
same_date? num, '%H'
end
def same_minute?(num)
same_date? num, '%M'
end
def mandatory_and_blank?
if type_champ == 'piece_justificative'
mandatory? && !piece_justificative_file.attached?
else
mandatory? && value.blank?
end
end
def same_date?(num, compare)
if type_champ == 'datetime' && value.present?
if value.to_datetime.strftime(compare) == num
return true
end
end
false
end
def self.regions
JSON.parse(Carto::GeoAPI::Driver.regions).sort_by { |e| e['nom'] }.pluck("nom")
end
def self.departements
JSON.parse(Carto::GeoAPI::Driver.departements).map { |liste| "#{liste['code']} - #{liste['nom']}" }.push('99 - Étranger')
end
def self.pays
JSON.parse(Carto::GeoAPI::Driver.pays).pluck("nom")
end
def to_s
if value.present?
case type_champ
when 'date'
Date.parse(value).strftime('%d/%m/%Y')
when 'multiple_drop_down_list'
drop_down_list.selected_options_without_decorator(self).join(', ')
else
value.to_s
end
string_value
else
''
end
@ -90,80 +29,19 @@ class Champ < ApplicationRecord
def for_export
if value.present?
case type_champ
when 'textarea'
ActionView::Base.full_sanitizer.sanitize(value)
when 'yes_no'
value == 'true' ? 'oui' : 'non'
when 'multiple_drop_down_list'
drop_down_list.selected_options_without_decorator(self).join(', ')
else
value
end
value_for_export
else
nil
end
end
def piece_justificative_file_errors
errors = []
if piece_justificative_file.attached? && piece_justificative_file.previous_changes.present?
if piece_justificative_file.blob.byte_size > PIECE_JUSTIFICATIVE_FILE_MAX_SIZE
errors << "Le fichier #{piece_justificative_file.filename.to_s} est trop lourd, il doit faire au plus #{PIECE_JUSTIFICATIVE_FILE_MAX_SIZE.to_s(:human_size, precision: 2)}"
end
if !piece_justificative_file.blob.content_type.in?(PIECE_JUSTIFICATIVE_FILE_ACCEPTED_FORMATS)
errors << "Le fichier #{piece_justificative_file.filename.to_s} est dans un format que nous n'acceptons pas"
end
# FIXME: add Clamav check
end
if errors.present?
piece_justificative_file.purge
end
errors
end
private
def format_date_to_iso
date = begin
Date.parse(value).iso8601
rescue
nil
end
self.value = date
def string_value
value.to_s
end
def format_datetime
if (value =~ /=>/).present?
date = begin
hash_date = YAML.safe_load(value.gsub('=>', ': '))
year, month, day, hour, minute = hash_date.values_at(1,2,3,4,5)
DateTime.new(year, month, day, hour, minute).strftime("%d/%m/%Y %H:%M")
rescue
nil
end
self.value = date
elsif /^\d{2}\/\d{2}\/\d{4}\s\d{2}:\d{2}$/.match?(value) # old browsers can send with dd/mm/yyyy hh:mm format
self.value = DateTime.parse(value, "%d/%m/%Y %H:%M").strftime("%Y-%m-%d %H:%M")
elsif !(/^\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}$/.match?(value)) # a datetime not correctly formatted should not be stored
self.value = nil
end
end
def multiple_select_to_string
if value.present?
json = JSON.parse(value)
if json == ['']
self.value = nil
else
json = json - ['']
self.value = json.to_s
end
end
def value_for_export
value
end
end

View file

@ -1,2 +1,18 @@
class Champs::DateChamp < Champ
before_save :format_before_save
private
def format_before_save
self.value =
begin
Date.parse(value).iso8601
rescue
nil
end
end
def string_value
Date.parse(value).strftime('%d/%m/%Y')
end
end

View file

@ -1,2 +1,34 @@
class Champs::DatetimeChamp < Champ
before_save :format_before_save
def same_hour?(num)
same_date?(num, '%H')
end
def same_minute?(num)
same_date?(num, '%M')
end
private
def same_date?(num, compare)
return value.present? && value.to_datetime.strftime(compare) == num
end
def format_before_save
if (value =~ /=>/).present?
self.value =
begin
hash_date = YAML.safe_load(value.gsub('=>', ': '))
year, month, day, hour, minute = hash_date.values_at(1,2,3,4,5)
DateTime.new(year, month, day, hour, minute).strftime("%d/%m/%Y %H:%M")
rescue
nil
end
elsif /^\d{2}\/\d{2}\/\d{4}\s\d{2}:\d{2}$/.match?(value) # old browsers can send with dd/mm/yyyy hh:mm format
self.value = DateTime.parse(value, "%d/%m/%Y %H:%M").strftime("%Y-%m-%d %H:%M")
elsif !(/^\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}$/.match?(value)) # a datetime not correctly formatted should not be stored
self.value = nil
end
end
end

View file

@ -1,2 +1,5 @@
class Champs::DepartementChamp < Champs::TextChamp
def self.departements
JSON.parse(Carto::GeoAPI::Driver.departements).map { |liste| "#{liste['code']} - #{liste['nom']}" }.push('99 - Étranger')
end
end

View file

@ -1,2 +1,25 @@
class Champs::MultipleDropDownListChamp < Champ
before_save :format_before_save
private
def format_before_save
if value.present?
json = JSON.parse(value)
if json == ['']
self.value = nil
else
json = json - ['']
self.value = json.to_s
end
end
end
def string_value
drop_down_list.selected_options_without_decorator(self).join(', ')
end
def value_for_export
drop_down_list.selected_options_without_decorator(self).join(', ')
end
end

View file

@ -1,2 +1,5 @@
class Champs::PaysChamp < Champs::TextChamp
def self.pays
JSON.parse(Carto::GeoAPI::Driver.pays).pluck("nom")
end
end

View file

@ -1,6 +1,51 @@
class Champs::PieceJustificativeChamp < Champ
after_commit :create_virus_scan
PIECE_JUSTIFICATIVE_FILE_MAX_SIZE = 200.megabytes
PIECE_JUSTIFICATIVE_FILE_ACCEPTED_FORMATS = [
"application/pdf",
"application/msword",
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
"application/vnd.ms-excel",
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
"application/vnd.ms-powerpoint",
"application/vnd.openxmlformats-officedocument.presentationml.presentation",
"application/vnd.oasis.opendocument.text",
"application/vnd.oasis.opendocument.presentation",
"application/vnd.oasis.opendocument.spreadsheet",
"image/png",
"image/jpeg"
]
def mandatory_and_blank?
mandatory? && !piece_justificative_file.attached?
end
def piece_justificative_file_errors
errors = []
if piece_justificative_file.attached? && piece_justificative_file.previous_changes.present?
if piece_justificative_file.blob.byte_size > PIECE_JUSTIFICATIVE_FILE_MAX_SIZE
errors << "Le fichier #{piece_justificative_file.filename.to_s} est trop lourd, il doit faire au plus #{PIECE_JUSTIFICATIVE_FILE_MAX_SIZE.to_s(:human_size, precision: 2)}"
end
if !piece_justificative_file.blob.content_type.in?(PIECE_JUSTIFICATIVE_FILE_ACCEPTED_FORMATS)
errors << "Le fichier #{piece_justificative_file.filename.to_s} est dans un format que nous n'acceptons pas"
end
# FIXME: add Clamav check
end
if errors.present?
piece_justificative_file.purge
end
errors
end
private
def create_virus_scan
if self.piece_justificative_file&.attachment&.blob.present?
VirusScan.where(champ: self).where.not(blob_key: self.piece_justificative_file.blob.key).delete_all

View file

@ -1,2 +1,5 @@
class Champs::RegionChamp < Champs::TextChamp
def self.regions
JSON.parse(Carto::GeoAPI::Driver.regions).sort_by { |e| e['nom'] }.pluck("nom")
end
end

View file

@ -1,2 +1,7 @@
class Champs::TextareaChamp < Champs::TextChamp
private
def value_for_export
ActionView::Base.full_sanitizer.sanitize(value)
end
end

View file

@ -1,2 +1,7 @@
class Champs::YesNoChamp < Champs::CheckboxChamp
private
def value_for_export
value == 'true' ? 'oui' : 'non'
end
end

View file

@ -30,8 +30,8 @@
= render partial: "layouts/flash_messages"
= yield
- if content_for?(:display_footer)
= render partial: "layouts/new_footer"
- if content_for?(:footer)
= content_for(:footer)
= render partial: "layouts/mailjet_newsletter"
= javascript_include_tag "new_design/application", "data-turbolinks-eval": false

View file

@ -16,6 +16,10 @@
= f.select :type_organisme, Service.type_organismes.keys.map { |key| [ I18n.t("type_organisme.#{key}"), key] }
%h2 Informations de contact
%p.explication Ces informations seront visibles par les utilisateurs du formulaire.
= f.label :email do
Courriel
%span.mandatory *

View file

@ -0,0 +1,39 @@
%footer.dossier-footer
.container
%ul.footer-columns
- service = dossier.procedure.service
- if service.present?
%li.footer-column
%h3.footer-header Cette démarche est gérée par :
%p
= service.nom
%br
= service.organisme
%br
= string_to_html(service.adresse)
%li.footer-column
%h3.footer-header Poser une question sur votre dossier :
%p
- if dossier.brouillon?
Par email :
= link_to service.email, "mailto:#{service.email}"
- else
Directement
= link_to "par la messagerie", users_dossier_recapitulatif_path(dossier)
%p
Par téléphone :
%a{ href: "tel:#{service.telephone}" }= service.telephone
%p
Horaires : #{ service.horaires.sub(/\S/, &:downcase) }
.footer-bottom-line
= link_to "Accessibilité", accessibilite_index_path, :class => "footer-link"
= link_to "CGU", CGU_URL, :class => "footer-link", :target => "_blank", rel: "noopener noreferrer"
= link_to "Mentions légales", MENTIONS_LEGALES_URL, :class => "footer-link", :target => "_blank", rel: "noopener noreferrer"
= link_to "Contact technique", "mailto:#{CONTACT_EMAIL}", :class => "footer-link"

View file

@ -1,3 +1,6 @@
- content_for :footer do
= render partial: "new_user/dossiers/footer", locals: { dossier: @dossier }
.two-columns
.columns-container
.column.preview
@ -11,7 +14,7 @@
.procedure-description
= h string_to_html(@dossier.procedure.description)
.column
.column.identity-form
= form_for @dossier.individual, url: update_identite_dossier_path(@dossier), html: { class: "form" } do |f|
%h1 Données d'identité

View file

@ -1,3 +1,6 @@
- content_for :footer do
= render partial: "new_user/dossiers/footer", locals: { dossier: @dossier }
.dossier-edit
.dossier-header
.container

View file

@ -1,6 +1,7 @@
%footer
%footer.landing-footer
.container
%ul.footer-columns
%li.footer-column
%ul.footer-logos
%li.footer-text

View file

@ -1,4 +1,5 @@
- content_for(:display_footer, true)
- content_for :footer do
= render partial: "root/footer"
.landing
.landing-panel.hero-panel

View file

@ -1,3 +1,3 @@
= form.select :value,
Champ.departements,
Champs::DepartementChamp.departements,
required: champ.mandatory?

View file

@ -1,3 +1,3 @@
= form.select :value,
Champ.pays,
Champs::PaysChamp.pays,
required: champ.mandatory?

View file

@ -1,3 +1,3 @@
= form.select :value,
Champ.regions,
Champs::RegionChamp.regions,
required: champ.mandatory?

View file

@ -1,2 +1,2 @@
= select_tag("champs['#{champ.id}']",
options_for_select(Champ.departements, selected: champ.object.value))
options_for_select(Champs::DepartementChamp.departements, selected: champ.object.value))

View file

@ -1,2 +1,2 @@
= select_tag("champs['#{champ.id}']",
options_for_select(Champ.pays, selected: champ.object.value))
options_for_select(Champs::PaysChamp.pays, selected: champ.object.value))

View file

@ -1,2 +1,2 @@
= select_tag("champs['#{champ.id}']",
options_for_select(Champ.regions, selected: champ.object.value))
options_for_select(Champs::RegionChamp.regions, selected: champ.object.value))

View file

@ -18,9 +18,15 @@ FactoryBot.define do
end
end
trait :with_service do
after(:build) do |dossier, _evaluator|
dossier.procedure.service = create(:service)
end
end
trait :for_individual do
after(:build) do |dossier, _evaluator|
dossier.individual = create :individual
dossier.individual = create(:individual)
dossier.save
end
end

View file

@ -20,6 +20,12 @@ FactoryBot.define do
end
end
trait :with_service do
after(:build) do |procedure, _evaluator|
procedure.service = create(:service)
end
end
trait :with_api_carto do
after(:build) do |procedure, _evaluator|
procedure.module_api_carto.use_api_carto = true

View file

@ -12,8 +12,8 @@ feature 'The user' do
# there are no extraneous input
# attached file works
scenario 'fill a dossier', js: true do
allow(Champ).to receive(:regions).and_return(['region1', 'region2']).at_least(:once)
allow(Champ).to receive(:departements).and_return(['dep1', 'dep2']).at_least(:once)
allow(Champs::RegionChamp).to receive(:regions).and_return(['region1', 'region2']).at_least(:once)
allow(Champs::DepartementChamp).to receive(:departements).and_return(['dep1', 'dep2']).at_least(:once)
log_in(user.email, password, procedure)

View file

@ -27,7 +27,7 @@ shared_examples 'champ_spec' do
end
describe '.departement', vcr: { cassette_name: 'call_geo_api_departements' } do
subject { Champ.departements }
subject { Champs::DepartementChamp.departements }
it { expect(subject).to include '99 - Étranger' }
end

View file

@ -0,0 +1,30 @@
describe 'new_user/dossiers/_footer.html.haml', type: :view do
let(:service) { create(:service) }
let(:dossier) {
dossier = create(:dossier)
dossier.procedure.service = service
return dossier
}
subject { render 'new_user/dossiers/footer.html.haml', dossier: dossier }
it "affiche les informations de contact" do
expect(subject).to have_text(service.nom)
expect(subject).to have_text(service.organisme)
expect(subject).to have_text(service.telephone)
end
it "affiche les liens usuels requis" do
expect(subject).to have_link("Accessibilité")
expect(subject).to have_link("CGU")
expect(subject).to have_link("Mentions légales")
end
context "quand le dossier n'a pas de service associé" do
let(:service) { nil }
it { is_expected.to have_selector("footer") }
it { is_expected.to have_link("Accessibilité") }
it { is_expected.not_to have_text('téléphone') }
end
end

View file

@ -0,0 +1,25 @@
require 'spec_helper'
describe 'new_user/dossiers/identite.html.haml', type: :view do
let(:dossier) { create(:dossier, :with_entreprise, :with_service, state: 'brouillon', procedure: create(:procedure, :with_api_carto, :with_two_type_de_piece_justificative, for_individual: true)) }
let(:footer) { view.content_for(:footer) }
before do
sign_in dossier.user
assign(:dossier, dossier)
end
context 'test de composition de la page' do
before do
render
end
it 'affiche les informations de la procédure' do
expect(rendered).to have_text(dossier.procedure.libelle)
end
it 'prépare le footer' do
expect(footer).to have_selector('footer')
end
end
end

View file

@ -0,0 +1,29 @@
require 'spec_helper'
describe 'new_user/dossiers/modifier.html.haml', type: :view do
let(:dossier) { create(:dossier, :with_entreprise, :with_service, state: 'brouillon', procedure: create(:procedure, :with_api_carto, :with_two_type_de_piece_justificative, for_individual: true)) }
let(:footer) { view.content_for(:footer) }
before do
sign_in dossier.user
assign(:dossier, dossier)
end
context 'test de composition de la page' do
before do
render
end
it 'affiche le libellé de la procédure' do
expect(rendered).to have_text(dossier.procedure.libelle)
end
it 'affiche les boutons de validation' do
expect(rendered).to have_selector('.send-wrapper')
end
it 'prépare le footer' do
expect(footer).to have_selector('footer')
end
end
end