-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2509 from alphagov/split-out-edit-user-email-page…
…-from-user-edit-page Add separate page for editing another user's email
- Loading branch information
Showing
17 changed files
with
593 additions
and
156 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
class Users::EmailsController < ApplicationController | ||
layout "admin_layout" | ||
|
||
before_action :authenticate_user! | ||
before_action :load_user | ||
before_action :authorize_user | ||
before_action :redirect_to_account_page_if_acting_on_own_user, only: %i[edit] | ||
|
||
def edit; end | ||
|
||
def update | ||
updater = UserUpdate.new(@user, user_params, current_user, user_ip_address) | ||
if updater.call | ||
redirect_to edit_user_path(@user), notice: "Updated user #{@user.email} successfully" | ||
else | ||
render :edit | ||
end | ||
end | ||
|
||
def resend_email_change | ||
@user.resend_confirmation_instructions | ||
if @user.errors.empty? | ||
redirect_to edit_user_path(@user), notice: "Successfully resent email change email to #{@user.unconfirmed_email}" | ||
else | ||
redirect_to edit_user_email_path(@user), alert: "Failed to send email change email" | ||
end | ||
end | ||
|
||
def cancel_email_change | ||
@user.cancel_email_change! | ||
|
||
redirect_to edit_user_path(@user) | ||
end | ||
|
||
private | ||
|
||
def load_user | ||
@user = User.find(params[:user_id]) | ||
end | ||
|
||
def authorize_user | ||
authorize @user | ||
end | ||
|
||
def user_params | ||
params.require(:user).permit(*current_user.permitted_params.intersection([:email])) | ||
end | ||
|
||
def redirect_to_account_page_if_acting_on_own_user | ||
redirect_to edit_account_email_path if current_user == @user | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<% content_for :title_caption, "Manage other users" %> | ||
<% content_for :title, "Change email for #{@user.name}" %> | ||
|
||
<% content_for :breadcrumbs, | ||
render("govuk_publishing_components/components/breadcrumbs", { | ||
collapse_on_mobile: true, | ||
breadcrumbs: [ | ||
{ | ||
title: "Dashboard", | ||
url: root_path, | ||
}, | ||
{ | ||
title: "Users", | ||
url: users_path, | ||
}, | ||
{ | ||
title: @user.name, | ||
url: edit_user_path(@user), | ||
}, | ||
{ | ||
title: "Change email", | ||
} | ||
] | ||
}) | ||
%> | ||
|
||
<% if @user.unconfirmed_email.present? %> | ||
<%= render "govuk_publishing_components/components/notice", { | ||
title: "A request has been made to change the email address" | ||
} do %> | ||
<p class="govuk-body">An email has been sent to <strong><%= @user.unconfirmed_email %></strong> with a link to confirm the change. If they haven't received this email, we can send it again:</p> | ||
|
||
<%= link_to "Resend confirmation email", resend_email_change_user_email_path(@user), method: :put, class: "govuk-button app-button--no-margin" %> | ||
<%= link_to "Cancel change", cancel_email_change_user_email_path(@user), method: :delete, class: "govuk-link app-link--inline" %> | ||
<% end %> | ||
<% end %> | ||
|
||
<% if @user.errors.count > 0 %> | ||
<% content_for :error_summary do %> | ||
<%= render "govuk_publishing_components/components/error_summary", { | ||
title: "There is a problem", | ||
items: @user.errors.map do |error| | ||
{ | ||
text: error.full_message, | ||
href: "#user_#{error.attribute}", | ||
} | ||
end, | ||
} %> | ||
<% end %> | ||
<% end %> | ||
|
||
<div class="govuk-grid-row"> | ||
<div class="govuk-grid-column-two-thirds"> | ||
<%= form_for @user, url: user_email_path do %> | ||
<%= render "govuk_publishing_components/components/input", { | ||
label: { | ||
text: "Email" | ||
}, | ||
name: "user[email]", | ||
id: "user_email", | ||
type: "email", | ||
value: @user.email, | ||
hint: @user.invited_but_not_yet_accepted? ? "Changes will trigger a new signup email." : nil, | ||
autocomplete: "off", | ||
error_items: @user.errors.full_messages_for(:email).map { |message| { text: message } } | ||
} %> | ||
<%= render "govuk_publishing_components/components/button", { | ||
text: "Change email" | ||
} %> | ||
<% end %> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.