Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

[31500] Output correctly translated errors in mail handler

Oliver Günther68d38fe2d508
diff --git a/app/models/mail_handler.rb b/app/models/mail_handler.rb
index 64772ac53a5..5444b76c724 100644
--- a/app/models/mail_handler.rb
+++ b/app/models/mail_handler.rb
@@ -84,6 +84,7 @@ class MailHandler < ActionMailer::Base
end
end
end
+
@user = User.find_by_mail(sender_email) if sender_email.present?
if @user && [email protected]?
log "ignoring email from non-active user [#{@user.login}]"
@@ -547,8 +548,7 @@ class MailHandler < ActionMailer::Base
def log(message, level = :info)
message = "MailHandler: #{message}"
-
- logger.send(level, message) if logger&.send(level)
+ logger.public_send(level, message)
end
def work_package_create_contract_class
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 796b908bcc7..e7b07cb350c 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -496,6 +496,8 @@ en:
confirmation: "doesn't match %{attribute}."
could_not_be_copied: "could not be (fully) copied."
does_not_exist: "does not exist."
+ error_unauthorized: "may not be accessed."
+ error_readonly: "is not writable."
empty: "can't be empty."
even: "must be even."
exclusion: "is reserved."
diff --git a/spec/models/mail_handler_spec.rb b/spec/models/mail_handler_spec.rb
index 60191a6800b..8e9269381d8 100644
--- a/spec/models/mail_handler_spec.rb
+++ b/spec/models/mail_handler_spec.rb
@@ -129,7 +129,7 @@ describe MailHandler, type: :model do
let!(:version) { FactoryBot.create(:version, name: 'alpha', project: project) }
include_context 'wp_on_given_project' do
- let(:submit_options) { { allow_override: 'fixed_version' } }
+ let(:submit_options) { {allow_override: 'fixed_version'} }
end
it_behaves_like 'work package created'
@@ -234,7 +234,7 @@ describe MailHandler, type: :model do
end
include_context 'wp_on_given_project' do
- let(:submit_options) { { issue: { type: default_type.name } } }
+ let(:submit_options) { {issue: {type: default_type.name}} }
end
it_behaves_like 'work package created'
@@ -250,7 +250,7 @@ describe MailHandler, type: :model do
Role.non_member.update_attribute :permissions, [:add_work_packages]
project.update_attribute :public, true
expect do
- work_package = submit_email('ticket_by_unknown_user.eml', issue: { project: 'onlinestore' }, unknown_user: 'create')
+ work_package = submit_email('ticket_by_unknown_user.eml', issue: {project: 'onlinestore'}, unknown_user: 'create')
work_package_created(work_package)
expect(work_package.author.active?).to be_truthy
expect(work_package.author.mail).to eq('[email protected]')
@@ -270,16 +270,44 @@ describe MailHandler, type: :model do
expect(found_user.check_password?(password)).to be_truthy
end.to change(User, :count).by(1)
end
+
+ it 'rejects if unknown_user=accept and permission check is present' do
+
+ expected =
+ 'MailHandler: work_package could not be created by Anonymous due to ' \
+ '#["may not be accessed.", "Type is not writable.", "Project is not writable.", ' \
+ '"Subject is not writable.", "Description is not writable."]'
+
+ expect(Rails.logger)
+ .to(receive(:error))
+ .with(expected)
+
+ result = submit_email 'ticket_by_unknown_user.eml',
+ issue: {project: project.identifier},
+ unknown_user: 'accept'
+
+ expect(result).to eq false
+ end
+
+ it 'accepts if unknown_user=accept and no_permission_check' do
+ work_package = submit_email 'ticket_by_unknown_user.eml',
+ issue: {project: project.identifier},
+ unknown_user: 'accept',
+ no_permission_check: 1
+
+ work_package_created(work_package)
+ expect(work_package.author).to eq(User.anonymous)
+ end
end
- context 'email from emission address', with_settings: { mail_from: '[email protected]' } do
+ context 'email from emission address', with_settings: {mail_from: '[email protected]'} do
before do
Role.non_member.add_permission!(:add_work_packages)
end
subject do
submit_email('ticket_from_emission_address.eml',
- issue: { project: public_project.identifier },
+ issue: {project: public_project.identifier},
unknown_user: 'create')
end
@@ -326,7 +354,7 @@ describe MailHandler, type: :model do
expect(WorkPackage).to receive(:find_by).with(id: 123).and_return(work_package)
# Mail with two attachemnts, one of which is skipped by signature.asc filename match
- submit_email 'update_ticket_with_attachment_and_sig.eml', issue: { project: 'onlinestore' }
+ submit_email 'update_ticket_with_attachment_and_sig.eml', issue: {project: 'onlinestore'}
work_package.reload
@@ -347,7 +375,7 @@ describe MailHandler, type: :model do
expect(WorkPackage).to receive(:find_by).with(id: 123).and_return(work_package)
# Mail with two attachemnts, one of which is skipped by signature.asc filename match
- submit_email 'update_ticket_with_attachment_and_sig.eml', issue: { project: 'onlinestore' }
+ submit_email 'update_ticket_with_attachment_and_sig.eml', issue: {project: 'onlinestore'}
expect(work_package.attachments.length).to eq 2
end
@@ -371,7 +399,7 @@ describe MailHandler, type: :model do
let(:custom_field) { FactoryBot.create :text_wp_custom_field, name: "Notes" }
before do
- submit_email 'work_package_with_text_custom_field.eml', issue: { project: project.identifier }
+ submit_email 'work_package_with_text_custom_field.eml', issue: {project: project.identifier}
work_package.reload
end
@@ -387,7 +415,7 @@ describe MailHandler, type: :model do
let(:custom_field) { FactoryBot.create :list_wp_custom_field, name: "Letters", possible_values: %w(A B C) }
before do
- submit_email 'work_package_with_list_custom_field.eml', issue: { project: project.identifier }
+ submit_email 'work_package_with_list_custom_field.eml', issue: {project: project.identifier}
work_package.reload
end
@@ -403,7 +431,7 @@ describe MailHandler, type: :model do
end
context 'truncate emails based on the Setting' do
- context 'with no setting', with_settings: { mail_handler_body_delimiters: '' } do
+ context 'with no setting', with_settings: {mail_handler_body_delimiters: ''} do
include_context 'wp_on_given_project'
it_behaves_like 'work package created'
@@ -417,7 +445,7 @@ describe MailHandler, type: :model do
end
end
- context 'with a single string', with_settings: { mail_handler_body_delimiters: '---' } do
+ context 'with a single string', with_settings: {mail_handler_body_delimiters: '---'} do
include_context 'wp_on_given_project'
it_behaves_like 'work package created'
@@ -438,7 +466,7 @@ describe MailHandler, type: :model do
end
context 'with a single quoted reply (e.g. reply to a OpenProject email notification)',
- with_settings: { mail_handler_body_delimiters: '--- Reply above. Do not remove this line. ---' } do
+ with_settings: {mail_handler_body_delimiters: '--- Reply above. Do not remove this line. ---'} do
include_context 'wp_update_with_quoted_reply_above'
it_behaves_like 'journal created'
@@ -456,7 +484,7 @@ describe MailHandler, type: :model do
end
context 'with multiple quoted replies (e.g. reply to a reply of a Redmine email notification)',
- with_settings: { mail_handler_body_delimiters: '--- Reply above. Do not remove this line. ---' } do
+ with_settings: {mail_handler_body_delimiters: '--- Reply above. Do not remove this line. ---'} do
include_context 'wp_update_with_quoted_reply_above'
it_behaves_like 'journal created'
@@ -474,7 +502,7 @@ describe MailHandler, type: :model do
end
context 'with multiple strings',
- with_settings: { mail_handler_body_delimiters: "---\nBREAK" } do
+ with_settings: {mail_handler_body_delimiters: "---\nBREAK"} do
include_context 'wp_on_given_project'
it_behaves_like 'work package created'
@@ -507,7 +535,7 @@ describe MailHandler, type: :model do
project.update_attribute :public, true
work_package = submit_email 'ticket_with_category.eml',
- issue: { project: 'onlinestore' },
+ issue: {project: 'onlinestore'},
allow_override: ['category'],
unknown_user: 'create'
work_package_created(work_package)