Module: DailyFocusAudiencesHelper

Included in:
DailyFocusController
Defined in:
app/helpers/daily_focus_audiences_helper.rb

Overview

Who may review which Daily Focus population.

Lived as private methods on DailyFocusController, which left the dashboard
gating its review card on can?(:change_sales_dash, Employee) — and CanCan's
manage Employee makes that true for every *_manager role. A tech manager
therefore saw the card, read sales numbers on it, and was redirected to the
support tab on click, where the numbers were different. Shared here so the
view and the controller cannot answer the question differently.

Constant Summary collapse

AUDIENCES =

Ordered for display. A third department is one entry here plus a branch in
DailyFocus.audience_for / .rep_scope — deliberately not a registry.

%w[sales support].freeze
AUDIENCE_LABELS =

Returns audience => card/tab label.

Returns:

  • (Hash{String => String})

    audience => card/tab label

{ 'sales' => 'Sales', 'support' => 'Tech' }.freeze

Instance Method Summary collapse

Instance Method Details

#can_manage_audience?(audience, account = current_account) ⇒ Boolean

Parameters:

  • audience (String, Symbol)
  • account (Account, nil) (defaults to: current_account)

Returns:

  • (Boolean)


34
35
36
37
38
39
# File 'app/helpers/daily_focus_audiences_helper.rb', line 34

def can_manage_audience?(audience,  = )
  return true if sales_daily_focus_manager?()
  return true if audience.to_s == 'support' && technical_support_manager?()

  false
end

#daily_focus_audience_label(audience) ⇒ String

Parameters:

  • audience (String, Symbol)

Returns:

  • (String)


49
50
51
# File 'app/helpers/daily_focus_audiences_helper.rb', line 49

def daily_focus_audience_label(audience)
  AUDIENCE_LABELS.fetch(audience.to_s, audience.to_s.titleize)
end

#manageable_daily_focus_audiences(account = current_account) ⇒ Array<String>

Returns audiences this person may review, in display order.

Parameters:

  • account (Account, nil) (defaults to: current_account)

Returns:

  • (Array<String>)

    audiences this person may review, in display order



43
44
45
# File 'app/helpers/daily_focus_audiences_helper.rb', line 43

def manageable_daily_focus_audiences( = )
  AUDIENCES.select { |audience| can_manage_audience?(audience, ) }
end

#sales_daily_focus_manager?(account = current_account) ⇒ Boolean

Parameters:

  • account (Account, nil) (defaults to: current_account)

Returns:

  • (Boolean)


21
22
23
# File 'app/helpers/daily_focus_audiences_helper.rb', line 21

def sales_daily_focus_manager?( = )
  &.has_role?(%w[admin executive_manager sales_manager sales_director]) || false
end

#technical_support_manager?(account = current_account) ⇒ Boolean

Parameters:

  • account (Account, nil) (defaults to: current_account)

Returns:

  • (Boolean)


27
28
29
# File 'app/helpers/daily_focus_audiences_helper.rb', line 27

def technical_support_manager?( = )
  &.has_role?(%w[technical_support_manager]) || false
end