diff --git a/app/assets/stylesheets/emails.scss b/app/assets/stylesheets/emails.scss index 98f8a47..0ec8079 100644 --- a/app/assets/stylesheets/emails.scss +++ b/app/assets/stylesheets/emails.scss @@ -6,11 +6,11 @@ background-color: cyan; padding: 1px 2px; } -.email_attribute_client { +.email_attribute_organisation { background-color: yellow; padding: 1px 2px; } -.email_attribute_ticket { +.email_attribute_issue { background-color: orange; padding: 1px 2px; } diff --git a/app/controllers/emails_controller.rb b/app/controllers/emails_controller.rb index 786aa7b..060f905 100644 --- a/app/controllers/emails_controller.rb +++ b/app/controllers/emails_controller.rb @@ -14,9 +14,9 @@ class EmailsController < ApplicationController size: 100, from: 0, aggregations: { - clients: { terms: { field: 'clients.keyword' } }, + organisations: { terms: { field: 'organisations.keyword' } }, servers: { terms: { field: 'servers.keyword' } }, - tickets: { terms: { field: 'tickets.keyword' } } + issues: { terms: { field: 'issues.keyword' } } }, }) @emails = results.results diff --git a/app/models/email.rb b/app/models/email.rb index 4c7fcac..d25604f 100644 --- a/app/models/email.rb +++ b/app/models/email.rb @@ -18,9 +18,9 @@ class Email attribute :plain_body attribute :cron, :boolean, default: false attribute :mailing_list, :boolean, default: false - attribute :clients, default: [] + attribute :organisations, default: [] attribute :servers, default: [] - attribute :tickets, default: [] + attribute :issues, default: [] attribute :created_at, :datetime, default: DateTime.now attribute :updated_at, :datetime, default: DateTime.now diff --git a/app/repositories/email_repository.rb b/app/repositories/email_repository.rb index 06e2f98..d3810b4 100644 --- a/app/repositories/email_repository.rb +++ b/app/repositories/email_repository.rb @@ -22,9 +22,9 @@ class EmailRepository indexes :message_id, type: 'keyword' indexes :cron, type: 'boolean' indexes :mailing_list, type: 'boolean' - indexes :clients, type: 'keyword' + indexes :organisations, type: 'keyword' indexes :servers, type: 'keyword' - indexes :tickets, type: 'keyword' + indexes :issues, type: 'keyword' indexes :created_at, type: 'date' indexes :updated_at, type: 'date' end diff --git a/app/services/email_action/issue_mapping.rb b/app/services/email_action/issue_mapping.rb index 410eac9..dfa655a 100644 --- a/app/services/email_action/issue_mapping.rb +++ b/app/services/email_action/issue_mapping.rb @@ -8,7 +8,7 @@ module EmailAction email.header_values(header_name) }.flatten.uniq - email.tickets = values + email.issues = values email end diff --git a/app/services/email_action/metadata_mapping.rb b/app/services/email_action/metadata_mapping.rb index e4b42aa..5c1872b 100644 --- a/app/services/email_action/metadata_mapping.rb +++ b/app/services/email_action/metadata_mapping.rb @@ -14,7 +14,7 @@ module EmailAction metadata_inputs = metadata_inputs(email) metadata = metadata_mapping_class.where(input: metadata_inputs).all - email.clients = metadata.filter_map(&:organisation).uniq + email.organisations = metadata.filter_map(&:organisation).uniq email.servers = metadata.filter_map(&:server).uniq email diff --git a/app/views/emails/index.html.erb b/app/views/emails/index.html.erb index bd17289..40e59da 100644 --- a/app/views/emails/index.html.erb +++ b/app/views/emails/index.html.erb @@ -19,9 +19,9 @@ <%= email.date %> <%= email.subject %> - <% email.clients.each do |client| %> - <%= client %> - <% end if email.clients %> + <% email.organisations.each do |organisation| %> + <%= organisation %> + <% end if email.organisations %> <% email.servers.each do |server| %> diff --git a/app/views/emails/show.html.erb b/app/views/emails/show.html.erb index ef294fd..909a716 100644 --- a/app/views/emails/show.html.erb +++ b/app/views/emails/show.html.erb @@ -23,12 +23,12 @@ Subject <%= @email.subject %> - <% if @email.clients.present? %> + <% if @email.organisations.present? %> Clients - <% @email.clients.presence.each do |client| %> - <%= client %> + <% @email.organisations.presence.each do |organisation| %> + <%= organisation %> <% end %> @@ -43,12 +43,12 @@ <% end %> - <% if @email.tickets.present? %> + <% if @email.issues.present? %> - Tickets + Issues - <% @email.tickets.presence.each do |ticket| %> - <%= ticket %> + <% @email.issues.presence.each do |issue| %> + <%= issue %> <% end %> diff --git a/db/migrate/20201017104739_create_emails.rb b/db/migrate/20201017104739_create_emails.rb deleted file mode 100644 index 66f4e6d..0000000 --- a/db/migrate/20201017104739_create_emails.rb +++ /dev/null @@ -1,20 +0,0 @@ -class CreateEmails < ActiveRecord::Migration[6.0] - def change - create_table :emails do |t| - t.string :message_id - t.string :subject - t.datetime :date - t.string :to - t.string :delivered_to - t.string :from - t.text :plain_body - t.text :raw_headers - t.boolean :cron - t.boolean :mailing_list - t.string :clients - t.string :servers - t.string :tickets - t.timestamps - end - end -end diff --git a/db/schema.rb b/db/schema.rb index 562ec7e..c011125 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -70,9 +70,9 @@ ActiveRecord::Schema.define(version: 2021_01_18_132809) do t.text "raw_headers" t.boolean "cron" t.boolean "mailing_list" - t.string "clients" + t.string "organisations" t.string "servers" - t.string "tickets" + t.string "issues" t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false end diff --git a/test/fixtures/files/tickets_multiple.eml b/test/fixtures/files/issues_multiple.eml similarity index 91% rename from test/fixtures/files/tickets_multiple.eml rename to test/fixtures/files/issues_multiple.eml index 00a0d4d..4987886 100644 --- a/test/fixtures/files/tickets_multiple.eml +++ b/test/fixtures/files/issues_multiple.eml @@ -9,7 +9,7 @@ MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Date: Sat, 12 Sep 2020 06:43:02 +0200 (CEST) -Message-Id: +Message-Id: X-Ticket-Id: 49123 X-Ticket-Id: 12345 diff --git a/test/fixtures/files/tickets_single.eml b/test/fixtures/files/issues_single.eml similarity index 91% rename from test/fixtures/files/tickets_single.eml rename to test/fixtures/files/issues_single.eml index ce35dbe..122e7e9 100644 --- a/test/fixtures/files/tickets_single.eml +++ b/test/fixtures/files/issues_single.eml @@ -9,7 +9,7 @@ MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Date: Sat, 12 Sep 2020 06:43:02 +0200 (CEST) -Message-Id: +Message-Id: X-Ticket-Id: 49123 dummy body diff --git a/test/fixtures/files/clients_multiple.eml b/test/fixtures/files/organisations_multiple.eml similarity index 90% rename from test/fixtures/files/clients_multiple.eml rename to test/fixtures/files/organisations_multiple.eml index 790d0a0..7c1aa48 100644 --- a/test/fixtures/files/clients_multiple.eml +++ b/test/fixtures/files/organisations_multiple.eml @@ -9,7 +9,7 @@ MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Date: Sat, 12 Sep 2020 06:43:02 +0200 (CEST) -Message-Id: +Message-Id: X-Client-Id: 42QUUX4567 X-Client-Id: 75FOOB0123 diff --git a/test/fixtures/files/clients_single.eml b/test/fixtures/files/organisations_single.eml similarity index 90% rename from test/fixtures/files/clients_single.eml rename to test/fixtures/files/organisations_single.eml index 234bbbe..22ee0d9 100644 --- a/test/fixtures/files/clients_single.eml +++ b/test/fixtures/files/organisations_single.eml @@ -9,7 +9,7 @@ MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Date: Sat, 12 Sep 2020 06:43:02 +0200 (CEST) -Message-Id: +Message-Id: X-Client-Id: 42QUUX4567 dummy body diff --git a/test/services/rule_set_processor_test.rb b/test/services/rule_set_processor_test.rb index 97ff1d8..3585ff1 100644 --- a/test/services/rule_set_processor_test.rb +++ b/test/services/rule_set_processor_test.rb @@ -20,38 +20,38 @@ class RuleSetProcessorTest < ActiveSupport::TestCase assert_not_predicate email, :cron? end - test "single ticket" do - email = email_from_eml_with_rules("tickets_single.eml") + test "single issue" do + email = email_from_eml_with_rules("issues_single.eml") expected = ["49123"] - actual = email.tickets + actual = email.issues assert_equal expected, actual end - test "multiple tickets" do - email = email_from_eml_with_rules("tickets_multiple.eml") + test "multiple issues" do + email = email_from_eml_with_rules("issues_multiple.eml") expected = ["49123", "12345"] - actual = email.tickets + actual = email.issues assert_equal expected, actual end - test "single client" do - email = email_from_eml_with_rules("clients_single.eml") + test "single organisation" do + email = email_from_eml_with_rules("organisations_single.eml") expected = ["quux"] - actual = email.clients + actual = email.organisations assert_equal expected, actual end - test "multiple clients" do - email = email_from_eml_with_rules("clients_multiple.eml") + test "multiple organisations" do + email = email_from_eml_with_rules("organisations_multiple.eml") expected = ["quux", "foobar"] - actual = email.clients + actual = email.organisations assert_equal expected, actual end