-
Notifications
You must be signed in to change notification settings - Fork 43
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 #2513 from alphagov/content-modelling/785-show-con…
…tent-block-updates-in-mainstream (Content modelling/785) Show content block updates in Mainstream
- Loading branch information
Showing
44 changed files
with
689 additions
and
11 deletions.
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
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,41 @@ | ||
class HostContentUpdateEvent < Data.define(:author, :created_at, :content_id, :content_title, :document_type) | ||
Author = Data.define(:name, :email) | ||
def self.all_for_artefact(artefact) | ||
events = Services.publishing_api.get_events_for_content_id(artefact.content_id, { | ||
action: "HostContentUpdateJob", | ||
}) | ||
|
||
user_uuids = events.map { |event| event["payload"]["source_block"]["updated_by_user_uid"] }.uniq | ||
users = users_with_uuids(user_uuids) | ||
|
||
events.map do |event| | ||
HostContentUpdateEvent.new( | ||
author: users[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"], | ||
document_type: event["payload"]["source_block"]["document_type"], | ||
) | ||
end | ||
end | ||
|
||
def self.users_with_uuids(uuids) | ||
Services.signon_api.get_users(uuids:).map { |user| | ||
[user["uid"], Author.new(user["name"], user["email"])] | ||
}.to_h | ||
end | ||
|
||
def is_for_edition?(edition) | ||
if edition.published? | ||
created_at.after?(edition.published_at) | ||
elsif edition.archived? && edition.superseded_at | ||
created_at.between?(edition.published_at, edition.superseded_at) | ||
else | ||
false | ||
end | ||
end | ||
|
||
def to_action | ||
Action.new(self) | ||
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,57 @@ | ||
class HostContentUpdateEvent | ||
class Action | ||
CONTENT_BLOCK_UPDATE = "content_block_update".freeze | ||
|
||
attr_reader :host_content_update_event | ||
|
||
def initialize(host_content_update_event) | ||
@host_content_update_event = host_content_update_event | ||
end | ||
|
||
def request_type | ||
CONTENT_BLOCK_UPDATE | ||
end | ||
|
||
delegate :created_at, to: :host_content_update_event | ||
|
||
def requester | ||
host_content_update_event.author | ||
end | ||
|
||
def to_s | ||
"Content block updated" | ||
end | ||
|
||
def comment | ||
"#{humanized_document_type} updated" | ||
end | ||
|
||
def block_url | ||
[ | ||
Plek.external_url_for("whitehall-admin"), | ||
"content-block-manager", | ||
"content-block", | ||
"content-id", | ||
host_content_update_event.content_id, | ||
].join("/") | ||
end | ||
|
||
def comment_sanitized | ||
false | ||
end | ||
|
||
def is_fact_check_request? | ||
false | ||
end | ||
|
||
def recipient_id | ||
nil | ||
end | ||
|
||
private | ||
|
||
def humanized_document_type | ||
host_content_update_event.document_type.delete_prefix("content_block_").humanize | ||
end | ||
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
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
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
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
Oops, something went wrong.