Created
May 9, 2012 04:00
-
-
Save mpautasso/2641689 to your computer and use it in GitHub Desktop.
Open Refinery controllers
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
Refinery::AdminController.class_eval do | |
before_filter :restrict_refinery_to_refinery_users | |
private | |
def restrict_refinery_to_refinery_users | |
return if current_user && current_user.has_role?(:refinery) | |
redirect_to root_path #this user is not a refinery user because they have no refinery roles. | |
return false | |
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
Refinery::ApplicationController.class_eval do | |
def self.included(base) | |
base.send :helper_method, | |
:current_refinery_user, | |
: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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment