From 77d14d4a60cff4a3345c4262eadbd3c720ed2d1b Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Mon, 4 Oct 2021 15:53:20 +0200 Subject: [PATCH] forbid admin merge yet --- app/controllers/manager/users_controller.rb | 5 +++-- spec/controllers/manager/users_controller_spec.rb | 11 +++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/app/controllers/manager/users_controller.rb b/app/controllers/manager/users_controller.rb index d107ca5c2..bb70d54d5 100644 --- a/app/controllers/manager/users_controller.rb +++ b/app/controllers/manager/users_controller.rb @@ -2,10 +2,11 @@ module Manager class UsersController < Manager::ApplicationController def update user = User.find(params[:id]) - preexisting_user = User.find_by(email: targeted_email) - if preexisting_user.nil? + if user.administrateur.present? + flash[:error] = "« #{targeted_email} » est un administrateur. On ne sait pas encore faire." + elsif preexisting_user.nil? user.skip_reconfirmation! user.update(email: targeted_email) diff --git a/spec/controllers/manager/users_controller_spec.rb b/spec/controllers/manager/users_controller_spec.rb index 896cbc21b..c1e43f856 100644 --- a/spec/controllers/manager/users_controller_spec.rb +++ b/spec/controllers/manager/users_controller_spec.rb @@ -30,6 +30,17 @@ describe Manager::UsersController, type: :controller do expect(User.find_by(id: user.id).email).to eq(nouvel_email) end + + context 'and the user is an administrateur' do + let(:user) { create(:administrateur).user } + + it 'rejects the modification' do + subject + + expect(flash[:error]).to match("« nouvel.email@domaine.fr » est un administrateur. On ne sait pas encore faire.") + expect(user.reload.email).not_to eq(nouvel_email) + end + end end describe 'with an invalid email' do