[PostEvents] Add event for changing background color (#655)

This commit is contained in:
Donovan Daniels 2024-06-28 11:26:01 -05:00 committed by GitHub
parent 0df2e77ab5
commit 6d1b15eab4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 13 additions and 2 deletions

View File

@ -19,6 +19,8 @@ class PostEventDecorator < ApplicationDecorator
"From: post ##{vals['child_id']}"
when "replacement_promoted"
"From: post ##{vals['source_post_id']}"
when "changed_bg_color"
"To: #{vals['bg_color'] || 'None'}"
end
end
end

View File

@ -30,7 +30,7 @@ class Post < ApplicationRecord
validate :updater_can_change_rating
before_save :update_tag_post_counts, if: :should_process_tags?
before_save :set_tag_counts, if: :should_process_tags?
after_save :create_lock_post_events
after_save :create_post_events
after_save :create_version
after_save :update_parent_on_save
after_save :apply_post_metatags
@ -1510,7 +1510,7 @@ class Post < ApplicationRecord
end
module PostEventMethods
def create_lock_post_events
def create_post_events
if saved_change_to_is_rating_locked?
action = is_rating_locked? ? :rating_locked : :rating_unlocked
PostEvent.add(id, CurrentUser.user, action)
@ -1527,6 +1527,9 @@ class Post < ApplicationRecord
action = is_comment_locked? ? :comment_locked : :comment_unlocked
PostEvent.add(id, CurrentUser.user, action)
end
if saved_change_to_bg_color?
PostEvent.add(id, CurrentUser.user, :changed_bg_color, { bg_color: bg_color })
end
end
end

View File

@ -24,6 +24,7 @@ class PostEvent < ApplicationRecord
replacement_promoted: 20,
replacement_deleted: 16,
expunged: 17,
changed_bg_color: 21,
}
MOD_ONLY_ACTIONS = [
actions[:comment_locked],

View File

@ -92,6 +92,11 @@ class PostEventTest < ActiveSupport::TestCase
@post.save
end
assert_post_events_created(@janitor, :changed_bg_color) do
@post.bg_color = "FFFFFF"
@post.save
end
assert_post_events_created(@admin, :expunged) do
@post.expunge!
end