Skip to content

Commit

Permalink
Use 'current_user' helper everywhere rather than '@current_user'. Sta…
Browse files Browse the repository at this point in the history
…ndardising to enable better engine integration later on.
  • Loading branch information
steveyken committed Sep 12, 2012
1 parent ccdd7df commit c1049e7
Show file tree
Hide file tree
Showing 122 changed files with 655 additions and 726 deletions.
2 changes: 1 addition & 1 deletion app/controllers/admin/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def auto_complete
#----------------------------------------------------------------------------
def require_admin_user
require_user
if @current_user && !@current_user.admin?
if current_user && !current_user.admin?
flash[:notice] = t(:msg_require_admin)
redirect_to root_path
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/admin/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def destroy
# PUT /admin/users/1/suspend.xml AJAX
#----------------------------------------------------------------------------
def suspend
@user.update_attribute(:suspended_at, Time.now) if @user != @current_user
@user.update_attribute(:suspended_at, Time.now) if @user != current_user

respond_with(@user)
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class ApplicationController < ActionController::Base
#----------------------------------------------------------------------------
def auto_complete
@query = params[:auto_complete_query] || ''
@auto_complete = hook(:auto_complete, self, :query => @query, :user => @current_user)
@auto_complete = hook(:auto_complete, self, :query => @query, :user => current_user)
if @auto_complete.empty?
@auto_complete = klass.my.text_search(@query).limit(10)
else
Expand Down
16 changes: 8 additions & 8 deletions app/controllers/entities/accounts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def show
# GET /accounts/new
#----------------------------------------------------------------------------
def new
@account.attributes = {:user => @current_user, :access => Setting.default_access, :assigned_to => nil}
@account.attributes = {:user => current_user, :access => Setting.default_access, :assigned_to => nil}

if params[:related]
model, id = params[:related].split('_')
Expand Down Expand Up @@ -85,7 +85,7 @@ def update
if @account.update_attributes(params[:account])
get_data_for_sidebar
else
@users = User.except(@current_user) # Need it to redraw [Edit Account] form.
@users = User.except(current_user) # Need it to redraw [Edit Account] form.
end
end
end
Expand Down Expand Up @@ -117,18 +117,18 @@ def destroy
#----------------------------------------------------------------------------
def options
unless params[:cancel].true?
@per_page = @current_user.pref[:accounts_per_page] || Account.per_page
@outline = @current_user.pref[:accounts_outline] || Account.outline
@sort_by = @current_user.pref[:accounts_sort_by] || Account.sort_by
@per_page = current_user.pref[:accounts_per_page] || Account.per_page
@outline = current_user.pref[:accounts_outline] || Account.outline
@sort_by = current_user.pref[:accounts_sort_by] || Account.sort_by
end
end

# POST /accounts/redraw AJAX
#----------------------------------------------------------------------------
def redraw
@current_user.pref[:accounts_per_page] = params[:per_page] if params[:per_page]
@current_user.pref[:accounts_outline] = params[:outline] if params[:outline]
@current_user.pref[:accounts_sort_by] = Account::sort_by_map[params[:sort_by]] if params[:sort_by]
current_user.pref[:accounts_per_page] = params[:per_page] if params[:per_page]
current_user.pref[:accounts_outline] = params[:outline] if params[:outline]
current_user.pref[:accounts_sort_by] = Account::sort_by_map[params[:sort_by]] if params[:sort_by]
@accounts = get_accounts(:page => 1)
render :index
end
Expand Down
16 changes: 8 additions & 8 deletions app/controllers/entities/campaigns_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def show
# GET /campaigns/new.xml AJAX
#----------------------------------------------------------------------------
def new
@campaign.attributes = {:user => @current_user, :access => Setting.default_access, :assigned_to => nil}
@campaign.attributes = {:user => current_user, :access => Setting.default_access, :assigned_to => nil}

if params[:related]
model, id = params[:related].split('_')
Expand Down Expand Up @@ -90,7 +90,7 @@ def update
if @campaign.update_attributes(params[:campaign])
get_data_for_sidebar if called_from_index_page?
else
@users = User.except(@current_user) # Need it to redraw [Edit Campaign] form.
@users = User.except(current_user) # Need it to redraw [Edit Campaign] form.
end
end
end
Expand Down Expand Up @@ -122,18 +122,18 @@ def destroy
#----------------------------------------------------------------------------
def options
unless params[:cancel].true?
@per_page = @current_user.pref[:campaigns_per_page] || Campaign.per_page
@outline = @current_user.pref[:campaigns_outline] || Campaign.outline
@sort_by = @current_user.pref[:campaigns_sort_by] || Campaign.sort_by
@per_page = current_user.pref[:campaigns_per_page] || Campaign.per_page
@outline = current_user.pref[:campaigns_outline] || Campaign.outline
@sort_by = current_user.pref[:campaigns_sort_by] || Campaign.sort_by
end
end

# POST /campaigns/redraw AJAX
#----------------------------------------------------------------------------
def redraw
@current_user.pref[:campaigns_per_page] = params[:per_page] if params[:per_page]
@current_user.pref[:campaigns_outline] = params[:outline] if params[:outline]
@current_user.pref[:campaigns_sort_by] = Campaign::sort_by_map[params[:sort_by]] if params[:sort_by]
current_user.pref[:campaigns_per_page] = params[:per_page] if params[:per_page]
current_user.pref[:campaigns_outline] = params[:outline] if params[:outline]
current_user.pref[:campaigns_sort_by] = Campaign::sort_by_map[params[:sort_by]] if params[:sort_by]
@campaigns = get_campaigns(:page => 1)
render :index
end
Expand Down
38 changes: 19 additions & 19 deletions app/controllers/entities/leads_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ def show
# GET /leads/new
#----------------------------------------------------------------------------
def new
@lead.attributes = {:user => @current_user, :access => Setting.default_access, :assigned_to => nil}
@users = User.except(@current_user)
@lead.attributes = {:user => current_user, :access => Setting.default_access, :assigned_to => nil}
@users = User.except(current_user)
get_campaigns

if params[:related]
Expand All @@ -62,7 +62,7 @@ def new
# GET /leads/1/edit AJAX
#----------------------------------------------------------------------------
def edit
@users = User.except(@current_user)
@users = User.except(current_user)
get_campaigns

if params[:previous].to_s =~ /(\d+)\z/
Expand All @@ -75,7 +75,7 @@ def edit
# POST /leads
#----------------------------------------------------------------------------
def create
@users = User.except(@current_user)
@users = User.except(current_user)
get_campaigns
@comment_body = params[:comment_body]

Expand All @@ -99,7 +99,7 @@ def update
if @lead.update_with_lead_counters(params[:lead])
update_sidebar
else
@users = User.except(@current_user)
@users = User.except(current_user)
@campaigns = Campaign.my.order('name')
end
end
Expand All @@ -119,10 +119,10 @@ def destroy
# GET /leads/1/convert
#----------------------------------------------------------------------------
def convert
@users = User.except(@current_user)
@account = Account.new(:user => @current_user, :name => @lead.company, :access => "Lead")
@users = User.except(current_user)
@account = Account.new(:user => current_user, :name => @lead.company, :access => "Lead")
@accounts = Account.my.order('name')
@opportunity = Opportunity.new(:user => @current_user, :access => "Lead", :stage => "prospecting", :campaign => @lead.campaign, :source => @lead.source)
@opportunity = Opportunity.new(:user => current_user, :access => "Lead", :stage => "prospecting", :campaign => @lead.campaign, :source => @lead.source)

if params[:previous].to_s =~ /(\d+)\z/
@previous = Lead.my.find_by_id($1) || $1.to_i
Expand All @@ -134,7 +134,7 @@ def convert
# PUT /leads/1/promote
#----------------------------------------------------------------------------
def promote
@users = User.except(@current_user)
@users = User.except(current_user)
@account, @opportunity, @contact = @lead.promote(params)
@accounts = Account.my.order('name')
@stage = Setting.unroll(:opportunity_stage)
Expand Down Expand Up @@ -177,29 +177,29 @@ def reject
#----------------------------------------------------------------------------
def options
unless params[:cancel].true?
@per_page = @current_user.pref[:leads_per_page] || Lead.per_page
@outline = @current_user.pref[:leads_outline] || Lead.outline
@sort_by = @current_user.pref[:leads_sort_by] || Lead.sort_by
@naming = @current_user.pref[:leads_naming] || Lead.first_name_position
@per_page = current_user.pref[:leads_per_page] || Lead.per_page
@outline = current_user.pref[:leads_outline] || Lead.outline
@sort_by = current_user.pref[:leads_sort_by] || Lead.sort_by
@naming = current_user.pref[:leads_naming] || Lead.first_name_position
end
end

# POST /leads/redraw AJAX
#----------------------------------------------------------------------------
def redraw
@current_user.pref[:leads_per_page] = params[:per_page] if params[:per_page]
@current_user.pref[:leads_outline] = params[:outline] if params[:outline]
current_user.pref[:leads_per_page] = params[:per_page] if params[:per_page]
current_user.pref[:leads_outline] = params[:outline] if params[:outline]

# Sorting and naming only: set the same option for Contacts if the hasn't been set yet.
if params[:sort_by]
@current_user.pref[:leads_sort_by] = Lead::sort_by_map[params[:sort_by]]
current_user.pref[:leads_sort_by] = Lead::sort_by_map[params[:sort_by]]
if Contact::sort_by_fields.include?(params[:sort_by])
@current_user.pref[:contacts_sort_by] ||= Contact::sort_by_map[params[:sort_by]]
current_user.pref[:contacts_sort_by] ||= Contact::sort_by_map[params[:sort_by]]
end
end
if params[:naming]
@current_user.pref[:leads_naming] = params[:naming]
@current_user.pref[:contacts_naming] ||= params[:naming]
current_user.pref[:leads_naming] = params[:naming]
current_user.pref[:contacts_naming] ||= params[:naming]
end

@leads = get_leads(:page => 1) # Start one the first page.
Expand Down
30 changes: 15 additions & 15 deletions app/controllers/entities/opportunities_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ def show
# GET /opportunities/new
#----------------------------------------------------------------------------
def new
@opportunity.attributes = {:user => @current_user, :stage => "prospecting", :access => Setting.default_access, :assigned_to => nil}
@users = User.except(@current_user)
@account = Account.new(:user => @current_user, :access => Setting.default_access)
@opportunity.attributes = {:user => current_user, :stage => "prospecting", :access => Setting.default_access, :assigned_to => nil}
@users = User.except(current_user)
@account = Account.new(:user => current_user, :access => Setting.default_access)
@accounts = Account.my.order('name')

if params[:related]
Expand All @@ -64,8 +64,8 @@ def new
# GET /opportunities/1/edit AJAX
#----------------------------------------------------------------------------
def edit
@users = User.except(@current_user)
@account = @opportunity.account || Account.new(:user => @current_user)
@users = User.except(current_user)
@account = @opportunity.account || Account.new(:user => current_user)
@accounts = Account.my.order('name')

if params[:previous].to_s =~ /(\d+)\z/
Expand All @@ -91,15 +91,15 @@ def create
get_data_for_sidebar(:campaign)
end
else
@users = User.except(@current_user)
@users = User.except(current_user)
@accounts = Account.my.order('name')
unless params[:account][:id].blank?
@account = Account.find(params[:account][:id])
else
if request.referer =~ /\/accounts\/(.+)$/
@account = Account.find($1) # related account
else
@account = Account.new(:user => @current_user)
@account = Account.new(:user => current_user)
end
end
@contact = Contact.find(params[:contact]) unless params[:contact].blank?
Expand All @@ -121,12 +121,12 @@ def update
get_data_for_sidebar(:campaign)
end
else
@users = User.except(@current_user)
@users = User.except(current_user)
@accounts = Account.my.order('name')
if @opportunity.account
@account = Account.find(@opportunity.account.id)
else
@account = Account.new(:user => @current_user)
@account = Account.new(:user => current_user)
end
end
end
Expand Down Expand Up @@ -164,9 +164,9 @@ def destroy
#----------------------------------------------------------------------------
def options
unless params[:cancel].true?
@per_page = @current_user.pref[:opportunities_per_page] || Opportunity.per_page
@outline = @current_user.pref[:opportunities_outline] || Opportunity.outline
@sort_by = @current_user.pref[:opportunities_sort_by] || Opportunity.sort_by
@per_page = current_user.pref[:opportunities_per_page] || Opportunity.per_page
@outline = current_user.pref[:opportunities_outline] || Opportunity.outline
@sort_by = current_user.pref[:opportunities_sort_by] || Opportunity.sort_by
end
end

Expand Down Expand Up @@ -231,9 +231,9 @@ def load_settings

#----------------------------------------------------------------------------
def set_params
@current_user.pref[:opportunities_per_page] = params[:per_page] if params[:per_page]
@current_user.pref[:opportunities_outline] = params[:outline] if params[:outline]
@current_user.pref[:opportunities_sort_by] = Opportunity::sort_by_map[params[:sort_by]] if params[:sort_by]
current_user.pref[:opportunities_per_page] = params[:per_page] if params[:per_page]
current_user.pref[:opportunities_outline] = params[:outline] if params[:outline]
current_user.pref[:opportunities_sort_by] = Opportunity::sort_by_map[params[:sort_by]] if params[:sort_by]
session[:opportunities_filter] = params[:stage] if params[:stage]
end
end
32 changes: 16 additions & 16 deletions app/controllers/home_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,31 +26,31 @@ def index
hook(:home_controller, self, :params => "it works!")

@activities = get_activities
@my_tasks = Task.visible_on_dashboard(@current_user).by_due_at
@my_opportunities = Opportunity.visible_on_dashboard(@current_user).by_closes_on
@my_accounts = Account.visible_on_dashboard(@current_user).by_name
@my_tasks = Task.visible_on_dashboard(current_user).by_due_at
@my_opportunities = Opportunity.visible_on_dashboard(current_user).by_closes_on
@my_accounts = Account.visible_on_dashboard(current_user).by_name
respond_with(@activities)
end

# GET /home/options AJAX
#----------------------------------------------------------------------------
def options
unless params[:cancel].true?
@asset = @current_user.pref[:activity_asset] || "all"
@action = @current_user.pref[:activity_event] || "all_events"
@user = @current_user.pref[:activity_user] || "all_users"
@duration = @current_user.pref[:activity_duration] || "two_days"
@asset = current_user.pref[:activity_asset] || "all"
@action = current_user.pref[:activity_event] || "all_events"
@user = current_user.pref[:activity_user] || "all_users"
@duration = current_user.pref[:activity_duration] || "two_days"
@all_users = User.order("first_name, last_name")
end
end

# POST /home/redraw AJAX
#----------------------------------------------------------------------------
def redraw
@current_user.pref[:activity_asset] = params[:asset] if params[:asset]
@current_user.pref[:activity_event] = params[:event] if params[:event]
@current_user.pref[:activity_user] = params[:user] if params[:user]
@current_user.pref[:activity_duration] = params[:duration] if params[:duration]
current_user.pref[:activity_asset] = params[:asset] if params[:asset]
current_user.pref[:activity_event] = params[:event] if params[:event]
current_user.pref[:activity_user] = params[:user] if params[:user]
current_user.pref[:activity_duration] = params[:duration] if params[:duration]

@activities = get_activities
render :index
Expand Down Expand Up @@ -105,12 +105,12 @@ def get_activities(options = {})
options[:user] ||= activity_user
options[:duration] ||= activity_duration

Version.latest(options).visible_to(@current_user)
Version.latest(options).visible_to(current_user)
end

#----------------------------------------------------------------------------
def activity_asset
asset = @current_user.pref[:activity_asset]
asset = current_user.pref[:activity_asset]
if asset.nil? || asset == "all"
nil
else
Expand All @@ -120,7 +120,7 @@ def activity_asset

#----------------------------------------------------------------------------
def activity_event
event = @current_user.pref[:activity_event]
event = current_user.pref[:activity_event]
if event == "all_events"
%w(create update destroy)
else
Expand All @@ -130,7 +130,7 @@ def activity_event

#----------------------------------------------------------------------------
def activity_user
user = @current_user.pref[:activity_user]
user = current_user.pref[:activity_user]
if user && user != "all_users"
user = if user =~ /@/ # email
User.where(:email => user).first
Expand All @@ -150,7 +150,7 @@ def activity_user

#----------------------------------------------------------------------------
def activity_duration
duration = @current_user.pref[:activity_duration]
duration = current_user.pref[:activity_duration]
if duration
words = duration.split("_") # "two_weeks" => 2.weeks
if %w(one two).include?(words.first)
Expand Down
Loading

0 comments on commit c1049e7

Please sign in to comment.