From c23bf816b73e1d5d0d4cabbbb7dee551f6cab4fb Mon Sep 17 00:00:00 2001 From: Keith Lawrence Date: Mon, 30 Sep 2024 16:36:20 +0100 Subject: [PATCH] Remove publishing_api tasks - As of https://github.com/alphagov/publishing-api/pull/2896, these are now in publishing-api with all the other special routes. --- config/content_items.yml | 41 ------- docs/support/rake_tasks.md | 32 +---- lib/publishing_api_tasks.rb | 130 -------------------- lib/tasks/publishing_api.rake | 23 ---- spec/lib/publishing_api_tasks_spec.rb | 164 -------------------------- 5 files changed, 1 insertion(+), 389 deletions(-) delete mode 100644 config/content_items.yml delete mode 100644 lib/publishing_api_tasks.rb delete mode 100644 lib/tasks/publishing_api.rake delete mode 100644 spec/lib/publishing_api_tasks_spec.rb diff --git a/config/content_items.yml b/config/content_items.yml deleted file mode 100644 index 52ce6cf6..00000000 --- a/config/content_items.yml +++ /dev/null @@ -1,41 +0,0 @@ ---- -help_pages: - sign_in: - content_id: "b6bb372b-3c4e-4a21-98a6-ffbf2ea5dc9e" - base_path: "/sign-in" - title: "Sign in to a service" - description: "Find the government service you need to sign in to. At the moment, there are separate accounts for different government services." - rendering_app: "frontend" - -redirects: [] - -special_routes: - - content_id: "0833d91b-d772-4144-b81f-e7a42df96d5b" - base_path: "/account" - title: "Sign in to GOV.UK (OAuth Redirect)" - rendering_app: "frontend" - - content_id: "49ecdc1f-c98b-430e-8256-7a402239daf8" - base_path: "/sign-in/redirect" - title: "Sign in to GOV.UK (OAuth Redirect)" - rendering_app: "frontend" - - content_id: "f04c45a7-c20b-4f66-a485-dc997a6a3b6d" - base_path: "/sign-in/callback" - title: "Sign in to GOV.UK (OAuth Callback)" - rendering_app: "frontend" - - content_id: "ff675fc1-2f0b-4f07-8dd3-bfe24d4318f8" - base_path: "/sign-in/first-time" - title: "Control how we use information about you" - rendering_app: "frontend" - - content_id: "7ee16fff-900d-4f5d-bd0a-62fdaa1ad3b6" - base_path: "/sign-out" - title: "Sign out from GOV.UK" - rendering_app: "frontend" - - content_id: "c1f08359-21f7-49c1-8811-54bf6690b6a3" - base_path: "/account/home" - title: "Account home page" - rendering_app: "frontend" - - content_id: "f8f91a56-2298-4365-9590-d7e80fe8c066" - base_path: "/api/personalisation/check-email-subscription" - title: "Account API - Check email Subscription" - description: "Personalisation API exposing email subscription data for progressive enhancement of GOV.UK pages" - rendering_app: "account-api" diff --git a/docs/support/rake_tasks.md b/docs/support/rake_tasks.md index ba3ca201..8f9eb0a6 100644 --- a/docs/support/rake_tasks.md +++ b/docs/support/rake_tasks.md @@ -1,36 +1,6 @@ # Rake Tasks -There are a number of Rake tasks available to help with -sending content to the Publishing API and administrating users. - -## Publishing API Tasks - -All content items are found in `config/content_items.yml` - -### Publish redirects -Publishes all routes in the `redirects` array -```ruby -publishing_api:publish_redirects -``` - -### Publish_all special_routes -Publishes all routes in the `special_routes` array - -```ruby -publishing_api:publish_special_routes -``` - -### Publish a help page by name -Publishes a single help page from the help_pages hash, the name -being the first key for the required help page. -```ruby -publishing_api:publish_help_page[name] -``` - -### Publish single special route by content_id -```ruby -publishing_api:publish_special_route[content_id] -``` +There are a number of Rake tasks available to help with administering users. ## User Support Tasks diff --git a/lib/publishing_api_tasks.rb b/lib/publishing_api_tasks.rb deleted file mode 100644 index 207eee05..00000000 --- a/lib/publishing_api_tasks.rb +++ /dev/null @@ -1,130 +0,0 @@ -# frozen_string_literal: true - -require "gds_api/publishing_api/special_route_publisher" - -class PublishingApiTasks - PUBLISHING_APP = "account-api" - LOCALE = "en" - - attr_reader :content_items - - def initialize(publishing_api: nil, logger: nil, content_items: nil) - @logger = logger || Logger.new($stdout) - @publishing_api = publishing_api || GdsApi.publishing_api - @content_items = content_items || YAML.safe_load(File.read(Rails.root.join("config/content_items.yml"))).deep_symbolize_keys - end - - def publish_help_page(name) - content_item = @content_items[:help_pages].fetch(name.to_sym) - content_id = content_item.fetch(:content_id) - base_path = content_item.fetch(:base_path) - payload = - { - document_type: "help_page", - schema_name: "help_page", - rendering_app: content_item.fetch(:rendering_app), - base_path:, - title: content_item.fetch(:title), - description: content_item.fetch(:description), - details: { - body: [ - { - content_type: "text/html", - content: ActionController::Base.render(template: "help_pages/#{name}"), - }, - ], - }, - routes: [ - { - path: content_item.fetch(:base_path), - type: "exact", - }, - ], - } - - claim_path base_path - publish_content_item(content_id, payload, "major") - end - - def publish_redirects - @content_items[:redirects].each do |redirect| - base_path = redirect.fetch(:base_path) - payload = - { - document_type: "redirect", - schema_name: "redirect", - base_path:, - redirects: [ - { - path: base_path, - destination: redirect.fetch(:destination), - type: "exact", - }, - ], - } - - claim_path base_path - publish_content_item(redirect.fetch(:content_id), payload, "major") - end - end - - def publish_special_route(content_id) - publisher = GdsApi::PublishingApi::SpecialRoutePublisher.new( - publishing_api: @publishing_api, - logger: @logger, - ) - - special_route = @content_items[:special_routes].find { |route| route[:content_id] == content_id } - - if special_route.nil? - puts "No special route found with content_id: #{content_id}" - puts "Check files stored in: https://github.com/alphagov/account-api/blob/main/config/content_items.yml" - return - end - - claim_path special_route.fetch(:base_path) - - publisher.publish( - special_route.merge( - publishing_app: PUBLISHING_APP, - type: "exact", - ), - ) - end - - def publish_special_routes - publisher = GdsApi::PublishingApi::SpecialRoutePublisher.new( - publishing_api: @publishing_api, - logger: @logger, - ) - - @content_items[:special_routes].each do |special_route| - claim_path special_route.fetch(:base_path) - - publisher.publish( - special_route.merge( - publishing_app: PUBLISHING_APP, - type: "exact", - ), - ) - end - end - - def claim_path(base_path) - @logger.info("Claiming ownership of route #{base_path}") - @publishing_api.put_path( - base_path, - publishing_app: PUBLISHING_APP, - override_existing: true, - ) - end - - def publish_content_item(content_id, payload, update_type) - @logger.info("Publishing content for #{payload.fetch(:base_path)}") - @publishing_api.put_content( - content_id, - payload.merge(publishing_app: PUBLISHING_APP, locale: LOCALE, update_type:), - ) - @publishing_api.publish(content_id, update_type, locale: LOCALE) - end -end diff --git a/lib/tasks/publishing_api.rake b/lib/tasks/publishing_api.rake deleted file mode 100644 index 4b445f0e..00000000 --- a/lib/tasks/publishing_api.rake +++ /dev/null @@ -1,23 +0,0 @@ -require_relative "../publishing_api_tasks" - -namespace :publishing_api do - desc "Publish redirects" - task publish_redirects: :environment do - PublishingApiTasks.new.publish_redirects - end - - desc "Publish special routes" - task publish_special_routes: :environment do - PublishingApiTasks.new.publish_special_routes - end - - desc "Publish a help page" - task :publish_help_page, [:name] => :environment do |_, args| - PublishingApiTasks.new.publish_help_page args[:name] - end - - desc "Publish a single special route by content_id" - task :publish_special_route, [:content_id] => :environment do |_, args| - PublishingApiTasks.new.publish_special_route args[:content_id] - end -end diff --git a/spec/lib/publishing_api_tasks_spec.rb b/spec/lib/publishing_api_tasks_spec.rb deleted file mode 100644 index a8600f29..00000000 --- a/spec/lib/publishing_api_tasks_spec.rb +++ /dev/null @@ -1,164 +0,0 @@ -require "publishing_api_tasks" - -require "gds_api/test_helpers/publishing_api" - -RSpec.describe PublishingApiTasks do - include GdsApi::TestHelpers::PublishingApi - - subject(:tasks) { described_class.new(logger:, content_items:) } - - let(:logger) { instance_double(Logger) } - let(:content_items) { nil } - - describe "content item definitions" do - subject(:content_items) { described_class.new.content_items } - - it "all have a unique content ID" do - content_ids = {} - content_items[:help_pages].each_value { |item| increment(content_ids, item[:content_id]) } - content_items[:redirects].each { |item| increment(content_ids, item[:content_id]) } - content_items[:special_routes].each { |item| increment(content_ids, item[:content_id]) } - - content_ids.each do |content_id, count| - expect("#{content_id}: #{count}").to eq("#{content_id}: 1") - end - end - - it "all have a unique base path" do - base_paths = {} - content_items[:help_pages].each_value { |item| increment(base_paths, item[:base_path]) } - content_items[:redirects].each { |item| increment(base_paths, item[:base_path]) } - content_items[:special_routes].each { |item| increment(base_paths, item[:base_path]) } - - base_paths.each do |base_path, count| - expect("#{base_path}: #{count}").to eq("#{base_path}: 1") - end - end - - def increment(hash, item) - hash[item] = hash.fetch(item, 0) + 1 - end - end - - describe "#publish_help_page" do - before { allow(logger).to receive(:info) } - - let(:help_page_name) { "sign_in" } - let(:help_page) { { content_id: SecureRandom.uuid, base_path: "/foo", title: "title", description: "description", rendering_app: "frontend" } } - let(:content_items) { { help_pages: { help_page_name.to_sym => help_page } } } - - it "takes ownership of the route and publishes the content item" do - stub_claim_path = stub_call_claim_path(help_page[:base_path]) - stub_put_content = stub_call_put_content(help_page[:content_id], help_page.except(:content_id), "major") - stub_publish = stub_call_publish(help_page[:content_id], "major") - - tasks.publish_help_page(help_page_name) - - expect(stub_claim_path).to have_been_made - expect(stub_put_content).to have_been_made - expect(stub_publish).to have_been_made - end - end - - describe "#publish_redirects" do - before { allow(logger).to receive(:info) } - - let(:redirect) { { content_id: SecureRandom.uuid, base_path: "/foo", destination: "/bar" } } - let(:content_items) { { redirects: [redirect] } } - - it "takes ownership of the route and publishes the content item" do - stub_claim_path = stub_call_claim_path(redirect[:base_path]) - stub_put_content = stub_call_put_content(redirect[:content_id], { redirects: [{ path: redirect[:base_path], destination: redirect[:destination], type: "exact" }] }, "major") - stub_publish = stub_call_publish(redirect[:content_id], "major") - - tasks.publish_redirects - - expect(stub_claim_path).to have_been_made - expect(stub_put_content).to have_been_made - expect(stub_publish).to have_been_made - end - end - - describe "#publish_special_route" do - before { allow(logger).to receive(:info) } - - let(:content_id) { SecureRandom.uuid } - let(:special_route) { { content_id:, base_path: "/foo", title: "title", rendering_app: "frontend" } } - let(:content_items) { { special_routes: [special_route] } } - - it "takes ownership of the route and publishes the content item" do - stub_claim_path = stub_call_claim_path(special_route[:base_path]) - stub_put_content = stub_call_put_content(special_route[:content_id], special_route.except(:content_id), "major") - stub_publish = stub_call_publish(special_route[:content_id], "major") - - tasks.publish_special_route(content_id) - - expect(stub_claim_path).to have_been_made - expect(stub_put_content).to have_been_made - expect(stub_publish).to have_been_made - end - end - - describe "#publish_special_routes" do - before { allow(logger).to receive(:info) } - - let(:special_route) { { content_id: SecureRandom.uuid, base_path: "/foo", title: "title", rendering_app: "frontend" } } - let(:content_items) { { special_routes: [special_route] } } - - it "takes ownership of the route and publishes the content item" do - stub_claim_path = stub_call_claim_path(special_route[:base_path]) - stub_put_content = stub_call_put_content(special_route[:content_id], special_route.except(:content_id), "major") - stub_publish = stub_call_publish(special_route[:content_id], "major") - - tasks.publish_special_routes - - expect(stub_claim_path).to have_been_made - expect(stub_put_content).to have_been_made - expect(stub_publish).to have_been_made - end - end - - describe "#claim_path" do - before { allow(logger).to receive(:info).with(/Claiming/) } - - let(:path) { "/some/page" } - - it "takes ownership of the path, overriding any existing ownership" do - stub = stub_call_claim_path(path) - - tasks.claim_path(path) - - expect(stub).to have_been_made - end - end - - describe "#publish_content_item" do - before { allow(logger).to receive(:info).with(/Publishing/) } - - let(:content_id) { SecureRandom.uuid } - let(:payload) { { base_path: "/foo", title: "title", description: "description" } } - let(:update_type) { "like, super major" } - - it "puts the content and then publishes it" do - stub_put_content = stub_call_put_content(content_id, payload, update_type) - stub_publish = stub_call_publish(content_id, update_type) - - tasks.publish_content_item(content_id, payload, update_type) - - expect(stub_put_content).to have_been_made - expect(stub_publish).to have_been_made - end - end - - def stub_call_claim_path(path) - stub_publishing_api_path_reservation(path, publishing_app: "account-api", override_existing: true) - end - - def stub_call_put_content(content_id, payload, update_type) - stub_publishing_api_put_content(content_id, hash_including(payload.merge(publishing_app: "account-api", locale: "en", update_type:))) - end - - def stub_call_publish(content_id, update_type) - stub_publishing_api_publish(content_id, { update_type:, locale: "en" }) - end -end