[Posts] Add events for status/note lock

This commit is contained in:
Earlopain 2022-01-06 13:54:40 +01:00
parent aa77f1a76a
commit ea28ab906b
No known key found for this signature in database
GPG Key ID: 6CFB948E15246897
5 changed files with 43 additions and 21 deletions

View File

@ -6,11 +6,11 @@ class PostEventDecorator < ApplicationDecorator
case object.action
when "deleted", "flag_created"
"Reason: #{vals['reason']}"
"#{vals['reason']}"
when "favorites_moved"
"Target: post ##{vals['parent_id']}"
when "favorites_recieved"
"Source: post ##{vals['child_id']}"
when "favorites_received"
"From: post ##{vals['child_id']}"
end
end
end

View File

@ -33,7 +33,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_rating_lock_post_event, if: :saved_change_to_is_rating_locked?
after_save :create_lock_post_events
after_save :create_version
after_save :update_parent_on_save
after_save :apply_post_metatags
@ -1472,7 +1472,7 @@ class Post < ApplicationRecord
FavoriteManager.give_to_parent!(self)
PostEvent.add(id, :favorites_moved, { parent_id: parent_id })
PostEvent.add(parent_id, :favorites_recieved, { child_id: id })
PostEvent.add(parent_id, :favorites_received, { child_id: id })
end
def parent_exists?
@ -1984,10 +1984,20 @@ class Post < ApplicationRecord
end
end
module RatingMethods
def create_rating_lock_post_event
action = is_rating_locked? ? :rating_locked : :rating_unlocked
PostEvent.add(id, action)
module PostEventMethods
def create_lock_post_events
if saved_change_to_is_rating_locked?
action = is_rating_locked? ? :rating_locked : :rating_unlocked
PostEvent.add(id, action)
end
if saved_change_to_is_status_locked?
action = is_status_locked? ? :status_locked : :status_unlocked
PostEvent.add(id, action)
end
if saved_change_to_is_note_locked?
action = is_note_locked? ? :note_locked : :note_unlocked
PostEvent.add(id, action)
end
end
end
@ -2098,7 +2108,7 @@ class Post < ApplicationRecord
extend SearchMethods
include IqdbMethods
include ValidationMethods
include RatingMethods
include PostEventMethods
include Danbooru::HasBitFlags
include Indexable
include PostIndex

View File

@ -6,16 +6,20 @@ class PostEvent < ApplicationRecord
undeleted: 1,
approved: 2,
unapproved: 3,
favorites_moved: 4,
favorites_recieved: 5,
rating_locked: 6,
rating_unlocked: 7,
flag_created: 8,
flag_removed: 9,
replacement_accepted: 10,
replacement_rejected: 11,
replacement_deleted: 12,
expunged: 13
flag_created: 4,
flag_removed: 5,
favorites_moved: 6,
favorites_received: 7,
rating_locked: 8,
rating_unlocked: 9,
status_locked: 10,
status_unlocked: 11,
note_locked: 12,
note_unlocked: 13,
replacement_accepted: 14,
replacement_rejected: 15,
replacement_deleted: 16,
expunged: 17
}
def self.add(post_id, action, data = {})

View File

@ -10,7 +10,7 @@
<th>Post</th>
<th>Type</th>
<th>User</th>
<th>Description</th>
<th>Info</th>
</tr>
</thead>
<tbody>

View File

@ -5080,6 +5080,14 @@ ALTER TABLE ONLY public.staff_notes
ADD CONSTRAINT fk_rails_bab7e2d92a FOREIGN KEY (user_id) REFERENCES public.users(id);
--
-- Name: post_events fk_rails_bd327ccee6; Type: FK CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.post_events
ADD CONSTRAINT fk_rails_bd327ccee6 FOREIGN KEY (creator_id) REFERENCES public.users(id);
--
-- Name: favorites fk_rails_d20e53bb68; Type: FK CONSTRAINT; Schema: public; Owner: -
--