diff --git a/app/components/settings/rules/automation_rules_table_row_component.html.erb b/app/components/settings/rules/automation_rules_table_row_component.html.erb index 45abb4ab..e9b9466f 100644 --- a/app/components/settings/rules/automation_rules_table_row_component.html.erb +++ b/app/components/settings/rules/automation_rules_table_row_component.html.erb @@ -9,6 +9,10 @@ <%= t condition.attr %> <%= t condition.type %> <%= condition.condition_object.name %> + <% elsif condition.type == 'Automation::BooleanCondition' %> + <%= t condition.attr %> + <%= t condition.type %> + <%= t condition.value %> <% else %> <%= t condition.attr %> <%= t condition.type %> diff --git a/app/components/settings/rules/condition_form_component.html.erb b/app/components/settings/rules/condition_form_component.html.erb index 45cbe128..fb450526 100644 --- a/app/components/settings/rules/condition_form_component.html.erb +++ b/app/components/settings/rules/condition_form_component.html.erb @@ -6,6 +6,10 @@ <%= @form.select :type, @condition_type_list, {}, class: "mt-2 block rounded-md border-0 py-1.5 pl-3 pr-10 text-gray-400 ring-1 ring-inset ring-gray-400 focus:ring-2 focus:ring-indigo-600 sm:text-sm sm:leading-6", disabled: !@enabled %> <%= @form.select :condition_object_id, @form.object.box_list, {}, class: "mt-2 block rounded-md border-0 py-1.5 pl-3 pr-10 text-gray-400 ring-1 ring-inset ring-gray-400 focus:ring-2 focus:ring-indigo-600 sm:text-sm sm:leading-6", disabled: !@enabled %> <%= @form.hidden_field :condition_object_type, value: 'Box' %> + <% elsif @form.object.attr.in? ['outbox'] %> + <%= @form.select :attr, @attr_list, {}, onchange: "this.form.requestSubmit(this.form.querySelector(\"#rerender\"))", class: "mt-2 block rounded-md border-0 py-1.5 pl-3 pr-10 text-gray-400 ring-1 ring-inset ring-gray-400 focus:ring-2 focus:ring-indigo-600 sm:text-sm sm:leading-6", disabled: !@enabled %> + <%= @form.select :type, @condition_type_list, {}, class: "mt-2 block rounded-md border-0 py-1.5 pl-3 pr-10 text-gray-400 ring-1 ring-inset ring-gray-400 focus:ring-2 focus:ring-indigo-600 sm:text-sm sm:leading-6", disabled: !@enabled %> + <%= @form.select :value, [['áno', true], ['nie', false]], {}, class: "mt-2 block rounded-md border-0 py-1.5 pl-3 pr-10 text-gray-400 ring-1 ring-inset ring-gray-400 focus:ring-2 focus:ring-indigo-600 sm:text-sm sm:leading-6", disabled: !@enabled %> <% else %> <%= @form.select :attr, @attr_list, {}, onchange: "this.form.requestSubmit(this.form.querySelector(\"#rerender\"))", class: "mt-2 block rounded-md border-0 py-1.5 pl-3 pr-10 text-gray-400 ring-1 ring-inset ring-gray-400 focus:ring-2 focus:ring-indigo-600 sm:text-sm sm:leading-6", disabled: !@enabled %> <%= @form.select :type, @condition_type_list, {}, class: "mt-2 block rounded-md border-0 py-1.5 pl-3 pr-10 text-gray-400 ring-1 ring-inset ring-gray-400 focus:ring-2 focus:ring-indigo-600 sm:text-sm sm:leading-6", disabled: !@enabled %> diff --git a/app/components/settings/rules/conditions_form_row_component.html.erb b/app/components/settings/rules/conditions_form_row_component.html.erb index de02aaec..b28a012c 100644 --- a/app/components/settings/rules/conditions_form_row_component.html.erb +++ b/app/components/settings/rules/conditions_form_row_component.html.erb @@ -6,6 +6,10 @@
<%= t @form.object.attr %>
<%= t @form.object.type %>
<%= @form.object&.condition_object&.name %>
+ <% elsif @form.object.attr.in? ['outbox'] %> +<%= t @form.object.attr %>
+<%= t @form.object.type %>
+<%= t @form.object.value %>
<% else %><%= t @form.object.attr %>
<%= t @form.object.type %>
diff --git a/app/models/automation/action.rb b/app/models/automation/action.rb index 37d00df7..c183cd2c 100644 --- a/app/models/automation/action.rb +++ b/app/models/automation/action.rb @@ -17,7 +17,7 @@ class Action < ApplicationRecord belongs_to :action_object, polymorphic: true, optional: true attr_accessor :delete_record - ACTION_LIST = ['Automation::AddMessageThreadTagAction', 'Automation::FireWebhookAction', 'Automation::ChangeMessageThreadTitleAction'].freeze + ACTION_LIST = ['Automation::AddMessageThreadTagAction', 'Automation::UnassignMessageThreadTagAction', 'Automation::FireWebhookAction', 'Automation::ChangeMessageThreadTitleAction'].freeze def tag_list automation_rule.tenant.tags.pluck(:name, :id) @@ -28,6 +28,24 @@ def tag_list class AddTagAction < Action end + class UnassignMessageThreadTagAction < Action + def run!(thing, _event) + tag = action_object + return if thing.tenant != tag.tenant + + object = if thing.respond_to? :thread + thing.thread + else + thing + end + object.unassign_tag(tag) if tag && object.tags.include?(tag) + end + + def object_based? + true + end + end + class AddMessageThreadTagAction < Action def run!(thing, _event) tag = action_object diff --git a/app/models/automation/condition.rb b/app/models/automation/condition.rb index a69fe3cf..e3fb51a0 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 object_type].freeze + ATTR_LIST = %i[box sender_name recipient_name title sender_uri recipient_uri outbox attachment edesk_class fs_submission_status fs_message_type object_type].freeze def valid_condition_type_list_for_attr Automation::Condition.subclasses.map do |subclass| @@ -48,9 +48,23 @@ def cleanup_record end end + class BooleanCondition < Automation::Condition + validates :value, presence: true + VALID_ATTR_LIST = %w[outbox].freeze + validates :attr, inclusion: { in: VALID_ATTR_LIST } + + def satisfied?(thing) + thing[attr] == ActiveRecord::Type::Boolean.new.cast(value) + end + + def cleanup_record + self.condition_object = nil + end + end + class MetadataValueCondition < Automation::Condition validates :value, presence: true - VALID_ATTR_LIST = %w[sender_uri recipient_uri fs_submission_status fs_message_type].freeze + VALID_ATTR_LIST = %w[sender_uri recipient_uri edesk_class fs_submission_status fs_message_type].freeze validates :attr, inclusion: { in: VALID_ATTR_LIST } def satisfied?(thing) @@ -62,6 +76,20 @@ def cleanup_record end end + class MetadataValueNotCondition < Automation::Condition + validates :value, presence: true + VALID_ATTR_LIST = %w[sender_uri recipient_uri edesk_class fs_submission_status fs_message_type].freeze + validates :attr, inclusion: { in: VALID_ATTR_LIST } + + def satisfied?(thing) + thing.metadata && !thing.metadata[attr]&.match?(value) + end + + def cleanup_record + self.condition_object = nil + end + end + class BoxCondition < Automation::Condition validates_associated :condition_object VALID_ATTR_LIST = ['box'].freeze @@ -83,7 +111,7 @@ def cleanup_record class MessageMetadataValueCondition < Automation::Condition validates :value, presence: true - VALID_ATTR_LIST = %w[fs_message_type].freeze + VALID_ATTR_LIST = %w[edesk_class fs_message_type].freeze validates :attr, inclusion: { in: VALID_ATTR_LIST } def satisfied?(thing) diff --git a/app/views/settings/automation_actions/_edit_form_unassign_message_thread_tag_action.turbo_stream.erb b/app/views/settings/automation_actions/_edit_form_unassign_message_thread_tag_action.turbo_stream.erb new file mode 100644 index 00000000..f8a5baf0 --- /dev/null +++ b/app/views/settings/automation_actions/_edit_form_unassign_message_thread_tag_action.turbo_stream.erb @@ -0,0 +1,2 @@ +<%= form.select :action_object_id, form.object.tag_list, {}, class: "mt-2 block rounded-md border-0 py-1.5 pl-3 pr-10 text-gray-400 ring-1 ring-inset ring-gray-400 focus:ring-2 focus:ring-indigo-600 sm:text-sm sm:leading-6", disabled: !enabled %> +<%= form.hidden_field :action_object_type, value: 'Tag' %> diff --git a/config/locales/sk.yml b/config/locales/sk.yml index 8b86a5cb..8c3fb570 100644 --- a/config/locales/sk.yml +++ b/config/locales/sk.yml @@ -1,4 +1,6 @@ sk: + true: "áno" + false: "nie" activerecord: attributes: message: @@ -262,9 +264,11 @@ sk: recipient_name: "Prijímateľ" sender_uri: "URI odosielateľa" recipient_uri: "URI prijímateľa" + outbox: "Odoslaná pošta" object_type: "Typ objektu" fs_submission_status: "Stav podania" - fs_message_type: "Typ správy" + edesk_class: "Typ ÚPVS správy" + fs_message_type: "Typ FS správy" box: "Schránka správy" attachment: "Príloha" boxes: @@ -276,11 +280,14 @@ sk: message_draft_submitted: "Odoslaná správa" message_object_downloaded: "Stiahnutý objekt správy" "Automation::ContainsCondition": "obsahuje" + "Automation::BooleanCondition": "je" "Automation::AttachmentContentContainsCondition": "obsahuje" "Automation::MetadataValueCondition": "v metadátach obsahuje" + "Automation::MetadataValueNotCondition": "v metadátach neobsahuje" "Automation::MessageMetadataValueCondition": "správa v metadátach obsahuje" "Automation::BoxCondition": "je" "Automation::AddMessageThreadTagAction": "Pridaj štítok na vlákno" + "Automation::UnassignMessageThreadTagAction": "Odober štítok z vlákna" "Automation::AddTagAction": "Pridaj štítok" "Automation::ChangeMessageThreadTitleAction": "Premenuj vlákno na" "Automation::FireWebhookAction": "Zavolaj integráciu" diff --git a/test/fixtures/automation/actions.yml b/test/fixtures/automation/actions.yml index 19406586..4c92353c 100644 --- a/test/fixtures/automation/actions.yml +++ b/test/fixtures/automation/actions.yml @@ -37,3 +37,8 @@ seven: automation_rule: six type: Automation::AddMessageThreadTagAction action_object: ssd_crac_success (Tag) + +unassign_done_tag: + automation_rule: unassign_done_tag + type: Automation::UnassignMessageThreadTagAction + action_object: ssd_done (Tag) diff --git a/test/fixtures/automation/conditions.yml b/test/fixtures/automation/conditions.yml index f52bf788..908eedf3 100644 --- a/test/fixtures/automation/conditions.yml +++ b/test/fixtures/automation/conditions.yml @@ -36,3 +36,15 @@ seven: automation_rule: six type: Automation::AttachmentContentContainsCondition value: "úspešne spracovaná" + +is_not_outbox: + automation_rule: unassign_done_tag + attr: outbox + type: Automation::BooleanCondition + value: false + +is_not_posting_confirmation: + automation_rule: unassign_done_tag + attr: edesk_class + type: Automation::MetadataValueNotCondition + value: POSTING_CONFIRMATION diff --git a/test/fixtures/automation/rules.yml b/test/fixtures/automation/rules.yml index 8817dfb8..a28da6a2 100644 --- a/test/fixtures/automation/rules.yml +++ b/test/fixtures/automation/rules.yml @@ -36,3 +36,9 @@ six: name: AttachmentContentContainsCondition2 trigger_event: message_created +unassign_done_tag: + user: basic + tenant: ssd + name: RemoveDoneTagWhenNewInboxMessage + trigger_event: message_created + diff --git a/test/fixtures/govbox/messages.yml b/test/fixtures/govbox/messages.yml index ba8f3801..bc011821 100644 --- a/test/fixtures/govbox/messages.yml +++ b/test/fixtures/govbox/messages.yml @@ -299,3 +299,49 @@ ssd_crac: