-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add modalitites block to api impot particulier
- Loading branch information
1 parent
9b962a6
commit b3fbc3b
Showing
28 changed files
with
406 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class AuthorizationDecorator < ApplicationDecorator | ||
delegate_all | ||
|
||
def name_for_select | ||
"Habilitation du #{slug} : #{name}" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
app/models/concerns/authorization_extensions/modalities.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
module AuthorizationExtensions::Modalities | ||
extend ActiveSupport::Concern | ||
|
||
included do | ||
add_attributes :modalities | ||
|
||
validates :modalities, | ||
presence: true, | ||
if: -> { need_complete_validation?(:modalities) } | ||
|
||
validate :modalities_in_available_values, | ||
if: -> { need_complete_validation?(:modalities) } | ||
end | ||
|
||
def modalities_in_available_values | ||
if modalities.is_a? Array | ||
errors.add(:modalities) unless (modalities - available_modalities).empty? | ||
elsif available_modalities.exclude?(modalities) | ||
errors.add(:modalities) | ||
end | ||
end | ||
|
||
def available_modalities | ||
self.class::MODALITIES | ||
rescue NameError | ||
raise "Must declare a constant MODALITIES in the model #{self.class}, for example %w[with_france_connect with_spi]" | ||
end | ||
end |
22 changes: 22 additions & 0 deletions
22
app/models/concerns/dgfip_extensions/api_impot_particulier_modalities.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
module DGFIPExtensions::APIImpotParticulierModalities | ||
extend ActiveSupport::Concern | ||
|
||
MODALITIES = %w[with_france_connect with_spi with_etat_civil].freeze | ||
|
||
included do | ||
include AuthorizationExtensions::Modalities | ||
|
||
add_attribute :france_connect_authorization_id | ||
|
||
validates :france_connect_authorization_id, | ||
presence: true, | ||
inclusion: { in: ->(authorization_request) { authorization_request.organization.valid_authorizations_of(AuthorizationRequest::FranceConnect).pluck(:id).map(&:to_s) } }, | ||
if: -> { modalities == 'with_france_connect' && need_complete_validation?(:modalities) } | ||
end | ||
|
||
def associated_france_connect_authorization | ||
return nil if france_connect_authorization_id.blank? | ||
|
||
Authorization.find(france_connect_authorization_id) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
app/views/authorization_request_forms/build/modalities.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<%= authorization_request_form(@authorization_request) do |f| %> | ||
<%= render partial: 'authorization_request_forms/shared/modalities', locals: { f: } %> | ||
<%= render partial: 'authorization_request_forms/build/wizard_buttons', locals: { f: } %> | ||
<% end %> |
5 changes: 5 additions & 0 deletions
5
app/views/authorization_request_forms/shared/_hidden_attributes.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<% if hidden_attributes.present? && hidden_attributes[:attributes].present? %> | ||
<% hidden_attributes[:attributes].each do |key, value| %> | ||
<%= f.hidden_field key, value: %> | ||
<% end %> | ||
<% end %> |
43 changes: 42 additions & 1 deletion
43
app/views/authorization_request_forms/shared/_modalities.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,42 @@ | ||
<!-- No need to implement it yet --> | ||
<% if @authorization_request.display_prefilled_banner_for_each_block? && @authorization_request.prefilled_data?(%i[modalities france_connect_authorization_id]) %> | ||
<%= render partial: "authorization_request_forms/shared/prefilled_banner" %> | ||
<% end %> | ||
<%= f.info_for(:modalities) %> | ||
|
||
<div data-controller="choose-modalite-impot-particulier"> | ||
<div class="fr-col-lg-9"> | ||
<%= | ||
f.dsfr_radio_buttons :modalities, | ||
@authorization_request.available_modalities, | ||
required: true, | ||
radio_group_class: "fr-radio-rich", | ||
fieldset_element_class: "small", | ||
input_options: { | ||
"data-action": "click->choose-modalite-impot-particulier#trigger", | ||
"data-choose-modalite-impot-particulier-target": "modality" | ||
} | ||
%> | ||
</div> | ||
|
||
<div class="fr-col-lg-9 fr-mb-5w <%= 'fr-hidden' if @authorization_request.modalities != 'with_france_connect' %>" data-choose-modalite-impot-particulier-target="franceConnectContainer"> | ||
<% france_connect_authorizations = current_organization.valid_authorizations_of(AuthorizationRequest::FranceConnect).map(&:decorate) %> | ||
<% if france_connect_authorizations.empty? %> | ||
<div class="fr-callout red-callout"> | ||
<h3 class="fr-callout__title"> | ||
<%= t("authorization_request_forms.api_impot_particulier_sandbox.modalities.callout.title") %> | ||
</h3> | ||
<p class="fr-callout__text fr-my-3w"> | ||
<%= t("authorization_request_forms.api_impot_particulier_sandbox.modalities.callout.content") %> | ||
</p> | ||
<%= link_to t("authorization_request_forms.api_impot_particulier_sandbox.modalities.callout.link"), new_authorization_request_form_path("france-connect"), class: "fr-link fr-btn--icon-right fr-icon-arrow-right-line" %> | ||
</div> | ||
|
||
<% else %> | ||
<% options = france_connect_authorizations.map{ |authorization| [authorization.name_for_select, authorization.id] } %> | ||
<% selected_option = @authorization_request.france_connect_authorization_id || france_connect_authorizations.first.id %> | ||
<%= f.dsfr_select :france_connect_authorization_id, options_for_select(options, selected_option), class: %w[fr-select], include_blank: "Sélectionner une option", required: true, input_options: { "data-choose-modalite-impot-particulier-target": "franceConnectSelector" } %> | ||
<% end %> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 10 additions & 3 deletions
13
app/views/authorization_requests/shared/blocks/_modalities.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,20 @@ | ||
<%= render layout: 'authorization_requests/shared/blocks/summary_block', locals: { title: f.wording_for('steps.modalities'), block_id: :basic_infos, f:, editable: } do %> | ||
<%= render layout: 'authorization_requests/shared/blocks/summary_block', locals: { title: f.wording_for('steps.modalities'), block_id: :modalities, f:, editable: } do %> | ||
<% if f.wording_for('modalities.intro') %> | ||
<%= f.wording_for('modalities.intro').html_safe %> | ||
<% end %> | ||
|
||
<% modalities = @authorization_request.modalities.is_a?(Array) ? @authorization_request.modalities : [@authorization_request.modalities] %> | ||
<ul> | ||
<% @authorization_request.modalities.each do |modality| %> | ||
<% modalities.each do |modality| %> | ||
<li> | ||
<%= f.label_value("modalities.values.#{modality}").html_safe %> | ||
</li> | ||
<% end %> | ||
</ul> | ||
|
||
<% if @authorization_request.try(:france_connect_authorization_id).present? && @authorization_request.modalities == 'with_france_connect' %> | ||
<p class="fr-pl-2w"> | ||
<%= @authorization_request.associated_france_connect_authorization.full_name %> | ||
</p> | ||
<% end %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.