Merge pull request #5270 from betagouv/dev

2020-06-16-01
This commit is contained in:
Paul Chavard 2020-06-16 17:08:07 +02:00 committed by GitHub
commit 97f3ef86b3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 185 additions and 49 deletions

View file

@ -167,18 +167,7 @@ module Instructeurs
def add_filter def add_filter
if params[:value].present? if params[:value].present?
filters = procedure_presentation.filters procedure_presentation.add_filter(statut, params[:field], params[:value])
table, column = params[:field].split('/')
label = find_field(table, column)['label']
filters[statut] << {
'label' => label,
'table' => table,
'column' => column,
'value' => params[:value]
}
procedure_presentation.update(filters: filters)
end end
redirect_back(fallback_location: instructeur_procedure_url(procedure)) redirect_back(fallback_location: instructeur_procedure_url(procedure))

View file

@ -1,4 +1,7 @@
class ApiEntreprise::ExercicesJob < ApiEntreprise::Job class ApiEntreprise::ExercicesJob < ApiEntreprise::Job
rescue_from(ApiEntreprise::API::BadFormatRequest) do |exception|
end
def perform(etablissement_id, procedure_id) def perform(etablissement_id, procedure_id)
etablissement = Etablissement.find(etablissement_id) etablissement = Etablissement.find(etablissement_id)
etablissement_params = ApiEntreprise::ExercicesAdapter.new(etablissement.siret, procedure_id).to_params etablissement_params = ApiEntreprise::ExercicesAdapter.new(etablissement.siret, procedure_id).to_params

View file

@ -1,6 +1,15 @@
class ApiEntreprise::Job < ApplicationJob class ApiEntreprise::Job < ApplicationJob
DEFAULT_MAX_ATTEMPTS_API_ENTREPRISE_JOBS = 5 DEFAULT_MAX_ATTEMPTS_API_ENTREPRISE_JOBS = 5
rescue_from(ApiEntreprise::API::ResourceNotFound) do |exception|
error(self, exception)
end
rescue_from(ApiEntreprise::API::BadFormatRequest) do |exception|
error(self, exception)
end
def max_attempts def max_attempts
ENV[MAX_ATTEMPTS_API_ENTREPRISE_JOBS].to_i || DEFAULT_MAX_ATTEMPTS_API_ENTREPRISE_JOBS ENV.fetch("MAX_ATTEMPTS_API_ENTREPRISE_JOBS", DEFAULT_MAX_ATTEMPTS_API_ENTREPRISE_JOBS).to_i
end end
end end

View file

@ -9,19 +9,11 @@ class ApplicationJob < ActiveJob::Base
Rails.logger.info("#{job.class.name} ended at #{Time.zone.now}") Rails.logger.info("#{job.class.name} ended at #{Time.zone.now}")
end end
rescue_from(ApiEntreprise::API::ResourceNotFound) do |exception|
error(self, exception)
end
rescue_from(ApiEntreprise::API::BadFormatRequest) do |exception|
error(self, exception)
end
def error(job, exception) def error(job, exception)
Raven.capture_exception(exception) Raven.capture_exception(exception)
end end
def max_attempts def max_attempts
ENV["MAX_ATTEMPTS_JOBS"].to_i || DEFAULT_MAX_ATTEMPTS_JOBS ENV.fetch("MAX_ATTEMPTS_JOBS", DEFAULT_MAX_ATTEMPTS_JOBS).to_i
end end
end end

View file

@ -173,8 +173,42 @@ class ProcedurePresentation < ApplicationRecord
dossiers.includes(relations_to_include) dossiers.includes(relations_to_include)
end end
def human_value_for_filter(filter)
if filter['table'] == 'type_de_champ'
type_de_champ = TypeDeChamp.find_by(id: filter['column'])
return type_de_champ.dynamic_type.filter_to_human(filter['value'])
end
filter['value']
end
def add_filter(statut, field, value)
if value.present?
updated_filters = self.filters
table, column = field.split('/')
label = find_field(table, column)['label']
if table == 'type_de_champ'
type_de_champ = TypeDeChamp.find_by(id: column)
value = type_de_champ.dynamic_type.human_to_filter(value)
end
updated_filters[statut] << {
'label' => label,
'table' => table,
'column' => column,
'value' => value
}
update(filters: updated_filters)
end
end
private private
def find_field(table, column)
fields.find { |c| c['table'] == table && c['column'] == column }
end
def check_allowed_displayed_fields def check_allowed_displayed_fields
displayed_fields.each do |field| displayed_fields.each do |field|
check_allowed_field(:displayed_fields, field) check_allowed_field(:displayed_fields, field)

View file

@ -23,4 +23,12 @@ class TypesDeChamp::TypeDeChampBase
def build_champ def build_champ
@type_de_champ.champ.build @type_de_champ.champ.build
end end
def filter_to_human(filter_value)
filter_value
end
def human_to_filter(human_value)
human_value
end
end end

View file

@ -1,2 +1,22 @@
class TypesDeChamp::YesNoTypeDeChamp < TypesDeChamp::CheckboxTypeDeChamp class TypesDeChamp::YesNoTypeDeChamp < TypesDeChamp::CheckboxTypeDeChamp
def filter_to_human(filter_value)
if filter_value == "true"
"oui"
elsif filter_value == "false"
"non"
else
filter_value
end
end
def human_to_filter(human_value)
human_value.downcase!
if human_value == "oui"
"true"
elsif human_value == "non"
"false"
else
human_value
end
end
end end

View file

@ -1,5 +1,5 @@
%span.dropdown.print-menu-opener %span.dropdown.print-menu-opener
%button.button.dropdown-button.icon-only{ title: 'imprimer' } %button.button.dropdown-button.icon-only{ title: 'imprimer', 'aria-label': 'imprimer' }
%span.icon.printer %span.icon.printer
%ul.print-menu.dropdown-content %ul.print-menu.dropdown-content
%li %li

View file

@ -100,7 +100,7 @@
%span.filter %span.filter
= link_to remove_filter_instructeur_procedure_path(@procedure, { statut: @statut, table: filter['table'], column: filter['column'], value: filter['value'] }) do = link_to remove_filter_instructeur_procedure_path(@procedure, { statut: @statut, table: filter['table'], column: filter['column'], value: filter['value'] }) do
%img.close-icon{ src: image_url("close.svg") } %img.close-icon{ src: image_url("close.svg") }
= "#{filter['label'].truncate(50)} : #{filter['value']}" = "#{filter['label'].truncate(50)} : #{@procedure_presentation.human_value_for_filter(filter)}"
%table.table.dossiers-table.hoverable %table.table.dossiers-table.hoverable
%thead %thead
%tr %tr

View file

@ -11,10 +11,10 @@
et incubé par et incubé par
= link_to "beta.gouv.fr", "https://beta.gouv.fr", title: "le site de Beta.gouv.fr" = link_to "beta.gouv.fr", "https://beta.gouv.fr", title: "le site de Beta.gouv.fr"
%li %li
= link_to "https://numerique.gouv.fr/", title: "DINUM" do = link_to "https://numerique.gouv.fr/", title: "DINUM", 'aria-label': 'DINUM' do
%span.footer-logo.footer-logo-dinum{ role: 'img', 'aria-label': 'DINUM' } %span.footer-logo.footer-logo-dinum{ role: 'img' }
= link_to "https://beta.gouv.fr", title: "le site de Beta.gouv.fr" do = link_to "https://beta.gouv.fr", title: "le site de Beta.gouv.fr", 'aria-label': 'beta.gouv.fr' do
%span.footer-logo.footer-logo-beta-gouv-fr{ role: 'img', 'aria-label': 'beta.gouv.fr' } %span.footer-logo.footer-logo-beta-gouv-fr{ role: 'img' }
%span.footer-logo.footer-logo-france{ role: 'img', 'aria-label': 'République Française' } %span.footer-logo.footer-logo-france{ role: 'img', 'aria-label': 'République Française' }
%li.footer-column %li.footer-column

View file

@ -12,7 +12,7 @@
.prologue .prologue
%p.mandatory-explanation %p.mandatory-explanation
Les champs avec un astérisque ( Les champs suivis dun astérisque (
%span.mandatory> * %span.mandatory> *
) sont obligatoires. ) sont obligatoires.
- if dossier.brouillon? - if dossier.brouillon?

View file

@ -6,11 +6,18 @@
.container .container
%h1.new-h1 Contact %h1.new-h1 Contact
.description
Contactez-nous via ce formulaire et nous vous répondrons dans les plus brefs délais.
Pensez bien à nous donner le plus d'informations possible pour que nous puissions vous aider au mieux
= form_tag contact_path, method: :post, multipart: true, class: 'form' do |f| = form_tag contact_path, method: :post, multipart: true, class: 'form' do |f|
.description
%p
Contactez-nous via ce formulaire et nous vous répondrons dans les plus brefs délais.
Pensez bien à nous donner le plus d'informations possible pour que nous puissions vous aider au mieux.
%br
%p.mandatory-explanation
Les champs suivis dun astérisque (
%span.mandatory *
) sont obligatoires.
- if !user_signed_in? - if !user_signed_in?
.contact-champ .contact-champ
= label_tag :email do = label_tag :email do
@ -28,7 +35,10 @@
.card-title .card-title
👉 Notre réponse 👉 Notre réponse
.card-content .card-content
%p Avez-vous bien vérifié que tous les champs obligatoires (*) sont bien remplis ? %p
Avez-vous bien vérifié que tous les champs obligatoires (
%span.mandatory *
) sont bien remplis ?
%p Si vous avez des questions sur les informations à saisir, contactez les services en charge de la démarche. %p Si vous avez des questions sur les informations à saisir, contactez les services en charge de la démarche.
%p %p
%a{ href: 'https://faq.demarches-simplifiees.fr/article/12-contacter-le-service-en-charge-de-ma-demarche' } %a{ href: 'https://faq.demarches-simplifiees.fr/article/12-contacter-le-service-en-charge-de-ma-demarche' }
@ -90,7 +100,7 @@
= text_area_tag :text, params[:text], rows: 6, required: true = text_area_tag :text, params[:text], rows: 6, required: true
.contact-champ .contact-champ
= label_tag :text do = label_tag :piece_jointe do
Pièce jointe Pièce jointe
%p.notice.hidden{ data: { 'contact-type-only': Helpscout::FormAdapter::TYPE_AMELIORATION } } %p.notice.hidden{ data: { 'contact-type-only': Helpscout::FormAdapter::TYPE_AMELIORATION } }
Une capture décran peut nous aider à identifier plus facilement lendroit à améliorer. Une capture décran peut nous aider à identifier plus facilement lendroit à améliorer.

View file

@ -16,7 +16,7 @@
- if dossier.can_be_updated_by_user? && !current_page?(modifier_dossier_path(dossier)) - if dossier.can_be_updated_by_user? && !current_page?(modifier_dossier_path(dossier))
= link_to "Modifier mon dossier", modifier_dossier_path(dossier), class: 'button accepted edit-form', 'title'=> "Vous pouvez modifier votre dossier tant qu'il n'est passé en instruction" = link_to "Modifier mon dossier", modifier_dossier_path(dossier), class: 'button accepted edit-form', 'title'=> "Vous pouvez modifier votre dossier tant qu'il n'est passé en instruction"
%span.dropdown.print-menu-opener %span.dropdown.print-menu-opener
%button.button.dropdown-button.icon-only{ title: 'imprimer' } %button.button.dropdown-button.icon-only{ title: 'imprimer', 'aria-label': 'imprimer' }
%span.icon.printer %span.icon.printer
%ul.print-menu.dropdown-content %ul.print-menu.dropdown-content
%li %li

View file

@ -0,0 +1,5 @@
class RemoveDossierProcedureId < ActiveRecord::Migration[5.2]
def change
remove_column :dossiers, :procedure_id
end
end

View file

@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2020_04_29_191305) do ActiveRecord::Schema.define(version: 2020_06_11_122406) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@ -238,7 +238,6 @@ ActiveRecord::Schema.define(version: 2020_04_29_191305) do
create_table "dossiers", id: :serial, force: :cascade do |t| create_table "dossiers", id: :serial, force: :cascade do |t|
t.boolean "autorisation_donnees" t.boolean "autorisation_donnees"
t.integer "procedure_id"
t.datetime "created_at" t.datetime "created_at"
t.datetime "updated_at" t.datetime "updated_at"
t.string "state" t.string "state"
@ -262,7 +261,6 @@ ActiveRecord::Schema.define(version: 2020_04_29_191305) do
t.index ["archived"], name: "index_dossiers_on_archived" t.index ["archived"], name: "index_dossiers_on_archived"
t.index ["groupe_instructeur_id"], name: "index_dossiers_on_groupe_instructeur_id" t.index ["groupe_instructeur_id"], name: "index_dossiers_on_groupe_instructeur_id"
t.index ["hidden_at"], name: "index_dossiers_on_hidden_at" t.index ["hidden_at"], name: "index_dossiers_on_hidden_at"
t.index ["procedure_id"], name: "index_dossiers_on_procedure_id"
t.index ["state"], name: "index_dossiers_on_state" t.index ["state"], name: "index_dossiers_on_state"
t.index ["user_id"], name: "index_dossiers_on_user_id" t.index ["user_id"], name: "index_dossiers_on_user_id"
end end

View file

@ -1,8 +1,9 @@
describe ProcedurePresentation do describe ProcedurePresentation do
let(:procedure) { create(:procedure, :with_type_de_champ, :with_type_de_champ_private) } let(:procedure) { create(:procedure, :with_type_de_champ, :with_type_de_champ_private) }
let(:assign_to) { create(:assign_to, procedure: procedure) } let(:assign_to) { create(:assign_to, procedure: procedure) }
let(:first_type_de_champ_id) { assign_to.procedure.types_de_champ.first.id.to_s } let(:first_type_de_champ) { assign_to.procedure.types_de_champ.first }
let (:procedure_presentation_id) { let(:first_type_de_champ_id) { first_type_de_champ.id.to_s }
let(:procedure_presentation) {
ProcedurePresentation.create( ProcedurePresentation.create(
assign_to: assign_to, assign_to: assign_to,
displayed_fields: [ displayed_fields: [
@ -10,10 +11,11 @@ describe ProcedurePresentation do
{ "label" => "test2", "table" => "type_de_champ", "column" => first_type_de_champ_id } { "label" => "test2", "table" => "type_de_champ", "column" => first_type_de_champ_id }
], ],
sort: { "table" => "user", "column" => "email", "order" => "asc" }, sort: { "table" => "user", "column" => "email", "order" => "asc" },
filters: { "a-suivre" => [], "suivis" => [{ "label" => "label1", "table" => "self", "column" => "created_at" }] } filters: filters
).id )
} }
let (:procedure_presentation) { ProcedurePresentation.find(procedure_presentation_id) } let(:procedure_presentation_id) { procedure_presentation.id }
let(:filters) { { "a-suivre" => [], "suivis" => [{ "label" => "label1", "table" => "self", "column" => "created_at" }] } }
describe "#displayed_fields" do describe "#displayed_fields" do
it { expect(procedure_presentation.displayed_fields).to eq([{ "label" => "test1", "table" => "user", "column" => "email" }, { "label" => "test2", "table" => "type_de_champ", "column" => first_type_de_champ_id }]) } it { expect(procedure_presentation.displayed_fields).to eq([{ "label" => "test1", "table" => "user", "column" => "email" }, { "label" => "test2", "table" => "type_de_champ", "column" => first_type_de_champ_id }]) }
@ -499,12 +501,14 @@ describe ProcedurePresentation do
let(:discarded_dossier) { create(:dossier, procedure: procedure) } let(:discarded_dossier) { create(:dossier, procedure: procedure) }
let(:type_de_champ) { procedure.types_de_champ.first } let(:type_de_champ) { procedure.types_de_champ.first }
context 'with single value' do
before do before do
kept_dossier.champs.find_by(type_de_champ: type_de_champ).update(value: 'keep me') kept_dossier.champs.find_by(type_de_champ: type_de_champ).update(value: 'keep me')
discarded_dossier.champs.find_by(type_de_champ: type_de_champ).update(value: 'discard me') discarded_dossier.champs.find_by(type_de_champ: type_de_champ).update(value: 'discard me')
end end
it { is_expected.to contain_exactly(kept_dossier.id) } it { is_expected.to contain_exactly(kept_dossier.id) }
end
context 'with multiple search values' do context 'with multiple search values' do
let(:filter) do let(:filter) do
@ -517,6 +521,8 @@ describe ProcedurePresentation do
let(:other_kept_dossier) { create(:dossier, procedure: procedure) } let(:other_kept_dossier) { create(:dossier, procedure: procedure) }
before do before do
kept_dossier.champs.find_by(type_de_champ: type_de_champ).update(value: 'keep me')
discarded_dossier.champs.find_by(type_de_champ: type_de_champ).update(value: 'discard me')
other_kept_dossier.champs.find_by(type_de_champ: type_de_champ).update(value: 'and me too') other_kept_dossier.champs.find_by(type_de_champ: type_de_champ).update(value: 'and me too')
end end
@ -524,6 +530,18 @@ describe ProcedurePresentation do
is_expected.to contain_exactly(kept_dossier.id, other_kept_dossier.id) is_expected.to contain_exactly(kept_dossier.id, other_kept_dossier.id)
end end
end end
context 'with yes_no type_de_champ' do
let(:filter) { [{ 'table' => 'type_de_champ', 'column' => type_de_champ.id.to_s, 'value' => 'true' }] }
let(:procedure) { create(:procedure, :with_yes_no) }
before do
kept_dossier.champs.find_by(type_de_champ: type_de_champ).update(value: 'true')
discarded_dossier.champs.find_by(type_de_champ: type_de_champ).update(value: 'false')
end
it { is_expected.to contain_exactly(kept_dossier.id) }
end
end end
context 'for type_de_champ_private table' do context 'for type_de_champ_private table' do
@ -864,4 +882,54 @@ describe ProcedurePresentation do
end end
end end
end end
describe "#human_value_for_filter" do
let(:filters) { { "suivis" => [{ "label" => "label1", "table" => "type_de_champ", "column" => first_type_de_champ_id, "value" => "true" }] } }
subject { procedure_presentation.human_value_for_filter(procedure_presentation.filters["suivis"].first) }
context 'when type_de_champ text' do
it 'should passthrough value' do
expect(subject).to eq("true")
end
end
context 'when type_de_champ yes_no' do
let(:procedure) { create(:procedure, :with_yes_no) }
it 'should transform value' do
expect(subject).to eq("oui")
end
end
end
describe "#add_filter" do
let(:filters) { { "suivis" => [] } }
context 'when type_de_champ yes_no' do
let(:procedure) { create(:procedure, :with_yes_no) }
it 'should downcase and transform value' do
procedure_presentation.add_filter("suivis", "type_de_champ/#{first_type_de_champ_id}", "Oui")
expect(procedure_presentation.filters).to eq({ "suivis" => [
{ "label" => first_type_de_champ.libelle, "table" => "type_de_champ", "column" => first_type_de_champ_id, "value" => "true" }
]
})
end
end
context 'when type_de_champ text' do
let(:filters) { { "suivis" => [] } }
it 'should passthrough value' do
procedure_presentation.add_filter("suivis", "type_de_champ/#{first_type_de_champ_id}", "Oui")
expect(procedure_presentation.filters).to eq({ "suivis" => [
{ "label" => first_type_de_champ.libelle, "table" => "type_de_champ", "column" => first_type_de_champ_id, "value" => "Oui" }
]
})
end
end
end
end end