From ac53f9ee2197e99bcd047185348f410420589119 Mon Sep 17 00:00:00 2001 From: Jason Zimdars Date: Thu, 29 May 2025 23:25:29 -0500 Subject: [PATCH] Need to do this in one transaction --- app/models/card.rb | 16 ++++++++++++++-- app/models/card/eventable.rb | 12 ------------ 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/app/models/card.rb b/app/models/card.rb index 744e8744c..74818320e 100644 --- a/app/models/card.rb +++ b/app/models/card.rb @@ -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 diff --git a/app/models/card/eventable.rb b/app/models/card/eventable.rb index 4ab8821d4..b9815fd93 100644 --- a/app/models/card/eventable.rb +++ b/app/models/card/eventable.rb @@ -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