28ed744d0c
to encompass behavior related to auto-closing and auto-reconsidering. Note that putting this code in a single place reveals an asymmetry between the actions: - Auto-closing period is an optional attribute of a collection - Auto-reconsidering period is hard-coded to 30 days for all collections
42 lines
725 B
Ruby
42 lines
725 B
Ruby
module Card::Closeable
|
|
extend ActiveSupport::Concern
|
|
|
|
included do
|
|
has_one :closure, dependent: :destroy
|
|
|
|
scope :closed, -> { joins(:closure) }
|
|
scope :open, -> { where.missing(:closure) }
|
|
|
|
scope :recently_closed_first, -> { closed.order("closures.created_at": :desc) }
|
|
end
|
|
|
|
def closed?
|
|
closure.present?
|
|
end
|
|
|
|
def open?
|
|
!closed?
|
|
end
|
|
|
|
def closed_by
|
|
closure&.user
|
|
end
|
|
|
|
def closed_at
|
|
closure&.created_at
|
|
end
|
|
|
|
def close(user: Current.user, reason: Closure::Reason.default)
|
|
unless closed?
|
|
transaction do
|
|
create_closure! user: user, reason: reason
|
|
track_event :closed, creator: user
|
|
end
|
|
end
|
|
end
|
|
|
|
def reopen
|
|
closure&.destroy
|
|
end
|
|
end
|