Skip to content

Commit

Permalink
Merge pull request #9837 from alphagov/content-modelling/828-add-inte…
Browse files Browse the repository at this point in the history
…rnal-and-external-change-notes-when-editing-blocks

(828) Add internal and external change notes when editing blocks
  • Loading branch information
pezholio authored Jan 23, 2025
2 parents c4f1209 + 31fdc56 commit 7f253eb
Show file tree
Hide file tree
Showing 27 changed files with 631 additions and 237 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddInternalChangeNoteToContentBlockEditions < ActiveRecord::Migration[7.1]
def change
add_column :content_block_editions, :internal_change_note, :string
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class AddChangeNoteAndMajorChangeToContentBlockEditions < ActiveRecord::Migration[7.1]
def up
change_table :content_block_editions, bulk: true do |t|
t.string "change_note"
t.boolean "major_change"
end
end

def down
change_table :content_block_editions, bulk: true do |t|
t.remove "change_note"
t.remove "major_change"
end
end
end
5 changes: 4 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.1].define(version: 2025_01_08_102234) do
ActiveRecord::Schema[7.1].define(version: 2025_01_22_155447) do
create_table "assets", charset: "utf8mb3", force: :cascade do |t|
t.string "asset_manager_id", null: false
t.string "variant", null: false
Expand Down Expand Up @@ -233,6 +233,9 @@
t.datetime "scheduled_publication", precision: nil
t.text "instructions_to_publishers"
t.string "title", default: "", null: false
t.string "internal_change_note"
t.string "change_note"
t.boolean "major_change"
t.index ["document_id"], name: "index_content_block_editions_on_document_id"
t.index ["user_id"], name: "index_content_block_editions_on_user_id"
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def instructions_item

def edit_action
{
href: helpers.content_block_manager.content_block_manager_content_block_workflow_path(id: content_block_edition.id, step: ContentBlockManager::ContentBlock::Editions::WorkflowController::NEW_BLOCK_STEPS[:edit_draft]),
href: helpers.content_block_manager.content_block_manager_content_block_workflow_path(id: content_block_edition.id, step: :edit_draft),
link_text: "Edit",
}
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def scheduled_publication_date_params
def review_update_url
content_block_manager.content_block_manager_content_block_workflow_path(
@content_block_edition,
step: ContentBlockManager::ContentBlock::Editions::WorkflowController::UPDATE_BLOCK_STEPS[:review_update],
step: :review,
)
end

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
module Workflow::ShowMethods
extend ActiveSupport::Concern

SHOW_ACTIONS = {
edit_draft: :edit_draft,
review_links: :review_links,
schedule_publishing: :schedule_publishing,
internal_note: :internal_note,
change_note: :change_note,
review: :review,
review_update: :review_update,
confirmation: :confirmation,
}.freeze

def edit_draft
@content_block_edition = ContentBlockManager::ContentBlock::Edition.find(params[:id])
@form = ContentBlockManager::ContentBlock::EditionForm.for(
content_block_edition: @content_block_edition,
schema: @schema,
)

render "content_block_manager/content_block/editions/new"
end

def review_links
@content_block_document = @content_block_edition.document
@order = params[:order]
@page = params[:page]

@host_content_items = ContentBlockManager::HostContentItem.for_document(
@content_block_document,
order: @order,
page: @page,
)

render :review_links
end

def schedule_publishing
@content_block_document = @content_block_edition.document

render :schedule_publishing
end

def internal_note
@content_block_document = @content_block_edition.document
@back_path = content_block_manager.content_block_manager_content_block_workflow_path(
@content_block_edition,
step: :schedule_publishing,
)

render :internal_note
end

def change_note
@content_block_document = @content_block_edition.document
@back_path = content_block_manager.content_block_manager_content_block_workflow_path(
@content_block_edition,
step: :internal_note,
)

render :change_note
end

def review_update
@content_block_edition = ContentBlockManager::ContentBlock::Edition.find(params[:id])

@url = review_update_url
@back_path = content_block_manager.content_block_manager_content_block_workflow_path(
@content_block_edition,
step: :change_note,
)

render :review
end

def review
@content_block_edition = ContentBlockManager::ContentBlock::Edition.find(params[:id])
@back_path = content_block_manager.content_block_manager_content_block_documents_path

@url = review_url

render :review
end

def confirmation
@content_block_edition = ContentBlockManager::ContentBlock::Edition.find(params[:id])

@confirmation_copy = ContentBlockManager::ConfirmationCopyPresenter.new(@content_block_edition)

render :confirmation
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
module Workflow::UpdateMethods
extend ActiveSupport::Concern

REVIEW_ERROR = Data.define(:attribute, :full_message)

UPDATE_ACTIONS = {
review_links: :redirect_to_schedule,
schedule_publishing: :validate_schedule,
internal_note: :update_internal_note,
change_note: :update_change_note,
review_update: :validate_review_page,
review: :validate_review_page,
}.freeze

def redirect_to_schedule
redirect_to content_block_manager.content_block_manager_content_block_workflow_path(
id: @content_block_edition.id,
step: :schedule_publishing,
)
end

def validate_schedule
@content_block_edition = ContentBlockManager::ContentBlock::Edition.find(params[:id])

validate_scheduled_edition

redirect_to content_block_manager.content_block_manager_content_block_workflow_path(
id: @content_block_edition.id,
step: :internal_note,
)
rescue ActiveRecord::RecordInvalid
render "content_block_manager/content_block/editions/workflow/schedule_publishing"
end

def update_internal_note
@content_block_edition.update!(internal_change_note: edition_params[:internal_change_note])

redirect_to content_block_manager.content_block_manager_content_block_workflow_path(
id: @content_block_edition.id,
step: :change_note,
)
end

def update_change_note
@content_block_edition.assign_attributes(change_note: edition_params[:change_note], major_change: edition_params[:major_change])
@content_block_edition.save!(context: :change_note)

redirect_to content_block_manager.content_block_manager_content_block_workflow_path(
id: @content_block_edition.id,
step: :review_update,
)
rescue ActiveRecord::RecordInvalid
render :change_note
end

def validate_review_page
if params[:is_confirmed].blank?
@confirm_error_copy = I18n.t("content_block_edition.review_page.errors.confirm")
@error_summary_errors = [{ text: @confirm_error_copy, href: "#is_confirmed-0" }]
@url = on_review_page? ? review_url : review_update_url
render "content_block_manager/content_block/editions/workflow/review"
else
schedule_or_publish
end
end

private

def on_review_page?
params[:step] == :review
end

def on_review_update_page?
params[:step] == :review_update
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ def edition_params
"scheduled_publication(4i)",
"scheduled_publication(5i)",
:title,
:internal_change_note,
:change_note,
:major_change,
document_attributes: %w[block_type],
details: @schema.permitted_params,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def update

validate_scheduled_edition

redirect_to content_block_manager.content_block_manager_content_block_workflow_path(@content_block_edition, step: :review_update)
redirect_to content_block_manager.content_block_manager_content_block_workflow_path(@content_block_edition, step: :review)
rescue ActiveRecord::RecordInvalid
render "content_block_manager/content_block/documents/schedule/edit"
end
Expand Down
Loading

0 comments on commit 7f253eb

Please sign in to comment.