Files
danbooru/app/logical/forum_updater.rb
evazion db63b6d44f pundit: convert forum topics / forum posts to pundit.
Fix it being possible for users to delete or undelete their own forum
posts and topics, even if they were deleted by a mod.
2020-03-20 18:03:00 -05:00

29 lines
653 B
Ruby

class ForumUpdater
attr_reader :forum_topic, :forum_post
def initialize(forum_topic, options = {})
@forum_topic = forum_topic
@forum_post = options[:forum_post]
end
def update(message)
return if forum_topic.nil?
CurrentUser.scoped(User.system) do
create_response(message)
if forum_post
update_post(message)
end
end
end
def create_response(body)
forum_topic.forum_posts.create(body: body, skip_mention_notifications: true, creator: User.system)
end
def update_post(body)
forum_post.update(body: "#{forum_post.body}\n\nEDIT: #{body}", skip_mention_notifications: true)
end
end