Merge pull request #4483 from tchak/fix-sentry-errors

Fix sentry errors
This commit is contained in:
Paul Chavard 2019-11-06 13:03:03 +01:00 committed by GitHub
commit 8ec6eb619d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 52 additions and 20 deletions

View file

@ -2,6 +2,7 @@ class API::V1::DossiersController < APIController
before_action :fetch_procedure_and_check_token
DEFAULT_PAGE_SIZE = 100
MAX_PAGE_SIZE = 1000
ORDER_DIRECTIONS = { 'asc' => :asc, 'desc' => :desc }
def index
@ -33,7 +34,12 @@ class API::V1::DossiersController < APIController
end
def per_page # inherited value from will_paginate
[params[:resultats_par_page]&.to_i || DEFAULT_PAGE_SIZE, 1000].min
resultats_par_page = params[:resultats_par_page]&.to_i
if resultats_par_page && resultats_par_page > 0
[resultats_par_page, MAX_PAGE_SIZE].min
else
DEFAULT_PAGE_SIZE
end
end
def fetch_procedure_and_check_token

View file

@ -48,8 +48,11 @@ module Users
end
def attestation
if dossier.attestation.pdf.attached?
if dossier.attestation&.pdf&.attached?
redirect_to url_for(dossier.attestation.pdf)
else
flash.notice = "L'attestation n'est plus disponible sur ce dossier."
redirect_to dossier_path(dossier)
end
end

View file

@ -595,14 +595,18 @@ class Procedure < ApplicationRecord
def move_type_de_champ_attributes(types_de_champ, type_de_champ, new_index)
old_index = types_de_champ.index(type_de_champ)
types_de_champ.insert(new_index, types_de_champ.delete_at(old_index))
.map.with_index do |type_de_champ, index|
{
id: type_de_champ.id,
libelle: type_de_champ.libelle,
order_place: index
}
end
if types_de_champ.delete_at(old_index)
types_de_champ.insert(new_index, type_de_champ)
.map.with_index do |type_de_champ, index|
{
id: type_de_champ.id,
libelle: type_de_champ.libelle,
order_place: index
}
end
else
[]
end
end
def before_publish

View file

@ -53,7 +53,7 @@ class TypesDeChamp::LinkedDropDownListTypeDeChamp < TypesDeChamp::TypeDeChampBas
def check_presence_of_primary_options
if !PRIMARY_PATTERN.match?(drop_down_list.options.second)
errors.add(libelle, "doit commencer par une entrée de menu primaire de la forme <code style='white-space: pre-wrap;'>--texte--</code>")
errors.add(libelle.presence || "La liste", "doit commencer par une entrée de menu primaire de la forme <code style='white-space: pre-wrap;'>--texte--</code>")
end
end

View file

@ -1,10 +1,11 @@
- champs = champ.rows.last
- index = (champ.rows.size - 1) * champs.size
%div{ class: "row row-#{champs.first.row}" }
- champs.each.with_index(index) do |champ, index|
= fields_for "#{attribute}[#{index}]", champ do |form|
= render partial: "shared/dossiers/editable_champs/editable_champ", locals: { champ: champ, form: form }
= form.hidden_field :id
= form.hidden_field :_destroy, disabled: true
%button.button.danger.remove-row
Supprimer
- if champs.present?
- index = (champ.rows.size - 1) * champs.size
%div{ class: "row row-#{champs.first.row}" }
- champs.each.with_index(index) do |champ, index|
= fields_for "#{attribute}[#{index}]", champ do |form|
= render partial: "shared/dossiers/editable_champs/editable_champ", locals: { champ: champ, form: form }
= form.hidden_field :id
= form.hidden_field :_destroy, disabled: true
%button.button.danger.remove-row
Supprimer

View file

@ -148,4 +148,22 @@ shared_examples 'type_de_champ_spec' do
expect(cloned_procedure.types_de_champ.first.types_de_champ).not_to be_empty
end
end
describe "linked_drop_down_list" do
let(:type_de_champ) { create(:type_de_champ_linked_drop_down_list) }
it 'should validate without label' do
type_de_champ.drop_down_list_value = 'toto'
expect(type_de_champ.validate).to be_falsey
messages = type_de_champ.errors.full_messages
expect(messages.size).to eq(1)
expect(messages.first.starts_with?("#{type_de_champ.libelle} doit commencer par")).to be_truthy
type_de_champ.libelle = ''
expect(type_de_champ.validate).to be_falsey
messages = type_de_champ.errors.full_messages
expect(messages.size).to eq(2)
expect(messages.last.starts_with?("La liste doit commencer par")).to be_truthy
end
end
end