Skip to content

Commit

Permalink
Merge pull request #2895 from alphagov/Remove-the-ability-to-create-n…
Browse files Browse the repository at this point in the history
…ew-documents

Remove the ability for users to create new news articles
  • Loading branch information
ollietreend authored Sep 28, 2023
2 parents 26d84b6 + 08d67eb commit 2d41dcf
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 6 deletions.
1 change: 1 addition & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class User < ApplicationRecord
MANAGING_EDITOR_PERMISSION = "managing_editor".freeze
ACCESS_LIMIT_OVERRIDE_PERMISSION = "access_limit_override".freeze
MANAGE_LIVE_HISTORY_MODE = "manage_live_history_mode".freeze
CREATE_NEW_DOCUMENT_PERMISSION = "create_new_document".freeze

def can_access?(edition)
return true unless edition.access_limit
Expand Down
14 changes: 8 additions & 6 deletions app/views/documents/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<% content_for :title, t("documents.index.title") %>

<% content_for :title_side, render("govuk_publishing_components/components/button", {
text: "Create new document",
href: new_document_path,
margin_bottom: true,
data_attributes: { gtm: "new-document" }
}) %>
<% if current_user.has_permission?(User::CREATE_NEW_DOCUMENT_PERMISSION) %>
<% content_for :title_side, render("govuk_publishing_components/components/button", {
text: "Create new document",
href: new_document_path,
margin_bottom: true,
data_attributes: { gtm: "new-document" }
}) %>
<% end %>

<div class="govuk-grid-row">
<div class="govuk-grid-column-one-quarter">
Expand Down
5 changes: 5 additions & 0 deletions spec/features/formats/news_article_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@
include TopicsHelper

scenario do
when_i_have_the_create_new_document_permission
when_i_choose_this_document_type
and_i_fill_in_the_form_fields
then_the_document_should_be_previewable
end

def when_i_have_the_create_new_document_permission
current_user.update(permissions: [User::CREATE_NEW_DOCUMENT_PERMISSION])
end

def when_i_choose_this_document_type
visit root_path
click_on "Create new document"
Expand Down
5 changes: 5 additions & 0 deletions spec/features/formats/publication_spec.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
RSpec.describe "Publication format" do
scenario do
when_i_have_the_create_new_document_permission
when_i_choose_this_document_type
and_i_fill_in_the_form_fields
then_the_document_should_be_previewable
end

def when_i_have_the_create_new_document_permission
current_user.update(permissions: [User::CREATE_NEW_DOCUMENT_PERMISSION, User::PRE_RELEASE_FEATURES_PERMISSION])
end

def when_i_choose_this_document_type
visit root_path
click_on "Create new document"
Expand Down
5 changes: 5 additions & 0 deletions spec/features/workflow/create_document_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
RSpec.feature "Create a document" do
scenario do
when_i_have_the_create_new_document_permission
given_i_am_on_the_home_page
when_i_click_to_create_a_document
and_i_select_a_supertype
Expand All @@ -9,6 +10,10 @@
and_i_see_the_timeline_entry
end

def when_i_have_the_create_new_document_permission
current_user.update(permissions: [User::CREATE_NEW_DOCUMENT_PERMISSION])
end

def given_i_am_on_the_home_page
visit root_path
end
Expand Down

0 comments on commit 2d41dcf

Please sign in to comment.