Project

General

Profile

Defect #40412 » 0001-Filter-Watcher-is-me-should-also-include-issues-watc.patch

Marius BĂLTEANU, 2024-04-28 11:07

View differences:

app/models/issue_query.rb
528 528

  
529 529
  def sql_for_watcher_id_field(field, operator, value)
530 530
    db_table = Watcher.table_name
531
    me, others = value.partition {|id| ['0', User.current.id.to_s].include?(id)}
531
    me_ids = [0, User.current.id]
532
    me_ids = me_ids.concat(User.current.groups.pluck(:id))
533
    me, others = value.partition {|id| me_ids.include?(id.to_i)}
532 534
    sql =
533 535
      if others.any?
534 536
        "SELECT #{Issue.table_name}.id FROM #{Issue.table_name} " +
test/unit/query_test.rb
1376 1376
    assert_equal Project.where(parent_id: bookmarks).ids, result.map(&:id).sort
1377 1377
  end
1378 1378

  
1379
  def test_filter_watched_issues
1379
  def test_filter_watched_issues_by_user
1380 1380
    User.current = User.find(1)
1381 1381
    query =
1382 1382
      IssueQuery.new(
......
1384 1384
        :filters => {
1385 1385
          'watcher_id' => {
1386 1386
            :operator => '=',
1387
            :values => ['me']
1387
            :values => [User.current.id]
1388 1388
          }
1389 1389
        }
1390 1390
      )
......
1394 1394
    assert_equal Issue.visible.watched_by(User.current).sort_by(&:id), result.sort_by(&:id)
1395 1395
  end
1396 1396

  
1397
  def test_filter_watched_issues_with_groups_also
1397
  def test_filter_watched_issues_by_me_should_include_user_groups
1398 1398
    user = User.find(2)
1399 1399
    group = Group.find(10)
1400 1400
    group.users << user
1401 1401
    Issue.find(3).add_watcher(user)
1402 1402
    Issue.find(7).add_watcher(group)
1403
    manager = Role.find(1)
1404
    # view_issue_watchers permission is not required to see watched issues by current user or user groups
1405
    manager.remove_permission! :view_issue_watchers
1403 1406
    User.current = user
1407

  
1404 1408
    query =
1405 1409
      IssueQuery.new(
1406 1410
        :name => '_',
......
1412 1416
        }
1413 1417
      )
1414 1418
    result = find_issues_with_query(query)
1419

  
1415 1420
    assert_not_nil result
1416 1421
    assert !result.empty?
1417 1422
    assert_equal [3, 7], result.sort_by(&:id).pluck(:id)
    (1-1/1)