]> source.dussan.org Git - redmine.git/commitdiff
Projects API should not return invisible trackers (#30121).
authorGo MAEDA <maeda@farend.jp>
Tue, 23 Feb 2021 03:17:29 +0000 (03:17 +0000)
committerGo MAEDA <maeda@farend.jp>
Tue, 23 Feb 2021 03:17:29 +0000 (03:17 +0000)
Patch by Yuichi HARADA.

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

app/helpers/projects_helper.rb
test/integration/api_test/projects_test.rb

index 7726050d95b951aae6b49a227e9642ba46812acc..77f964a9ef5176544c3eb68704c06cd9f7def631 100644 (file)
@@ -134,7 +134,7 @@ module ProjectsHelper
 
   def render_api_includes(project, api)
     api.array :trackers do
-      project.trackers.each do |tracker|
+      project.rolled_up_trackers(false).visible.each do |tracker|
         api.tracker(:id => tracker.id, :name => tracker.name)
       end
     end if include_in_api_response?('trackers')
index befd8907d0d21ac36963d9eb93a0461f3302ab45..044d67b49bdfa9317818b1a2fd5a7acd25e257b6 100644 (file)
@@ -154,6 +154,33 @@ class Redmine::ApiTest::ProjectsTest < Redmine::ApiTest::Base
     assert_select 'trackers[type=array] tracker[id="2"][name="Feature request"]'
   end
 
+  test "GET /projects/:id.xml with include=trackers should return trackers based on role-based permissioning" do
+    project = Project.find(1)
+    assert_equal [1, 2, 3], project.tracker_ids
+
+    role = Role.find(3) # Reporter
+    role.permissions_all_trackers = {'view_issues' => '0'}
+    role.permissions_tracker_ids = {'view_issues' => ['1']}
+    role.save!
+
+    user = User.find_by(:login => 'jsmith')
+    member = project.members.detect{|m| m.user == user}
+    member.roles.delete_all
+    member.role_ids = [role.id]
+    member.roles.reload
+    assert_equal [role.id], member.role_ids
+
+    get '/projects/1.xml?include=trackers', :headers => credentials(user.login)
+    assert_response :success
+    assert_equal 'application/xml', @response.content_type
+
+    assert_select 'trackers[type=array]' do
+      assert_select 'tracker[id="1"]', :count => 1
+      assert_select 'tracker[id="2"]', :count => 0
+      assert_select 'tracker[id="3"]', :count => 0
+    end
+  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