Sha256: 1685f37b012821efea9acd93c17b245d49722150920eef2ee86d23940a391fc8

Contents?: true

Size: 1002 Bytes

Versions: 2

Compression:

Stored size: 1002 Bytes

Contents

class MongoidForums::ApplicationController < ApplicationController
  helper MongoidForums::Engine.helpers

  before_action :set_categories
  before_action :set_alerts

  before_filter :authorize

  delegate :allow?, to: :current_permission
  helper_method :allow?

  #delegate :allow_param?, to: :current_permission
  #helper_method :allow?

  private

  def set_alerts
    if mongoid_forums_user.present?
      @alerts = MongoidForums::Alert.where(:user_id => mongoid_forums_user.id, :read => false).desc(:updated_at).limit(25)
    end
  end

  def set_categories
    @categories = MongoidForums::Category.all
  end


  def current_permission
    @current_permission ||= MongoidForums::Permission.new(mongoid_forums_user)
  end

  def current_resource
    nil
  end


  def authorize
    if current_permission.allow? params[:controller], params[:action], current_resource
      #current_permission.permit_params! params
    else
      redirect_to root_path, alert: "Not authorized"
    end
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mongoid-forums-0.0.2 app/controllers/mongoid_forums/application_controller.rb
mongoid-forums-0.0.1 app/controllers/mongoid_forums/application_controller.rb