Files
fizzy/app/models/bubble/statuses.rb
T
Kevin McConnell 55464f39a2 Don't duplicate notifications on publish
We're already sending everyone the "published" notification, and for
assignees that will include the assignment message. Tracking the event
again here would just duplicate that.
2025-02-27 16:37:53 +00:00

38 lines
915 B
Ruby

module Bubble::Statuses
extend ActiveSupport::Concern
included do
enum :status, %w[ creating drafted published ].index_by(&:itself)
scope :published_or_drafted_by, ->(user) { where(status: :published).or(where(status: :drafted, creator: user)) }
end
class_methods do
def remove_abandoned_creations
Bubble.creating.where(updated_at: ..1.day.ago).destroy_all
end
end
def can_recover_abandoned_creation?
abandoned_creations.where(updated_at: 1.day.ago..).any?
end
def recover_abandoned_creation
abandoned_creations.last.tap do |bubble|
Bubble.creating.where(creator: creator).excluding(bubble).destroy_all
end
end
def publish
transaction do
published!
track_event :published
end
end
private
def abandoned_creations
Bubble.creating.where(creator: creator).where("created_at != updated_at").excluding(self)
end
end