From f90435eb329462007b74fb219a9fa09475ed890e Mon Sep 17 00:00:00 2001 From: Warren Huang <62491485+warrenlet@users.noreply.github.com> Date: Fri, 23 Feb 2024 11:57:28 -0800 Subject: [PATCH 01/14] Update .codeclimate.yml --- .codeclimate.yml | 2 +- ...ion_instructions_to_submission_template.rb | 5 +++ spec/models/currency_conversion_spec.rb | 37 +++++++++++++++++++ 3 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20240226175634_rename_submission_instructions_to_submission_template.rb create mode 100644 spec/models/currency_conversion_spec.rb diff --git a/.codeclimate.yml b/.codeclimate.yml index c9e9a0539..fde9f3784 100644 --- a/.codeclimate.yml +++ b/.codeclimate.yml @@ -1,4 +1,4 @@ plugins: rubocop: enabled: true - channel: rubocop-1-56-3 + channel: rubocop-1-48-1 diff --git a/db/migrate/20240226175634_rename_submission_instructions_to_submission_template.rb b/db/migrate/20240226175634_rename_submission_instructions_to_submission_template.rb new file mode 100644 index 000000000..e6c70a134 --- /dev/null +++ b/db/migrate/20240226175634_rename_submission_instructions_to_submission_template.rb @@ -0,0 +1,5 @@ +class RenameSubmissionInstructionsToSubmissionTemplate < ActiveRecord::Migration[7.0] + def change + rename_column :event_types, :submission_instructions, :submission_template + end +end diff --git a/spec/models/currency_conversion_spec.rb b/spec/models/currency_conversion_spec.rb new file mode 100644 index 000000000..0e012594e --- /dev/null +++ b/spec/models/currency_conversion_spec.rb @@ -0,0 +1,37 @@ +# frozen_string_literal: true + +# == Schema Information +# +# Table name: currency_conversions +# +# id :bigint not null, primary key +# from_currency :string +# rate :decimal(, ) +# to_currency :string +# created_at :datetime not null +# updated_at :datetime not null +# conference_id :bigint not null +# +# Indexes +# +# index_currency_conversions_on_conference_id (conference_id) +# +# Foreign Keys +# +# fk_rails_... (conference_id => conferences.id) +# +require 'spec_helper' + +describe CurrencyConversion do + let!(:conference) { create(:conference, title: 'ExampleCon') } + + describe 'validations' do + before do + conference.currency_conversions << create(:currency_conversion) + end + + it { is_expected.to validate_numericality_of(:rate).is_greater_than(0) } + + it { is_expected.to validate_uniqueness_of(:from_currency).scoped_to(:to_currency).on(:create) } + end +end From 4a4df63e0413aa1a42a2241c7272ee2e361de5e1 Mon Sep 17 00:00:00 2001 From: Warren Huang Date: Mon, 18 Mar 2024 17:57:50 -0700 Subject: [PATCH 02/14] Add upload csv schedule button --- app/views/admin/schedules/show.html.haml | 27 ++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/app/views/admin/schedules/show.html.haml b/app/views/admin/schedules/show.html.haml index 5777f4836..8340ecab9 100644 --- a/app/views/admin/schedules/show.html.haml +++ b/app/views/admin/schedules/show.html.haml @@ -4,10 +4,37 @@ .col-md-12 .page-header %h1= "#{@conference.title} Schedule" + + .btn-group.pull-right + %button.btn.btn-primary{ title: 'Mass import of schedule for events', + data: { toggle: 'modal', target: '#mass-schedule-modal' } } + Upload with CSV file + %p.text-muted Create the schedules for the conference = render 'schedules/event_types_key', event_types: @event_types, favourites: false +.modal#mass-schedule-modal + .modal-dialog + .modal-content + .modal-header + %h1 + Schedule events + .modal-body + = form_for('', url: mass_upload_schedules_admin_conference_program_path(@conference.short_title), method: :post) do |f| + .form-group + = f.file_field 'file', as: :file + %span.help-block + Upload your file.csv with data in the following format: + %b Event_ID, xx:xx - xx:xx, Room + for instance: + %pre + Event_ID, xx:xx - xx:xx, Room + 1, 10:00 - 11:00, Room 1 + 2, 11:00 - 12:00, Room 2 + .modal-footer + = f.submit nil, class: 'btn btn-primary' + - if @rooms.present? .row .col-md-2 From 2022ffb0abce0904557feac2507525b243774022 Mon Sep 17 00:00:00 2001 From: Warren Huang Date: Wed, 27 Mar 2024 17:27:33 -0700 Subject: [PATCH 03/14] Add comment code to enable button funcionality --- app/views/admin/schedules/show.html.haml | 40 ++++++++++++------------ 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/app/views/admin/schedules/show.html.haml b/app/views/admin/schedules/show.html.haml index 8340ecab9..7a66856fa 100644 --- a/app/views/admin/schedules/show.html.haml +++ b/app/views/admin/schedules/show.html.haml @@ -14,26 +14,26 @@ Create the schedules for the conference = render 'schedules/event_types_key', event_types: @event_types, favourites: false -.modal#mass-schedule-modal - .modal-dialog - .modal-content - .modal-header - %h1 - Schedule events - .modal-body - = form_for('', url: mass_upload_schedules_admin_conference_program_path(@conference.short_title), method: :post) do |f| - .form-group - = f.file_field 'file', as: :file - %span.help-block - Upload your file.csv with data in the following format: - %b Event_ID, xx:xx - xx:xx, Room - for instance: - %pre - Event_ID, xx:xx - xx:xx, Room - 1, 10:00 - 11:00, Room 1 - 2, 11:00 - 12:00, Room 2 - .modal-footer - = f.submit nil, class: 'btn btn-primary' +-# .modal#mass-schedule-modal +-# .modal-dialog +-# .modal-content +-# .modal-header +-# %h1 +-# Schedule events +-# .modal-body +-# = form_for('', url: mass_upload_schedules_admin_conference_program_path(@conference.short_title), method: :post) do |f| +-# .form-group +-# = f.file_field 'file', as: :file +-# %span.help-block +-# Upload your file.csv with data in the following format: +-# %b Event_ID, xx:xx - xx:xx, Room +-# for instance: +-# %pre +-# Event_ID, xx:xx - xx:xx, Room +-# 1, 10:00 - 11:00, Room 1 +-# 2, 11:00 - 12:00, Room 2 +-# .modal-footer +-# = f.submit nil, class: 'btn btn-primary' - if @rooms.present? .row From 6a89df678ce25310bc02a29339472d412709536b Mon Sep 17 00:00:00 2001 From: Owen Yang Date: Mon, 22 Apr 2024 01:22:32 -0700 Subject: [PATCH 04/14] Upload CSV Added --- app/controllers/admin/schedules_controller.rb | 32 +++++++++++++++ app/views/admin/schedules/show.html.haml | 40 +++++++++---------- config/routes.rb | 5 +++ ...20240308190204_add_currency_to_payments.rb | 5 --- ...025823_add_currency_to_ticket_purchases.rb | 5 --- package-lock.json | 2 +- 6 files changed, 58 insertions(+), 31 deletions(-) delete mode 100644 db/migrate/20240308190204_add_currency_to_payments.rb delete mode 100644 db/migrate/20240315025823_add_currency_to_ticket_purchases.rb diff --git a/app/controllers/admin/schedules_controller.rb b/app/controllers/admin/schedules_controller.rb index f3176245c..df7b7b884 100644 --- a/app/controllers/admin/schedules_controller.rb +++ b/app/controllers/admin/schedules_controller.rb @@ -68,6 +68,38 @@ def destroy end end + def upload_csv + Rails.logger.debug "Entered the upload_csv method" + @conference = Conference.find_by!(short_title: params[:conference_id]) + authorize! :update, @conference + + # Check if the file was included in the params + if params[:schedule] && params[:schedule][:file].present? + file = params[:schedule][:file] + begin + CSV.foreach(file.path, headers: true) do |row| + event_date = Date.strptime(row['Date'], '%m/%d/%y') + event_time = Time.parse(row['Start_Time']) + event_start_time = DateTime.new(event_date.year, event_date.month, event_date.day, event_time.hour, event_time.min, event_time.sec, event_time.zone) + + room = Room.find_or_create_by(name: row['Room']) + event = Event.find_by(id: row['Event_ID']) + + if event + event.update(start_time: event_start_time, room: room) + end + end + flash[:notice] = 'Schedule uploaded successfully!' + rescue => e + flash[:alert] = "Failed to process CSV file: #{e.message}" + end + else + flash[:alert] = 'No file was attached!' + end + redirect_to admin_conference_schedules_path(@conference) + end + + private def schedule_params diff --git a/app/views/admin/schedules/show.html.haml b/app/views/admin/schedules/show.html.haml index 7a66856fa..3e3a8e837 100644 --- a/app/views/admin/schedules/show.html.haml +++ b/app/views/admin/schedules/show.html.haml @@ -14,26 +14,26 @@ Create the schedules for the conference = render 'schedules/event_types_key', event_types: @event_types, favourites: false --# .modal#mass-schedule-modal --# .modal-dialog --# .modal-content --# .modal-header --# %h1 --# Schedule events --# .modal-body --# = form_for('', url: mass_upload_schedules_admin_conference_program_path(@conference.short_title), method: :post) do |f| --# .form-group --# = f.file_field 'file', as: :file --# %span.help-block --# Upload your file.csv with data in the following format: --# %b Event_ID, xx:xx - xx:xx, Room --# for instance: --# %pre --# Event_ID, xx:xx - xx:xx, Room --# 1, 10:00 - 11:00, Room 1 --# 2, 11:00 - 12:00, Room 2 --# .modal-footer --# = f.submit nil, class: 'btn btn-primary' +.modal#mass-schedule-modal + .modal-dialog + .modal-content + .modal-header + %h1 + Schedule events + .modal-body + = form_for :schedule, url: upload_csv_admin_conference_schedules_path(@conference), html: { multipart: true }, method: :post do |f| + .form-group + = f.file_field :file, as: :file + %span.help-block + Upload your CSV file with data in the following format: + %b Event_ID, Start_Time, Date, Room + for instance: + %pre + Event_ID, Start_Time, Date, Room + 1, 10:00, 6/1/2024, Australia + 2, 11:00, 6/2/2024, Brazil + .modal-footer + = f.submit 'Upload', class: 'btn btn-primary' - if @rooms.present? .row diff --git a/config/routes.rb b/config/routes.rb index 6e49e0666..62ac3dfdd 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -40,6 +40,11 @@ resource :ticket_scanning, only: [:create] resources :comments, only: [:index] resources :conferences do + resources :schedules do + collection do + post :upload_csv + end + end resources :surveys do resources :survey_questions, except: :index end diff --git a/db/migrate/20240308190204_add_currency_to_payments.rb b/db/migrate/20240308190204_add_currency_to_payments.rb deleted file mode 100644 index 467a04f43..000000000 --- a/db/migrate/20240308190204_add_currency_to_payments.rb +++ /dev/null @@ -1,5 +0,0 @@ -class AddCurrencyToPayments < ActiveRecord::Migration[7.0] - def change - add_column :payments, :currency, :string - end -end diff --git a/db/migrate/20240315025823_add_currency_to_ticket_purchases.rb b/db/migrate/20240315025823_add_currency_to_ticket_purchases.rb deleted file mode 100644 index 70e4f9d96..000000000 --- a/db/migrate/20240315025823_add_currency_to_ticket_purchases.rb +++ /dev/null @@ -1,5 +0,0 @@ -class AddCurrencyToTicketPurchases < ActiveRecord::Migration[7.0] - def change - add_column :ticket_purchases, :currency, :string - end -end diff --git a/package-lock.json b/package-lock.json index e5e7a779a..fedc26385 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,5 +1,5 @@ { - "name": "snapcon", + "name": "snapcon2", "lockfileVersion": 2, "requires": true, "packages": { From 4389a319fe31e2ccc6c896261880f752b2348780 Mon Sep 17 00:00:00 2001 From: Owen Yang Date: Mon, 22 Apr 2024 17:02:55 -0700 Subject: [PATCH 05/14] add upload CSV function --- app/controllers/admin/schedules_controller.rb | 23 +++++++++++-------- app/views/admin/schedules/show.html.haml | 4 ++-- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/app/controllers/admin/schedules_controller.rb b/app/controllers/admin/schedules_controller.rb index df7b7b884..c7cbf911f 100644 --- a/app/controllers/admin/schedules_controller.rb +++ b/app/controllers/admin/schedules_controller.rb @@ -69,35 +69,38 @@ def destroy end def upload_csv - Rails.logger.debug "Entered the upload_csv method" @conference = Conference.find_by!(short_title: params[:conference_id]) authorize! :update, @conference - - # Check if the file was included in the params + if params[:schedule] && params[:schedule][:file].present? file = params[:schedule][:file] - begin - CSV.foreach(file.path, headers: true) do |row| + CSV.foreach(file.path, headers: true) do |row| + next if row['Event_ID'].blank? || row['Date'].blank? || row['Start_Time'].blank? || row['Room'].blank? + + begin event_date = Date.strptime(row['Date'], '%m/%d/%y') event_time = Time.parse(row['Start_Time']) event_start_time = DateTime.new(event_date.year, event_date.month, event_date.day, event_time.hour, event_time.min, event_time.sec, event_time.zone) - room = Room.find_or_create_by(name: row['Room']) event = Event.find_by(id: row['Event_ID']) - + if event event.update(start_time: event_start_time, room: room) + else + Rails.logger.warn "Event not found with ID: #{row['Event_ID']}" end + rescue => e + Rails.logger.error "Error processing row: #{row.to_h}, Error: #{e.message}" + next end - flash[:notice] = 'Schedule uploaded successfully!' - rescue => e - flash[:alert] = "Failed to process CSV file: #{e.message}" end + flash[:notice] = 'Schedule uploaded successfully!' else flash[:alert] = 'No file was attached!' end redirect_to admin_conference_schedules_path(@conference) end + private diff --git a/app/views/admin/schedules/show.html.haml b/app/views/admin/schedules/show.html.haml index 3e3a8e837..0b1d0f56a 100644 --- a/app/views/admin/schedules/show.html.haml +++ b/app/views/admin/schedules/show.html.haml @@ -30,8 +30,8 @@ for instance: %pre Event_ID, Start_Time, Date, Room - 1, 10:00, 6/1/2024, Australia - 2, 11:00, 6/2/2024, Brazil + osemdemo, 10:00, 6/1/2024, Australia + osemdemo, 11:00, 6/2/2024, Brazil .modal-footer = f.submit 'Upload', class: 'btn btn-primary' From 0e228b8eb999ac08e2d3167cc489c999d849e8cb Mon Sep 17 00:00:00 2001 From: Owen Yang Date: Sat, 27 Apr 2024 21:39:35 -0700 Subject: [PATCH 06/14] Fix RuboCop offenses in schedules controller --- app/controllers/admin/schedules_controller.rb | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/app/controllers/admin/schedules_controller.rb b/app/controllers/admin/schedules_controller.rb index c7cbf911f..b0194b1fa 100644 --- a/app/controllers/admin/schedules_controller.rb +++ b/app/controllers/admin/schedules_controller.rb @@ -89,7 +89,7 @@ def upload_csv else Rails.logger.warn "Event not found with ID: #{row['Event_ID']}" end - rescue => e + rescue StandardError => e Rails.logger.error "Error processing row: #{row.to_h}, Error: #{e.message}" next end @@ -101,10 +101,7 @@ def upload_csv redirect_to admin_conference_schedules_path(@conference) end - - private - def schedule_params params.require(:schedule).permit(:track_id) if params[:schedule] end From 645f95aa2510701ac2e22a7dfc518a22c1783638 Mon Sep 17 00:00:00 2001 From: Owen Yang Date: Sat, 27 Apr 2024 21:58:28 -0700 Subject: [PATCH 07/14] Fix RuboCop offenses in schedules controller2 --- app/controllers/admin/schedules_controller.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/admin/schedules_controller.rb b/app/controllers/admin/schedules_controller.rb index b0194b1fa..066e1128f 100644 --- a/app/controllers/admin/schedules_controller.rb +++ b/app/controllers/admin/schedules_controller.rb @@ -102,6 +102,7 @@ def upload_csv end private + def schedule_params params.require(:schedule).permit(:track_id) if params[:schedule] end From 384218407bcea9cb782964afd940106bac8fc048 Mon Sep 17 00:00:00 2001 From: Owen Yang Date: Sat, 27 Apr 2024 22:56:34 -0700 Subject: [PATCH 08/14] Fix RuboCop offenses in schedules controller3 --- app/controllers/admin/schedules_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/admin/schedules_controller.rb b/app/controllers/admin/schedules_controller.rb index 066e1128f..141ace908 100644 --- a/app/controllers/admin/schedules_controller.rb +++ b/app/controllers/admin/schedules_controller.rb @@ -102,7 +102,7 @@ def upload_csv end private - + def schedule_params params.require(:schedule).permit(:track_id) if params[:schedule] end From 6ba98dd874523c4f141b2e206f3eeeda1b72c0b8 Mon Sep 17 00:00:00 2001 From: Owen Yang Date: Sat, 27 Apr 2024 23:35:40 -0700 Subject: [PATCH 09/14] Refactored for add event by csv --- app/controllers/admin/schedules_controller.rb | 71 ++++++++++++------- db/schema.rb | 1 - 2 files changed, 47 insertions(+), 25 deletions(-) diff --git a/app/controllers/admin/schedules_controller.rb b/app/controllers/admin/schedules_controller.rb index 141ace908..fa9156837 100644 --- a/app/controllers/admin/schedules_controller.rb +++ b/app/controllers/admin/schedules_controller.rb @@ -4,6 +4,7 @@ module Admin class SchedulesController < Admin::BaseController # By authorizing 'conference' resource, we can ensure there will be no unauthorized access to # the schedule of a conference, which should not be accessed in the first place + before_action :set_conference load_and_authorize_resource :conference, find_by: :short_title load_and_authorize_resource :program, through: :conference, singleton: true load_and_authorize_resource :schedule, through: :program, except: %i[new create] @@ -69,40 +70,62 @@ def destroy end def upload_csv - @conference = Conference.find_by!(short_title: params[:conference_id]) authorize! :update, @conference + return flash[:alert] = 'No file was attached!' unless file_present? - if params[:schedule] && params[:schedule][:file].present? - file = params[:schedule][:file] - CSV.foreach(file.path, headers: true) do |row| - next if row['Event_ID'].blank? || row['Date'].blank? || row['Start_Time'].blank? || row['Room'].blank? - - begin - event_date = Date.strptime(row['Date'], '%m/%d/%y') - event_time = Time.parse(row['Start_Time']) - event_start_time = DateTime.new(event_date.year, event_date.month, event_date.day, event_time.hour, event_time.min, event_time.sec, event_time.zone) - room = Room.find_or_create_by(name: row['Room']) - event = Event.find_by(id: row['Event_ID']) - - if event - event.update(start_time: event_start_time, room: room) - else - Rails.logger.warn "Event not found with ID: #{row['Event_ID']}" - end - rescue StandardError => e - Rails.logger.error "Error processing row: #{row.to_h}, Error: #{e.message}" - next - end - end + if process_csv flash[:notice] = 'Schedule uploaded successfully!' else - flash[:alert] = 'No file was attached!' + flash[:alert] = "Failed to process CSV file." end + redirect_to admin_conference_schedules_path(@conference) end private + def set_conference + @conference = Conference.find_by!(short_title: params[:conference_id]) + end + + def file_present? + params[:schedule] && params[:schedule][:file].present? + end + + def process_csv + file = params[:schedule][:file] + CSV.foreach(file.path, headers: true) do |row| + process_row(row) + end + true + rescue => e + Rails.logger.error "CSV Processing Error: #{e.message}" + false + end + + def process_row(row) + event_date = parse_date(row['Date']) + event_time = parse_time(row['Start_Time']) + event_start_time = combine_datetime(event_date, event_time) + + room = Room.find_or_create_by(name: row['Room']) + event = Event.find_by(id: row['Event_ID']) + + event.update(start_time: event_start_time, room: room) if event + end + + def parse_date(date_str) + Date.strptime(date_str, '%m/%d/%y') + end + + def parse_time(time_str) + Time.parse(time_str) + end + + def combine_datetime(date, time) + DateTime.new(date.year, date.month, date.day, time.hour, time.min, time.sec, time.zone) + end + def schedule_params params.require(:schedule).permit(:track_id) if params[:schedule] end diff --git a/db/schema.rb b/db/schema.rb index 01fbae77e..c31c972f9 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -625,7 +625,6 @@ t.boolean "is_disabled", default: false t.string "picture" t.string "timezone" - t.string "default_currency" t.index ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true t.index ["email"], name: "index_users_on_email", unique: true t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true From c847c3a04329a83317820a421d63f18312bf55d4 Mon Sep 17 00:00:00 2001 From: Owen Yang Date: Sat, 27 Apr 2024 23:41:41 -0700 Subject: [PATCH 10/14] Fix RuboCop offenses in schedules controller --- app/controllers/admin/schedules_controller.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/admin/schedules_controller.rb b/app/controllers/admin/schedules_controller.rb index fa9156837..6e716caaf 100644 --- a/app/controllers/admin/schedules_controller.rb +++ b/app/controllers/admin/schedules_controller.rb @@ -76,7 +76,7 @@ def upload_csv if process_csv flash[:notice] = 'Schedule uploaded successfully!' else - flash[:alert] = "Failed to process CSV file." + flash[:alert] = 'Failed to process CSV file.' end redirect_to admin_conference_schedules_path(@conference) @@ -98,7 +98,7 @@ def process_csv process_row(row) end true - rescue => e + rescue StandardError => e Rails.logger.error "CSV Processing Error: #{e.message}" false end @@ -111,7 +111,7 @@ def process_row(row) room = Room.find_or_create_by(name: row['Room']) event = Event.find_by(id: row['Event_ID']) - event.update(start_time: event_start_time, room: room) if event + event&.update(start_time: event_start_time, room: room) end def parse_date(date_str) From cf52a84a62ff0d7ee94b1b06580440b7067c49db Mon Sep 17 00:00:00 2001 From: Owen Yang Date: Sun, 28 Apr 2024 03:07:56 -0700 Subject: [PATCH 11/14] Fix code style issues --- app/assets/javascripts/osem-schedule.js | 2 +- app/models/commercial.rb | 62 ++++++++++++++++--------- spec/features/event_schedules_spec.rb | 2 +- 3 files changed, 41 insertions(+), 25 deletions(-) diff --git a/app/assets/javascripts/osem-schedule.js b/app/assets/javascripts/osem-schedule.js index 61e6894bb..c233c877d 100644 --- a/app/assets/javascripts/osem-schedule.js +++ b/app/assets/javascripts/osem-schedule.js @@ -84,7 +84,7 @@ $(document).ready( function() { var now = new Date(); var closestEventId = null; var smallestDiff = Infinity; - var i=0 + var i = 0; $('.event-item').each(function() { diff --git a/app/models/commercial.rb b/app/models/commercial.rb index 42d4ccadf..5ec8f6e98 100644 --- a/app/models/commercial.rb +++ b/app/models/commercial.rb @@ -40,34 +40,50 @@ def self.render_from_url(url) end end + # Extracted method to parse the URI and handle errors + def self.parse_uri(url) + URI.parse(url) + rescue URI::InvalidURIError + nil + end + + # New method to determine if the URL is a Snap! project + def self.snap_berkeley_project?(uri) + uri.host == 'snap.berkeley.edu' && uri.path == '/project' + end + + # Extracted method to parse query parameters + def self.parse_query(uri) + URI.decode_www_form(uri.query).to_h + end + + # New method to build the embed URL + def self.build_embed_url(uri, args) + new_query = URI.encode_www_form({ + 'projectname' => args['projectname'], + 'username' => args['username'], + 'showTitle' => 'true', + 'showAuthor' => 'true', + 'editButton' => 'true', + 'pauseButton' => 'true' + }) + URI::HTTPS.build(host: uri.host, path: '/embed', query: new_query).to_s + end + + # Updated generate_snap_embed to use extracted methods def self.generate_snap_embed(url) return url unless url - uri = URI.parse(url) - if uri.host == 'snap.berkeley.edu' && uri.path == '/project' - args = URI.decode_www_form(uri.query).to_h - else - return url - end - if args.key?('username') && args.key?('projectname') - new_query = URI.encode_www_form({ - 'projectname' => args['projectname'], - 'username' => args['username'], - 'showTitle' => 'true', - 'showAuthor' => 'true', - 'editButton' => 'true', - 'pauseButton' => 'true' - }) - new_uri = URI::HTTPS.build( - host: uri.host, - path: '/embed', - query: new_query - ) - return new_uri.to_s - end - url + uri = parse_uri(url) + return url unless uri && snap_berkeley_project?(uri) + + args = parse_query(uri) + return url unless args.key?('username') && args.key?('projectname') + + build_embed_url(uri, args) end + def self.iframe_fallback(url) "".html_safe end diff --git a/spec/features/event_schedules_spec.rb b/spec/features/event_schedules_spec.rb index a166a247f..cc01677a5 100644 --- a/spec/features/event_schedules_spec.rb +++ b/spec/features/event_schedules_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe EventSchedule, js: true do +describe EventSchedule, :js do Timecop.return let(:test_date) { Time.current } let!(:conference) do From b7999bcc18be167585202d452c20033b545e2229 Mon Sep 17 00:00:00 2001 From: Owen Yang Date: Sun, 28 Apr 2024 03:09:18 -0700 Subject: [PATCH 12/14] Fix code style issues --- app/models/commercial.rb | 62 +++++++++++++++------------------------- 1 file changed, 23 insertions(+), 39 deletions(-) diff --git a/app/models/commercial.rb b/app/models/commercial.rb index 5ec8f6e98..42d4ccadf 100644 --- a/app/models/commercial.rb +++ b/app/models/commercial.rb @@ -40,50 +40,34 @@ def self.render_from_url(url) end end - # Extracted method to parse the URI and handle errors - def self.parse_uri(url) - URI.parse(url) - rescue URI::InvalidURIError - nil - end - - # New method to determine if the URL is a Snap! project - def self.snap_berkeley_project?(uri) - uri.host == 'snap.berkeley.edu' && uri.path == '/project' - end - - # Extracted method to parse query parameters - def self.parse_query(uri) - URI.decode_www_form(uri.query).to_h - end - - # New method to build the embed URL - def self.build_embed_url(uri, args) - new_query = URI.encode_www_form({ - 'projectname' => args['projectname'], - 'username' => args['username'], - 'showTitle' => 'true', - 'showAuthor' => 'true', - 'editButton' => 'true', - 'pauseButton' => 'true' - }) - URI::HTTPS.build(host: uri.host, path: '/embed', query: new_query).to_s - end - - # Updated generate_snap_embed to use extracted methods def self.generate_snap_embed(url) return url unless url - uri = parse_uri(url) - return url unless uri && snap_berkeley_project?(uri) - - args = parse_query(uri) - return url unless args.key?('username') && args.key?('projectname') - - build_embed_url(uri, args) + uri = URI.parse(url) + if uri.host == 'snap.berkeley.edu' && uri.path == '/project' + args = URI.decode_www_form(uri.query).to_h + else + return url + end + if args.key?('username') && args.key?('projectname') + new_query = URI.encode_www_form({ + 'projectname' => args['projectname'], + 'username' => args['username'], + 'showTitle' => 'true', + 'showAuthor' => 'true', + 'editButton' => 'true', + 'pauseButton' => 'true' + }) + new_uri = URI::HTTPS.build( + host: uri.host, + path: '/embed', + query: new_query + ) + return new_uri.to_s + end + url end - def self.iframe_fallback(url) "".html_safe end From 92fa56039edb3e7270c8236a7c41221bf3334de4 Mon Sep 17 00:00:00 2001 From: Michael Ball Date: Sat, 20 Jul 2024 14:10:42 -0700 Subject: [PATCH 13/14] fix commericals function call --- app/models/commercial.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/commercial.rb b/app/models/commercial.rb index 417e91057..df448b701 100644 --- a/app/models/commercial.rb +++ b/app/models/commercial.rb @@ -30,7 +30,7 @@ class Commercial < ApplicationRecord def self.render_from_url(url) register_provider - url = generate_snap_embed(url) + url = Commercial.generate_snap_embed(url) begin resource = OEmbed::Providers.get(url, maxwidth: 560, maxheight: 315) { html: resource.html.html_safe } From 021a24b1ac751be7c2d06c29dbee7626e1aec5ca Mon Sep 17 00:00:00 2001 From: Michael Ball Date: Sat, 20 Jul 2024 15:22:30 -0700 Subject: [PATCH 14/14] Fixup events admin table --- app/views/admin/events/index.html.haml | 1 + db/schema.rb | 2 -- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/app/views/admin/events/index.html.haml b/app/views/admin/events/index.html.haml index 6f68faee1..2d1ac6372 100644 --- a/app/views/admin/events/index.html.haml +++ b/app/views/admin/events/index.html.haml @@ -66,6 +66,7 @@ %th Rating %th Submitter %th Speakers + %th Volunteers - if @program.languages.present? %th Language %th Requires Registration diff --git a/db/schema.rb b/db/schema.rb index c31c972f9..eae662993 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -330,7 +330,6 @@ t.integer "conference_id", null: false t.datetime "created_at", precision: nil, null: false t.datetime "updated_at", precision: nil, null: false - t.string "currency" end create_table "physical_tickets", force: :cascade do |t| @@ -545,7 +544,6 @@ t.integer "payment_id" t.integer "week" t.float "amount_paid", default: 0.0 - t.string "currency" end create_table "ticket_scannings", force: :cascade do |t|