Merge pull request #4684 from betagouv/feat/admin-edit-email
Modification d'un email d'un utilisateur dans le manager
This commit is contained in:
commit
f2179979fe
5 changed files with 50 additions and 3 deletions
|
@ -1,5 +1,18 @@
|
|||
module Manager
|
||||
class UsersController < Manager::ApplicationController
|
||||
def update
|
||||
user = User.find(params[:id])
|
||||
new_email = params[:user][:email]
|
||||
user.skip_reconfirmation!
|
||||
user.update(email: new_email)
|
||||
if (user.valid?)
|
||||
flash[:notice] = "L'email a été modifié en « #{new_email} » sans notification ni validation par email."
|
||||
else
|
||||
flash[:error] = "« #{new_email} » n'est pas une adresse valide."
|
||||
end
|
||||
redirect_to edit_manager_user_path(user)
|
||||
end
|
||||
|
||||
def resend_confirmation_instructions
|
||||
user = User.find(params[:id])
|
||||
user.resend_confirmation_instructions
|
||||
|
|
|
@ -41,7 +41,9 @@ class UserDashboard < Administrate::BaseDashboard
|
|||
# FORM_ATTRIBUTES
|
||||
# an array of attributes that will be displayed
|
||||
# on the model's form (`new` and `edit`) pages.
|
||||
FORM_ATTRIBUTES = [].freeze
|
||||
FORM_ATTRIBUTES = [
|
||||
:email
|
||||
].freeze
|
||||
|
||||
# Overwrite this method to customize how users are displayed
|
||||
# across all pages of the admin dashboard.
|
||||
|
|
|
@ -24,9 +24,11 @@ as well as a link to its edit page.
|
|||
<%= content_for(:title) %>
|
||||
</h1>
|
||||
|
||||
<div>
|
||||
<%= button_to "modifier", edit_manager_user_path(page.resource), method: :get, class: "button" %>
|
||||
</div>
|
||||
<div>
|
||||
<%= button_to "supprimer", delete_manager_user_path(page.resource), method: :delete, disabled: !page.resource.can_be_deleted?, class: "button", data: { confirm: "Confirmez-vous la suppression de l'utilisateur ?" }, title: page.resource.can_be_deleted? ? "Supprimer" : "Cet utilisateur a des dossiers dont l'instruction a commencé et ne peut être supprimé" %>
|
||||
|
||||
</div>
|
||||
<div>
|
||||
<% if !user.confirmed? %>
|
||||
|
|
|
@ -24,7 +24,7 @@ Rails.application.routes.draw do
|
|||
delete 'delete', on: :member
|
||||
end
|
||||
|
||||
resources :users, only: [:index, :show] do
|
||||
resources :users, only: [:index, :show, :edit, :update] do
|
||||
delete 'delete', on: :member
|
||||
post 'resend_confirmation_instructions', on: :member
|
||||
put 'enable_feature', on: :member
|
||||
|
|
|
@ -1,6 +1,36 @@
|
|||
describe Manager::UsersController, type: :controller do
|
||||
let(:administration) { create(:administration) }
|
||||
|
||||
describe '#update' do
|
||||
let!(:user) { create(:user, email: 'ancien.email@domaine.fr') }
|
||||
|
||||
before {
|
||||
sign_in administration
|
||||
}
|
||||
subject { patch :update, params: { id: user.id, user: { email: nouvel_email } } }
|
||||
|
||||
describe 'with a valid email' do
|
||||
let(:nouvel_email) { 'nouvel.email@domaine.fr' }
|
||||
|
||||
it 'updates the user email' do
|
||||
subject
|
||||
|
||||
expect(User.find_by(id: user.id).email).to eq(nouvel_email)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'with an invalid email' do
|
||||
let(:nouvel_email) { 'plop' }
|
||||
|
||||
it 'does not update the user email' do
|
||||
subject
|
||||
|
||||
expect(User.find_by(id: user.id).email).not_to eq(nouvel_email)
|
||||
expect(flash[:error]).to match("« #{nouvel_email} » n'est pas une adresse valide.")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#delete' do
|
||||
let!(:user) { create(:user) }
|
||||
|
||||
|
|
Loading…
Reference in a new issue