From 44b4b5d0ab7039d242dafcbfc207cc9615cd34af Mon Sep 17 00:00:00 2001 From: seb-by-ouidou Date: Mon, 4 Sep 2023 10:07:04 +0000 Subject: [PATCH] feat: rename admins_group_manager to gestionnaire --- .../admins_group_manager_controller.rb | 9 ---- .../admins_groups_controller.rb | 14 ----- app/controllers/application_controller.rb | 28 +++++----- .../gestionnaires/gestionnaire_controller.rb | 9 ++++ .../groupe_gestionnaires_controller.rb | 14 +++++ .../admins_group_managers_controller.rb | 4 -- .../manager/admins_groups_controller.rb | 32 ------------ .../manager/gestionnaires_controller.rb | 4 ++ .../groupe_gestionnaires_controller.rb | 32 ++++++++++++ ...dashboard.rb => gestionnaire_dashboard.rb} | 12 ++--- ...rd.rb => groupe_gestionnaire_dashboard.rb} | 12 ++--- app/helpers/application_helper.rb | 6 +-- app/mailers/admins_group_mailer.rb | 13 ----- app/mailers/groupe_gestionnaire_mailer.rb | 13 +++++ app/mailers/user_mailer.rb | 4 +- app/models/administrateur.rb | 2 +- app/models/admins_group.rb | 30 ----------- ...dmins_group_manager.rb => gestionnaire.rb} | 6 +-- app/models/groupe_gestionnaire.rb | 30 +++++++++++ app/models/user.rb | 16 +++--- ...tify_added_admins_group_managers.html.haml | 6 --- .../notify_added_gestionnaires.html.haml | 6 +++ app/views/layouts/_account_dropdown.haml | 6 +-- ...tml.haml => invite_gestionnaire.html.haml} | 2 +- config/locales/en.yml | 2 +- config/locales/fr.yml | 2 +- .../fr.yml | 6 +-- .../fr.yml | 6 +-- .../notify_added_admins_group_managers/en.yml | 4 -- .../notify_added_admins_group_managers/fr.yml | 4 -- .../notify_added_gestionnaires/en.yml | 4 ++ .../notify_added_gestionnaires/fr.yml | 4 ++ .../views/layouts/_account_dropdown.en.yml | 4 +- .../views/layouts/_account_dropdown.fr.yml | 4 +- config/locales/views/manager/fr.yml | 4 +- config/routes.rb | 12 ++--- ...0813091837_create_admins_group_managers.rb | 9 ---- .../20230813091838_create_admins_groups.rb | 15 ------ ...846_add_admins_group_to_administrateurs.rb | 7 --- ...ign_key_admins_group_to_administrateurs.rb | 5 -- ...ign_key_admins_group_to_administrateurs.rb | 5 -- .../20230813091937_create_gestionnaires.rb | 9 ++++ ...30813091938_create_groupe_gestionnaires.rb | 15 ++++++ ..._groupe_gestionnaire_to_administrateurs.rb | 7 +++ ..._groupe_gestionnaire_to_administrateurs.rb | 5 ++ ..._groupe_gestionnaire_to_administrateurs.rb | 5 ++ db/schema.rb | 52 +++++++++---------- spec/factories/admins_group_manager.rb | 12 ----- spec/factories/gestionnaire.rb | 12 +++++ ...admins_group.rb => groupe_gestionnaire.rb} | 2 +- spec/mailers/admins_group_mailer_spec.rb | 16 ------ .../groupe_gestionnaire_mailer_spec.rb | 16 ++++++ .../previews/admins_group_mailer_preview.rb | 14 ----- .../groupe_gestionnaire_mailer_preview.rb | 14 +++++ spec/mailers/previews/user_mailer_preview.rb | 6 +-- spec/models/administrateur_spec.rb | 2 +- spec/models/admins_group_manager_spec.rb | 5 -- spec/models/admins_group_spec.rb | 8 --- spec/models/gestionnaire_spec.rb | 5 ++ spec/models/groupe_gestionnaire_spec.rb | 8 +++ 60 files changed, 310 insertions(+), 310 deletions(-) delete mode 100644 app/controllers/admins_group_managers/admins_group_manager_controller.rb delete mode 100644 app/controllers/admins_group_managers/admins_groups_controller.rb create mode 100644 app/controllers/gestionnaires/gestionnaire_controller.rb create mode 100644 app/controllers/gestionnaires/groupe_gestionnaires_controller.rb delete mode 100644 app/controllers/manager/admins_group_managers_controller.rb delete mode 100644 app/controllers/manager/admins_groups_controller.rb create mode 100644 app/controllers/manager/gestionnaires_controller.rb create mode 100644 app/controllers/manager/groupe_gestionnaires_controller.rb rename app/dashboards/{admins_group_manager_dashboard.rb => gestionnaire_dashboard.rb} (85%) rename app/dashboards/{admins_group_dashboard.rb => groupe_gestionnaire_dashboard.rb} (85%) delete mode 100644 app/mailers/admins_group_mailer.rb create mode 100644 app/mailers/groupe_gestionnaire_mailer.rb delete mode 100644 app/models/admins_group.rb rename app/models/{admins_group_manager.rb => gestionnaire.rb} (77%) create mode 100644 app/models/groupe_gestionnaire.rb delete mode 100644 app/views/admins_group_mailer/notify_added_admins_group_managers.html.haml create mode 100644 app/views/groupe_gestionnaire_mailer/notify_added_gestionnaires.html.haml rename app/views/user_mailer/{invite_admins_group_manager.html.haml => invite_gestionnaire.html.haml} (78%) rename config/locales/models/{admins_group_manager => gestionnaire}/fr.yml (54%) rename config/locales/models/{admins_group => groupe_gestionnaire}/fr.yml (58%) delete mode 100644 config/locales/views/admins_group_mailer/notify_added_admins_group_managers/en.yml delete mode 100644 config/locales/views/admins_group_mailer/notify_added_admins_group_managers/fr.yml create mode 100644 config/locales/views/groupe_gestionnaire_mailer/notify_added_gestionnaires/en.yml create mode 100644 config/locales/views/groupe_gestionnaire_mailer/notify_added_gestionnaires/fr.yml delete mode 100644 db/migrate/20230813091837_create_admins_group_managers.rb delete mode 100644 db/migrate/20230813091838_create_admins_groups.rb delete mode 100644 db/migrate/20230813091846_add_admins_group_to_administrateurs.rb delete mode 100644 db/migrate/20230813091847_add_foreign_key_admins_group_to_administrateurs.rb delete mode 100644 db/migrate/20230813091848_validate_foreign_key_admins_group_to_administrateurs.rb create mode 100644 db/migrate/20230813091937_create_gestionnaires.rb create mode 100644 db/migrate/20230813091938_create_groupe_gestionnaires.rb create mode 100644 db/migrate/20230813091946_add_groupe_gestionnaire_to_administrateurs.rb create mode 100644 db/migrate/20230813091947_add_foreign_key_groupe_gestionnaire_to_administrateurs.rb create mode 100644 db/migrate/20230813091948_validate_foreign_key_groupe_gestionnaire_to_administrateurs.rb delete mode 100644 spec/factories/admins_group_manager.rb create mode 100644 spec/factories/gestionnaire.rb rename spec/factories/{admins_group.rb => groupe_gestionnaire.rb} (67%) delete mode 100644 spec/mailers/admins_group_mailer_spec.rb create mode 100644 spec/mailers/groupe_gestionnaire_mailer_spec.rb delete mode 100644 spec/mailers/previews/admins_group_mailer_preview.rb create mode 100644 spec/mailers/previews/groupe_gestionnaire_mailer_preview.rb delete mode 100644 spec/models/admins_group_manager_spec.rb delete mode 100644 spec/models/admins_group_spec.rb create mode 100644 spec/models/gestionnaire_spec.rb create mode 100644 spec/models/groupe_gestionnaire_spec.rb diff --git a/app/controllers/admins_group_managers/admins_group_manager_controller.rb b/app/controllers/admins_group_managers/admins_group_manager_controller.rb deleted file mode 100644 index fad6629e3..000000000 --- a/app/controllers/admins_group_managers/admins_group_manager_controller.rb +++ /dev/null @@ -1,9 +0,0 @@ -module AdminsGroupManagers - class AdminsGroupManagerController < ApplicationController - before_action :authenticate_admins_group_manager! - - def nav_bar_profile - :admins_group_manager - end - end -end diff --git a/app/controllers/admins_group_managers/admins_groups_controller.rb b/app/controllers/admins_group_managers/admins_groups_controller.rb deleted file mode 100644 index 3e599883a..000000000 --- a/app/controllers/admins_group_managers/admins_groups_controller.rb +++ /dev/null @@ -1,14 +0,0 @@ -module AdminsGroupManagers - class AdminsGroupsController < AdminsGroupManagerController - def index - @admins_groups = admins_groups - end - - private - - def admins_groups - admins_group_ids = current_admins_group_manager.admins_group_ids - AdminsGroup.where(id: admins_group_ids.compact.uniq) - end - end -end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index b95db7663..17600d1e0 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -22,7 +22,7 @@ class ApplicationController < ActionController::Base helper_method :multiple_devise_profile_connect?, :instructeur_signed_in?, :current_instructeur, :current_expert, :expert_signed_in?, :administrateur_signed_in?, :current_administrateur, :current_account, :localization_enabled?, :set_locale, :current_expert_not_instructeur?, - :admins_group_manager_signed_in?, :current_admins_group_manager + :gestionnaire_signed_in?, :current_gestionnaire before_action do Current.request_id = request.uuid @@ -38,12 +38,12 @@ class ApplicationController < ActionController::Base def multiple_devise_profile_connect? user_signed_in? && instructeur_signed_in? || instructeur_signed_in? && administrateur_signed_in? || - instructeur_signed_in? && admins_group_manager_signed_in? || + instructeur_signed_in? && gestionnaire_signed_in? || instructeur_signed_in? && expert_signed_in? || user_signed_in? && administrateur_signed_in? || - user_signed_in? && admins_group_manager_signed_in? || + user_signed_in? && gestionnaire_signed_in? || user_signed_in? && expert_signed_in? || - administrateur_signed_in? && admins_group_manager_signed_in? + administrateur_signed_in? && gestionnaire_signed_in? end def current_instructeur @@ -62,12 +62,12 @@ class ApplicationController < ActionController::Base current_administrateur.present? end - def current_admins_group_manager - current_user&.admins_group_manager + def current_gestionnaire + current_user&.gestionnaire end - def admins_group_manager_signed_in? - current_admins_group_manager.present? + def gestionnaire_signed_in? + current_gestionnaire.present? end def current_expert @@ -84,7 +84,7 @@ class ApplicationController < ActionController::Base def current_account { - admins_group_manager: current_admins_group_manager, + gestionnaire: current_gestionnaire, administrateur: current_administrateur, instructeur: current_instructeur, user: current_user @@ -128,8 +128,8 @@ class ApplicationController < ActionController::Base authenticate_expert! elsif administrateur_signed_in? authenticate_administrateur! - elsif admins_group_manager_signed_in? - authenticate_admins_group_manager! + elsif gestionnaire_signed_in? + authenticate_gestionnaire! else authenticate_user! end @@ -159,8 +159,8 @@ class ApplicationController < ActionController::Base end end - def authenticate_admins_group_manager! - if !admins_group_manager_signed_in? + def authenticate_gestionnaire! + if !gestionnaire_signed_in? redirect_to new_user_session_path end end @@ -199,7 +199,7 @@ class ApplicationController < ActionController::Base current_user, current_instructeur, current_administrateur, - current_admins_group_manager, + current_gestionnaire, current_super_admin ].compact.map { |role| role.class.name } diff --git a/app/controllers/gestionnaires/gestionnaire_controller.rb b/app/controllers/gestionnaires/gestionnaire_controller.rb new file mode 100644 index 000000000..c9026553d --- /dev/null +++ b/app/controllers/gestionnaires/gestionnaire_controller.rb @@ -0,0 +1,9 @@ +module Gestionnaires + class GestionnaireController < ApplicationController + before_action :authenticate_gestionnaire! + + def nav_bar_profile + :gestionnaire + end + end +end diff --git a/app/controllers/gestionnaires/groupe_gestionnaires_controller.rb b/app/controllers/gestionnaires/groupe_gestionnaires_controller.rb new file mode 100644 index 000000000..99f413bf9 --- /dev/null +++ b/app/controllers/gestionnaires/groupe_gestionnaires_controller.rb @@ -0,0 +1,14 @@ +module Gestionnaires + class GroupeGestionnairesController < GestionnaireController + def index + @groupe_gestionnaires = groupe_gestionnaires + end + + private + + def groupe_gestionnaires + groupe_gestionnaire_ids = current_gestionnaire.groupe_gestionnaire_ids + GroupeGestionnaire.where(id: groupe_gestionnaire_ids.compact.uniq) + end + end +end diff --git a/app/controllers/manager/admins_group_managers_controller.rb b/app/controllers/manager/admins_group_managers_controller.rb deleted file mode 100644 index f580748e1..000000000 --- a/app/controllers/manager/admins_group_managers_controller.rb +++ /dev/null @@ -1,4 +0,0 @@ -module Manager - class AdminsGroupManagersController < Manager::ApplicationController - end -end diff --git a/app/controllers/manager/admins_groups_controller.rb b/app/controllers/manager/admins_groups_controller.rb deleted file mode 100644 index ebb92784c..000000000 --- a/app/controllers/manager/admins_groups_controller.rb +++ /dev/null @@ -1,32 +0,0 @@ -module Manager - class AdminsGroupsController < Manager::ApplicationController - def add_admins_group_manager - emails = (params['emails'].presence || '').split(',').to_json - emails = JSON.parse(emails).map { EmailSanitizableConcern::EmailSanitizer.sanitize(_1) } - - admins_group_managers, invalid_emails = admins_group.add_admins_group_managers(emails:) - - if invalid_emails.present? - flash[:alert] = t('.wrong_address', - count: invalid_emails.size, - emails: invalid_emails) - end - - if admins_group_managers.present? - flash[:notice] = "Les gestionnaires ont bien été affectés au groupe d'administrateurs" - - AdminsGroupMailer - .notify_added_admins_group_managers(admins_group, admins_group_managers, current_super_admin.email) - .deliver_later - end - - redirect_to manager_admins_groups_path(admins_group) - end - - private - - def admins_group - @admins_group ||= AdminsGroup.find(params[:id]) - end - end -end diff --git a/app/controllers/manager/gestionnaires_controller.rb b/app/controllers/manager/gestionnaires_controller.rb new file mode 100644 index 000000000..859bf2749 --- /dev/null +++ b/app/controllers/manager/gestionnaires_controller.rb @@ -0,0 +1,4 @@ +module Manager + class GestionnairesController < Manager::ApplicationController + end +end diff --git a/app/controllers/manager/groupe_gestionnaires_controller.rb b/app/controllers/manager/groupe_gestionnaires_controller.rb new file mode 100644 index 000000000..612f5e66a --- /dev/null +++ b/app/controllers/manager/groupe_gestionnaires_controller.rb @@ -0,0 +1,32 @@ +module Manager + class GroupeGestionnairesController < Manager::ApplicationController + def add_gestionnaire + emails = (params['emails'].presence || '').split(',').to_json + emails = JSON.parse(emails).map { EmailSanitizableConcern::EmailSanitizer.sanitize(_1) } + + gestionnaires, invalid_emails = groupe_gestionnaire.add_gestionnaires(emails:) + + if invalid_emails.present? + flash[:alert] = t('.wrong_address', + count: invalid_emails.size, + emails: invalid_emails) + end + + if gestionnaires.present? + flash[:notice] = "Les gestionnaires ont bien été affectés au groupe d'administrateurs" + + GroupeGestionnaireMailer + .notify_added_gestionnaires(groupe_gestionnaire, gestionnaires, current_super_admin.email) + .deliver_later + end + + redirect_to manager_groupe_gestionnaires_path(groupe_gestionnaire) + end + + private + + def groupe_gestionnaire + @groupe_gestionnaire ||= GroupeGestionnaire.find(params[:id]) + end + end +end diff --git a/app/dashboards/admins_group_manager_dashboard.rb b/app/dashboards/gestionnaire_dashboard.rb similarity index 85% rename from app/dashboards/admins_group_manager_dashboard.rb rename to app/dashboards/gestionnaire_dashboard.rb index 09a8c8c20..0e78e4ddb 100644 --- a/app/dashboards/admins_group_manager_dashboard.rb +++ b/app/dashboards/gestionnaire_dashboard.rb @@ -1,6 +1,6 @@ require "administrate/base_dashboard" -class AdminsGroupManagerDashboard < Administrate::BaseDashboard +class GestionnaireDashboard < Administrate::BaseDashboard # ATTRIBUTE_TYPES # a hash that describes the type of each of the model's fields. # @@ -12,7 +12,7 @@ class AdminsGroupManagerDashboard < Administrate::BaseDashboard user: Field::HasOne.with_options(searchable: true, searchable_field: 'email'), created_at: Field::DateTime, updated_at: Field::DateTime, - admins_groups: Field::HasMany.with_options(limit: 20), + groupe_gestionnaires: Field::HasMany.with_options(limit: 20), registration_state: Field::String.with_options(searchable: false), email: Field::Email.with_options(searchable: false) }.freeze @@ -26,7 +26,7 @@ class AdminsGroupManagerDashboard < Administrate::BaseDashboard :id, :user, :created_at, - :admins_groups, + :groupe_gestionnaires, :registration_state ].freeze @@ -38,7 +38,7 @@ class AdminsGroupManagerDashboard < Administrate::BaseDashboard :created_at, :updated_at, :registration_state, - :admins_groups + :groupe_gestionnaires ].freeze # FORM_ATTRIBUTES @@ -51,7 +51,7 @@ class AdminsGroupManagerDashboard < Administrate::BaseDashboard # Overwrite this method to customize how users are displayed # across all pages of the admin dashboard. # - def display_resource(admins_group_manager) - admins_group_manager.email + def display_resource(gestionnaire) + gestionnaire.email end end diff --git a/app/dashboards/admins_group_dashboard.rb b/app/dashboards/groupe_gestionnaire_dashboard.rb similarity index 85% rename from app/dashboards/admins_group_dashboard.rb rename to app/dashboards/groupe_gestionnaire_dashboard.rb index 223d15a43..b60b38f71 100644 --- a/app/dashboards/admins_group_dashboard.rb +++ b/app/dashboards/groupe_gestionnaire_dashboard.rb @@ -1,6 +1,6 @@ require "administrate/base_dashboard" -class AdminsGroupDashboard < Administrate::BaseDashboard +class GroupeGestionnaireDashboard < Administrate::BaseDashboard # ATTRIBUTE_TYPES # a hash that describes the type of each of the model's fields. # @@ -12,7 +12,7 @@ class AdminsGroupDashboard < Administrate::BaseDashboard name: Field::String, created_at: Field::DateTime, updated_at: Field::DateTime, - admins_group_managers: Field::HasMany, + gestionnaires: Field::HasMany, administrateurs: Field::HasMany }.freeze @@ -25,14 +25,14 @@ class AdminsGroupDashboard < Administrate::BaseDashboard :id, :created_at, :name, - :admins_group_managers, + :gestionnaires, :administrateurs ].freeze # SHOW_PAGE_ATTRIBUTES # an array of attributes that will be displayed on the model's show page. SHOW_PAGE_ATTRIBUTES = [ - :admins_group_managers, + :gestionnaires, :administrateurs, :id, :created_at @@ -48,7 +48,7 @@ class AdminsGroupDashboard < Administrate::BaseDashboard # Overwrite this method to customize how users are displayed # across all pages of the admin dashboard. # - def display_resource(admins_group) - admins_group.name + def display_resource(groupe_gestionnaire) + groupe_gestionnaire.name end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 974a2aac1..bb313aa30 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -48,7 +48,7 @@ module ApplicationHelper current_user&.email || current_instructeur&.email || current_administrateur&.email || - current_admins_group_manager&.email + current_gestionnaire&.email end def staging? @@ -78,8 +78,8 @@ module ApplicationHelper case nav_bar_profile when :administrateur [admin_procedures_path, t("admin", scope: "layouts.root_path_link_title")] - when :admins_group_manager - [admins_group_manager_admins_groups_path, t("admins_group_manager", scope: "layouts.root_path_link_title")] + when :gestionnaire + [gestionnaire_groupe_gestionnaires_path, t("gestionnaire", scope: "layouts.root_path_link_title")] when :instructeur [instructeur_procedures_path, t("instructeur", scope: "layouts.root_path_link_title")] when :user diff --git a/app/mailers/admins_group_mailer.rb b/app/mailers/admins_group_mailer.rb deleted file mode 100644 index 03e552a1b..000000000 --- a/app/mailers/admins_group_mailer.rb +++ /dev/null @@ -1,13 +0,0 @@ -class AdminsGroupMailer < ApplicationMailer - layout 'mailers/layout' - - def notify_added_admins_group_managers(admins_group, added_admins_group_managers, current_super_admin_email) - added_admins_group_manager_emails = added_admins_group_managers.map(&:email) - @admins_group = admins_group - @current_super_admin_email = current_super_admin_email - - subject = "Vous avez été ajouté(e) en tant que gestionnaire du groupe d'administrateur \"#{admins_group.name}\"" - - mail(bcc: added_admins_group_manager_emails, subject: subject) - end -end diff --git a/app/mailers/groupe_gestionnaire_mailer.rb b/app/mailers/groupe_gestionnaire_mailer.rb new file mode 100644 index 000000000..fc367e751 --- /dev/null +++ b/app/mailers/groupe_gestionnaire_mailer.rb @@ -0,0 +1,13 @@ +class GroupeGestionnaireMailer < ApplicationMailer + layout 'mailers/layout' + + def notify_added_gestionnaires(groupe_gestionnaire, added_gestionnaires, current_super_admin_email) + added_gestionnaire_emails = added_gestionnaires.map(&:email) + @groupe_gestionnaire = groupe_gestionnaire + @current_super_admin_email = current_super_admin_email + + subject = "Vous avez été ajouté(e) en tant que gestionnaire du groupe d'administrateur \"#{groupe_gestionnaire.name}\"" + + mail(bcc: added_gestionnaire_emails, subject: subject) + end +end diff --git a/app/mailers/user_mailer.rb b/app/mailers/user_mailer.rb index 4304dfce5..4e8f97db9 100644 --- a/app/mailers/user_mailer.rb +++ b/app/mailers/user_mailer.rb @@ -38,10 +38,10 @@ class UserMailer < ApplicationMailer reply_to: CONTACT_EMAIL) end - def invite_admins_group_manager(user, reset_password_token, admins_group) + def invite_gestionnaire(user, reset_password_token, groupe_gestionnaire) @reset_password_token = reset_password_token @user = user - @admins_group = admins_group + @groupe_gestionnaire = groupe_gestionnaire subject = "Activez votre compte gestionnaire" mail(to: user.email, diff --git a/app/models/administrateur.rb b/app/models/administrateur.rb index 73904ae39..0f6e1e6de 100644 --- a/app/models/administrateur.rb +++ b/app/models/administrateur.rb @@ -9,7 +9,7 @@ class Administrateur < ApplicationRecord has_and_belongs_to_many :default_zones, class_name: 'Zone', join_table: 'default_zones_administrateurs' belongs_to :user - belongs_to :admins_group, optional: true + belongs_to :groupe_gestionnaire, optional: true default_scope { eager_load(:user) } diff --git a/app/models/admins_group.rb b/app/models/admins_group.rb deleted file mode 100644 index e828e419b..000000000 --- a/app/models/admins_group.rb +++ /dev/null @@ -1,30 +0,0 @@ -class AdminsGroup < ApplicationRecord - belongs_to :admins_group, optional: true # parent - has_many :children, class_name: "AdminsGroup", inverse_of: :admins_group - has_many :administrateurs - has_and_belongs_to_many :admins_group_managers - - def add(admins_group_manager) - admins_group_managers << admins_group_manager - end - - def add_admins_group_managers(ids: [], emails: []) - admins_group_managers_to_add, valid_emails, invalid_emails = AdminsGroupManager.find_all_by_identifier_with_emails(ids:, emails:) - not_found_emails = valid_emails - admins_group_managers_to_add.map(&:email) - - # Send invitations to users without account - if not_found_emails.present? - admins_group_managers_to_add += not_found_emails.map do |email| - user = User.create_or_promote_to_admins_group_manager(email, SecureRandom.hex) - user.invite_admins_group_manager!(self) - user.admins_group_manager - end - end - - # We dont't want to assign a user to an admins_group if they are already assigned to it - admins_group_managers_to_add -= admins_group_managers - admins_group_managers_to_add.each { add(_1) } - - [admins_group_managers_to_add, invalid_emails] - end -end diff --git a/app/models/admins_group_manager.rb b/app/models/gestionnaire.rb similarity index 77% rename from app/models/admins_group_manager.rb rename to app/models/gestionnaire.rb index cb11b1bd3..19228c412 100644 --- a/app/models/admins_group_manager.rb +++ b/app/models/gestionnaire.rb @@ -1,5 +1,5 @@ -class AdminsGroupManager < ApplicationRecord - has_and_belongs_to_many :admins_groups +class Gestionnaire < ApplicationRecord + has_and_belongs_to_many :groupe_gestionnaires belongs_to :user @@ -26,7 +26,7 @@ class AdminsGroupManager < ApplicationRecord end def can_be_deleted? - !(root_admins_group = admins_groups.where(admins_group: nil).first) || root_admins_group.admins_group_managers.size > 1 + !(root_groupe_gestionnaire = groupe_gestionnaires.where(groupe_gestionnaire: nil).first) || root_groupe_gestionnaire.gestionnaires.size > 1 end def registration_state diff --git a/app/models/groupe_gestionnaire.rb b/app/models/groupe_gestionnaire.rb new file mode 100644 index 000000000..526418d37 --- /dev/null +++ b/app/models/groupe_gestionnaire.rb @@ -0,0 +1,30 @@ +class GroupeGestionnaire < ApplicationRecord + belongs_to :groupe_gestionnaire, optional: true # parent + has_many :children, class_name: "GroupeGestionnaire", inverse_of: :groupe_gestionnaire + has_many :administrateurs + has_and_belongs_to_many :gestionnaires + + def add(gestionnaire) + gestionnaires << gestionnaire + end + + def add_gestionnaires(ids: [], emails: []) + gestionnaires_to_add, valid_emails, invalid_emails = Gestionnaire.find_all_by_identifier_with_emails(ids:, emails:) + not_found_emails = valid_emails - gestionnaires_to_add.map(&:email) + + # Send invitations to users without account + if not_found_emails.present? + gestionnaires_to_add += not_found_emails.map do |email| + user = User.create_or_promote_to_gestionnaire(email, SecureRandom.hex) + user.invite_gestionnaire!(self) + user.gestionnaire + end + end + + # We dont't want to assign a user to an groupe_gestionnaire if they are already assigned to it + gestionnaires_to_add -= gestionnaires + gestionnaires_to_add.each { add(_1) } + + [gestionnaires_to_add, invalid_emails] + end +end diff --git a/app/models/user.rb b/app/models/user.rb index 25c08fb4e..606aea642 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -26,7 +26,7 @@ class User < ApplicationRecord has_one :france_connect_information, dependent: :destroy has_one :instructeur, dependent: :destroy has_one :administrateur, dependent: :destroy - has_one :admins_group_manager, dependent: :destroy + has_one :gestionnaire, dependent: :destroy has_one :expert, dependent: :destroy belongs_to :requested_merge_into, class_name: 'User', optional: true @@ -77,8 +77,8 @@ class User < ApplicationRecord UserMailer.invite_instructeur(self, set_reset_password_token).deliver_later end - def invite_admins_group_manager!(admins_group) - UserMailer.invite_admins_group_manager(self, set_reset_password_token, admins_group).deliver_later + def invite_gestionnaire!(groupe_gestionnaire) + UserMailer.invite_gestionnaire(self, set_reset_password_token, groupe_gestionnaire).deliver_later end def invite_administrateur!(administration_id) @@ -108,11 +108,11 @@ class User < ApplicationRecord user end - def self.create_or_promote_to_admins_group_manager(email, password) + def self.create_or_promote_to_gestionnaire(email, password) user = User.create_or_promote_to_administrateur(email, password) - if user.valid? && user.admins_group_manager.nil? - user.create_admins_group_manager! + if user.valid? && user.gestionnaire.nil? + user.create_gestionnaire! end user @@ -160,8 +160,8 @@ class User < ApplicationRecord instructeur.present? end - def admins_group_manager? - admins_group_manager.present? + def gestionnaire? + gestionnaire.present? end def expert? diff --git a/app/views/admins_group_mailer/notify_added_admins_group_managers.html.haml b/app/views/admins_group_mailer/notify_added_admins_group_managers.html.haml deleted file mode 100644 index 40c1190a3..000000000 --- a/app/views/admins_group_mailer/notify_added_admins_group_managers.html.haml +++ /dev/null @@ -1,6 +0,0 @@ -%p= t(:hello, scope: [:views, :shared, :greetings]) - -%p - = t(".email_body", admins_group_name: @admins_group.name, email: @current_super_admin_email, application_name: APPLICATION_NAME) - -= render partial: "layouts/mailers/signature" diff --git a/app/views/groupe_gestionnaire_mailer/notify_added_gestionnaires.html.haml b/app/views/groupe_gestionnaire_mailer/notify_added_gestionnaires.html.haml new file mode 100644 index 000000000..94f82e361 --- /dev/null +++ b/app/views/groupe_gestionnaire_mailer/notify_added_gestionnaires.html.haml @@ -0,0 +1,6 @@ +%p= t(:hello, scope: [:views, :shared, :greetings]) + +%p + = t(".email_body", groupe_gestionnaire_name: @groupe_gestionnaire.name, email: @current_super_admin_email, application_name: APPLICATION_NAME) + += render partial: "layouts/mailers/signature" diff --git a/app/views/layouts/_account_dropdown.haml b/app/views/layouts/_account_dropdown.haml index bfcd975d6..99f86a93f 100644 --- a/app/views/layouts/_account_dropdown.haml +++ b/app/views/layouts/_account_dropdown.haml @@ -30,11 +30,11 @@ = link_to admin_procedures_path, class: "fr-nav__link" do %span.fr-icon-refresh-line.fr-icon--sm = t('go_admin', scope: [:layouts]) - - if admins_group_manager_signed_in? && nav_bar_profile != :admins_group_manager + - if gestionnaire_signed_in? && nav_bar_profile != :gestionnaire %li - = link_to admins_group_manager_admins_groups_path, class: "fr-nav__link" do + = link_to gestionnaire_groupe_gestionnaires_path, class: "fr-nav__link" do %span.fr-icon-refresh-line.fr-icon--sm - = t('go_admins_group_manager', scope: [:layouts]) + = t('go_gestionnaire', scope: [:layouts]) - if super_admin_signed_in? %li diff --git a/app/views/user_mailer/invite_admins_group_manager.html.haml b/app/views/user_mailer/invite_gestionnaire.html.haml similarity index 78% rename from app/views/user_mailer/invite_admins_group_manager.html.haml rename to app/views/user_mailer/invite_gestionnaire.html.haml index 879f9898f..35e3d8007 100644 --- a/app/views/user_mailer/invite_admins_group_manager.html.haml +++ b/app/views/user_mailer/invite_gestionnaire.html.haml @@ -4,7 +4,7 @@ Bonjour, %p - Vous venez d’être nommé gestionnaire du groupe #{@admins_group.name} sur #{APPLICATION_NAME}. + Vous venez d’être nommé gestionnaire du groupe #{@groupe_gestionnaire.name} 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 :  diff --git a/config/locales/en.yml b/config/locales/en.yml index 15da4b231..f7265c860 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -101,7 +101,7 @@ en: user: 'Go to files list' instructeur: 'Go to procedures list' admin: 'Go to administration panel' - admins_group_manager: "Aller admins group panel" + gestionnaire: "Aller admins group panel" views: legal_notice: title: "Legal Notices" diff --git a/config/locales/fr.yml b/config/locales/fr.yml index aa6d6fb5f..aa32f67ba 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -92,7 +92,7 @@ fr: user: 'Aller à la liste des dossiers' instructeur: 'Aller à la liste des démarches' admin: "Aller au panneau d’administration" - admins_group_manager: "Aller au panneau de gestionnaire" + gestionnaire: "Aller au panneau de gestionnaire" views: legal_notice: title: "Mentions légales" diff --git a/config/locales/models/admins_group_manager/fr.yml b/config/locales/models/gestionnaire/fr.yml similarity index 54% rename from config/locales/models/admins_group_manager/fr.yml rename to config/locales/models/gestionnaire/fr.yml index c6d9b2293..60ee3bcf9 100644 --- a/config/locales/models/admins_group_manager/fr.yml +++ b/config/locales/models/gestionnaire/fr.yml @@ -1,9 +1,9 @@ fr: activerecord: attributes: - admins_group_manager: - admins_groups: Groupes + gestionnaire: + groupe_gestionnaires: Groupes models: - admins_group_manager: + gestionnaire: one: Gestionnaire other: Gestionnaires diff --git a/config/locales/models/admins_group/fr.yml b/config/locales/models/groupe_gestionnaire/fr.yml similarity index 58% rename from config/locales/models/admins_group/fr.yml rename to config/locales/models/groupe_gestionnaire/fr.yml index 4aeb8b4ba..ef29657cb 100644 --- a/config/locales/models/admins_group/fr.yml +++ b/config/locales/models/groupe_gestionnaire/fr.yml @@ -1,9 +1,9 @@ fr: activerecord: attributes: - admins_group: - admins_group_managers: Gestionnaires + groupe_gestionnaire: + gestionnaires: Gestionnaires models: - admins_group: + groupe_gestionnaire: one: Groupe d'administrateurs other: Groupes d'administrateurs diff --git a/config/locales/views/admins_group_mailer/notify_added_admins_group_managers/en.yml b/config/locales/views/admins_group_mailer/notify_added_admins_group_managers/en.yml deleted file mode 100644 index 95528051d..000000000 --- a/config/locales/views/admins_group_mailer/notify_added_admins_group_managers/en.yml +++ /dev/null @@ -1,4 +0,0 @@ -en: - admins_group_mailer: - notify_added_admins_group_managers: - email_body: "You were assigned as manager on the admins group %{admins_group_name} on %{application_name} by « %{email} »" diff --git a/config/locales/views/admins_group_mailer/notify_added_admins_group_managers/fr.yml b/config/locales/views/admins_group_mailer/notify_added_admins_group_managers/fr.yml deleted file mode 100644 index f63b8007c..000000000 --- a/config/locales/views/admins_group_mailer/notify_added_admins_group_managers/fr.yml +++ /dev/null @@ -1,4 +0,0 @@ -fr: - admins_group_mailer: - notify_added_admins_group_managers: - email_body: "Vous venez d’être nommé gestionnaire du groupe %{admins_group_name} sur %{application_name} par « %{email} »." diff --git a/config/locales/views/groupe_gestionnaire_mailer/notify_added_gestionnaires/en.yml b/config/locales/views/groupe_gestionnaire_mailer/notify_added_gestionnaires/en.yml new file mode 100644 index 000000000..ff5f8c9d6 --- /dev/null +++ b/config/locales/views/groupe_gestionnaire_mailer/notify_added_gestionnaires/en.yml @@ -0,0 +1,4 @@ +en: + groupe_gestionnaire_mailer: + notify_added_gestionnaires: + email_body: "You were assigned as manager on the admins group %{groupe_gestionnaire_name} on %{application_name} by « %{email} »" diff --git a/config/locales/views/groupe_gestionnaire_mailer/notify_added_gestionnaires/fr.yml b/config/locales/views/groupe_gestionnaire_mailer/notify_added_gestionnaires/fr.yml new file mode 100644 index 000000000..c603cf67b --- /dev/null +++ b/config/locales/views/groupe_gestionnaire_mailer/notify_added_gestionnaires/fr.yml @@ -0,0 +1,4 @@ +fr: + groupe_gestionnaire_mailer: + notify_added_gestionnaires: + email_body: "Vous venez d’être nommé gestionnaire du groupe %{groupe_gestionnaire_name} sur %{application_name} par « %{email} »." diff --git a/config/locales/views/layouts/_account_dropdown.en.yml b/config/locales/views/layouts/_account_dropdown.en.yml index b4ec8ff11..a611a8065 100644 --- a/config/locales/views/layouts/_account_dropdown.en.yml +++ b/config/locales/views/layouts/_account_dropdown.en.yml @@ -8,14 +8,14 @@ en: go_instructor: "Switch to instructor" go_expert: "Switch to expert" go_admin: "Switch to administrator" - go_admins_group_manager: "Switch to admins group manager" + go_gestionnaire: "Switch to admins group manager" profile: "See my profile" logout: "Log out" my_account: "My account" connected_as: "connected as %{profile}" instructeur: instructor administrateur: admin - admins_group_manager: admins group manager + gestionnaire: admins group manager expert: expert user: user guest: guest diff --git a/config/locales/views/layouts/_account_dropdown.fr.yml b/config/locales/views/layouts/_account_dropdown.fr.yml index 4a83e1dc2..5b3ab8274 100644 --- a/config/locales/views/layouts/_account_dropdown.fr.yml +++ b/config/locales/views/layouts/_account_dropdown.fr.yml @@ -8,14 +8,14 @@ fr: go_instructor: "Passer en instructeur" go_expert: "Passer en expert" go_admin: "Passer en administrateur" - go_admins_group_manager: "Passer en gestionnaire" + go_gestionnaire: "Passer en gestionnaire" profile: "Voir mon profil" logout: "Se déconnecter" my_account: "Mon compte" connected_as: "connecté en tant qu’%{profile}" instructeur: instructeur administrateur: administrateur - admins_group_manager: gestionnaire + gestionnaire: gestionnaire expert: expert user: usager guest: invité diff --git a/config/locales/views/manager/fr.yml b/config/locales/views/manager/fr.yml index 2da3bf467..108d954bd 100644 --- a/config/locales/views/manager/fr.yml +++ b/config/locales/views/manager/fr.yml @@ -1,7 +1,7 @@ fr: manager: - admins_groups: - add_admins_group_manager: + groupe_gestionnaires: + add_gestionnaire: wrong_address: one: "%{emails} n’est pas une adresse email valide" other: "%{emails} ne sont pas des adresses emails valides" diff --git a/config/routes.rb b/config/routes.rb index 1da10ded2..8404179c1 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -57,10 +57,10 @@ Rails.application.routes.draw do end if ENV['ADMINS_GROUP_ENABLED'] == 'enabled' # can be removed if needed when EVERY PARTS of the feature will be merged / from env.example.optional - resources :admins_group_managers, path: 'gestionnaires', only: [:index, :show, :edit, :update] + resources :gestionnaires, only: [:index, :show, :edit, :update] - resources :admins_groups, path: 'groupe_administrateurs', only: [:index, :show, :new, :create, :edit, :update] do - post 'add_admins_group_manager', on: :member + resources :groupe_gestionnaires, path: 'groupe_administrateurs', only: [:index, :show, :new, :create, :edit, :update] do + post 'add_gestionnaire', on: :member end end @@ -476,11 +476,11 @@ Rails.application.routes.draw do if ENV['ADMINS_GROUP_ENABLED'] == 'enabled' # can be removed if needed when EVERY PARTS of the feature will be merged / from env.example.optional # - # Admins Group Manager (gestionnaire) + # Gestionnaire # - scope module: 'admins_group_managers', path: 'gestionnaire', as: 'admins_group_manager' do - resources :admins_groups, path: 'groupe_administrateurs', only: [:index, :create] + scope module: 'gestionnaires', as: 'gestionnaire' do + resources :groupe_gestionnaires, path: 'groupe_administrateurs', only: [:index, :create] end end diff --git a/db/migrate/20230813091837_create_admins_group_managers.rb b/db/migrate/20230813091837_create_admins_group_managers.rb deleted file mode 100644 index b8cb3780c..000000000 --- a/db/migrate/20230813091837_create_admins_group_managers.rb +++ /dev/null @@ -1,9 +0,0 @@ -class CreateAdminsGroupManagers < ActiveRecord::Migration[7.0] - def change - create_table "admins_group_managers" do |t| - t.bigint :user_id, null: false - t.index [:user_id], name: :index_admins_group_managers_on_user_id - t.timestamps - end - end -end diff --git a/db/migrate/20230813091838_create_admins_groups.rb b/db/migrate/20230813091838_create_admins_groups.rb deleted file mode 100644 index 75a38013e..000000000 --- a/db/migrate/20230813091838_create_admins_groups.rb +++ /dev/null @@ -1,15 +0,0 @@ -class CreateAdminsGroups < ActiveRecord::Migration[7.0] - def change - create_table "admins_groups" do |t| - t.string :name, null: false - t.references :admins_group - t.index [:name], name: :index_admins_groups_on_name - t.timestamps - end - - create_join_table :admins_groups, :admins_group_managers do |t| - t.index [:admins_group_id, :admins_group_manager_id], name: :index_on_admins_group_and_admins_group_manager - t.index [:admins_group_manager_id, :admins_group_id], name: :index_on_admins_group_manager_and_admins_group - end - end -end diff --git a/db/migrate/20230813091846_add_admins_group_to_administrateurs.rb b/db/migrate/20230813091846_add_admins_group_to_administrateurs.rb deleted file mode 100644 index 52c07d340..000000000 --- a/db/migrate/20230813091846_add_admins_group_to_administrateurs.rb +++ /dev/null @@ -1,7 +0,0 @@ -class AddAdminsGroupToAdministrateurs < ActiveRecord::Migration[7.0] - disable_ddl_transaction! - - def change - add_reference :administrateurs, :admins_group, index: { algorithm: :concurrently }, null: true - end -end diff --git a/db/migrate/20230813091847_add_foreign_key_admins_group_to_administrateurs.rb b/db/migrate/20230813091847_add_foreign_key_admins_group_to_administrateurs.rb deleted file mode 100644 index e155c3a13..000000000 --- a/db/migrate/20230813091847_add_foreign_key_admins_group_to_administrateurs.rb +++ /dev/null @@ -1,5 +0,0 @@ -class AddForeignKeyAdminsGroupToAdministrateurs < ActiveRecord::Migration[7.0] - def change - add_foreign_key :administrateurs, :admins_groups, validate: false - end -end diff --git a/db/migrate/20230813091848_validate_foreign_key_admins_group_to_administrateurs.rb b/db/migrate/20230813091848_validate_foreign_key_admins_group_to_administrateurs.rb deleted file mode 100644 index 6af848b01..000000000 --- a/db/migrate/20230813091848_validate_foreign_key_admins_group_to_administrateurs.rb +++ /dev/null @@ -1,5 +0,0 @@ -class ValidateForeignKeyAdminsGroupToAdministrateurs < ActiveRecord::Migration[7.0] - def change - validate_foreign_key :administrateurs, :admins_groups - end -end diff --git a/db/migrate/20230813091937_create_gestionnaires.rb b/db/migrate/20230813091937_create_gestionnaires.rb new file mode 100644 index 000000000..a4247751c --- /dev/null +++ b/db/migrate/20230813091937_create_gestionnaires.rb @@ -0,0 +1,9 @@ +class CreateGestionnaires < ActiveRecord::Migration[7.0] + def change + create_table "gestionnaires" do |t| + t.bigint :user_id, null: false + t.index [:user_id], name: :index_gestionnaires_on_user_id + t.timestamps + end + end +end diff --git a/db/migrate/20230813091938_create_groupe_gestionnaires.rb b/db/migrate/20230813091938_create_groupe_gestionnaires.rb new file mode 100644 index 000000000..ef8352297 --- /dev/null +++ b/db/migrate/20230813091938_create_groupe_gestionnaires.rb @@ -0,0 +1,15 @@ +class CreateGroupeGestionnaires < ActiveRecord::Migration[7.0] + def change + create_table "groupe_gestionnaires" do |t| + t.string :name, null: false + t.references :groupe_gestionnaire + t.index [:name], name: :index_groupe_gestionnaires_on_name + t.timestamps + end + + create_join_table :groupe_gestionnaires, :gestionnaires do |t| + t.index [:groupe_gestionnaire_id, :gestionnaire_id], name: :index_on_groupe_gestionnaire_and_gestionnaire + t.index [:gestionnaire_id, :groupe_gestionnaire_id], name: :index_on_gestionnaire_and_groupe_gestionnaire + end + end +end diff --git a/db/migrate/20230813091946_add_groupe_gestionnaire_to_administrateurs.rb b/db/migrate/20230813091946_add_groupe_gestionnaire_to_administrateurs.rb new file mode 100644 index 000000000..e50fdacfe --- /dev/null +++ b/db/migrate/20230813091946_add_groupe_gestionnaire_to_administrateurs.rb @@ -0,0 +1,7 @@ +class AddGroupeGestionnaireToAdministrateurs < ActiveRecord::Migration[7.0] + disable_ddl_transaction! + + def change + add_reference :administrateurs, :groupe_gestionnaire, index: { algorithm: :concurrently }, null: true + end +end diff --git a/db/migrate/20230813091947_add_foreign_key_groupe_gestionnaire_to_administrateurs.rb b/db/migrate/20230813091947_add_foreign_key_groupe_gestionnaire_to_administrateurs.rb new file mode 100644 index 000000000..fd14a0a1d --- /dev/null +++ b/db/migrate/20230813091947_add_foreign_key_groupe_gestionnaire_to_administrateurs.rb @@ -0,0 +1,5 @@ +class AddForeignKeyGroupeGestionnaireToAdministrateurs < ActiveRecord::Migration[7.0] + def change + add_foreign_key :administrateurs, :groupe_gestionnaires, validate: false + end +end diff --git a/db/migrate/20230813091948_validate_foreign_key_groupe_gestionnaire_to_administrateurs.rb b/db/migrate/20230813091948_validate_foreign_key_groupe_gestionnaire_to_administrateurs.rb new file mode 100644 index 000000000..1a638090e --- /dev/null +++ b/db/migrate/20230813091948_validate_foreign_key_groupe_gestionnaire_to_administrateurs.rb @@ -0,0 +1,5 @@ +class ValidateForeignKeyGroupeGestionnaireToAdministrateurs < ActiveRecord::Migration[7.0] + def change + validate_foreign_key :administrateurs, :groupe_gestionnaires + end +end diff --git a/db/schema.rb b/db/schema.rb index d06624b51..1ac529e07 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -61,11 +61,11 @@ ActiveRecord::Schema[7.0].define(version: 2023_09_28_083809) do end create_table "administrateurs", id: :serial, force: :cascade do |t| - t.bigint "admins_group_id" t.datetime "created_at", precision: 6 + t.bigint "groupe_gestionnaire_id" t.datetime "updated_at", precision: 6 t.bigint "user_id", null: false - t.index ["admins_group_id"], name: "index_administrateurs_on_admins_group_id" + t.index ["groupe_gestionnaire_id"], name: "index_administrateurs_on_groupe_gestionnaire_id" t.index ["user_id"], name: "index_administrateurs_on_user_id" end @@ -90,29 +90,6 @@ ActiveRecord::Schema[7.0].define(version: 2023_09_28_083809) do t.index ["procedure_id"], name: "index_administrateurs_procedures_on_procedure_id" end - create_table "admins_group_managers", force: :cascade do |t| - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.bigint "user_id", null: false - t.index ["user_id"], name: "index_admins_group_managers_on_user_id" - end - - create_table "admins_group_managers_groups", id: false, force: :cascade do |t| - t.bigint "admins_group_id", null: false - t.bigint "admins_group_manager_id", null: false - t.index ["admins_group_id", "admins_group_manager_id"], name: "index_on_admins_group_and_admins_group_manager" - t.index ["admins_group_manager_id", "admins_group_id"], name: "index_on_admins_group_manager_and_admins_group" - end - - create_table "admins_groups", force: :cascade do |t| - t.bigint "admins_group_id" - t.datetime "created_at", null: false - t.string "name", null: false - t.datetime "updated_at", null: false - t.index ["admins_group_id"], name: "index_admins_groups_on_admins_group_id" - t.index ["name"], name: "index_admins_groups_on_name" - end - create_table "api_tokens", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.bigint "administrateur_id", null: false t.bigint "allowed_procedure_ids", array: true @@ -650,6 +627,29 @@ ActiveRecord::Schema[7.0].define(version: 2023_09_28_083809) do t.index ["groupe_instructeur_id"], name: "index_contact_informations_on_groupe_instructeur_id" end + create_table "gestionnaires", force: :cascade do |t| + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.bigint "user_id", null: false + t.index ["user_id"], name: "index_gestionnaires_on_user_id" + end + + create_table "gestionnaires_groupe_gestionnaires", id: false, force: :cascade do |t| + t.bigint "gestionnaire_id", null: false + t.bigint "groupe_gestionnaire_id", null: false + t.index ["gestionnaire_id", "groupe_gestionnaire_id"], name: "index_on_gestionnaire_and_groupe_gestionnaire" + t.index ["groupe_gestionnaire_id", "gestionnaire_id"], name: "index_on_groupe_gestionnaire_and_gestionnaire" + end + + create_table "groupe_gestionnaires", force: :cascade do |t| + t.datetime "created_at", null: false + t.bigint "groupe_gestionnaire_id" + t.string "name", null: false + t.datetime "updated_at", null: false + t.index ["groupe_gestionnaire_id"], name: "index_groupe_gestionnaires_on_groupe_gestionnaire_id" + t.index ["name"], name: "index_groupe_gestionnaires_on_name" + end + create_table "groupe_instructeurs", force: :cascade do |t| t.boolean "closed", default: false t.datetime "created_at", precision: 6, null: false @@ -1059,7 +1059,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_09_28_083809) do add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id" add_foreign_key "active_storage_variant_records", "active_storage_blobs", column: "blob_id" - add_foreign_key "administrateurs", "admins_groups" + add_foreign_key "administrateurs", "groupe_gestionnaires" add_foreign_key "administrateurs", "users" add_foreign_key "administrateurs_instructeurs", "administrateurs" add_foreign_key "administrateurs_instructeurs", "instructeurs" diff --git a/spec/factories/admins_group_manager.rb b/spec/factories/admins_group_manager.rb deleted file mode 100644 index b8bf34a83..000000000 --- a/spec/factories/admins_group_manager.rb +++ /dev/null @@ -1,12 +0,0 @@ -FactoryBot.define do - sequence(:admins_group_manager_email) { |n| "admins_group_manager#{n}@demarches-simplifiees.fr" } - - factory :admins_group_manager do - user { association :user, email: email, password: password } - - transient do - email { generate(:admins_group_manager_email) } - password { 'somethingverycomplated!' } - end - end -end diff --git a/spec/factories/gestionnaire.rb b/spec/factories/gestionnaire.rb new file mode 100644 index 000000000..d8ca3af36 --- /dev/null +++ b/spec/factories/gestionnaire.rb @@ -0,0 +1,12 @@ +FactoryBot.define do + sequence(:gestionnaire_email) { |n| "gestionnaire#{n}@demarches-simplifiees.fr" } + + factory :gestionnaire do + user { association :user, email: email, password: password } + + transient do + email { generate(:gestionnaire_email) } + password { 'somethingverycomplated!' } + end + end +end diff --git a/spec/factories/admins_group.rb b/spec/factories/groupe_gestionnaire.rb similarity index 67% rename from spec/factories/admins_group.rb rename to spec/factories/groupe_gestionnaire.rb index b85b14cd4..b06039d02 100644 --- a/spec/factories/admins_group.rb +++ b/spec/factories/groupe_gestionnaire.rb @@ -1,5 +1,5 @@ FactoryBot.define do - factory :admins_group do + factory :groupe_gestionnaire do sequence(:name) { |n| "Group #{n}" } end end diff --git a/spec/mailers/admins_group_mailer_spec.rb b/spec/mailers/admins_group_mailer_spec.rb deleted file mode 100644 index dfb507417..000000000 --- a/spec/mailers/admins_group_mailer_spec.rb +++ /dev/null @@ -1,16 +0,0 @@ -RSpec.describe AdminsGroupMailer, type: :mailer do - describe '#notify_added_admins_group_managers' do - let(:admins_group) { create(:admins_group) } - - let(:admins_group_managers_to_add) { [create(:admins_group_manager, email: 'int3@g'), create(:admins_group_manager, email: 'int4@g')] } - - let(:current_super_admin_email) { 'toto@email.com' } - - subject { described_class.notify_added_admins_group_managers(admins_group, admins_group_managers_to_add, current_super_admin_email) } - - before { admins_group_managers_to_add.each { admins_group.add(_1) } } - - it { expect(subject.body).to include('Vous venez d’être nommé gestionnaire du groupe') } - it { expect(subject.bcc).to match_array(['int3@g', 'int4@g']) } - end -end diff --git a/spec/mailers/groupe_gestionnaire_mailer_spec.rb b/spec/mailers/groupe_gestionnaire_mailer_spec.rb new file mode 100644 index 000000000..6a36ebd58 --- /dev/null +++ b/spec/mailers/groupe_gestionnaire_mailer_spec.rb @@ -0,0 +1,16 @@ +RSpec.describe GroupeGestionnaireMailer, type: :mailer do + describe '#notify_added_gestionnaires' do + let(:groupe_gestionnaire) { create(:groupe_gestionnaire) } + + let(:gestionnaires_to_add) { [create(:gestionnaire, email: 'int3@g'), create(:gestionnaire, email: 'int4@g')] } + + let(:current_super_admin_email) { 'toto@email.com' } + + subject { described_class.notify_added_gestionnaires(groupe_gestionnaire, gestionnaires_to_add, current_super_admin_email) } + + before { gestionnaires_to_add.each { groupe_gestionnaire.add(_1) } } + + it { expect(subject.body).to include('Vous venez d’être nommé gestionnaire du groupe') } + it { expect(subject.bcc).to match_array(['int3@g', 'int4@g']) } + end +end diff --git a/spec/mailers/previews/admins_group_mailer_preview.rb b/spec/mailers/previews/admins_group_mailer_preview.rb deleted file mode 100644 index 0c92760ef..000000000 --- a/spec/mailers/previews/admins_group_mailer_preview.rb +++ /dev/null @@ -1,14 +0,0 @@ -class AdminsGroupMailerPreview < ActionMailer::Preview - def notify_added_admins_group_managers - admins_group = AdminsGroup.new(name: 'un groupe d\'admin') - current_super_admin_email = 'admin@dgfip.com' - admins_group_managers = [AdminsGroupManager.new(user: user)] - AdminsGroupMailer.notify_added_admins_group_managers(admins_group, admins_group_managers, current_super_admin_email) - end - - private - - def user - User.new(id: 10, email: 'test@exemple.fr') - end -end diff --git a/spec/mailers/previews/groupe_gestionnaire_mailer_preview.rb b/spec/mailers/previews/groupe_gestionnaire_mailer_preview.rb new file mode 100644 index 000000000..e522ee69d --- /dev/null +++ b/spec/mailers/previews/groupe_gestionnaire_mailer_preview.rb @@ -0,0 +1,14 @@ +class GroupeGestionnaireMailerPreview < ActionMailer::Preview + def notify_added_gestionnaires + groupe_gestionnaire = GroupeGestionnaire.new(name: 'un groupe d\'admin') + current_super_admin_email = 'admin@dgfip.com' + gestionnaires = [Gestionnaire.new(user: user)] + GroupeGestionnaireMailer.notify_added_gestionnaires(groupe_gestionnaire, gestionnaires, current_super_admin_email) + end + + private + + def user + User.new(id: 10, email: 'test@exemple.fr') + end +end diff --git a/spec/mailers/previews/user_mailer_preview.rb b/spec/mailers/previews/user_mailer_preview.rb index 2601027d8..e77f4ce26 100644 --- a/spec/mailers/previews/user_mailer_preview.rb +++ b/spec/mailers/previews/user_mailer_preview.rb @@ -24,9 +24,9 @@ class UserMailerPreview < ActionMailer::Preview UserMailer.invite_instructeur(user, 'aedfa0d0') end - def invite_admins_group_manager - admins_group = AdminsGroup.new(name: 'Root admins group') - UserMailer.invite_admins_group_manager(user, 'aedfa0d0', admins_group) + def invite_gestionnaire + groupe_gestionnaire = GroupeGestionnaire.new(name: 'Root admins group') + UserMailer.invite_gestionnaire(user, 'aedfa0d0', groupe_gestionnaire) end private diff --git a/spec/models/administrateur_spec.rb b/spec/models/administrateur_spec.rb index e658359e7..958d9016e 100644 --- a/spec/models/administrateur_spec.rb +++ b/spec/models/administrateur_spec.rb @@ -3,7 +3,7 @@ describe Administrateur, type: :model do describe 'associations' do it { is_expected.to have_and_belong_to_many(:instructeurs) } - it { is_expected.to belong_to(:admins_group).optional } + it { is_expected.to belong_to(:groupe_gestionnaire).optional } end describe "#can_be_deleted?" do diff --git a/spec/models/admins_group_manager_spec.rb b/spec/models/admins_group_manager_spec.rb deleted file mode 100644 index 61ca156d0..000000000 --- a/spec/models/admins_group_manager_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -describe AdminsGroupManager, type: :model do - describe 'associations' do - it { is_expected.to have_and_belong_to_many(:admins_groups) } - end -end diff --git a/spec/models/admins_group_spec.rb b/spec/models/admins_group_spec.rb deleted file mode 100644 index 30d227a4a..000000000 --- a/spec/models/admins_group_spec.rb +++ /dev/null @@ -1,8 +0,0 @@ -describe AdminsGroup, type: :model do - describe 'associations' do - it { is_expected.to belong_to(:admins_group).optional } - it { is_expected.to have_many(:children) } - it { is_expected.to have_many(:administrateurs) } - it { is_expected.to have_and_belong_to_many(:admins_group_managers) } - end -end diff --git a/spec/models/gestionnaire_spec.rb b/spec/models/gestionnaire_spec.rb new file mode 100644 index 000000000..2a679ae04 --- /dev/null +++ b/spec/models/gestionnaire_spec.rb @@ -0,0 +1,5 @@ +describe Gestionnaire, type: :model do + describe 'associations' do + it { is_expected.to have_and_belong_to_many(:groupe_gestionnaires) } + end +end diff --git a/spec/models/groupe_gestionnaire_spec.rb b/spec/models/groupe_gestionnaire_spec.rb new file mode 100644 index 000000000..d9f37b6b4 --- /dev/null +++ b/spec/models/groupe_gestionnaire_spec.rb @@ -0,0 +1,8 @@ +describe GroupeGestionnaire, type: :model do + describe 'associations' do + it { is_expected.to belong_to(:groupe_gestionnaire).optional } + it { is_expected.to have_many(:children) } + it { is_expected.to have_many(:administrateurs) } + it { is_expected.to have_and_belong_to_many(:gestionnaires) } + end +end