From ee183731577830ad54869e9dd5d1f523cdd45eb9 Mon Sep 17 00:00:00 2001
From: Monica Cellio <cellio@pobox.com>
Date: Thu, 6 Feb 2025 17:38:31 -0500
Subject: [PATCH] for mods, add number of warnings/suspensions sent (if any) to
 user profile page

---
 app/models/community_user.rb  | 4 ++++
 app/views/users/show.html.erb | 8 ++++++++
 2 files changed, 12 insertions(+)

diff --git a/app/models/community_user.rb b/app/models/community_user.rb
index e81d1f579..ee9e90fd7 100644
--- a/app/models/community_user.rb
+++ b/app/models/community_user.rb
@@ -30,6 +30,10 @@ class CommunityUser < ApplicationRecord
     false
   end
 
+  def latest_warning
+    mod_warnings&.order(created_at: 'desc').first.created_at
+  end
+
   # Calculation functions for privilege scores
   # These are quite expensive, so we'll cache them for a while
   def post_score
diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb
index bb10e0ec4..493d19b49 100644
--- a/app/views/users/show.html.erb
+++ b/app/views/users/show.html.erb
@@ -20,6 +20,14 @@
   </div>
 <% end %>
 
+<% if moderator? && @user.community_user.mod_warnings&.size.positive? %>
+<div class="notice is-info h-m-b-4">
+  <p><%= pluralize(@user.community_user.mod_warnings.count, 'message') %> sent,
+  most recent: <%= time_ago_in_words(@user.community_user.latest_warning) %> ago
+  </p>
+</div>
+<% end %>
+
 <div class="grid <%= deleted_user?(@user) ? 'deleted-content' : '' %>">
   <div class="grid--cell is-9-lg is-12">
     <div class="h-p-0 h-p-t-0">
-- 
GitLab