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.

application_controller.rb 21KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755
  1. # frozen_string_literal: true
  2. # Redmine - project management software
  3. # Copyright (C) 2006-2021 Jean-Philippe Lang
  4. #
  5. # This program is free software; you can redistribute it and/or
  6. # modify it under the terms of the GNU General Public License
  7. # as published by the Free Software Foundation; either version 2
  8. # of the License, or (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. require 'uri'
  19. require 'cgi'
  20. class Unauthorized < StandardError; end
  21. class ApplicationController < ActionController::Base
  22. include Redmine::I18n
  23. include Redmine::Pagination
  24. include Redmine::Hook::Helper
  25. include RoutesHelper
  26. include AvatarsHelper
  27. helper :routes
  28. helper :avatars
  29. class_attribute :accept_api_auth_actions
  30. class_attribute :accept_rss_auth_actions
  31. class_attribute :model_object
  32. layout 'base'
  33. protect_from_forgery
  34. def verify_authenticity_token
  35. unless api_request?
  36. super
  37. end
  38. end
  39. def handle_unverified_request
  40. unless api_request?
  41. super
  42. cookies.delete(autologin_cookie_name)
  43. self.logged_user = nil
  44. set_localization
  45. render_error :status => 422, :message => l(:error_invalid_authenticity_token)
  46. end
  47. end
  48. before_action :session_expiration, :user_setup, :check_if_login_required, :set_localization, :check_password_change, :check_twofa_activation
  49. after_action :record_project_usage
  50. rescue_from ::Unauthorized, :with => :deny_access
  51. rescue_from ::ActionView::MissingTemplate, :with => :missing_template
  52. include Redmine::Search::Controller
  53. include Redmine::MenuManager::MenuController
  54. helper Redmine::MenuManager::MenuHelper
  55. include Redmine::SudoMode::Controller
  56. def session_expiration
  57. if session[:user_id] && Rails.application.config.redmine_verify_sessions != false
  58. if session_expired? && !try_to_autologin
  59. set_localization(User.active.find_by_id(session[:user_id]))
  60. self.logged_user = nil
  61. flash[:error] = l(:error_session_expired)
  62. require_login
  63. end
  64. end
  65. end
  66. def session_expired?
  67. ! User.verify_session_token(session[:user_id], session[:tk])
  68. end
  69. def start_user_session(user)
  70. session[:user_id] = user.id
  71. session[:tk] = user.generate_session_token
  72. if user.must_change_password?
  73. session[:pwd] = '1'
  74. end
  75. if user.must_activate_twofa?
  76. session[:must_activate_twofa] = '1'
  77. end
  78. end
  79. def user_setup
  80. # Check the settings cache for each request
  81. Setting.check_cache
  82. # Find the current user
  83. User.current = find_current_user
  84. logger.info(" Current user: " + (User.current.logged? ? "#{User.current.login} (id=#{User.current.id})" : "anonymous")) if logger
  85. end
  86. # Returns the current user or nil if no user is logged in
  87. # and starts a session if needed
  88. def find_current_user
  89. user = nil
  90. unless api_request?
  91. if session[:user_id]
  92. # existing session
  93. user =
  94. begin
  95. User.active.find(session[:user_id])
  96. rescue
  97. nil
  98. end
  99. elsif autologin_user = try_to_autologin
  100. user = autologin_user
  101. elsif params[:format] == 'atom' && params[:key] && request.get? && accept_rss_auth?
  102. # RSS key authentication does not start a session
  103. user = User.find_by_rss_key(params[:key])
  104. end
  105. end
  106. if user.nil? && Setting.rest_api_enabled? && accept_api_auth?
  107. if (key = api_key_from_request)
  108. # Use API key
  109. user = User.find_by_api_key(key)
  110. elsif /\ABasic /i.match?(request.authorization.to_s)
  111. # HTTP Basic, either username/password or API key/random
  112. authenticate_with_http_basic do |username, password|
  113. user = User.try_to_login(username, password) || User.find_by_api_key(username)
  114. end
  115. if user && user.must_change_password?
  116. render_error :message => 'You must change your password', :status => 403
  117. return
  118. end
  119. end
  120. # Switch user if requested by an admin user
  121. if user && user.admin? && (username = api_switch_user_from_request)
  122. su = User.find_by_login(username)
  123. if su && su.active?
  124. logger.info(" User switched by: #{user.login} (id=#{user.id})") if logger
  125. user = su
  126. else
  127. render_error :message => 'Invalid X-Redmine-Switch-User header', :status => 412
  128. end
  129. end
  130. end
  131. # store current ip address in user object ephemerally
  132. user.remote_ip = request.remote_ip if user
  133. user
  134. end
  135. def autologin_cookie_name
  136. Redmine::Configuration['autologin_cookie_name'].presence || 'autologin'
  137. end
  138. def try_to_autologin
  139. if cookies[autologin_cookie_name] && Setting.autologin?
  140. # auto-login feature starts a new session
  141. user = User.try_to_autologin(cookies[autologin_cookie_name])
  142. if user
  143. reset_session
  144. start_user_session(user)
  145. end
  146. user
  147. end
  148. end
  149. # Sets the logged in user
  150. def logged_user=(user)
  151. reset_session
  152. if user && user.is_a?(User)
  153. User.current = user
  154. start_user_session(user)
  155. else
  156. User.current = User.anonymous
  157. end
  158. end
  159. # Logs out current user
  160. def logout_user
  161. if User.current.logged?
  162. if autologin = cookies.delete(autologin_cookie_name)
  163. User.current.delete_autologin_token(autologin)
  164. end
  165. User.current.delete_session_token(session[:tk])
  166. self.logged_user = nil
  167. end
  168. end
  169. # check if login is globally required to access the application
  170. def check_if_login_required
  171. # no check needed if user is already logged in
  172. return true if User.current.logged?
  173. require_login if Setting.login_required?
  174. end
  175. def check_password_change
  176. if session[:pwd]
  177. if User.current.must_change_password?
  178. flash[:error] = l(:error_password_expired)
  179. redirect_to my_password_path
  180. else
  181. session.delete(:pwd)
  182. end
  183. end
  184. end
  185. def init_twofa_pairing_and_send_code_for(twofa)
  186. twofa.init_pairing!
  187. if twofa.send_code(controller: 'twofa', action: 'activate')
  188. flash[:notice] = l('twofa_code_sent')
  189. end
  190. redirect_to controller: 'twofa', action: 'activate_confirm', scheme: twofa.scheme_name
  191. end
  192. def check_twofa_activation
  193. if session[:must_activate_twofa]
  194. if User.current.must_activate_twofa?
  195. flash[:warning] = l('twofa_warning_require')
  196. if Redmine::Twofa.available_schemes.length == 1
  197. twofa_scheme = Redmine::Twofa.for_twofa_scheme(Redmine::Twofa.available_schemes.first)
  198. twofa = twofa_scheme.new(User.current)
  199. init_twofa_pairing_and_send_code_for(twofa)
  200. else
  201. redirect_to controller: 'twofa', action: 'select_scheme'
  202. end
  203. else
  204. session.delete(:must_activate_twofa)
  205. end
  206. end
  207. end
  208. def set_localization(user=User.current)
  209. lang = nil
  210. if user && user.logged?
  211. lang = find_language(user.language)
  212. end
  213. if lang.nil? && !Setting.force_default_language_for_anonymous? && request.env['HTTP_ACCEPT_LANGUAGE']
  214. accept_lang = parse_qvalues(request.env['HTTP_ACCEPT_LANGUAGE']).first
  215. if !accept_lang.blank?
  216. accept_lang = accept_lang.downcase
  217. lang = find_language(accept_lang) || find_language(accept_lang.split('-').first)
  218. end
  219. end
  220. lang ||= Setting.default_language
  221. set_language_if_valid(lang)
  222. end
  223. def require_login
  224. if !User.current.logged?
  225. # Extract only the basic url parameters on non-GET requests
  226. if request.get?
  227. url = request.original_url
  228. else
  229. url = url_for(:controller => params[:controller], :action => params[:action], :id => params[:id], :project_id => params[:project_id])
  230. end
  231. respond_to do |format|
  232. format.html do
  233. if request.xhr?
  234. head :unauthorized
  235. else
  236. redirect_to signin_path(:back_url => url)
  237. end
  238. end
  239. format.any(:atom, :pdf, :csv) do
  240. redirect_to signin_path(:back_url => url)
  241. end
  242. format.api do
  243. if Setting.rest_api_enabled? && accept_api_auth?
  244. head(:unauthorized, 'WWW-Authenticate' => 'Basic realm="Redmine API"')
  245. else
  246. head(:forbidden)
  247. end
  248. end
  249. format.js {head :unauthorized, 'WWW-Authenticate' => 'Basic realm="Redmine API"'}
  250. format.any {head :unauthorized}
  251. end
  252. return false
  253. end
  254. true
  255. end
  256. def require_admin
  257. return unless require_login
  258. if !User.current.admin?
  259. render_403
  260. return false
  261. end
  262. true
  263. end
  264. def deny_access
  265. User.current.logged? ? render_403 : require_login
  266. end
  267. # Authorize the user for the requested action
  268. def authorize(ctrl = params[:controller], action = params[:action], global = false)
  269. allowed = User.current.allowed_to?({:controller => ctrl, :action => action}, @project || @projects, :global => global)
  270. if allowed
  271. true
  272. else
  273. if @project && @project.archived?
  274. @archived_project = @project
  275. render_403 :message => :notice_not_authorized_archived_project
  276. elsif @project && !@project.allows_to?(:controller => ctrl, :action => action)
  277. # Project module is disabled
  278. render_403
  279. else
  280. deny_access
  281. end
  282. end
  283. end
  284. # Authorize the user for the requested action outside a project
  285. def authorize_global(ctrl = params[:controller], action = params[:action], global = true)
  286. authorize(ctrl, action, global)
  287. end
  288. # Find project of id params[:id]
  289. def find_project(project_id=params[:id])
  290. @project = Project.find(project_id)
  291. rescue ActiveRecord::RecordNotFound
  292. render_404
  293. end
  294. # Find project of id params[:project_id]
  295. def find_project_by_project_id
  296. find_project(params[:project_id])
  297. end
  298. # Find project of id params[:id] if present
  299. def find_optional_project_by_id
  300. if params[:id].present?
  301. find_project(params[:id])
  302. end
  303. end
  304. # Find a project based on params[:project_id]
  305. # and authorize the user for the requested action
  306. def find_optional_project
  307. if params[:project_id].present?
  308. find_project(params[:project_id])
  309. end
  310. authorize_global
  311. end
  312. # Finds and sets @project based on @object.project
  313. def find_project_from_association
  314. render_404 unless @object.present?
  315. @project = @object.project
  316. end
  317. def find_model_object
  318. model = self.class.model_object
  319. if model
  320. @object = model.find(params[:id])
  321. self.instance_variable_set('@' + controller_name.singularize, @object) if @object
  322. end
  323. rescue ActiveRecord::RecordNotFound
  324. render_404
  325. end
  326. def self.model_object(model)
  327. self.model_object = model
  328. end
  329. # Find the issue whose id is the :id parameter
  330. # Raises a Unauthorized exception if the issue is not visible
  331. def find_issue
  332. # Issue.visible.find(...) can not be used to redirect user to the login form
  333. # if the issue actually exists but requires authentication
  334. @issue = Issue.find(params[:id])
  335. raise Unauthorized unless @issue.visible?
  336. @project = @issue.project
  337. rescue ActiveRecord::RecordNotFound
  338. render_404
  339. end
  340. # Find issues with a single :id param or :ids array param
  341. # Raises a Unauthorized exception if one of the issues is not visible
  342. def find_issues
  343. @issues = Issue.
  344. where(:id => (params[:id] || params[:ids])).
  345. preload(:project, :status, :tracker, :priority,
  346. :author, :assigned_to, :relations_to,
  347. {:custom_values => :custom_field}).
  348. to_a
  349. raise ActiveRecord::RecordNotFound if @issues.empty?
  350. raise Unauthorized unless @issues.all?(&:visible?)
  351. @projects = @issues.collect(&:project).compact.uniq
  352. @project = @projects.first if @projects.size == 1
  353. rescue ActiveRecord::RecordNotFound
  354. render_404
  355. end
  356. def find_attachments
  357. if (attachments = params[:attachments]).present?
  358. att = attachments.values.collect do |attachment|
  359. Attachment.find_by_token(attachment[:token]) if attachment[:token].present?
  360. end
  361. att.compact!
  362. end
  363. @attachments = att || []
  364. end
  365. def parse_params_for_bulk_update(params)
  366. attributes = (params || {}).reject {|k, v| v.blank?}
  367. attributes.keys.each {|k| attributes[k] = '' if attributes[k] == 'none'}
  368. if custom = attributes[:custom_field_values]
  369. custom.reject! {|k, v| v.blank?}
  370. custom.keys.each do |k|
  371. if custom[k].is_a?(Array)
  372. custom[k] << '' if custom[k].delete('__none__')
  373. else
  374. custom[k] = '' if custom[k] == '__none__'
  375. end
  376. end
  377. end
  378. attributes
  379. end
  380. # make sure that the user is a member of the project (or admin) if project is private
  381. # used as a before_action for actions that do not require any particular permission on the project
  382. def check_project_privacy
  383. if @project && !@project.archived?
  384. if @project.visible?
  385. true
  386. else
  387. deny_access
  388. end
  389. else
  390. @project = nil
  391. render_404
  392. false
  393. end
  394. end
  395. def record_project_usage
  396. if @project && @project.id && User.current.logged? && User.current.allowed_to?(:view_project, @project)
  397. Redmine::ProjectJumpBox.new(User.current).project_used(@project)
  398. end
  399. true
  400. end
  401. def back_url
  402. url = params[:back_url]
  403. if url.nil? && referer = request.env['HTTP_REFERER']
  404. url = CGI.unescape(referer.to_s)
  405. # URLs that contains the utf8=[checkmark] parameter added by Rails are
  406. # parsed as invalid by URI.parse so the redirect to the back URL would
  407. # not be accepted (ApplicationController#validate_back_url would return
  408. # false)
  409. url.gsub!(/(\?|&)utf8=\u2713&?/, '\1')
  410. end
  411. url
  412. end
  413. helper_method :back_url
  414. def redirect_back_or_default(default, options={})
  415. if back_url = validate_back_url(params[:back_url].to_s)
  416. redirect_to(back_url)
  417. return
  418. elsif options[:referer]
  419. redirect_to_referer_or default
  420. return
  421. end
  422. redirect_to default
  423. false
  424. end
  425. # Returns a validated URL string if back_url is a valid url for redirection,
  426. # otherwise false
  427. def validate_back_url(back_url)
  428. return false if back_url.blank?
  429. if CGI.unescape(back_url).include?('..')
  430. return false
  431. end
  432. begin
  433. uri = URI.parse(back_url)
  434. rescue URI::InvalidURIError
  435. return false
  436. end
  437. [:scheme, :host, :port].each do |component|
  438. if uri.send(component).present? && uri.send(component) != request.send(component)
  439. return false
  440. end
  441. uri.send(:"#{component}=", nil)
  442. end
  443. # Always ignore basic user:password in the URL
  444. uri.userinfo = nil
  445. path = uri.to_s
  446. # Ensure that the remaining URL starts with a slash, followed by a
  447. # non-slash character or the end
  448. if !%r{\A/([^/]|\z)}.match?(path)
  449. return false
  450. end
  451. if %r{/(login|account/register|account/lost_password)}.match?(path)
  452. return false
  453. end
  454. if relative_url_root.present? && !path.starts_with?(relative_url_root)
  455. return false
  456. end
  457. return path
  458. end
  459. private :validate_back_url
  460. helper_method :validate_back_url
  461. def valid_back_url?(back_url)
  462. !!validate_back_url(back_url)
  463. end
  464. private :valid_back_url?
  465. helper_method :valid_back_url?
  466. # Redirects to the request referer if present, redirects to args or call block otherwise.
  467. def redirect_to_referer_or(*args, &block)
  468. if referer = request.headers["Referer"]
  469. redirect_to referer
  470. else
  471. if args.any?
  472. redirect_to *args
  473. elsif block_given?
  474. yield
  475. else
  476. raise "#redirect_to_referer_or takes arguments or a block"
  477. end
  478. end
  479. end
  480. def render_403(options={})
  481. @project = nil
  482. render_error({:message => :notice_not_authorized, :status => 403}.merge(options))
  483. return false
  484. end
  485. def render_404(options={})
  486. render_error({:message => :notice_file_not_found, :status => 404}.merge(options))
  487. return false
  488. end
  489. # Renders an error response
  490. def render_error(arg)
  491. arg = {:message => arg} unless arg.is_a?(Hash)
  492. @message = arg[:message]
  493. @message = l(@message) if @message.is_a?(Symbol)
  494. @status = arg[:status] || 500
  495. respond_to do |format|
  496. format.html do
  497. render :template => 'common/error', :layout => use_layout, :status => @status
  498. end
  499. format.any {head @status}
  500. end
  501. end
  502. # Handler for ActionView::MissingTemplate exception
  503. def missing_template(exception)
  504. logger.warn "Missing template, responding with 404: #{exception}"
  505. @project = nil
  506. render_404
  507. end
  508. # Filter for actions that provide an API response
  509. # but have no HTML representation for non admin users
  510. def require_admin_or_api_request
  511. return true if api_request?
  512. if User.current.admin?
  513. true
  514. elsif User.current.logged?
  515. render_error(:status => 406)
  516. else
  517. deny_access
  518. end
  519. end
  520. # Picks which layout to use based on the request
  521. #
  522. # @return [boolean, string] name of the layout to use or false for no layout
  523. def use_layout
  524. request.xhr? ? false : 'base'
  525. end
  526. def render_feed(items, options={})
  527. @items = (items || []).to_a
  528. @items.sort! {|x, y| y.event_datetime <=> x.event_datetime}
  529. @items = @items.slice(0, Setting.feeds_limit.to_i)
  530. @title = options[:title] || Setting.app_title
  531. render :template => "common/feed", :formats => [:atom], :layout => false,
  532. :content_type => 'application/atom+xml'
  533. end
  534. def self.accept_rss_auth(*actions)
  535. if actions.any?
  536. self.accept_rss_auth_actions = actions
  537. else
  538. self.accept_rss_auth_actions || []
  539. end
  540. end
  541. def accept_rss_auth?(action=action_name)
  542. self.class.accept_rss_auth.include?(action.to_sym)
  543. end
  544. def self.accept_api_auth(*actions)
  545. if actions.any?
  546. self.accept_api_auth_actions = actions
  547. else
  548. self.accept_api_auth_actions || []
  549. end
  550. end
  551. def accept_api_auth?(action=action_name)
  552. self.class.accept_api_auth.include?(action.to_sym)
  553. end
  554. # Returns the number of objects that should be displayed
  555. # on the paginated list
  556. def per_page_option
  557. per_page = nil
  558. if params[:per_page] && Setting.per_page_options_array.include?(params[:per_page].to_s.to_i)
  559. per_page = params[:per_page].to_s.to_i
  560. session[:per_page] = per_page
  561. elsif session[:per_page]
  562. per_page = session[:per_page]
  563. else
  564. per_page = Setting.per_page_options_array.first || 25
  565. end
  566. per_page
  567. end
  568. # Returns offset and limit used to retrieve objects
  569. # for an API response based on offset, limit and page parameters
  570. def api_offset_and_limit(options=params)
  571. if options[:offset].present?
  572. offset = options[:offset].to_i
  573. if offset < 0
  574. offset = 0
  575. end
  576. end
  577. limit = options[:limit].to_i
  578. if limit < 1
  579. limit = 25
  580. elsif limit > 100
  581. limit = 100
  582. end
  583. if offset.nil? && options[:page].present?
  584. offset = (options[:page].to_i - 1) * limit
  585. offset = 0 if offset < 0
  586. end
  587. offset ||= 0
  588. [offset, limit]
  589. end
  590. # qvalues http header parser
  591. # code taken from webrick
  592. def parse_qvalues(value)
  593. tmp = []
  594. if value
  595. parts = value.split(/,\s*/)
  596. parts.each do |part|
  597. if m = %r{^([^\s,]+?)(?:;\s*q=(\d+(?:\.\d+)?))?$}.match(part)
  598. val = m[1]
  599. q = (m[2] or 1).to_f
  600. tmp.push([val, q])
  601. end
  602. end
  603. tmp = tmp.sort_by{|val, q| -q}
  604. tmp.collect!{|val, q| val}
  605. end
  606. return tmp
  607. rescue
  608. nil
  609. end
  610. # Returns a string that can be used as filename value in Content-Disposition header
  611. def filename_for_content_disposition(name)
  612. %r{(MSIE|Trident|Edge)}.match?(request.env['HTTP_USER_AGENT'].to_s) ? ERB::Util.url_encode(name) : name
  613. end
  614. def api_request?
  615. %w(xml json).include? params[:format]
  616. end
  617. # Returns the API key present in the request
  618. def api_key_from_request
  619. if params[:key].present?
  620. params[:key].to_s
  621. elsif request.headers["X-Redmine-API-Key"].present?
  622. request.headers["X-Redmine-API-Key"].to_s
  623. end
  624. end
  625. # Returns the API 'switch user' value if present
  626. def api_switch_user_from_request
  627. request.headers["X-Redmine-Switch-User"].to_s.presence
  628. end
  629. # Renders a warning flash if obj has unsaved attachments
  630. def render_attachment_warning_if_needed(obj)
  631. flash[:warning] = l(:warning_attachments_not_saved, obj.unsaved_attachments.size) if obj.unsaved_attachments.present?
  632. end
  633. # Rescues an invalid query statement. Just in case...
  634. def query_statement_invalid(exception)
  635. logger.error "Query::StatementInvalid: #{exception.message}" if logger
  636. session.delete(:issue_query)
  637. render_error l(:error_query_statement_invalid)
  638. end
  639. # Renders a 204 response for successful updates or deletions via the API
  640. def render_api_ok
  641. render_api_head :no_content
  642. end
  643. # Renders a head API response
  644. def render_api_head(status)
  645. head status
  646. end
  647. # Renders API response on validation failure
  648. # for an object or an array of objects
  649. def render_validation_errors(objects)
  650. messages = Array.wrap(objects).map {|object| object.errors.full_messages}.flatten
  651. render_api_errors(messages)
  652. end
  653. def render_api_errors(*messages)
  654. @error_messages = messages.flatten
  655. render :template => 'common/error_messages.api', :status => :unprocessable_entity, :layout => nil
  656. end
  657. # Overrides #_include_layout? so that #render with no arguments
  658. # doesn't use the layout for api requests
  659. def _include_layout?(*args)
  660. api_request? ? false : super
  661. end
  662. end