Skip to content

Commit

Permalink
Add scopes option to MultiStagesDefinitionGenerator
Browse files Browse the repository at this point in the history
  • Loading branch information
skelz0r committed Dec 12, 2024
1 parent fe3a20f commit 95ccaf3
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -37,6 +42,10 @@ def dgfip?
provider == 'dgfip'
end

def scopes?
options.fetch(:scopes)
end

def provider
options.fetch(:provider, 'dinum').downcase
end
Expand All @@ -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}
Expand All @@ -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

Expand All @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ class AuthorizationRequest::<%= name.classify %> < 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) }
end
Original file line number Diff line number Diff line change
Expand Up @@ -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? %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
- name: basic_infos
- name: personal_data
- name: legal
<% if scopes? %>
- name: scopes
<% end %>
- name: contacts

<%= name.underscore.dasherize %>:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 95ccaf3

Please sign in to comment.