Rescue invalid query statement error with an error message.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@3104 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
915bbcfaff
commit
99b52c8796
@ -26,6 +26,8 @@ class IssuesController < ApplicationController
|
|||||||
before_filter :find_optional_project, :only => [:index, :changes, :gantt, :calendar]
|
before_filter :find_optional_project, :only => [:index, :changes, :gantt, :calendar]
|
||||||
accept_key_auth :index, :show, :changes
|
accept_key_auth :index, :show, :changes
|
||||||
|
|
||||||
|
rescue_from Query::StatementInvalid, :with => :query_statement_invalid
|
||||||
|
|
||||||
helper :journals
|
helper :journals
|
||||||
helper :projects
|
helper :projects
|
||||||
include ProjectsHelper
|
include ProjectsHelper
|
||||||
@ -507,4 +509,12 @@ private
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Rescues an invalid query statement. Just in case...
|
||||||
|
def query_statement_invalid(exception)
|
||||||
|
logger.error "Query::StatementInvalid: #{exception.message}" if logger
|
||||||
|
session.delete(:query)
|
||||||
|
sort_clear
|
||||||
|
render_error "An error occurred while executing the query and has been logged. Please report this error to your Redmine administrator."
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -61,6 +61,9 @@ class QueryCustomFieldColumn < QueryColumn
|
|||||||
end
|
end
|
||||||
|
|
||||||
class Query < ActiveRecord::Base
|
class Query < ActiveRecord::Base
|
||||||
|
class StatementInvalid < ::ActiveRecord::StatementInvalid
|
||||||
|
end
|
||||||
|
|
||||||
belongs_to :project
|
belongs_to :project
|
||||||
belongs_to :user
|
belongs_to :user
|
||||||
serialize :filters
|
serialize :filters
|
||||||
@ -392,6 +395,8 @@ class Query < ActiveRecord::Base
|
|||||||
# Returns the issue count
|
# Returns the issue count
|
||||||
def issue_count
|
def issue_count
|
||||||
Issue.count(:include => [:status, :project], :conditions => statement)
|
Issue.count(:include => [:status, :project], :conditions => statement)
|
||||||
|
rescue ::ActiveRecord::StatementInvalid => e
|
||||||
|
raise StatementInvalid.new(e.message)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns the issue count by group or nil if query is not grouped
|
# Returns the issue count by group or nil if query is not grouped
|
||||||
@ -406,6 +411,8 @@ class Query < ActiveRecord::Base
|
|||||||
else
|
else
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
rescue ::ActiveRecord::StatementInvalid => e
|
||||||
|
raise StatementInvalid.new(e.message)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns the issues
|
# Returns the issues
|
||||||
@ -419,6 +426,8 @@ class Query < ActiveRecord::Base
|
|||||||
:order => order_option,
|
:order => order_option,
|
||||||
:limit => options[:limit],
|
:limit => options[:limit],
|
||||||
:offset => options[:offset]
|
:offset => options[:offset]
|
||||||
|
rescue ::ActiveRecord::StatementInvalid => e
|
||||||
|
raise StatementInvalid.new(e.message)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns the journals
|
# Returns the journals
|
||||||
@ -429,6 +438,8 @@ class Query < ActiveRecord::Base
|
|||||||
:order => options[:order],
|
:order => options[:order],
|
||||||
:limit => options[:limit],
|
:limit => options[:limit],
|
||||||
:offset => options[:offset]
|
:offset => options[:offset]
|
||||||
|
rescue ::ActiveRecord::StatementInvalid => e
|
||||||
|
raise StatementInvalid.new(e.message)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns the versions
|
# Returns the versions
|
||||||
@ -436,6 +447,8 @@ class Query < ActiveRecord::Base
|
|||||||
def versions(options={})
|
def versions(options={})
|
||||||
Version.find :all, :include => :project,
|
Version.find :all, :include => :project,
|
||||||
:conditions => Query.merge_conditions(project_statement, options[:conditions])
|
:conditions => Query.merge_conditions(project_statement, options[:conditions])
|
||||||
|
rescue ::ActiveRecord::StatementInvalid => e
|
||||||
|
raise StatementInvalid.new(e.message)
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
@ -269,6 +269,13 @@ class QueryTest < ActiveSupport::TestCase
|
|||||||
assert_equal values.sort, values
|
assert_equal values.sort, values
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_invalid_query_should_raise_query_statement_invalid_error
|
||||||
|
q = Query.new
|
||||||
|
assert_raise Query::StatementInvalid do
|
||||||
|
q.issues(:conditions => "foo = 1")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_label_for
|
def test_label_for
|
||||||
q = Query.new
|
q = Query.new
|
||||||
assert_equal 'assigned_to', q.label_for('assigned_to_id')
|
assert_equal 'assigned_to', q.label_for('assigned_to_id')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user