2018-01-08 17:40:25 +01:00
|
|
|
module Manager
|
|
|
|
class AdministrateursController < Manager::ApplicationController
|
2018-01-17 10:28:59 +01:00
|
|
|
def create
|
2020-11-05 15:09:11 +01:00
|
|
|
administrateur = current_super_admin.invite_admin(create_administrateur_params[:email])
|
2018-01-17 10:28:59 +01:00
|
|
|
|
|
|
|
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
|
2024-03-19 17:17:44 +01:00
|
|
|
Administrateur.find_inactive_by_id(params[:id]).user.invite_administrateur!
|
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
|
|
|
|
|
2019-07-22 15:33:58 +02:00
|
|
|
def delete
|
|
|
|
administrateur = Administrateur.find(params[:id])
|
|
|
|
|
2023-10-05 11:23:46 +02:00
|
|
|
result = AdministrateurDeletionService.new(current_super_admin, administrateur).call
|
|
|
|
|
|
|
|
case result
|
|
|
|
in Dry::Monads::Result::Success
|
|
|
|
logger.info("L'administrateur #{administrateur.id} est supprimé par #{current_super_admin.id}")
|
|
|
|
flash[:notice] = "L'administrateur #{administrateur.id} est supprimé"
|
|
|
|
in Dry::Monads::Result::Failure(reason)
|
|
|
|
flash[:alert] = I18n.t(reason, scope: "manager.administrateurs.delete")
|
|
|
|
end
|
2019-07-22 15:33:58 +02:00
|
|
|
|
|
|
|
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
|