ajout d'un bouton de suppression des admin dans le manager
This commit is contained in:
parent
f633e3b774
commit
f166077f5e
4 changed files with 23 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 "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
|
||||
|
||||
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
|
||||
|
|
|
@ -33,6 +33,9 @@ as well as a link to its edit page.
|
|||
</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? %>
|
||||
<%= link_to "renvoyer l'invitation", reinvite_manager_administrateur_path(page.resource), method: :post, class: "button" %>
|
||||
<% end %>
|
||||
|
|
|
@ -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