Files
fizzy/app/models/card.rb
T
Jason Zimdars 902a99ca56 Merge branch 'main' into change-collection
* main: (25 commits)
  Add controller to retarget links
  Use more complete regexp
  dep: bundle update
  refactor: Extract a Card::Entropy concern
  Autolink emails and URLs at rendering time
  Remove the "mirror" storage service
  Update production storage to write to the Pure blob store
  Clean up the purestorage config, and add explanatory comments.
  Drop the action_text_markdowns table
  Mount mission control under `/admin/jobs`
  dep: add mission_control-jobs
  Flip the storage mirror to write to Pure as the primary
  Production mirrors Active Storage to `:purestorage`
  Make sure Sentry is configured for the beta env.
  Update lexical
  update lexical
  update lexical
  Create a distinct "beta" environment
  Revert "Patch for cards missing description"
  Add a kamal "ssh" alias
  ...
2025-06-02 09:34:01 -05:00

61 lines
1.7 KiB
Ruby

class Card < ApplicationRecord
include Assignable, Colored, Engageable, Entropy, Eventable,
Golden, Mentions, Pinnable, Closeable, Readable, Searchable,
Staged, Statuses, Taggable, Watchable
belongs_to :collection, touch: true
belongs_to :creator, class_name: "User", default: -> { Current.user }
has_many :comments, dependent: :destroy
has_one_attached :image, dependent: :purge_later
has_rich_text :description
before_save :set_default_title, if: :published?
after_save :handle_collection_change, if: :saved_change_to_collection_id?
scope :reverse_chronologically, -> { order created_at: :desc, id: :desc }
scope :chronologically, -> { order created_at: :asc, id: :asc }
scope :latest, -> { order updated_at: :desc, id: :desc }
scope :indexed_by, ->(index) do
case index
when "newest" then reverse_chronologically
when "oldest" then chronologically
when "latest" then latest
when "stalled" then chronologically
when "closed" then closed
end
end
def cache_key
[ super, collection.name ].compact.join("/")
end
def card
self
end
private
def set_default_title
self.title = "Untitled" if title.blank?
end
def handle_collection_change
transaction do
old_collection = Collection.find_by(id: collection_id_before_last_save)
if old_collection.present?
track_event "collection_changed", particulars: {
old_collection: old_collection.name,
new_collection: collection.name
}
end
grant_access_to_assignees unless collection.all_access?
end
end
def grant_access_to_assignees
collection.accesses.grant_to(assignees)
end
end