Sha256: 9e048d3058e277b993e2d4c8339e86a7abce775310617ecd223fc4a21cde5919

Contents?: true

Size: 1.53 KB

Versions: 9

Compression:

Stored size: 1.53 KB

Contents

# frozen_string_literal: true

module Lcms
  module Engine
    class ApplicationController < ActionController::Base
      # store location to use at after sign in or other devise callbacks
      include LocationStorable

      before_action :authenticate_user!, unless: :pdf_request?

      before_action :check_user_has_survey_filled_in, if: :user_signed_in?, unless: :devise_controller?
      before_action :configure_permitted_parameters, if: :devise_controller?
      before_action :handle_x_frame_headers

      rescue_from ActiveRecord::RecordNotFound do
        render 'lcms/engine/pages/not_found', status: :not_found
      end

      protected

      # Raise translation missing errors in controllers too
      def t(key, options = {})
        options[:raise] = true
        translate(key, **options)
      end

      def check_user_has_survey_filled_in
        return if current_user.ready_to_go?

        store_location_for(:user, request.url) unless devise_controller?
        redirect_to survey_path
      end

      def configure_permitted_parameters
        devise_parameter_sanitizer.permit(:sign_up, keys: [:access_code])
      end

      def handle_x_frame_headers
        response.headers.delete('X-Frame-Options') if params[:controller].index('pdfjs_viewer').present?
      end

      private

      def after_sign_in_path_for(resource_or_scope)
        stored_location_for(resource_or_scope) || main_app.root_path
      end

      def after_sign_out_path_for(resource_or_scope)
        session_path(resource_or_scope)
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
lcms-engine-0.5.5 app/controllers/lcms/engine/application_controller.rb
lcms-engine-0.5.4 app/controllers/lcms/engine/application_controller.rb
lcms-engine-0.5.3 app/controllers/lcms/engine/application_controller.rb
lcms-engine-0.5.2 app/controllers/lcms/engine/application_controller.rb
lcms-engine-0.5.1 app/controllers/lcms/engine/application_controller.rb
lcms-engine-0.5.0 app/controllers/lcms/engine/application_controller.rb
lcms-engine-0.4.2 app/controllers/lcms/engine/application_controller.rb
lcms-engine-0.4.1 app/controllers/lcms/engine/application_controller.rb
lcms-engine-0.4.0 app/controllers/lcms/engine/application_controller.rb