delete adminis with procs managed by other admins
This commit is contained in:
parent
a0b4d97d08
commit
696a058280
3 changed files with 27 additions and 2 deletions
|
@ -68,6 +68,6 @@ class Administrateur < ApplicationRecord
|
|||
end
|
||||
|
||||
def can_be_deleted?
|
||||
dossiers.state_instruction_commencee.none? && procedures.none?
|
||||
dossiers.state_instruction_commencee.none? && procedures.all? { |p| p.administrateurs.count > 1 }
|
||||
end
|
||||
end
|
||||
|
|
|
@ -36,7 +36,7 @@ as well as a link to its edit page.
|
|||
<% if page.resource.invitation_expired? %>
|
||||
<%= link_to "renvoyer l'invitation", reinvite_manager_administrateur_path(page.resource), method: :post, class: "button" %>
|
||||
<% end %>
|
||||
<%= button_to "supprimer", delete_manager_administrateur_path(page.resource), method: :delete, disabled: !page.resource.can_be_deleted?, class: "button", data: { confirm: "Confirmez-vous la suppression de l'administrateur ?" }, title: page.resource.can_be_deleted? ? "Supprimer" : "Cet administrateur a des dossiers ou des procédures et ne peut être supprimé" %>
|
||||
<%= button_to "supprimer", delete_manager_administrateur_path(page.resource), method: :delete, disabled: !page.resource.can_be_deleted?, class: "button", data: { confirm: "Confirmez-vous la suppression de l'administrateur ?" }, title: page.resource.can_be_deleted? ? "Supprimer" : "Cet administrateur a des dossiers ou des procédures dont il est le seul admin et ne peut être supprimé" %>
|
||||
</div>
|
||||
|
||||
</header>
|
||||
|
|
|
@ -21,6 +21,31 @@ describe Administrateur, type: :model do
|
|||
end
|
||||
end
|
||||
|
||||
describe "#can_be_deleted?" do
|
||||
subject { administrateur.can_be_deleted? }
|
||||
|
||||
context 'when the administrateur has a dossier in instruction' do
|
||||
let!(:dossier) { create(:dossier, :en_instruction) }
|
||||
let(:administrateur) { dossier.procedure.administrateurs.first }
|
||||
|
||||
it { is_expected.to be false }
|
||||
end
|
||||
|
||||
context "when the administrateur's procedures have other administrateurs" do
|
||||
let!(:administrateur) { create(:administrateur) }
|
||||
let!(:autre_administrateur) { create(:administrateur) }
|
||||
let!(:procedure) { create(:procedure, administrateurs: [administrateur, autre_administrateur]) }
|
||||
|
||||
it { is_expected.to be true }
|
||||
end
|
||||
|
||||
context "when the administrateur has no procedure" do
|
||||
let!(:administrateur) { create(:administrateur) }
|
||||
|
||||
it { is_expected.to be true }
|
||||
end
|
||||
end
|
||||
|
||||
# describe '#password_complexity' do
|
||||
# let(:email) { 'mail@beta.gouv.fr' }
|
||||
# let(:passwords) { ['pass', '12pass23', 'démarches ', 'démarches-simple', 'démarches-simplifiées-pwd'] }
|
||||
|
|
Loading…
Reference in a new issue