From 90a4ac3bf5aaa378984acc2c8fc2c08a73872b4a Mon Sep 17 00:00:00 2001 From: evazion Date: Sat, 15 May 2021 03:39:32 -0500 Subject: [PATCH] users: reword ban notice messages. * Show the ban length instead of the ban expiration date in ban notices. * Fix the ban notice to not say "Your account has been temporarily banned" when it's a permanent ban. --- app/helpers/application_helper.rb | 13 ++++--------- app/models/ban.rb | 6 +++--- app/presenters/user_presenter.rb | 8 -------- app/views/bans/index.html.erb | 2 +- app/views/bans/show.html.erb | 2 +- app/views/layouts/default.html.erb | 4 +--- app/views/users/_ban_notice.html.erb | 16 +++++++++++----- app/views/users/_statistics.html.erb | 5 +++-- 8 files changed, 24 insertions(+), 32 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index ddd15a408..7eb57a832 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -98,17 +98,12 @@ module ApplicationHelper tag.time content || datetime, datetime: datetime, title: time.to_formatted_s, **options end - def humanized_duration(from, to) - if to - from > 10.years - duration = "forever" + def humanized_duration(duration) + if duration >= 100.years + "forever" else - duration = distance_of_time_in_words(from, to) + duration.inspect end - - datetime = from.iso8601 + "/" + to.iso8601 - title = "#{from.strftime("%Y-%m-%d %H:%M")} to #{to.strftime("%Y-%m-%d %H:%M")}" - - raw content_tag(:time, duration, datetime: datetime, title: title) end def humanized_number(number) diff --git a/app/models/ban.rb b/app/models/ban.rb index 310b79a45..7cf7bca53 100644 --- a/app/models/ban.rb +++ b/app/models/ban.rb @@ -64,7 +64,7 @@ class Ban < ApplicationRecord end def humanized_duration - ApplicationController.helpers.distance_of_time_in_words(created_at, expires_at) + ApplicationController.helpers.humanized_duration(duration) end def expired? @@ -72,11 +72,11 @@ class Ban < ApplicationRecord end def create_feedback - user.feedback.create!(creator: banner, category: "negative", body: "Banned for #{humanized_duration}: #{reason}") + user.feedback.create!(creator: banner, category: "negative", body: "Banned #{humanized_duration}: #{reason}") end def create_ban_mod_action - ModAction.log(%{Banned <@#{user_name}> for #{humanized_duration}: #{reason}}, :user_ban) + ModAction.log(%{Banned <@#{user_name}> #{humanized_duration}: #{reason}}, :user_ban) end def create_unban_mod_action diff --git a/app/presenters/user_presenter.rb b/app/presenters/user_presenter.rb index b6e29e3cf..a7e30acba 100644 --- a/app/presenters/user_presenter.rb +++ b/app/presenters/user_presenter.rb @@ -13,14 +13,6 @@ class UserPresenter user.created_at.strftime("%Y-%m-%d") end - def ban_reason - if user.is_banned? - "#{user.active_ban.reason}; expires #{user.active_ban.expires_at} (#{user.bans.count} bans total)" - else - nil - end - end - def permissions permissions = [] diff --git a/app/views/bans/index.html.erb b/app/views/bans/index.html.erb index 0da3a4e3f..eda335be9 100644 --- a/app/views/bans/index.html.erb +++ b/app/views/bans/index.html.erb @@ -15,7 +15,7 @@ <% end %> <% t.column "Duration" do |ban| %> - <%= humanized_duration(ban.created_at, ban.expires_at) %> + <%= humanized_duration(ban.duration) %> <% end %> <% t.column "Banner" do |ban| %> <%= link_to_user ban.banner %> diff --git a/app/views/bans/show.html.erb b/app/views/bans/show.html.erb index 8b27eeea7..bc6a222b5 100644 --- a/app/views/bans/show.html.erb +++ b/app/views/bans/show.html.erb @@ -6,7 +6,7 @@

Show Ban