diff --git a/app/models/assign_to.rb b/app/models/assign_to.rb index 1e5621fe3..43da53ea3 100644 --- a/app/models/assign_to.rb +++ b/app/models/assign_to.rb @@ -3,6 +3,8 @@ class AssignTo < ApplicationRecord belongs_to :gestionnaire has_one :procedure_presentation, dependent: :destroy + scope :with_email_notifications, -> { where(email_notifications_enabled: true) } + def procedure_presentation_or_default_and_errors errors = reset_procedure_presentation_if_invalid [procedure_presentation || build_procedure_presentation, errors] diff --git a/app/models/gestionnaire.rb b/app/models/gestionnaire.rb index 82516d4de..8d00dda66 100644 --- a/app/models/gestionnaire.rb +++ b/app/models/gestionnaire.rb @@ -11,6 +11,10 @@ class Gestionnaire < ApplicationRecord has_many :assign_to, dependent: :destroy has_many :procedures, through: :assign_to + + has_many :assign_to_with_email_notifications, -> { with_email_notifications }, class_name: 'AssignTo' + has_many :procedures_with_email_notifications, through: :assign_to_with_email_notifications, source: :procedure + has_many :dossiers, -> { state_not_brouillon }, through: :procedures has_many :follows has_many :followed_dossiers, through: :follows, source: :dossier diff --git a/db/migrate/20190318154812_add_email_notifications_column_to_assign_to.rb b/db/migrate/20190318154812_add_email_notifications_column_to_assign_to.rb new file mode 100644 index 000000000..9443922fc --- /dev/null +++ b/db/migrate/20190318154812_add_email_notifications_column_to_assign_to.rb @@ -0,0 +1,5 @@ +class AddEmailNotificationsColumnToAssignTo < ActiveRecord::Migration[5.2] + def change + add_column :assign_tos, :email_notifications_enabled, :boolean, default: false, null: false + end +end diff --git a/db/schema.rb b/db/schema.rb index 9cb1ebfe5..6b3b6e255 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: 2019_03_11_140926) do +ActiveRecord::Schema.define(version: 2019_03_18_154812) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -99,6 +99,7 @@ ActiveRecord::Schema.define(version: 2019_03_11_140926) do t.integer "procedure_id" t.datetime "created_at" t.datetime "updated_at" + t.boolean "email_notifications_enabled", default: false, null: false t.index ["gestionnaire_id", "procedure_id"], name: "index_assign_tos_on_gestionnaire_id_and_procedure_id", unique: true t.index ["gestionnaire_id"], name: "index_assign_tos_on_gestionnaire_id" t.index ["procedure_id"], name: "index_assign_tos_on_procedure_id"