/
action_helper.rb
34 lines (29 loc) · 1.07 KB
/
action_helper.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
module ActionHelper
def edition_actions(edition)
edition.actions.reverse
end
def action_note?(action)
action.comment.present? || action.is_fact_check_request? || action.request_type == "assign"
end
def action_note(action)
if action.comment.present?
format_and_auto_link_plain_text(action.comment)
elsif action.is_fact_check_request? && action.email_addresses.present?
"Request sent to #{mail_to action.email_addresses}".html_safe
elsif action.recipient_id.present?
"Assigned to #{mail_to action.recipient.email, action.recipient.name}".html_safe
end
end
def format_and_auto_link_plain_text(text)
text = auto_link(escape_once(text), link: :urls, sanitize: false)
text = auto_link_zendesk_tickets(text)
simple_format(text, {}, :sanitize => false).html_safe
end
def auto_link_zendesk_tickets(text)
text = text.gsub(/(?:zen|zendesk|zendesk ticket)(?:\s)?(?:#|\:)?(?:\s)?(\d{4,})/i) do |match|
ticket = $1
link_to match, "https://govuk.zendesk.com/tickets/#{ticket}"
end
text.html_safe
end
end