From 6ed9d58ecc89c284682a23afa35a425bf2c97d25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Loi=CC=88c=20Delmaire?= Date: Thu, 12 Dec 2024 13:47:58 +0100 Subject: [PATCH] Add scopes option to MultiStagesDefinitionGenerator --- .../multi_stages_definition_generator.rb | 31 +++++++++++++------ .../authorization_request_sandbox.rb.erb | 3 +- .../templates/scenario.feature.erb | 4 +-- 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/lib/generators/multi_stages_definition/multi_stages_definition_generator.rb b/lib/generators/multi_stages_definition/multi_stages_definition_generator.rb index a825b6d6b..4f0edac6b 100644 --- a/lib/generators/multi_stages_definition/multi_stages_definition_generator.rb +++ b/lib/generators/multi_stages_definition/multi_stages_definition_generator.rb @@ -8,6 +8,11 @@ class MultiStagesDefinitionGenerator < Rails::Generators::NamedBase default: 'dinum', desc: "Specify the provider, if it's dgfip it will add more stuffs" + class_option :scopes, + type: :boolean, + default: true, + desc: 'Add scopes' + def create_models_file template 'authorization_request_sandbox.rb.erb', "app/models/authorization_request/#{name.underscore}_sandbox.rb" template 'authorization_request_production.rb.erb', "app/models/authorization_request/#{name.underscore}.rb" @@ -37,6 +42,10 @@ def dgfip? provider == 'dgfip' end + def scopes? + options.fetch(:scopes) + end + def provider options.fetch(:provider, 'dinum').downcase end @@ -62,12 +71,16 @@ def definitions_data - name: basic_infos - name: personal_data - name: legal - - name: scopes + #{scopes? ? '- name: scopes' : ''} - name: contacts - scopes: &#{name.underscore}_scopes - - name: "Scope 1" - value: "value_1" - group: "Groupe" + #{if scopes? + "scopes: &#{name.underscore}_scopes + - name: 'Scope 1' + value: 'value_1' + group: 'Groupe'" + else + '' + end} #{name.underscore}: name: #{humanized_name} @@ -87,12 +100,12 @@ def definitions_data - name: basic_infos - name: personal_data - name: legal - - name: scopes + #{scopes? ? '- name: scopes' : ''} - name: contacts - name: operational_acceptance - name: safety_certification - name: volumetrie - scopes: *#{name.underscore}_scopes + #{scopes? ? "scopes: *#{name.underscore}_scopes" : ''} YAML_DATA end @@ -107,7 +120,7 @@ def factory_data with_basic_infos with_personal_data with_cadre_juridique - with_scopes + #{scopes? ? 'with_scopes' : ''} end trait :#{name.underscore} do @@ -118,7 +131,7 @@ def factory_data with_basic_infos with_personal_data with_cadre_juridique - with_scopes + #{scopes? ? 'with_scopes' : ''} with_safety_certification with_operational_acceptance with_volumetrie diff --git a/lib/generators/multi_stages_definition/templates/authorization_request_sandbox.rb.erb b/lib/generators/multi_stages_definition/templates/authorization_request_sandbox.rb.erb index 62b4693b9..d062cd723 100644 --- a/lib/generators/multi_stages_definition/templates/authorization_request_sandbox.rb.erb +++ b/lib/generators/multi_stages_definition/templates/authorization_request_sandbox.rb.erb @@ -7,10 +7,11 @@ class AuthorizationRequest::<%= name.classify %>Sandbox < AuthorizationRequest add_document :maquette_projet, content_type: ['application/pdf'], size: { less_than: 10.megabytes } add_attributes :date_prevue_mise_en_production - +<% if scopes? %> add_scopes(validation: { presence: true, if: -> { need_complete_validation?(:scopes) } }) +<% end %> contact :contact_technique, validation_condition: ->(record) { record.need_complete_validation?(:contacts) } <% if dgfip? %> diff --git a/lib/generators/multi_stages_definition/templates/scenario.feature.erb b/lib/generators/multi_stages_definition/templates/scenario.feature.erb index b91eb40af..155e5d0bd 100644 --- a/lib/generators/multi_stages_definition/templates/scenario.feature.erb +++ b/lib/generators/multi_stages_definition/templates/scenario.feature.erb @@ -15,10 +15,10 @@ Fonctionnalité: Soumission d'une demande d'habilitation <%= humanized_name %> * je renseigne le cadre légal * je clique sur "Suivant" - +<% if scopes? %> * je coche "Scope 1" * je clique sur "Suivant" - +<% end %> * je renseigne les informations des contacts RGPD * je renseigne les informations du contact technique * je clique sur "Suivant"