From 4f48540ea652a39bc45c4fa3a7bf882a66634121 Mon Sep 17 00:00:00 2001 From: luciajanikova <19lucia99@gmail.com> Date: Wed, 2 Oct 2024 11:42:11 +0200 Subject: [PATCH 1/3] Save templates MessageDraft content to HTML visualization in order to be searchable --- app/helpers/message_helper.rb | 4 ++ app/models/message_draft.rb | 1 + test/fixtures/message_object_data.yml | 4 ++ test/fixtures/message_objects.yml | 6 +++ test/fixtures/message_threads.yml | 7 ++++ test/fixtures/message_threads_tags.yml | 4 ++ test/fixtures/messages.yml | 14 +++++++ test/fixtures/tag_groups.yml | 4 ++ test/fixtures/tags.yml | 2 +- test/fixtures/upvs/message_templates.yml | 1 + test/system/message_drafts_test.rb | 53 ++++++++++++++++++++++++ 11 files changed, 99 insertions(+), 1 deletion(-) diff --git a/app/helpers/message_helper.rb b/app/helpers/message_helper.rb index 22e028694..ecd440771 100644 --- a/app/helpers/message_helper.rb +++ b/app/helpers/message_helper.rb @@ -6,6 +6,10 @@ def self.export_filename(message) def format_html_visualization return ActionController::Base.helpers.simple_format(html_visualization) if is_a?(Fs::MessageDraft) + return metadata["data"].map do |k,v| + "#{k}: #{v}" + end.join(', ') if template.present? + html_visualization end end diff --git a/app/models/message_draft.rb b/app/models/message_draft.rb index 5dbd4839d..2dc4c11a9 100644 --- a/app/models/message_draft.rb +++ b/app/models/message_draft.rb @@ -70,6 +70,7 @@ class MessageDraft < Message def update_content(parameters) metadata["data"] = parameters.to_h + self.html_visualization = format_html_visualization save! template.build_message_from_template(self) diff --git a/test/fixtures/message_object_data.yml b/test/fixtures/message_object_data.yml index 3df899c3f..b01660fca 100644 --- a/test/fixtures/message_object_data.yml +++ b/test/fixtures/message_object_data.yml @@ -12,6 +12,10 @@ draft_two: message_object: ssd_main_general_draft_two_form blob: predmettext +empty_draft: + message_object: ssd_main_empty_draft_form + blob: + fs_one: message_object: ssd_main_fs_one_form blob: Daňový úrad Bratislava Ševčenkova 32, 850 00 Bratislava 000000000/2022 Mgr. X Y 02/00000000 x.y@FINANCNASPRAVA.SK Bratislava 2022-04-19 Rozhodnutie diff --git a/test/fixtures/message_objects.yml b/test/fixtures/message_objects.yml index cbf70b78b..4358c11f6 100644 --- a/test/fixtures/message_objects.yml +++ b/test/fixtures/message_objects.yml @@ -108,3 +108,9 @@ ssd_main_draft_to_be_signed4_draft_form: name: MyString mimetype: MyString object_type: FORM + +ssd_main_empty_draft_form: + message: ssd_main_empty_draft + name: MyString + mimetype: MyString + object_type: FORM diff --git a/test/fixtures/message_threads.yml b/test/fixtures/message_threads.yml index a4ca141fb..4cc60e30a 100644 --- a/test/fixtures/message_threads.yml +++ b/test/fixtures/message_threads.yml @@ -63,6 +63,13 @@ ssd_main_draft_to_be_signed4: delivered_at: 2023-05-18 18:15:22 last_message_delivered_at: 2023-05-18 18:16:22 +ssd_main_empty_draft: + box: ssd_main + title: Empty Draft + original_title: MyString + delivered_at: 2023-05-18 16:05:00 + last_message_delivered_at: 2023-05-18 16:05:00 + solver_main_general_agenda: box: solver_main title: General agenda Solver diff --git a/test/fixtures/message_threads_tags.yml b/test/fixtures/message_threads_tags.yml index 9fbd1ee40..2110dbcc1 100644 --- a/test/fixtures/message_threads_tags.yml +++ b/test/fixtures/message_threads_tags.yml @@ -127,3 +127,7 @@ ssd_main_draft_to_be_signed4_ssd_signature_requested: ssd_main_draft_to_be_signed4_ssd_signers_signature_requested: message_thread: ssd_main_draft_to_be_signed4 tag: ssd_signers_signature_requested + +ssd_main_empty_draft_ssd_basic_user_drafts: + message_thread: ssd_main_empty_draft + tag: ssd_basic_user_drafts diff --git a/test/fixtures/messages.yml b/test/fixtures/messages.yml index b5f2b3df5..1c2dce92d 100644 --- a/test/fixtures/messages.yml +++ b/test/fixtures/messages.yml @@ -263,6 +263,20 @@ ssd_main_draft_to_be_signed4_draft: status: created author: basic +ssd_main_empty_draft: + type: Upvs::MessageDraft + uuid: <%= SecureRandom.uuid %> + title: Všeobecná agenda + delivered_at: 2023-05-18 16:05:00 + thread: ssd_main_empty_draft + replyable: false + metadata: + status: created + template_id: 2 + recipient_uri: ico://sk/83369723 + correlation_id: <%= SecureRandom.uuid %> + author: basic + solver_main_delivery_notification_one: uuid: bbff2617-3430-44c6-b827-519059ff1e90 title: Authorized Delivery notification diff --git a/test/fixtures/tag_groups.yml b/test/fixtures/tag_groups.yml index 2b00667b4..856268e80 100644 --- a/test/fixtures/tag_groups.yml +++ b/test/fixtures/tag_groups.yml @@ -1,5 +1,9 @@ # Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html +drafts_basic_user: + tag: ssd_basic_user_drafts + group: ssd_basic_user + finance_basic_user: tag: ssd_finance group: ssd_basic_user diff --git a/test/fixtures/tags.yml b/test/fixtures/tags.yml index 87330fdab..b8c4d4775 100644 --- a/test/fixtures/tags.yml +++ b/test/fixtures/tags.yml @@ -175,7 +175,7 @@ solver_everything: visible: false tenant: solver -solver_basic_user_drafts: +ssd_basic_user_drafts: name: Drafts-Basic user owner: basic type: DraftTag diff --git a/test/fixtures/upvs/message_templates.yml b/test/fixtures/upvs/message_templates.yml index 45a846bda..dbea37d6b 100644 --- a/test/fixtures/upvs/message_templates.yml +++ b/test/fixtures/upvs/message_templates.yml @@ -14,6 +14,7 @@ message_reply: type: Upvs::MessageTemplate general_agenda: + id: 2 content: {{ Predmet:text_field }} {{ Text:text_area }} diff --git a/test/system/message_drafts_test.rb b/test/system/message_drafts_test.rb index f31c31120..c29b01a07 100644 --- a/test/system/message_drafts_test.rb +++ b/test/system/message_drafts_test.rb @@ -1,6 +1,59 @@ require "application_system_test_case" class MessageDraftsTest < ApplicationSystemTestCase + setup do + Searchable::MessageThread.reindex_all + + silence_warnings do + @old_value = MessageThreadCollection.const_get("PER_PAGE") + MessageThreadCollection.const_set("PER_PAGE", 1) + end + + sign_in_as(:basic) + end + + teardown do + silence_warnings do + MessageThreadCollection.const_set("PER_PAGE", @old_value) + end + end + test "user can create message draft as reply on replyable message" do end + + test "templated message draft content is searchable" do + message = messages(:ssd_main_empty_draft) + thread = message_threads(:ssd_main_empty_draft) + + visit message_thread_path thread + + within "#body_upvs_message_draft_#{message.id}_form" do + fill_in "message_draft_Text", with: "Pozdrav zo Slovensko.Digital! :)" + fill_in "message_draft_Predmet", with: "Pozdravovacia sprava" + end + + assert_text "Zmeny boli uložené" + + GoodJob.perform_inline + + # Search the draft content keywords + visit message_threads_path + + assert_no_selector "#next_page_area" + + fill_in "search", with: "Slovensko.Digital" + find("#search").send_keys(:enter) + + assert_no_selector "#next_page_area" + + thread_general = message_threads(:ssd_main_general) + thread_issue = message_threads(:ssd_main_issue) + + within_thread_in_listing(thread) do + assert_text "Slovensko.Digital" + end + + refute_selector(thread_in_listing_selector(thread_general)) + refute_selector(thread_in_listing_selector(thread_issue)) + end end From 1a691016db7f4495d867dc386f42dd3eaa85fac1 Mon Sep 17 00:00:00 2001 From: luciajanikova <19lucia99@gmail.com> Date: Tue, 15 Oct 2024 16:53:04 +0200 Subject: [PATCH 2/3] Move saving html_visualization to MessageTemplate --- app/helpers/message_helper.rb | 4 ---- app/models/message_draft.rb | 1 - app/models/upvs/message_template.rb | 6 ++++++ 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/app/helpers/message_helper.rb b/app/helpers/message_helper.rb index ecd440771..22e028694 100644 --- a/app/helpers/message_helper.rb +++ b/app/helpers/message_helper.rb @@ -6,10 +6,6 @@ def self.export_filename(message) def format_html_visualization return ActionController::Base.helpers.simple_format(html_visualization) if is_a?(Fs::MessageDraft) - return metadata["data"].map do |k,v| - "#{k}: #{v}" - end.join(', ') if template.present? - html_visualization end end diff --git a/app/models/message_draft.rb b/app/models/message_draft.rb index 2dc4c11a9..5dbd4839d 100644 --- a/app/models/message_draft.rb +++ b/app/models/message_draft.rb @@ -70,7 +70,6 @@ class MessageDraft < Message def update_content(parameters) metadata["data"] = parameters.to_h - self.html_visualization = format_html_visualization save! template.build_message_from_template(self) diff --git a/app/models/upvs/message_template.rb b/app/models/upvs/message_template.rb index d9a884e5f..b8695ad8c 100644 --- a/app/models/upvs/message_template.rb +++ b/app/models/upvs/message_template.rb @@ -106,6 +106,12 @@ def build_message_from_template(message) filled_content.gsub!(template_item[:placeholder], message.metadata['data'][template_item[:name]].to_s) end + message.update( + html_visualization: message.metadata["data"]&.map do |k,v| + "#{k}: #{v}" + end&.join(', ') + ) + if message.form_object.message_object_datum message.form_object.message_object_datum.update( blob: filled_content From 8dfb31cbc87c2858e852420ba84e9fc7684907ae Mon Sep 17 00:00:00 2001 From: luciajanikova <19lucia99@gmail.com> Date: Wed, 16 Oct 2024 08:33:26 +0200 Subject: [PATCH 3/3] Small update --- app/models/upvs/message_template.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/app/models/upvs/message_template.rb b/app/models/upvs/message_template.rb index b8695ad8c..6abeaef4a 100644 --- a/app/models/upvs/message_template.rb +++ b/app/models/upvs/message_template.rb @@ -107,10 +107,8 @@ def build_message_from_template(message) end message.update( - html_visualization: message.metadata["data"]&.map do |k,v| - "#{k}: #{v}" - end&.join(', ') - ) + html_visualization: message.metadata["data"].map { _1.join(": ") }.join(", ") + ) if message.metadata["data"] if message.form_object.message_object_datum message.form_object.message_object_datum.update(