##// END OF EJS Templates
Removed deprecated accept_key_auth methods....
Removed deprecated accept_key_auth methods. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@9392 e93f8b46-1217-0410-a6f0-8f06a7374b81

File last commit:

r9258:354e09811b5d
r9258:354e09811b5d
Show More
application_controller.rb
539 lines | 16.2 KiB | text/x-ruby | RubyLexer
/ app / controllers / application_controller.rb
Jean-Philippe Lang
Adds an issues visibility level on roles (#7412)....
r5296 # Redmine - project management software
# Copyright (C) 2006-2011 Jean-Philippe Lang
Jean-Philippe Lang
added svn:eol-style native property on /app files...
r330 #
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
Toshi MARUYAMA
remove trailing white-spaces from app/controllers/application_controller.rb....
r5629 #
Jean-Philippe Lang
added svn:eol-style native property on /app files...
r330 # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
Toshi MARUYAMA
remove trailing white-spaces from app/controllers/application_controller.rb....
r5629 #
Jean-Philippe Lang
added svn:eol-style native property on /app files...
r330 # You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Jean-Philippe Lang
Redirect user to the previous page after logging in (#1679)....
r1686 require 'uri'
Jean-Philippe Lang
Unescape back_url param before calling redirect_to....
r1891 require 'cgi'
Jean-Philippe Lang
Redirect user to the previous page after logging in (#1679)....
r1686
Jean-Philippe Lang
Fixed: private queries should not be accessible to other users (#8729)....
r6043 class Unauthorized < Exception; end
Jean-Philippe Lang
added svn:eol-style native property on /app files...
r330 class ApplicationController < ActionController::Base
Jean-Philippe Lang
Merged Rails 2.2 branch. Redmine now requires Rails 2.2.2....
r2430 include Redmine::I18n
Eric Davis
Upgraded to Rails 2.3.4 (#3597)...
r2773
Jean-Philippe Lang
Moves @layout 'base'@ to ApplicationController....
r1726 layout 'base'
Jean-Philippe Lang
Adds a pseudo format to api template names and overrides ActionController#default_template so that api templates are chosen automatically....
r4352 exempt_from_layout 'builder', 'rsb'
Toshi MARUYAMA
remove trailing white-spaces from app/controllers/application_controller.rb....
r6405
Jean-Philippe Lang
Sets forgery protection filter first....
r6195 protect_from_forgery
Jean-Philippe Lang
Remove autologin cookie on unverified request....
r6196 def handle_unverified_request
super
cookies.delete(:autologin)
end
Jean-Philippe Lang
Remove broken cookies after upgrade from 0.8.x to prevent an error from Rails (#4292)....
r2979 # Remove broken cookie after upgrade from 0.8.x (#4292)
# See https://rails.lighthouseapp.com/projects/8994/tickets/3360
# TODO: remove it when Rails is fixed
before_filter :delete_broken_cookies
def delete_broken_cookies
if cookies['_redmine_session'] && cookies['_redmine_session'] !~ /--/
Toshi MARUYAMA
remove trailing white-spaces from app/controllers/application_controller.rb....
r5629 cookies.delete '_redmine_session'
Jean-Philippe Lang
Removes "xxx and return" calls (#4446)....
r3071 redirect_to home_path
return false
Jean-Philippe Lang
Remove broken cookies after upgrade from 0.8.x to prevent an error from Rails (#4292)....
r2979 end
end
Toshi MARUYAMA
remove trailing white-spaces from app/controllers/application_controller.rb....
r5629
Toshi MARUYAMA
Ruby1.9: enforce UTF-8 encodings on the params hash on Rails2 (#4050, #4796)...
r8594 # FIXME: Remove this when all of Rack and Rails have learned how to
# properly use encodings
before_filter :params_filter
def params_filter
if RUBY_VERSION >= '1.9' && defined?(Rails) && Rails::VERSION::MAJOR < 3
self.utf8nize!(params)
end
end
def utf8nize!(obj)
Toshi MARUYAMA
Ruby1.9: skip enforcing UTF-8 encodings on the params hash on Rails2 if it is frozen (#4050, #4796)...
r8596 if obj.frozen?
obj
elsif obj.is_a? String
Toshi MARUYAMA
Ruby1.9: enforce UTF-8 encodings on the params hash on Rails2 (#4050, #4796)...
r8594 obj.respond_to?(:force_encoding) ? obj.force_encoding("UTF-8") : obj
elsif obj.is_a? Hash
obj.each {|k, v| obj[k] = self.utf8nize!(v)}
elsif obj.is_a? Array
obj.each {|v| self.utf8nize!(v)}
else
obj
end
end
Jean-Philippe Lang
Merged 0.6 branch into trunk....
r663 before_filter :user_setup, :check_if_login_required, :set_localization
Jean-Philippe Lang
added svn:eol-style native property on /app files...
r330 filter_parameter_logging :password
Toshi MARUYAMA
remove trailing white-spaces from app/controllers/application_controller.rb....
r5629
Jean-Philippe Lang
Display an error when authenticity token is invalid....
r2980 rescue_from ActionController::InvalidAuthenticityToken, :with => :invalid_authenticity_token
Jean-Philippe Lang
Fixed: private queries should not be accessible to other users (#8729)....
r6043 rescue_from ::Unauthorized, :with => :deny_access
Toshi MARUYAMA
remove trailing white-spaces from app/controllers/application_controller.rb....
r5629
Jean-Philippe Lang
Contextual quick search (#3263)....
r2829 include Redmine::Search::Controller
Jean-Philippe Lang
Highlight the current item of the main menu....
r1062 include Redmine::MenuManager::MenuController
helper Redmine::MenuManager::MenuHelper
Toshi MARUYAMA
remove trailing white-spaces from app/controllers/application_controller.rb....
r5629
Eric Davis
Converted the REDMINE_SUPPORTED_SCM constant to a class...
r3326 Redmine::Scm::Base.all.each do |scm|
Jean-Philippe Lang
Applied this fix http://dev.rubyonrails.org/ticket/4967 to solve namespaced models dependencies problem....
r558 require_dependency "repository/#{scm.underscore}"
end
Jean-Philippe Lang
Remove broken cookies after upgrade from 0.8.x to prevent an error from Rails (#4292)....
r2979
Jean-Philippe Lang
Merged 0.6 branch into trunk....
r663 def user_setup
Jean-Philippe Lang
Moved current user management to a dedicated method for modularity....
r1016 # Check the settings cache for each request
Jean-Philippe Lang
Added cache for application settings (Setting model)....
r674 Setting.check_cache
Jean-Philippe Lang
Moved current user management to a dedicated method for modularity....
r1016 # Find the current user
Jean-Philippe Lang
Do not start user session when accessing atom feed with token-based authentication....
r2679 User.current = find_current_user
Jean-Philippe Lang
Moved current user management to a dedicated method for modularity....
r1016 end
Toshi MARUYAMA
remove trailing white-spaces from app/controllers/application_controller.rb....
r5629
Jean-Philippe Lang
Moved current user management to a dedicated method for modularity....
r1016 # Returns the current user or nil if no user is logged in
Jean-Philippe Lang
Do not start user session when accessing atom feed with token-based authentication....
r2679 # and starts a session if needed
Jean-Philippe Lang
Moved current user management to a dedicated method for modularity....
r1016 def find_current_user
Jean-Philippe Lang
added svn:eol-style native property on /app files...
r330 if session[:user_id]
Jean-Philippe Lang
Merged 0.6 branch into trunk....
r663 # existing session
Jean-Philippe Lang
Replaces User.find_active with a named scope....
r2077 (User.active.find(session[:user_id]) rescue nil)
Jean-Philippe Lang
Merged 0.6 branch into trunk....
r663 elsif cookies[:autologin] && Setting.autologin?
Jean-Philippe Lang
Do not start user session when accessing atom feed with token-based authentication....
r2679 # auto-login feature starts a new session
user = User.try_to_autologin(cookies[:autologin])
session[:user_id] = user.id if user
user
Jean-Philippe Lang
Separation of RSS/API auth actions....
r6077 elsif params[:format] == 'atom' && params[:key] && request.get? && accept_rss_auth?
Jean-Philippe Lang
Do not start user session when accessing atom feed with token-based authentication....
r2679 # RSS key authentication does not start a session
Jean-Philippe Lang
Moved current user management to a dedicated method for modularity....
r1016 User.find_by_rss_key(params[:key])
Jean-Philippe Lang
Separation of RSS/API auth actions....
r6077 elsif Setting.rest_api_enabled? && accept_api_auth?
if (key = api_key_from_request)
Eric Davis
Added support for HTTP Basic access to the API. (#3920)...
r3105 # Use API key
Jean-Philippe Lang
Makes the API accepts the X-Redmine-API-Key header to hold the API key....
r4459 User.find_by_api_key(key)
Eric Davis
Added support for HTTP Basic access to the API. (#3920)...
r3105 else
# HTTP Basic, either username/password or API key/random
authenticate_with_http_basic do |username, password|
User.try_to_login(username, password) || User.find_by_api_key(username)
end
end
Jean-Philippe Lang
added svn:eol-style native property on /app files...
r330 end
end
Eric Davis
Added support for HTTP Basic access to the API. (#3920)...
r3105
Jean-Philippe Lang
Fixed: When logging in via an autologin cookie the user's last_login_on should be updated (#2820)....
r2460 # Sets the logged in user
def logged_user=(user)
Jean-Philippe Lang
Reset session on login/logout (#4248)....
r2966 reset_session
Jean-Philippe Lang
Fixed: When logging in via an autologin cookie the user's last_login_on should be updated (#2820)....
r2460 if user && user.is_a?(User)
User.current = user
session[:user_id] = user.id
else
User.current = User.anonymous
end
end
Toshi MARUYAMA
remove trailing white-spaces from app/controllers/application_controller.rb....
r5629
Jean-Philippe Lang
added svn:eol-style native property on /app files...
r330 # check if login is globally required to access the application
def check_if_login_required
Jean-Philippe Lang
Added autologin feature (disabled by default)....
r511 # no check needed if user is already logged in
Jean-Philippe Lang
Merged 0.6 branch into trunk....
r663 return true if User.current.logged?
Jean-Philippe Lang
added svn:eol-style native property on /app files...
r330 require_login if Setting.login_required?
Toshi MARUYAMA
remove trailing white-spaces from app/controllers/application_controller.rb....
r5629 end
Jean-Philippe Lang
added svn:eol-style native property on /app files...
r330 def set_localization
Jean-Philippe Lang
Merged Rails 2.2 branch. Redmine now requires Rails 2.2.2....
r2430 lang = nil
if User.current.logged?
lang = find_language(User.current.language)
end
if lang.nil? && request.env['HTTP_ACCEPT_LANGUAGE']
Jean-Philippe Lang
Fixed: 500 internal error when browsing any Redmine page in Epiphany (#5401)....
r3588 accept_lang = parse_qvalues(request.env['HTTP_ACCEPT_LANGUAGE']).first
Jean-Philippe Lang
Merged Rails 2.2 branch. Redmine now requires Rails 2.2.2....
r2430 if !accept_lang.blank?
Jean-Philippe Lang
Fixed: 500 internal error when browsing any Redmine page in Epiphany (#5401)....
r3588 accept_lang = accept_lang.downcase
Jean-Philippe Lang
Merged Rails 2.2 branch. Redmine now requires Rails 2.2.2....
r2430 lang = find_language(accept_lang) || find_language(accept_lang.split('-').first)
Jean-Philippe Lang
added svn:eol-style native property on /app files...
r330 end
Jean-Philippe Lang
Merged Rails 2.2 branch. Redmine now requires Rails 2.2.2....
r2430 end
lang ||= Setting.default_language
set_language_if_valid(lang)
Jean-Philippe Lang
added svn:eol-style native property on /app files...
r330 end
Toshi MARUYAMA
remove trailing white-spaces from app/controllers/application_controller.rb....
r5629
Jean-Philippe Lang
added svn:eol-style native property on /app files...
r330 def require_login
Jean-Philippe Lang
Merged 0.6 branch into trunk....
r663 if !User.current.logged?
Eric Davis
Fix 500 errors with a POST request that requires a login. #4216...
r2936 # Extract only the basic url parameters on non-GET requests
if request.get?
url = url_for(params)
else
url = url_for(:controller => params[:controller], :action => params[:action], :id => params[:id], :project_id => params[:project_id])
end
Eric Davis
Allow authenticating with an API token via XML or JSON. (#3920)...
r3104 respond_to do |format|
format.html { redirect_to :controller => "account", :action => "login", :back_url => url }
Eric Davis
Added support for HTTP Basic access to the API. (#3920)...
r3105 format.atom { redirect_to :controller => "account", :action => "login", :back_url => url }
Jean-Philippe Lang
Fixed: API 401 response does not include WWW-Authenticate header (#5322)....
r3565 format.xml { head :unauthorized, 'WWW-Authenticate' => 'Basic realm="Redmine API"' }
Eric Davis
Allow js formatted responses....
r3713 format.js { head :unauthorized, 'WWW-Authenticate' => 'Basic realm="Redmine API"' }
Jean-Philippe Lang
Fixed: API 401 response does not include WWW-Authenticate header (#5322)....
r3565 format.json { head :unauthorized, 'WWW-Authenticate' => 'Basic realm="Redmine API"' }
Eric Davis
Allow authenticating with an API token via XML or JSON. (#3920)...
r3104 end
Jean-Philippe Lang
added svn:eol-style native property on /app files...
r330 return false
end
true
end
def require_admin
return unless require_login
Jean-Philippe Lang
Merged 0.6 branch into trunk....
r663 if !User.current.admin?
Jean-Philippe Lang
A 403 error page is now displayed (instead of a blank page) when trying to access a protected page....
r492 render_403
Jean-Philippe Lang
added svn:eol-style native property on /app files...
r330 return false
end
true
end
Toshi MARUYAMA
remove trailing white-spaces from app/controllers/application_controller.rb....
r5629
Jean-Philippe Lang
Adds cross-project time reports support (#994)....
r1777 def deny_access
User.current.logged? ? render_403 : require_login
end
Jean-Philippe Lang
added svn:eol-style native property on /app files...
r330
Jean-Philippe Lang
Merged 0.6 branch into trunk....
r663 # Authorize the user for the requested action
Jean-Philippe Lang
Ability to allow non-admin users to create projects (#1007)....
r2651 def authorize(ctrl = params[:controller], action = params[:action], global = false)
Jean-Baptiste Barth
Added ability to delete issues from different projects through contextual menu (#5332)...
r4122 allowed = User.current.allowed_to?({:controller => ctrl, :action => action}, @project || @projects, :global => global)
Jean-Philippe Lang
Improved error message when trying to access an archived project (#2995)....
r4171 if allowed
true
else
if @project && @project.archived?
render_403 :message => :notice_not_authorized_archived_project
else
deny_access
end
end
Jean-Philippe Lang
added svn:eol-style native property on /app files...
r330 end
Jean-Philippe Lang
Ability to allow non-admin users to create projects (#1007)....
r2651
# Authorize the user for the requested action outside a project
def authorize_global(ctrl = params[:controller], action = params[:action], global = true)
authorize(ctrl, action, global)
end
Eric Davis
Refactor: Pull up several #find_project methods to ApplicationController...
r3256
# Find project of id params[:id]
def find_project
@project = Project.find(params[:id])
rescue ActiveRecord::RecordNotFound
render_404
end
Eric Davis
Refactor: Split the find_object methods to prep for a larger refactoring....
r3477
Eric Davis
Refactor: convert ProjectEnumerations to a resource on a project....
r3961 # Find project of id params[:project_id]
def find_project_by_project_id
@project = Project.find(params[:project_id])
rescue ActiveRecord::RecordNotFound
render_404
end
Eric Davis
Refactor: Pull up #find_optional_project to ApplicationController....
r3602 # Find a project based on params[:project_id]
# TODO: some subclasses override this, see about merging their logic
def find_optional_project
@project = Project.find(params[:project_id]) unless params[:project_id].blank?
allowed = User.current.allowed_to?({:controller => params[:controller], :action => params[:action]}, @project, :global => true)
allowed ? true : deny_access
rescue ActiveRecord::RecordNotFound
render_404
end
Eric Davis
Refactor: Split the find_object methods to prep for a larger refactoring....
r3477 # Finds and sets @project based on @object.project
def find_project_from_association
render_404 unless @object.present?
Toshi MARUYAMA
remove trailing white-spaces from app/controllers/application_controller.rb....
r5629
Eric Davis
Refactor: Split the find_object methods to prep for a larger refactoring....
r3477 @project = @object.project
end
Eric Davis
Refactor: Change the different find_object filters to share a common method....
r3483 def find_model_object
model = self.class.read_inheritable_attribute('model_object')
if model
@object = model.find(params[:id])
self.instance_variable_set('@' + controller_name.singularize, @object) if @object
end
rescue ActiveRecord::RecordNotFound
render_404
end
def self.model_object(model)
write_inheritable_attribute('model_object', model)
end
Eric Davis
Refactor: Pull up method to ApplicationController....
r3824
# Filter for bulk issue operations
def find_issues
@issues = Issue.find_all_by_id(params[:id] || params[:ids])
raise ActiveRecord::RecordNotFound if @issues.empty?
Jean-Philippe Lang
Adds an issues visibility level on roles (#7412)....
r5296 if @issues.detect {|issue| !issue.visible?}
deny_access
return
end
Jean-Baptiste Barth
Splitted #find_issues filter in ApplicationController to #find_issues and #check_project_uniqueness (#5332)...
r4114 @projects = @issues.collect(&:project).compact.uniq
@project = @projects.first if @projects.size == 1
rescue ActiveRecord::RecordNotFound
render_404
end
Toshi MARUYAMA
remove trailing white-spaces from app/controllers/application_controller.rb....
r5629
Jean-Philippe Lang
added svn:eol-style native property on /app files...
r330 # make sure that the user is a member of the project (or admin) if project is private
# used as a before_filter for actions that do not require any particular permission on the project
def check_project_privacy
Jean-Philippe Lang
Fixes #820: invalid project id causes a NoMethodError in SearchController (Angel Dobbs-Sciortino)....
r1223 if @project && @project.active?
Jean-Philippe Lang
Code cleanup....
r8833 if @project.visible?
Jean-Philippe Lang
Fixes #820: invalid project id causes a NoMethodError in SearchController (Angel Dobbs-Sciortino)....
r1223 true
else
Jean-Philippe Lang
Code cleanup....
r7859 deny_access
Jean-Philippe Lang
Fixes #820: invalid project id causes a NoMethodError in SearchController (Angel Dobbs-Sciortino)....
r1223 end
else
Jean-Philippe Lang
Added the ability to archive projects:...
r546 @project = nil
render_404
Jean-Philippe Lang
Fixes #820: invalid project id causes a NoMethodError in SearchController (Angel Dobbs-Sciortino)....
r1223 false
Jean-Philippe Lang
Added the ability to archive projects:...
r546 end
Jean-Philippe Lang
added svn:eol-style native property on /app files...
r330 end
Eric Davis
Refactor: extract back_url method to ApplicationController....
r3798 def back_url
params[:back_url] || request.env['HTTP_REFERER']
end
Jean-Philippe Lang
v0.2.0...
r5 def redirect_back_or_default(default)
Jean-Philippe Lang
Unescape back_url param before calling redirect_to....
r1891 back_url = CGI.unescape(params[:back_url].to_s)
Jean-Philippe Lang
Redirect user to the previous page after logging in (#1679)....
r1686 if !back_url.blank?
Jean-Philippe Lang
Rescue back_url param parsing on redirect....
r2124 begin
uri = URI.parse(back_url)
# do not redirect user to another host or to the login or register page
if (uri.relative? || (uri.host == request.host)) && !uri.path.match(%r{/(login|account/register)})
Jean-Philippe Lang
Removes "xxx and return" calls (#4446)....
r3071 redirect_to(back_url)
return
Jean-Philippe Lang
Rescue back_url param parsing on redirect....
r2124 end
rescue URI::InvalidURIError
# redirect to default
Jean-Philippe Lang
Redirect user to the previous page after logging in (#1679)....
r1686 end
Jean-Philippe Lang
v0.2.0...
r5 end
Jean-Philippe Lang
Redirect user to the previous page after logging in (#1679)....
r1686 redirect_to default
Toshi MARUYAMA
Fix potential Execution After Redirect bugs....
r5491 false
Jean-Philippe Lang
v0.2.0...
r5 end
Toshi MARUYAMA
remove trailing white-spaces from app/controllers/application_controller.rb....
r5629
Jean-Philippe Lang
Code cleanup....
r9229 # Redirects to the request referer if present, redirects to args or call block otherwise.
def redirect_to_referer_or(*args, &block)
redirect_to :back
rescue ::ActionController::RedirectBackError
if args.any?
redirect_to *args
elsif block_given?
block.call
else
raise "#redirect_to_referer_or takes arguments or a block"
end
end
Jean-Philippe Lang
Improved error message when trying to access an archived project (#2995)....
r4171 def render_403(options={})
Jean-Philippe Lang
A 403 error page is now displayed (instead of a blank page) when trying to access a protected page....
r492 @project = nil
Jean-Philippe Lang
Refactor: merged error rendering methods....
r4172 render_error({:message => :notice_not_authorized, :status => 403}.merge(options))
Jean-Philippe Lang
A 403 error page is now displayed (instead of a blank page) when trying to access a protected page....
r492 return false
end
Toshi MARUYAMA
remove trailing white-spaces from app/controllers/application_controller.rb....
r5629
Jean-Philippe Lang
Refactor: merged error rendering methods....
r4172 def render_404(options={})
render_error({:message => :notice_file_not_found, :status => 404}.merge(options))
Jean-Philippe Lang
added svn:eol-style native property on /app files...
r330 return false
end
Toshi MARUYAMA
remove trailing white-spaces from app/controllers/application_controller.rb....
r5629
Jean-Philippe Lang
Refactor: merged error rendering methods....
r4172 # Renders an error response
def render_error(arg)
arg = {:message => arg} unless arg.is_a?(Hash)
Toshi MARUYAMA
remove trailing white-spaces from app/controllers/application_controller.rb....
r5629
Jean-Philippe Lang
Refactor: merged error rendering methods....
r4172 @message = arg[:message]
@message = l(@message) if @message.is_a?(Symbol)
@status = arg[:status] || 500
Toshi MARUYAMA
remove trailing white-spaces from app/controllers/application_controller.rb....
r5629
Jean-Philippe Lang
XML REST API for issues that provides CRUD operations for Issues (#1214)....
r3196 respond_to do |format|
Jean-Philippe Lang
Refactor: merged error rendering methods....
r4172 format.html {
render :template => 'common/error', :layout => use_layout, :status => @status
Jean-Philippe Lang
XML REST API for issues that provides CRUD operations for Issues (#1214)....
r3196 }
Jean-Philippe Lang
Refactor: merged error rendering methods....
r4172 format.atom { head @status }
format.xml { head @status }
format.js { head @status }
format.json { head @status }
Jean-Philippe Lang
XML REST API for issues that provides CRUD operations for Issues (#1214)....
r3196 end
Jean-Philippe Lang
Show explicit error message when the scm command failed (eg. when svn binary is not available)....
r1080 end
Jean-Philippe Lang
Adds API response to /trackers to get the list of all available trackers (#7181)....
r7757
# Filter for actions that provide an API response
# but have no HTML representation for non admin users
def require_admin_or_api_request
return true if api_request?
if User.current.admin?
true
elsif User.current.logged?
render_error(:status => 406)
else
deny_access
end
end
Eric Davis
Use the base layout for all 403, 404, and 500 pages. #6172...
r3835
# Picks which layout to use based on the request
#
# @return [boolean, string] name of the layout to use or false for no layout
def use_layout
request.xhr? ? false : 'base'
end
Toshi MARUYAMA
remove trailing white-spaces from app/controllers/application_controller.rb....
r5629
Jean-Philippe Lang
Display an error when authenticity token is invalid....
r2980 def invalid_authenticity_token
Jean-Philippe Lang
Adds a log message when an API call raises an InvalidAuthenticityToken error....
r3218 if api_request?
logger.error "Form authenticity token is missing or is invalid. API calls must include a proper Content-type header (text/xml or text/json)."
end
Jean-Philippe Lang
Display an error when authenticity token is invalid....
r2980 render_error "Invalid form authenticity token."
end
Toshi MARUYAMA
remove trailing white-spaces from app/controllers/application_controller.rb....
r5629
def render_feed(items, options={})
Jean-Philippe Lang
Added atom feed on the new cross-project issue list....
r675 @items = items || []
@items.sort! {|x,y| y.event_datetime <=> x.event_datetime }
Jean-Philippe Lang
Fixed: Feed content limit setting has no effect (closes #954)....
r1295 @items = @items.slice(0, Setting.feeds_limit.to_i)
Jean-Philippe Lang
Merged 0.6 branch into trunk....
r663 @title = options[:title] || Setting.app_title
Toshi MARUYAMA
remove hard-coded '.rxml' from ApplicationController 'render_feed' (#6317)...
r7453 render :template => "common/feed.atom", :layout => false,
:content_type => 'application/atom+xml'
Jean-Philippe Lang
Merged 0.6 branch into trunk....
r663 end
Toshi MARUYAMA
remove trailing white-spaces from app/controllers/application_controller.rb....
r6405
Jean-Philippe Lang
Separation of RSS/API auth actions....
r6077 def self.accept_rss_auth(*actions)
if actions.any?
write_inheritable_attribute('accept_rss_auth_actions', actions)
else
read_inheritable_attribute('accept_rss_auth_actions') || []
end
end
Toshi MARUYAMA
remove trailing white-spaces from app/controllers/application_controller.rb....
r6405
Jean-Philippe Lang
Separation of RSS/API auth actions....
r6077 def accept_rss_auth?(action=action_name)
self.class.accept_rss_auth.include?(action.to_sym)
end
Toshi MARUYAMA
remove trailing white-spaces from app/controllers/application_controller.rb....
r6405
Jean-Philippe Lang
Separation of RSS/API auth actions....
r6077 def self.accept_api_auth(*actions)
if actions.any?
write_inheritable_attribute('accept_api_auth_actions', actions)
else
read_inheritable_attribute('accept_api_auth_actions') || []
end
end
Toshi MARUYAMA
remove trailing white-spaces from app/controllers/application_controller.rb....
r6405
Jean-Philippe Lang
Separation of RSS/API auth actions....
r6077 def accept_api_auth?(action=action_name)
self.class.accept_api_auth.include?(action.to_sym)
Jean-Philippe Lang
Merged 0.6 branch into trunk....
r663 end
Toshi MARUYAMA
remove trailing white-spaces from app/controllers/application_controller.rb....
r5629
Jean-Philippe Lang
New setting added to specify how many objects should be displayed on most paginated lists....
r1013 # Returns the number of objects that should be displayed
# on the paginated list
def per_page_option
per_page = nil
if params[:per_page] && Setting.per_page_options_array.include?(params[:per_page].to_s.to_i)
per_page = params[:per_page].to_s.to_i
session[:per_page] = per_page
elsif session[:per_page]
per_page = session[:per_page]
else
per_page = Setting.per_page_options_array.first || 25
end
per_page
end
Jean-Philippe Lang
Makes API accept offset/limit or page/limit parameters for retrieving collections....
r4457 # Returns offset and limit used to retrieve objects
# for an API response based on offset, limit and page parameters
def api_offset_and_limit(options=params)
if options[:offset].present?
offset = options[:offset].to_i
Jean-Philippe Lang
Restores object count and adds offset/limit attributes to API responses for paginated collections (#6140)....
r4375 if offset < 0
offset = 0
end
end
Jean-Philippe Lang
Makes API accept offset/limit or page/limit parameters for retrieving collections....
r4457 limit = options[:limit].to_i
Jean-Philippe Lang
Restores object count and adds offset/limit attributes to API responses for paginated collections (#6140)....
r4375 if limit < 1
limit = 25
elsif limit > 100
limit = 100
end
Jean-Philippe Lang
Makes API accept offset/limit or page/limit parameters for retrieving collections....
r4457 if offset.nil? && options[:page].present?
offset = (options[:page].to_i - 1) * limit
offset = 0 if offset < 0
end
offset ||= 0
Toshi MARUYAMA
remove trailing white-spaces from app/controllers/application_controller.rb....
r5629
Jean-Philippe Lang
Restores object count and adds offset/limit attributes to API responses for paginated collections (#6140)....
r4375 [offset, limit]
end
Toshi MARUYAMA
remove trailing white-spaces from app/controllers/application_controller.rb....
r5629
Jean-Philippe Lang
added svn:eol-style native property on /app files...
r330 # qvalues http header parser
# code taken from webrick
def parse_qvalues(value)
tmp = []
if value
parts = value.split(/,\s*/)
parts.each {|part|
if m = %r{^([^\s,]+?)(?:;\s*q=(\d+(?:\.\d+)?))?$}.match(part)
val = m[1]
q = (m[2] or 1).to_f
tmp.push([val, q])
end
}
tmp = tmp.sort_by{|val, q| -q}
tmp.collect!{|val, q| val}
end
return tmp
Jean-Philippe Lang
Merged Rails 2.2 branch. Redmine now requires Rails 2.2.2....
r2430 rescue
nil
Jean-Philippe Lang
added svn:eol-style native property on /app files...
r330 end
Toshi MARUYAMA
remove trailing white-spaces from app/controllers/application_controller.rb....
r5629
Jean-Philippe Lang
Non-ascii attachement filename fix for IE....
r1039 # Returns a string that can be used as filename value in Content-Disposition header
def filename_for_content_disposition(name)
request.env['HTTP_USER_AGENT'] =~ %r{MSIE} ? ERB::Util.url_encode(name) : name
end
Toshi MARUYAMA
remove trailing white-spaces from app/controllers/application_controller.rb....
r5629
Jean-Philippe Lang
Adds a log message when an API call raises an InvalidAuthenticityToken error....
r3218 def api_request?
%w(xml json).include? params[:format]
end
Toshi MARUYAMA
remove trailing white-spaces from app/controllers/application_controller.rb....
r5629
Jean-Philippe Lang
Makes the API accepts the X-Redmine-API-Key header to hold the API key....
r4459 # Returns the API key present in the request
def api_key_from_request
if params[:key].present?
params[:key]
elsif request.headers["X-Redmine-API-Key"].present?
request.headers["X-Redmine-API-Key"]
end
end
Eric Davis
Refactor: Decouple failed attachments and the flash messages...
r3414
# Renders a warning flash if obj has unsaved attachments
def render_attachment_warning_if_needed(obj)
flash[:warning] = l(:warning_attachments_not_saved, obj.unsaved_attachments.size) if obj.unsaved_attachments.present?
end
Eric Davis
Refactor: pull #query_statement_invalid up to ApplicationController....
r3582
Eric Davis
Refactor: pull up method to ApplicationController....
r3826 # Sets the `flash` notice or error based the number of issues that did not save
#
# @param [Array, Issue] issues all of the saved and unsaved Issues
# @param [Array, Integer] unsaved_issue_ids the issue ids that were not saved
def set_flash_from_bulk_issue_save(issues, unsaved_issue_ids)
if unsaved_issue_ids.empty?
flash[:notice] = l(:notice_successful_update) unless issues.empty?
else
flash[:error] = l(:notice_failed_to_save_issues,
:count => unsaved_issue_ids.size,
:total => issues.size,
:ids => '#' + unsaved_issue_ids.join(', #'))
end
end
Eric Davis
Refactor: pull #query_statement_invalid up to ApplicationController....
r3582 # 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 if respond_to?(:sort_clear)
render_error "An error occurred while executing the query and has been logged. Please report this error to your Redmine administrator."
end
Jean-Philippe Lang
Adds a reusable method to render API response on validation failure....
r4341 # Renders API response on validation failure
Jean-Philippe Lang
Cleanup in TimelogController#destroy....
r8975 def render_validation_errors(objects)
if objects.is_a?(Array)
@error_messages = objects.map {|object| object.errors.full_messages}.flatten
else
@error_messages = objects.errors.full_messages
end
Jean-Philippe Lang
Adds a template for API error messages so that it does not depend on AR::Errors serialization....
r8974 render :template => 'common/error_messages.api', :status => :unprocessable_entity, :layout => false
Jean-Philippe Lang
Adds a reusable method to render API response on validation failure....
r4341 end
Toshi MARUYAMA
remove trailing white-spaces from app/controllers/application_controller.rb....
r5629
Jean-Philippe Lang
Adds a pseudo format to api template names and overrides ActionController#default_template so that api templates are chosen automatically....
r4352 # Overrides #default_template so that the api template
# is used automatically if it exists
def default_template(action_name = self.action_name)
if api_request?
begin
return self.view_paths.find_template(default_template_name(action_name), 'api')
rescue ::ActionView::MissingTemplate
# the api template was not found
# fallback to the default behaviour
end
end
super
end
Toshi MARUYAMA
remove trailing white-spaces from app/controllers/application_controller.rb....
r5629
Jean-Philippe Lang
Adds a pseudo format to api template names and overrides ActionController#default_template so that api templates are chosen automatically....
r4352 # Overrides #pick_layout so that #render with no arguments
# doesn't use the layout for api requests
def pick_layout(*args)
api_request? ? nil : super
end
Jean-Philippe Lang
Merged 0.6 branch into trunk....
r663 end