diff --git a/app/models/mail_handler.rb b/app/models/mail_handler.rb index 9afe2a170..d5ca28ba9 100644 --- a/app/models/mail_handler.rb +++ b/app/models/mail_handler.rb @@ -182,6 +182,10 @@ class MailHandler < ActionMailer::Base # Creates a new issue def receive_issue project = target_project + + # Never receive emails to projects where adding issues is not possible + raise UnauthorizedAction, "not possible to add issues to project [#{project.name}]" unless project.allows_to?(:add_issues) + # check permission unless handler_options[:no_permission_check] raise UnauthorizedAction, "not allowed to add issues to project [#{project.name}]" unless user.allowed_to?(:add_issues, project) @@ -223,6 +227,10 @@ class MailHandler < ActionMailer::Base return nil end + # Never receive emails to projects where adding issue notes is not possible + project = issue.project + raise UnauthorizedAction, "not possible to add notes to project [#{project.name}]" unless project.allows_to?(:add_issue_notes) + # check permission unless handler_options[:no_permission_check] unless issue.notes_addable? @@ -274,6 +282,10 @@ class MailHandler < ActionMailer::Base return nil end + # Never receive emails to projects where adding messages is not possible + project = message.project + raise UnauthorizedAction, "not possible to add messages to project [#{project.name}]" unless project.allows_to?(:add_messages) + unless handler_options[:no_permission_check] raise UnauthorizedAction, "not allowed to add messages to project [#{message.project.name}]" unless user.allowed_to?(:add_messages, message.project) end diff --git a/test/unit/mail_handler_test.rb b/test/unit/mail_handler_test.rb index 9d0dad1a7..b36259c14 100644 --- a/test/unit/mail_handler_test.rb +++ b/test/unit/mail_handler_test.rb @@ -403,6 +403,35 @@ class MailHandlerTest < ActiveSupport::TestCase end end + def test_no_issue_on_closed_project_without_permission_check + Project.find(2).close + assert_no_difference 'User.count' do + assert_no_difference 'Issue.count' do + submit_email( + 'ticket_by_unknown_user.eml', + :issue => {:project => 'onlinestore'}, + :no_permission_check => '1', + :unknown_user => 'accept' + ) + end + end + ensure + Project.find(2).reopen + end + + def test_no_issue_on_closed_project_without_issue_tracking_module + assert_no_difference 'User.count' do + assert_no_difference 'Issue.count' do + submit_email( + 'ticket_by_unknown_user.eml', + :issue => {:project => 'subproject2'}, + :no_permission_check => '1', + :unknown_user => 'accept' + ) + end + end + end + def test_add_issue_by_created_user Setting.default_language = 'en' assert_difference 'User.count' do