From 6a97f21db254b0fa1f38072ad75e47302aac049e Mon Sep 17 00:00:00 2001 From: luciajanikova <19lucia99@gmail.com> Date: Tue, 12 Nov 2024 17:32:00 +0100 Subject: [PATCH] Update download message object event --- .../rules/rule_header_form_component.rb | 2 +- app/controllers/message_objects_controller.rb | 4 ++-- app/lib/event_bus.rb | 2 +- app/models/automation/condition.rb | 18 ++++++++++++++++-- app/models/message_object.rb | 14 ++++++++++---- config/locales/sk.yml | 4 +++- 6 files changed, 33 insertions(+), 11 deletions(-) diff --git a/app/components/settings/rules/rule_header_form_component.rb b/app/components/settings/rules/rule_header_form_component.rb index db40add0..1939b39e 100644 --- a/app/components/settings/rules/rule_header_form_component.rb +++ b/app/components/settings/rules/rule_header_form_component.rb @@ -6,7 +6,7 @@ def before_render @trigger_events_list = [ [t('message_created'), 'message_created'], [t('message_draft_submitted'), 'message_draft_submitted'], - [t('form_object_downloaded'), 'form_object_downloaded'], + [t('message_object_downloaded'), 'message_object_downloaded'], ] end end diff --git a/app/controllers/message_objects_controller.rb b/app/controllers/message_objects_controller.rb index fd78aa9b..89b0014e 100644 --- a/app/controllers/message_objects_controller.rb +++ b/app/controllers/message_objects_controller.rb @@ -27,7 +27,7 @@ def show def download authorize @message_object - EventBus.publish(:form_object_downloaded, @message_object.message) if @message_object.form? + EventBus.publish(:message_object_downloaded, @message_object) send_data @message_object.content, filename: MessageObjectHelper.displayable_name(@message_object), type: @message_object.mimetype, disposition: :download end @@ -37,7 +37,7 @@ def download_pdf pdf_content = @message_object.prepare_pdf_visualization if pdf_content - EventBus.publish(:form_object_downloaded, @message_object.message) if @message_object.form? + EventBus.publish(:message_object_downloaded, @message_object) send_data pdf_content, filename: MessageObjectHelper.pdf_name(@message_object), type: 'application/pdf', disposition: :download else diff --git a/app/lib/event_bus.rb b/app/lib/event_bus.rb index c5e52632..367663ed 100644 --- a/app/lib/event_bus.rb +++ b/app/lib/event_bus.rb @@ -28,7 +28,7 @@ def self.reset! # wiring # automation -[:message_thread_created, :message_created, :message_draft_submitted, :form_object_downloaded].each do |event| +[:message_thread_created, :message_created, :message_draft_submitted, :message_object_downloaded].each do |event| EventBus.subscribe_job event, Automation::ApplyRulesForEventJob end diff --git a/app/models/automation/condition.rb b/app/models/automation/condition.rb index 1bb91be2..1d3a85ff 100644 --- a/app/models/automation/condition.rb +++ b/app/models/automation/condition.rb @@ -21,7 +21,7 @@ class Condition < ApplicationRecord attr_accessor :delete_record # when adding items, check defaults in condition_form_component.rb - ATTR_LIST = %i[box sender_name recipient_name title sender_uri recipient_uri attachment fs_submission_status fs_message_type].freeze + ATTR_LIST = %i[box sender_name recipient_name title sender_uri recipient_uri attachment fs_submission_status fs_message_type object_type].freeze def valid_condition_type_list_for_attr Automation::Condition.subclasses.map do |subclass| @@ -36,7 +36,7 @@ def box_list class ContainsCondition < Automation::Condition validates :value, presence: true - VALID_ATTR_LIST = %w[sender_name recipient_name title].freeze + VALID_ATTR_LIST = %w[sender_name recipient_name title object_type].freeze validates :attr, inclusion: { in: VALID_ATTR_LIST } def satisfied?(thing) @@ -81,6 +81,20 @@ def cleanup_record end end + class MessageMetadataValueCondition < Automation::Condition + validates :value, presence: true + VALID_ATTR_LIST = %w[fs_message_type].freeze + validates :attr, inclusion: { in: VALID_ATTR_LIST } + + def satisfied?(thing) + thing.message.metadata && thing.message.metadata[attr]&.match?(value) + end + + def cleanup_record + self.condition_object = nil + end + end + class AttachmentContentContainsCondition < Automation::Condition validates :value, presence: true VALID_ATTR_LIST = ['attachment'].freeze diff --git a/app/models/message_object.rb b/app/models/message_object.rb index 30215df7..1b045260 100644 --- a/app/models/message_object.rb +++ b/app/models/message_object.rb @@ -23,6 +23,8 @@ class MessageObject < ApplicationRecord has_many :tags, through: :message_objects_tags has_one :archived_object, dependent: :destroy + delegate :tenant, to: :message + scope :unsigned, -> { where(is_signed: false) } validates :name, presence: { message: "Name can't be blank" }, on: :validate_data @@ -85,6 +87,10 @@ def remove_signature_requested_from_group(group) thread.remove_signature_requested_from_group(group) end + def automation_rules_for_event(event) + tenant.automation_rules.where(trigger_event: event) + end + def content message_object_datum&.blob end @@ -136,6 +142,10 @@ def xml? Utils::XML_MIMETYPES.any? { |xml_mimetype| xml_mimetype == Utils.mimetype_without_optional_params(mimetype) } end + def thread + message.thread + end + private def allowed_mimetype? @@ -154,10 +164,6 @@ def unassign_tag(tag) message_objects_tags.find_by(tag: tag)&.destroy end - def thread - message.thread - end - def remove_object_related_tags_from_thread tags.each do |tag| thread.unassign_tag(tag) unless other_thread_objects_include_tag?(tag) diff --git a/config/locales/sk.yml b/config/locales/sk.yml index 8e859638..2a55fd23 100644 --- a/config/locales/sk.yml +++ b/config/locales/sk.yml @@ -262,6 +262,7 @@ sk: recipient_name: "Prijímateľ" sender_uri: "URI odosielateľa" recipient_uri: "URI prijímateľa" + object_type: "Typ objektu" fs_submission_status: "Stav podania" fs_message_type: "Typ správy" box: "Schránka správy" @@ -273,10 +274,11 @@ sk: message_updated: "Upravená správa" message_thread_changed: "Zmena vo vlákne správ" message_draft_submitted: "Odoslaná správa" - form_object_downloaded: "Stiahnutá správa" + message_object_downloaded: "Stiahnutý objekt správy" "Automation::ContainsCondition": "obsahuje" "Automation::AttachmentContentContainsCondition": "obsahuje" "Automation::MetadataValueCondition": "v metadátach obsahuje" + "Automation::MessageMetadataValueCondition": "správa v metadátach obsahuje" "Automation::BoxCondition": "je" "Automation::AddMessageThreadTagAction": "Pridaj štítok na vlákno" "Automation::AddTagAction": "Pridaj štítok"