Created
February 22, 2013 13:22
-
-
Save mohitjain1/5013346 to your computer and use it in GitHub Desktop.
test
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
class ApplicationController < ActionController::Base | |
#protect_from_forgery | |
before_filter :authenticate_user! | |
before_filter :block_whole_all_requests_in_case_welcome_flow_not_completed | |
# helper_method :user_is_report_manager?, :user_is_group_member?, :user_is_manager_or_owner? | |
# =================== | |
# = Private Methods = | |
# =================== | |
private | |
def block_whole_all_requests_in_case_welcome_flow_not_completed | |
if !current_user.nil? and current_user.is_a?(User) and !current_user.owner_id.blank? and current_user.company.welocome_flow_status == 0 and (!['devise/sessions'].include?(params[:controller])) | |
redirect_to welcome_path | |
end | |
end | |
def after_sign_in_path_for(current_user) | |
if current_user.is_a?(User) and current_user.banned == 1 | |
sign_out resource | |
block_path | |
elsif current_user.is_a?(User) and (current_user.owner_id.blank? or current_user.company.welocome_flow_status == 1) | |
user_company_path(current_user, current_user.company) | |
else | |
welcome_path | |
end | |
end | |
#---------------- Helper - Methods ----------------# | |
# Method to check whether the user is manager for a group or not. | |
# def user_is_group_manager?(group) | |
# group.manager.eql?(current_user) | |
# end | |
# Method to check whether the user is authorised manager for a report or not | |
# def user_is_report_manager?(report) | |
# report.manager.eql?(current_user) || report.group.manager.eql?(current_user) | |
# end | |
# Method to check whether the user is part of group or not | |
# def user_is_group_member?(group) | |
# group.users.include?(current_user) | |
# end | |
# Method to check whether the user is either company owner or manager for any group | |
# def user_is_manager_or_owner? | |
# # unless ( !current_user.managed_groups.blank? || current_user.owner_id? ) | |
# unless ( current_user.owner_or_group_manager? ) | |
# redirect_to(root_path, :notice => 'You must be manager or owner for inviting other users !') | |
# end | |
# end | |
def redirect_unauthorized | |
respond_to do |format| | |
format.html { redirect_to( root_path) } | |
format.js { render( 'shared/auth_fail') } | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment