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-181 Create InboxTag in order to filter only delivered significant messages #546

Merged
merged 4 commits into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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
11 changes: 11 additions & 0 deletions app/jobs/add_inbox_tag_to_thread_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class AddInboxTagToThreadJob < ApplicationJob
def perform(message_thread)
message_thread.assign_tag(message_thread.tenant.inbox_tag) if message_thread.messages.any?{ |message| significant_inbox_message?(message) }
end

private

def significant_inbox_message?(message)
!message.outbox? && !Govbox::Message::INSIGNIFICANT_MESSAGE_CLASSES.include?(message.metadata.dig('edesk_class'))
jsuchal marked this conversation as resolved.
Show resolved Hide resolved
end
end
5 changes: 5 additions & 0 deletions app/jobs/add_inbox_tag_to_threads_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddInboxTagToThreadsJob < ApplicationJob
def perform
MessageThread.find_each { |message_thread| AddInboxTagToThreadJob.perform_later(message_thread) }
end
end
Comment on lines +1 to +5
Copy link
Member Author

Choose a reason for hiding this comment

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

Tento job, aj ten dalsi, ktory sa scheduluje v tomto jobe su iba docasne, aby sme mali ako vykonat hromadne update na uz existujucich vlaknach (kedze v migracii by to cele nezbehlo). Potom zmazeme.

14 changes: 12 additions & 2 deletions app/models/govbox/message.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Govbox::Message < ApplicationRecord

EGOV_DOCUMENT_CLASS = 'EGOV_DOCUMENT'
EGOV_NOTIFICATION_CLASS = 'EGOV_NOTIFICATION'
COLLAPSED_BY_DEFAULT_MESSAGE_CLASSES = ['ED_DELIVERY_REPORT', 'POSTING_CONFIRMATION', 'POSTING_INFORMATION']
INSIGNIFICANT_MESSAGE_CLASSES = ['ED_DELIVERY_REPORT', 'POSTING_CONFIRMATION', 'POSTING_INFORMATION']
GENERAL_AGENDA_SCHEMA = 'http://schemas.gov.sk/form/App.GeneralAgenda/1.9'

DELIVERY_NOTIFICATION_TAG = 'delivery_notification'
Expand All @@ -39,6 +39,7 @@ def self.create_message_with_thread!(govbox_message)
title: message.metadata.dig("delivery_notification", "consignment", "subject").presence || message.title,
delivered_at: govbox_message.delivered_at
)
message.thread.assign_tag(message.thread.tenant.inbox_tag) if !message.outbox? && !govbox_message.insignificant?

message.save!

Expand Down Expand Up @@ -66,7 +67,15 @@ def replyable?
end

def collapsed?
payload["class"].in?(COLLAPSED_BY_DEFAULT_MESSAGE_CLASSES)
insignificant?
end

def read?
folder.outbox? || insignificant?
end

def insignificant?
payload["class"].in?(INSIGNIFICANT_MESSAGE_CLASSES)
end

def delivery_notification
Expand Down Expand Up @@ -97,6 +106,7 @@ def self.create_message(govbox_message)
replyable: govbox_message.replyable?,
collapsed: govbox_message.collapsed?,
outbox: govbox_message.folder.outbox?,
read: govbox_message.read?,
metadata: {
"correlation_id": govbox_message.payload["correlation_id"],
"reference_id": govbox_message.payload["reference_id"],
Expand Down
22 changes: 22 additions & 0 deletions app/models/inbox_tag.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# == Schema Information
#
# Table name: tags
#
# id :bigint not null, primary key
# color :enum
# external_name :string
# icon :string
# name :string not null
# tag_groups_count :integer default(0), not null
# type :string not null
# visible :boolean default(TRUE), not null
# created_at :datetime not null
# updated_at :datetime not null
# owner_id :bigint
# tenant_id :bigint not null
#
class InboxTag < Tag
def destroyable?
false
end
end
2 changes: 2 additions & 0 deletions app/models/tenant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class Tenant < ApplicationRecord

has_one :draft_tag, -> { where(owner_id: nil) }
has_one :everything_tag
has_one :inbox_tag
has_one :signature_requested_tag
has_one :signed_tag
has_one :signed_externally_tag
Expand Down Expand Up @@ -117,6 +118,7 @@ def create_default_objects

create_draft_tag!(name: "Rozpracované", visible: true)
create_everything_tag!(name: "Všetky správy", visible: false)
create_inbox_tag!(name: "Doručené", visible: false)
create_archived_tag!(name: "Archivované", color: "green", icon: "archive-box", visible: true)
create_signature_requested_tag!(name: "Na podpis", visible: true, color: "yellow", icon: "pencil")
create_signed_tag!(name: "Podpísané", visible: true, color: "green", icon: "fingerprint")
Expand Down
12 changes: 12 additions & 0 deletions db/migrate/20250204074342_create_inbox_tag.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class CreateInboxTag < ActiveRecord::Migration[7.1]
def up
Tenant.find_each do |tenant|
tenant.create_inbox_tag!(name: "Doručené", visible: false) unless tenant.inbox_tag
AddInboxTagToThreadsJob.set(job_context: :later).perform_later
end
end

def down
# noop
end
end
2 changes: 1 addition & 1 deletion db/schema.rb

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

94 changes: 93 additions & 1 deletion test/fixtures/govbox/messages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ ssd_done_new:
class: FORM
content: Dummy

ssd_posting_confirmation:
ssd_main_done_posting_confirmation:
message_id: <%= SecureRandom.uuid %>
correlation_id: d2d6ab13-347e-49f4-9c3b-0b8390430870
edesk_message_id: 102
Expand All @@ -345,3 +345,95 @@ ssd_posting_confirmation:
signed: false
class: FORM
content: Dummy

ssd_egov_application:
message_id: <%= SecureRandom.uuid %>
correlation_id: f932fd8b-c996-4eb8-ba6c-af7714ef4069
edesk_message_id: 103
delivered_at: <%= DateTime.current %>
edesk_class: EGOV_APPLICATION
folder: ssd_sent
payload:
message_id: <%= SecureRandom.uuid %>
subject: MySubject
sender_name: MySender
sender_uri: MySenderURI
recipient_name: MyRecipient
delivered_at: <%= DateTime.current.to_s %>
original_html: MyHtml
class: EGOV_APPLICATION
objects:
- name: form
mime_type: application/x-eform-xml
signed: false
class: FORM
content: Dummy

ssd_posting_confirmation:
message_id: <%= SecureRandom.uuid %>
correlation_id: f932fd8b-c996-4eb8-ba6c-af7714ef4069
edesk_message_id: 104
delivered_at: <%= DateTime.current %>
edesk_class: POSTING_CONFIRMATION
folder: ssd_one
payload:
message_id: <%= SecureRandom.uuid %>
subject: MySubject
sender_name: MySender
sender_uri: MySenderURI
recipient_name: MyRecipient
delivered_at: <%= DateTime.current.to_s %>
original_html: MyHtml
class: POSTING_CONFIRMATION
objects:
- name: form
mime_type: application/x-eform-xml
signed: false
class: FORM
content: Dummy

ssd_delivery_report:
message_id: <%= SecureRandom.uuid %>
correlation_id: f932fd8b-c996-4eb8-ba6c-af7714ef4069
edesk_message_id: 105
delivered_at: <%= DateTime.current %>
edesk_class: ED_DELIVERY_REPORT
folder: ssd_one
payload:
message_id: <%= SecureRandom.uuid %>
subject: MySubject
sender_name: MySender
sender_uri: MySenderURI
recipient_name: MyRecipient
delivered_at: <%= DateTime.current.to_s %>
original_html: MyHtml
class: ED_DELIVERY_REPORT
objects:
- name: form
mime_type: application/x-eform-xml
signed: false
class: FORM
content: Dummy

ssd_egov_document:
message_id: <%= SecureRandom.uuid %>
correlation_id: f932fd8b-c996-4eb8-ba6c-af7714ef4069
edesk_message_id: 106
delivered_at: <%= DateTime.current %>
edesk_class: EGOV_DOCUMENT
folder: ssd_one
payload:
message_id: <%= SecureRandom.uuid %>
subject: MySubject
sender_name: MySender
sender_uri: MySenderURI
recipient_name: MyRecipient
delivered_at: <%= DateTime.current.to_s %>
original_html: MyHtml
class: EGOV_DOCUMENT
objects:
- name: form
mime_type: application/x-eform-xml
signed: false
class: FORM
content: Dummy
18 changes: 18 additions & 0 deletions test/fixtures/tags.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ ssd_everything:
visible: false
tenant: ssd

ssd_inbox:
name: Inbox
type: InboxTag
visible: false
tenant: ssd

ssd_signed_externally:
name: SignedExternally
type: SignedExternallyTag
Expand Down Expand Up @@ -187,6 +193,12 @@ solver_everything:
visible: false
tenant: solver

solver_inbox:
name: Inbox
type: InboxTag
visible: false
tenant: solver

ssd_basic_user_drafts:
name: Drafts-Basic user
owner: basic
Expand Down Expand Up @@ -240,6 +252,12 @@ accountants_everything:
visible: false
tenant: accountants

accountants_inbox:
name: Inbox
type: InboxTag
visible: false
tenant: accountants

accountants_signature_requested:
name: Na podpis
type: SignatureRequestedTag
Expand Down
2 changes: 1 addition & 1 deletion test/models/automation/rule_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class Automation::RuleTest < ActiveSupport::TestCase
test 'should not run an automation on message created outbox BooleanCondition, edesk_class MessageMetadataValueNotCondition UnassignMessageThreadTagAction if POSTING_CONFIRMATION delivered' do
tag = tags(:ssd_done)
message_thread = message_threads(:ssd_main_done)
govbox_message = govbox_messages(:ssd_posting_confirmation)
govbox_message = govbox_messages(:ssd_main_done_posting_confirmation)

govbox_message.update_column(:correlation_id, 'd2d6ab13-347e-49f4-9c3b-0b8390430870')

Expand Down
28 changes: 28 additions & 0 deletions test/models/govbox/message_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,34 @@ class Govbox::MessageTest < ActiveSupport::TestCase
assert_equal message.recipient_name, "SSD main"
end

test "#create_message_with_thread! should handle adding inbox tag to thread" do
Govbox::Message.create_message_with_thread!(govbox_messages(:ssd_egov_application))

message_thread = MessageThread.last

# Inbox tag not added when outbox message processed
assert_not message_thread.tags.include?(tags(:ssd_inbox))

Govbox::Message.create_message_with_thread!(govbox_messages(:ssd_posting_confirmation))
# Inbox tag not added when insignificant inbox message processed
assert_not message_thread.tags.include?(tags(:ssd_inbox))

Govbox::Message.create_message_with_thread!(govbox_messages(:ssd_delivery_report))
# Inbox tag not added when another insignificant inbox message processed
assert_not message_thread.tags.include?(tags(:ssd_inbox))

# Outbox or insignificant messages are automatically marked read
assert message_thread.messages.reload.all?{|m| m.read?}

Govbox::Message.create_message_with_thread!(govbox_messages(:ssd_egov_document))
# Inbox tag is added when significant inbox message processed
assert message_thread.tags.include?(tags(:ssd_inbox))

# Significant inbox messages is marked unread
assert_not message_thread.messages.reload.all?{|m| m.read?}
assert_not message_thread.messages.last.read?
end

test "#create_message_with_thread! should include general agenda subject in message title" do
govbox_message = govbox_messages(:ssd_general_agenda)

Expand Down