]> source.dussan.org Git - redmine.git/commitdiff
Merged r15855 (#23766).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 2 Oct 2016 10:21:02 +0000 (10:21 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 2 Oct 2016 10:21:02 +0000 (10:21 +0000)
git-svn-id: http://svn.redmine.org/redmine/branches/3.3-stable@15875 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/issue.rb
test/integration/api_test/issues_test.rb

index d2e36e8fd21b75ad2b634420e6ca14ccd80d67e2..3f963a08a7e09e6c9a04cca412773813add452e4 100644 (file)
@@ -496,8 +496,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
index b1e1891811add698be668d9a5615871668a2dfe3..c21d2ccb93e5afedaa3adeb2320101ccdb0410a7 100644 (file)
@@ -491,6 +491,16 @@ JSON
     assert_equal 'API test', issue.subject
   end
 
+  test "POST /issues.json should accept project identifier as project_id" do
+    assert_difference('Issue.count') do
+      post '/issues.json',
+        {:issue => {:project_id => 'subproject1', :tracker_id => 2, :subject => 'Foo'}},
+        credentials('jsmith')
+
+      assert_response :created
+    end
+  end
+
   test "POST /issues.json without tracker_id should accept custom fields" do
     field = IssueCustomField.generate!(
       :field_format => 'list',