Module: CoPlan::CommentsHelper

Defined in:
app/helpers/coplan/comments_helper.rb

Instance Method Summary collapse

Instance Method Details

#comment_author_name(comment) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'app/helpers/coplan/comments_helper.rb', line 3

def comment_author_name(comment)
  case comment.author_type
  when "human"
    CoPlan::User.find_by(id: comment.author_id)&.name || "Unknown"
  when "local_agent"
    user_name = CoPlan::User
      .joins(:api_tokens)
      .where(coplan_api_tokens: { id: comment.author_id })
      .pick(:name) || "Agent"
    comment.agent_name.present? ? "#{user_name} (#{comment.agent_name})" : user_name
  when "cloud_persona"
    AutomatedPlanReviewer.find_by(id: comment.author_id)&.name || "Reviewer"
  else
    comment.author_type
  end
end