Sha256: 24c3b5fd98e1f4932200d9367183794461c08a524de4f028802866e24b897a80

Contents?: true

Size: 1.88 KB

Versions: 7

Compression:

Stored size: 1.88 KB

Contents

require 'cancan'

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

  rescue_from CanCan::AccessDenied do
    redirect_to root_path, :alert => t("mongoid.access_denied")
  end

  def current_ability
    MongoidForums::Ability.new(mongoid_forums_user)
  end

  before_action :set_categories
  before_action :set_alerts

  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.asc(:position)
  end

    def authenticate_mongoid_forums_user
    if !mongoid_forums_user
      session["user_return_to"] = request.fullpath
      flash.alert = t("mongoid_forums.errors.not_signed_in")
      devise_route = "new_#{MongoidForums.user_class.to_s.underscore}_session_path"
      sign_in_path = MongoidForums.sign_in_path ||
        (main_app.respond_to?(devise_route) && main_app.send(devise_route)) ||
        (main_app.respond_to?(:sign_in_path) && main_app.send(:sign_in_path))
      if sign_in_path
        redirect_to sign_in_path
      else
        raise "MongoidForums could not determine the sign in path for your application. Please do one of these things:
1) Define sign_in_path in the config/routes.rb of your application like this:
or; 2) Set MongoidForums.sign_in_path to a String value that represents the location of your sign in form, such as '/users/sign_in'."
      end
    end
  end

  def mongoid_forums_admin?
    mongoid_forums_user && mongoid_forums_user.mongoid_forums_admin?
  end
  helper_method :mongoid_forums_admin?

  def mongoid_forums_admin_or_moderator?(forum)
    mongoid_forums_user && (mongoid_forums_user.mongoid_forums_admin? || forum.moderator?(mongoid_forums_user))
  end
  helper_method :mongoid_forums_admin_or_moderator?

end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
mongoid-forums-1.0.7 app/controllers/mongoid_forums/application_controller.rb
mongoid-forums-1.0.6 app/controllers/mongoid_forums/application_controller.rb
ack-mongoid-forums-1.0.5 app/controllers/mongoid_forums/application_controller.rb
mongoid-forums-1.0.4 app/controllers/mongoid_forums/application_controller.rb
mongoid-forums-1.0.3 app/controllers/mongoid_forums/application_controller.rb
mongoid-forums-1.0.2 app/controllers/mongoid_forums/application_controller.rb
mongoid-forums-1.0.1 app/controllers/mongoid_forums/application_controller.rb