Merge pull request #4129 from Keirua/feat/delete-admin
Ajout d'un bouton de suppression des admin dans le manager
This commit is contained in:
commit
a344010677
4 changed files with 21 additions and 0 deletions
|
@ -33,6 +33,21 @@ module Manager
|
|||
head :ok
|
||||
end
|
||||
|
||||
def delete
|
||||
administrateur = Administrateur.find(params[:id])
|
||||
|
||||
if !administrateur.can_be_deleted?
|
||||
fail "Impossible de supprimer cet administrateur car il a des dossiers ou des procédures"
|
||||
end
|
||||
administrateur.dossiers.each(&:delete_and_keep_track)
|
||||
administrateur.destroy
|
||||
|
||||
logger.info("L'administrateur #{administrateur.id} est supprimé par #{current_user.id}")
|
||||
flash[:notice] = "L'administrateur #{administrateur.id} est supprimé"
|
||||
|
||||
redirect_to manager_administrateurs_path
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def create_administrateur_params
|
||||
|
|
|
@ -123,4 +123,8 @@ class Administrateur < ApplicationRecord
|
|||
def gestionnaire
|
||||
Gestionnaire.find_by(email: email)
|
||||
end
|
||||
|
||||
def can_be_deleted?
|
||||
dossiers.state_instruction_commencee.none? && procedures.none?
|
||||
end
|
||||
end
|
||||
|
|
|
@ -36,6 +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é" %>
|
||||
</div>
|
||||
|
||||
</header>
|
||||
|
|
|
@ -21,6 +21,7 @@ Rails.application.routes.draw do
|
|||
resources :administrateurs, only: [:index, :show, :new, :create] do
|
||||
post 'reinvite', on: :member
|
||||
put 'enable_feature', on: :member
|
||||
delete 'delete', on: :member
|
||||
end
|
||||
|
||||
resources :users, only: [:index, :show] do
|
||||
|
|
Loading…
Reference in a new issue