-
Notifications
You must be signed in to change notification settings - Fork 194
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
(688) Add content block updates to a document's timeline #9754
Open
pezholio
wants to merge
10
commits into
main
Choose a base branch
from
content-modelling/688-pull-in-when-content-has-been-updated-by-an-update-to-a-content-block-within-publishing-apps
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
03d0567
Use a decorator instead of a presenter
pezholio fcfa164
Simplify the timeline query
pezholio e1cd197
Add a `HostContentUpdateEvent` model
pezholio 00332b7
Refactor PaginatedTimelineTest
pezholio 5b44220
Include events in paginated timeline
pezholio da9ce39
Add methods to get when events occured on editions
pezholio d99f6db
Add history helpers to versions and remarks
pezholio 8d4a784
Add timeline helpers to the HostContentUpdateEvent
pezholio 090f1d6
Use new methods in PaginatedTimeline
pezholio 297f3b5
Add component for HostContentUpdateEvents
pezholio File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
class HostContentUpdateEvent < Data.define(:author, :created_at, :content_id, :content_title) | ||
def self.all_for_date_window(document:, from:, to:) | ||
events = Services.publishing_api.get_events_for_content_id(document.content_id, { | ||
action: "HostContentUpdateJob", | ||
from:, | ||
to:, | ||
}) | ||
|
||
events.map do |event| | ||
HostContentUpdateEvent.new( | ||
author: get_user_for_uuid(event["payload"]["source_block"]["updated_by_user_uid"]), | ||
created_at: Time.zone.parse(event["created_at"]), | ||
content_id: event["payload"]["source_block"]["content_id"], | ||
content_title: event["payload"]["source_block"]["title"], | ||
) | ||
end | ||
end | ||
|
||
private | ||
|
||
def self.get_user_for_uuid(uuid) | ||
User.find_by(uid: uuid) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
require "test_helper" | ||
|
||
class HostContentUpdateEventTest < ActiveSupport::TestCase | ||
extend Minitest::Spec::DSL | ||
|
||
let(:document) { create(:document) } | ||
let(:user) { create(:user) } | ||
|
||
describe ".all_for_date_window" do | ||
it "returns all HostContentUpdateJobs" do | ||
from = Time.zone.now - 2.months | ||
to = Time.zone.now - 1.month | ||
|
||
Services.publishing_api.expects(:get_events_for_content_id).with( | ||
document.content_id, { | ||
action: "HostContentUpdateJob", | ||
from:, | ||
to:, | ||
} | ||
).returns( | ||
[ | ||
{ | ||
"id" => 1593, | ||
"action" => "HostContentUpdateJob", | ||
"created_at" => "2024-01-01T00:00:00.000Z", | ||
"updated_at" => "2024-01-01T00:00:00.000Z", | ||
"request_id" => SecureRandom.uuid, | ||
"content_id" => document.content_id, | ||
"payload" => { | ||
"title" => "Host content updated by content block update", | ||
"locale" => "en", | ||
"content_id" => document.content_id, | ||
"source_block" => { | ||
"title" => "An exciting piece of content", | ||
"content_id" => "ef224ae6-7a81-4c59-830b-e9884fe57ec8", | ||
"updated_by_user_uid" => user.uid, | ||
}, | ||
}, | ||
}, | ||
{ | ||
"id" => 1593, | ||
"action" => "HostContentUpdateJob", | ||
"user_uid" => SecureRandom.uuid, | ||
"created_at" => "2023-12-01T00:00:00.000Z", | ||
"updated_at" => "2023-12-01T00:00:00.000Z", | ||
"request_id" => SecureRandom.uuid, | ||
"content_id" => document.content_id, | ||
"payload" => { | ||
"title" => "Host content updated by content block update", | ||
"locale" => "en", | ||
"content_id" => document.content_id, | ||
"source_block" => { | ||
"title" => "Another exciting piece of content", | ||
"content_id" => "5c5520ce-6677-4a76-bd6e-4515f46a804e", | ||
"updated_by_user_uid" => nil, | ||
}, | ||
}, | ||
}, | ||
], | ||
) | ||
|
||
result = HostContentUpdateEvent.all_for_date_window(document:, from:, to:) | ||
|
||
assert_equal result.count, 2 | ||
|
||
assert_equal result.first.author, user | ||
assert_equal result.first.created_at, Time.zone.parse("2024-01-01T00:00:00.000Z") | ||
assert_equal result.first.content_id, "ef224ae6-7a81-4c59-830b-e9884fe57ec8" | ||
assert_equal result.first.content_title, "An exciting piece of content" | ||
|
||
assert_nil result.second.author | ||
assert_equal result.second.created_at, Time.zone.parse("2023-12-01T00:00:00.000Z") | ||
assert_equal result.second.content_id, "5c5520ce-6677-4a76-bd6e-4515f46a804e" | ||
assert_equal result.second.content_title, "Another exciting piece of content" | ||
end | ||
end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice tests ⭐