Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def authenticate_if_needed
# Disable this extra authentication in test mode
return true if Rails.env.test?
return true # any hint of basic auth will stop BL staff from accessing site so instead we open all the "private" demo sites
if (is_hidden || is_staging) && !is_api_or_pdf
if (is_hidden || is_staging) && !is_api_or_pdf # rubocop:disable Lint/UnreachableCode
authenticate_or_request_with_http_basic do |username, password|
username == ENV.fetch("HYKU_DEMO_USER", "bl_demo_user") && password == ENV.fetch("HYKU_DEMO_PASSWORD", "resu_omed_lb")
end
Expand Down
26 changes: 26 additions & 0 deletions config/initializers/hyrax.rb
Original file line number Diff line number Diff line change
Expand Up @@ -230,3 +230,29 @@ def build_query_url(q)

require 'hydra/derivatives'
Hydra::Derivatives::Processors::Video::Processor.config.video_bitrate = '1500k'

# Monkey patch Bulkrax so controlled URI validation allows http://thing.com/a/file/with/an/extension.html
# not just http://thing.com/thing(|/)
# Remove all the trailing slashes from authorities and remove from input if present rather than the inverse
Bulkrax::ImportBehavior.module_eval do

# @param value [String] value to validate
# @param field [String] name of the controlled property
# @return [String, nil] validated URI value or nil
def validate_value(value, field)
if value.match?(::URI::DEFAULT_PARSER.make_regexp)
value = value.strip.chomp
# add trailing forward slash unless one is already present or there's an obvious file extension
value << '/' unless value.match?(%r{/$}) || value.match?(%r{/[^./]+\.[^./]+$})
end

valid = if active_id_for_authority?(value, field)
true
else
value.include?('https') ? value.sub!('https', 'http') : value.sub!('http', 'https')
active_id_for_authority?(value, field)
end

valid ? value : nil
end
end
Loading