Skip to content

Commit

Permalink
Customise note if an event is host content update
Browse files Browse the repository at this point in the history
This will show when a content block has been updated, as well as
providing a link to view the block in the Content Block Manager
  • Loading branch information
pezholio committed Jan 28, 2025
1 parent ff62371 commit 335d62c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
9 changes: 8 additions & 1 deletion app/helpers/action_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@ def action_note(action)
notes = []

if action.comment.present?
if action.request_type == Action::RECEIVE_FACT_CHECK
case action.request_type
when Action::RECEIVE_FACT_CHECK
formatted_email_parts = format_email_text(action.comment)
notes.concat(formatted_email_parts)
when HostContentUpdateEvent::Action::REQUEST_TYPE
notes << content_block_update_comment(action)
else
notes << format_and_auto_link_plain_text(action.comment)
end
Expand All @@ -32,6 +35,10 @@ def action_note(action)
notes.join.html_safe
end

def content_block_update_comment(action)
"#{action.comment} (#{link_to 'View in Content Block Manager', action.block_url, target: '_blank', rel: 'noopener'})"
end

def action_class(action)
action.request_type.tr("_", "-")
end
Expand Down
14 changes: 13 additions & 1 deletion test/support/factories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@
end

factory :host_content_update_event, class: "HostContentUpdateEvent" do
author { HostContentUpdateEvent::Author.new(name: "someone", email: "[email protected]") }
author { build(:host_content_update_event_author) }
created_at { Time.zone.now }
content_id { SecureRandom.uuid }
content_title { "Something" }
Expand All @@ -351,6 +351,18 @@
end
end

factory :host_content_update_event_author, class: "HostContentUpdateEvent::Author" do
name { "Someone" }
email { "[email protected]" }

initialize_with do
new(
name:,
email:,
)
end
end

factory :link_check_report do
batch_id { 1 }
status { "in_progress" }
Expand Down
11 changes: 11 additions & 0 deletions test/unit/helpers/admin/action_helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,15 @@ class ActionHelperTest < ActionView::TestCase
assert_match(/older/, unformatted_email.last)
end
end

test "#action_note supports host content update events" do
host_content_update_event = FactoryBot.build(:host_content_update_event, document_type: "Something")
action = host_content_update_event.to_action

note = action_note(action)

assert_match(/Something updated/, note)
assert_match(/View in Content Block Manager/, note)
assert_match(/#{action.block_url}/, note)
end
end

0 comments on commit 335d62c

Please sign in to comment.