empêche la suppression d'un user qui est admin
This commit is contained in:
parent
d8a51f986f
commit
d4de5769ee
4 changed files with 13 additions and 3 deletions
|
@ -24,7 +24,7 @@ module Manager
|
|||
def delete
|
||||
user = User.find(params[:id])
|
||||
if !user.can_be_deleted?
|
||||
fail "Impossible de supprimer cet utilisateur car il a des dossiers en instruction"
|
||||
fail "Impossible de supprimer cet utilisateur. Il a des dossiers en instruction ou il est administrateur."
|
||||
end
|
||||
user.delete_and_keep_track_dossiers(current_administration)
|
||||
|
||||
|
|
|
@ -97,7 +97,7 @@ class User < ApplicationRecord
|
|||
end
|
||||
|
||||
def can_be_deleted?
|
||||
dossiers.state_instruction_commencee.empty?
|
||||
administrateur.nil? && dossiers.state_instruction_commencee.empty?
|
||||
end
|
||||
|
||||
def delete_and_keep_track_dossiers(administration)
|
||||
|
|
|
@ -25,7 +25,7 @@ as well as a link to its edit page.
|
|||
</h1>
|
||||
|
||||
<div>
|
||||
<%= button_to "supprimer", delete_manager_user_path(page.resource), method: :delete, disabled: !page.resource.can_be_deleted?, class: "button", data: { confirm: "Confirmez-vous la suppression de l'utilisateur ?" }, title: page.resource.can_be_deleted? ? "Supprimer" : "Cet utilisateur a des dossiers dont l'instruction a commencé et ne peut être supprimé" %>
|
||||
<%= button_to "supprimer", delete_manager_user_path(page.resource), method: :delete, disabled: !page.resource.can_be_deleted?, class: "button", data: { confirm: "Confirmez-vous la suppression de l'utilisateur ?" }, title: page.resource.can_be_deleted? ? "Supprimer" : "Cet utilisateur ne peut être supprimé. Il a des dossiers dont l'instruction a commencé ou c'est un administrateur" %>
|
||||
|
||||
</div>
|
||||
<div>
|
||||
|
|
|
@ -224,6 +224,16 @@ describe User, type: :model do
|
|||
context 'when the user has no dossier in instruction' do
|
||||
it { is_expected.to be true }
|
||||
end
|
||||
|
||||
context 'when the user is an administrateur' do
|
||||
it 'cannot be deleted' do
|
||||
administrateur = create(:administrateur)
|
||||
user = administrateur.user
|
||||
|
||||
expect(user.can_be_deleted?).to be_falsy
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe '#delete_and_keep_track_dossiers' do
|
||||
|
|
Loading…
Reference in a new issue