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.
This commit is contained in:
evazion
2021-05-15 03:39:32 -05:00
parent 8ca757244a
commit 90a4ac3bf5
8 changed files with 24 additions and 32 deletions

View File

@@ -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)

View File

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

View File

@@ -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 = []

View File

@@ -15,7 +15,7 @@
</div>
<% 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 %>

View File

@@ -6,7 +6,7 @@
<h1>Show Ban</h1>
<ul style="margin-bottom: 1em;">
<li><strong>User</strong> <%= link_to_user(@ban.user) %></li>
<li><strong>Duration</strong> <%= humanized_duration(@ban.created_at, @ban.expires_at) %></li>
<li><strong>Duration</strong> <%= humanized_duration(@ban.duration) %></li>
<li>
<strong>Reason</strong>
<div class="prose">

View File

@@ -81,9 +81,7 @@
<%= render "users/upgrade_notice" %>
<% end %>
<% if CurrentUser.user.is_banned? %>
<%= render "users/ban_notice" %>
<% end %>
<%= render "users/ban_notice" %>
<% if params[:controller] != "dmails" && has_unread_dmails?(CurrentUser.user) %>
<%= render "users/dmail_notice" %>

View File

@@ -1,5 +1,11 @@
<div class="notice notice-error notice-large" id="ban-notice">
<h2>Your account has been temporarily banned</h2>
<div>Reason: <span class="prose"><%= format_text CurrentUser.user.active_ban.reason, inline: true %></span></div>
<div>Your ban will expire in <%= time_ago_in_words(CurrentUser.user.active_ban.expires_at) %></div>
</div>
<% if CurrentUser.user.is_banned? %>
<% @active_ban = CurrentUser.user.active_ban %>
<div class="notice notice-error notice-large" id="ban-notice">
<h2>You have been banned <%= humanized_duration @active_ban.duration %></h2>
<div>
Reason: <span class="prose"><%= format_text @active_ban.reason, inline: true %></span>
</div>
</div>
<% end %>

View File

@@ -89,12 +89,13 @@
<td><%= presenter.permissions %></td>
</tr>
<% if user.is_banned? %>
<% if user.is_banned? && user.active_ban.present? %>
<tr>
<th>Ban reason</th>
<td>
<span class="prose">
<%= format_text presenter.ban_reason, inline: true %>
<%= format_text user.active_ban.reason, inline: true %>
(banned <%= humanized_duration(user.active_ban.duration) %>)
</span>
</td>
</tr>