Skip to content

Commit

Permalink
Consider spam role in the user_status method (forem#20449)
Browse files Browse the repository at this point in the history
* Add spam role to user_status method

* Take spam role into account in user status indicator

* Return passed statuses
  • Loading branch information
lightalloy authored Dec 13, 2023
1 parent 2ff439d commit adfd76f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
4 changes: 3 additions & 1 deletion app/helpers/admin/users_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ def format_role_tooltip(user)
def user_status(user)
if user.suspended?
I18n.t("views.admin.users.statuses.Suspended")
elsif user.spam?
I18n.t("views.admin.users.statuses.Spam")
elsif user.warned?
I18n.t("views.admin.users.statuses.Warned")
elsif user.comment_suspended?
Expand Down Expand Up @@ -97,7 +99,7 @@ def organization_tooltip(organization_names, count, imposed_limit: 0)
# Returns a string hex code representing the indicator color for the given status (also known as BASE_ROLE)
def status_to_indicator_color(status)
case status
when "Suspended"
when "Suspended", "Spam"
"#DC2626"
when "Warned"
"#F59E0B"
Expand Down
2 changes: 2 additions & 0 deletions app/views/admin/users/index/_user_status_indicator.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<% if user.suspended? %>
<%= render "admin/users/index/status_indicator", status: "Suspended" %>
<% elsif user.spam? %>
<%= render "admin/users/index/status_indicator", status: "Spam" %>
<% elsif user.warned? %>
<%= render "admin/users/index/status_indicator", status: "Warned" %>
<% elsif user.comment_suspended? %>
Expand Down
6 changes: 6 additions & 0 deletions spec/helpers/admin/users_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@
expect(status).to eq "Suspended"
end

it "renders the proper status for a user that is spam" do
spam_user = create(:user, :spam)
status = helper.user_status(spam_user)
expect(status).to eq "Spam"
end

it "renders the proper status for a user that is warned" do
warned_user = create(:user, :warned)
status = helper.user_status(warned_user)
Expand Down

0 comments on commit adfd76f

Please sign in to comment.