Ensure Follow dates can not be not null
* Add Follow.unfollowed_at * Change the unicity constraint to gestionnaire/dossier AND unfollowed_at
This commit is contained in:
parent
66a683fab7
commit
ba48a1da6e
3 changed files with 21 additions and 19 deletions
|
@ -94,23 +94,17 @@ class Gestionnaire < ApplicationRecord
|
||||||
.find_by(gestionnaire: self, dossier: dossier)
|
.find_by(gestionnaire: self, dossier: dossier)
|
||||||
|
|
||||||
if follow.present?
|
if follow.present?
|
||||||
# retirer le seen_at.present? une fois la contrainte de presence en base (et les migrations ad hoc)
|
champs_publiques = follow.dossier.champs.updated_since?(follow.demande_seen_at).any?
|
||||||
champs_publiques = follow.demande_seen_at.present? &&
|
|
||||||
follow.dossier.champs.updated_since?(follow.demande_seen_at).any?
|
|
||||||
|
|
||||||
pieces_justificatives = follow.demande_seen_at.present? &&
|
pieces_justificatives = follow.dossier.pieces_justificatives.updated_since?(follow.demande_seen_at).any?
|
||||||
follow.dossier.pieces_justificatives.updated_since?(follow.demande_seen_at).any?
|
|
||||||
|
|
||||||
demande = champs_publiques || pieces_justificatives
|
demande = champs_publiques || pieces_justificatives
|
||||||
|
|
||||||
annotations_privees = follow.annotations_privees_seen_at.present? &&
|
annotations_privees = follow.dossier.champs_private.updated_since?(follow.annotations_privees_seen_at).any?
|
||||||
follow.dossier.champs_private.updated_since?(follow.annotations_privees_seen_at).any?
|
|
||||||
|
|
||||||
avis_notif = follow.avis_seen_at.present? &&
|
avis_notif = follow.dossier.avis.updated_since?(follow.avis_seen_at).any?
|
||||||
follow.dossier.avis.updated_since?(follow.avis_seen_at).any?
|
|
||||||
|
|
||||||
messagerie = follow.messagerie_seen_at.present? &&
|
messagerie = dossier.commentaires
|
||||||
dossier.commentaires
|
|
||||||
.where.not(email: OLD_CONTACT_EMAIL)
|
.where.not(email: OLD_CONTACT_EMAIL)
|
||||||
.where.not(email: CONTACT_EMAIL)
|
.where.not(email: CONTACT_EMAIL)
|
||||||
.updated_since?(follow.messagerie_seen_at).any?
|
.updated_since?(follow.messagerie_seen_at).any?
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
class EnsureFollowDatesNotNull < ActiveRecord::Migration[5.2]
|
||||||
|
def change
|
||||||
|
change_column_null :follows, :demande_seen_at, false
|
||||||
|
change_column_null :follows, :annotations_privees_seen_at, false
|
||||||
|
change_column_null :follows, :avis_seen_at, false
|
||||||
|
change_column_null :follows, :messagerie_seen_at, false
|
||||||
|
end
|
||||||
|
end
|
10
db/schema.rb
10
db/schema.rb
|
@ -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: 2019_03_27_102360) do
|
ActiveRecord::Schema.define(version: 2019_06_07_122941) 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"
|
||||||
|
@ -327,10 +327,10 @@ ActiveRecord::Schema.define(version: 2019_03_27_102360) do
|
||||||
create_table "follows", id: :serial, force: :cascade do |t|
|
create_table "follows", id: :serial, force: :cascade do |t|
|
||||||
t.integer "gestionnaire_id", null: false
|
t.integer "gestionnaire_id", null: false
|
||||||
t.integer "dossier_id", null: false
|
t.integer "dossier_id", null: false
|
||||||
t.datetime "demande_seen_at"
|
t.datetime "demande_seen_at", null: false
|
||||||
t.datetime "annotations_privees_seen_at"
|
t.datetime "annotations_privees_seen_at", null: false
|
||||||
t.datetime "avis_seen_at"
|
t.datetime "avis_seen_at", null: false
|
||||||
t.datetime "messagerie_seen_at"
|
t.datetime "messagerie_seen_at", null: false
|
||||||
t.datetime "created_at"
|
t.datetime "created_at"
|
||||||
t.datetime "updated_at"
|
t.datetime "updated_at"
|
||||||
t.index ["dossier_id"], name: "index_follows_on_dossier_id"
|
t.index ["dossier_id"], name: "index_follows_on_dossier_id"
|
||||||
|
|
Loading…
Add table
Reference in a new issue