-
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 #2537 from alphagov/split-out-edit-user-role-page-…
…from-user-email-page Add separate page for editing another user's role
- Loading branch information
Showing
11 changed files
with
391 additions
and
60 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,38 @@ | ||
class Users::RolesController < 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 | ||
|
||
private | ||
|
||
def load_user | ||
@user = User.find(params[:user_id]) | ||
end | ||
|
||
def authorize_user | ||
authorize(@user) | ||
authorize(@user, :assign_role?) | ||
end | ||
|
||
def user_params | ||
params.require(:user).permit(*current_user.permitted_params.intersection([:role])) | ||
end | ||
|
||
def redirect_to_account_page_if_acting_on_own_user | ||
redirect_to edit_account_role_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
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,66 @@ | ||
<% content_for :title_caption, "Manage other users" %> | ||
<% content_for :title, "Change role 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 role", | ||
} | ||
] | ||
}) | ||
%> | ||
|
||
<% 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_role_path(@user) do %> | ||
<% if @user.exempt_from_2sv? %> | ||
<%= render "govuk_publishing_components/components/inset_text", { | ||
text: "This user's role is set to #{@user.role.humanize}. They are currently exempted from 2-step verification, meaning that their role cannot be changed as admins are required to have 2-step verification.", | ||
} %> | ||
<% else %> | ||
<%= render "govuk_publishing_components/components/select", { | ||
id: "user_role", | ||
name: "user[role]", | ||
label: "Role", | ||
hint: user_role_select_hint, | ||
options: current_user.manageable_roles.map { |role| { text: role.humanize, value: role, selected: @user.role == role } }, | ||
error_message: @user.errors[:role].any? ? @user.errors.full_messages_for(:role).to_sentence : nil | ||
} %> | ||
<div class="govuk-button-group"> | ||
<%= render "govuk_publishing_components/components/button", { | ||
text: "Change role", | ||
} %> | ||
<%= link_to "Cancel", edit_user_path(@user), class: "govuk-link govuk-link--no-visited-state" %> | ||
</div> | ||
<% end %> | ||
<% 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
Oops, something went wrong.