Skip to content

Commit

Permalink
Add convenience method for checking cdl settings
Browse files Browse the repository at this point in the history
Co-authored-by: Chris Colvard <chris.colvard@gmail.com>
  • Loading branch information
masaball and cjcolvar committed Aug 10, 2022
1 parent d9b9b79 commit 9099434
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 15 deletions.
8 changes: 5 additions & 3 deletions app/controllers/admin/collections_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,10 @@ def update_access(collection, params)

collection.default_visibility = params[:visibility] unless params[:visibility].blank?
collection.default_hidden = params[:hidden] == "1"
lending_period = build_default_lending_period(collection)
collection.default_lending_period = lending_period if lending_period.positive?
if Avalon::Configuration.controlled_digital_lending_enabled?
lending_period = build_default_lending_period(collection)
collection.default_lending_period = lending_period if lending_period.positive?
end
end

def build_default_lending_period(collection)
Expand Down Expand Up @@ -330,7 +332,7 @@ def build_default_lending_period(collection)
collection.errors.add(:lending_period, "cannot be set to 0 days 0 hours.")
end

flash[:notice] = collection.errors.full_messages.join if collection.errors.present? && Settings.controlled_digital_lending.enable
flash[:notice] = collection.errors.full_messages.join if collection.errors.present?
lending_period.to_i
end

Expand Down
2 changes: 1 addition & 1 deletion app/jobs/bulk_action_jobs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def perform(collection_id, overwrite = true)
media_object = MediaObject.find(id)
media_object.hidden = collection.default_hidden
media_object.visibility = collection.default_visibility
if Settings.controlled_digital_lending.enable
if Avalon::Configuration.controlled_digital_lending_enabled?
media_object.lending_period = collection.default_lending_period
end

Expand Down
2 changes: 1 addition & 1 deletion app/models/access_control_step.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def execute context
unless limited_access_submit
media_object.visibility = context[:visibility] unless context[:visibility].blank?
media_object.hidden = context[:hidden] == "1"
if Settings.controlled_digital_lending.enable
if Avalon::Configuration.controlled_digital_lending_enabled?
lending_period = build_lending_period(context['add_lending_period_days'], context['add_lending_period_hours'])
if lending_period.positive?
media_object.lending_period = lending_period
Expand Down
2 changes: 1 addition & 1 deletion app/views/_user_util_links.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Unless required by applicable law or agreed to in writing, software distributed
<%= link_to 'Timelines', main_app.timelines_path, id:'timelines_nav', class: 'nav-link' %>
</li>
<% end %>
<% if Settings.controlled_digital_lending.enable %>
<% if Avalon::Configuration.controlled_digital_lending_enabled? %>
<% if current_ability.can? :create, Checkout %>
<li class="nav-item <%= active_for_controller('checkouts') %>">
<%= link_to main_app.checkouts_path, id:'checkouts_nav', class: 'nav-link' do %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/media_objects/_item_view.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Unless required by applicable law or agreed to in writing, software distributed
<% f_start, f_end = parse_media_fragment params['t'] %>
<div class="row">
<div class="col-sm-8" id="left_column">
<% if Settings.controlled_digital_lending.enable && !can_stream %>
<% if Avalon::Configuration.controlled_digital_lending_enabled? && !can_stream %>
<%= render 'embed_checkout' %>
<% elsif @currentStream %>
<%= render partial: "modules/player/section", locals: {section: @currentStream, section_info: @currentStreamInfo, f_start: @f_start, f_end: @f_end} %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/media_objects/_metadata_display.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ Unless required by applicable law or agreed to in writing, software distributed
</div>
<div class="card-body">
<%= @media_object.access_text %> <br />
<% if Settings.controlled_digital_lending.enable %>
<% if Avalon::Configuration.controlled_digital_lending_enabled? %>
Lending Period: <%= ActiveSupport::Duration.build(@media_object.lending_period).to_day_hour_s %>
<% end %>
</div>
Expand Down
4 changes: 2 additions & 2 deletions app/views/modules/_access_control.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ Unless required by applicable law or agreed to in writing, software distributed
</div>
</div>

<% if Settings.controlled_digital_lending.enable %>
<% if Avalon::Configuration.controlled_digital_lending_enabled? %>
<div class="card item-lending-period">
<div class="card-header">
<h3 class="card-title">Item lending period</h3>
Expand Down Expand Up @@ -132,7 +132,7 @@ Unless required by applicable law or agreed to in writing, software distributed
</div>
</div>

<% if Settings.controlled_digital_lending.enable %>
<% if Avalon::Configuration.controlled_digital_lending_enabled? %>
<div class="card item-access">
<div class="card-header">
<h3 class="card-title">Item lending period</h3>
Expand Down
4 changes: 3 additions & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,9 @@ en:
or ffaa:aaff:bbcc:ddee:1122:3344:5566:7777/ffff:ffff:ffff:ffff:ffff:ffff:ffff:ff00
Start and end dates are not required; if included, access for the specified IP Address(es) will start at the beginning of the start date and end at the beginning of the end date. Otherwise, access will be open ended for the specified IP Address(es).
lending_period: |
Lending Period is the length of time that an item may be checked out for. Day and Hour values must be positive integers.
Lending Period is the length of time that an item may be checked out for.
Lending Period must be greater than 0.
Day and Hour values must be positive integers.
contact:
title: 'Contact Us - %{application_name}'
Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
end
end

resources :checkouts, only: [:index, :create, :show, :update, :destroy], :constraints => lambda { |request| Settings.controlled_digital_lending.enable } do
resources :checkouts, only: [:index, :create, :show, :update, :destroy], :constraints => lambda { |request| Avalon::Configuration.controlled_digital_lending_enabled? } do
collection do
patch :return_all
end
Expand Down
11 changes: 8 additions & 3 deletions lib/avalon/configuration.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Copyright 2011-2022, The Trustees of Indiana University and Northwestern
# University. Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
#
#
# You may obtain a copy of the License at
#
#
# http://www.apache.org/licenses/LICENSE-2.0
#
#
# Unless required by applicable law or agreed to in writing, software distributed
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
# CONDITIONS OF ANY KIND, either express or implied. See the License for the
Expand Down Expand Up @@ -35,6 +35,11 @@ def sanitize_filename
end
end

# To be called as Avalon::Configuration.controlled_digital_lending_enabled?
def controlled_digital_lending_enabled?
!!Settings.controlled_digital_lending&.enable
end

private
class << self
def coerce(value, method)
Expand Down

0 comments on commit 9099434

Please sign in to comment.