2018-03-20 16:33:51 +01:00
|
|
|
module Manager
|
|
|
|
class DemandesController < Manager::ApplicationController
|
|
|
|
def index
|
|
|
|
@pending_demandes = pending_demandes
|
|
|
|
end
|
|
|
|
|
2018-03-21 10:28:17 +01:00
|
|
|
def create_administrateur
|
2020-11-05 15:09:11 +01:00
|
|
|
administrateur = current_super_admin.invite_admin(create_administrateur_params[:email])
|
2018-03-21 10:28:17 +01:00
|
|
|
|
|
|
|
if administrateur.errors.empty?
|
2018-03-23 17:25:58 +01:00
|
|
|
PipedriveAcceptsDealsJob.perform_later(
|
|
|
|
create_administrateur_params[:person_id],
|
2020-11-05 15:09:11 +01:00
|
|
|
current_super_admin.id,
|
2018-03-23 17:31:03 +01:00
|
|
|
create_administrateur_params[:stage_id]
|
2018-03-23 17:25:58 +01:00
|
|
|
)
|
|
|
|
|
2018-03-21 10:28:17 +01:00
|
|
|
flash.notice = "Administrateur créé"
|
|
|
|
redirect_to manager_demandes_path
|
|
|
|
else
|
2019-01-24 15:48:00 +01:00
|
|
|
flash.now.alert = administrateur.errors.full_messages.to_sentence
|
2018-03-21 10:28:17 +01:00
|
|
|
@pending_demandes = pending_demandes
|
|
|
|
render :index
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-03-27 13:32:14 +02:00
|
|
|
def refuse_administrateur
|
|
|
|
PipedriveRefusesDealsJob.perform_later(
|
|
|
|
refuse_administrateur_params[:person_id],
|
2020-11-05 15:09:11 +01:00
|
|
|
current_super_admin.id
|
2018-03-27 13:32:14 +02:00
|
|
|
)
|
2018-03-27 13:52:34 +02:00
|
|
|
|
|
|
|
AdministrationMailer
|
|
|
|
.refuse_admin(refuse_administrateur_params[:email])
|
|
|
|
.deliver_later
|
|
|
|
|
|
|
|
flash.notice = "La demande de #{refuse_administrateur_params[:email]} va être refusée"
|
2018-03-27 13:32:14 +02:00
|
|
|
redirect_to manager_demandes_path
|
|
|
|
end
|
|
|
|
|
2018-03-20 16:33:51 +01:00
|
|
|
private
|
|
|
|
|
2018-03-21 10:28:17 +01:00
|
|
|
def create_administrateur_params
|
2018-03-23 17:31:03 +01:00
|
|
|
params.permit(:email, :person_id, :stage_id)
|
2018-03-21 10:28:17 +01:00
|
|
|
end
|
|
|
|
|
2018-03-27 13:32:14 +02:00
|
|
|
def refuse_administrateur_params
|
2018-03-27 13:52:34 +02:00
|
|
|
params.permit(:email, :person_id)
|
2018-03-27 13:32:14 +02:00
|
|
|
end
|
|
|
|
|
2018-03-20 16:33:51 +01:00
|
|
|
def pending_demandes
|
2020-02-05 18:19:05 +01:00
|
|
|
already_approved_emails = Administrateur.eager_load(:user)
|
2020-01-30 17:08:09 +01:00
|
|
|
.where(users: { email: demandes.map { |d| d[:email] } })
|
2020-02-03 16:54:31 +01:00
|
|
|
.map(&:email)
|
2018-03-20 16:33:51 +01:00
|
|
|
|
|
|
|
demandes.reject { |demande| already_approved_emails.include?(demande[:email]) }
|
|
|
|
end
|
|
|
|
|
|
|
|
def demandes
|
2018-04-06 09:15:35 +02:00
|
|
|
@demandes ||= PipedriveService.get_demandes
|
2018-03-20 16:33:51 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|