Sha256: 688c591aa19d1b8ab548f58e229802d8e70aa32414f43e99f4ac5d46163db848

Contents?: true

Size: 1.83 KB

Versions: 3

Compression:

Stored size: 1.83 KB

Contents

require 'nokogiri'
require 'effective_datatables'
require 'effective_regions'
require 'effective_posts/engine'
require 'effective_posts/version'

module EffectivePosts
  mattr_accessor :posts_table_name

  mattr_accessor :authorization_method
  mattr_accessor :permitted_params

  mattr_accessor :layout
  mattr_accessor :simple_form_options
  mattr_accessor :admin_simple_form_options

  mattr_accessor :categories
  mattr_accessor :use_category_routes
  mattr_accessor :use_blog_routes

  mattr_accessor :use_effective_roles
  mattr_accessor :use_fullscreen_editor

  mattr_accessor :per_page
  mattr_accessor :post_meta_author

  mattr_accessor :submissions_enabled
  mattr_accessor :submissions_require_current_user
  mattr_accessor :submissions_require_approval
  mattr_accessor :submissions_note

  # These are hashes of configs
  mattr_accessor :mailer

  def self.setup
    yield self
  end

  def self.authorized?(controller, action, resource)
    @_exceptions ||= [Effective::AccessDenied, (CanCan::AccessDenied if defined?(CanCan)), (Pundit::NotAuthorizedError if defined?(Pundit))].compact

    return !!authorization_method unless authorization_method.respond_to?(:call)
    controller = controller.controller if controller.respond_to?(:controller)

    begin
      !!(controller || self).instance_exec((controller || self), action, resource, &authorization_method)
    rescue *@_exceptions
      false
    end
  end

  def self.authorize!(controller, action, resource)
    raise Effective::AccessDenied.new('Access Denied', action, resource) unless authorized?(controller, action, resource)
  end

  def self.permitted_params
    @@permitted_params ||= [
      :title, :excerpt, :description, :draft, :category, :slug, :published_at, :body, :tags, :extra,
      :start_at, :end_at, :location, :website_name, :website_href, roles: []
    ].compact
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
effective_posts-1.1.5 lib/effective_posts.rb
effective_posts-1.1.4 lib/effective_posts.rb
effective_posts-1.1.3 lib/effective_posts.rb