Defect #8603 » subproject_filter_for_all_projects.patch
| app/models/issue_query.rb | ||
|---|---|---|
| 263 | 263 |
"last_updated_by", |
| 264 | 264 |
:type => :list, :values => lambda {author_values}
|
| 265 | 265 |
) |
| 266 |
if project && !project.leaf?
|
|
| 266 |
if project.nil? || !project.leaf?
|
|
| 267 | 267 |
add_available_filter( |
| 268 | 268 |
"subproject_id", |
| 269 | 269 |
:type => :list_subprojects, |
| app/models/query.rb | ||
|---|---|---|
| 613 | 613 |
end |
| 614 | 614 | |
| 615 | 615 |
def subproject_values |
| 616 |
return [] unless project |
|
| 617 | ||
| 616 | 618 |
project.descendants.visible.pluck(:name, :id).map {|name, id| [name, id.to_s]}
|
| 617 | 619 |
end |
| 618 | 620 | |
| app/models/time_entry_query.rb | ||
|---|---|---|
| 51 | 51 |
"project_id", |
| 52 | 52 |
:type => :list, :values => lambda {project_values}
|
| 53 | 53 |
) if project.nil? |
| 54 |
if project && !project.leaf?
|
|
| 54 |
if project.nil? || !project.leaf?
|
|
| 55 | 55 |
add_available_filter( |
| 56 | 56 |
"subproject_id", |
| 57 | 57 |
:type => :list_subprojects, |
| test/functional/queries_controller_test.rb | ||
|---|---|---|
| 500 | 500 |
assert_equal Query::VISIBILITY_PUBLIC, query.visibility |
| 501 | 501 |
end |
| 502 | 502 | |
| 503 |
def test_create_query_for_all_projects_with_subproject_filter |
|
| 504 |
@request.session[:user_id] = 1 |
|
| 505 |
query = new_record(Query) do |
|
| 506 |
post( |
|
| 507 |
:create, |
|
| 508 |
:params => {
|
|
| 509 |
:project_id => 'ecookbook', |
|
| 510 |
:query_is_for_all => '1', |
|
| 511 |
:f => ['subproject_id'], |
|
| 512 |
:op => {'subproject_id' => '!*'},
|
|
| 513 |
:query => {'name' => 'Without subprojects', 'visibility' => '2'}
|
|
| 514 |
} |
|
| 515 |
) |
|
| 516 |
assert_response :found |
|
| 517 |
end |
|
| 518 |
assert_nil query.project |
|
| 519 |
assert_equal({:operator => '!*', :values => ['']}, query.filters['subproject_id'])
|
|
| 520 |
end |
|
| 521 | ||
| 503 | 522 |
def test_create_global_public_query_should_force_private_with_manage_public_queries_permission |
| 504 | 523 |
@request.session[:user_id] = 2 |
| 505 | 524 |
query = new_record(Query) do |
| test/unit/query_test.rb | ||
|---|---|---|
| 3271 | 3271 |
assert query.available_filters.has_key?('project.status')
|
| 3272 | 3272 |
end |
| 3273 | 3273 | |
| 3274 |
def test_subproject_filter_should_be_available_for_query_for_all_projects |
|
| 3275 |
query = IssueQuery.new(:project => nil, :name => '_') |
|
| 3276 |
assert_include 'subproject_id', query.available_filters.keys |
|
| 3277 |
assert_equal [], query.available_filters['subproject_id'][:values] |
|
| 3278 |
end |
|
| 3279 | ||
| 3280 |
def test_subproject_filter_should_not_be_available_when_project_is_leaf |
|
| 3281 |
query = IssueQuery.new(:project => Project.find(2), :name => '_') |
|
| 3282 |
assert_not_include 'subproject_id', query.available_filters.keys |
|
| 3283 |
end |
|
| 3284 | ||
| 3285 |
def test_subproject_filter_of_query_for_all_projects_should_apply_in_project |
|
| 3286 |
query = IssueQuery.new(:project => nil, :name => '_') |
|
| 3287 |
query.add_filter('subproject_id', '!*', [''])
|
|
| 3288 |
assert_include 'subproject_id', query.filters.keys |
|
| 3289 | ||
| 3290 |
assert_include 5, find_issues_with_query(query).map(&:id) |
|
| 3291 | ||
| 3292 |
query.project = Project.find(1) |
|
| 3293 |
assert_equal [1, 2, 3, 7], find_issues_with_query(query).map(&:id).sort |
|
| 3294 |
end |
|
| 3295 | ||
| 3274 | 3296 |
def test_project_status_filter_should_be_available_when_project_has_subprojects |
| 3275 | 3297 |
query = IssueQuery.new(:project => Project.find(1), :name => '_') |
| 3276 | 3298 |
assert query.available_filters.has_key?('project.status')
|