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

Show user status as tag instead of strikethrough #2713

Merged
merged 4 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 1 addition & 2 deletions app/helpers/api_users_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ def truncate_access_token(token)
end

def api_user_name(user)
anchor_tag = link_to(user.name, edit_api_user_path(user), class: "govuk-link")
user.suspended? ? content_tag(:del, anchor_tag) : anchor_tag
link_to(user.name, edit_api_user_path(user), class: "govuk-link")
end

def application_list(user)
Expand Down
13 changes: 11 additions & 2 deletions app/helpers/users_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ def status(user)
user.status.humanize
end

def status_with_tag(user)
css_classes = if user.status == User::USER_STATUS_ACTIVE
"govuk-tag--green"
else
"govuk-tag--grey"
end

govuk_tag(status(user), css_classes)
end

def two_step_status(user)
user.two_step_status.humanize.capitalize
end
Expand Down Expand Up @@ -63,8 +73,7 @@ def filtered_users_heading(users)
end

def user_name(user)
anchor_tag = link_to(user.name, edit_user_path(user), class: "govuk-link")
user.suspended? ? content_tag(:del, anchor_tag) : anchor_tag
link_to(user.name, edit_user_path(user), class: "govuk-link")
end

def options_for_role_select(selected: nil)
Expand Down
4 changes: 2 additions & 2 deletions app/views/api_users/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
text: "Apps",
},
{
text: "Suspended?",
text: "Status",
},
],
rows: @api_users.map do |user|
Expand All @@ -39,7 +39,7 @@
text: application_list(user),
},
{
text: user.suspended? ? "Yes" : "No",
text: status_with_tag(user),
},
]
end,
Expand Down
2 changes: 1 addition & 1 deletion app/views/users/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
{ text: user_name(user) },
{ text: user.email },
{ text: user.role_display_name },
{ text: status(user) },
{ text: status_with_tag(user) },
{ text: two_step_status(user) },
]
end,
Expand Down
9 changes: 9 additions & 0 deletions test/helpers/users_helper_test.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
require "test_helper"

class UsersHelperTest < ActionView::TestCase
include ApplicationHelper

test "sync_needed? should work with user permissions not synced yet" do
application = create(:application)
user = create(:user)
Expand All @@ -16,6 +18,13 @@ class UsersHelperTest < ActionView::TestCase
assert_equal "Suspended", status(build(:suspended_user))
end

test "status_with_tag should enclose the status in a govuk tag" do
assert_equal "<strong class=\"govuk-tag govuk-tag--grey\">Invited</strong>", status_with_tag(build(:invited_user))
assert_equal "<strong class=\"govuk-tag govuk-tag--green\">Active</strong>", status_with_tag(build(:active_user))
assert_equal "<strong class=\"govuk-tag govuk-tag--grey\">Locked</strong>", status_with_tag(build(:locked_user))
assert_equal "<strong class=\"govuk-tag govuk-tag--grey\">Suspended</strong>", status_with_tag(build(:suspended_user))
end

test "two_step_status should reflect the user's status accurately when the user is exempted from 2sv" do
assert_equal "Exempted", two_step_status(create(:two_step_exempted_user))
assert_equal "Exempted", two_step_status_with_requirement(create(:two_step_exempted_user))
Expand Down
2 changes: 1 addition & 1 deletion test/integration/manage_api_users_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class ManageApiUsersTest < ActionDispatch::IntegrationTest
assert page.has_selector?("td", text: @api_user.email)

assert page.has_selector?("td", text: @application.name)
assert page.has_selector?("td:last-child", text: "No") # suspended?
assert page.has_selector?("td:last-child", text: "Active") # status
end

should "be able to create and edit an API user" do
Expand Down
Loading