Skip to content

Commit

Permalink
Merge Sufia configuration with the CurationConcerns
Browse files Browse the repository at this point in the history
This reduces confusion over which configuration someone should be using.
Fixes #2139
  • Loading branch information
jcoyne committed Jun 13, 2016
1 parent 1ee2d75 commit 9234795
Show file tree
Hide file tree
Showing 8 changed files with 140 additions and 55 deletions.
Expand Up @@ -23,7 +23,7 @@ def create
end

def after_deliver
return unless Sufia::Engine.config.enable_contact_form_delivery
return unless Sufia.config.enable_contact_form_delivery
end
end
end
2 changes: 1 addition & 1 deletion app/views/curation_concerns/base/_form_progress.html.erb
Expand Up @@ -21,7 +21,7 @@
</div>
<% end %>
<div class="panel-footer text-center">
<% if Sufia::Engine.config.active_deposit_agreement_acceptance %>
<% if Sufia.config.active_deposit_agreement_acceptance %>
<label>
<%= check_box_tag 'agreement', 1, f.object.agreement_accepted, required: true %>
<%= t('sufia.active_consent_to_agreement') %><br>
Expand Down
1 change: 1 addition & 0 deletions lib/generators/sufia/config_generator.rb
Expand Up @@ -14,6 +14,7 @@ class Sufia::ConfigGenerator < Rails::Generators::Base
source_root File.expand_path('../templates', __FILE__)

def create_initializer_config_file
remove_file 'config/initializers/curation_concerns.rb'
copy_file 'config/sufia.rb', 'config/initializers/sufia.rb'
end

Expand Down
19 changes: 5 additions & 14 deletions lib/generators/sufia/templates/config/sufia.rb
@@ -1,16 +1,11 @@
Sufia.config do |config|
config.max_days_between_audits = 7
config.max_notifications_for_dashboard = 5
config.register_curation_concern :generic_work

config.permission_levels = {
"Choose Access" => "none",
"View/Download" => "read",
"Edit" => "edit"
}
# How many notifications should be displayed on the dashboard
# config.max_notifications_for_dashboard = 5

config.owner_permission_levels = {
"Edit" => "edit"
}
# How frequently should a file be audited.
# config.max_days_between_audits = 7

# Enable displaying usage statistics in the UI
# Defaults to FALSE
Expand Down Expand Up @@ -46,10 +41,6 @@
# Store identifier minter's state in a file for later replayability
# config.minter_statefile = '/tmp/minter-state'

# Process for translating Fedora URIs to identifiers and vice versa
# config.translate_uri_to_id = ActiveFedora::Noid.config.translate_uri_to_id
# config.translate_id_to_uri = ActiveFedora::Noid.config.translate_id_to_uri

# Specify the prefix for Redis keys:
# config.redis_namespace = "sufia"

Expand Down
5 changes: 3 additions & 2 deletions lib/sufia.rb
Expand Up @@ -27,8 +27,9 @@ module Sufia
extend ActiveSupport::Autoload

eager_autoload do
autoload :RedisEventStore
autoload :Arkivo
autoload :Configuration
autoload :RedisEventStore
autoload :Zotero
end

Expand All @@ -39,7 +40,7 @@ def self.queue
end

def self.config(&block)
@config ||= Sufia::Engine::Configuration.new
@config ||= Sufia::Configuration.new

yield @config if block

Expand Down
127 changes: 127 additions & 0 deletions lib/sufia/configuration.rb
@@ -0,0 +1,127 @@
module Sufia
class Configuration
def curation_concerns_config
@curation_concerns_config ||= CurationConcerns.config
end

delegate(*(CurationConcerns.config.methods - Object.methods),
to: :curation_concerns_config)

attr_writer :persistent_hostpath
def persistent_hostpath
@persistent_hostpath ||= "http://localhost/files/"
end

attr_writer :redis_namespace
def redis_namespace
@redis_namespace ||= "sufia"
end

# TODO: This should move to curation_concerns
attr_writer :libreoffice_path
def libreoffice_path
@libreoffice_path ||= "soffice"
end

attr_writer :enable_contact_form_delivery
def enable_contact_form_delivery
@enable_contact_form_delivery ||= false
end

attr_writer :browse_everything
def browse_everything
@browse_everything ||= nil
end

attr_writer :analytics
def analytics
@analytics ||= false
end
attr_writer :citations
def citations
@citations ||= false
end

attr_writer :max_notifications_for_dashboard
def max_notifications_for_dashboard
@max_notifications_for_dashboard ||= 5
end

attr_writer :activity_to_show_default_seconds_since_now
def activity_to_show_default_seconds_since_now
@activity_to_show_default_seconds_since_now ||= 24 * 60 * 60
end

attr_writer :arkivo_api
def arkivo_api
@arkivo_api ||= false
end

attr_writer :geonames_username
def geonames_username
@geonames_username ||= ""
end

attr_writer :active_deposit_agreement_acceptance
def active_deposit_agreement_acceptance
return true if @active_deposit_agreement_acceptance.nil?
@active_deposit_agreement_acceptance
end

attr_writer :batch_user_key
def batch_user_key
@batch_user_key ||= 'batchuser@example.com'
end

attr_writer :audit_user_key
def audit_user_key
@audit_user_key ||= 'audituser@example.com'
end

# TODO: this is called working_path in curation_concerns
attr_writer :upload_path
def upload_path
@upload_path ||= ->() { Rails.root + 'tmp' + 'uploads' }
end

# Should a button with "Share my work" show on the front page to all users (even those not logged in)?
attr_writer :always_display_share_button
def always_display_share_button
return true if @always_display_share_button.nil?
@always_display_share_button
end

# Defaulting analytic start date to whenever the file was uploaded by leaving it blank
attr_writer :analytic_start_date
attr_reader :analytic_start_date

attr_writer :display_media_download_link
def display_media_download_link
@display_media_download_link ||= false
end

attr_writer :permission_levels
def permission_levels
@permission_levels ||= { "Choose Access" => "none",
"View/Download" => "read",
"Edit" => "edit" }
end

attr_writer :owner_permission_levels
def owner_permission_levels
@owner_permission_levels ||= { "Edit Access" => "edit" }
end

# TODO: Delegate to curation_concerns when https://github.com/projecthydra/curation_concerns/pull/848 is merged
attr_writer :translate_uri_to_id
def translate_uri_to_id
@translate_uri_to_id ||= ActiveFedora::Noid.config.translate_uri_to_id
end

# TODO: Delegate to curation_concerns when https://github.com/projecthydra/curation_concerns/pull/848 is merged
attr_writer :translate_id_to_uri
def translate_id_to_uri
@translate_id_to_uri ||= ActiveFedora::Noid.config.translate_id_to_uri
end
end
end
37 changes: 1 addition & 36 deletions lib/sufia/engine.rb
Expand Up @@ -39,14 +39,14 @@ class Engine < ::Rails::Engine
Hydra::Derivatives.enable_ffmpeg = c.enable_ffmpeg
Hydra::Derivatives.libreoffice_path = c.libreoffice_path

# TODO: Remove when https://github.com/projecthydra/curation_concerns/pull/848 is merged
ActiveFedora::Base.translate_uri_to_id = c.translate_uri_to_id
ActiveFedora::Base.translate_id_to_uri = c.translate_id_to_uri
ActiveFedora::Noid.config.template = c.noid_template
ActiveFedora::Noid.config.statefile = c.minter_statefile
end

CurationConcerns::CurationConcern.actor_factory = Sufia::ActorFactory
CurationConcerns.config.display_media_download_link = false
end

initializer 'sufia.assets.precompile' do |app|
Expand Down Expand Up @@ -80,40 +80,5 @@ class Engine < ::Rails::Engine
# nop, GenericWork hasn't been generated yet.
end
end

# Set some configuration defaults
config.persistent_hostpath = "http://localhost/files/"
config.enable_ffmpeg = false
config.ffmpeg_path = 'ffmpeg'
config.fits_message_length = 5
config.temp_file_base = nil
config.redis_namespace = "sufia"
config.fits_path = "fits.sh"
config.libreoffice_path = "soffice"
config.enable_contact_form_delivery = false
config.browse_everything = nil
config.analytics = false
config.citations = false
config.max_notifications_for_dashboard = 5
config.activity_to_show_default_seconds_since_now = 24 * 60 * 60
config.arkivo_api = false
config.geonames_username = ""
config.active_deposit_agreement_acceptance = true
config.batch_user_key = 'batchuser@example.com'
config.audit_user_key = 'audituser@example.com'
config.upload_path = ->() { Rails.root + 'tmp' + 'uploads' }

# Should a button with "Share my work" show on the front page to all users (even those not logged in)?
config.always_display_share_button = true

# Noid identifiers
config.enable_noids = true
config.noid_template = '.reeddeeddk'
config.minter_statefile = '/tmp/minter-state'
config.translate_uri_to_id = ActiveFedora::Noid.config.translate_uri_to_id
config.translate_id_to_uri = ActiveFedora::Noid.config.translate_id_to_uri

# Defaulting analytic start date to whenever the file was uploaded by leaving it blank
config.analytic_start_date = nil
end
end
Expand Up @@ -57,7 +57,7 @@

context "with passive deposit agreement" do
before do
allow(Sufia::Engine.config).to receive(:active_deposit_agreement_acceptance)
allow(Sufia.config).to receive(:active_deposit_agreement_acceptance)
.and_return(false)
end
it "shows accept text" do
Expand Down

0 comments on commit 9234795

Please sign in to comment.