ajout d'un bouton de suppression des admin dans le manager

This commit is contained in:
clemkeirua 2019-07-22 15:33:58 +02:00
parent f633e3b774
commit f166077f5e
4 changed files with 23 additions and 0 deletions

View file

@ -33,6 +33,21 @@ module Manager
head :ok head :ok
end end
def delete
administrateur = Administrateur.find(params[:id])
if !administrateur.can_be_deleted?
fail "Cannot delete this administrateur because it has dossiers or procedures"
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 private
def create_administrateur_params def create_administrateur_params

View file

@ -123,4 +123,8 @@ class Administrateur < ApplicationRecord
def gestionnaire def gestionnaire
Gestionnaire.find_by(email: email) Gestionnaire.find_by(email: email)
end end
def can_be_deleted?
dossiers.state_instruction_commencee.none? && procedures.none?
end
end end

View file

@ -33,6 +33,9 @@ as well as a link to its edit page.
</div> </div>
<div> <div>
<% if page.resource.can_be_deleted? %>
<%= link_to "supprimer", delete_manager_administrateur_path(page.resource), method: :delete, class: "button", data: { confirm: "Confirmez-vous la suppression de l'administrateur ?" } %>
<% end %>
<% if page.resource.invitation_expired? %> <% if page.resource.invitation_expired? %>
<%= link_to "renvoyer l'invitation", reinvite_manager_administrateur_path(page.resource), method: :post, class: "button" %> <%= link_to "renvoyer l'invitation", reinvite_manager_administrateur_path(page.resource), method: :post, class: "button" %>
<% end %> <% end %>

View file

@ -21,6 +21,7 @@ Rails.application.routes.draw do
resources :administrateurs, only: [:index, :show, :new, :create] do resources :administrateurs, only: [:index, :show, :new, :create] do
post 'reinvite', on: :member post 'reinvite', on: :member
put 'enable_feature', on: :member put 'enable_feature', on: :member
delete 'delete', on: :member
end end
resources :users, only: [:index, :show] do resources :users, only: [:index, :show] do