Merge pull request #4802 from betagouv/feat/4796-add-column-assign_tos
feat/4796 - Step1 : add new column to Assign_tos
This commit is contained in:
commit
6b598fc080
5 changed files with 29 additions and 1 deletions
|
@ -232,6 +232,7 @@ 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
|
||||
|
|
|
@ -3,9 +3,14 @@ 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
|
||||
|
||||
def procedure_presentation_or_default_and_errors
|
||||
errors = reset_procedure_presentation_if_invalid
|
||||
[procedure_presentation || build_procedure_presentation, errors]
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
class AddDailyEmailNotificationsEnabledToAssignTos < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
add_column :assign_tos, :daily_email_notifications_enabled, :boolean, default: false, null: false
|
||||
end
|
||||
end
|
|
@ -10,7 +10,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 2020_02_11_170134) do
|
||||
ActiveRecord::Schema.define(version: 2020_02_18_144724) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
|
@ -103,6 +103,7 @@ ActiveRecord::Schema.define(version: 2020_02_11_170134) do
|
|||
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
|
||||
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 ["instructeur_id", "procedure_id"], name: "index_assign_tos_on_instructeur_id_and_procedure_id", unique: true
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
namespace :after_party do
|
||||
desc 'Deployment task: backfill_daily_email_notification_columns'
|
||||
task backfill_daily_email_notification_columns: :environment do
|
||||
puts "Running deploy task 'backfill_daily_email_notification_columns'"
|
||||
AssignTo.find_each do |assign_to|
|
||||
columns_to_update = {}
|
||||
if assign_to.email_notifications_enabled != assign_to.daily_email_notifications_enabled
|
||||
columns_to_update[:daily_email_notifications_enabled] = assign_to.email_notifications_enabled
|
||||
end
|
||||
assign_to.update_columns(columns_to_update) unless columns_to_update.empty?
|
||||
end
|
||||
# Update task as completed. If you remove the line below, the task will
|
||||
# run with every deploy (or every time you call after_party:run).
|
||||
AfterParty::TaskRecord.create version: '20200220142710'
|
||||
end # task :backfill_daily_email_notification_columns
|
||||
end # namespace :after_party
|
Loading…
Reference in a new issue