diff --git a/app/controllers/queries_controller.rb b/app/controllers/queries_controller.rb index e8f6a0a7..6a649ec1 100644 --- a/app/controllers/queries_controller.rb +++ b/app/controllers/queries_controller.rb @@ -20,6 +20,7 @@ class QueriesController < ApplicationController def new @query = Query.new(params[:query]) @query.project = params[:query_is_for_all] ? nil : @project + @query.display_subprojects = params[:display_subprojects] if params[:display_subprojects].present? @query.user = User.current @query.is_public = false unless User.current.allowed_to?(:manage_public_queries, @project) || User.current.admin? diff --git a/app/helpers/queries_helper.rb b/app/helpers/queries_helper.rb index d65aad61..0f2e6938 100644 --- a/app/helpers/queries_helper.rb +++ b/app/helpers/queries_helper.rb @@ -84,11 +84,12 @@ module QueriesHelper end end @query.group_by = params[:group_by] + @query.display_subprojects = params[:display_subprojects] if params[:display_subprojects] @query.column_names = params[:c] || (params[:query] && params[:query][:column_names]) - session[:query] = {:project_id => @query.project_id, :filters => @query.filters, :group_by => @query.group_by, :column_names => @query.column_names} + session[:query] = {:project_id => @query.project_id, :filters => @query.filters, :group_by => @query.group_by, :column_names => @query.column_names, :display_subprojects => @query.display_subprojects} else @query = Query.find_by_id(session[:query][:id]) if session[:query][:id] - @query ||= Query.new(:name => "_", :project => @project, :filters => session[:query][:filters], :group_by => session[:query][:group_by], :column_names => session[:query][:column_names]) + @query ||= Query.new(:name => "_", :project => @project, :filters => session[:query][:filters], :group_by => session[:query][:group_by], :column_names => session[:query][:column_names], :display_subprojects => session[:query][:display_subprojects]) @query.project = @project end end diff --git a/app/models/query.rb b/app/models/query.rb index 72b6d412..d3c8d04c 100644 --- a/app/models/query.rb +++ b/app/models/query.rb @@ -82,6 +82,7 @@ class Query < ActiveRecord::Base def initialize(attributes = nil) super attributes self.filters ||= { 'status_id' => {:operator => "o", :values => [""]} } + self.display_subprojects ||= Setting.display_subprojects_issues? end def after_initialize @@ -353,7 +354,7 @@ class Query < ActiveRecord::Base # all subprojects ids += project.descendants.collect(&:id) end - elsif Setting.display_subprojects_issues? + elsif display_subprojects? ids += project.descendants.collect(&:id) end project_clauses << "#{Project.table_name}.id IN (%s)" % ids.join(',') diff --git a/app/views/issues/index.rhtml b/app/views/issues/index.rhtml index a4974771..aadd2dbc 100644 --- a/app/views/issues/index.rhtml +++ b/app/views/issues/index.rhtml @@ -34,6 +34,20 @@ <%= select_tag('group_by', options_for_select([[]] + @query.groupable_columns.collect {|c| [c.caption, c.name.to_s]}, @query.group_by)) %> + + <%= l(:label_project_plural) %> + + +
+ + + diff --git a/app/views/queries/_form.rhtml b/app/views/queries/_form.rhtml index 5db801a2..132b59e7 100644 --- a/app/views/queries/_form.rhtml +++ b/app/views/queries/_form.rhtml @@ -16,6 +16,18 @@ <%= check_box_tag 'query_is_for_all', 1, @query.project.nil?, :disabled => (!@query.new_record? && (@query.project.nil? || (@query.is_public? && !User.current.admin?))) %>

+

+ +
+ +

+

<%= check_box_tag 'default_columns', 1, @query.has_default_columns?, :id => 'query_default_columns', :onclick => 'if (this.checked) {Element.hide("columns")} else {Element.show("columns")}' %>

diff --git a/config/locales/en.yml b/config/locales/en.yml index 8560fc8f..fac284e3 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -936,6 +936,8 @@ en: text_default_encoding: "Default: UTF-8" text_mercurial_repo_example: "local repository (e.g. /hgrepo, c:\\hgrepo)" text_git_repo_example: "a bare and local repository (e.g. /gitrepo, c:\\gitrepo)" + text_display_subprojects: Display subprojects + text_current_project: Current project default_role_manager: Manager default_role_developer: Developer diff --git a/db/migrate/20111025231354_add_display_subprojects_to_query.rb b/db/migrate/20111025231354_add_display_subprojects_to_query.rb new file mode 100644 index 00000000..78c6335e --- /dev/null +++ b/db/migrate/20111025231354_add_display_subprojects_to_query.rb @@ -0,0 +1,9 @@ +class AddDisplaySubprojectsToQuery < ActiveRecord::Migration + def self.up + add_column :queries, :display_subprojects, :boolean + end + + def self.down + remove_column :queries, :display_subprojects + end +end diff --git a/test/unit/query_test.rb b/test/unit/query_test.rb index 9ef009bb..43d8f282 100644 --- a/test/unit/query_test.rb +++ b/test/unit/query_test.rb @@ -383,6 +383,50 @@ class QueryTest < ActiveSupport::TestCase assert !q.editable_by?(developer) end + context "#display_subprojects" do + setup do + Setting.display_subprojects_issues = 0 + User.current = nil + end + + should "not include subprojects when false" do + query = Query.new(:project => Project.find(1), :name => '_') + query.display_subprojects = false + + issues = find_issues_with_query(query) + issue_ids = issues.collect(&:id) + + assert issue_ids.include?(1), "Didn't find issue 1 on current project" + assert !issue_ids.include?(5), "Issue 5 on sub-project included when it shouldn't be" + assert !issue_ids.include?(6), "Issue 6 on a private sub-project included when it shouldn't be" + end + + should "include subprojects when true" do + query = Query.new(:project => Project.find(1), :name => '_') + query.display_subprojects = true + + issues = find_issues_with_query(query) + issue_ids = issues.collect(&:id) + + assert issue_ids.include?(1), "Didn't find issue 1 on current project" + assert issue_ids.include?(5), "Didn't find issue 5 on sub-project" + assert !issue_ids.include?(6), "Issue 6 on a private sub-project included when it shouldn't be" + end + + should "include private subprojects automatically when true" do + User.current = User.find(2) + query = Query.new(:project => Project.find(1), :name => '_') + query.display_subprojects = true + + issues = find_issues_with_query(query) + issue_ids = issues.collect(&:id) + + assert issue_ids.include?(1), "Didn't find issue 1 on current project" + assert issue_ids.include?(5), "Didn't find issue 5 on sub-project" + assert issue_ids.include?(6), "Didn't find issue 6 on a private sub-project" + end + end + context "#available_filters" do setup do @query = Query.new(:name => "_")