Sha256: ac5e2dedf268ab9d89d142f42f81d8f1f9084d6d93a02d27bd5db4942fb92cfe

Contents?: true

Size: 1.38 KB

Versions: 9

Compression:

Stored size: 1.38 KB

Contents

# frozen_string_literal: true

module Lcms
  module Engine
    module Admin
      class AdminController < Lcms::Engine::ApplicationController
        include Lcms::Engine::PathHelper

        CONFIG_PATH ||= Rails.root.join('config', 'lcms-admin.yml')

        DEFAULTS ||= {
          layout: 'lcms/engine/admin',
          materials_query: Lcms::Engine::AdminMaterialsQuery
        }.freeze

        RE_GOOGLE_FOLDER = %r{/drive/(.*/)?folders/}.freeze

        layout :customized_layout

        before_action :authenticate_admin!

        def self.settings
          @settings ||= DEFAULTS.merge((YAML.load_file(CONFIG_PATH) || {}).deep_symbolize_keys)
        end

        private

        def authenticate_admin!
          redirect_to dynamic_path(:root_path), alert: 'Access denied' unless current_user&.admin?
        end

        def customized_layout
          AdminController.settings[:layout] || DEFAULTS[:layout]
        end

        def customized_view
          @customized_view ||= AdminController
                                 .settings
                                 .dig(controller_name.to_sym, action_name.to_sym).presence
        end

        def render_customized_view
          render customized_view if customized_view
        end

        def view_links
          Array.wrap(AdminController.settings.dig(controller_name.to_sym, :view_links))
        end
      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/admin/admin_controller.rb
lcms-engine-0.5.4 app/controllers/lcms/engine/admin/admin_controller.rb
lcms-engine-0.5.3 app/controllers/lcms/engine/admin/admin_controller.rb
lcms-engine-0.5.2 app/controllers/lcms/engine/admin/admin_controller.rb
lcms-engine-0.5.1 app/controllers/lcms/engine/admin/admin_controller.rb
lcms-engine-0.5.0 app/controllers/lcms/engine/admin/admin_controller.rb
lcms-engine-0.4.2 app/controllers/lcms/engine/admin/admin_controller.rb
lcms-engine-0.4.1 app/controllers/lcms/engine/admin/admin_controller.rb
lcms-engine-0.4.0 app/controllers/lcms/engine/admin/admin_controller.rb