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.
{ 'sales' => 'Sales', 'support' => 'Tech' }.freeze
Instance Method Summary collapse
- #can_manage_audience?(audience, account = current_account) ⇒ Boolean
- #daily_focus_audience_label(audience) ⇒ String
-
#manageable_daily_focus_audiences(account = current_account) ⇒ Array<String>
Audiences this person may review, in display order.
- #sales_daily_focus_manager?(account = current_account) ⇒ Boolean
- #technical_support_manager?(account = current_account) ⇒ Boolean
Instance Method Details
#can_manage_audience?(audience, account = current_account) ⇒ Boolean
34 35 36 37 38 39 |
# File 'app/helpers/daily_focus_audiences_helper.rb', line 34 def can_manage_audience?(audience, account = current_account) return true if sales_daily_focus_manager?(account) return true if audience.to_s == 'support' && technical_support_manager?(account) false end |
#daily_focus_audience_label(audience) ⇒ 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.
43 44 45 |
# File 'app/helpers/daily_focus_audiences_helper.rb', line 43 def manageable_daily_focus_audiences(account = current_account) AUDIENCES.select { |audience| can_manage_audience?(audience, account) } end |
#sales_daily_focus_manager?(account = current_account) ⇒ Boolean
21 22 23 |
# File 'app/helpers/daily_focus_audiences_helper.rb', line 21 def sales_daily_focus_manager?(account = current_account) account&.has_role?(%w[admin executive_manager sales_manager sales_director]) || false end |
#technical_support_manager?(account = current_account) ⇒ Boolean
27 28 29 |
# File 'app/helpers/daily_focus_audiences_helper.rb', line 27 def technical_support_manager?(account = current_account) account&.has_role?(%w[technical_support_manager]) || false end |