diff --git a/app/models/mod_action.rb b/app/models/mod_action.rb index cbec8de4d..2409661e7 100644 --- a/app/models/mod_action.rb +++ b/app/models/mod_action.rb @@ -31,6 +31,12 @@ class ModAction < ApplicationRecord post_move_favorites: 47, post_regenerate: 48, post_regenerate_iqdb: 49, + post_note_lock_create: 210, + post_note_lock_delete: 212, + post_rating_lock_create: 220, + post_rating_lock_delete: 222, + post_status_lock_create: 230, + post_status_lock_delete: 232, pool_delete: 62, pool_undelete: 63, artist_ban: 184, diff --git a/app/models/post.rb b/app/models/post.rb index 40babeb7e..056d62cd9 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -31,6 +31,7 @@ class Post < ApplicationRecord validate :uploader_is_not_limited, on: :create before_save :update_tag_post_counts before_save :set_tag_counts + before_save :create_mod_action_for_lock_change before_create :autoban after_save :create_version after_save :update_parent_on_save @@ -1510,6 +1511,32 @@ class Post < ApplicationRecord save end + def create_mod_action_for_lock_change + if is_note_locked != is_note_locked_was + if is_note_locked + ModAction.log("locked notes for post ##{id}", :post_note_lock_create) + else + ModAction.log("unlocked notes for post ##{id}", :post_note_lock_delete) + end + end + + if is_rating_locked != is_rating_locked_was + if is_rating_locked + ModAction.log("locked rating for post ##{id}", :post_rating_lock_create) + else + ModAction.log("unlocked rating for post ##{id}", :post_rating_lock_delete) + end + end + + if is_status_locked != is_status_locked_was + if is_status_locked + ModAction.log("locked status for post ##{id}", :post_status_lock_create) + else + ModAction.log("unlocked status for post ##{id}", :post_status_lock_delete) + end + end + end + def self.model_restriction(table) super.where(table[:is_pending].eq(false)).where(table[:is_flagged].eq(false)).where(table[:is_deleted].eq(false)) end diff --git a/test/unit/post_test.rb b/test/unit/post_test.rb index 4ad48f51a..7482fd8fb 100644 --- a/test/unit/post_test.rb +++ b/test/unit/post_test.rb @@ -534,6 +534,52 @@ class PostTest < ActiveSupport::TestCase assert_includes(approval.errors.full_messages, "Post is locked and cannot be approved") end end + + context "Locking post fields" do + should "create ModAction entries" do + @post = create(:post) + assert_difference("ModAction.post_note_lock_create.count", 1) do + @post.is_note_locked = true + @post.save! + end + + assert_difference("ModAction.post_note_lock_delete.count", 1) do + @post.is_note_locked = false + @post.save! + end + + assert_difference("ModAction.post_rating_lock_create.count", 1) do + @post.is_rating_locked = true + @post.save! + end + + assert_difference("ModAction.post_rating_lock_delete.count", 1) do + @post.is_rating_locked = false + @post.save! + end + + assert_difference("ModAction.post_status_lock_create.count", 1) do + @post.is_status_locked = true + @post.save! + end + + assert_difference("ModAction.post_status_lock_delete.count", 1) do + @post.is_status_locked = false + @post.save! + end + + assert_difference("ModAction.post_status_lock_create.count", 1) do + assert_difference("ModAction.post_rating_lock_create.count", 1) do + assert_difference("ModAction.post_note_lock_create.count", 1) do + @post.is_status_locked = true + @post.is_rating_locked = true + @post.is_note_locked = true + @post.save! + end + end + end + end + end end context "Tagging:" do