mod actions: fix messages to use consistent format.
Fix mod actions to use the same message format everywhere. Before mod actions were formatted in various inconsistent ways: * "deleted post #1234" * "comment #1234 updated by <user>" * "<user> updated forum #1234" * "<user> level changed Member -> Builder" Now all mod actions consistently use this format: * "deleted post #1234" * "updated comment #1234" * "updated forum #1234" * "promoted <user> from Member to Builder" This way mod actions are formatted consistently with other actions on the /user_actions page, where everything is written as "<user> did X". Also add a fix script to fix existing mod actions.
This commit is contained in:
@@ -19,8 +19,10 @@ class Admin::UsersControllerTest < ActionDispatch::IntegrationTest
|
||||
context "on a basic user" do
|
||||
should "succeed" do
|
||||
put_auth admin_user_path(@user), @mod, params: {:user => {:level => "30"}}
|
||||
|
||||
assert_redirected_to(edit_admin_user_path(@user))
|
||||
assert_equal(30, @user.reload.level)
|
||||
assert_match(/promoted "#{@user.name}":\/users\/#{@user.id} from Member to Gold/, ModAction.last.description)
|
||||
end
|
||||
|
||||
should "promote the user to unrestricted uploads" do
|
||||
@@ -30,6 +32,8 @@ class Admin::UsersControllerTest < ActionDispatch::IntegrationTest
|
||||
assert_equal(true, @user.is_builder?)
|
||||
assert_equal(true, @user.can_upload_free?)
|
||||
assert_equal(false, @user.can_approve_posts?)
|
||||
assert_match(/granted unlimited upload privileges to "#{@user.name}":\/users\/#{@user.id}/, ModAction.first.description)
|
||||
assert_match(/promoted "#{@user.name}":\/users\/#{@user.id} from Member to Builder/, ModAction.last.description)
|
||||
end
|
||||
|
||||
should "promote the user to approver" do
|
||||
@@ -39,6 +43,8 @@ class Admin::UsersControllerTest < ActionDispatch::IntegrationTest
|
||||
assert_equal(true, @user.is_builder?)
|
||||
assert_equal(false, @user.can_upload_free?)
|
||||
assert_equal(true, @user.can_approve_posts?)
|
||||
assert_match(/granted approval privileges to "#{@user.name}":\/users\/#{@user.id}/, ModAction.first.description)
|
||||
assert_match(/promoted "#{@user.name}":\/users\/#{@user.id} from Member to Builder/, ModAction.last.description)
|
||||
end
|
||||
|
||||
context "promoted to an admin" do
|
||||
|
||||
@@ -60,6 +60,7 @@ class BansControllerTest < ActionDispatch::IntegrationTest
|
||||
|
||||
assert_redirected_to bans_path
|
||||
assert_equal(true, @user.reload.is_banned?)
|
||||
assert_match(/banned <@#{@user.name}> 1 day: xxx/, ModAction.last.description)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -131,7 +132,9 @@ class BansControllerTest < ActionDispatch::IntegrationTest
|
||||
|
||||
assert_difference("Ban.count", -1) do
|
||||
delete_auth ban_path(@ban.id), @mod
|
||||
|
||||
assert_redirected_to bans_path
|
||||
assert_match(/unbanned <@#{@ban.user.name}>/, ModAction.last.description)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -141,7 +141,9 @@ class CommentsControllerTest < ActionDispatch::IntegrationTest
|
||||
context "when updating another user's comment" do
|
||||
should "succeed if updater is a moderator" do
|
||||
put_auth comment_path(@comment.id), @user, params: {comment: {body: "abc"}}, xhr: true
|
||||
|
||||
assert_equal("abc", @comment.reload.body)
|
||||
assert_match(/updated comment ##{@comment.id}/, ModAction.last.description)
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
@@ -156,7 +158,9 @@ class CommentsControllerTest < ActionDispatch::IntegrationTest
|
||||
context "when stickying a comment" do
|
||||
should "succeed if updater is a moderator" do
|
||||
put_auth comment_path(@comment.id), @mod, params: {comment: {is_sticky: true}}, xhr: true
|
||||
|
||||
assert_equal(true, @comment.reload.is_sticky)
|
||||
assert_match(/updated comment ##{@comment.id}/, ModAction.last.description)
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
@@ -179,14 +183,18 @@ class CommentsControllerTest < ActionDispatch::IntegrationTest
|
||||
|
||||
should "update the body" do
|
||||
put_auth comment_path(@comment.id), @user, params: {comment: {body: "abc"}}, xhr: true
|
||||
|
||||
assert_equal("abc", @comment.reload.body)
|
||||
assert_match(/updated comment ##{@comment.id}/, ModAction.last.description)
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
should "allow changing the body and is_deleted" do
|
||||
put_auth comment_path(@comment.id), @user, params: {comment: {body: "herp derp", is_deleted: true}}, xhr: true
|
||||
|
||||
assert_equal("herp derp", @comment.reload.body)
|
||||
assert_equal(true, @comment.is_deleted)
|
||||
assert_match(/deleted comment ##{@comment.id}/, ModAction.last.description)
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
@@ -240,6 +248,7 @@ class CommentsControllerTest < ActionDispatch::IntegrationTest
|
||||
|
||||
assert_equal(true, @comment.reload.is_deleted)
|
||||
assert_redirected_to @comment
|
||||
assert_match(/deleted comment ##{@comment.id}/, ModAction.last.description)
|
||||
end
|
||||
|
||||
should "mark all pending moderation reports against the comment as handled" do
|
||||
@@ -263,6 +272,7 @@ class CommentsControllerTest < ActionDispatch::IntegrationTest
|
||||
|
||||
assert_redirected_to(@comment)
|
||||
assert_equal(false, @comment.reload.is_deleted)
|
||||
assert_match(/updated comment ##{@comment.id}/, ModAction.last.description)
|
||||
end
|
||||
|
||||
should "not allow normal Members to undelete their own comments" do
|
||||
|
||||
@@ -213,7 +213,9 @@ class ForumPostsControllerTest < ActionDispatch::IntegrationTest
|
||||
|
||||
should "allow moderators to update other people's posts" do
|
||||
put_auth forum_post_path(@forum_post), @mod, params: { forum_post: { body: "test" }}
|
||||
|
||||
assert_redirected_to(forum_topic_path(@forum_topic, anchor: "forum_post_#{@forum_post.id}"))
|
||||
assert_match(/updated forum ##{@forum_post.id}/, ModAction.last.description)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -224,6 +226,7 @@ class ForumPostsControllerTest < ActionDispatch::IntegrationTest
|
||||
|
||||
assert_redirected_to(@forum_reply)
|
||||
assert_equal(true, @forum_reply.reload.is_deleted?)
|
||||
assert_match(/updated forum ##{@forum_reply.id}/, ModAction.last.description)
|
||||
end
|
||||
|
||||
should "not allow users to delete their own posts" do
|
||||
@@ -262,6 +265,7 @@ class ForumPostsControllerTest < ActionDispatch::IntegrationTest
|
||||
|
||||
assert_redirected_to(@forum_reply)
|
||||
assert_equal(false, @forum_reply.reload.is_deleted?)
|
||||
assert_match(/updated forum ##{@forum_reply.id}/, ModAction.last.description)
|
||||
end
|
||||
|
||||
should "not allow users to undelete their own posts" do
|
||||
|
||||
@@ -18,13 +18,16 @@ class IpBansControllerTest < ActionDispatch::IntegrationTest
|
||||
should "create a new ip ban" do
|
||||
assert_difference("IpBan.count", 1) do
|
||||
post_auth ip_bans_path, @admin, params: {:ip_ban => {:ip_addr => "1.2.3.4", :reason => "xyz"}}
|
||||
|
||||
assert_response :redirect
|
||||
end
|
||||
end
|
||||
|
||||
should "log a mod action" do
|
||||
post_auth ip_bans_path, @admin, params: { ip_ban: { ip_addr: "1.2.3.4", reason: "xyz" }}
|
||||
|
||||
assert_equal("ip_ban_create", ModAction.last&.category)
|
||||
assert_match(/created ip ban for 1\.2\.3\.4/, ModAction.last.description)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -61,6 +64,17 @@ class IpBansControllerTest < ActionDispatch::IntegrationTest
|
||||
assert_response :success
|
||||
assert_equal(true, @ip_ban.reload.is_deleted)
|
||||
assert_equal("ip_ban_delete", ModAction.last.category)
|
||||
assert_match(/deleted ip ban for #{@ip_ban.ip_addr}/, ModAction.last.description)
|
||||
end
|
||||
|
||||
should "mark an ip ban as undeleted" do
|
||||
@ip_ban = create(:ip_ban, ip_addr: "5.6.7.8", is_deleted: true)
|
||||
put_auth ip_ban_path(@ip_ban), @admin, params: { ip_ban: { is_deleted: false }, format: "js" }
|
||||
|
||||
assert_response :success
|
||||
assert_equal(false, @ip_ban.reload.is_deleted?)
|
||||
assert_equal("ip_ban_undelete", ModAction.last.category)
|
||||
assert_match(/undeleted ip ban for #{@ip_ban.ip_addr}/, ModAction.last.description)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -33,7 +33,7 @@ class PostRegenerationsControllerTest < ActionDispatch::IntegrationTest
|
||||
|
||||
assert_equal(@mod, ModAction.last.creator)
|
||||
assert_equal("post_regenerate_iqdb", ModAction.last.category)
|
||||
assert_equal("<@#{@mod.name}> regenerated IQDB for post ##{@post.id}", ModAction.last.description)
|
||||
assert_equal("regenerated IQDB for post ##{@post.id}", ModAction.last.description)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -55,7 +55,7 @@ class PostRegenerationsControllerTest < ActionDispatch::IntegrationTest
|
||||
|
||||
assert_equal(@mod, ModAction.last.creator)
|
||||
assert_equal("post_regenerate", ModAction.last.category)
|
||||
assert_equal("<@#{@mod.name}> regenerated image samples for post ##{@post.id}", ModAction.last.description)
|
||||
assert_equal("regenerated image samples for post ##{@post.id}", ModAction.last.description)
|
||||
end
|
||||
|
||||
should "fix the width and height of exif-rotated images" do
|
||||
|
||||
@@ -286,7 +286,7 @@ class PostVotesControllerTest < ActionDispatch::IntegrationTest
|
||||
assert_equal(0, @post.up_score)
|
||||
assert_equal(0, @post.votes.active.count)
|
||||
assert_equal(true, @vote.reload.is_deleted?)
|
||||
assert_match(/#{admin.name} deleted post vote #\d+ on post #\d+/, ModAction.post_vote_delete.last.description)
|
||||
assert_match(/deleted post vote #\d+ on post #\d+/, ModAction.post_vote_delete.last.description)
|
||||
end
|
||||
|
||||
should "not fail when attempting to remove an already removed vote" do
|
||||
|
||||
@@ -100,6 +100,7 @@ class UserFeedbacksControllerTest < ActionDispatch::IntegrationTest
|
||||
|
||||
assert_redirected_to(@user_feedback)
|
||||
assert_equal("positive", @user_feedback.reload.category)
|
||||
assert_equal(0, ModAction.count)
|
||||
end
|
||||
|
||||
should "not allow updating deleted feedbacks" do
|
||||
@@ -114,14 +115,24 @@ class UserFeedbacksControllerTest < ActionDispatch::IntegrationTest
|
||||
|
||||
assert_response :redirect
|
||||
assert_equal(true, @user_feedback.reload.is_deleted)
|
||||
assert_equal(0, ModAction.count)
|
||||
end
|
||||
|
||||
context "by a moderator" do
|
||||
should "allow updating feedbacks given to other users" do
|
||||
put_auth user_feedback_path(@user_feedback), @mod, params: { user_feedback: { body: "blah" }}
|
||||
|
||||
assert_redirected_to @user_feedback
|
||||
assert_equal("blah", @user_feedback.reload.body)
|
||||
assert_match(/updated user feedback for "#{@user.name}":\/users\/#{@user.id}/, ModAction.last.description)
|
||||
end
|
||||
|
||||
should "allow deleting feedbacks given to other users" do
|
||||
put_auth user_feedback_path(@user_feedback), @mod, params: { user_feedback: { is_deleted: "true" }}
|
||||
|
||||
assert_redirected_to @user_feedback
|
||||
assert(@user_feedback.reload.is_deleted?)
|
||||
assert_match(/updated user feedback for "#{@user.name}":\/users\/#{@user.id}/, ModAction.last.description)
|
||||
end
|
||||
|
||||
should "not allow updating feedbacks given to themselves" do
|
||||
|
||||
@@ -106,7 +106,7 @@ class PostVoteTest < ActiveSupport::TestCase
|
||||
vote = create(:post_vote, post: @post, score: 1)
|
||||
|
||||
vote.soft_delete!(updater: admin)
|
||||
assert_match(/admin deleted post vote #\d+ on post #\d+/, ModAction.post_vote_delete.last.description)
|
||||
assert_match(/deleted post vote #\d+ on post #\d+/, ModAction.post_vote_delete.last.description)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -128,7 +128,7 @@ class PostVoteTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "leave a mod action" do
|
||||
assert_match(/admin undeleted post vote #\d+ on post #\d+/, ModAction.post_vote_undelete.last.description)
|
||||
assert_match(/undeleted post vote #\d+ on post #\d+/, ModAction.post_vote_undelete.last.description)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -67,6 +67,11 @@ class UserDeletionTest < ActiveSupport::TestCase
|
||||
assert_equal(false, @user.authenticate_password("password"))
|
||||
end
|
||||
|
||||
should "generate a modaction" do
|
||||
@deletion.delete!
|
||||
assert_match(/deleted user ##{@user.id}/, ModAction.last.description)
|
||||
end
|
||||
|
||||
should "remove any favorites" do
|
||||
@post = create(:post)
|
||||
Favorite.create!(post: @post, user: @user)
|
||||
|
||||
Reference in New Issue
Block a user