You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

queries_controller.rb 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. class QueriesController < ApplicationController
  18. layout 'base'
  19. menu_item :issues
  20. before_filter :find_query, :except => :new
  21. before_filter :find_optional_project, :only => :new
  22. def new
  23. @query = Query.new(params[:query])
  24. @query.project = params[:query_is_for_all] ? nil : @project
  25. @query.user = User.current
  26. @query.is_public = false unless (@query.project && current_role.allowed_to?(:manage_public_queries)) || User.current.admin?
  27. @query.column_names = nil if params[:default_columns]
  28. params[:fields].each do |field|
  29. @query.add_filter(field, params[:operators][field], params[:values][field])
  30. end if params[:fields]
  31. if request.post? && params[:confirm] && @query.save
  32. flash[:notice] = l(:notice_successful_create)
  33. redirect_to :controller => 'issues', :action => 'index', :project_id => @project, :query_id => @query
  34. return
  35. end
  36. render :layout => false if request.xhr?
  37. end
  38. def edit
  39. if request.post?
  40. @query.filters = {}
  41. params[:fields].each do |field|
  42. @query.add_filter(field, params[:operators][field], params[:values][field])
  43. end if params[:fields]
  44. @query.attributes = params[:query]
  45. @query.project = nil if params[:query_is_for_all]
  46. @query.is_public = false unless (@query.project && current_role.allowed_to?(:manage_public_queries)) || User.current.admin?
  47. @query.column_names = nil if params[:default_columns]
  48. if @query.save
  49. flash[:notice] = l(:notice_successful_update)
  50. redirect_to :controller => 'issues', :action => 'index', :project_id => @project, :query_id => @query
  51. end
  52. end
  53. end
  54. def destroy
  55. @query.destroy if request.post?
  56. redirect_to :controller => 'issues', :action => 'index', :project_id => @project, :set_filter => 1
  57. end
  58. private
  59. def find_query
  60. @query = Query.find(params[:id])
  61. @project = @query.project
  62. render_403 unless @query.editable_by?(User.current)
  63. rescue ActiveRecord::RecordNotFound
  64. render_404
  65. end
  66. def find_optional_project
  67. @project = Project.find(params[:project_id]) if params[:project_id]
  68. User.current.allowed_to?(:save_queries, @project, :global => true)
  69. rescue ActiveRecord::RecordNotFound
  70. render_404
  71. end
  72. end