-
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 #2540 from alphagov/split-out-edit-user-organisati…
…on-page-from-user-edit-page Split out edit user organisation page from user edit page
- Loading branch information
Showing
12 changed files
with
396 additions
and
53 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::OrganisationsController < 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_organisation?) | ||
end | ||
|
||
def user_params | ||
params.require(:user).permit(*current_user.permitted_params.intersection([:organisation_id])) | ||
end | ||
|
||
def redirect_to_account_page_if_acting_on_own_user | ||
redirect_to edit_account_organisation_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,59 @@ | ||
<% content_for :title_caption, "Manage other users" %> | ||
<% content_for :title, "Change organisation 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 organisation", | ||
} | ||
] | ||
}) | ||
%> | ||
|
||
<% 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_organisation_path(@user) do %> | ||
<%= render "govuk_publishing_components/components/select", { | ||
id: "user_organisation_id", | ||
name: "user[organisation_id]", | ||
label: "Organisation", | ||
options: options_for_organisation_select(selected: @user.organisation_id), | ||
error_message: @user.errors[:organisation_id].any? ? @user.errors.full_messages_for(:organisation_id).to_sentence : nil | ||
} %> | ||
<div class="govuk-button-group"> | ||
<%= render "govuk_publishing_components/components/button", { | ||
text: "Change organisation", | ||
} %> | ||
<%= link_to "Cancel", edit_user_path(@user), class: "govuk-link govuk-link--no-visited-state" %> | ||
</div> | ||
<% 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
Oops, something went wrong.