Skip to content
This repository has been archived by the owner on Mar 29, 2019. It is now read-only.

Commit

Permalink
[#672] Allow each Query to control if subprojects are included or not
Browse files Browse the repository at this point in the history
  • Loading branch information
edavis10 committed Oct 26, 2011
1 parent 061beb4 commit 2b7a221
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 3 deletions.
1 change: 1 addition & 0 deletions app/controllers/queries_controller.rb
Expand Up @@ -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?

Expand Down
5 changes: 3 additions & 2 deletions app/helpers/queries_helper.rb
Expand Up @@ -83,11 +83,12 @@ def retrieve_query
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
Expand Down
3 changes: 2 additions & 1 deletion app/models/query.rb
Expand Up @@ -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
Expand Down Expand Up @@ -352,7 +353,7 @@ def project_statement
# 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(',')
Expand Down
14 changes: 14 additions & 0 deletions app/views/issues/index.rhtml
Expand Up @@ -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>
Expand Down
12 changes: 12 additions & 0 deletions app/views/queries/_form.rhtml
Expand Up @@ -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>
Expand Down
2 changes: 2 additions & 0 deletions config/locales/en.yml
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions 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
44 changes: 44 additions & 0 deletions test/unit/query_test.rb
Expand Up @@ -382,6 +382,50 @@ def test_editable_by
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 => "_")
Expand Down

0 comments on commit 2b7a221

Please sign in to comment.