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

This commit is contained in:
Tim Lange 2019-03-27 21:29:15 +01:00 committed by Régis Hanol
parent 0d3531c2f1
commit 12181599db
2 changed files with 14 additions and 1 deletions

View File

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

View File

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