Files
fizzy/app/models/card/statuses.rb
T
Jankees van Woezik 477b4d65f2 API: Support created_at for API card and comment creation (#2056)
* Add support to set `created_at`

Discussed in
https://github.com/basecamp/fizzy/pull/1766#issuecomment-3637846074,
this allows users to import cards from another system with entries from
the past. For instance I'm importing all our Github issues (including
the closed onces) to Fizzy.

* Iron out published state tracking

---------

Co-authored-by: Jeremy Daer <jeremy@37signals.com>
2025-12-10 19:57:38 -08:00

29 lines
709 B
Ruby

module Card::Statuses
extend ActiveSupport::Concern
included do
enum :status, %w[ drafted published ].index_by(&:itself)
before_save :mark_if_just_published
after_create -> { track_event :published }, if: :published?
scope :published_or_drafted_by, ->(user) { where(status: :published).or(where(status: :drafted, creator: user)) }
end
attr_accessor :was_just_published
alias_method :was_just_published?, :was_just_published
def publish
transaction do
self.created_at = Time.current
published!
track_event :published
end
end
private
def mark_if_just_published
self.was_just_published = true if published? && status_changed?
end
end