To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / app / controllers / queries_controller.rb @ 912:5e80956cc792
History | View | Annotate | Download (3.79 KB)
| 1 | 909:cbb26bc654de | Chris | # Redmine - project management software
|
|---|---|---|---|
| 2 | # Copyright (C) 2006-2011 Jean-Philippe Lang
|
||
| 3 | 0:513646585e45 | Chris | #
|
| 4 | # This program is free software; you can redistribute it and/or
|
||
| 5 | # modify it under the terms of the GNU General Public License
|
||
| 6 | # as published by the Free Software Foundation; either version 2
|
||
| 7 | # of the License, or (at your option) any later version.
|
||
| 8 | 909:cbb26bc654de | Chris | #
|
| 9 | 0:513646585e45 | Chris | # This program is distributed in the hope that it will be useful,
|
| 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
| 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
| 12 | # GNU General Public License for more details.
|
||
| 13 | 909:cbb26bc654de | Chris | #
|
| 14 | 0:513646585e45 | Chris | # You should have received a copy of the GNU General Public License
|
| 15 | # along with this program; if not, write to the Free Software
|
||
| 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||
| 17 | |||
| 18 | class QueriesController < ApplicationController |
||
| 19 | menu_item :issues
|
||
| 20 | 909:cbb26bc654de | Chris | before_filter :find_query, :except => [:new, :create, :index] |
| 21 | before_filter :find_optional_project, :only => [:new, :create] |
||
| 22 | |||
| 23 | accept_api_auth :index
|
||
| 24 | |||
| 25 | include QueriesHelper
|
||
| 26 | |||
| 27 | def index |
||
| 28 | case params[:format] |
||
| 29 | when 'xml', 'json' |
||
| 30 | @offset, @limit = api_offset_and_limit |
||
| 31 | else
|
||
| 32 | @limit = per_page_option
|
||
| 33 | 0:513646585e45 | Chris | end
|
| 34 | 909:cbb26bc654de | Chris | |
| 35 | @query_count = Query.visible.count |
||
| 36 | @query_pages = Paginator.new self, @query_count, @limit, params['page'] |
||
| 37 | @queries = Query.visible.all(:limit => @limit, :offset => @offset, :order => "#{Query.table_name}.name") |
||
| 38 | |||
| 39 | respond_to do |format|
|
||
| 40 | format.html { render :nothing => true }
|
||
| 41 | format.api |
||
| 42 | 0:513646585e45 | Chris | end
|
| 43 | end
|
||
| 44 | |||
| 45 | 909:cbb26bc654de | Chris | def new |
| 46 | @query = Query.new |
||
| 47 | @query.user = User.current |
||
| 48 | @query.project = @project |
||
| 49 | @query.is_public = false unless User.current.allowed_to?(:manage_public_queries, @project) || User.current.admin? |
||
| 50 | build_query_from_params |
||
| 51 | end
|
||
| 52 | |||
| 53 | verify :method => :post, :only => :create, :render => {:nothing => true, :status => :method_not_allowed } |
||
| 54 | def create |
||
| 55 | @query = Query.new(params[:query]) |
||
| 56 | @query.user = User.current |
||
| 57 | @query.project = params[:query_is_for_all] ? nil : @project |
||
| 58 | @query.is_public = false unless User.current.allowed_to?(:manage_public_queries, @project) || User.current.admin? |
||
| 59 | build_query_from_params |
||
| 60 | @query.column_names = nil if params[:default_columns] |
||
| 61 | |||
| 62 | if @query.save |
||
| 63 | flash[:notice] = l(:notice_successful_create) |
||
| 64 | redirect_to :controller => 'issues', :action => 'index', :project_id => @project, :query_id => @query |
||
| 65 | else
|
||
| 66 | render :action => 'new', :layout => !request.xhr? |
||
| 67 | end
|
||
| 68 | end
|
||
| 69 | |||
| 70 | def edit |
||
| 71 | end
|
||
| 72 | |||
| 73 | verify :method => :put, :only => :update, :render => {:nothing => true, :status => :method_not_allowed } |
||
| 74 | def update |
||
| 75 | @query.attributes = params[:query] |
||
| 76 | @query.project = nil if params[:query_is_for_all] |
||
| 77 | @query.is_public = false unless User.current.allowed_to?(:manage_public_queries, @project) || User.current.admin? |
||
| 78 | build_query_from_params |
||
| 79 | @query.column_names = nil if params[:default_columns] |
||
| 80 | |||
| 81 | if @query.save |
||
| 82 | flash[:notice] = l(:notice_successful_update) |
||
| 83 | redirect_to :controller => 'issues', :action => 'index', :project_id => @project, :query_id => @query |
||
| 84 | else
|
||
| 85 | render :action => 'edit' |
||
| 86 | end
|
||
| 87 | end
|
||
| 88 | |||
| 89 | verify :method => :delete, :only => :destroy, :render => {:nothing => true, :status => :method_not_allowed } |
||
| 90 | 0:513646585e45 | Chris | def destroy |
| 91 | 909:cbb26bc654de | Chris | @query.destroy
|
| 92 | 0:513646585e45 | Chris | redirect_to :controller => 'issues', :action => 'index', :project_id => @project, :set_filter => 1 |
| 93 | end
|
||
| 94 | 909:cbb26bc654de | Chris | |
| 95 | 0:513646585e45 | Chris | private |
| 96 | def find_query |
||
| 97 | @query = Query.find(params[:id]) |
||
| 98 | @project = @query.project |
||
| 99 | render_403 unless @query.editable_by?(User.current) |
||
| 100 | rescue ActiveRecord::RecordNotFound |
||
| 101 | render_404 |
||
| 102 | end
|
||
| 103 | 909:cbb26bc654de | Chris | |
| 104 | 0:513646585e45 | Chris | def find_optional_project |
| 105 | @project = Project.find(params[:project_id]) if params[:project_id] |
||
| 106 | render_403 unless User.current.allowed_to?(:save_queries, @project, :global => true) |
||
| 107 | rescue ActiveRecord::RecordNotFound |
||
| 108 | render_404 |
||
| 109 | end
|
||
| 110 | end |