From fc7c5e3a4263d4d1842ef65644d8f90d0c12e9db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20G=C3=BCnther?= Date: Mon, 17 Feb 2025 14:59:57 +0100 Subject: [PATCH] Fix mail handler attrs --- app/models/mail_handler.rb | 5 +- .../configuration/incoming-emails/README.md | 29 ++++---- lib_static/redmine/i18n.rb | 2 +- .../mail_handler/wp_with_attribute_keys.eml | 31 +++++++++ .../wp_with_attributes_i18n_de.eml | 31 +++++++++ spec/models/mail_handler_spec.rb | 69 +++++++++++++++++++ 6 files changed, 151 insertions(+), 16 deletions(-) create mode 100644 spec/fixtures/mail_handler/wp_with_attribute_keys.eml create mode 100644 spec/fixtures/mail_handler/wp_with_attributes_i18n_de.eml diff --git a/app/models/mail_handler.rb b/app/models/mail_handler.rb index 3525d0d6ba2..9951bbfb90f 100644 --- a/app/models/mail_handler.rb +++ b/app/models/mail_handler.rb @@ -355,7 +355,10 @@ class MailHandler < ActionMailer::Base end def human_attr_translations(attr) - keys = [attr.to_s.humanize] + keys = [ + attr.to_s, + attr.to_s.humanize + ] [user&.language, Setting.default_language].compact_blank.each do |lang| keys << all_attribute_translations(lang)[attr] diff --git a/docs/installation-and-operations/configuration/incoming-emails/README.md b/docs/installation-and-operations/configuration/incoming-emails/README.md index 6b3f9db7fb1..24be6702afe 100644 --- a/docs/installation-and-operations/configuration/incoming-emails/README.md +++ b/docs/installation-and-operations/configuration/incoming-emails/README.md @@ -180,21 +180,22 @@ OR set it as fixed variable with `project=identifier`. The subject of the work package that shall be created is derived from the subject of the email. The body of the email gets parsed and all lines that contain recognized keys are removed. What is left will become the description. -Other available keys for the email are: +Other available keys for the email are as follows. You can always use the internal **Key** or the **Name** of the attribute. The name will depend on the system's default language or the selected language of the user identified through the email address. -| Key | Description | Example | -|-----------------|-------------------------------------------------------|----------------------------------| -| Project | sets the project. Use the project identifier | Project:test\_project | -| Accountable | sets the accountable, via user email or login | Accountable:user@example.org | -| Assignee | sets the assignee. Use the email or login of the user | Assignee:test.nutzer@example.org | -| Type | sets the type | type:Milestone | -| Version | sets the version | version:v4.1.0 | -| Start date | sets the start date | start date:2015-02-28 | -| Due date | sets the finish date | | -| Estimated hours | sets the estimated hours. Use a number | Estimated hours:10.5 | -| Remaining hours | sets the remaining hours. Use a number | Remaining hours:2.5 | -| Status | sets the status | Status:closed | -| priority | sets the priority | priority:High | +| Key | Name (EN) | Description | Example | +| --------------- | --------------- | ----------------------------------------------------- | -------------------------------- | +| project | Project | sets the project. Use the project identifier | project:test\_project | +| responsible | Accountable | sets the accountable, via user email or login | responsible:user@example.org | +| assigned_to | Assignee | sets the assignee. Use the email or login of the user | assignee:test.nutzer@example.org | +| type | Type | sets the type | type:Milestone | +| version | Version | sets the version | version:v4.1.0 | +| start_date | Start date | sets the start date | start_date:2015-02-28 | +| due_date | Due date | sets the finish date | due:_date:2015-02-28 | +| estimated_hours | Estimated hours | sets the estimated hours. Use a number | estimated_hours:10.5 | +| remaining_hours | Remaining hours | sets the remaining hours. Use a number | remaining_hours:2.5 | +| status | Status | sets the status | status:closed | +| priority | Priority | sets the priority | priority:High | +| category | Category | sets the category from the project's categories | category:Testing | If you want to set a custom field just use the name as it is displayed in your browser, e.g. `Custom field:new value` diff --git a/lib_static/redmine/i18n.rb b/lib_static/redmine/i18n.rb index 68a150f5871..a8e0e980deb 100644 --- a/lib_static/redmine/i18n.rb +++ b/lib_static/redmine/i18n.rb @@ -245,7 +245,7 @@ module Redmine general_attributes = ::I18n.t("attributes", locale:) ::I18n.t("activerecord.attributes", locale:).inject(general_attributes) do |attr_t, model_t| - attr_t.merge(model_t.last || {}) + attr_t.reverse_merge(model_t.last || {}) end end @cached_attribute_translations[locale] diff --git a/spec/fixtures/mail_handler/wp_with_attribute_keys.eml b/spec/fixtures/mail_handler/wp_with_attribute_keys.eml new file mode 100644 index 00000000000..f58d843f670 --- /dev/null +++ b/spec/fixtures/mail_handler/wp_with_attribute_keys.eml @@ -0,0 +1,31 @@ +Return-Path: +Received: from osiris ([127.0.0.1]) + by OSIRIS + with hMailServer ; Sun, 22 Jun 2008 12:28:07 +0200 +Message-ID: <000501c8d452$a95cd7e0$0a00a8c0@osiris> +From: "John Smith" +To: +Subject: New ticket with full attributes +Date: Sun, 22 Jun 2008 12:28:07 +0200 +MIME-Version: 1.0 +Content-Type: text/plain; charset=utf-8 +Content-Transfer-Encoding: 7bit +X-Priority: 3 +X-MSMail-Priority: Normal +X-Mailer: Microsoft Outlook Express 6.00.2900.2869 +X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2869 + +project: onlinestore +type: Feature request +status: Resolved +category: Stock management +version: alpha +priority: Urgent +assigned_to: jsmith@somenet.foo +responsible: jsmith@somenet.foo +start_date: 2025-01-01 +due_date: 2025-12-31 +estimated_hours: 20 +remaining_hours: 10.5 + +Some description here diff --git a/spec/fixtures/mail_handler/wp_with_attributes_i18n_de.eml b/spec/fixtures/mail_handler/wp_with_attributes_i18n_de.eml new file mode 100644 index 00000000000..c97f948c037 --- /dev/null +++ b/spec/fixtures/mail_handler/wp_with_attributes_i18n_de.eml @@ -0,0 +1,31 @@ +Return-Path: +Received: from osiris ([127.0.0.1]) + by OSIRIS + with hMailServer ; Sun, 22 Jun 2008 12:28:07 +0200 +Message-ID: <000501c8d452$a95cd7e0$0a00a8c0@osiris> +From: "John Smith" +To: +Subject: Neues Arbeitspaket +Date: Sun, 22 Jun 2008 12:28:07 +0200 +MIME-Version: 1.0 +Content-Type: text/plain; charset=utf-8 +Content-Transfer-Encoding: 7bit +X-Priority: 3 +X-MSMail-Priority: Normal +X-Mailer: Microsoft Outlook Express 6.00.2900.2869 +X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2869 + +Project: onlinestore +Typ: Feature request +Status: Resolved +Kategorie: Stock management +Version: alpha +Priorität: Urgent +Zugewiesen an: jsmith@somenet.foo +Verantwortlich: jsmith@somenet.foo +Anfangstermin: 2025-01-01 +Endtermin: 2025-12-31 +Aufwand: 20 +Verbleibender Aufwand: 10.5 + +Beschreibung würde hier stehen. diff --git a/spec/models/mail_handler_spec.rb b/spec/models/mail_handler_spec.rb index eb4b177667e..aa64bbe4882 100644 --- a/spec/models/mail_handler_spec.rb +++ b/spec/models/mail_handler_spec.rb @@ -272,6 +272,9 @@ RSpec.describe MailHandler do shared_context "with a new work package with attributes with additional spaces" do let(:permissions) { %i[add_work_packages assign_versions work_package_assigned] } + let(:role) do + create(:project_role, permissions:) + end let!(:user) do create(:user, mail: "JSmith@somenet.foo", @@ -294,6 +297,21 @@ RSpec.describe MailHandler do let!(:high_priority) do create(:priority_high) end + let!(:version) { create(:version, name: "alpha", project:) } + let!(:original_status) do + create(:default_status) + end + let!(:resolved_status) do + create(:status, + name: "Resolved") do |status| + create(:workflow, + old_status: original_status, + new_status: status, + role:, + type: feature_type) + end + end + let(:submit_options) { {} } subject do @@ -1171,6 +1189,57 @@ RSpec.describe MailHandler do .to eql "This is a html-only email." end end + + context "for a wp with attribute keys" do + include_context "with a new work package with attributes with additional spaces" + it_behaves_like "work package created" + + subject do + submit_email("wp_with_attribute_keys.eml", allow_override: ["category"]) + end + + it "sets the description" do + expect(subject.description).to eq("Some description here") + expect(subject.subject).to eq("New ticket with full attributes") + expect(subject.type).to eq(feature_type) + expect(subject.status).to eq(resolved_status) + expect(subject.version).to eq(version) + expect(subject.priority).to eq(urgent_priority) + expect(subject.assigned_to).to eq(user) + expect(subject.responsible).to eq(user) + expect(subject.start_date).to eq(Date.parse("2025-01-01")) + expect(subject.due_date).to eq(Date.parse("2025-12-31")) + expect(subject.estimated_hours).to eq(20) + expect(subject.remaining_hours).to eq(10.5) + expect(subject.category).to eq(stock_category) + end + + context "with the user having a german locale" do + before do + user.update!(language: "de") + end + + subject do + submit_email("wp_with_attributes_i18n_de.eml", allow_override: ["category"]) + end + + it "sets the description" do + expect(subject.description).to eq("Beschreibung würde hier stehen.") + expect(subject.subject).to eq("Neues Arbeitspaket") + expect(subject.type).to eq(feature_type) + expect(subject.status).to eq(resolved_status) + expect(subject.version).to eq(version) + expect(subject.priority).to eq(urgent_priority) + expect(subject.assigned_to).to eq(user) + expect(subject.responsible).to eq(user) + expect(subject.start_date).to eq(Date.parse("2025-01-01")) + expect(subject.due_date).to eq(Date.parse("2025-12-31")) + expect(subject.estimated_hours).to eq(20) + expect(subject.remaining_hours).to eq(10.5) + expect(subject.category).to eq(stock_category) + end + end + end end context "when sending a reply to work package mail" do