Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split "edit user" page and move top to GOV.UK Design System #2567

Merged
merged 51 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
f5402c6
Move error summary on edit user page outside form
floehopper Nov 29, 2023
6212de1
Fix indentation in app/views/users/_form_fields.html.erb
floehopper Nov 29, 2023
d3622a0
Inline form_fields partial into users edit template
floehopper Nov 29, 2023
3a6caf3
Move non-form elements on edit user page outside form
floehopper Nov 29, 2023
3d26433
Split manage permissions page out of edit user page
floehopper Nov 30, 2023
b8bdcf9
Hide suspend link unless current user has permission
floehopper Nov 30, 2023
bc51ef2
Hide reset 2SV link unless current user has permission
floehopper Nov 30, 2023
433ded1
Simplify suspend link text logic on edit user page
floehopper Nov 30, 2023
85bb924
Move resend invitation permission check closer to link
floehopper Nov 30, 2023
2393f72
Move unlock permission check closer to link
floehopper Nov 30, 2023
7777bf3
Use User instance in all edit user permission checks
floehopper Nov 30, 2023
07ad204
Remove brackets & quotes around user name in title/heading
floehopper Nov 30, 2023
05e1c98
Extract UsersHelper#status method
floehopper Nov 30, 2023
1094739
Move status to user details section on edit user page
floehopper Nov 30, 2023
2afff6e
Move access log link to actions section on edit user page
floehopper Nov 30, 2023
e1c82a3
Move suspension link to actions section on edit user page
floehopper Nov 30, 2023
85072b4
Move resend invitation link to actions section on edit user page
floehopper Nov 30, 2023
5cd660d
Move unlock account link to actions section on edit user page
floehopper Nov 30, 2023
c8fa23a
Move name to user details section on edit user page
floehopper Nov 30, 2023
9cd3dcc
Move email to user details section on edit user page
floehopper Nov 30, 2023
b1c7e1c
Move organisation to user details section on edit user page
floehopper Nov 30, 2023
4d1cea8
Move role to user details section on edit user page
floehopper Nov 30, 2023
65aeeb9
Move 2sv exemption link to actions section on edit user page
floehopper Nov 30, 2023
39e101d
Move 2sv reset link to actions section on edit user page
floehopper Nov 30, 2023
bef3550
Simplify logic for displaying reset 2SV on edit user page
floehopper Nov 30, 2023
553e54c
Move mandate 2sv link to actions section on edit user page
floehopper Nov 30, 2023
2b2cfcb
Extract User#not_setup_2sv? method
floehopper Nov 30, 2023
56dbc42
Extract UsersHelper#two_step_status_with_requirement
floehopper Nov 30, 2023
9245bf2
Move 2SV status to user details section on edit user page
floehopper Nov 30, 2023
9e98c89
Remove suspension reason from edit user page
floehopper Nov 30, 2023
ebe527f
Remove invitation not accepted explanation on edit user page
floehopper Nov 30, 2023
1393fdc
Remove account locked explanation on edit user page
floehopper Nov 30, 2023
46ed5b6
Extract User#organisation_name method
floehopper Nov 30, 2023
f24c775
Add coverage for access log clink on edit user page
floehopper Dec 4, 2023
24fa57f
Extract UsersHelper#link_to_access_log
floehopper Dec 4, 2023
1941d80
Extract UsersHelper#link_to_suspension
floehopper Dec 4, 2023
71ff412
Extract UsersHelper#link_to_resend_invitation
floehopper Dec 4, 2023
3871485
Extract UsersHelper#link_to_unlock
floehopper Dec 4, 2023
9cfce05
Add coverage for 2SV exemption link on edit user page
floehopper Dec 4, 2023
ca82dcc
Extract UsersHelper#link_to_2sv_exemption
floehopper Dec 4, 2023
8a3c52d
Extract UsersHelper#link_to_reset_2sv
floehopper Dec 4, 2023
695211b
Add coverage for mandate 2SV link on edit user page
floehopper Dec 4, 2023
b09cb9f
Extract UsersHelper#link_to_mandate_2sv
floehopper Dec 4, 2023
8d16e6f
Move edit user page to use GOV.UK Design System 🎉
floehopper Dec 4, 2023
0578eef
Improve access log link text on edit user page
floehopper Dec 4, 2023
62971ec
Simplify link text for 2SV exemption on edit user page
floehopper Dec 4, 2023
250fed7
Improve mandate 2SV link text on edit user page
floehopper Dec 4, 2023
c9f6249
Reorder action links on edit user page
floehopper Dec 4, 2023
217123a
Tweaks to access log page title
floehopper Dec 4, 2023
1c77886
Tweaks to suspend/unsuspend page title & breadcrumb
floehopper Dec 4, 2023
1e98cb9
Use normal_user factory in UsersControllerTest
floehopper Dec 5, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
class UsersController < ApplicationController
include UserPermissionsControllerMethods

layout "admin_layout", only: %w[index event_logs require_2sv]
layout "admin_layout", only: %w[index edit event_logs require_2sv]

before_action :authenticate_user!
before_action :load_user, except: %i[index]
before_action :redirect_to_account_page_if_acting_on_own_user, only: %i[edit]
before_action :redirect_to_account_page_if_acting_on_own_user, only: %i[edit manage_permissions]
before_action :authorize_user, except: %i[index]
before_action :allow_no_application_access, only: [:update]
before_action :redirect_legacy_filters, only: [:index]
Expand All @@ -31,7 +31,9 @@ def index
end
end

def edit
def edit; end

def manage_permissions
@application_permissions = all_applications_and_permissions_for(@user)
end

Expand All @@ -41,7 +43,7 @@ def update
redirect_to users_path, notice: "Updated user #{@user.email} successfully"
else
@application_permissions = all_applications_and_permissions_for(@user)
render :edit
render :manage_permissions
end
end

Expand Down
87 changes: 87 additions & 0 deletions app/helpers/users_helper.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
module UsersHelper
include Pundit::Authorization

def status(user)
user.status.humanize
end

def two_step_status(user)
user.two_step_status.humanize.capitalize
end

def two_step_status_with_requirement(user)
if user.not_setup_2sv? && user.require_2sv?
"Required but #{two_step_status(user).downcase}"
else
two_step_status(user)
end
end

def organisation_options(form_builder)
accessible_organisations = policy_scope(Organisation)
options_from_collection_for_select(
Expand Down Expand Up @@ -104,4 +116,79 @@ def user_role_select_hint
],
}
end

def summary_list_item_for_name(user)
{ field: "Name", value: user.name, edit: { href: edit_user_name_path(user) } }
end

def summary_list_item_for_email(user)
{ field: "Email", value: user.email, edit: { href: edit_user_email_path(user) } }
end

def summary_list_item_for_organisation(user)
item = { field: "Organisation", value: user.organisation_name }
item[:edit] = { href: edit_user_organisation_path(user) } if policy(user).assign_organisation?
item
end

def summary_list_item_for_role(user)
item = { field: "Role", value: user.role.humanize.capitalize }
item[:edit] = { href: edit_user_role_path(user) } if policy(user).assign_role?
item
end

def summary_list_item_for_status(user)
{ field: "Status", value: status(user) }
end

def summary_list_item_for_2sv_status(user)
{ field: "2-step verification", value: two_step_status_with_requirement(user) }
end

def link_to_access_log(user)
link_to "View account access log", event_logs_user_path(user)
end

def link_to_suspension(user)
return unless policy(user).suspension?

link_to user.suspended? ? "Unsuspend user" : "Suspend user", edit_suspension_path(user)
end

def link_to_resend_invitation(user)
return unless policy(user).resend_invitation?
return unless user.invited_but_not_yet_accepted?

link_to "Resend signup email", edit_user_invitation_resend_path(user)
end

def link_to_unlock(user)
return unless policy(user).unlock?
return unless user.access_locked?

link_to "Unlock account", edit_user_unlocking_path(user)
end

def link_to_2sv_exemption(user)
return unless policy(user).exempt_from_two_step_verification?

text = user.exempt_from_2sv? ? "Edit 2-step verification exemption" : "Exempt user from 2-step verification"
link_to text, edit_two_step_verification_exemption_path(user)
end

def link_to_reset_2sv(user)
return unless policy(user).reset_2sv?
return unless user.has_2sv?

link_to "Reset 2-step verification", edit_user_two_step_verification_reset_path(user)
end

def link_to_mandate_2sv(user)
return unless policy(user).mandate_2sv?
return if user.require_2sv?

text = "Turn on 2-step verification for this user"
text += " (this will remove their exemption)" if user.exempt_from_2sv?
link_to text, edit_user_two_step_verification_mandation_path(user)
end
end
8 changes: 8 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,10 @@ def two_step_status
end
end

def not_setup_2sv?
two_step_status == TWO_STEP_STATUS_NOT_SET_UP
end

def role_class
Roles.const_get(role.classify)
end
Expand Down Expand Up @@ -411,6 +415,10 @@ def belongs_to_gds?
organisation.try(:content_id).to_s == Organisation::GDS_ORG_CONTENT_ID
end

def organisation_name
organisation.present? ? organisation.name : Organisation::NONE
end

private

def two_step_mandated_changed?
Expand Down
1 change: 1 addition & 0 deletions app/policies/user_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def edit?
alias_method :reset_two_step_verification?, :edit?
alias_method :resend_email_change?, :edit?
alias_method :cancel_email_change?, :edit?
alias_method :manage_permissions?, :edit?

def assign_role?
current_user.superadmin?
Expand Down
2 changes: 1 addition & 1 deletion app/presenters/user_export_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def row(user)
user.sign_in_count,
user.current_sign_in_at.try(:to_formatted_s, :db),
user.created_at.try(:to_formatted_s, :db),
user.status.humanize,
status(user),
two_step_status(user),
user.expiry_date_for_2sv_exemption.try(:strftime, "%d/%m/%Y"),
].concat(app_permissions_for(user))
Expand Down
4 changes: 2 additions & 2 deletions app/views/doorkeeper_applications/users_with_access.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@
{ text: formatted_user_name(user), format: user_name_format(user) },
{ text: user.email, format: 'email' },
{ text: user.role.humanize },
{ text: user.organisation.try(:name) },
{ text: user.organisation_name },
{ text: user.sign_in_count },
{ text: formatted_last_sign_in(user) },
{ text: user.status.humanize },
{ text: status(user) },
{ text: user.eager_loaded_permission_for(@application).to_sentence },
]
end,
Expand Down
6 changes: 4 additions & 2 deletions app/views/suspensions/edit.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<% content_for :title, "Suspend [#{@user.name}]" %>
<% content_for :title_caption, "Manage other users" %>
<% content_for :title, "Suspend or unsuspend #{@user.name}" %>

<% content_for :breadcrumbs,
render("govuk_publishing_components/components/breadcrumbs", {
collapse_on_mobile: true,
Expand All @@ -16,7 +18,7 @@
url: user_path(@user),
},
{
title: "Suspend",
title: "Suspend or unsuspend",
},
]
})
Expand Down
82 changes: 0 additions & 82 deletions app/views/users/_form_fields.html.erb

This file was deleted.

Loading