Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GO-124 Fix removing SignatureRequested Tag from MessageThread #466

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/models/message_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions db/migrate/20240820143244_remove_extra_signature_tags.rb
Original file line number Diff line number Diff line change
@@ -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
3 changes: 1 addition & 2 deletions db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 14 additions & 3 deletions test/models/message_object_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)

Expand Down
Loading