Module: DailyFocus::ConversationSharing

Defined in:
app/services/daily_focus/conversation_sharing.rb

Overview

Role shares so leadership can open Daily Focus briefings in Sunny with
collaborator access (send messages), not view-only.

Nightly generation assigns +user+ to the first active leader for the
briefing's audience (see DailyFocusAnalysisRepWorker). Without shares,
other managers hit "Conversation not found" when following review links.

Audiences are separate:

  • sales → sales_manager / sales_director
  • support → technical_support_manager (tech workload, not sales)

Constant Summary collapse

SALES_LEADERSHIP_ROLES =
%w[sales_manager sales_director].freeze
SUPPORT_LEADERSHIP_ROLES =
%w[technical_support_manager].freeze

Class Method Summary collapse

Class Method Details

.roles_for(audience) ⇒ Array<String>

Parameters:

  • audience (String, Symbol)

Returns:

  • (Array<String>)


52
53
54
# File 'app/services/daily_focus/conversation_sharing.rb', line 52

def self.roles_for(audience)
  audience.to_s == 'support' ? SUPPORT_LEADERSHIP_ROLES : SALES_LEADERSHIP_ROLES
end

.share_with_leadership!(conversation, shared_by:, audience: 'sales') ⇒ Object

Share a briefing with the leadership roles for its audience.

Parameters:

  • conversation (AssistantConversation)
  • shared_by (Party)
  • audience (String, Symbol) (defaults to: 'sales')

    'sales' or 'support'



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/services/daily_focus/conversation_sharing.rb', line 32

def self.share_with_leadership!(conversation, shared_by:, audience: 'sales')
  roles_for(audience).each do |role_name|
    role = Role.find_by(name: role_name)
    unless role
      Rails.logger.warn("[DailyFocus::ConversationSharing] Role not found: #{role_name.inspect} — skipping share")
      next
    end

    share = AssistantConversationShare.find_or_initialize_by(
      assistant_conversation_id: conversation.id,
      role_id: role.id
    )
    share.shared_by_id = shared_by.id
    share.access_level = 'collaborator'
    share.save!
  end
end

.share_with_sales_leadership!(conversation, shared_by:) ⇒ Object

Deprecated.

Prefer share_with_leadership! with an audience. Kept for
call sites that always mean sales.

Parameters:



23
24
25
# File 'app/services/daily_focus/conversation_sharing.rb', line 23

def self.share_with_sales_leadership!(conversation, shared_by:)
  share_with_leadership!(conversation, shared_by: shared_by, audience: 'sales')
end