Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Link to zendesk tickets from edition notes automatically #296

Merged
merged 3 commits into from Nov 17, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 13 additions & 3 deletions app/helpers/action_helper.rb
Expand Up @@ -11,14 +11,24 @@ 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}"
"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}"
"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)
simple_format(text, {}, :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
2 changes: 1 addition & 1 deletion app/views/shared/_edition_history.html.erb
Expand Up @@ -34,7 +34,7 @@
</div>
<% end %>
<blockquote class="add-left-margin">
<%= action_note(action).html_safe %>
<%= action_note(action) %>
</blockquote>
<% end %>
</li>
Expand Down
17 changes: 17 additions & 0 deletions test/unit/helpers/admin/action_helper_test.rb
@@ -0,0 +1,17 @@
require 'test_helper'

class ActionHelperTest < ActionView::TestCase
test "it converts zendesk tickets to links" do

expected_link = 'https://govuk.zendesk.com/tickets/1234'
texts = ['Zendesk ticket #1234', 'zendesk 1234', 'Zen 1234', 'zen #1234', 'zen#1234', 'zen:1234', 'zendesk: 1234']

texts.each do |text|
assert_equal auto_link_zendesk_tickets(text), "<a href=\"#{expected_link}\">#{text}</a>"
end

assert_equal auto_link_zendesk_tickets("zendesk 1234. Next"), "<a href=\"#{expected_link}\">zendesk 1234</a>. Next"
assert_equal auto_link_zendesk_tickets("something something zendesk 1234. Next"), "something something <a href=\"#{expected_link}\">zendesk 1234</a>. Next"
assert_equal auto_link_zendesk_tickets("somezendesk 1234. Next"), "some<a href=\"#{expected_link}\">zendesk 1234</a>. Next"
end
end