-
-
Save snooc/3250827 to your computer and use it in GitHub Desktop.
RefineryCMS integration with existing Rails 3.2.3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
# for refinery | |
config.autoload_paths += Dir["#{config.root}/lib/**/"] # to load files from lib directory, including subfolders | |
config.before_initialize do | |
require 'refinery_patch' | |
require 'restrict_refinery_to_refinery_users' | |
end | |
include Refinery::Engine | |
after_inclusion do | |
[ApplicationController, ApplicationHelper].each do |c| | |
c.send :include, ::RefineryPatch | |
end | |
::Refinery::AdminController.send :include, ::RestrictRefineryToRefineryUsers | |
::Refinery::AdminController.send :before_filter, :restrict_refinery_to_refinery_users | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source 'https://rubygems.org' | |
gem 'rails', '3.2.3' | |
gem 'pg' | |
gem 'thin' | |
gem 'activeadmin' | |
# Add users roles management | |
gem 'cancan' | |
# Add IP reverse geocoding support | |
gem 'geocoder' | |
## Add static pages management ## | |
## REFINERY ## | |
gem 'refinerycms-core' | |
gem 'refinerycms-dashboard' | |
gem 'refinerycms-images' | |
gem 'refinerycms-pages' | |
gem 'refinerycms-resources' | |
gem 'refinerycms-settings' | |
# Gems used only for assets and not required | |
# in production environments by default. | |
group :assets do | |
gem 'sass-rails', '~> 3.2.3' | |
gem 'coffee-rails', '~> 3.2.1' | |
gem 'uglifier', '>= 1.0.3' | |
end | |
gem 'jquery-rails' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module RefineryPatch | |
def self.included(base) | |
base.send :helper_method, | |
:current_refinery_user, | |
:refinery_user_signed_in?, | |
:refinery_user? if base.respond_to? :helper_method | |
end | |
def current_refinery_user | |
current_user | |
end | |
def just_installed? | |
Role[:refinery].users.empty? | |
end | |
def refinery_user_signed_in? | |
user_signed_in? | |
end | |
def refinery_user? | |
refinery_user_signed_in? && current_refinery_user.has_role?(:refinery) | |
end | |
def authenticate_refinery_user! | |
authenticate_user! | |
end | |
def store_location | |
session[:return_to] = request.fullpath | |
end | |
def redirect_back_or_default(default) | |
redirect_to(session[:return_to] || default) | |
session[:return_to] = nil | |
end | |
protected | |
def refinery_user_required? | |
if just_installed? and %w[registrations users].exclude?(controller_name) | |
redirect_to main_app.new_user_registration_path | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module RestrictRefineryToRefineryUsers | |
def restrict_refinery_to_refinery_users | |
return if current_user && current_user.has_role?(:refinery) | |
redirect_to main_app.root_path #this user is not a refinery user because they have no refinery roles. | |
return false | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment