To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / app / controllers / queries_controller.rb @ 957:35782bf2eb58

History | View | Annotate | Download (3.79 KB)

1
# Redmine - project management software
2
# Copyright (C) 2006-2011  Jean-Philippe Lang
3
#
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
#
9
# 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
#
14
# 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
  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
    end
34

    
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
    end
43
  end
44

    
45
  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
  def destroy
91
    @query.destroy
92
    redirect_to :controller => 'issues', :action => 'index', :project_id => @project, :set_filter => 1
93
  end
94

    
95
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

    
104
  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