Consider spam role in the user_status method (#20449)

* Add spam role to user_status method

* Take spam role into account in user status indicator

* Return passed statuses
This commit is contained in:
Anna Buianova 2023-12-13 19:56:27 +03:00 committed by GitHub
parent 2ff439da80
commit adfd76feb6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 1 deletions

View file

@ -48,6 +48,8 @@ module Admin
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?
@ -97,7 +99,7 @@ module Admin
# 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"

View file

@ -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? %>

View file

@ -121,6 +121,12 @@ describe Admin::UsersHelper do
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)