Merge pull request #6340 from betagouv/main

2021-07-13-01
This commit is contained in:
Kara Diaby 2021-07-13 16:00:12 +02:00 committed by GitHub
commit 832fbb8795
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 40 additions and 7 deletions

View file

@ -12,6 +12,7 @@ gem 'anchored'
gem 'bcrypt'
gem 'bootsnap', '>= 1.4.4', require: false # Reduces boot times through caching; required in config/boot.rb
gem 'browser'
gem 'charlock_holmes'
gem 'chartkick'
gem 'chunky_png'
gem 'clamav-client', require: 'clamav/client'

View file

@ -155,6 +155,7 @@ GEM
marcel (~> 1.0)
nokogiri (~> 1.10, >= 1.10.4)
rubyzip (>= 1.3.0, < 3)
charlock_holmes (0.7.7)
chartkick (3.4.2)
childprocess (3.0.0)
choice (0.2.0)
@ -793,6 +794,7 @@ DEPENDENCIES
capybara-email
capybara-screenshot
capybara-selenium
charlock_holmes
chartkick
chunky_png
clamav-client

View file

@ -170,7 +170,10 @@ module NewAdministrateur
redirect_to admin_procedure_groupe_instructeurs_path(procedure)
else
groupes_emails = CSV.new(group_csv_file.read.force_encoding("UTF-8"), headers: true, header_converters: :downcase)
file = group_csv_file.read
# find the original encoding to avoid encoding errors
base_encoding = CharlockHolmes::EncodingDetector.detect(file)
groupes_emails = CSV.new(file.encode("UTF-8", base_encoding[:encoding], invalid: :replace, replace: ""), headers: true, header_converters: :downcase)
.map { |r| r.to_h.slice('groupe', 'email') }
groupes_emails_has_keys = groupes_emails.first.has_key?("groupe") && groupes_emails.first.has_key?("email")

View file

@ -48,6 +48,9 @@ export function useMapStyle(
const enabledLayers = Object.entries(layers).filter(
([, { enabled }]) => enabled
);
const layerIds = enabledLayers.map(
([layer, { opacity }]) => `${layer}-${opacity}`
);
const style = useMemo(
() =>
getMapStyle(
@ -57,13 +60,10 @@ export function useMapStyle(
enabledLayers.map(([layer, { opacity }]) => [layer, opacity])
)
),
[
styleId,
enabledLayers.map(([layer, { opacity }]) => `${layer}-${opacity}`)
]
[styleId, layerIds]
);
useEffect(() => onStyleChange(), [styleId, cadastreEnabled]);
useEffect(() => onStyleChange(), [styleId, layerIds, cadastreEnabled]);
return { style, layers, setStyle, setLayerEnabled, setLayerOpacity };
}

View file

@ -22,6 +22,8 @@ class ProcedurePresentation < ApplicationRecord
TYPE_DE_CHAMP = 'type_de_champ'
TYPE_DE_CHAMP_PRIVATE = 'type_de_champ_private'
FILTERS_VALUE_MAX_LENGTH = 100
belongs_to :assign_to, optional: false
delegate :procedure, to: :assign_to
@ -30,6 +32,7 @@ class ProcedurePresentation < ApplicationRecord
validate :check_allowed_sort_column
validate :check_allowed_sort_order
validate :check_allowed_filter_columns
validate :check_filters_max_length
def fields
fields = [
@ -282,6 +285,14 @@ class ProcedurePresentation < ApplicationRecord
end
end
def check_filters_max_length
filters.values.flatten.each do |filter|
if filter['value']&.length.to_i > FILTERS_VALUE_MAX_LENGTH
errors.add(:filters, :too_long)
end
end
end
def field_hash(label, table, column)
{
'label' => label,

View file

@ -86,7 +86,7 @@
= select_tag :field, options_for_select(@displayed_fields_options)
%br
= label_tag :value, "Valeur"
= text_field_tag :value
= text_field_tag :value, nil, maxlength: ProcedurePresentation::FILTERS_VALUE_MAX_LENGTH
= hidden_field_tag :statut, @statut
%br
= submit_tag "Ajouter le filtre", class: 'button'

View file

@ -365,6 +365,16 @@ describe NewAdministrateur::GroupeInstructeursController, type: :controller do
it { expect(flash.alert).to eq("Import terminé. Cependant les emails suivants ne sont pas pris en compte: kara") }
end
context 'when the content of csv contains special characters' do
let(:csv_file) { fixture_file_upload('spec/fixtures/files/groupe_avec_caracteres_speciaux.csv', 'text/csv') }
before { subject }
it { expect(procedure.groupe_instructeurs.pluck(:label)).to eq(["défaut", "Auvergne-Rhône-Alpes", "Vendée"]) }
it { expect(flash.notice).to be_present }
it { expect(flash.notice).to eq("La liste des instructeurs a été importée avec succès") }
end
context 'when the csv file length is more than 1 mo' do
let(:csv_file) { fixture_file_upload('spec/fixtures/files/groupe-instructeur.csv', 'text/csv') }

View file

@ -0,0 +1,5 @@
Email,Groupe
kara@beta.gouv.fr,Auvergne-Rhône-Alpes
camilya@beta.gouv.fr,Vendée
philippe@beta.gouv.fr,Auvergne-Rhône-Alpes
sim@beta.gouv.fr,Vendée
1 Email Groupe
2 kara@beta.gouv.fr Auvergne-Rhône-Alpes
3 camilya@beta.gouv.fr Vendée
4 philippe@beta.gouv.fr Auvergne-Rhône-Alpes
5 sim@beta.gouv.fr Vendée

View file

@ -45,6 +45,7 @@ describe ProcedurePresentation do
context 'of filters' do
it { expect(build(:procedure_presentation, filters: { "suivis" => [{ "table" => "user", "column" => "reset_password_token", "order" => "asc" }] })).to be_invalid }
it { expect(build(:procedure_presentation, filters: { "suivis" => [{ "table" => "user", "column" => "email", "value" => "A" * 200 }] })).to be_invalid }
end
end