2018-05-31 15:18:06 +02:00
|
|
|
|
module Manager
|
|
|
|
|
class UsersController < Manager::ApplicationController
|
2020-01-13 14:35:25 +01:00
|
|
|
|
def update
|
|
|
|
|
user = User.find(params[:id])
|
2021-10-04 14:00:32 +02:00
|
|
|
|
|
|
|
|
|
preexisting_user = User.find_by(email: targeted_email)
|
|
|
|
|
|
|
|
|
|
if preexisting_user.nil?
|
|
|
|
|
user.skip_reconfirmation!
|
|
|
|
|
user.update(email: targeted_email)
|
|
|
|
|
|
|
|
|
|
if (user.valid?)
|
|
|
|
|
flash[:notice] = "L'email a été modifié en « #{targeted_email} » sans notification ni validation par email."
|
|
|
|
|
else
|
|
|
|
|
flash[:error] = user.errors.full_messages.to_sentence
|
|
|
|
|
end
|
2020-01-13 14:35:25 +01:00
|
|
|
|
else
|
2021-10-04 14:00:32 +02:00
|
|
|
|
user.dossiers.update_all(user_id: preexisting_user.id)
|
|
|
|
|
|
2021-10-04 15:26:01 +02:00
|
|
|
|
if preexisting_user.instructeur.nil?
|
|
|
|
|
user.instructeur&.update(user: preexisting_user)
|
|
|
|
|
else
|
|
|
|
|
preexisting_user.instructeur.merge(user.instructeur)
|
|
|
|
|
end
|
|
|
|
|
|
2021-10-04 14:00:32 +02:00
|
|
|
|
user.expert&.update(user: preexisting_user)
|
2020-01-13 14:35:25 +01:00
|
|
|
|
end
|
2021-10-04 14:00:32 +02:00
|
|
|
|
|
2020-01-13 14:35:25 +01:00
|
|
|
|
redirect_to edit_manager_user_path(user)
|
|
|
|
|
end
|
|
|
|
|
|
2018-07-17 12:10:56 +02:00
|
|
|
|
def resend_confirmation_instructions
|
|
|
|
|
user = User.find(params[:id])
|
|
|
|
|
user.resend_confirmation_instructions
|
2021-05-26 15:16:30 +02:00
|
|
|
|
flash[:notice] = "L'email d’activation de votre compte a été renvoyé."
|
2018-07-17 12:10:56 +02:00
|
|
|
|
redirect_to manager_user_path(user)
|
|
|
|
|
end
|
2019-07-04 12:36:17 +02:00
|
|
|
|
|
|
|
|
|
def enable_feature
|
|
|
|
|
user = User.find(params[:id])
|
|
|
|
|
|
|
|
|
|
params[:features].each do |key, enable|
|
|
|
|
|
if enable
|
|
|
|
|
Flipper.enable_actor(key.to_sym, user)
|
|
|
|
|
else
|
|
|
|
|
Flipper.disable_actor(key.to_sym, user)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
head :ok
|
|
|
|
|
end
|
2020-01-08 10:50:16 +01:00
|
|
|
|
|
|
|
|
|
def delete
|
|
|
|
|
user = User.find(params[:id])
|
2020-09-17 15:39:16 +02:00
|
|
|
|
if !user.can_be_deleted?
|
|
|
|
|
fail "Impossible de supprimer cet utilisateur. Il a des dossiers en instruction ou il est administrateur."
|
2020-01-08 10:50:16 +01:00
|
|
|
|
end
|
2020-11-05 15:09:11 +01:00
|
|
|
|
user.delete_and_keep_track_dossiers(current_super_admin)
|
2020-01-08 10:50:16 +01:00
|
|
|
|
|
2020-11-05 15:09:11 +01:00
|
|
|
|
logger.info("L'utilisateur #{user.id} est supprimé par #{current_super_admin.id}")
|
2020-01-08 10:50:16 +01:00
|
|
|
|
flash[:notice] = "L'utilisateur #{user.id} est supprimé"
|
|
|
|
|
|
|
|
|
|
redirect_to manager_users_path
|
|
|
|
|
end
|
2020-10-06 16:52:10 +02:00
|
|
|
|
|
|
|
|
|
def emails
|
|
|
|
|
@user = User.find(params[:id])
|
2021-04-13 10:57:26 +02:00
|
|
|
|
|
|
|
|
|
email_services = [
|
|
|
|
|
Mailjet::API.new,
|
|
|
|
|
Sendinblue::API.new
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
@sent_mails = email_services
|
|
|
|
|
.filter(&:properly_configured?)
|
|
|
|
|
.map { |api| api.sent_mails(@user.email) }
|
|
|
|
|
.flatten
|
|
|
|
|
.sort_by(&:delivered_at)
|
|
|
|
|
.reverse
|
2020-10-07 10:07:38 +02:00
|
|
|
|
end
|
|
|
|
|
|
2021-04-08 17:46:11 +02:00
|
|
|
|
def unblock_email
|
|
|
|
|
@user = User.find(params[:user_id])
|
|
|
|
|
if Sendinblue::API.new.unblock_user(@user.email)
|
|
|
|
|
flash.notice = "L'adresse email a été débloquée auprès de Sendinblue"
|
|
|
|
|
else
|
|
|
|
|
flash.alert = "Impossible de débloquer cette addresse email auprès de Sendinblue"
|
|
|
|
|
end
|
|
|
|
|
redirect_to emails_manager_user_path(@user)
|
2020-10-06 16:52:10 +02:00
|
|
|
|
end
|
2021-10-04 14:00:32 +02:00
|
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
|
|
def targeted_email
|
|
|
|
|
params[:user][:email]
|
|
|
|
|
end
|
2018-05-31 15:18:06 +02:00
|
|
|
|
end
|
|
|
|
|
end
|