Skip to content

Commit

Permalink
Merge branch 'main' into 187391225_Add_committees_info
Browse files Browse the repository at this point in the history
  • Loading branch information
warrenlet committed Apr 16, 2024
2 parents 81b174e + 773adb5 commit 5f5aa4d
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .codeclimate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ version: "2"
plugins:
rubocop:
enabled: true
channel: rubocop-1-48-1
channel: rubocop-1-56-3

2 changes: 1 addition & 1 deletion .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ Metrics/ModuleLength:
# Offense count: 25
# Configuration parameters: AllowedMethods, AllowedPatterns.
Metrics/PerceivedComplexity:
Max: 17
Max: 18

# Offense count: 13
Naming/AccessorMethodName:
Expand Down
30 changes: 21 additions & 9 deletions app/controllers/admin/commercials_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,22 +61,34 @@ def mass_upload

if !params[:file]
flash[:error] = 'Empty file detected while adding materials to Event'
elsif errors.all? { |_k, v| v.blank? }
flash[:notice] = 'Successfully added materials.'
else
errors_text = ''
errors_text += 'Unable to find event with ID: ' + errors[:no_event].join(', ') + '. ' if errors[:no_event].any?
if errors[:validation_errors].any?
errors_text += 'There were some errors: ' + errors[:validation_errors].join('. ')
end
elsif errors.present?
errors_text = aggregate_errors(errors)
flash[:notice] = if errors_text.length > 4096
'Errors are too long to be displayed. Please check the logs.'
else
errors_text
end

flash[:error] = errors_text
else
flash[:notice] = 'Successfully added materials.'
end
redirect_back(fallback_location: root_path)
end

private

# Aggregate errors and ensure that they do not exceed 4 KB in total size
def aggregate_errors(errors)
errors_text = ''
if errors[:no_event].any?
errors_text += 'Unable to find events with IDs: ' + errors[:no_event].join(', ') + '. '
end
if errors[:validation_errors].any?
errors_text += 'Validation errors: ' + errors[:validation_errors].join('. ')
end
errors_text
end

def commercial_params
params.require(:commercial).permit(:title, :url)
end
Expand Down
1 change: 0 additions & 1 deletion app/models/commercial.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#
require 'csv'


class Commercial < ApplicationRecord
require 'oembed'

Expand Down
4 changes: 2 additions & 2 deletions app/views/admin/events/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
for instance:
%pre
Event_ID,Title,URL
1,title,https://youtube.com/myvideo
2,title,https://vimeo.com/myvideo
1,Session Recording,https://youtube.com/myvideo
2,Demo Video,https://vimeo.com/myvideo
.modal-footer
= f.submit nil, class: 'btn btn-primary'
.row
Expand Down

0 comments on commit 5f5aa4d

Please sign in to comment.