| 
									
										
										
										
											2011-07-06 16:57:04 +00:00
										 |  |  | # Redmine - project management software | 
					
						
							| 
									
										
										
										
											2016-03-13 10:30:10 +00:00
										 |  |  | # Copyright (C) 2006-2016  Jean-Philippe Lang | 
					
						
							| 
									
										
										
										
											2006-12-16 13:37:32 +00:00
										 |  |  | # | 
					
						
							|  |  |  | # This program is free software; you can redistribute it and/or | 
					
						
							|  |  |  | # modify it under the terms of the GNU General Public License | 
					
						
							|  |  |  | # as published by the Free Software Foundation; either version 2 | 
					
						
							|  |  |  | # of the License, or (at your option) any later version. | 
					
						
							| 
									
										
										
										
											2011-08-31 12:02:01 +00:00
										 |  |  | # | 
					
						
							| 
									
										
										
										
											2006-12-16 13:37:32 +00:00
										 |  |  | # This program is distributed in the hope that it will be useful, | 
					
						
							|  |  |  | # but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							|  |  |  | # GNU General Public License for more details. | 
					
						
							| 
									
										
										
										
											2011-08-31 12:02:01 +00:00
										 |  |  | # | 
					
						
							| 
									
										
										
										
											2006-12-16 13:37:32 +00:00
										 |  |  | # You should have received a copy of the GNU General Public License | 
					
						
							|  |  |  | # along with this program; if not, write to the Free Software | 
					
						
							|  |  |  | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class QueriesController < ApplicationController | 
					
						
							| 
									
										
										
										
											2008-01-19 11:53:43 +00:00
										 |  |  |   menu_item :issues | 
					
						
							| 
									
										
										
										
											2011-10-24 20:19:26 +00:00
										 |  |  |   before_filter :find_query, :except => [:new, :create, :index] | 
					
						
							|  |  |  |   before_filter :find_optional_project, :only => [:new, :create] | 
					
						
							| 
									
										
										
										
											2011-08-31 12:02:01 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-09 08:56:07 +00:00
										 |  |  |   accept_api_auth :index | 
					
						
							| 
									
										
										
										
											2011-08-31 12:02:01 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-24 20:19:26 +00:00
										 |  |  |   include QueriesHelper | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-06 16:57:04 +00:00
										 |  |  |   def index | 
					
						
							|  |  |  |     case params[:format] | 
					
						
							|  |  |  |     when 'xml', 'json' | 
					
						
							|  |  |  |       @offset, @limit = api_offset_and_limit | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |       @limit = per_page_option | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2012-12-09 14:10:49 +00:00
										 |  |  |     @query_count = IssueQuery.visible.count | 
					
						
							| 
									
										
										
										
											2013-01-08 20:18:12 +00:00
										 |  |  |     @query_pages = Paginator.new @query_count, @limit, params['page'] | 
					
						
							| 
									
										
										
										
											2014-01-10 10:30:57 +00:00
										 |  |  |     @queries = IssueQuery.visible. | 
					
						
							|  |  |  |                     order("#{Query.table_name}.name"). | 
					
						
							|  |  |  |                     limit(@limit). | 
					
						
							|  |  |  |                     offset(@offset). | 
					
						
							| 
									
										
										
										
											2014-10-22 17:37:16 +00:00
										 |  |  |                     to_a | 
					
						
							| 
									
										
										
										
											2011-07-06 16:57:04 +00:00
										 |  |  |     respond_to do |format| | 
					
						
							| 
									
										
										
										
											2014-10-22 17:37:16 +00:00
										 |  |  |       format.html {render_error :status => 406} | 
					
						
							| 
									
										
										
										
											2011-07-06 16:57:04 +00:00
										 |  |  |       format.api | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2011-08-31 12:02:01 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-06-23 13:49:29 +00:00
										 |  |  |   def new | 
					
						
							| 
									
										
										
										
											2012-12-09 14:10:49 +00:00
										 |  |  |     @query = IssueQuery.new | 
					
						
							| 
									
										
										
										
											2007-11-20 15:40:16 +00:00
										 |  |  |     @query.user = User.current | 
					
						
							| 
									
										
										
										
											2011-10-24 20:19:26 +00:00
										 |  |  |     @query.project = @project | 
					
						
							| 
									
										
										
										
											2012-12-09 15:11:00 +00:00
										 |  |  |     @query.build_from_params(params) | 
					
						
							| 
									
										
										
										
											2011-10-24 20:19:26 +00:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2011-08-31 12:02:01 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-24 20:19:26 +00:00
										 |  |  |   def create | 
					
						
							| 
									
										
										
										
											2015-06-29 16:06:37 +00:00
										 |  |  |     @query = IssueQuery.new | 
					
						
							| 
									
										
										
										
											2011-10-24 20:19:26 +00:00
										 |  |  |     @query.user = User.current | 
					
						
							| 
									
										
										
										
											2015-06-29 16:06:37 +00:00
										 |  |  |     @query.project = @project | 
					
						
							|  |  |  |     update_query_from_params | 
					
						
							| 
									
										
										
										
											2011-08-31 12:02:01 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-24 20:19:26 +00:00
										 |  |  |     if @query.save | 
					
						
							| 
									
										
										
										
											2007-06-23 13:49:29 +00:00
										 |  |  |       flash[:notice] = l(:notice_successful_create) | 
					
						
							| 
									
										
										
										
											2013-07-14 13:41:30 +00:00
										 |  |  |       redirect_to_issues(:query_id => @query) | 
					
						
							| 
									
										
										
										
											2011-10-24 20:19:26 +00:00
										 |  |  |     else | 
					
						
							|  |  |  |       render :action => 'new', :layout => !request.xhr? | 
					
						
							| 
									
										
										
										
											2007-06-23 13:49:29 +00:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2011-08-31 12:02:01 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-12-16 13:37:32 +00:00
										 |  |  |   def edit | 
					
						
							| 
									
										
										
										
											2011-10-24 20:19:26 +00:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2011-08-31 12:02:01 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-24 20:19:26 +00:00
										 |  |  |   def update | 
					
						
							| 
									
										
										
										
											2015-06-29 16:06:37 +00:00
										 |  |  |     update_query_from_params | 
					
						
							| 
									
										
										
										
											2011-10-24 20:19:26 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if @query.save | 
					
						
							|  |  |  |       flash[:notice] = l(:notice_successful_update) | 
					
						
							| 
									
										
										
										
											2013-07-14 13:41:30 +00:00
										 |  |  |       redirect_to_issues(:query_id => @query) | 
					
						
							| 
									
										
										
										
											2011-10-24 20:19:26 +00:00
										 |  |  |     else | 
					
						
							|  |  |  |       render :action => 'edit' | 
					
						
							| 
									
										
										
										
											2006-12-16 13:37:32 +00:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def destroy | 
					
						
							| 
									
										
										
										
											2011-10-24 20:19:26 +00:00
										 |  |  |     @query.destroy | 
					
						
							| 
									
										
										
										
											2013-07-14 13:41:30 +00:00
										 |  |  |     redirect_to_issues(:set_filter => 1) | 
					
						
							| 
									
										
										
										
											2006-12-16 13:37:32 +00:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2011-08-31 12:02:01 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-12-16 13:37:32 +00:00
										 |  |  | private | 
					
						
							| 
									
										
										
										
											2008-03-30 12:29:07 +00:00
										 |  |  |   def find_query | 
					
						
							| 
									
										
										
										
											2012-12-09 14:10:49 +00:00
										 |  |  |     @query = IssueQuery.find(params[:id]) | 
					
						
							| 
									
										
										
										
											2008-03-30 12:29:07 +00:00
										 |  |  |     @project = @query.project | 
					
						
							|  |  |  |     render_403 unless @query.editable_by?(User.current) | 
					
						
							|  |  |  |   rescue ActiveRecord::RecordNotFound | 
					
						
							|  |  |  |     render_404 | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2011-08-31 12:02:01 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-03-30 14:20:07 +00:00
										 |  |  |   def find_optional_project | 
					
						
							|  |  |  |     @project = Project.find(params[:project_id]) if params[:project_id] | 
					
						
							| 
									
										
										
										
											2010-03-24 20:25:09 +00:00
										 |  |  |     render_403 unless User.current.allowed_to?(:save_queries, @project, :global => true) | 
					
						
							| 
									
										
										
										
											2007-01-02 08:47:07 +00:00
										 |  |  |   rescue ActiveRecord::RecordNotFound | 
					
						
							|  |  |  |     render_404 | 
					
						
							| 
									
										
										
										
											2006-12-16 13:37:32 +00:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2013-07-14 13:41:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-29 16:06:37 +00:00
										 |  |  |   def update_query_from_params | 
					
						
							|  |  |  |     @query.project = params[:query_is_for_all] ? nil : @project | 
					
						
							|  |  |  |     @query.build_from_params(params) | 
					
						
							|  |  |  |     @query.column_names = nil if params[:default_columns] | 
					
						
							|  |  |  |     @query.sort_criteria = params[:query] && params[:query][:sort_criteria] | 
					
						
							|  |  |  |     @query.name = params[:query] && params[:query][:name] | 
					
						
							|  |  |  |     if User.current.allowed_to?(:manage_public_queries, @query.project) || User.current.admin? | 
					
						
							|  |  |  |       @query.visibility = (params[:query] && params[:query][:visibility]) || IssueQuery::VISIBILITY_PRIVATE | 
					
						
							| 
									
										
										
										
											2015-08-02 07:02:44 +00:00
										 |  |  |       @query.role_ids = params[:query] && params[:query][:role_ids] | 
					
						
							| 
									
										
										
										
											2015-06-29 16:06:37 +00:00
										 |  |  |     else | 
					
						
							|  |  |  |       @query.visibility = IssueQuery::VISIBILITY_PRIVATE | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |     @query | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-14 13:41:30 +00:00
										 |  |  |   def redirect_to_issues(options) | 
					
						
							|  |  |  |     if params[:gantt] | 
					
						
							|  |  |  |       if @project | 
					
						
							|  |  |  |         redirect_to project_gantt_path(@project, options) | 
					
						
							|  |  |  |       else | 
					
						
							|  |  |  |         redirect_to issues_gantt_path(options) | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |       redirect_to _project_issues_path(@project, options) | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2006-12-16 13:37:32 +00:00
										 |  |  | end |