diff --git a/app/models/user.rb b/app/models/user.rb index e1a43691e8..6f827f4a5c 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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 diff --git a/app/views/documents/index.html.erb b/app/views/documents/index.html.erb index d9878d1bc5..48880b0aa2 100644 --- a/app/views/documents/index.html.erb +++ b/app/views/documents/index.html.erb @@ -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 %>
diff --git a/spec/features/formats/news_article_spec.rb b/spec/features/formats/news_article_spec.rb index 1d9937c5c9..a92763165e 100644 --- a/spec/features/formats/news_article_spec.rb +++ b/spec/features/formats/news_article_spec.rb @@ -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" diff --git a/spec/features/formats/publication_spec.rb b/spec/features/formats/publication_spec.rb index 44bac91f94..1b6c909616 100644 --- a/spec/features/formats/publication_spec.rb +++ b/spec/features/formats/publication_spec.rb @@ -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" diff --git a/spec/features/workflow/create_document_spec.rb b/spec/features/workflow/create_document_spec.rb index 27121277f2..b5c994c887 100644 --- a/spec/features/workflow/create_document_spec.rb +++ b/spec/features/workflow/create_document_spec.rb @@ -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 @@ -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