Skip to content

Commit

Permalink
Merge branch 'feature/import-2023-08-30'
Browse files Browse the repository at this point in the history
  • Loading branch information
maatinito committed Jan 11, 2024
2 parents 0dac126 + 614dc20 commit 339bbd2
Show file tree
Hide file tree
Showing 51 changed files with 420 additions and 195 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ group :test do
gem 'rack_session_access'
gem 'rails-controller-testing'
gem 'rspec_junit_formatter'
gem 'rspec-retry'
gem 'selenium-devtools'
gem 'selenium-webdriver'
gem 'shoulda-matchers', require: false
Expand Down
3 changes: 3 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,8 @@ GEM
rspec-expectations (~> 3.11)
rspec-mocks (~> 3.11)
rspec-support (~> 3.11)
rspec-retry (0.6.2)
rspec-core (> 3.3)
rspec-support (3.12.0)
rspec_junit_formatter (0.4.1)
rspec-core (>= 2, < 4, != 2.12.0)
Expand Down Expand Up @@ -928,6 +930,7 @@ DEPENDENCIES
rexml
rqrcode
rspec-rails
rspec-retry
rspec_junit_formatter
rubocop
rubocop-performance
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class Instructeurs::ActivateAccountFormComponent < ApplicationComponent
attr_reader :user
def initialize(user:)
@user = user
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
en:
title: Create your account for %{application_name}
activate: Activate your account %{email}
email_disabled: Instructor email address not changeable
submit: Choose password
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
fr:
title: Création de compte sur %{application_name}
activate: Se créer un compte pour %{email} en choissant un mot de passe
email_disabled: Adresse instructeur non modifiable
submit: Définir le mot de passe

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
= form_for user, url: { controller: 'users/activate', action: :create }, html: { class: "fr-py-5w" } do |f|

%h1.fr-h2.fr-mb-7w= t('.title', application_name: APPLICATION_NAME)

.fr-background-alt--grey.fr-px-12w.fr-py-7w
%fieldset.fr-mb-0.fr-fieldset{ aria: { labelledby: 'activate-account-legend' } }

%legend.fr-fieldset__legend#activate-account-legend
%h2.fr-h6.fr-mb-0= t('.activate', email: user.email)

.fr-fieldset__element
%p.fr-text--sm= t('utils.mandatory_champs')

.fr-fieldset__element= render Dsfr::InputComponent.new(form: f, attribute: :email, input_type: :email_field, opts: { disabled: :disabled, class: 'fr-input-group--disabled', value: t('.email_disabled') })

.fr-fieldset__element= render Dsfr::InputComponent.new(form: f, attribute: :password, input_type: :password_field, opts: { autocomplete: 'current-password', autofocus: 'true', data: { controller: 'turbo-input', turbo_input_url_value: show_password_complexity_path(@user.min_password_complexity) }})

= f.hidden_field :reset_password_token, value: params[:token]

#password_complexity
= render PasswordComplexityComponent.new

.fr-fieldset__element
.fr-btns-group--right.fr-btns-group.fr-btns-group--inline.fr-btns-group.fr-btns-group--inline
%ul
%li= f.submit t('.submit'), id: 'submit-password', class: 'fr-mt-2v fr-btn fr-btn'
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ fr:
Le routage permet d’acheminer les dossiers vers différents groupes d’instructeurs.
routing_configuration_notice_2_html: |
<p>Pour le configurer, votre formulaire doit comporter
au moins un champ « choix simple ».</p>
au moins un champ de type « choix simple » ou « départements ».</p>
<p>Ajoutez ce champ dans la page <a href="%{path}">« Configuration des champs »</a>.</p>
delete_title: Aucun dossier ne sera supprimé. Les groupes d'instructeurs vont être supprimés. Seuls les instructeurs du groupe « %{defaut_label} » resteront affectés à la démarche.
delete_confirmation: |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
class: 'fr-btn',
method: :delete,
title: t('.delete_title', defaut_label: @procedure.defaut_groupe_instructeur.label),
data: ( @procedure.publiee? ? { disable_with: "Suppression...", confirm: t('.delete_confirmation', defaut_label: @procedure.defaut_groupe_instructeur.label) } : nil)
data: ( @procedure.publiee? ? { disable_with: "Suppression", confirm: t('.delete_confirmation', defaut_label: @procedure.defaut_groupe_instructeur.label) } : nil)

- elsif @state == 'choix'
= form_for :choice,
Expand Down
16 changes: 13 additions & 3 deletions app/components/procedure/one_groupe_management_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,18 @@ def values_for_select(targeted_champ)

def available_values_for_select(targeted_champ)
return [] if targeted_champ.is_a?(Logic::Empty)
targeted_champ
.options(@revision.types_de_champ_public)
.map { |(label, value)| [label, constant(value).to_json] }

case @revision.types_de_champ_public.find_by(stable_id: targeted_champ.stable_id).type_champ
when TypeDeChamp.type_champs.fetch(:departements)
departements_for_select
when TypeDeChamp.type_champs.fetch(:drop_down_list)
targeted_champ
.options(@revision.types_de_champ_public)
.map { |(label, value)| [label, constant(value).to_json] }
end
end

def departements_for_select
APIGeoService.departements.map { ["#{_1[:code]}#{_1[:name]}", constant(_1[:code]).to_json] }
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@
- if @private_move_changes.present?
- list.with_item do
= t(".private.move", count: @private_move_changes.size)
- if @previous_revision.procedure.groupe_instructeurs.any?(&:invalid_rule?)
- if @previous_revision.procedure.routing_enabled? && @previous_revision.procedure.groupe_instructeurs.any?(&:invalid_rule?)
- list.with_item do
.fr-alert.fr-alert--warning.fr-mt-1v
= t(".invalid_routing_rules_alert")
26 changes: 19 additions & 7 deletions app/controllers/administrateurs/groupe_instructeurs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,26 @@ def create_simple_routing

tdc = @procedure.active_revision.routable_types_de_champ.find { |tdc| tdc.stable_id == stable_id }

tdc_options = tdc.drop_down_options.reject(&:empty?)
case tdc.type_champ
when TypeDeChamp.type_champs.fetch(:departements)
tdc_options = APIGeoService.departements.map { ["#{_1[:code]}#{_1[:name]}", _1[:code]] }
tdc_options.each do |code_and_name, code|
routing_rule = ds_eq(champ_value(stable_id), constant(code))
@procedure
.groupe_instructeurs
.find_or_create_by(label: code_and_name)
.update(instructeurs: [current_administrateur.instructeur], routing_rule:)
end

tdc_options.each do |option_label|
routing_rule = ds_eq(champ_value(stable_id), constant(option_label))
@procedure
.groupe_instructeurs
.find_or_create_by(label: option_label)
.update(instructeurs: [current_administrateur.instructeur], routing_rule:)
when TypeDeChamp.type_champs.fetch(:drop_down_list)
tdc_options = tdc.drop_down_options.reject(&:empty?)
tdc_options.each do |option_label|
routing_rule = ds_eq(champ_value(stable_id), constant(option_label))
@procedure
.groupe_instructeurs
.find_or_create_by(label: option_label)
.update(instructeurs: [current_administrateur.instructeur], routing_rule:)
end
end

if tdc.drop_down_other?
Expand Down
3 changes: 2 additions & 1 deletion app/controllers/instructeurs/dossiers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ def avis_new
end

def personnes_impliquees
@following_instructeurs_emails = dossier.followers_instructeurs.map(&:email)
# sort following_instructeurs (last follower on top) for the API of Agence de l'Eau Loire-Bretagne
@following_instructeurs_emails = dossier.followers_instructeurs.joins(:follows).merge(Follow.order(id: :desc)).map(&:email)
previous_followers = dossier.previous_followers_instructeurs - dossier.followers_instructeurs
@previous_following_instructeurs_emails = previous_followers.map(&:email)
@avis_emails = dossier.experts.map(&:email)
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/procedures_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def logo
if @procedure.logo.attached?
redirect_to url_for(@procedure.logo.variant(:email))
else
redirect_to image_url(PROCEDURE_DEFAULT_LOGO_SRC)
redirect_to ActionController::Base.helpers.image_url(PROCEDURE_DEFAULT_LOGO_SRC)
end
end

Expand Down
9 changes: 8 additions & 1 deletion app/controllers/users/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Users::SessionsController < Devise::SessionsController
layout 'login', only: [:new, :create]

before_action :restore_procedure_context, only: [:new, :create]

skip_before_action :redirect_if_untrusted, only: [:reset_link_sent]
# POST /resource/sign_in
def create
user = User.find_by(email: params[:user][:email])
Expand All @@ -18,6 +18,13 @@ def create
super
end

def reset_link_sent
if send_login_token_or_bufferize(current_instructeur)
flash[:notice] = "Nous venons de vous renvoyer un nouveau lien de connexion sécurisée à #{APPLICATION_NAME}"
end
redirect_to link_sent_path(email: current_instructeur.email)
end

def link_sent
if Devise.email_regexp.match?(params[:email])
@email = params[:email]
Expand Down
6 changes: 3 additions & 3 deletions app/helpers/procedure_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ def can_manage_groupe_instructeurs?(procedure)
end

def can_send_groupe_message?(procedure)
total_groupe_instructeur_on_procedure = procedure.groupe_instructeurs.active.count
total_groupe_instructeur_on_instructeur = current_instructeur.groupe_instructeurs.active.where(procedure: procedure).count
groupe_instructeur_on_procedure_ids = procedure.groupe_instructeurs.active.ids.sort
groupe_instructeur_on_instructeur_ids = current_instructeur.groupe_instructeurs.active.where(procedure: procedure).ids.sort

total_groupe_instructeur_on_procedure == total_groupe_instructeur_on_instructeur
groupe_instructeur_on_procedure_ids == groupe_instructeur_on_instructeur_ids
end

def url_or_email_to_lien_dpo(procedure)
Expand Down
7 changes: 5 additions & 2 deletions app/models/concerns/trusted_device_concern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@ def trusted_device?

def send_login_token_or_bufferize(instructeur)
if !instructeur.young_login_token?
login_token = instructeur.create_trusted_device_token
InstructeurMailer.send_login_token(instructeur, login_token).deliver_later
token = instructeur.create_trusted_device_token
InstructeurMailer.send_login_token(instructeur, token).deliver_later
true
else
false
end
end

Expand Down
8 changes: 7 additions & 1 deletion app/models/groupe_instructeur.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,13 @@ def other_groupe_instructeurs

def routing_rule_matches_tdc?
routing_tdc = procedure.active_revision.types_de_champ.find_by(stable_id: routing_rule.left.stable_id)
options = routing_tdc.options_with_drop_down_other

options = case routing_tdc.type_champ
when TypeDeChamp.type_champs.fetch(:departements)
APIGeoService.departements.map { _1[:code] }
when TypeDeChamp.type_champs.fetch(:drop_down_list)
routing_tdc.options_with_drop_down_other
end
routing_rule.right.value.in?(options)
end

Expand Down
2 changes: 2 additions & 0 deletions app/models/logic/champ_value.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ def compute(champs)
targeted_champ.selected
when "Champs::MultipleDropDownListChamp"
targeted_champ.selected_options
when "Champs::DepartementChamp"
targeted_champ.code
end
end

Expand Down
11 changes: 7 additions & 4 deletions app/models/procedure_presentation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def fields
field_hash('user', 'email', type: :text),
field_hash('followers_instructeurs', 'email', type: :text),
field_hash('groupe_instructeur', 'id', type: :enum),
field_hash('avis', 'answer', type: :text)
field_hash('avis', 'question_answer', filterable: false)
)

if procedure.for_individual
Expand Down Expand Up @@ -104,7 +104,9 @@ def displayable_fields_for_select
end

def filterable_fields_options
fields.map do |field|
fields.filter_map do |field|
next if field['filterable'] == false

[field['label'], field_id(field)]
end
end
Expand Down Expand Up @@ -447,7 +449,7 @@ def check_filters_max_length
end
end

def field_hash(table, column, label: nil, classname: '', virtual: false, type: :text, scope: '', value_column: :value)
def field_hash(table, column, label: nil, classname: '', virtual: false, type: :text, scope: '', value_column: :value, filterable: true)
{
'label' => label || I18n.t(column, scope: [:activerecord, :attributes, :procedure_presentation, :fields, table]),
TABLE => table,
Expand All @@ -456,7 +458,8 @@ def field_hash(table, column, label: nil, classname: '', virtual: false, type: :
'virtual' => virtual,
'type' => type,
'scope' => scope,
'value_column' => value_column
'value_column' => value_column,
'filterable' => filterable
}
end

Expand Down
2 changes: 1 addition & 1 deletion app/models/procedure_revision.rb
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ def coordinate_and_tdc(stable_id)
end

def routable_types_de_champ
types_de_champ_public.filter { |tdc| [:drop_down_list].include?(tdc.type_champ.to_sym) }
types_de_champ_public.filter { |tdc| [:drop_down_list, :departements].include?(tdc.type_champ.to_sym) }
end

private
Expand Down
2 changes: 1 addition & 1 deletion app/services/sva_svr_decision_date_calculator_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def decision_date
start_date = determine_start_date + 1.day
correction_delay = calculate_correction_delay(start_date)

start_date + correction_delay + duration
start_date + duration + correction_delay
end

private
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@
%li
= link_to 'Retour', options_admin_procedure_groupe_instructeurs_path(@procedure, state: :choix), class: 'fr-btn fr-btn--secondary'
%li
%button.fr-btn{ disabled: true, data: { 'radio-enabled-submit-target': 'submit' } } Créer les groupes
%button.fr-btn{ disabled: true, data: { disable_with: 'Création des groupes…', 'radio-enabled-submit-target': 'submit' } } Créer les groupes
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@

.text-right
%p.fr-mb-0.width-max-content N° #{number_with_html_delimiter(procedure.id)}
- if procedure.close?
- if procedure.close? || procedure.depubliee?
%span.fr-badge.fr-badge--sm.fr-badge--warning
= t('closed', scope: [:layouts, :breadcrumb])

- elsif procedure.locked?
- elsif procedure.publiee?
%span.fr-badge.fr-badge--sm.fr-badge--success
= t('published', scope: [:layouts, :breadcrumb])

Expand Down
2 changes: 1 addition & 1 deletion app/views/instructeur_mailer/send_login_token.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Bonjour,

%p
Veuillez cliquer sur le lien suivant pour vous connecter sur le site #{APPLICATION_NAME} : 
Veuillez cliquer sur le lien sécurisé suivant pour vous connecter à #{APPLICATION_NAME} : 
= link_to(sign_in_by_link_url(@instructeur_id, jeton: @login_token), sign_in_by_link_url(@instructeur_id, jeton: @login_token))

%p
Expand Down
2 changes: 1 addition & 1 deletion app/views/shared/_social_login.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
.form-column.procedure-context-content
.auth-form.sign-in-form.fr-py-5w
.social-logins
%h2.fr-h5= title
%h2.fr-h4= title
%br
- OmniAuthService.providers.each do |provider|
= link_to url_for(controller: '/omniauth', action: 'login', provider:), class: "fr-btn fr-btn--lg fr-btn--secondary" do
Expand Down
11 changes: 9 additions & 2 deletions app/views/user_mailer/invite_instructeur.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,18 @@
Vous venez d’être nommé instructeur sur #{APPLICATION_NAME}.

%p
Votre compte a été créé pour l'adresse email #{@user.email}. Pour l’activer, nous vous invitons à cliquer sur le lien suivant : 
Votre compte a été créé pour l'adresse email
%strong #{@user.email}.

%p
Pour l’activer, cliquez sur le lien suivant : 
= link_to(users_activate_url(token: @reset_password_token), users_activate_url(token: @reset_password_token))

%p
Par ailleurs, nous vous invitons à prendre quelques minutes pour consulter notre tutoriel à destination des nouveaux instructeurs :
Lors de vos prochaines connexions sur #{APPLICATION_NAME} cliquez sur le bouton « Se connecter » positionné sur le haut de page ou bien sur ce lien : 
= link_to new_user_session_url, new_user_session_url
%p
Nous vous invitons aussi à consulter notre tutoriel à destination des nouveaux instructeurs :
= link_to(INSTRUCTEUR_TUTORIAL_URL, INSTRUCTEUR_TUTORIAL_URL)

= render partial: "layouts/mailers/signature"
Loading

0 comments on commit 339bbd2

Please sign in to comment.