Class: ApplicationController

Inherits:
ActionController::Base
  • Object
show all
Includes:
FlashTruncation, Sequencescape::Api::Rails::ApplicationController, SessionHelper
Defined in:
app/controllers/application_controller.rb

Overview

Base controller for application Sets up:

  • v1 api support

  • Sequencescape::Api::Rails::ApplicationController imports settings from #api_connection_options

  • session validation on #check_for_current_user!

Instance Method Summary collapse

Instance Method Details

#api_connection_optionsObject



15
16
17
# File 'app/controllers/application_controller.rb', line 15

def api_connection_options
  Limber::Application.config.api.v1.connection_options.dup
end

#check_for_current_user!Object



21
22
23
24
25
26
27
28
# File 'app/controllers/application_controller.rb', line 21

def check_for_current_user!
  return true if current_user_uuid.present?

  redirect_to(
    search_path,
    alert: 'You must be logged in to do that. Performing actions in multiple tabs can log you out.' # rubocop:todo Rails/I18nLocaleTexts
  )
end

#check_for_login!Object Originally defined in module SessionHelper

#current_user_uuidObject Originally defined in module SessionHelper

#logged_in?Boolean Originally defined in module SessionHelper

Returns:

  • (Boolean)

#logged_in_classObject Originally defined in module SessionHelper

Toggle class if user is logged in. This is applied to the body, so you shouldn’t need to add it to other elements

#max_flash_sizeObject Originally defined in module FlashTruncation

The maximum cookie size is 4096 bytes, however this is post-encryption, which increases the size. The value of 2048 was obtained by mapping the size of encrypted strings. In practice 2255 bytes was the largest size, but I rounded down to 2kb to provide a bit of overhead for array serialization, additional flash information to and allow for slight implementation changes.

#session_switcherObject Originally defined in module SessionHelper

#truncate_flash(message, max_size = max_flash_size) ⇒ Array, String Originally defined in module FlashTruncation

Truncates the flash message to avoid an ActionDispatch::Cookies::CookieOverflow. Maximum cookie size is checked against ActionDispatch::Cookies::MAX_COOKIE_SIZE which is 4096 bytes; however:

  • This is the size of the session cookie post encryption, which inflates the size

  • This cookie also needs to contain other data, such as the session_id, user_uuid and user_name

Parameters:

  • message (Array, String)

    The flash to truncate

  • max_size (Integer) (defaults to: max_flash_size)

    The maximum allowed flash size

Returns:

  • (Array, String)

    The truncated message

#truncate_flash_array(array, max_size = max_flash_size) ⇒ Array Originally defined in module FlashTruncation

Handles truncation of arrays passed to the flash. This is not intended to be used directly, instead use truncate_flash.

Parameters:

  • array (Array)

    The flash to truncate

  • max_size (Integer) (defaults to: max_flash_size)

    The maximum allowed flash size

Returns:

  • (Array)

    The truncated array

See Also:

#user_nameObject Originally defined in module SessionHelper

Returns the name of the logged in user. Returns guest if no one is logged in.