Skip to content

Commit

Permalink
Fixes issue list filter "Watched by: me" only shows issues watched vi…
Browse files Browse the repository at this point in the history
…a group for projects with the @view_issue_watchers@ permission (#40412).

git-svn-id: https://svn.redmine.org/redmine/trunk@22819 e93f8b46-1217-0410-a6f0-8f06a7374b81
  • Loading branch information
marius-balteanu committed May 11, 2024
1 parent 6d89e6a commit 47099cc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
4 changes: 3 additions & 1 deletion app/models/issue_query.rb
Expand Up @@ -551,7 +551,9 @@ def sql_for_spent_time_field(field, operator, value)

def sql_for_watcher_id_field(field, operator, value)
db_table = Watcher.table_name
me, others = value.partition {|id| ['0', User.current.id.to_s].include?(id)}
me_ids = [0, User.current.id]
me_ids = me_ids.concat(User.current.groups.pluck(:id))
me, others = value.partition {|id| me_ids.include?(id.to_i)}
sql =
if others.any?
"SELECT #{Issue.table_name}.id FROM #{Issue.table_name} " +
Expand Down
11 changes: 8 additions & 3 deletions test/unit/query_test.rb
Expand Up @@ -1376,15 +1376,15 @@ def test_filter_project_parent_id_with_my_bookmarks
assert_equal Project.where(parent_id: bookmarks).ids.sort, result.map(&:id).sort
end

def test_filter_watched_issues
def test_filter_watched_issues_by_user
User.current = User.find(1)
query =
IssueQuery.new(
:name => '_',
:filters => {
'watcher_id' => {
:operator => '=',
:values => ['me']
:values => [User.current.id]
}
}
)
Expand All @@ -1394,13 +1394,17 @@ def test_filter_watched_issues
assert_equal Issue.visible.watched_by(User.current).sort_by(&:id), result.sort_by(&:id)
end

def test_filter_watched_issues_with_groups_also
def test_filter_watched_issues_by_me_should_include_user_groups
user = User.find(2)
group = Group.find(10)
group.users << user
Issue.find(3).add_watcher(user)
Issue.find(7).add_watcher(group)
manager = Role.find(1)
# view_issue_watchers permission is not required to see watched issues by current user or user groups
manager.remove_permission! :view_issue_watchers
User.current = user

query =
IssueQuery.new(
:name => '_',
Expand All @@ -1412,6 +1416,7 @@ def test_filter_watched_issues_with_groups_also
}
)
result = find_issues_with_query(query)

assert_not_nil result
assert !result.empty?
assert_equal [3, 7], result.sort_by(&:id).pluck(:id)
Expand Down

0 comments on commit 47099cc

Please sign in to comment.