diff --git a/app/controllers/instructeurs/procedures_controller.rb b/app/controllers/instructeurs/procedures_controller.rb index 425f78132..4726bd12b 100644 --- a/app/controllers/instructeurs/procedures_controller.rb +++ b/app/controllers/instructeurs/procedures_controller.rb @@ -232,7 +232,6 @@ module Instructeurs def update_email_notifications assign_to.update!(assign_to_params) - assign_to.update!(daily_email_notifications_enabled: params[:assign_to][:email_notifications_enabled]) flash.notice = 'Vos notifications sont enregistrées.' redirect_to instructeur_procedure_path(procedure) end @@ -247,7 +246,7 @@ module Instructeurs private def assign_to_params - params.require(:assign_to).permit(:email_notifications_enabled, :weekly_email_notifications_enabled) + params.require(:assign_to).permit(:daily_email_notifications_enabled, :weekly_email_notifications_enabled) end def assign_exports diff --git a/app/models/assign_to.rb b/app/models/assign_to.rb index e3264ea40..ac563191d 100644 --- a/app/models/assign_to.rb +++ b/app/models/assign_to.rb @@ -3,13 +3,8 @@ class AssignTo < ApplicationRecord belongs_to :groupe_instructeur has_one :procedure_presentation, dependent: :destroy has_one :procedure, through: :groupe_instructeur - before_save :save_to_new_daily_email_column - scope :with_email_notifications, -> { where(email_notifications_enabled: true) } - - def save_to_new_daily_email_column - self.daily_email_notifications_enabled = email_notifications_enabled - end + scope :with_email_notifications, -> { where(daily_email_notifications_enabled: true) } def procedure_presentation_or_default_and_errors errors = reset_procedure_presentation_if_invalid diff --git a/app/services/notification_service.rb b/app/services/notification_service.rb index c72816826..0c3881ac0 100644 --- a/app/services/notification_service.rb +++ b/app/services/notification_service.rb @@ -3,7 +3,7 @@ class NotificationService def send_instructeur_email_notification Instructeur .includes(assign_to: { procedure: :dossiers }) - .where(assign_tos: { email_notifications_enabled: true }) + .where(assign_tos: { daily_email_notifications_enabled: true }) .find_in_batches { |instructeurs| send_batch_of_instructeurs_email_notification(instructeurs) } end diff --git a/app/views/instructeurs/procedures/email_notifications.html.haml b/app/views/instructeurs/procedures/email_notifications.html.haml index 7ec771b45..950b7db08 100644 --- a/app/views/instructeurs/procedures/email_notifications.html.haml +++ b/app/views/instructeurs/procedures/email_notifications.html.haml @@ -20,11 +20,11 @@ .radios %label - = form.radio_button :email_notifications_enabled, true + = form.radio_button :daily_email_notifications_enabled, true Oui %label - = form.radio_button :email_notifications_enabled, false + = form.radio_button :daily_email_notifications_enabled, false Non = form.label :email_notification, "Recevoir un récapitulatif hebdomadaire" diff --git a/db/migrate/20200227100001_remove_email_notifications_enabled_from_assign_tos.rb b/db/migrate/20200227100001_remove_email_notifications_enabled_from_assign_tos.rb new file mode 100644 index 000000000..eaa5bd99a --- /dev/null +++ b/db/migrate/20200227100001_remove_email_notifications_enabled_from_assign_tos.rb @@ -0,0 +1,5 @@ +class RemoveEmailNotificationsEnabledFromAssignTos < ActiveRecord::Migration[5.2] + def change + remove_column :assign_tos, :email_notifications_enabled + end +end diff --git a/db/schema.rb b/db/schema.rb index d6fa3ff97..7f59ae967 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2020_02_18_144724) do +ActiveRecord::Schema.define(version: 2020_02_27_100001) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -100,7 +100,6 @@ ActiveRecord::Schema.define(version: 2020_02_18_144724) do t.integer "procedure_id" t.datetime "created_at" t.datetime "updated_at" - t.boolean "email_notifications_enabled", default: false, null: false t.bigint "groupe_instructeur_id" t.boolean "weekly_email_notifications_enabled", default: true, null: false t.boolean "daily_email_notifications_enabled", default: false, null: false diff --git a/spec/controllers/instructeurs/procedures_controller_spec.rb b/spec/controllers/instructeurs/procedures_controller_spec.rb index fe614cee5..4fde099fa 100644 --- a/spec/controllers/instructeurs/procedures_controller_spec.rb +++ b/spec/controllers/instructeurs/procedures_controller_spec.rb @@ -424,7 +424,7 @@ describe Instructeurs::ProceduresController, type: :controller do let(:assign_to) { instructeur.assign_to.joins(:groupe_instructeur).find_by(groupe_instructeurs: { procedure: procedure }) } before do - patch :update_email_notifications, params: { procedure_id: procedure.id, assign_to: { id: assign_to.id, email_notifications_enabled: true } } + patch :update_email_notifications, params: { procedure_id: procedure.id, assign_to: { id: assign_to.id, daily_email_notifications_enabled: true } } end it { expect(instructeur.groupe_instructeur_with_email_notifications).to eq([procedure.defaut_groupe_instructeur]) } diff --git a/spec/models/instructeur_spec.rb b/spec/models/instructeur_spec.rb index 2b79e1500..dcd8cefef 100644 --- a/spec/models/instructeur_spec.rb +++ b/spec/models/instructeur_spec.rb @@ -384,7 +384,7 @@ describe Instructeur, type: :model do let(:procedure_to_assign) { create(:procedure) } before do - create(:assign_to, instructeur: instructeur, procedure: procedure_to_assign, email_notifications_enabled: true, groupe_instructeur: procedure_to_assign.defaut_groupe_instructeur) + create(:assign_to, instructeur: instructeur, procedure: procedure_to_assign, daily_email_notifications_enabled: true, groupe_instructeur: procedure_to_assign.defaut_groupe_instructeur) end context 'when a dossier in construction exists' do diff --git a/spec/services/notification_service_spec.rb b/spec/services/notification_service_spec.rb index e2375c8a5..e5db1502c 100644 --- a/spec/services/notification_service_spec.rb +++ b/spec/services/notification_service_spec.rb @@ -28,7 +28,7 @@ describe NotificationService do create(:assign_to, instructeur: instructeur_with_email_notifications, procedure: procedure, - email_notifications_enabled: true) + daily_email_notifications_enabled: true) end context "when there is no activity on the instructeur's procedures" do