-
Notifications
You must be signed in to change notification settings - Fork 193
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9754 from alphagov/content-modelling/688-pull-in-…
…when-content-has-been-updated-by-an-update-to-a-content-block-within-publishing-apps (688) Add content block updates to a document's timeline
- Loading branch information
Showing
32 changed files
with
1,093 additions
and
333 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
app/assets/stylesheets/admin/views/_host-content-update-event.scss
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,20 @@ | ||
.app-view-editions-host-content-update-event-entry { | ||
&__list-item { | ||
margin-bottom: govuk-spacing(4); | ||
} | ||
|
||
&__detail { | ||
margin-top: govuk-spacing(0); | ||
margin-bottom: govuk-spacing(0); | ||
} | ||
|
||
&__heading { | ||
margin-bottom: govuk-spacing(1); | ||
} | ||
|
||
&__datetime { | ||
margin-top: govuk-spacing(0); | ||
margin-bottom: govuk-spacing(0); | ||
color: $govuk-secondary-text-colour; | ||
} | ||
} |
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
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
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
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
11 changes: 11 additions & 0 deletions
11
app/components/admin/editions/host_content_update_event_component.html.erb
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,11 @@ | ||
<div class="app-view-editions-host-content-update-event-entry__list-item"> | ||
<h4 class="govuk-heading-s app-view-editions-host-content-update-event-entry__heading">Content Block Update</h4> | ||
|
||
<p class="govuk-body app-view-editions-host-content-update-event-entry__detail"> | ||
<%= activity %> | ||
</p> | ||
|
||
<p class="govuk-body-s app-view-editions-host-content-update-event-entry__datetime"> | ||
<%= time %> by <%= actor %> | ||
</p> | ||
</div> |
23 changes: 23 additions & 0 deletions
23
app/components/admin/editions/host_content_update_event_component.rb
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,23 @@ | ||
class Admin::Editions::HostContentUpdateEventComponent < ViewComponent::Base | ||
include ApplicationHelper | ||
|
||
def initialize(event) | ||
@event = event | ||
end | ||
|
||
private | ||
|
||
attr_reader :event | ||
|
||
def activity | ||
"#{event.content_title.strip} updated" | ||
end | ||
|
||
def time | ||
absolute_time(event.created_at) | ||
end | ||
|
||
def actor | ||
event.author ? linked_author(event.author, class: "govuk-link") : "User (removed)" | ||
end | ||
end |
45 changes: 45 additions & 0 deletions
45
app/decorators/document/paginated_timeline/version_decorator.rb
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,45 @@ | ||
class Document::PaginatedTimeline::VersionDecorator < SimpleDelegator | ||
def initialize(version, is_first_edition: false, previous_version: nil) | ||
@is_first_edition = is_first_edition | ||
@preloaded_previous_version = previous_version | ||
super(version) | ||
end | ||
|
||
def ==(other) | ||
self.class == other.class && | ||
id == other.id && | ||
action == other.action | ||
end | ||
|
||
def actor | ||
user | ||
end | ||
|
||
def action | ||
case event | ||
when "create" | ||
@is_first_edition ? "created" : "editioned" | ||
else | ||
previous_version&.state != state ? state : "updated" | ||
end | ||
end | ||
|
||
def is_for_newer_edition?(edition) | ||
item_id > edition.id | ||
end | ||
|
||
def is_for_current_edition?(edition) | ||
item_id == edition.id | ||
end | ||
|
||
def is_for_older_edition?(edition) | ||
item_id < edition.id | ||
end | ||
|
||
private | ||
|
||
def previous_version | ||
# we can avoid n+1 queries by using our preloaded_prev_version | ||
@previous_version ||= @preloaded_previous_version || previous | ||
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
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
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
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
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,34 @@ | ||
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 | ||
|
||
def is_for_newer_edition?(edition) | ||
edition.superseded? && created_at.after?(edition.superseded_at) | ||
end | ||
|
||
def is_for_current_edition?(edition) | ||
edition.published_at && created_at.after?(edition.published_at) && !is_for_newer_edition?(edition) | ||
end | ||
|
||
def is_for_older_edition?(edition) | ||
!is_for_newer_edition?(edition) && !is_for_current_edition?(edition) | ||
end | ||
|
||
def self.get_user_for_uuid(uuid) | ||
User.find_by(uid: uuid) | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.