FIX: Staff action records now also accepts action_name as filter (#7256)

FIX: Staff action records now also accepts action_name as filter (#7256)

diff --git a/app/models/user_history.rb b/app/models/user_history.rb
index 276d306..7239e07 100644
--- a/app/models/user_history.rb
+++ b/app/models/user_history.rb
@@ -193,11 +193,12 @@ class UserHistory < ActiveRecord::Base
   end
 
   def self.staff_filters
-    [:action_id, :custom_type, :acting_user, :target_user, :subject]
+    [:action_id, :custom_type, :acting_user, :target_user, :subject, :action_name]
   end
 
   def self.staff_action_records(viewer, opts = nil)
     opts ||= {}
+    opts[:action_id] = self.actions[opts[:action_name].to_sym] if opts[:action_name]
     query = self.with_filters(opts.slice(*staff_filters)).only_staff_actions.limit(200).order('id DESC').includes(:acting_user, :target_user)
     query = query.where(admin_only: false) unless viewer && viewer.admin?
     query
diff --git a/spec/models/user_history_spec.rb b/spec/models/user_history_spec.rb
index 823dcc5..8aa547b 100644
--- a/spec/models/user_history_spec.rb
+++ b/spec/models/user_history_spec.rb
@@ -34,6 +34,18 @@ describe UserHistory do
         records = described_class.staff_action_records(Fabricate(:moderator)).to_a
         expect(records).to eq([@change_trust_level])
       end
+
+      it 'filters by action' do
+        records = described_class.staff_action_records(Fabricate(:admin), action_id: @change_site_setting.action_before_type_cast).to_a
+        expect(records.size).to eq(1)
+        expect(records.first).to eq(@change_site_setting)
+      end
+
+      it 'filters by action_name' do
+        records = described_class.staff_action_records(Fabricate(:admin), action_name: "change_site_setting").to_a
+        expect(records.size).to eq(1)
+        expect(records.first).to eq(@change_site_setting)
+      end
     end
   end

GitHub sha: 12181599