Skip to content

Commit

Permalink
Update download message object event
Browse files Browse the repository at this point in the history
  • Loading branch information
luciajanikova committed Nov 12, 2024
1 parent 16dc11c commit 6a97f21
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions app/controllers/message_objects_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/lib/event_bus.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
18 changes: 16 additions & 2 deletions app/models/automation/condition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down
14 changes: 10 additions & 4 deletions app/models/message_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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?
Expand All @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion config/locales/sk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down

0 comments on commit 6a97f21

Please sign in to comment.