From c075a4e415ab5f5522d0b568bd748fd8010b6700 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Thu, 13 Oct 2022 17:45:33 +0200 Subject: [PATCH] =?UTF-8?q?fix(dossier):=20we=20should=20never=20detroy=20?= =?UTF-8?q?user=E2=80=99s=20dossiers=20in=20cascade?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/user.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/models/user.rb b/app/models/user.rb index 3081b0f95..6125321fc 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -41,7 +41,10 @@ class User < ApplicationRecord devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable, :confirmable, :lockable - has_many :dossiers, dependent: :destroy + # We should never cascade delete dossiers. In normal case we call delete_and_keep_track_dossiers + # before deleting a user (which dissociate dossiers from the user). + # Destroying a user with dossier is always a mistake. + has_many :dossiers, dependent: :restrict_with_exception has_many :targeted_user_links, dependent: :destroy has_many :invites, dependent: :destroy has_many :dossiers_invites, through: :invites, source: :dossier