diff --git a/app/helpers/admin/editions_helper.rb b/app/helpers/admin/editions_helper.rb index 19960b14617..adcf50fb39d 100644 --- a/app/helpers/admin/editions_helper.rb +++ b/app/helpers/admin/editions_helper.rb @@ -59,6 +59,7 @@ def admin_state_filter_options ["All states", "active"], %w[Draft draft], %w[Submitted submitted], + %w[Approved approved], %w[Rejected rejected], %w[Scheduled scheduled], %w[Published published], diff --git a/app/models/concerns/edition/workflow.rb b/app/models/concerns/edition/workflow.rb index b75b4f3a5b2..dc7d3dae6ec 100644 --- a/app/models/concerns/edition/workflow.rb +++ b/app/models/concerns/edition/workflow.rb @@ -11,7 +11,7 @@ def in_state(state) end def valid_state?(state) - %w[active draft submitted rejected published scheduled force_published withdrawn not_published unpublished].include?(state) + %w[active draft submitted rejected approved published scheduled force_published withdrawn not_published unpublished].include?(state) end end @@ -24,6 +24,7 @@ def valid_state?(state) state :draft state :submitted state :rejected + state :approved state :scheduled state :published state :superseded @@ -44,7 +45,7 @@ def valid_state?(state) end event :schedule do - transitions from: :submitted, to: :scheduled + transitions from: :approved, to: :scheduled end event :force_schedule do @@ -56,7 +57,7 @@ def valid_state?(state) end event :publish do - transitions from: %i[submitted scheduled], to: :published + transitions from: %i[approved scheduled], to: :published end event :force_publish do @@ -67,6 +68,19 @@ def valid_state?(state) transitions from: %i[published unpublished], to: :unpublished end + # TODO: presumably we need some governance around how an edition can become + # approved. I guess whoever has the power to 'reject' a submitted edition + # should also have the power to 'approve'. + # + # And there should be implications for the publishing workflow, i.e. right now + # it is possible to publish (not force publish) a submitted edition), but + # we're saying that an edition that is merely 'submitted' should now only have + # the force-publish/force-schedule options available to it. Only "approved" + # editions should be able to be published or scheduled normally. + event :approve do + transitions from: %i[submitted], to: :approved + end + event :supersede, success: :destroy_associations_with_edition_dependencies_and_dependants do transitions from: %i[published unpublished], to: :superseded end diff --git a/test/functional/admin/edition_workflow_controller_test.rb b/test/functional/admin/edition_workflow_controller_test.rb index b7772f92b02..874a5be63b8 100644 --- a/test/functional/admin/edition_workflow_controller_test.rb +++ b/test/functional/admin/edition_workflow_controller_test.rb @@ -217,13 +217,14 @@ class Admin::EditionWorkflowControllerTest < ActionController::TestCase assert_equal "All workflow actions require a lock version", response.body end - test "approve_retrospectively marks the document as having been approved retrospectively and redirects back to he edition" do + test "approve_retrospectively marks the document as having been approved retrospectively and redirects back to the edition" do editor = create(:departmental_editor) acting_as(editor) { force_publish(draft_edition) } post :approve_retrospectively, params: { id: draft_edition, lock_version: draft_edition.lock_version } assert_redirected_to admin_publication_path(draft_edition) assert_equal "Thanks for reviewing; this document is no longer marked as force-published", flash[:notice] + # Missing assertion here. Should check `force_published` is now false, end test "approve_retrospectively responds with 422 if missing a lock version" do