diff --git a/app/models/issue.rb b/app/models/issue.rb index 4e32dce..c0236d0 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -502,8 +502,13 @@ class Issue < ActiveRecord::Base # Project and Tracker must be set before since new_statuses_allowed_to depends on it. if (p = attrs.delete('project_id')) && safe_attribute?('project_id') - if allowed_target_projects(user).where(:id => p.to_i).exists? - self.project_id = p + if p.is_a?(String) && !p.match(/^\d*$/) + p_id = Project.find_by_identifier(p).try(:id) + else + p_id = p.to_i + end + if allowed_target_projects(user).where(:id => p_id).exists? + self.project_id = p_id end if project_id_changed? && attrs['category_id'].to_s == category_id_was.to_s diff --git a/test/functional/issues_controller_test.rb b/test/functional/issues_controller_test.rb index ff37229..a97f325 100644 --- a/test/functional/issues_controller_test.rb +++ b/test/functional/issues_controller_test.rb @@ -2535,6 +2535,21 @@ class IssuesControllerTest < Redmine::ControllerTest assert_equal 2, issue.tracker_id end + def test_create_with_project_identifier + @request.session[:user_id] = 2 + + assert_difference 'Issue.count' do + post :create, + :issue => {:project_id => 'subproject1', + :tracker_id => 2, + :subject => 'Foo'} + assert_response 302 + end + issue = Issue.order('id DESC').first + assert_equal 3, issue.project_id + assert_equal 2, issue.tracker_id + end + def test_create_without_project_id_and_continue_should_redirect_without_project_id @request.session[:user_id] = 2