Skip to content

Commit

Permalink
Fix rebase conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
masaball committed Aug 12, 2022
1 parent 10b4d05 commit f2ec65f
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
8 changes: 6 additions & 2 deletions app/controllers/admin/collections_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,11 @@ def update_access(collection, params)
collection.default_hidden = params[:hidden] == "1"
if Avalon::Configuration.controlled_digital_lending_enabled?
lending_period = build_default_lending_period(collection)
collection.default_lending_period = lending_period if lending_period.positive?
if lending_period.positive?
collection.default_lending_period = lending_period
elsif lending_period.zero?
flash[:error] = "Lending period must be greater than 0."
end
end
end

Expand All @@ -312,7 +316,7 @@ def build_default_lending_period(collection)
d.negative? ? collection.errors.add(:lending_period, "days needs to be a positive integer.") : lending_period += d.days
h.negative? ? collection.errors.add(:lending_period, "hours needs to be a positive integer.") : lending_period += h.hours

flash[:error] = collection.errors.full_messages.join if collection.errors.present?
flash[:error] = collection.errors.full_messages.join(' ') if collection.errors.present?
lending_period.to_i
rescue
0
Expand Down
8 changes: 4 additions & 4 deletions app/models/access_control_step.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,11 @@ def execute context
media_object.visibility = context[:visibility] unless context[:visibility].blank?
media_object.hidden = context[:hidden] == "1"
if Avalon::Configuration.controlled_digital_lending_enabled?
lending_period = build_lending_period(context['add_lending_period_days'], context['add_lending_period_hours'])
lending_period = build_lending_period(context)
if lending_period.positive?
media_object.lending_period = lending_period
else
context[:error] = "Lending period days and hours need to be positive integers."
elsif lending_period.zero?
context[:error] = "Lending period must be greater than 0."
end
end
end
Expand Down Expand Up @@ -136,7 +136,7 @@ def build_lending_period(context)
d.negative? ? errors.append("Lending period days needs to be a positive integer.") : lending_period += d.days
h.negative? ? errors.append("Lending period hours needs to be a positive integer.") : lending_period += h.hours

context[:error] = errors.join if errors.present?
context[:error] = errors.join(' ') if errors.present?
lending_period.to_i
rescue
0
Expand Down
1 change: 0 additions & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ en:
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.
Lending Period must be greater than 0.
Day and Hour values must be positive integers.
contact:
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/admin_collections_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@
it "returns error if both day and hour are 0" do
expect { put 'update', params: { id: collection.id, save_access: "Save Access Settings", add_lending_period_days: 0, add_lending_period_hours: 0 } }.not_to change { collection.reload.default_lending_period }
expect(response).to redirect_to(admin_collection_path(collection))
expect(flash[:notice]).to be_present
expect(flash[:error]).to be_present
end
end
end
Expand Down

0 comments on commit f2ec65f

Please sign in to comment.