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 @ 438:34214e593c67

History | View | Annotate | Download (2.93 KB)

1
# redMine - project management software
2
# Copyright (C) 2006-2007  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
21
  before_filter :find_optional_project, :only => :new
22
  
23
  def new
24
    @query = Query.new(params[:query])
25
    @query.project = params[:query_is_for_all] ? nil : @project
26
    @query.user = User.current
27
    @query.is_public = false unless User.current.allowed_to?(:manage_public_queries, @project) || User.current.admin?
28
    @query.column_names = nil if params[:default_columns]
29
    
30
    @query.add_filters(params[:fields], params[:operators], params[:values]) if params[:fields]
31
    @query.group_by ||= params[:group_by]
32
    
33
    if request.post? && params[:confirm] && @query.save
34
      flash[:notice] = l(:notice_successful_create)
35
      redirect_to :controller => 'issues', :action => 'index', :project_id => @project, :query_id => @query
36
      return
37
    end
38
    render :layout => false if request.xhr?
39
  end
40
  
41
  def edit
42
    if request.post?
43
      @query.filters = {}
44
      @query.add_filters(params[:fields], params[:operators], params[:values]) if params[:fields]
45
      @query.attributes = params[:query]
46
      @query.project = nil if params[:query_is_for_all]
47
      @query.is_public = false unless User.current.allowed_to?(:manage_public_queries, @project) || User.current.admin?
48
      @query.column_names = nil if params[:default_columns]
49
      
50
      if @query.save
51
        flash[:notice] = l(:notice_successful_update)
52
        redirect_to :controller => 'issues', :action => 'index', :project_id => @project, :query_id => @query
53
      end
54
    end
55
  end
56

    
57
  def destroy
58
    @query.destroy if request.post?
59
    redirect_to :controller => 'issues', :action => 'index', :project_id => @project, :set_filter => 1
60
  end
61
  
62
private
63
  def find_query
64
    @query = Query.find(params[:id])
65
    @project = @query.project
66
    render_403 unless @query.editable_by?(User.current)
67
  rescue ActiveRecord::RecordNotFound
68
    render_404
69
  end
70
  
71
  def find_optional_project
72
    @project = Project.find(params[:project_id]) if params[:project_id]
73
    render_403 unless User.current.allowed_to?(:save_queries, @project, :global => true)
74
  rescue ActiveRecord::RecordNotFound
75
    render_404
76
  end
77
end