Merge pull request #111 from edavis10/ticket/unstable/672-query-subprojects
#672 Allow queries to include subproject issues
This commit is contained in:
commit
b1671e46f0
@ -20,6 +20,7 @@ class QueriesController < ApplicationController
|
|||||||
def new
|
def new
|
||||||
@query = Query.new(params[:query])
|
@query = Query.new(params[:query])
|
||||||
@query.project = params[:query_is_for_all] ? nil : @project
|
@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.user = User.current
|
||||||
@query.is_public = false unless User.current.allowed_to?(:manage_public_queries, @project) || User.current.admin?
|
@query.is_public = false unless User.current.allowed_to?(:manage_public_queries, @project) || User.current.admin?
|
||||||
|
|
||||||
|
@ -84,11 +84,12 @@ module QueriesHelper
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
@query.group_by = params[:group_by]
|
@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])
|
@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
|
else
|
||||||
@query = Query.find_by_id(session[:query][:id]) if session[:query][:id]
|
@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
|
@query.project = @project
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -82,6 +82,7 @@ class Query < ActiveRecord::Base
|
|||||||
def initialize(attributes = nil)
|
def initialize(attributes = nil)
|
||||||
super attributes
|
super attributes
|
||||||
self.filters ||= { 'status_id' => {:operator => "o", :values => [""]} }
|
self.filters ||= { 'status_id' => {:operator => "o", :values => [""]} }
|
||||||
|
self.display_subprojects ||= Setting.display_subprojects_issues?
|
||||||
end
|
end
|
||||||
|
|
||||||
def after_initialize
|
def after_initialize
|
||||||
@ -353,7 +354,7 @@ class Query < ActiveRecord::Base
|
|||||||
# all subprojects
|
# all subprojects
|
||||||
ids += project.descendants.collect(&:id)
|
ids += project.descendants.collect(&:id)
|
||||||
end
|
end
|
||||||
elsif Setting.display_subprojects_issues?
|
elsif display_subprojects?
|
||||||
ids += project.descendants.collect(&:id)
|
ids += project.descendants.collect(&:id)
|
||||||
end
|
end
|
||||||
project_clauses << "#{Project.table_name}.id IN (%s)" % ids.join(',')
|
project_clauses << "#{Project.table_name}.id IN (%s)" % ids.join(',')
|
||||||
|
@ -34,6 +34,20 @@
|
|||||||
<td><label for='group_by'><%= l(:field_group_by) %></label></td>
|
<td><label for='group_by'><%= l(:field_group_by) %></label></td>
|
||||||
<td><%= select_tag('group_by', options_for_select([[]] + @query.groupable_columns.collect {|c| [c.caption, c.name.to_s]}, @query.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>
|
||||||
|
<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>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
@ -16,6 +16,18 @@
|
|||||||
<%= check_box_tag 'query_is_for_all', 1, @query.project.nil?,
|
<%= 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>
|
: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>
|
<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',
|
<%= 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>
|
:onclick => 'if (this.checked) {Element.hide("columns")} else {Element.show("columns")}' %></p>
|
||||||
|
@ -936,6 +936,8 @@ en:
|
|||||||
text_default_encoding: "Default: UTF-8"
|
text_default_encoding: "Default: UTF-8"
|
||||||
text_mercurial_repo_example: "local repository (e.g. /hgrepo, c:\\hgrepo)"
|
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_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_manager: Manager
|
||||||
default_role_developer: Developer
|
default_role_developer: Developer
|
||||||
|
@ -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
|
@ -383,6 +383,50 @@ class QueryTest < ActiveSupport::TestCase
|
|||||||
assert !q.editable_by?(developer)
|
assert !q.editable_by?(developer)
|
||||||
end
|
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
|
context "#available_filters" do
|
||||||
setup do
|
setup do
|
||||||
@query = Query.new(:name => "_")
|
@query = Query.new(:name => "_")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user