Skip to content

Commit

Permalink
Merge pull request #2389 from alphagov/edit-page-admin
Browse files Browse the repository at this point in the history
Add skip fact check to admin tab when edition is in fact check
  • Loading branch information
syed-ali-tw authored Nov 5, 2024
2 parents f2d0e61 + 57fd5a9 commit 42fdb5a
Show file tree
Hide file tree
Showing 10 changed files with 374 additions and 246 deletions.
33 changes: 24 additions & 9 deletions app/controllers/editions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ class EditionsController < InheritedResources::Base
before_action only: %i[unpublish confirm_unpublish process_unpublish] do
require_govuk_editor(redirect_path: edition_path(resource))
end
before_action only: %i[progress admin] do
require_editor_permissions
end

helper_method :locale_to_language

Expand All @@ -26,15 +29,12 @@ def show

alias_method :metadata, :show
alias_method :unpublish, :show
alias_method :admin, :show

def history
render action: "show"
end

def admin
render action: "show"
end

def linking
render action: "show"
end
Expand Down Expand Up @@ -65,6 +65,15 @@ def process_unpublish
render_confirm_page_with_error
end

def progress
if progress_edition(resource, params[:edition][:activity].permit(:comment, :request_type, :publish_at))
flash[:success] = @command.status_message
else
flash[:danger] = @command.status_message
end
redirect_to edition_path(resource)
end

protected

def setup_view_paths
Expand All @@ -73,6 +82,11 @@ def setup_view_paths

private

def progress_edition(resource, activity_params)
@command = EditionProgressor.new(resource, current_user)
@command.progress(squash_multiparameter_datetime_attributes(activity_params.to_h, %w[publish_at]))
end

def unpublish_edition(artefact)
params["redirect_url"].strip.empty? ? UnpublishService.call(artefact, current_user) : UnpublishService.call(artefact, current_user, redirect_url)
end
Expand All @@ -86,11 +100,6 @@ def downstream_error_message
"Due to a service problem, the edition couldn't be unpublished"
end

def setup_view_paths_for(publication)
prepend_view_path "app/views/editions"
prepend_view_path template_folder_for(publication)
end

def locale_to_language(locale)
case locale
when "en"
Expand Down Expand Up @@ -118,4 +127,10 @@ def redirect_url
def description(resource)
resource.format.underscore.humanize
end

def progress_action_param
params[:edition][:activity][:request_type]
rescue StandardError
nil
end
end
4 changes: 0 additions & 4 deletions app/helpers/base_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ def resource_fields(resource)
"/#{resource.format.underscore.downcase.pluralize}/fields"
end

def skip_fact_check_for_edition(edition)
send("skip_fact_check_edition_path", edition)
end

def edition_can_be_deleted?(edition)
!edition.published?
end
Expand Down
52 changes: 31 additions & 21 deletions app/helpers/tabbed_nav_helper.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module TabbedNavHelper
def edition_nav_items(edition)
def edition_nav_items(edition, current_user)
nav_items = []

all_tab_names.each do |item|
accessible_tabs(current_user, edition).each do |item|
next if !edition.state.eql?("published") && item == "unpublish"

nav_items << standard_nav_items(item, edition)
Expand All @@ -11,6 +11,35 @@ def edition_nav_items(edition)
nav_items.flatten
end

def current_tab_name
current_tab = (request.path.split("/") & all_tab_names).first

case current_tab
when "metadata"
"metadata"
when "unpublish"
"unpublish"
when "admin"
"admin"
else
"temp_nav_text"
end
end

private

def all_tab_names
%w[edit tagging metadata history admin related_external_links unpublish]
end

def accessible_tabs(current_user, edition)
nav_items_to_remove = []
nav_items_to_remove << "admin" unless current_user.has_editor_permissions?(edition)
nav_items_to_remove << "unpublish" unless current_user.govuk_editor?

all_tab_names.reject { |tab| nav_items_to_remove.include?(tab) }
end

def standard_nav_items(item, edition)
url = item.eql?("edit") ? url_for([:edition, { id: edition.id }]) : url_for([:edition, { action: item, id: edition.id }])

Expand All @@ -30,23 +59,4 @@ def edit_nav_item(label, href, current)
},
]
end

def current_tab_name
current_tab = (request.path.split("/") & all_tab_names).first

case current_tab
when "metadata"
"metadata"
when "unpublish"
"unpublish"
else
"temp_nav_text"
end
end

private

def all_tab_names
%w[edit tagging metadata history admin related_external_links unpublish]
end
end
2 changes: 1 addition & 1 deletion app/views/editions/_secondary_navigation.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%= render "govuk_publishing_components/components/secondary_navigation", {
aria_label: "Document navigation",
items: edition_nav_items(@edition),
items: edition_nav_items(@edition, current_user),
} %>
14 changes: 14 additions & 0 deletions app/views/editions/secondary_nav_tabs/_admin.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<% @edition = @resource %>
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<%= header_for("Admin") %>

<% if @edition.fact_check? %>
<%= form_for @edition, url: skip_fact_check_edition_path(@edition), method: "post" do %>
<%= render "govuk_publishing_components/components/button", {
text: "Skip fact check",
} %>
<% end %>
<% end %>
</div>
</div>
2 changes: 1 addition & 1 deletion app/views/shared/_admin.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<% if @resource.fact_check? %>
<h3 class="add-bottom-margin h4">Skip fact check</h3>
<%= button_to "Skip fact check", skip_fact_check_for_edition(@resource), :method => :post, :class => "btn btn-default" %>
<%= button_to "Skip fact check", skip_fact_check_edition_path(@resource), :method => :post, :class => "btn btn-default" %>
<% end %>

<% if @edition.published? && @edition.can_create_new_edition? %>
Expand Down
9 changes: 9 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@
get "unpublish"
get "unpublish/confirm-unpublish", to: "editions#confirm_unpublish", as: "confirm_unpublish"
post "process_unpublish"
post "progress"
post "skip_fact_check",
to: "editions#progress",
edition: {
activity: {
request_type: "skip_fact_check",
comment: "Fact check skipped by request.",
},
}
end
end
end
Expand Down
Loading

0 comments on commit 42fdb5a

Please sign in to comment.