Need to do this in one transaction

This commit is contained in:
Jason Zimdars
2025-05-29 23:25:29 -05:00
parent c1cc1f8fca
commit ac53f9ee21
2 changed files with 14 additions and 14 deletions
+14 -2
View File
@@ -12,7 +12,7 @@ class Card < ApplicationRecord
has_rich_text :description
before_save :set_default_title, if: :published?
after_save :grant_access_to_assignees, if: :saved_change_to_collection_id?
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 }
@@ -41,8 +41,20 @@ class Card < ApplicationRecord
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
return if collection.all_access?
collection.accesses.grant_to(assignees)
end
end
-12
View File
@@ -7,7 +7,6 @@ module Card::Eventable
before_create { self.last_active_at = Time.current }
after_save :track_title_change, if: :saved_change_to_title?
after_save :track_collection_change, if: :saved_change_to_collection_id?
end
def event_was_created(event)
@@ -28,17 +27,6 @@ module Card::Eventable
end
end
def track_collection_change
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
end
def create_system_comment_for(event)
SystemCommenter.new(self, event).comment
end