remove useless condition to admin that can be deleted
administrateur can be deleted only if he/she has a procedure where he/she is the only admin
This commit is contained in:
parent
4bf020cb96
commit
5a46effcbc
3 changed files with 10 additions and 11 deletions
|
@ -68,14 +68,13 @@ class Administrateur < ApplicationRecord
|
|||
end
|
||||
|
||||
def can_be_deleted?
|
||||
dossiers.state_instruction_commencee.none? && procedures.all? { |p| p.administrateurs.count > 1 }
|
||||
procedures.all? { |p| p.administrateurs.count > 1 }
|
||||
end
|
||||
|
||||
def delete_and_transfer_services
|
||||
if !can_be_deleted?
|
||||
fail "Impossible de supprimer cet administrateur car il a des dossiers ou des procédures"
|
||||
fail "Impossible de supprimer cet administrateur car il a des procédures où il est le seul administrateur"
|
||||
end
|
||||
dossiers.each(&:delete_and_keep_track)
|
||||
|
||||
procedures.each do |procedure|
|
||||
next_administrateur = procedure.administrateurs.where.not(id: self.id).first
|
||||
|
|
|
@ -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 dont il est le seul admin 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 procédures dont il est le seul admin et ne peut être supprimé" %>
|
||||
</div>
|
||||
|
||||
</header>
|
||||
|
|
|
@ -24,13 +24,6 @@ describe Administrateur, type: :model do
|
|||
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) }
|
||||
|
@ -39,6 +32,13 @@ describe Administrateur, type: :model do
|
|||
it { is_expected.to be true }
|
||||
end
|
||||
|
||||
context "when the administrateur has a procedure where he/she is the only admin" do
|
||||
let!(:administrateur) { create(:administrateur) }
|
||||
let!(:procedure) { create(:procedure, administrateurs: [administrateur]) }
|
||||
|
||||
it { is_expected.to be false }
|
||||
end
|
||||
|
||||
context "when the administrateur has no procedure" do
|
||||
let!(:administrateur) { create(:administrateur) }
|
||||
|
||||
|
|
Loading…
Reference in a new issue