30121-api-will-return-trackers-with-role-based.patch

Yuichi HARADA, 2018-12-13 02:52

Download (2.06 KB)

View differences:

app/helpers/projects_helper.rb
115 115

  
116 116
  def render_api_includes(project, api)
117 117
    api.array :trackers do
118
      project.trackers.each do |tracker|
118
      project.rolled_up_trackers(false).visible.each do |tracker|
119 119
        api.tracker(:id => tracker.id, :name => tracker.name)
120 120
      end
121 121
    end if include_in_api_response?('trackers')
test/integration/api_test/projects_test.rb
130 130
    assert_select 'trackers[type=array] tracker[id="2"][name="Feature request"]'
131 131
  end
132 132

  
133
  test "GET /projects/:id.xml with include=trackers should return trackers based on role-based permissioning" do
134
    project = Project.find(1)
135
    assert_equal [1, 2, 3], project.tracker_ids
136

  
137
    role = Role.find(3) # Reporter
138
    role.permissions_all_trackers = {'view_issues' => '0'}
139
    role.permissions_tracker_ids = {'view_issues' => ['1']}
140
    role.save!
141

  
142
    user = User.find_by_login('jsmith')
143
    member = project.members.detect{|m| m.user == user}
144
    member.roles.delete_all
145
    member.role_ids = [role.id]
146
    member.roles.reload
147
    assert_equal [role.id], member.role_ids
148

  
149
    get '/projects/1.xml?include=trackers', :headers => credentials(user.login)
150
    assert_response :success
151
    assert_equal 'application/xml', @response.content_type
152

  
153
    assert_select 'trackers[type=array]' do
154
      assert_select 'tracker[id="1"]', :count => 1
155
      assert_select 'tracker[id="2"]', :count => 0
156
      assert_select 'tracker[id="3"]', :count => 0
157
    end
158
  end
159

  
133 160
  test "GET /projects/:id.xml with include=enabled_modules should return enabled modules" do
134 161
    get '/projects/1.xml?include=enabled_modules'
135 162
    assert_response :success