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.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2013 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. menu_item :issues
  19. before_filter :find_query, :except => [:new, :create, :index]
  20. before_filter :find_optional_project, :only => [:new, :create]
  21. accept_api_auth :index
  22. include QueriesHelper
  23. def index
  24. case params[:format]
  25. when 'xml', 'json'
  26. @offset, @limit = api_offset_and_limit
  27. else
  28. @limit = per_page_option
  29. end
  30. @query_count = IssueQuery.visible.count
  31. @query_pages = Paginator.new @query_count, @limit, params['page']
  32. @queries = IssueQuery.visible.all(:limit => @limit, :offset => @offset, :order => "#{Query.table_name}.name")
  33. respond_to do |format|
  34. format.api
  35. end
  36. end
  37. def new
  38. @query = IssueQuery.new
  39. @query.user = User.current
  40. @query.project = @project
  41. @query.is_public = false unless User.current.allowed_to?(:manage_public_queries, @project) || User.current.admin?
  42. @query.build_from_params(params)
  43. end
  44. def create
  45. @query = IssueQuery.new(params[:query])
  46. @query.user = User.current
  47. @query.project = params[:query_is_for_all] ? nil : @project
  48. @query.is_public = false unless User.current.allowed_to?(:manage_public_queries, @project) || User.current.admin?
  49. @query.build_from_params(params)
  50. @query.column_names = nil if params[:default_columns]
  51. if @query.save
  52. flash[:notice] = l(:notice_successful_create)
  53. redirect_to _project_issues_path(@project, :query_id => @query)
  54. else
  55. render :action => 'new', :layout => !request.xhr?
  56. end
  57. end
  58. def edit
  59. end
  60. def update
  61. @query.attributes = params[:query]
  62. @query.project = nil if params[:query_is_for_all]
  63. @query.is_public = false unless User.current.allowed_to?(:manage_public_queries, @project) || User.current.admin?
  64. @query.build_from_params(params)
  65. @query.column_names = nil if params[:default_columns]
  66. if @query.save
  67. flash[:notice] = l(:notice_successful_update)
  68. redirect_to _project_issues_path(@project, :query_id => @query)
  69. else
  70. render :action => 'edit'
  71. end
  72. end
  73. def destroy
  74. @query.destroy
  75. redirect_to _project_issues_path(@project, :set_filter => 1)
  76. end
  77. private
  78. def find_query
  79. @query = IssueQuery.find(params[:id])
  80. @project = @query.project
  81. render_403 unless @query.editable_by?(User.current)
  82. rescue ActiveRecord::RecordNotFound
  83. render_404
  84. end
  85. def find_optional_project
  86. @project = Project.find(params[:project_id]) if params[:project_id]
  87. render_403 unless User.current.allowed_to?(:save_queries, @project, :global => true)
  88. rescue ActiveRecord::RecordNotFound
  89. render_404
  90. end
  91. end