forbid admin merge yet

This commit is contained in:
simon lehericey 2021-10-04 15:53:20 +02:00
parent 5009c583ea
commit 77d14d4a60
2 changed files with 14 additions and 2 deletions

View file

@ -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)

View file

@ -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