bans: change expires_at field to duration.
Changes: * Change the `expires_at` field to `duration`. * Make moderators choose from a fixed set of standard ban lengths, instead of allowing arbitrary ban lengths. * List `duration` in seconds in the /bans.json API. * Dump bans to BigQuery. Note that some old bans have a negative duration. This is because their expiration date was before their creation date, which is because in 2013 bans were migrated to Danbooru 2 and the original ban creation dates were lost.
This commit is contained in:
@@ -2,16 +2,10 @@ require 'test_helper'
|
||||
|
||||
class BansControllerTest < ActionDispatch::IntegrationTest
|
||||
context "A bans controller" do
|
||||
setup do
|
||||
@mod = create(:moderator_user, name: "danbo")
|
||||
@admin = create(:admin_user)
|
||||
@user = create(:member_user, id: 999, name: "cirno")
|
||||
|
||||
as(@mod) { @ban = create(:ban, reason: "blah", user: @user, banner: @mod) }
|
||||
end
|
||||
|
||||
context "new action" do
|
||||
should "render" do
|
||||
@mod = create(:mod_user)
|
||||
|
||||
get_auth new_ban_path, @mod
|
||||
assert_response :success
|
||||
end
|
||||
@@ -19,6 +13,9 @@ class BansControllerTest < ActionDispatch::IntegrationTest
|
||||
|
||||
context "edit action" do
|
||||
should "render" do
|
||||
@mod = create(:mod_user)
|
||||
@ban = create(:ban)
|
||||
|
||||
get_auth edit_ban_path(@ban.id), @mod
|
||||
assert_response :success
|
||||
end
|
||||
@@ -26,14 +23,18 @@ class BansControllerTest < ActionDispatch::IntegrationTest
|
||||
|
||||
context "show action" do
|
||||
should "render" do
|
||||
get_auth ban_path(@ban.id), @mod
|
||||
@ban = create(:ban)
|
||||
|
||||
get ban_path(@ban)
|
||||
assert_response :success
|
||||
end
|
||||
end
|
||||
|
||||
context "index action" do
|
||||
setup do
|
||||
as(@admin) { @admin_ban = create(:ban, user: build(:builder_user), banner: @admin, expires_at: 1.day.ago ) }
|
||||
@mod = create(:mod_user, name: "mod")
|
||||
@ban1 = create(:ban, created_at: 1.week.ago, duration: 1.day)
|
||||
@ban2 = create(:ban, user: build(:builder_user), reason: "blah", banner: @mod, duration: 100.years)
|
||||
end
|
||||
|
||||
should "render" do
|
||||
@@ -41,24 +42,21 @@ class BansControllerTest < ActionDispatch::IntegrationTest
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
should respond_to_search({}).with { [@admin_ban, @ban] }
|
||||
should respond_to_search(reason_matches: "blah").with { @ban }
|
||||
should respond_to_search(expired: "true").with { @admin_ban }
|
||||
should respond_to_search({}).with { [@ban2, @ban1] }
|
||||
should respond_to_search(reason_matches: "blah").with { @ban2 }
|
||||
should respond_to_search(expired: "false").with { @ban2 }
|
||||
should respond_to_search(duration: "<1w").with { @ban1 }
|
||||
|
||||
context "using includes" do
|
||||
should respond_to_search(banner_name: "danbo").with { @ban }
|
||||
should respond_to_search(banner: {level: User::Levels::ADMIN}).with { @admin_ban }
|
||||
should respond_to_search(user_id: 999).with { @ban }
|
||||
should respond_to_search(user: {name: "cirno"}).with { @ban }
|
||||
should respond_to_search(user: {level: User::Levels::BUILDER}).with { @admin_ban }
|
||||
end
|
||||
should respond_to_search(banner_name: "mod").with { @ban2 }
|
||||
should respond_to_search(banner: { level: User::Levels::MODERATOR }).with { @ban2 }
|
||||
end
|
||||
|
||||
context "create action" do
|
||||
should "allow mods to ban members" do
|
||||
assert_difference("Ban.count", 1) do
|
||||
@user = create(:user)
|
||||
post_auth bans_path, @mod, params: { ban: { duration: 60, reason: "xxx", user_id: @user.id }}
|
||||
@mod = create(:mod_user)
|
||||
post_auth bans_path, @mod, params: { ban: { duration: 1.day.iso8601, reason: "xxx", user_id: @user.id }}
|
||||
|
||||
assert_redirected_to bans_path
|
||||
assert_equal(true, @user.reload.is_banned?)
|
||||
@@ -67,7 +65,9 @@ class BansControllerTest < ActionDispatch::IntegrationTest
|
||||
|
||||
should "not allow mods to ban admins" do
|
||||
assert_difference("Ban.count", 0) do
|
||||
post_auth bans_path, @mod, params: { ban: { duration: 60, reason: "xxx", user_id: @admin.id }}
|
||||
@admin = create(:admin_user)
|
||||
@mod = create(:mod_user)
|
||||
post_auth bans_path, @mod, params: { ban: { duration: 1.day.iso8601, reason: "xxx", user_id: @admin.id }}
|
||||
|
||||
assert_response 403
|
||||
assert_equal(false, @admin.reload.is_banned?)
|
||||
@@ -76,8 +76,9 @@ class BansControllerTest < ActionDispatch::IntegrationTest
|
||||
|
||||
should "not allow mods to ban other mods" do
|
||||
assert_difference("Ban.count", 0) do
|
||||
@mod = create(:mod_user)
|
||||
@mod2 = create(:mod_user)
|
||||
post_auth bans_path, @mod, params: { ban: { duration: 60, reason: "xxx", user_id: @mod2.id }}
|
||||
post_auth bans_path, @mod, params: { ban: { duration: 1.day.iso8601, reason: "xxx", user_id: @mod2.id }}
|
||||
|
||||
assert_response 403
|
||||
assert_equal(false, @mod2.reload.is_banned?)
|
||||
@@ -87,7 +88,8 @@ class BansControllerTest < ActionDispatch::IntegrationTest
|
||||
should "not allow regular users to ban anyone" do
|
||||
assert_difference("Ban.count", 0) do
|
||||
@user = create(:user)
|
||||
post_auth bans_path, @user, params: { ban: { duration: 60, reason: "xxx", user_id: @mod.id }}
|
||||
@mod = create(:mod_user)
|
||||
post_auth bans_path, @user, params: { ban: { duration: 1.day.iso8601, reason: "xxx", user_id: @mod.id }}
|
||||
|
||||
assert_response 403
|
||||
assert_equal(false, @mod.reload.is_banned?)
|
||||
@@ -95,13 +97,17 @@ class BansControllerTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
should "not allow users to be double banned" do
|
||||
@ban = create(:ban, duration: 1.week)
|
||||
@mod = create(:mod_user)
|
||||
|
||||
assert_difference("Ban.count", 0) do
|
||||
post_auth bans_path, @mod, params: { ban: { duration: 60, reason: "xxx", user_id: @ban.user.id }}
|
||||
post_auth bans_path, @mod, params: { ban: { duration: 1.day.iso8601, reason: "xxx", user_id: @ban.user.id }}
|
||||
assert_response :success
|
||||
end
|
||||
end
|
||||
|
||||
should "not raise an exception on a blank username" do
|
||||
@mod = create(:mod_user)
|
||||
post_auth bans_path, @mod, params: {}
|
||||
assert_response :success
|
||||
end
|
||||
@@ -109,7 +115,10 @@ class BansControllerTest < ActionDispatch::IntegrationTest
|
||||
|
||||
context "update action" do
|
||||
should "update a ban" do
|
||||
put_auth ban_path(@ban.id), @mod, params: {ban: {reason: "xxx", duration: 60}}
|
||||
@ban = create(:ban)
|
||||
@mod = create(:mod_user)
|
||||
put_auth ban_path(@ban.id), @mod, params: {ban: {reason: "xxx", duration: 1.day.iso8601}}
|
||||
|
||||
assert_equal("xxx", @ban.reload.reason)
|
||||
assert_redirected_to(ban_path(@ban))
|
||||
end
|
||||
@@ -117,6 +126,9 @@ class BansControllerTest < ActionDispatch::IntegrationTest
|
||||
|
||||
context "destroy action" do
|
||||
should "destroy a ban" do
|
||||
@ban = create(:ban)
|
||||
@mod = create(:mod_user)
|
||||
|
||||
assert_difference("Ban.count", -1) do
|
||||
delete_auth ban_path(@ban.id), @mod
|
||||
assert_redirected_to bans_path
|
||||
|
||||
Reference in New Issue
Block a user