Add the possibility to disable weekly email notifications (instructeur) && rename the column email_notifications_enabled to daily_email_notification_enabled

This commit is contained in:
kara Diaby 2020-02-11 15:51:15 +01:00 committed by GitHub Action
parent 35b608fb7d
commit 0b8a59d5e9
6 changed files with 33 additions and 8 deletions

View file

@ -231,8 +231,7 @@ module Instructeurs
end end
def update_email_notifications def update_email_notifications
assign_to.update!(email_notifications_enabled: params[:assign_to][:email_notifications_enabled]) assign_to.update!(assign_to_params)
flash.notice = 'Vos notifications sont enregistrées.' flash.notice = 'Vos notifications sont enregistrées.'
redirect_to instructeur_procedure_path(procedure) redirect_to instructeur_procedure_path(procedure)
end end
@ -246,6 +245,10 @@ module Instructeurs
private private
def assign_to_params
params.require(:assign_to).permit(:email_notifications_enabled, :weekly_email_notifications_enabled)
end
def assign_exports def assign_exports
groupe_instructeurs_for_procedure = current_instructeur.groupe_instructeurs.where(procedure: procedure) groupe_instructeurs_for_procedure = current_instructeur.groupe_instructeurs.where(procedure: procedure)
@xlsx_export = Export.find_for_format_and_groupe_instructeurs(:xlsx, groupe_instructeurs_for_procedure) @xlsx_export = Export.find_for_format_and_groupe_instructeurs(:xlsx, groupe_instructeurs_for_procedure)

View file

@ -75,11 +75,12 @@ class Instructeur < ApplicationRecord
start_date = Time.zone.now.beginning_of_week start_date = Time.zone.now.beginning_of_week
active_procedure_overviews = procedures active_procedure_overviews = procedures
.where(assign_tos: { weekly_email_notifications_enabled: true })
.publiees .publiees
.map { |procedure| procedure.procedure_overview(start_date, groupe_instructeurs) } .map { |procedure| procedure.procedure_overview(start_date, groupe_instructeurs) }
.filter(&:had_some_activities?) .filter(&:had_some_activities?)
if active_procedure_overviews.count == 0 if active_procedure_overviews.empty?
nil nil
else else
{ {

View file

@ -27,18 +27,18 @@
= form.radio_button :email_notifications_enabled, false = form.radio_button :email_notifications_enabled, false
Non Non
= form.label nil, "Recevoir un récapitulatif hebdomadaire" = form.label :email_notification, "Recevoir un récapitulatif hebdomadaire"
%p.notice %p.notice
Cet email récapitule lactivité de la semaine sur lensemble de vos démarches. Cet email récapitule lactivité de la semaine sur lensemble de vos démarches.
%p.notice %p.notice
Il est envoyé chaque semaine le lundi matin, et nest pas désactivable. Il est envoyé chaque semaine le lundi matin.
.radios .radios
%label %label
= radio_button_tag "not_implemented", "Oui", true, disabled: true = form.radio_button :weekly_email_notifications_enabled, true
Oui Oui
%label %label
= radio_button_tag "not_implemented", "Non", false, disabled: true = form.radio_button :weekly_email_notifications_enabled, false
Non Non
.send-wrapper .send-wrapper

View file

@ -0,0 +1,5 @@
class AddWeeklyEmailNotificationsToAssignTos < ActiveRecord::Migration[5.2]
def change
add_column :assign_tos, :weekly_email_notifications_enabled, :boolean, default: true, null: false
end
end

View file

@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2020_01_30_165328) do ActiveRecord::Schema.define(version: 2020_02_10_100938) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@ -104,6 +104,7 @@ ActiveRecord::Schema.define(version: 2020_01_30_165328) do
t.datetime "updated_at" t.datetime "updated_at"
t.boolean "email_notifications_enabled", default: false, null: false t.boolean "email_notifications_enabled", default: false, null: false
t.bigint "groupe_instructeur_id" t.bigint "groupe_instructeur_id"
t.boolean "weekly_email_notifications_enabled", default: true, null: false
t.index ["groupe_instructeur_id", "instructeur_id"], name: "unique_couple_groupe_instructeur_instructeur", unique: true t.index ["groupe_instructeur_id", "instructeur_id"], name: "unique_couple_groupe_instructeur_instructeur", unique: true
t.index ["groupe_instructeur_id"], name: "index_assign_tos_on_groupe_instructeur_id" t.index ["groupe_instructeur_id"], name: "index_assign_tos_on_groupe_instructeur_id"
t.index ["instructeur_id", "procedure_id"], name: "index_assign_tos_on_instructeur_id_and_procedure_id", unique: true t.index ["instructeur_id", "procedure_id"], name: "index_assign_tos_on_instructeur_id_and_procedure_id", unique: true

View file

@ -147,6 +147,21 @@ describe Instructeur, type: :model do
it { expect(instructeur2.last_week_overview[:procedure_overviews]).to match([procedure_overview]) } it { expect(instructeur2.last_week_overview[:procedure_overviews]).to match([procedure_overview]) }
end end
context 'when a procedure published was active and weekly notifications is disable' do
let!(:procedure) { create(:procedure, :published, libelle: 'procedure') }
let(:procedure_overview) { double('procedure_overview', 'had_some_activities?'.to_sym => true) }
before :each do
instructeur2.assign_to_procedure(procedure)
AssignTo
.where(instructeur: instructeur2, groupe_instructeur: procedure.groupe_instructeurs.first)
.update(weekly_email_notifications_enabled: false)
allow_any_instance_of(Procedure).to receive(:procedure_overview).and_return(procedure_overview)
end
it { expect(instructeur2.last_week_overview).to be_nil }
end
context 'when a procedure not published was active with no notifications' do context 'when a procedure not published was active with no notifications' do
let!(:procedure) { create(:procedure, libelle: 'procedure') } let!(:procedure) { create(:procedure, libelle: 'procedure') }
let(:procedure_overview) { double('procedure_overview', 'had_some_activities?'.to_sym => true) } let(:procedure_overview) { double('procedure_overview', 'had_some_activities?'.to_sym => true) }