mod actions: hide ip bans from non-mods.

Hide IP ban creation and deletion actions from non-mods in the
/mod_actions listing.

The previous approach of just filtering out the IP from the description
was hacky and didn't work with the `only` param (/mod_actions.json?only=id
still included the description field).
This commit is contained in:
evazion
2019-12-16 12:20:41 -06:00
parent 84ba1d417f
commit 3d03de1c52
3 changed files with 15 additions and 20 deletions

View File

@@ -3,17 +3,15 @@ require 'test_helper'
class ModActionTest < ActiveSupport::TestCase
context "A mod action" do
setup do
@user = FactoryBot.create(:user)
CurrentUser.user = @user
CurrentUser.ip_addr = "127.0.0.1"
@user = create(:user)
@mod = create(:moderator_user)
end
should "hide ip addresses from non-moderators in ip ban modactions" do
FactoryBot.create(:ip_ban, ip_addr: "1.1.1.1", reason: "test")
as(@mod) { create(:ip_ban, ip_addr: "1.1.1.1", reason: "test") }
assert_equal(1, ModAction.count)
assert_equal("#{@user.name} created ip ban", ModAction.last.filtered_description)
assert_equal("#{@user.name} created ip ban", ModAction.last.as_json["description"])
as(@user) { assert_equal(0, ModAction.search({}).count) }
as(@mod) { assert_equal(1, ModAction.search({}).count) }
end
end
end