Sha256: 02196285b1c2ef003851bdbc727aaac98238569d939f6ee9fddfd7aed3029c93

Contents?: true

Size: 1.8 KB

Versions: 6

Compression:

Stored size: 1.8 KB

Contents

module Sufia::Controller
  extend ActiveSupport::Concern

  included do
    # Adds Hydra behaviors into the application controller
    include Hydra::Controller::ControllerBehavior

    before_filter :notifications_number
  end

  def current_ability
    user_signed_in? ? current_user.ability : super
  end

  def normalize_identifier
    params[:id] = Sufia::Noid.namespaceize(params[:id])
  end

  def render_404(exception)
    logger.error("Rendering 404 page due to exception: #{exception.inspect} - #{exception.backtrace if exception.respond_to? :backtrace}")
    render template: '/error/404', layout: "error", formats: [:html], status: 404
  end

  def render_500(exception)
    logger.error("Rendering 500 page due to exception: #{exception.inspect} - #{exception.backtrace if exception.respond_to? :backtrace}")
    render template: '/error/500', layout: "error", formats: [:html], status: 500
  end

  def render_single_use_error(exception)
    logger.error("Rendering PAGE due to exception: #{exception.inspect} - #{exception.backtrace if exception.respond_to? :backtrace}")
    render template: '/error/single_use_error', layout: "error", formats: [:html], status: 404
  end

  def notifications_number
    @notify_number = 0
    @batches = []
    return if action_name == "index" && controller_name == "mailbox"
    if user_signed_in?
      @notify_number = current_user.mailbox.inbox(unread: true).count
      @batches = current_user.mailbox.inbox.map { |msg| msg.last_message.body[/<span id="(.*)"><a (href=|data-content=)(.*)/,1] }.select{ |val| !val.blank? }
    end
  end

  # Override Devise method to redirect to dashboard after signing in
  def after_sign_in_path_for(resource)
    sufia.dashboard_index_path
  end

  protected

  ### Hook which is overridden in Sufia::Ldap::Controller
  def has_access?
    true
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
sufia-5.0.0 app/controllers/concerns/sufia/controller.rb
sufia-5.0.0.rc1 app/controllers/concerns/sufia/controller.rb
sufia-4.3.1 app/controllers/concerns/sufia/controller.rb
sufia-4.2.0 app/controllers/concerns/sufia/controller.rb
sufia-4.1.0 app/controllers/concerns/sufia/controller.rb
sufia-4.0.1 app/controllers/concerns/sufia/controller.rb