From 3510ebb641093fb38e7d42ef42f403ff7ed97643 Mon Sep 17 00:00:00 2001 From: luciajanikova <19lucia99@gmail.com> Date: Tue, 20 Aug 2024 15:04:05 +0200 Subject: [PATCH 1/2] Fix removing SignatureRequested Tag from MessageThread --- app/models/message_object.rb | 1 + test/models/message_object_test.rb | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/app/models/message_object.rb b/app/models/message_object.rb index 6be2c1eca..08579fd15 100644 --- a/app/models/message_object.rb +++ b/app/models/message_object.rb @@ -157,6 +157,7 @@ def remove_object_related_tags_from_thread end message.thread.unassign_tag(message.tenant.signed_tag!) unless message.thread.tags.reload.where(type: SignedByTag.to_s).any? + message.thread.unassign_tag(message.tenant.signature_requested_tag!) unless message.thread.tags.reload.where(type: SignatureRequestedFromTag.to_s).any? end def other_thread_objects_include_tag?(tag) diff --git a/test/models/message_object_test.rb b/test/models/message_object_test.rb index c150d9d80..7d0f4c043 100644 --- a/test/models/message_object_test.rb +++ b/test/models/message_object_test.rb @@ -188,7 +188,7 @@ class MessageObjectTest < ActiveSupport::TestCase object_1.message.thread.tags.signing_tags.reload.to_set end - test "before_destroy callback deletes object related tags from message thread after object removal (if no more objects with the tag present)" do + test "before_destroy callback deletes object related tags from message thread (if no more objects with the tag present)" do tenant = tenants(:ssd) signer = users(:basic_two) signed_by_tag = tags(:ssd_basic_user_signed) @@ -206,7 +206,7 @@ class MessageObjectTest < ActiveSupport::TestCase assert_not object.message.thread.tags.include?(tenant.signed_tag!) end - test "before_destroy callback keeps object related tags for message thread after object removal (if another objects with the tag present in the message)" do + test "before_destroy callback keeps object related tags for message thread (if another objects with the tag present in the message)" do tenant = tenants(:ssd) signer = users(:basic_two) signed_by_tag = tags(:ssd_basic_user_signed) @@ -230,7 +230,7 @@ class MessageObjectTest < ActiveSupport::TestCase assert attachment_object.message.thread.tags.include?(tenant.signed_tag!) end - test "before_destroy callback keeps object related tags for message thread after object removal (if objects with the tag present in another message in the thread)" do + test "before_destroy callback keeps object related tags for message thread (if objects with the tag present in another message in the thread)" do tenant = tenants(:ssd) signer = users(:basic_two) signed_by_tag = tags(:ssd_basic_user_signed) @@ -254,6 +254,17 @@ class MessageObjectTest < ActiveSupport::TestCase assert attachment_object.message.thread.tags.include?(tenant.signed_tag!) end + test "before_destroy callback deletes SignatureRequested tag from message thread (if no more objects with requested signature present in the thread)" do + signature_requested_tag = tags(:ssd_signature_requested) + form_object = message_objects(:ssd_main_draft_to_be_signed4_draft_form) + + assert form_object.message.thread.tags.include?(signature_requested_tag) + + form_object.destroy + + assert_not form_object.message.thread.tags.reload.include?(signature_requested_tag) + end + test "prepares PDF visualization" do message_object = message_objects(:ssd_main_fs_one_form) From c07e647d0b63e2a1d0f31c79cf05fa4163887e30 Mon Sep 17 00:00:00 2001 From: luciajanikova <19lucia99@gmail.com> Date: Tue, 20 Aug 2024 16:47:38 +0200 Subject: [PATCH 2/2] Update existing threads --- db/migrate/20240820143244_remove_extra_signature_tags.rb | 8 ++++++++ db/schema.rb | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20240820143244_remove_extra_signature_tags.rb diff --git a/db/migrate/20240820143244_remove_extra_signature_tags.rb b/db/migrate/20240820143244_remove_extra_signature_tags.rb new file mode 100644 index 000000000..0928d4e99 --- /dev/null +++ b/db/migrate/20240820143244_remove_extra_signature_tags.rb @@ -0,0 +1,8 @@ +class RemoveExtraSignatureTags < ActiveRecord::Migration[7.1] + def up + MessageThread.find_each do |message_thread| + message_thread.unassign_tag(message_thread.tenant.signature_requested_tag!) unless message_thread.tags.reload.where(type: SignatureRequestedFromTag.to_s).any? + message_thread.unassign_tag(message_thread.tenant.signed_tag!) unless message_thread.tags.reload.where(type: SignedByTag.to_s).any? + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 0dfaee20d..b22c56b6d 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.1].define(version: 2024_07_18_084836) do +ActiveRecord::Schema[7.1].define(version: 2024_08_20_143244) do # These are extensions that must be enabled in order to support this database enable_extension "pgcrypto" enable_extension "plpgsql"