diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 2a0de88ec..f53327966 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -8,7 +8,6 @@ def close end class ApplicationController < ActionController::Base - include DuaMixin include Encoder include ErrorMixin include NumberMixin diff --git a/app/controllers/dua_controller.rb b/app/controllers/dua_controller.rb deleted file mode 100644 index a6122d6e9..000000000 --- a/app/controllers/dua_controller.rb +++ /dev/null @@ -1,60 +0,0 @@ -# TODO: remove this, then remove it from exclude list in top-level .rubocop.yml -class DuaController < ApplicationController - before_action :require_user - - #:nocov: - def index - object = InvObject.where('inv_objects.ark = ?', params_u(:object)).first - dua_hash = with_fetched_tempfile(object.dua_uri) { |f| Dua.parse_file(f) } - if params['commit'] == 'Accept' - (flash[:message] = 'You must check that you accept the terms.') && return if params[:accept].blank? - if params[:name].blank? || params[:affiliation].blank? || params[:user_agent_email].blank? - (flash[:message] = 'Please enter the required fields') && return - end - (flash[:message] = 'You must fill in a valid return email address.') && return unless params[:user_agent_email] =~ /^.+@.+$/ - - group = object.group - DuaMailer.dua_email(to: params[:user_agent_email], - cc: APP_CONFIG['dua_email_to'] + [dua_hash['Notification'] || ''], - reply_to: dua_hash['Notification'], - title: dua_hash['Title'], - name: params[:name], - affiliation: params[:affiliation], - object: params_u(:object), - collection: group.description, - terms: dua_hash['Terms']).deliver - # user accepted DUA, go ahead and process file/object/version download - session[:collection_acceptance][group.id] = (dua_hash['Persistence'] || 'single') - redirect_to mk_merritt_url('d', params[:object], params[:version], params[:file]) - elsif params[:commit] == 'Do Not Accept' - redirect_to mk_merritt_url('m', params[:object], params[:version]) - else - @title = dua_hash['Title'] - @terms = dua_hash['Terms'] - end - end - #:nocov: - - # TODO: is this only used for DUAs? if so, let's remove it - # rubocop:disable Security/Open - def with_fetched_tempfile(*args) - require 'open-uri' - require 'fileutils' - # TODO: figure out what we really mean to be opening here, & use more specific methods - open(*args) do |data| - tmp_file = Tempfile.new('mrt_http') - begin - until (buff = data.read(4096)).nil? - tmp_file << buff - end - tmp_file.rewind - yield(tmp_file) - ensure - tmp_file.close - tmp_file.delete - end - end - end - # rubocop:enable Security/Open - -end diff --git a/app/controllers/file_controller.rb b/app/controllers/file_controller.rb index 6ad861f8a..5a9fabb94 100644 --- a/app/controllers/file_controller.rb +++ b/app/controllers/file_controller.rb @@ -62,7 +62,6 @@ def check_download def check_version version = @file.inv_version obj = version.inv_object - check_dua(obj, { object: obj, version: version, file: @file }) end def not_found_obj diff --git a/app/controllers/help_controller.rb b/app/controllers/help_controller.rb deleted file mode 100644 index 840accc29..000000000 --- a/app/controllers/help_controller.rb +++ /dev/null @@ -1,4 +0,0 @@ -# :nocov: -class HelpController < ApplicationController -end -# :nocov: diff --git a/app/controllers/object_controller.rb b/app/controllers/object_controller.rb index 527c65f98..8984872c9 100644 --- a/app/controllers/object_controller.rb +++ b/app/controllers/object_controller.rb @@ -16,10 +16,6 @@ class ObjectController < ApplicationController end end - before_action(only: %i[download download_user presign]) do - check_dua(@object, { object: @object }) - end - before_action(only: %i[ingest mint update]) do if current_user render(status: 404, plain: '') unless current_user.groups('write').any? { |g| g.submission_profile == params[:profile] } diff --git a/app/controllers/version_controller.rb b/app/controllers/version_controller.rb index 932e3a374..aed64d043 100644 --- a/app/controllers/version_controller.rb +++ b/app/controllers/version_controller.rb @@ -10,11 +10,6 @@ class VersionController < ApplicationController end end - before_action(only: %i[download download_user presign]) do - obj = @version.inv_object - check_dua(obj, { object: obj, version: @version }) - end - before_action(only: %i[download download_user]) do if @version.exceeds_download_size? render file: "#{Rails.root}/public/403.html", status: 403, layout: false diff --git a/app/helpers/dua_helper.rb b/app/helpers/dua_helper.rb deleted file mode 100644 index 3ace72e99..000000000 --- a/app/helpers/dua_helper.rb +++ /dev/null @@ -1,3 +0,0 @@ -module DuaHelper - -end diff --git a/app/lib/dua_mixin.rb b/app/lib/dua_mixin.rb deleted file mode 100644 index ebdaf4114..000000000 --- a/app/lib/dua_mixin.rb +++ /dev/null @@ -1,40 +0,0 @@ -# TODO: remove this, then remove it from exclude list in top-level .rubocop.yml -module DuaMixin - - # :nocov: - # returns the response of the HTTP request for the DUA URI - def process_dua_request(uri) - http = Net::HTTP.new(uri.host, uri.port) - uri_response = http.request(Net::HTTP::Get.new(uri.request_uri)) - uri_response.instance_of?(Net::HTTPOK) - end - # :nocov: - - # :nocov: - # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity - def check_dua(object, redirect_args) - # bypass DUA processing for python scripts - indicated by special param - return if params[:blue] - - puts 333 - puts session - puts 444 - puts session.keys - puts 555 - puts redirect_args - - session[:collection_acceptance] ||= Hash.new(false) - # check if user already saw DUA and accepted: if so, return - if session[:collection_acceptance][object.group.id] - # clear out acceptance if it does not have session persistence - session[:collection_acceptance].delete(object.group.id) if session[:collection_acceptance][object.group.id] != 'session' - nil - elsif object.dua_exists? && process_dua_request(object.dua_uri) - # if the DUA for this collection exists, display DUA to user for acceptance before displaying file - puts 666 - redirect_to({ controller: 'dua', action: 'index' }.merge(redirect_args)) && return - end - end - # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity - # :nocov: -end diff --git a/app/mailers/dua_mailer.rb b/app/mailers/dua_mailer.rb deleted file mode 100644 index 83f73ec92..000000000 --- a/app/mailers/dua_mailer.rb +++ /dev/null @@ -1,16 +0,0 @@ -# :nocov: -class DuaMailer < ActionMailer::Base - default from: APP_CONFIG['dua_email_from'] - - def dua_email(args) - @to = args[:to] - @title = args[:title] - @name = args[:name] - @affiliation = args[:affiliation] - @collection = args[:collection] - @object = args[:object] - @terms = args[:terms] - mail(to: @to, cc: args[:cc], subject: "Merritt DUA acceptance: #{@title}", reply_to: args[:reply_to]) - end -end -# :nocov: diff --git a/app/models/dua.rb b/app/models/dua.rb deleted file mode 100644 index 057bce87c..000000000 --- a/app/models/dua.rb +++ /dev/null @@ -1,17 +0,0 @@ -# :nocov: -class Dua - def self.parse_file(dua_file) - # regex to capture match of name:value and put them into a hash - rx = /(\w+)\s*:\s*(.+)/ - a = [] - File.open(dua_file.path) do |f| - while (line = f.gets) - unless rx.match(line).nil? - a << $LAST_MATCH_INFO.captures.map(&:strip) # clean up the entries - end - end - a.to_h - end - end -end -# :nocov: diff --git a/app/models/inv_duas.rb b/app/models/inv_duas.rb deleted file mode 100644 index 77fe68a89..000000000 --- a/app/models/inv_duas.rb +++ /dev/null @@ -1,4 +0,0 @@ -class InvDuas < ApplicationRecord - belongs_to :inv_object - has_one :sha_duas, foreign_key: 'id', inverse_of: :inv_duas -end diff --git a/app/models/inv_object.rb b/app/models/inv_object.rb index 4dfad04fa..d88462cac 100644 --- a/app/models/inv_object.rb +++ b/app/models/inv_object.rb @@ -7,7 +7,6 @@ class InvObject < ApplicationRecord has_many :inv_files, through: :inv_versions has_many :inv_dublinkernels - has_one :inv_duas has_one :inv_embargo has_many :inv_collections_inv_objects @@ -57,19 +56,6 @@ def bytestream_uri3 URI.parse("#{APP_CONFIG['uri_3']}#{node_number}/#{to_param}") end - def dua_exists? - merritt_retry_block do - !inv_duas.blank? - end - end - - # :nocov: - def dua_uri - URI.parse("#{APP_CONFIG['uri_1']}#{node_number}/#{inv_collection.to_param}/0/#{urlencode(APP_CONFIG['mrt_dua_file'])}") - end - - # :nocov: - def node_number inv_nodes.where('inv_nodes_inv_objects.role' => 'primary').select('inv_nodes.number').map(&:number).first end diff --git a/config/database.yml b/config/database.yml index 633d22d30..95721a13a 100644 --- a/config/database.yml +++ b/config/database.yml @@ -13,7 +13,8 @@ default: &default encoding: utf8mb4 host: "{!SSM: inv/db-host}" database: "{!SSM: inv/db-name}" - pool: 20 + pool: 25 + idle_timeout: 0 port: 3306 username: "{!SSM: inv/readwrite/db-user}" password: "{!SSM: inv/readwrite/db-password}" @@ -34,4 +35,4 @@ docker: &docker username: user password: password encoding: utf8mb4 - + idle_timeout: 0 diff --git a/spec/controllers/dua_controller_spec.rb b/spec/controllers/dua_controller_spec.rb deleted file mode 100644 index 814750b3d..000000000 --- a/spec/controllers/dua_controller_spec.rb +++ /dev/null @@ -1,51 +0,0 @@ -require 'rails_helper' - -class Openable - def initialize(data) - @data = data - end - - def open(*_rest) - io = StringIO.new(@data, 'r') - return io unless block_given? - - yield io - end -end - -describe DuaController do - describe ':with_fetched_tempfile' do - attr_reader :data - - before(:each) do - # We don't really care what the data is so long as we can read/write it in text mode - @data = SecureRandom.hex(5000).freeze - end - - skip it 'copies an arbitrary openable to a tempfile' do - contents = nil - - controller.send(:with_fetched_tempfile, Openable.new(data)) do |tmp_file| - contents = tmp_file.read - end - expect(contents).to eq(data) - end - - it 'copies a file to a tempfile' do - bytes_file = Tempfile.new(%w[foo bin]) - bytes_file.write(data) - bytes_file.close - bytes_file_path = File.expand_path(bytes_file.path) - - begin - contents = nil - controller.send(:with_fetched_tempfile, bytes_file_path) do |tmp_file| - contents = tmp_file.read - end - expect(contents).to eq(data) - ensure - File.delete(bytes_file_path) - end - end - end -end diff --git a/spec/controllers/file_controller_spec.rb b/spec/controllers/file_controller_spec.rb index 17ae421a1..2386c735e 100644 --- a/spec/controllers/file_controller_spec.rb +++ b/spec/controllers/file_controller_spec.rb @@ -198,20 +198,6 @@ def my_presign_wrapper end.to raise_error(MerrittRetryMixin::RetryException) end - it 'redirects to presign url for the file - retry dua check' do - mock_permissions_all(user_id, collection_id) - - request.session.merge!({ uid: user_id }) - allow_any_instance_of(InvObject) - .to receive(:inv_duas) - .with(any_args) - .and_raise(Mysql2::Error::ConnectionError.new('Simulate Failure')) - - expect do - get(:presign, params: params) - end.to raise_error(MerrittRetryMixin::RetryException) - end - it 'test ark encoding recovery' do mock_permissions_all(user_id, collection_id)