Fix redirect loop for gestionnaire if hidden procedure is saved in procedure_filter

This commit is contained in:
Mathieu Magnin 2017-06-29 11:45:30 +02:00
parent 70c7c42e1f
commit ce171208da
2 changed files with 16 additions and 3 deletions

View file

@ -20,9 +20,13 @@ class Gestionnaire < ActiveRecord::Base
include CredentialsSyncableConcern
def procedure_filter
return nil unless assign_to.pluck(:procedure_id).include?(self[:procedure_filter])
self[:procedure_filter]
procedure_id = self[:procedure_filter]
if procedures.find_by(id: procedure_id).present?
procedure_id
else
self.update_column(:procedure_filter, nil)
nil
end
end
def can_view_dossier?(dossier_id)

View file

@ -260,6 +260,15 @@ describe Gestionnaire, type: :model do
it { expect(AssignTo.where(gestionnaire: gestionnaire, procedure: procedure_3).count).to eq 0 }
it { is_expected.to be_nil }
end
context "when procedure is hidden clear procedure_filter" do
before do
gestionnaire.update_column :procedure_filter, procedure_3.id
procedure_3.hide!
end
it { is_expected.to be_nil }
end
end
end