Module: DailyFocus::ConversationSharing

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

Overview

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

Nightly generation assigns +user+ to the first active sales_manager/sales_director
(see DailyFocusAnalysisRepWorker). Without shares, other managers hit
"Conversation not found" when following digest or review links.

Constant Summary collapse

SALES_LEADERSHIP_ROLES =
%w[sales_manager sales_director].freeze

Class Method Summary collapse

Class Method Details

.share_with_sales_leadership!(conversation, shared_by:) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/services/daily_focus/conversation_sharing.rb', line 14

def self.share_with_sales_leadership!(conversation, shared_by:)
  SALES_LEADERSHIP_ROLES.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