demarches-normaliennes/app/controllers/manager/users_controller.rb

111 lines
3.1 KiB
Ruby
Raw Normal View History

2018-05-31 15:18:06 +02:00
module Manager
class UsersController < Manager::ApplicationController
def update
user = User.find(params[:id])
targeted_user = User.find_by(email: targeted_email)
if targeted_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
2021-11-29 13:47:45 +01:00
redirect_to edit_manager_user_path(user)
else
2021-10-22 15:17:25 +02:00
targeted_user.merge(user)
2021-10-04 15:44:05 +02:00
flash[:notice] = "Le compte « #{targeted_email} » a absorbé le compte « #{user.email} »."
2021-11-29 13:47:45 +01:00
redirect_to edit_manager_user_path(targeted_user)
end
end
def unblock_mails
user = User.find(params[:id])
user.update!(email_verified_at: Time.current)
flash[:notice] = "Les emails ont été débloqués."
redirect_to manager_user_path(user)
end
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 dactivation de votre compte a été renvoyé."
redirect_to manager_user_path(user)
end
2019-07-04 12:36:17 +02:00
def resend_reset_password_instructions
user = User.find(params[:id])
user.send_reset_password_instructions
flash[:notice] = "L'email de réinitialisation du mot de passe a été renvoyé."
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])
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
user.delete_and_keep_track_dossiers_also_delete_user(current_super_admin, reason: :user_removed)
2020-01-08 10:50:16 +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
def emails
@user = User.find(params[:id])
email_services = [
2022-04-26 11:44:42 +02:00
Sendinblue::API.new,
Dolist::API.new
]
@sent_mails = email_services
.filter(&:properly_configured?)
.map { |api| api.sent_mails(@user.email) }
.flatten
.sort_by(&:delivered_at)
.reverse
end
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
2021-10-27 18:59:18 +02:00
flash.alert = "Impossible de débloquer cette adresse email auprès de Sendinblue"
end
redirect_to emails_manager_user_path(@user)
end
private
def targeted_email
params[:user][:email]
end
def paginate_resources(_resources)
super.without_count
end
2018-05-31 15:18:06 +02:00
end
end