Skip to content

Commit

Permalink
Merge tag '2024-05-16-01' into feature/import-2024-05-16
Browse files Browse the repository at this point in the history
==> update DN and piece justificative to enable update via stable id

# Conflicts:
#	Gemfile.lock
#	app/components/editable_champ/editable_champ_component/editable_champ_component.html.haml
#	app/components/editable_champ/siret_component/siret_component.html.haml
#	config/database.yml
#	config/initializers/flipper.rb
#	config/routes.rb
  • Loading branch information
maatinito committed Aug 28, 2024
2 parents faf15f3 + 1d2550e commit a1f1bf2
Show file tree
Hide file tree
Showing 40 changed files with 263 additions and 116 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ GEM
net-smtp (0.4.0.1)
net-protocol
nio4r (2.7.1)
nokogiri (1.16.4-x86_64-linux)
nokogiri (1.16.5-x86_64-linux)
racc (~> 1.4)
openid_connect (2.3.0)
activemodel
Expand Down
1 change: 0 additions & 1 deletion app/assets/stylesheets/procedure_admin.scss
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

.container {
a {
cursor: pointer;
overflow-wrap: break-word;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
= form_for @dossier, url: update_identite_dossier_path(@dossier), html: { id: 'identite-form', class: "form", "data-controller" => "for-tiers" } do |f|
= f.hidden_field :for_tiers
- if for_tiers?
.fr-alert.fr-alert--info.fr-mb-2w
%p.fr-notice__text
Expand Down
8 changes: 8 additions & 0 deletions app/components/editable_champ/carte_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,12 @@ def initialize(**args)

@autocomplete_component = EditableChamp::ComboSearchComponent.new(**args)
end

def update_path
if Champ.update_by_stable_id?
champs_carte_features_path(@champ.dossier, @champ.stable_id, row_id: @champ.row_id)
else
champs_legacy_carte_features_path(@champ)
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
= react_component("MapEditor",
{ featureCollection: @champ.to_feature_collection,
champId: @champ.input_id,
url: champs_carte_features_path(@champ),
url: update_path,
options: @champ.render_options,
autocompleteAnnounceTemplateId: @autocomplete_component.announce_template_id,
autocompleteScreenReaderInstructions: t("combo_search_component.screen_reader_instructions") },
Expand Down
12 changes: 10 additions & 2 deletions app/components/editable_champ/editable_champ_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,17 @@ def stimulus_values

def turbo_poll_url_value
if @champ.private?
annotation_instructeur_dossier_path(@champ.dossier.procedure, @champ.dossier, @champ)
if Champ.update_by_stable_id?
annotation_instructeur_dossier_path(@champ.dossier.procedure, @champ.dossier, @champ.stable_id, row_id: @champ.row_id, with_public_id: true)
else
annotation_instructeur_dossier_path(@champ.dossier.procedure, @champ.dossier, @champ)
end
else
champ_dossier_path(@champ.dossier, @champ)
if Champ.update_by_stable_id?
champ_dossier_path(@champ.dossier, @champ.stable_id, row_id: @champ.row_id, with_public_id: true)
else
champ_dossier_path(@champ.dossier, @champ)
end
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@

= render Dsfr::InputStatusMessageComponent.new(errors_on_attribute: champ_component.errors_on_attribute?, error_full_messages: champ_component.error_full_messages, describedby_id: @champ.describedby_id, champ: @champ)

= @form.hidden_field :id, value: @champ.id
- if Champ.update_by_stable_id?
= @form.hidden_field :with_public_id, value: 'true'
- else
= @form.hidden_field :id, value: @champ.id

- if has_champ_revisions?
%div{ class: 'dropdown revision-dropdown', data: { controller: 'menu-button' } }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,12 @@ def dsfr_input_classname
def dsfr_champ_container
@champ.render_as_checkboxes? ? :fieldset : :div
end

def update_path(option)
if Champ.update_by_stable_id?
champs_options_path(@champ.dossier, @champ.stable_id, row_id: @champ.row_id, option:)
else
champs_legacy_options_path(@champ, option:)
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
- if @champ.selected_options.present?
.fr-mb-2w.fr-mt-2w{ "data-turbo": "true" }
- @champ.selected_options.each do |option|
= render NestedForms::OwnedButtonComponent.new(formaction: champs_options_path(@champ.id, option:), http_method: :delete, opt: { aria: {pressed: true }, class: 'fr-tag fr-tag-bug fr-mb-1w fr-mr-1w', id: @champ.checkbox_id(option) }) do
= render NestedForms::OwnedButtonComponent.new(formaction: update_path(option), http_method: :delete, opt: { aria: {pressed: true }, class: 'fr-tag fr-tag-bug fr-mb-1w fr-mr-1w', id: @champ.checkbox_id(option) }) do
= option
- if @champ.unselected_options.present?
= @form.select :value, @champ.unselected_options, { selected: '', include_blank: false, prompt: t('.prompt') }, id: @champ.input_id, aria: { describedby: @champ.describedby_id }, class: 'fr-select fr-mt-2v'
7 changes: 7 additions & 0 deletions app/components/editable_champ/numero_dn_component.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
class EditableChamp::NumeroDnComponent < EditableChamp::EditableChampBaseComponent
def update_path
if Champ.update_by_stable_id?
champs_dn_path(@champ.dossier, @champ.stable_id, row_id: @champ.row_id)
else
champs_legacy_dn_path(@champ)
end
end
end
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.numero-dn{ data: { controller: 'numero-dn', numero_dn_url_value: champs_dn_path(@champ.id) } }
.numero-dn{ data: { controller: 'numero-dn', numero_dn_url_value: update_path } }
%span
= @form.label :numero_dn, "DN"
= @form.text_field :numero_dn,
Expand Down
8 changes: 8 additions & 0 deletions app/components/editable_champ/rna_component.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
class EditableChamp::RNAComponent < EditableChamp::EditableChampBaseComponent
def dsfr_input_classname
'fr-input'
end

def update_path
if Champ.update_by_stable_id?
champs_rna_path(@champ.dossier, @champ.stable_id, row_id: @champ.row_id)
else
champs_legacy_rna_path(@champ)
end
end
end
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
= @form.text_field(:value, input_opts( id: @champ.input_id, aria: { describedby: @champ.describedby_id }, data: { controller: 'turbo-input', turbo_input_load_on_connect_value: @champ.prefilled? && @champ.value.present? && @champ.data.blank?, turbo_input_url_value: champs_rna_path(@champ.id) }, required: @champ.required?, pattern: "W[0-9]{9}", class: "width-33-desktop", maxlength: 10))
= @form.text_field(:value, input_opts( id: @champ.input_id, aria: { describedby: @champ.describedby_id }, data: { controller: 'turbo-input', turbo_input_load_on_connect_value: @champ.prefilled? && @champ.value.present? && @champ.data.blank?, turbo_input_url_value: update_path }, required: @champ.required?, pattern: "W[0-9]{9}", class: "width-33-desktop", maxlength: 10))

.rna-info{ id: dom_id(@champ, :rna_info) }
= render 'shared/champs/rna/association', champ: @champ, error: nil
10 changes: 9 additions & 1 deletion app/components/editable_champ/siret_component.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class EditableChamp::SiretComponent < EditableChamp::EditableChampBaseComponent
def dsfr_input_classname
'fr-input'
end
end

def hint_id
dom_id(@champ, :siret_info)
Expand All @@ -10,4 +10,12 @@ def hint_id
def hintable?
true
end

def update_path
if Champ.update_by_stable_id?
champs_siret_path(@champ.dossier, @champ.stable_id, row_id: @champ.row_id)
else
champs_legacy_siret_path(@champ)
end
end
end
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
= @form.text_field(:value, input_opts(id: @champ.input_id, aria: { describedby: @champ.describedby_id }, data: { controller: 'turbo-input', turbo_input_load_on_connect_value: @champ.prefilled? && @champ.value.present? && @champ.etablissement.blank?, turbo_input_url_value: champs_siret_path(@champ.id) }, required: @champ.required?, pattern: "[A-Z0-9][0-9]{5}", class: "width-33-desktop", maxlength: 14))
= @form.text_field(:value, input_opts(id: @champ.input_id, aria: { describedby: @champ.describedby_id }, data: { controller: 'turbo-input', turbo_input_load_on_connect_value: @champ.prefilled? && @champ.value.present? && @champ.etablissement.blank?, turbo_input_url_value: update_path }, required: @champ.required?, pattern: "[A-Z0-9][0-9]{5}", class: "width-33-desktop", maxlength: 14))
.siret-info{ id: dom_id(@champ, :siret_info) }
- if @champ.etablissement.present? && @champ.etablissement.siret.length == 9 && @champ.etablissement.siret == @champ.value.sub('-', "")
= render EditableChamp::EtablissementTitreComponent.new(etablissement: @champ.etablissement)
Expand Down
8 changes: 8 additions & 0 deletions app/components/procedure/email_template_card_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,12 @@ def edited?
def edit_path
edit_admin_procedure_mail_template_path(@email_template.procedure, @email_template.class.const_get(:SLUG))
end

def final_decision_templates
[Mails::WithoutContinuationMail.const_get(:SLUG), Mails::RefusedMail.const_get(:SLUG), Mails::ClosedMail.const_get(:SLUG)]
end

def not_editable?
@email_template.procedure.accuse_lecture? && final_decision_templates.include?(@email_template.class.const_get(:SLUG))
end
end
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
= render Dsfr::CardVerticalComponent.new(title: title, desc: desc, error: error, tags: [tag]) do |c|
- c.with_footer_button do
= link_to 'Modifier', edit_path, class: 'fr-btn'
- if not_editable?
%a{ role: "link", "aria-disabled" => "true", class: 'fr-link fr-icon-arrow-right-line fr-link--icon-right' }
Modifier
- else
= link_to 'Modifier', edit_path, class: 'fr-link fr-icon-arrow-right-line fr-link--icon-right'
5 changes: 1 addition & 4 deletions app/controllers/champs/numero_dn_controller.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
class Champs::NumeroDnController < ApplicationController
before_action :authenticate_logged_user!

class Champs::NumeroDnController < Champs::ChampController
def show
@champ = policy_scope(Champ).find(params[:champ_id])
@dn = params[:dn]
@ddn = params[:ddn]

Expand Down
1 change: 1 addition & 0 deletions app/controllers/champs/options_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ class Champs::OptionsController < Champs::ChampController

def remove
@champ.remove_option([params[:option]].compact, true)
@champ.reload
@dossier = @champ.private? ? nil : @champ.dossier
champs_attributes = { @champ.public_id => params[:champ_id].present? ? { id: @champ.id } : { with_public_id: true } }
@to_show, @to_hide, @to_update = champs_to_turbo_update(champs_attributes, @champ.dossier.champs)
Expand Down
22 changes: 13 additions & 9 deletions app/controllers/champs/piece_justificative_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ def show
end

def download_path
champs_piece_justificative_download_path({ champ_id: params[:champ_id], h: params[:h], i: "0" })
if params[:dossier_id].present?
champs_piece_justificative_download_path({ dossier_id: params[:dossier_id], stable_id: params[:stable_id], row_id: params[:row_id], h: params[:h], i: "0" })
else
champs_legacy_piece_justificative_download_path({ champ_id: params[:champ_id], h: params[:h], i: "0" })
end
end

def update
Expand All @@ -27,7 +31,7 @@ def download
if (0..@champ.piece_justificative_file.size).cover?(index)
blob = @champ.piece_justificative_file[index]
if blob.filename.extension == 'pdf' && @champ.dossier.procedure.feature_enabled?(:qrcoded_pdf)
send_data StampService.new.stamp(blob, download_url(@champ, index)), filename: blob.filename.to_s, type: 'application/pdf'
send_data StampService.new.stamp(blob, TypesDeChamp::PieceJustificativeTypeDeChamp.download_url(@champ, index)), filename: blob.filename.to_s, type: 'application/pdf'
else
redirect_to blob.url, status: :found, allow_other_host: true
end
Expand All @@ -41,12 +45,6 @@ def download
end
end

def download_url(champ, index)
Rails.application.routes.url_helpers.champs_piece_justificative_download_url(
{ champ_id: champ.id, h: champ.encoded_date(:created_at), i: index }
)
end

def template
redirect_to @champ.type_de_champ.piece_justificative_template.blob
end
Expand Down Expand Up @@ -74,7 +72,13 @@ def find_champ
h = params[:h]
return super if h.blank?

champ = Champ.find(params[:champ_id])
champ = if params[:champ_id].present?
Champ.find(params[:champ_id])
else
dossier = Dossier.includes(:champs, revision: [:types_de_champ]).find(params[:dossier_id])
type_de_champ = dossier.find_type_de_champ_by_stable_id(params[:stable_id])
dossier.champ_for_export(type_de_champ, params_row_id)
end
champ&.match_encoded_date?(:created_at, h) ? champ : nil
end
end
5 changes: 3 additions & 2 deletions app/controllers/instructeurs/dossiers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -298,11 +298,12 @@ def print

def annotation
@dossier = dossier_with_champs(pj_template: false)
annotation_id_or_stable_id = params[:stable_id]
annotation = if params[:with_public_id].present?
type_de_champ = @dossier.find_type_de_champ_by_stable_id(params[:annotation_id], :private)
type_de_champ = @dossier.find_type_de_champ_by_stable_id(annotation_id_or_stable_id, :private)
@dossier.project_champ(type_de_champ, params[:row_id])
else
@dossier.champs_private_all.find(params[:annotation_id])
@dossier.champs_private_all.find(annotation_id_or_stable_id)
end

respond_to do |format|
Expand Down
7 changes: 4 additions & 3 deletions app/controllers/users/dossiers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def identite
respond_to do |format|
format.html
format.turbo_stream do
@dossier.update_columns(params.require(:dossier).permit(:for_tiers).to_h)
@dossier.for_tiers = params[:dossier][:for_tiers]
end
end
end
Expand Down Expand Up @@ -380,11 +380,12 @@ def merci

def champ
@dossier = dossier_with_champs(pj_template: false)
champ_id_or_stable_id = params[:stable_id]
champ = if params[:with_public_id].present?
type_de_champ = @dossier.find_type_de_champ_by_stable_id(params[:champ_id], :public)
type_de_champ = @dossier.find_type_de_champ_by_stable_id(champ_id_or_stable_id, :public)
@dossier.project_champ(type_de_champ, params[:row_id])
else
@dossier.champs_public_all.find(params[:champ_id])
@dossier.champs_public_all.find(champ_id_or_stable_id)
end

respond_to do |format|
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def auto_switch_domain?(request, user_signed_in)
end

def switch_domain_enabled?(request)
request.params.key?(:switch_domain) || Flipper.enabled?(:switch_domain)
request.params.key?(:switch_domain) || Flipper.enabled?(:switch_domain, Current.user)
end

def html_lang
Expand Down
6 changes: 5 additions & 1 deletion app/helpers/champ_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ def format_text_value(text)

def auto_attach_url(object, params = {})
if object.is_a?(Champ)
champs_attach_piece_justificative_url(object.id, params)
if Champ.update_by_stable_id?
champs_piece_justificative_url(object.dossier, object.stable_id, params.merge(row_id: object.row_id))
else
champs_legacy_piece_justificative_url(object.id, params)
end
elsif object.is_a?(TypeDeChamp) && object.piece_justificative?
piece_justificative_template_admin_procedure_type_de_champ_url(stable_id: object.stable_id, procedure_id: object.procedure.id, **params)
elsif object.is_a?(TypeDeChamp) && object.explication?
Expand Down
14 changes: 12 additions & 2 deletions app/javascript/components/MapEditor/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export function useFeatureCollection(
for (const feature of features) {
const id = feature.properties?.id;
if (id) {
await httpRequest(`${url}/${id}`, {
await httpRequest(endpointWithId(url, id), {
method: 'patch',
json: { feature }
}).json();
Expand Down Expand Up @@ -174,7 +174,9 @@ export function useFeatureCollection(
const deletedFeatures = [];
for (const feature of features) {
const id = feature.properties?.id;
await httpRequest(`${url}/${id}`, { method: 'delete' }).json();
await httpRequest(endpointWithId(url, id), {
method: 'delete'
}).json();
deletedFeatures.push(feature);
}
removeFeatures(deletedFeatures, external);
Expand Down Expand Up @@ -212,3 +214,11 @@ function useError(): [string | undefined, (message: string) => void] {

return [error, onError];
}

// We need this because endoint can have query params. For example with /champs/123?row_id=abc we can't juste concatanate id.
// We want /champs/123/456?row_id=abc not /champs/123?row_id=abc/456
function endpointWithId(endpoint: string, id: string) {
const url = new URL(endpoint, document.baseURI);
url.pathname = `${url.pathname}/${id}`;
return url.toString();
}
4 changes: 4 additions & 0 deletions app/models/champ.rb
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,10 @@ def normalize
self.value = value.delete("\u0000")
end

def self.update_by_stable_id?
Flipper.enabled?(:champ_update_by_stable_id, Current.user)
end

class NotImplemented < ::StandardError
def initialize(method)
super(":#{method} not implemented")
Expand Down
2 changes: 1 addition & 1 deletion app/models/type_de_champ.rb
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ def current_section_level(revision)
end

def level_for_revision(revision)
rtdc = revision.revision_types_de_champ.find { |rtdc| rtdc.stable_id == stable_id }
rtdc = revision.revision_types_de_champ.includes(:type_de_champ, parent: :type_de_champ).find { |rtdc| rtdc.stable_id == stable_id }
if rtdc.child?
header_section_level_value.to_i + rtdc.parent.type_de_champ.current_section_level(revision)
elsif header_section_level_value
Expand Down
14 changes: 13 additions & 1 deletion app/models/types_de_champ/piece_justificative_type_de_champ.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def champ_value_for_tag(champ, path = nil)

champ.piece_justificative_file.each_with_index.filter_map do |attachment, i|
if attachment.virus_scanner.safe? || attachment.virus_scanner.pending?
url = Rails.application.routes.url_helpers.champs_piece_justificative_download_url({ champ_id: champ.id, h: champ.encoded_date(:created_at), i: })
url = download_url(champ, i)
display = attachment.filename
if attachment.image?
tag.img '', src: url, width: '100', id: attachment.id, display: display
Expand All @@ -24,6 +24,18 @@ def champ_value_for_tag(champ, path = nil)
end.flat_map { |e| [e, ",", tag.br] }[0..-3].reduce(&:+)
end

def download_url(champ, index)
if Champ.update_by_stable_id?
Rails.application.routes.url_helpers.champs_piece_justificative_download_url(
{ dossier_id: champ.dossier_id, stable_id: champ.stable_id, h: champ.encoded_date(:created_at), i: index, row_id: champ.row_id }
)
else
Rails.application.routes.url_helpers.champs_legacy_piece_justificative_download_url(
{ champ_id: champ.id, h: champ.encoded_date(:created_at), i: index }
)
end
end

def champ_value_for_export(champ, path = :value)
champ.piece_justificative_file.map { _1.filename.to_s }.join(', ')
end
Expand Down
Loading

0 comments on commit a1f1bf2

Please sign in to comment.