From 8b61ba26f75d2fdb16a51f13811ad1c06332519a Mon Sep 17 00:00:00 2001 From: Yazan Date: Mon, 28 Mar 2022 09:10:38 +0200 Subject: [PATCH] Allow to list "watchers" when listing several issues. --- app/views/issues/index.api.rsb | 6 ++++++ test/functional/issues_controller_test.rb | 20 ++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/app/views/issues/index.api.rsb b/app/views/issues/index.api.rsb index 4bba32549..f45593976 100644 --- a/app/views/issues/index.api.rsb +++ b/app/views/issues/index.api.rsb @@ -32,6 +32,12 @@ api.array :issues, api_meta(:total_count => @issue_count, :offset => @offset, :l end end if include_in_api_response?('attachments') + api.array :watchers do + issue.watcher_users.each do |user| + api.user :id => user.id, :name => user.name + end + end if include_in_api_response?('watchers') && User.current.allowed_to?(:view_issue_watchers, issue.project) + api.array :relations do issue.relations.each do |relation| api.relation(:id => relation.id, :issue_id => relation.issue_from_id, :issue_to_id => relation.issue_to_id, :relation_type => relation.relation_type, :delay => relation.delay) diff --git a/test/functional/issues_controller_test.rb b/test/functional/issues_controller_test.rb index 2a4fc6d5b..6401a3a65 100644 --- a/test/functional/issues_controller_test.rb +++ b/test/functional/issues_controller_test.rb @@ -8274,4 +8274,24 @@ class IssuesControllerTest < Redmine::ControllerTest end end end + + def test_should_not_list_the_wathcers_in_issue_index_api_without_permission + get :index, params: { :include => ["watchers"], :format => 'json' } + assert_response :success + assert_not_include 'watchers', response.body + end + + def test_should_list_the_wathcers_in_issue_index_api_with_permission + Role.last.add_permission!(:view_issue_watchers) + get :index, params: { :include => ["watchers"], :format => 'json' } + assert_response :success + watchers = Watcher.where(watchable_type: 'Issue').sort_by(&:user_id) + + if watchers.count + watchers.each do |watcher| + st = "{\"id\":#{watcher.user.id},\"name\":\"#{watcher.user.name}\"}" + assert_include st, response.body + end + end + end end -- 2.17.1