diff --git a/app/generators/elastic_search_bet_id_generator.rb b/app/generators/elastic_search_bet_id_generator.rb deleted file mode 100644 index 35037fe8..00000000 --- a/app/generators/elastic_search_bet_id_generator.rb +++ /dev/null @@ -1,5 +0,0 @@ -class ElasticSearchBetIDGenerator - def self.generate(query, match_type) - "#{query}-#{match_type}" - end -end diff --git a/app/lib/services.rb b/app/lib/services.rb index 84a2500f..4e22a91f 100644 --- a/app/lib/services.rb +++ b/app/lib/services.rb @@ -8,14 +8,4 @@ def self.publishing_api bearer_token: ENV["PUBLISHING_API_BEARER_TOKEN"] || "example", ) end - - # TODO: update RUMMAGER_BEARER_TOKEN to SEARCH_API_BEARER_TOKEN - def self.search_api - @search_api ||= - GdsApi::Search.new( - Plek.find("search-api"), - api_version: "V2", - bearer_token: ENV["RUMMAGER_BEARER_TOKEN"] || "example", - ) - end end diff --git a/app/models/elastic_search_recommended_link.rb b/app/models/elastic_search_recommended_link.rb deleted file mode 100644 index 2e7b5b3b..00000000 --- a/app/models/elastic_search_recommended_link.rb +++ /dev/null @@ -1,36 +0,0 @@ -class ElasticSearchRecommendedLink - delegate :format, :link, :title, :description, to: :recommended_link - - def initialize(recommended_link) - @recommended_link = recommended_link - end - - def body - { - link:, - details: details.to_json, - } - end - - def details - { - title:, - link:, - description:, - format:, - indexable_content:, - } - end - - def id - link - end - - def indexable_content - recommended_link.keywords - end - -private - - attr_reader :recommended_link -end diff --git a/app/parsers/bet_params_parser.rb b/app/parsers/bet_params_parser.rb deleted file mode 100644 index d805dcb5..00000000 --- a/app/parsers/bet_params_parser.rb +++ /dev/null @@ -1,44 +0,0 @@ -class BetParamsParser - attr_reader :bet_params, :user_id - - def initialize(bet_params, user_id) - @bet_params = bet_params - @user_id = user_id - end - - def bet_attributes - bet_params.merge( - expiration_date: date_attributes, - user_id:, - manual: true, - is_best: best_bet?, - permanent: permanent?, - ) - end - -private - - def date_attributes - date_complete? ? DateParser.new(**date_hash).date : "" - end - - def date_hash - bet_params[:expiration_date].to_h.deep_symbolize_keys - end - - def date_complete? - date_hash.values.reject(&:empty?).count == 3 - end - - def best_bet? - !is_worst_bet? - end - - def is_worst_bet? - bet_params[:is_worst] == "1" - end - - def permanent? - bet_params[:permanent] == "1" - end -end diff --git a/app/parsers/date_parser.rb b/app/parsers/date_parser.rb deleted file mode 100644 index 7e536316..00000000 --- a/app/parsers/date_parser.rb +++ /dev/null @@ -1,15 +0,0 @@ -class DateParser - attr_reader :day, :month, :year - - def initialize(day:, month:, year:) - @day = day - @month = month - @year = year - end - - def date - Time.zone.local(year, month, day) - rescue ArgumentError - "" - end -end diff --git a/app/validators/bet_date_validator.rb b/app/validators/bet_date_validator.rb deleted file mode 100644 index 426ab75d..00000000 --- a/app/validators/bet_date_validator.rb +++ /dev/null @@ -1,34 +0,0 @@ -class BetDateValidator < ActiveModel::EachValidator - def validate_each(record, attribute, value) - @record = record - @attribute = attribute - @value = value - - validations - end - -private - - attr_reader :record, :attribute, :value - - def validations - if expiration_date_missing? - record_error("is invalid") - end - if expiration_date_in_past? - record_error("can't be in the past") - end - end - - def expiration_date_missing? - record.permanent == false && value.nil? - end - - def expiration_date_in_past? - record.expiration_date.present? && record.expiration_date < Time.zone.today - end - - def record_error(msg) - record.errors.add(attribute, message: msg) - end -end diff --git a/app/validators/bet_link_validator.rb b/app/validators/bet_link_validator.rb deleted file mode 100644 index e3bd1608..00000000 --- a/app/validators/bet_link_validator.rb +++ /dev/null @@ -1,47 +0,0 @@ -require "uri" - -class BetLinkValidator < ActiveModel::EachValidator - def validate_each(record, attribute, value) - @record = record - @attribute = attribute - uri = parse(value) - - return record_error("couldn't be parsed as a URL") if value.blank? || uri.nil? - - return validate_external_link(uri, value) if uri&.absolute? - - validate_path(value) - end - -private - - def validate_external_link(uri, value) - if RecommendedLink.find_by(link: value).nil? - if %w[www.gov.uk gov.uk].include?(uri.host) - record_error("looks like an internal link so should just be a path: use /random, not gov.uk/random.") - else - record_error("looks like an external link, so you should first create a recommended link in search admin (click External links)") - end - end - - unless uri.is_a?(URI::HTTP) - record_error("looks like an external link, so you should prepend it with http:// or https://, like https://#{value}") - end - end - - def validate_path(value) - if value.nil? || value[0] != "/" - record_error("looks like an internal link, so should be formatted like /my-link, with a forward slash") - end - end - - def record_error(msg) - @record.errors.add(@attribute, message: msg) - end - - def parse(value) - URI.parse(value) - rescue URI::InvalidURIError - nil - end -end diff --git a/app/views/similar_search_results/_form.html.erb b/app/views/similar_search_results/_form.html.erb deleted file mode 100644 index 9d77a425..00000000 --- a/app/views/similar_search_results/_form.html.erb +++ /dev/null @@ -1,16 +0,0 @@ -<%= form_tag similar_search_result_path(:result), method: :get do %> - <%= render "govuk_publishing_components/components/input", { - label: { - text: 'Path or URL of search result (eg. /guidance/pupil-premium-reviews)' - }, - name: "base_path", - value: base_path, - type: "search" - } %> - - <%= render "govuk_publishing_components/components/button", { - text: "Show similar search results", - name: "commit", - type: "submit" - } %> -<% end %> diff --git a/app/views/similar_search_results/_results.html.erb b/app/views/similar_search_results/_results.html.erb deleted file mode 100644 index 2d87a8f2..00000000 --- a/app/views/similar_search_results/_results.html.erb +++ /dev/null @@ -1,32 +0,0 @@ -
- <%= render "govuk_publishing_components/components/input", { - label: { - text: "Filter search results" - }, - name: "table-filter", - type: "search", - search_icon: true, - tabindex: 0 - } %> - - <%= GovukPublishingComponents::AppHelpers::TableHelper.helper(self) do |t| %> - <%= t.head do %> - <%= t.header "#" %> - <%= t.header "Title" %> - <%= t.header "Score" %> - <%= t.header "Format" %> - <%= t.header "Content store document type" %> - <% end %> - <%= t.body do %> - <% results.each_with_index do |result, index| %> - <%= t.row do %> - <%= t.cell index + 1 %> - <%= t.cell link_to(result.title, Plek.new.website_root + result.link, target: 'blank', class: 'govuk-link') %> - <%= t.cell result.es_score %> - <%= t.cell result.format %> - <%= t.cell result.content_store_document_type %> - <% end %> - <% end %> - <% end %> - <% end %> -
diff --git a/app/views/similar_search_results/new.html.erb b/app/views/similar_search_results/new.html.erb deleted file mode 100644 index 4c16431a..00000000 --- a/app/views/similar_search_results/new.html.erb +++ /dev/null @@ -1,3 +0,0 @@ -<%= render "common/page_title", title: "Search for similar search results" %> - -<%= render 'form', base_path: base_path %> diff --git a/app/views/similar_search_results/show.html.erb b/app/views/similar_search_results/show.html.erb deleted file mode 100644 index 26750b91..00000000 --- a/app/views/similar_search_results/show.html.erb +++ /dev/null @@ -1,7 +0,0 @@ -<%= render "common/page_title", title: "Similar search results" %> - -<%= render 'form', base_path: base_path %> - -<% if results.present? %> - <%= render 'results', results: results %> -<% end %> diff --git a/config/application.rb b/config/application.rb index 672f70f5..0468d312 100644 --- a/config/application.rb +++ b/config/application.rb @@ -58,22 +58,5 @@ class Application < Rails::Application # Require `belongs_to` associations by default. Previous versions had false. config.active_record.belongs_to_required_by_default = false - - # Rotate SHA1 cookies to SHA256 (the new Rails 7 default) - # TODO: Remove this after existing user sessions have been rotated - # https://guides.rubyonrails.org/v7.0/upgrading_ruby_on_rails.html#key-generator-digest-class-changing-to-use-sha256 - Rails.application.config.action_dispatch.cookies_rotations.tap do |cookies| - salt = Rails.application.config.action_dispatch.authenticated_encrypted_cookie_salt - secret_key_base = Rails.application.secrets.secret_key_base - next if secret_key_base.blank? - - key_generator = ActiveSupport::KeyGenerator.new( - secret_key_base, iterations: 1000, hash_digest_class: OpenSSL::Digest::SHA1 - ) - key_len = ActiveSupport::MessageEncryptor.key_len - secret = key_generator.generate_key(salt, key_len) - - cookies.rotate :encrypted, secret - end end end diff --git a/config/initializers/services_and_listeners.rb b/config/initializers/services_and_listeners.rb deleted file mode 100644 index 1d78bb25..00000000 --- a/config/initializers/services_and_listeners.rb +++ /dev/null @@ -1,16 +0,0 @@ -require "gds_api/search" - -# Extend the adapters to allow us to request URLs directly. -module GdsApi - class Search < Base - def get(path) - request_url = "#{base_url}#{path}" - get_json(request_url) - end - - def delete!(path) - request_url = "#{base_url}#{path}" - delete_json(request_url) - end - end -end diff --git a/config/initializers/zeitwerk.rb b/config/initializers/zeitwerk.rb deleted file mode 100644 index 7ec6463a..00000000 --- a/config/initializers/zeitwerk.rb +++ /dev/null @@ -1,5 +0,0 @@ -Rails.autoloaders.each do |autoloader| - autoloader.inflector.inflect( - "elastic_search_bet_id_generator" => "ElasticSearchBetIDGenerator", - ) -end diff --git a/config/sidekiq.yml b/config/sidekiq.yml deleted file mode 100644 index 5dbd442c..00000000 --- a/config/sidekiq.yml +++ /dev/null @@ -1,13 +0,0 @@ ---- -:scheduler: - :concurrency: 2 - :schedule: - expired_bet_worker: - every: '1h' - class: ExpiredBetWorker - delete_old_bets_worker: - cron: '0 5 * * * Europe/London' - class: DeleteOldBetsWorker - notify_expiring_bets_worker: - cron: '0 7 * * * Europe/London' - class: NotifyExpiringBetsWorker diff --git a/features/step_definitions/query_steps.rb b/features/step_definitions/query_steps.rb deleted file mode 100644 index 52324ca1..00000000 --- a/features/step_definitions/query_steps.rb +++ /dev/null @@ -1,32 +0,0 @@ -When(/^I create a new query$/) do - create_query(query: "jobs", match_type: "exact") -end - -Then(/^the query should be listed on the query index$/) do - check_for_query_on_index_page(query: "jobs", match_type: "exact") -end - -When(/^I edit the query$/) do - edit_query(query_text: @query.query, new_query_text: "visas") -end - -Then(/^the edited query should be listed on the query index$/) do - check_for_query_on_index_page(query: "visas", match_type: @query.match_type) -end - -When(/^I delete the query$/) do - delete_query(query_text: @query.query) -end - -Then(/^the query should not be listed on the query index$/) do - check_for_absence_of_query_on_index_page(query: @query.query, match_type: @query.match_type) -end - -When(/^I visit the query$/) do - visit query_path(@query || Query.last) -end - -Then(/^I should see the queries search results on the page$/) do - expect(page).to have_selector("iframe") - expect(find("iframe")[:src]).to include "gov.uk/search/all?keywords=jobs" -end diff --git a/features/support/best_bets.rb b/features/support/best_bets.rb deleted file mode 100644 index 7850558f..00000000 --- a/features/support/best_bets.rb +++ /dev/null @@ -1,167 +0,0 @@ -def create_query(user: nil, query: nil, match_type: nil, bets: []) - visit queries_path - click_on "New query" - - fill_in "Query", with: query if query - select match_type.humanize, from: "Match type" if match_type - - click_on "Save" - - unless user == :admin - check_query_page_has_no_date_fields - end - bets.each do |(link, is_best, position, comment, permanent)| - fill_in "Link", with: link - if is_best - fill_in "Position", with: position - else - check "Is worst bet?" - end - if permanent == 1 - check "Make permanent?" - end - fill_in "Comment", with: comment - click_on "Save" - end -end - -def edit_query(query_text: nil, new_query_text: nil) - visit queries_path - - within(".queries") do - click_on query_text - end - - click_on "Edit query" - fill_in "Query", with: new_query_text - click_on "Save" -end - -def delete_query(query_text: nil) - visit queries_path - - within(".queries") do - click_on query_text - end - - click_on "Delete query" -end - -def check_for_query_on_index_page(query: nil, match_type: nil) - visit queries_path - - within(".queries .govuk-table__body .govuk-table__row") do - expect(page).to have_content(query) - expect(page).to have_content(match_type) - end -end - -def check_for_bet_on_query_page(permanent: nil, link: nil, is_best: nil, position: nil, query: nil, match_type: nil, comment: nil) - query = Query.where(query:, match_type:).first - visit query_path(query) - - bet_type = is_best ? "best" : "worst" - - within(".#{bet_type}-bets .govuk-table__body .govuk-table__row") do - expect(page).to have_css "td", text: link - expect(page).to have_css "td", text: comment - expect(page).to have_css "td", text: position if is_best - expect(pate).to have_css "td", text: "Permanent" if permanent - end -end - -def edit_best_bet(bet:, link:, permanent: nil) - visit query_path(bet.query) - click_on bet.link - if permanent - check "Make permanent?" - end - fill_in "Link", with: link - click_on "Save" -end - -def delete_best_bet(query, _best_bet) - visit query_path(query) - - within ".best-bets .govuk-table__body .govuk-table__row:first-child" do - click_on "Delete" - end -end - -def check_for_absence_of_query_on_index_page(query: nil, match_type: nil) - visit queries_path - - expect(page).not_to have_content(query) - expect(page).not_to have_content(match_type) -end - -def check_absence_of_best_bet_on_query_page(query, link) - visit query_path(query) - expect(page).not_to have_content(link) -end - -def check_for_queries_in_csv_format(queries) - headers, *rows = *CSV.parse(page.body) - - expect(headers).to eq(["query", "match_type", "link", "best/worst", "comment", "status", "position", "last edit date", "author"]) - - queries.each do |query| - query.bets.each do |bet| - expect(rows).to include([query.query, query.match_type, bet.link, "best", "", "Permanent"]) - end - end -end - -def check_search_api_was_sent_an_exact_best_bet_document(query) - elasticsearch_doc = build_es_doc_from_query(query) - doc_id = "#{query.query}-#{query.match_type}" - - expect(@search_api).to have_received(:add_document).with( - doc_id, - elasticsearch_doc, - "metasearch", - ) -end - -def check_search_api_was_sent_a_best_bet_delete(query_es_ids) - query_es_ids.each do |id| - expect(@search_api).to have_received(:delete_document).with(id, "metasearch") - end -end - -def check_search_api_was_sent_a_recommended_link_delete(link:, index:) - assert_search_api_deleted_item(link, index:) -end - -def confirm_best_bets_elasticsearch_format(dump, queries) - queries.each do |query| - es_doc_header = { - "index" => { - "_id" => "#{query.query}-#{query.match_type}", - "_type" => "best_bet", - }, - } - - es_doc = build_es_doc_from_query(query) - expect(dump).to include("#{es_doc_header.to_json}\n#{es_doc.to_json}") - end -end - -def build_es_doc_from_query(query) - details_json = { - best_bets: query.best_bets.map { |bet| { link: bet.link, position: bet.position } }, - worst_bets: query.worst_bets.map { |bet| { link: bet.link } }, - }.to_json - - query_field = "#{query.match_type}_query".to_sym - - { - query_field => query.query, - details: details_json, - } -end - -def check_query_page_has_no_date_fields - expect(page).to_not have_content "Make permanent?" - expect(page).to_not have_content "Set an expiry date" -end diff --git a/features/support/recommended_links.rb b/features/support/recommended_links.rb index e0bc7a4c..379bc7b9 100644 --- a/features/support/recommended_links.rb +++ b/features/support/recommended_links.rb @@ -74,22 +74,6 @@ def check_for_recommended_links_in_csv_format(recommended_links) end end -def check_search_api_was_sent_an_exact_recommended_link_document(recommended_link:, index:) - elasticsearch_doc = build_doc_from_recommended_link(recommended_link) - assert_search_api_posted_item( - elasticsearch_doc.merge( - "_type" => "edition", - "link" => recommended_link.link, - "_id" => recommended_link.link, - ), - index:, - ) -end - -def check_search_api_was_sent_a_recommended_link_delete(link:, index:) - assert_search_api_deleted_item(link, index:) -end - def check_recommended_link_was_published(recommended_link, publishing_count) assert_publishing_api_put_content( recommended_link.content_id, @@ -104,20 +88,6 @@ def check_recommended_link_was_unpublished(content_id) assert_publishing_api_unpublish(content_id) end -def confirm_recommended_links_elasticsearch_format(dump, recommended_links) - recommended_links.each do |recommended_link| - es_doc_header = { - "index" => { - "_id" => recommended_link.link, - "_type" => recommended_link.format, - }, - } - - es_doc = build_doc_from_recommended_link(recommended_link, include_es_data: true) - expect(dump).to include("#{es_doc_header.to_json}\n#{es_doc.to_json}") - end -end - def build_doc_from_recommended_link(recommended_link, include_es_data: false) details = { title: recommended_link.title, diff --git a/features/support/rummager.rb b/features/support/rummager.rb deleted file mode 100644 index 29e061a8..00000000 --- a/features/support/rummager.rb +++ /dev/null @@ -1,17 +0,0 @@ -Before "@stub_best_bets" do - @search_api = double(:search_api, delete_document: true, add_document: true) - allow(Services).to receive(:search_api).and_return(@search_api) -end - -Before "@stub_best_bets_with_404" do - @search_api = double(:search_api, add_document: true) - allow(@search_api).to receive(:delete_document).and_raise(GdsApi::HTTPNotFound.new(404)) - allow(Services).to receive(:search_api).and_return(@search_api) -end - -Before "@stub_best_bets_with_500" do - @search_api = double(:search_api) - allow(@search_api).to receive(:delete_document).and_raise(GdsApi::HTTPClientError.new(500)) - allow(@search_api).to receive(:add_document).and_raise(GdsApi::HTTPClientError.new(500)) - allow(Services).to receive(:search_api).and_return(@search_api) -end diff --git a/lib/tasks/once_off/remove_council_external_links.rake b/lib/tasks/once_off/remove_council_external_links.rake deleted file mode 100644 index 326e7cc3..00000000 --- a/lib/tasks/once_off/remove_council_external_links.rake +++ /dev/null @@ -1,18 +0,0 @@ -# External links to council homepages are now published and managed -# by Local Links Manager. -namespace :once_off do - desc "Unpublish all external links that are council homepages" - task remove_council_external_links: :environment do - non_councils = [ - "Corporation of London", - "Comhairle nan Eilean Siar", - "City and County of Swansea", - ] - - council_links = RecommendedLink.where("title LIKE '%Council%'") + RecommendedLink.where(title: non_councils) - council_links.each do |link| - ExternalContentPublisher.unpublish(link) - link.destroy! - end - end -end diff --git a/script/cucumber b/script/cucumber deleted file mode 100755 index 51b721ca..00000000 --- a/script/cucumber +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env ruby - -vendored_cucumber_bin = Dir["#{File.dirname(__FILE__)}/../vendor/{gems,plugins}/cucumber*/bin/cucumber"].first -if vendored_cucumber_bin - load File.expand_path(vendored_cucumber_bin) -else - require "rubygems" unless ENV["NO_RUBYGEMS"] - require "cucumber" - load Cucumber::BINARY -end diff --git a/spec/generators/elastic_search_bet_id_generator_spec.rb b/spec/generators/elastic_search_bet_id_generator_spec.rb deleted file mode 100644 index a9366c39..00000000 --- a/spec/generators/elastic_search_bet_id_generator_spec.rb +++ /dev/null @@ -1,10 +0,0 @@ -require "spec_helper" - -describe ElasticSearchBetIDGenerator do - describe ".generate(query, match_type)" do - it "concatenates the `query` and `match_type` with a hyphen" do - generated_id = ElasticSearchBetIDGenerator.generate("jobs", "exact") - expect(generated_id).to eq("jobs-exact") - end - end -end diff --git a/spec/models/elastic_search_recommended_link_spec.rb b/spec/models/elastic_search_recommended_link_spec.rb deleted file mode 100644 index ae87576f..00000000 --- a/spec/models/elastic_search_recommended_link_spec.rb +++ /dev/null @@ -1,29 +0,0 @@ -require "spec_helper" - -describe ElasticSearchRecommendedLink do - let(:recommended_link) do - create( - :recommended_link, - title: "Tax", - link: "https://www.tax.service.gov.uk/", - description: "Self assessment", - keywords: "self, assessment, tax", - content_id: SecureRandom.uuid, - ) - end - - it "builds an elasticsearch doc from the provided recommended link" do - es_recommended_link = ElasticSearchRecommendedLink.new(recommended_link) - - expect(es_recommended_link.body).to eq( - link: "https://www.tax.service.gov.uk/", - details: { - title: "Tax", - link: "https://www.tax.service.gov.uk/", - description: "Self assessment", - format: "recommended-link", - indexable_content: "self, assessment, tax", - }.to_json, - ) - end -end