Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/helpers/admin/editions_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
20 changes: 17 additions & 3 deletions app/models/concerns/edition/workflow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -24,6 +24,7 @@ def valid_state?(state)
state :draft
state :submitted
state :rejected
state :approved
state :scheduled
state :published
state :superseded
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion test/functional/admin/edition_workflow_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading