feat(fork): mark a fork as stale for future deletion, so it can't be reused
This commit is contained in:
parent
76088d1ee8
commit
218c7d08c2
2 changed files with 8 additions and 1 deletions
|
@ -6,7 +6,7 @@ module DossierCloneConcern
|
||||||
has_many :cloned_dossiers, class_name: 'Dossier', foreign_key: :parent_dossier_id, dependent: :nullify, inverse_of: :parent_dossier
|
has_many :cloned_dossiers, class_name: 'Dossier', foreign_key: :parent_dossier_id, dependent: :nullify, inverse_of: :parent_dossier
|
||||||
|
|
||||||
belongs_to :editing_fork_origin, class_name: 'Dossier', optional: true
|
belongs_to :editing_fork_origin, class_name: 'Dossier', optional: true
|
||||||
has_many :editing_forks, class_name: 'Dossier', foreign_key: :editing_fork_origin_id, dependent: :destroy, inverse_of: :editing_fork_origin
|
has_many :editing_forks, -> { where(hidden_by_reason: nil) }, class_name: 'Dossier', foreign_key: :editing_fork_origin_id, dependent: :destroy, inverse_of: :editing_fork_origin
|
||||||
end
|
end
|
||||||
|
|
||||||
def find_or_create_editing_fork(user)
|
def find_or_create_editing_fork(user)
|
||||||
|
@ -32,6 +32,7 @@ module DossierCloneConcern
|
||||||
|
|
||||||
def destroy_editing_fork!
|
def destroy_editing_fork!
|
||||||
if editing_fork?
|
if editing_fork?
|
||||||
|
update!(hidden_by_administration_at: Time.current, hidden_by_reason: :stale_fork)
|
||||||
DestroyRecordLaterJob.perform_later(self)
|
DestroyRecordLaterJob.perform_later(self)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -86,6 +86,12 @@ RSpec.describe DossierCloneConcern do
|
||||||
it 'update dossier search terms' do
|
it 'update dossier search terms' do
|
||||||
expect { subject }.to have_enqueued_job(DossierUpdateSearchTermsJob).with(dossier)
|
expect { subject }.to have_enqueued_job(DossierUpdateSearchTermsJob).with(dossier)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'fork is hidden after merge' do
|
||||||
|
subject
|
||||||
|
expect(forked_dossier.reload.hidden_by_reason).to eq("stale_fork")
|
||||||
|
expect(dossier.reload.editing_forks).to be_empty
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with new revision' do
|
context 'with new revision' do
|
||||||
|
|
Loading…
Reference in a new issue