]> source.dussan.org Git - redmine.git/commitdiff
Let the API accept project identifier for creating issues (#23766).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 1 Oct 2016 09:06:17 +0000 (09:06 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 1 Oct 2016 09:06:17 +0000 (09:06 +0000)
Patch by Holger Just.

git-svn-id: http://svn.redmine.org/redmine/trunk@15855 e93f8b46-1217-0410-a6f0-8f06a7374b81

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

index d550616a9137879542de64b3b43f0584f87a1c91..e2699394b40e5e1bd212e3c3cd810fef16fbea23 100644 (file)
@@ -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
index 50119f4d1d4754e5a9d5c054e87a90de12ed138f..077ae9601e51fb98c3dc701a607b9672972222e0 100644 (file)
@@ -488,6 +488,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',