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-83 Save templates MessageDraft content to HTML visualization in order to be searchable #479

Merged
merged 3 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 4 additions & 0 deletions app/helpers/message_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions app/models/message_draft.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class MessageDraft < Message

def update_content(parameters)
metadata["data"] = parameters.to_h
self.html_visualization = format_html_visualization
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Toto mi pride podozrive. preco sa to nedeje v tom build_message_from_template?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pravda, nebolo to tuto spravne, presunula som.

save!

template.build_message_from_template(self)
Expand Down
4 changes: 4 additions & 0 deletions test/fixtures/message_object_data.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ draft_two:
message_object: ssd_main_general_draft_two_form
blob: <GeneralAgenda xmlns="http://schemas.gov.sk/form/App.GeneralAgenda/1.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><subject>predmet</subject><text>text</text></GeneralAgenda>

empty_draft:
message_object: ssd_main_empty_draft_form
blob: <GeneralAgenda xmlns="http://schemas.gov.sk/form/App.GeneralAgenda/1.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><subject></subject><text></text></GeneralAgenda>

fs_one:
message_object: ssd_main_fs_one_form
blob: <n0:ElectronicOfficialDocument xmlns:n0="http://schemas.gov.sk/form/42499500.FS_EUD_v1_0.sk/1.6"> <n0:Sender> <n0:PersonData> <n0:CorporateBody> <n0:FinancialAdministrationAuthority>Daňový úrad Bratislava</n0:FinancialAdministrationAuthority> </n0:CorporateBody> <n0:PhysicalAddress> <n0:AddressLine>Ševčenkova 32, 850 00 Bratislava</n0:AddressLine> </n0:PhysicalAddress> </n0:PersonData> </n0:Sender> <n0:Document> <n0:DocumentReference>000000000/2022</n0:DocumentReference> <n0:ContactPerson>Mgr. X Y</n0:ContactPerson> <n0:PhoneNumber>02/00000000</n0:PhoneNumber> <n0:EmailAddress>[email protected]</n0:EmailAddress> <n0:IssuePlace>Bratislava</n0:IssuePlace> <n0:IssueDate>2022-04-19</n0:IssueDate> <n0:Subject>Rozhodnutie</n0:Subject> </n0:Document></n0:ElectronicOfficialDocument>
6 changes: 6 additions & 0 deletions test/fixtures/message_objects.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 7 additions & 0 deletions test/fixtures/message_threads.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions test/fixtures/message_threads_tags.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
14 changes: 14 additions & 0 deletions test/fixtures/messages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions test/fixtures/tag_groups.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/tags.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/upvs/message_templates.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ message_reply:
type: Upvs::MessageTemplate

general_agenda:
id: 2
content: <GeneralAgenda xmlns="http://schemas.gov.sk/form/App.GeneralAgenda/1.9">
<subject>{{ Predmet:text_field }}</subject>
<text>{{ Text:text_area }}</text>
Expand Down
53 changes: 53 additions & 0 deletions test/system/message_drafts_test.rb
Original file line number Diff line number Diff line change
@@ -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
Loading