[#672] Allow each Query to control if subprojects are included or not

This commit is contained in:
Eric Davis 2011-10-25 18:13:32 -07:00
parent 061beb4967
commit 2b7a221dee
8 changed files with 87 additions and 3 deletions

View File

@ -19,6 +19,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?

View File

@ -83,11 +83,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

View File

@ -81,6 +81,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
@ -352,7 +353,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(',')

View File

@ -29,6 +29,20 @@
<td><%= l(:field_group_by) %></td>
<td><%= select_tag('group_by', options_for_select([[]] + @query.groupable_columns.collect {|c| [c.caption, c.name.to_s]}, @query.group_by)) %></td>
</tr>
<tr>
<td><%= l(:label_project_plural) %></td>
<td>
<label>
<%= radio_button_tag('display_subprojects', '0', !@query.display_subprojects?) %>
<%= l(:text_current_project) %>
</label>
<br />
<label>
<%= radio_button_tag('display_subprojects', '1', @query.display_subprojects?) %>
<%= l(:label_and_its_subprojects, :value => l(:text_current_project)) %>
</label>
</td>
</tr>
</table>
</div>
</fieldset>

View File

@ -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?))) %></p>
<p><label><%= l(:label_project_plural) %></label>
<label style="text-align: left; float: none; margin-left: 0px;font-weight: normal">
<%= radio_button_tag('display_subprojects', '0', !@query.display_subprojects?) %>
<%= l(:text_current_project) %>
</label>
<br />
<label style="text-align: left; float: none; margin-left: 0px;font-weight: normal">
<%= radio_button_tag('display_subprojects', '1', @query.display_subprojects?) %>
<%= l(:label_and_its_subprojects, :value => l(:text_current_project)) %>
</label>
</p>
<p><label for="query_default_columns"><%=l(:label_default_columns)%></label>
<%= 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")}' %></p>

View File

@ -935,6 +935,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

View File

@ -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

View File

@ -382,6 +382,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 => "_")