Files
fizzy/app/models/card/eventable/system_commenter.rb
T
Jason Zimdars c6c9e0d5fc Rework system events
- Restyle system events so they don't look like comments and aren't attributed to the system user
- Ensure the event creator is included in the description so it's clear who did it.
- Walk back system comment replacement. Yes, it potentially avoids embarassing people when they change their mind, it's also losing data. If two intentional assigments happen in proximity, we've been only showing the latest one,.
2025-05-28 15:26:41 -05:00

30 lines
1014 B
Ruby

class Card::Eventable::SystemCommenter
attr_reader :card, :event
def initialize(card, event)
@card, @event = card, event
end
def comment
return unless comment_body.present?
card.comments.create! creator: User.system, body: comment_body, created_at: event.created_at
end
private
def comment_body
case event.action
when "card_assigned"
"#{event.creator.name} assigned this to #{event.assignees.pluck(:name).to_sentence}."
when "card_unassigned"
"#{event.creator.name} unassigned from #{event.assignees.pluck(:name).to_sentence}."
when "card_staged"
"#{event.creator.name} moved this to '#{event.stage_name}'."
when "card_closed"
"Closed as “#{ card.closure.reason }” by #{ event.creator.name }"
when "card_title_changed"
"#{event.creator.name} changed the title from '#{event.particulars.dig('particulars', 'old_title')}' to '#{event.particulars.dig('particulars', 'new_title')}'."
end
end
end