]> source.dussan.org Git - redmine.git/commitdiff
Include enabled modules in projects API (#17602).
authorJean-Baptiste Barth <jeanbaptiste.barth@gmail.com>
Sat, 6 Sep 2014 03:17:51 +0000 (03:17 +0000)
committerJean-Baptiste Barth <jeanbaptiste.barth@gmail.com>
Sat, 6 Sep 2014 03:17:51 +0000 (03:17 +0000)
Contributed by Jan Schulz-Hofen <jan@plan.io>

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

app/helpers/projects_helper.rb
app/views/projects/index.api.rsb
app/views/projects/show.api.rsb
test/integration/api_test/projects_test.rb

index 8337d43ab6d4a29665ead8ee05322b006987a030..8e23ccdda6c64aa48ed1d250667abff80337e77e 100644 (file)
@@ -91,4 +91,25 @@ module ProjectsHelper
     sharing = 'none' unless Version::VERSION_SHARINGS.include?(sharing)
     l("label_version_sharing_#{sharing}")
   end
+
+  def render_api_includes(project, api)
+    api.array :trackers do
+      project.trackers.each do |tracker|
+        api.tracker(:id => tracker.id, :name => tracker.name)
+      end
+    end if include_in_api_response?('trackers')
+
+    api.array :issue_categories do
+      project.issue_categories.each do |category|
+        api.issue_category(:id => category.id, :name => category.name)
+      end
+    end if include_in_api_response?('issue_categories')
+
+    api.array :enabled_modules do
+      project.enabled_modules.each do |enabled_module|
+        api.enabled_module(:id => enabled_module.id, :name => enabled_module.name)
+      end
+    end if include_in_api_response?('enabled_modules')
+
+  end
 end
index a07db1b710b05f263eafdf7bec2af56e467e45c8..d309af2415cb8ab2512171b259eaeb50b04bfa5d 100644 (file)
@@ -10,6 +10,7 @@ api.array :projects, api_meta(:total_count => @project_count, :offset => @offset
       api.is_public   project.is_public?
 
       render_api_custom_values project.visible_custom_field_values, api
+      render_api_includes(project, api)
 
       api.created_on  project.created_on
       api.updated_on  project.updated_on
index 7a1e07c02ccb349239375f016e29d7f279e3dbc2..6e1958a34ec2118de193fe242aaf0cbc6017ce17 100644 (file)
@@ -9,19 +9,8 @@ api.project do
   api.is_public   @project.is_public?
 
   render_api_custom_values @project.visible_custom_field_values, api
+  render_api_includes(@project, api)
 
   api.created_on @project.created_on
   api.updated_on @project.updated_on
-
-  api.array :trackers do
-    @project.trackers.each do |tracker|
-      api.tracker(:id => tracker.id, :name => tracker.name)
-    end
-  end if include_in_api_response?('trackers')
-
-  api.array :issue_categories do
-    @project.issue_categories.each do |category|
-      api.issue_category(:id => category.id, :name => category.name)
-    end
-  end if include_in_api_response?('issue_categories')
 end
index efb41f03bf8c47b3e36b6d1f1f792f7f13efb082..28b8b94527355bfe9e41f237f69e870f97c17869 100644 (file)
@@ -66,6 +66,53 @@ class Redmine::ApiTest::ProjectsTest < Redmine::ApiTest::Base
     assert json['projects'].first.has_key?('id')
   end
 
+  test "GET /projects.xml with include=issue_categories should return categories" do
+    get '/projects.xml?include=issue_categories'
+    assert_response :success
+    assert_equal 'application/xml', @response.content_type
+
+    assert_tag 'issue_categories',
+      :attributes => {:type => 'array'},
+      :child => {
+        :tag => 'issue_category',
+        :attributes => {
+          :id => '2',
+          :name => 'Recipes'
+        }
+      }
+  end
+
+  test "GET /projects.xml with include=trackers should return trackers" do
+    get '/projects.xml?include=trackers'
+    assert_response :success
+    assert_equal 'application/xml', @response.content_type
+
+    assert_tag 'trackers',
+      :attributes => {:type => 'array'},
+      :child => {
+        :tag => 'tracker',
+        :attributes => {
+          :id => '2',
+          :name => 'Feature request'
+        }
+      }
+  end
+
+  test "GET /projects.xml with include=enabled_modules should return enabled modules" do
+    get '/projects.xml?include=enabled_modules'
+    assert_response :success
+    assert_equal 'application/xml', @response.content_type
+
+    assert_tag 'enabled_modules',
+      :attributes => {:type => 'array'},
+      :child => {
+        :tag => 'enabled_module',
+        :attributes => {
+          :name => 'issue_tracking'
+        }
+      }
+  end
+
   test "GET /projects/:id.xml should return the project" do
     get '/projects/1.xml'
     assert_response :success
@@ -132,6 +179,21 @@ class Redmine::ApiTest::ProjectsTest < Redmine::ApiTest::Base
       }
   end
 
+  test "GET /projects/:id.xml with include=enabled_modules should return enabled modules" do
+    get '/projects/1.xml?include=enabled_modules'
+    assert_response :success
+    assert_equal 'application/xml', @response.content_type
+
+    assert_tag 'enabled_modules',
+      :attributes => {:type => 'array'},
+      :child => {
+        :tag => 'enabled_module',
+        :attributes => {
+          :name => 'issue_tracking'
+        }
+      }
+  end
+
   test "POST /projects.xml with valid parameters should create the project" do
     Setting.default_projects_modules = ['issue_tracking', 'repository']