2018-01-08 17:40:25 +01:00
|
|
|
module Manager
|
|
|
|
class AdministrateursController < Manager::ApplicationController
|
2018-01-17 10:28:59 +01:00
|
|
|
def create
|
|
|
|
administrateur = current_administration.invite_admin(create_administrateur_params[:email])
|
|
|
|
|
|
|
|
if administrateur.errors.empty?
|
|
|
|
flash.notice = "Administrateur créé"
|
2018-01-16 14:51:28 +01:00
|
|
|
redirect_to manager_administrateurs_path
|
2018-01-17 10:28:59 +01:00
|
|
|
else
|
2018-01-16 14:51:28 +01:00
|
|
|
render :new, locals: {
|
2018-10-01 14:06:08 +02:00
|
|
|
page: Administrate::Page::Form.new(dashboard, administrateur)
|
2018-01-16 14:51:28 +01:00
|
|
|
}
|
2018-01-17 10:28:59 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-01-18 10:04:34 +01:00
|
|
|
def reinvite
|
2018-05-31 18:07:19 +02:00
|
|
|
Administrateur.find_inactive_by_id(params[:id]).invite!(current_administration.id)
|
2018-01-16 16:28:13 +01:00
|
|
|
flash.notice = "Invitation renvoyée"
|
2018-01-16 16:28:13 +01:00
|
|
|
redirect_to manager_administrateur_path(params[:id])
|
|
|
|
end
|
|
|
|
|
2018-04-26 14:40:03 +02:00
|
|
|
def enable_feature
|
|
|
|
administrateur = Administrateur.find(params[:id])
|
|
|
|
|
|
|
|
params[:features].each do |key, enable|
|
|
|
|
if enable
|
|
|
|
administrateur.enable_feature(key.to_sym)
|
|
|
|
else
|
|
|
|
administrateur.disable_feature(key.to_sym)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
head :ok
|
|
|
|
end
|
|
|
|
|
2019-07-22 15:33:58 +02:00
|
|
|
def delete
|
|
|
|
administrateur = Administrateur.find(params[:id])
|
|
|
|
|
|
|
|
if !administrateur.can_be_deleted?
|
2019-07-23 15:24:43 +02:00
|
|
|
fail "Impossible de supprimer cet administrateur car il a des dossiers ou des procédures"
|
2019-07-22 15:33:58 +02:00
|
|
|
end
|
|
|
|
administrateur.dossiers.each(&:delete_and_keep_track)
|
|
|
|
administrateur.destroy
|
|
|
|
|
2019-08-19 10:47:37 +02:00
|
|
|
logger.info("L'administrateur #{administrateur.id} est supprimé par #{current_administration.id}")
|
2019-07-22 15:33:58 +02:00
|
|
|
flash[:notice] = "L'administrateur #{administrateur.id} est supprimé"
|
|
|
|
|
|
|
|
redirect_to manager_administrateurs_path
|
|
|
|
end
|
|
|
|
|
2018-01-17 10:28:59 +01:00
|
|
|
private
|
|
|
|
|
|
|
|
def create_administrateur_params
|
|
|
|
params.require(:administrateur).permit(:email)
|
|
|
|
end
|
2018-01-08 17:40:25 +01:00
|
|
|
end
|
|
|
|
end
|