From ab263ca96e02e3444c93459f67ddcc8b5b304f56 Mon Sep 17 00:00:00 2001 From: Michael Ball Date: Sun, 23 Jul 2023 00:28:10 +0200 Subject: [PATCH 01/17] Automatically use embeddable URL for media items --- app/models/commercial.rb | 11 ++++++++- lib/embeddable_url.rb | 42 +++++++++++++++++++++++++++++++++ spec/lib/embeddable_url_spec.rb | 17 +++++++++++++ 3 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 lib/embeddable_url.rb create mode 100644 spec/lib/embeddable_url_spec.rb diff --git a/app/models/commercial.rb b/app/models/commercial.rb index d5ac9a463..a08a890e6 100644 --- a/app/models/commercial.rb +++ b/app/models/commercial.rb @@ -38,14 +38,17 @@ def self.render_from_url(url) end def self.iframe_fallback(url) - "".html_safe + url = EmbeddableURL.new(url).iframe_url + "".html_safe end def self.read_file(file) + require 'csv' errors = {} errors[:no_event] = [] errors[:validation_errors] = [] + file. file.read.each_line do |line| # Get the event id (text before :) id = line.match(/:/).pre_match.to_i @@ -66,6 +69,12 @@ def self.read_file(file) private + def optional_params + return '' unless self.url.match(%r{snap.berkeley}) + + 'allow="geolocation;microphone;camera"' + end + def valid_url result = Commercial.render_from_url(url) errors.add(:base, result[:error]) if result[:error] diff --git a/lib/embeddable_url.rb b/lib/embeddable_url.rb new file mode 100644 index 000000000..0a4872bc5 --- /dev/null +++ b/lib/embeddable_url.rb @@ -0,0 +1,42 @@ +# Transform a URL to a version that allows iframes + +class EmbeddableURL + attr_accessor :url + + TRANSFORMATIONS = { + /snap\.berkeley\.edu/ => snap, + /docs\.google\.com/ => google_docs, + /dropbox\.com/ => dropbox + }.freeze + + def iframe_url + TRANSFORMATIONS.each do |regex, fn| + return fn.call(url) if url.match?(regex) + end + url + end + + private + + def google_docs(url) + # replace /edit, /share ,/comment with /embed and remove the querystring + url.gsub(%r{(/edit|/share|/comment).*}, '/embed') + end + + def dropbox(url) + uri = URI.parse(url) + query = CGI.parse(uri.query) + query.delete('dl') + query['raw'] = '1' + uri.query = query.to_query + uri.to_s + end + + def snap(url) + uri = URI.parse(url) + query = CGI.parse(uri.query) + username = query['username'][0] || query['user'][0] + project = query['projectname'][0] || query['project'][0] + "https://snap.berkeley.edu/embed?projectname=#{project}&username=#{username}&showTitle=true&showAuthor=true&editButton=true&pauseButton=true" + end +end diff --git a/spec/lib/embeddable_url_spec.rb b/spec/lib/embeddable_url_spec.rb new file mode 100644 index 000000000..3282d2dc6 --- /dev/null +++ b/spec/lib/embeddable_url_spec.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe EmbeddableURL do + describe '#iframe_url' do + it 'returns the original url if no transformations apply' do + url = 'https://example.com' + expect(EmbeddableURL.new(url).iframe_url).to eq url + end + + it 'returns the transformed url if a transformation applies' do + url = 'https://docs.google.com' + expect(EmbeddableURL.new(url).iframe_url).to include '/embed' + end + end +end From 28e751bd3cc108cf17bd40f5f2e695387cb61e32 Mon Sep 17 00:00:00 2001 From: Michael Ball Date: Mon, 24 Jul 2023 18:41:49 -0700 Subject: [PATCH 02/17] WIP Cleanup registrations datatable to show price+attendance --- app/datatables/registration_datatable.rb | 20 ++++++++++++++-- app/views/admin/registrations/index.html.haml | 23 ++++++++++++++----- 2 files changed, 35 insertions(+), 8 deletions(-) diff --git a/app/datatables/registration_datatable.rb b/app/datatables/registration_datatable.rb index 1639ef422..7a6305ae2 100644 --- a/app/datatables/registration_datatable.rb +++ b/app/datatables/registration_datatable.rb @@ -5,6 +5,9 @@ class RegistrationDatatable < AjaxDatatablesRails::ActiveRecord def_delegator :@view, :dom_id def_delegator :@view, :edit_admin_conference_registration_path + # def_delegator :@view, :delete_admin_conference_registration_path + def_delegator :@view, :admin_conference_registration_toggle_attendance_path + def initialize(params, opts = {}) @view = opts[:view_context] @@ -17,6 +20,8 @@ def view_columns name: { source: 'User.name' }, email: { source: 'User.email' }, accepted_code_of_conduct: { source: 'Registration.accepted_code_of_conduct', searchable: false }, + attended: { source: 'Registration.attended', searchable: false }, + ticket_price: { source: 'TicketPurchase.amount_paid' }, ticket_type: { source: 'Ticket.title' }, actions: { source: 'Registration.id', searchable: false, orderable: false } } @@ -34,6 +39,14 @@ def conference_role_titles(record) end.compact end + def registration_ticket(record) + record.user.tickets.for_registration(conference) + end + + def registration_ticket_price(record) + record.user.ticket_purchases.where(ticket: registration_ticket(record)).first.amount_paid + end + def data records.map do |record| { @@ -42,15 +55,18 @@ def data roles: conference_role_titles(record.user), email: record.email, accepted_code_of_conduct: !!record.accepted_code_of_conduct, # rubocop:disable Style/DoubleNegation - ticket_type: record.user.tickets.where(conference: conference).pluck(:title), + ticket_type: registration_ticket(record).title, + ticket_price: registration_ticket_price(record), + attended: false, edit_url: edit_admin_conference_registration_path(conference, record), + # delete_url: delete_admin_conference_registration_path(conference, record), DT_RowId: dom_id(record) } end end def get_raw_records # rubocop:disable Naming/AccessorMethodName - conference.registrations.includes(user: %i[roles tickets]).references(:users, :roles).distinct + conference.registrations.includes(user: %i[roles tickets ticket_purchases]).references(:users, :roles).distinct end # override upstream santitation, which converts everything to strings diff --git a/app/views/admin/registrations/index.html.haml b/app/views/admin/registrations/index.html.haml index 45f66b232..f1fe910a6 100644 --- a/app/views/admin/registrations/index.html.haml +++ b/app/views/admin/registrations/index.html.haml @@ -28,8 +28,11 @@ %th{ width: '25%' } Name %th{ width: '0' } E-Mail %th{ width: '0' } Ticket Type - %th{ width: '0' } - %abbr{ title: 'Code of Conduct' } CoC + %th{ width: '0' } Price + %th{ width: '0' } Attended + - if @code_of_conduct + %th{ width: '0' } + %abbr{ title: 'Code of Conduct' } CoC %th{ width: '0' } Actions %tbody @@ -69,20 +72,28 @@ { "data": "ticket_type" }, + { + "data": "ticket_price", + "render": (data) => `$${data}` + }, + { + "data": "attended" + }, { "data": "accepted_code_of_conduct", "className": "code-of-conduct text-center", "searchable": false, + // TODO: conditionally hide }, { "data": "actions", "className": "actions", "searchable": false, "sortable": false, - "render": function (data, type, row, meta) { - return '
'+ - 'Edit'+ - '
'; + "render": (data, type, row, meta) => { + return `
+ Edit +
`; } } ] From 2d426d1ce467585e2cf97806a24498ce0c1af81d Mon Sep 17 00:00:00 2001 From: Michael Ball Date: Sat, 29 Jul 2023 10:41:06 -0700 Subject: [PATCH 03/17] Fix CoC visibility on reg page --- app/views/admin/registrations/index.html.haml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/app/views/admin/registrations/index.html.haml b/app/views/admin/registrations/index.html.haml index f1fe910a6..a73a814e5 100644 --- a/app/views/admin/registrations/index.html.haml +++ b/app/views/admin/registrations/index.html.haml @@ -30,9 +30,8 @@ %th{ width: '0' } Ticket Type %th{ width: '0' } Price %th{ width: '0' } Attended - - if @code_of_conduct - %th{ width: '0' } - %abbr{ title: 'Code of Conduct' } CoC + %th{ width: '0' } + %abbr{ title: 'Code of Conduct' } CoC %th{ width: '0' } Actions %tbody @@ -83,7 +82,7 @@ "data": "accepted_code_of_conduct", "className": "code-of-conduct text-center", "searchable": false, - // TODO: conditionally hide + "visible": codeOfConductPresent }, { "data": "actions", From ece1d7d8644ea5b73c7442d00cd06a6cf9d9b2a2 Mon Sep 17 00:00:00 2001 From: Michael Ball Date: Sat, 29 Jul 2023 11:21:12 -0700 Subject: [PATCH 04/17] Registrations table refactoring complete, I think --- app/assets/javascripts/osem-switch.js | 4 +-- app/datatables/registration_datatable.rb | 3 +-- app/views/admin/registrations/index.html.haml | 26 ++++++++++++++----- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/app/assets/javascripts/osem-switch.js b/app/assets/javascripts/osem-switch.js index 5e8c47921..b4517c1cb 100644 --- a/app/assets/javascripts/osem-switch.js +++ b/app/assets/javascripts/osem-switch.js @@ -1,7 +1,5 @@ function checkboxSwitch(selector){ - $(selector).bootstrapSwitch( - - ); + $(selector).bootstrapSwitch(); $(selector).on('switchChange.bootstrapSwitch', function(event, state) { var url = $(this).attr('url') + state; diff --git a/app/datatables/registration_datatable.rb b/app/datatables/registration_datatable.rb index 7a6305ae2..f25d73fdc 100644 --- a/app/datatables/registration_datatable.rb +++ b/app/datatables/registration_datatable.rb @@ -57,9 +57,8 @@ def data accepted_code_of_conduct: !!record.accepted_code_of_conduct, # rubocop:disable Style/DoubleNegation ticket_type: registration_ticket(record).title, ticket_price: registration_ticket_price(record), - attended: false, + attended: record.attended?, edit_url: edit_admin_conference_registration_path(conference, record), - # delete_url: delete_admin_conference_registration_path(conference, record), DT_RowId: dom_id(record) } end diff --git a/app/views/admin/registrations/index.html.haml b/app/views/admin/registrations/index.html.haml index a73a814e5..4ddafe6dc 100644 --- a/app/views/admin/registrations/index.html.haml +++ b/app/views/admin/registrations/index.html.haml @@ -57,12 +57,12 @@ { "data": "name", "className": "truncate", - "render": function(data, type, row) { - var content = '' + data + '
'; - $.each(row.roles, function(index, role){ - content += ' ' + role + '' - }); - return content; + "render": (data, type, row) => { + return ` + ${data} +
+ ${row.roles.map(role => ` ${role}`)} + `; } }, { @@ -76,7 +76,19 @@ "render": (data) => `$${data}` }, { - "data": "attended" + "data": "attended", + "render": (data, _type, row) => { + let js_url = "#{toggle_attendance_admin_conference_registration_path(@conference.short_title, id: 'ROW_ID')}"; + return ` + + `; + } }, { "data": "accepted_code_of_conduct", From 6a05fd8747fc7564d10eadd182032e3e341e643d Mon Sep 17 00:00:00 2001 From: Michael Ball Date: Sat, 29 Jul 2023 11:37:06 -0700 Subject: [PATCH 05/17] I think the reg datatable is good now. :) --- app/views/admin/registrations/index.html.haml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/views/admin/registrations/index.html.haml b/app/views/admin/registrations/index.html.haml index 4ddafe6dc..c756e8dd2 100644 --- a/app/views/admin/registrations/index.html.haml +++ b/app/views/admin/registrations/index.html.haml @@ -73,13 +73,15 @@ }, { "data": "ticket_price", - "render": (data) => `$${data}` + "render": data => `$${data}` }, { "data": "attended", + "search": data => data, "render": (data, _type, row) => { let js_url = "#{toggle_attendance_admin_conference_registration_path(@conference.short_title, id: 'ROW_ID')}"; return ` + ${data} { + "render": (data, type, row) => { return ``; From 32144e4d1c564746d6b12b29a7d4c6874857b7ee Mon Sep 17 00:00:00 2001 From: Michael Ball Date: Sun, 30 Jul 2023 14:45:02 -0700 Subject: [PATCH 06/17] use CSV to create a commercial/materials --- app/models/commercial.rb | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/app/models/commercial.rb b/app/models/commercial.rb index a08a890e6..622739b13 100644 --- a/app/models/commercial.rb +++ b/app/models/commercial.rb @@ -48,18 +48,17 @@ def self.read_file(file) errors[:no_event] = [] errors[:validation_errors] = [] - file. - file.read.each_line do |line| - # Get the event id (text before :) - id = line.match(/:/).pre_match.to_i - # Get the commercial url (text after :) - url = line.match(/:/).post_match + # parse file as a CSV with a header of id, title, url + CSV.parse(file, headers: true) do |row| + id = row['id'].to_i + title = row['title'] + url = row['url'] event = Event.find_by(id: id) # Go to next event, if the event is not found (errors[:no_event] << id) && next unless event - commercial = event.commercials.new(url: url) + commercial = event.commercials.new(url: url, title: title) unless commercial.save errors[:validation_errors] << ("Could not create materials for event with ID #{event.id} (" + commercial.errors.full_messages.to_sentence + ')') end From 1134f16401bf090b5026177ae14cb74dba14a129 Mon Sep 17 00:00:00 2001 From: Michael Ball Date: Sun, 13 Aug 2023 15:24:51 -0700 Subject: [PATCH 07/17] Refactor embedding slides, etc --- app/lib/embeddable_url.rb | 71 +++++++++++++++++++++++++++++++++ app/models/commercial.rb | 17 ++------ lib/embeddable_url.rb | 42 ------------------- spec/lib/embeddable_url_spec.rb | 20 ++++++++-- 4 files changed, 91 insertions(+), 59 deletions(-) create mode 100644 app/lib/embeddable_url.rb delete mode 100644 lib/embeddable_url.rb diff --git a/app/lib/embeddable_url.rb b/app/lib/embeddable_url.rb new file mode 100644 index 000000000..7dc8a992c --- /dev/null +++ b/app/lib/embeddable_url.rb @@ -0,0 +1,71 @@ +# Transform a URL to a version that allows iframes + +class EmbeddableURL + attr_accessor :url + + DEFAULT_FRAME_ATTRS = 'width=560 height=315 frameborder=0 allowfullscreen'.freeze + + TRANSFORMATIONS = { + /snap\.berkeley\.edu/ => :snap, + /docs\.google\.com/ => :google_docs, + /dropbox\.com/ => :dropbox + }.freeze + + def initialize(url) + self.url = url + end + + def render_embed + return render_dropbox if url.match?(/dropbox\.com/) + + "" + end + + def iframe_url + TRANSFORMATIONS.each do |regex, fn| + return send(fn, url) if url.match?(regex) + end + url + end + + # TODO: Consider adjusting the id / loading if > 1 dropbox embed per page. + def render_dropbox + <<~HTML +
+ + +
+ HTML + end + + private + + def optional_params + return '' unless url.match?(/snap\.berkeley/) + + 'allow="geolocation;microphone;camera"' + end + + def google_docs(url) + # replace /edit, /share, /comment with /embed and remove the querystring + url.gsub(%r{(/edit|/share|/comment).*}, '/embed') + end + + def dropbox(url) + uri = URI.parse(url) + query = CGI.parse(uri.query) + query.delete('dl') + query['raw'] = '1' + uri.query = query.to_query + uri.to_s + end + + def snap(url) + uri = URI.parse(url) + query = CGI.parse(uri.query) + username = query['username'][0] || query['user'][0] + project = query['projectname'][0] || query['project'][0] + "https://snap.berkeley.edu/embed?projectname=#{project}&username=#{username}&showTitle=true&showAuthor=true&editButton=true&pauseButton=true" + end +end diff --git a/app/models/commercial.rb b/app/models/commercial.rb index 622739b13..b027354b1 100644 --- a/app/models/commercial.rb +++ b/app/models/commercial.rb @@ -16,6 +16,7 @@ # class Commercial < ApplicationRecord require 'oembed' + require_relative '../lib/embeddable_url' belongs_to :commercialable, polymorphic: true, touch: true @@ -32,16 +33,11 @@ def self.render_from_url(url) resource = OEmbed::Providers.get(url, maxwidth: 560, maxheight: 315) { html: resource.html.html_safe } rescue StandardError - { html: iframe_fallback(url) } + { html: EmbeddableURL.new(url).render_embed.html_safe } # { error: exception.message } end end - def self.iframe_fallback(url) - url = EmbeddableURL.new(url).iframe_url - "".html_safe - end - def self.read_file(file) require 'csv' errors = {} @@ -60,7 +56,8 @@ def self.read_file(file) commercial = event.commercials.new(url: url, title: title) unless commercial.save - errors[:validation_errors] << ("Could not create materials for event with ID #{event.id} (" + commercial.errors.full_messages.to_sentence + ')') + errors[:validation_errors] << + "Could not create materials for event with ID #{event.id} (#{commercial.errors.full_messages.to_sentence})" end end errors @@ -68,12 +65,6 @@ def self.read_file(file) private - def optional_params - return '' unless self.url.match(%r{snap.berkeley}) - - 'allow="geolocation;microphone;camera"' - end - def valid_url result = Commercial.render_from_url(url) errors.add(:base, result[:error]) if result[:error] diff --git a/lib/embeddable_url.rb b/lib/embeddable_url.rb deleted file mode 100644 index 0a4872bc5..000000000 --- a/lib/embeddable_url.rb +++ /dev/null @@ -1,42 +0,0 @@ -# Transform a URL to a version that allows iframes - -class EmbeddableURL - attr_accessor :url - - TRANSFORMATIONS = { - /snap\.berkeley\.edu/ => snap, - /docs\.google\.com/ => google_docs, - /dropbox\.com/ => dropbox - }.freeze - - def iframe_url - TRANSFORMATIONS.each do |regex, fn| - return fn.call(url) if url.match?(regex) - end - url - end - - private - - def google_docs(url) - # replace /edit, /share ,/comment with /embed and remove the querystring - url.gsub(%r{(/edit|/share|/comment).*}, '/embed') - end - - def dropbox(url) - uri = URI.parse(url) - query = CGI.parse(uri.query) - query.delete('dl') - query['raw'] = '1' - uri.query = query.to_query - uri.to_s - end - - def snap(url) - uri = URI.parse(url) - query = CGI.parse(uri.query) - username = query['username'][0] || query['user'][0] - project = query['projectname'][0] || query['project'][0] - "https://snap.berkeley.edu/embed?projectname=#{project}&username=#{username}&showTitle=true&showAuthor=true&editButton=true&pauseButton=true" - end -end diff --git a/spec/lib/embeddable_url_spec.rb b/spec/lib/embeddable_url_spec.rb index 3282d2dc6..1e4f3f81c 100644 --- a/spec/lib/embeddable_url_spec.rb +++ b/spec/lib/embeddable_url_spec.rb @@ -9,9 +9,21 @@ expect(EmbeddableURL.new(url).iframe_url).to eq url end - it 'returns the transformed url if a transformation applies' do - url = 'https://docs.google.com' - expect(EmbeddableURL.new(url).iframe_url).to include '/embed' + it 'transforms a Google Drive URL' do + url = EmbeddableURL.new('https://docs.google.com/presentation/d/1eGbEQtcOPW2N2P5rKfBVfSo2zn4C307Sh6C7vpJsruE/edit#slide=id.g1088c029399_0_47').iframe_url + expect(url).to include '/embed' + expect(url).to_not include('/edit') end - end + + it 'transforms a Dropbox URL' do + url = EmbeddableURL.new('https://www.dropbox.com/scl/fi/49gkp6ghfnxgqex64zvzd/Guzdial-SnapCon23.pdf?rlkey=ecwvmcmfscqtwfq21l3kzqcul&dl=1').iframe_url + expect(url).to include('raw=1') + expect(url).to_not include('dl=') + end + + it 'transforms a Snap! Project URL' do + url = EmbeddableURL.new('').iframe_url + expect(url).to include('/embed') + end + end From 48a6292418f1bf29695464b3701592f18b4b85b9 Mon Sep 17 00:00:00 2001 From: Michael Ball Date: Sun, 13 Aug 2023 15:39:37 -0700 Subject: [PATCH 08/17] Move embeddable_url to services --- app/models/commercial.rb | 2 +- app/{lib => services}/embeddable_url.rb | 4 ++-- spec/{lib => services}/embeddable_url_spec.rb | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) rename app/{lib => services}/embeddable_url.rb (97%) rename spec/{lib => services}/embeddable_url_spec.rb (80%) diff --git a/app/models/commercial.rb b/app/models/commercial.rb index b027354b1..47a45755b 100644 --- a/app/models/commercial.rb +++ b/app/models/commercial.rb @@ -16,7 +16,7 @@ # class Commercial < ApplicationRecord require 'oembed' - require_relative '../lib/embeddable_url' + # require_relative '../lib/embeddable_url' belongs_to :commercialable, polymorphic: true, touch: true diff --git a/app/lib/embeddable_url.rb b/app/services/embeddable_url.rb similarity index 97% rename from app/lib/embeddable_url.rb rename to app/services/embeddable_url.rb index 7dc8a992c..6e4ed3830 100644 --- a/app/lib/embeddable_url.rb +++ b/app/services/embeddable_url.rb @@ -55,8 +55,8 @@ def google_docs(url) def dropbox(url) uri = URI.parse(url) query = CGI.parse(uri.query) - query.delete('dl') - query['raw'] = '1' + query.delete('raw') + query['dl'] = '0' uri.query = query.to_query uri.to_s end diff --git a/spec/lib/embeddable_url_spec.rb b/spec/services/embeddable_url_spec.rb similarity index 80% rename from spec/lib/embeddable_url_spec.rb rename to spec/services/embeddable_url_spec.rb index 1e4f3f81c..d9dcb6f1a 100644 --- a/spec/lib/embeddable_url_spec.rb +++ b/spec/services/embeddable_url_spec.rb @@ -17,12 +17,12 @@ it 'transforms a Dropbox URL' do url = EmbeddableURL.new('https://www.dropbox.com/scl/fi/49gkp6ghfnxgqex64zvzd/Guzdial-SnapCon23.pdf?rlkey=ecwvmcmfscqtwfq21l3kzqcul&dl=1').iframe_url - expect(url).to include('raw=1') - expect(url).to_not include('dl=') + expect(url).to include('dl=0') + expect(url).to_not include('raw=') end it 'transforms a Snap! Project URL' do - url = EmbeddableURL.new('').iframe_url + url = EmbeddableURL.new('https://snap.berkeley.edu/project?username=jedi_force&projectname=Autograder%2dlite').iframe_url expect(url).to include('/embed') end From 89c1e1bd56ff5daf70109e71068fd613880519fa Mon Sep 17 00:00:00 2001 From: Michael Ball Date: Sun, 13 Aug 2023 15:47:50 -0700 Subject: [PATCH 09/17] Class autoloads as EmbeddableURL now, Dropbox works, but function is broken... --- app/models/commercial.rb | 1 - app/services/embeddable_url.rb | 2 +- config/initializers/inflections.rb | 6 +++--- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/app/models/commercial.rb b/app/models/commercial.rb index 47a45755b..7b67cd5d5 100644 --- a/app/models/commercial.rb +++ b/app/models/commercial.rb @@ -16,7 +16,6 @@ # class Commercial < ApplicationRecord require 'oembed' - # require_relative '../lib/embeddable_url' belongs_to :commercialable, polymorphic: true, touch: true diff --git a/app/services/embeddable_url.rb b/app/services/embeddable_url.rb index 6e4ed3830..9d5a520ca 100644 --- a/app/services/embeddable_url.rb +++ b/app/services/embeddable_url.rb @@ -33,7 +33,7 @@ def render_dropbox <<~HTML
-
HTML diff --git a/config/initializers/inflections.rb b/config/initializers/inflections.rb index ac033bf9d..90ac51ca2 100644 --- a/config/initializers/inflections.rb +++ b/config/initializers/inflections.rb @@ -11,6 +11,6 @@ # end # These inflection rules are supported but not enabled by default: -# ActiveSupport::Inflector.inflections(:en) do |inflect| -# inflect.acronym 'RESTful' -# end +ActiveSupport::Inflector.inflections(:en) do |inflect| + inflect.acronym 'URL' +end From 20cc01852392bd5631e482556816aba214d9f7a5 Mon Sep 17 00:00:00 2001 From: Michael Ball Date: Sun, 13 Aug 2023 18:03:56 -0700 Subject: [PATCH 10/17] Attempt to fix dropbox URL generation --- app/services/embeddable_url.rb | 12 +++++++----- config/puma.rb | 3 ++- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/app/services/embeddable_url.rb b/app/services/embeddable_url.rb index 9d5a520ca..396e26f07 100644 --- a/app/services/embeddable_url.rb +++ b/app/services/embeddable_url.rb @@ -33,7 +33,7 @@ def render_dropbox <<~HTML
-
HTML @@ -53,11 +53,13 @@ def google_docs(url) end def dropbox(url) + # debugger uri = URI.parse(url) - query = CGI.parse(uri.query) - query.delete('raw') - query['dl'] = '0' - uri.query = query.to_query + params = URI.decode_www_form(uri.query) + params.delete('raw') + params['dl'] = '0' + # params['rlkey'] = params['rlkey'] + uri.query = params uri.to_s end diff --git a/config/puma.rb b/config/puma.rb index 35d73834e..c401d6fc2 100644 --- a/config/puma.rb +++ b/config/puma.rb @@ -25,12 +25,13 @@ # processes). # workers ENV.fetch('WEB_CONCURRENCY') { 2 } +# Set a 10 minute timeout in development for debugging. +worker_timeout 60 * 60 * 10 if ENV.fetch('RAILS_ENV') == 'development' # Use the `preload_app!` method when specifying a `workers` number. # This directive tells Puma to first boot the application and load code # before forking the application. This takes advantage of Copy On Write # process behavior so workers use less memory. -# preload_app! lowlevel_error_handler do |ex, env| From e82d13094c643961fc56ec5778b94a7c5b313c32 Mon Sep 17 00:00:00 2001 From: Michael Ball Date: Mon, 14 Aug 2023 02:06:13 -0700 Subject: [PATCH 11/17] fix messup in spec file --- spec/services/embeddable_url_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/services/embeddable_url_spec.rb b/spec/services/embeddable_url_spec.rb index d9dcb6f1a..5e54fbc88 100644 --- a/spec/services/embeddable_url_spec.rb +++ b/spec/services/embeddable_url_spec.rb @@ -25,5 +25,5 @@ url = EmbeddableURL.new('https://snap.berkeley.edu/project?username=jedi_force&projectname=Autograder%2dlite').iframe_url expect(url).to include('/embed') end - + end end From 4c83a217d3744a0a393e7536576127ebc405c1e0 Mon Sep 17 00:00:00 2001 From: Michael Ball Date: Mon, 14 Aug 2023 02:09:22 -0700 Subject: [PATCH 12/17] delete spec which leads to warning about being ineffective --- spec/models/track_spec.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/spec/models/track_spec.rb b/spec/models/track_spec.rb index 7c8df641a..a054de04b 100644 --- a/spec/models/track_spec.rb +++ b/spec/models/track_spec.rb @@ -61,8 +61,6 @@ withdrawn]) } - it { is_expected.to validate_inclusion_of(:cfp_active).in_array([true, false]) } - context 'when self_organized_and_accepted_or_confirmed? returns true' do before do allow(subject).to receive(:self_organized_and_accepted_or_confirmed?).and_return(true) From 518f3fdc29a637da02499e1a355aefdfee2c02ca Mon Sep 17 00:00:00 2001 From: Michael Ball Date: Sat, 20 Jul 2024 12:22:32 -0700 Subject: [PATCH 13/17] delint --- app/datatables/registration_datatable.rb | 1 - spec/services/embeddable_url_spec.rb | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/app/datatables/registration_datatable.rb b/app/datatables/registration_datatable.rb index f25d73fdc..d8969fff8 100644 --- a/app/datatables/registration_datatable.rb +++ b/app/datatables/registration_datatable.rb @@ -8,7 +8,6 @@ class RegistrationDatatable < AjaxDatatablesRails::ActiveRecord # def_delegator :@view, :delete_admin_conference_registration_path def_delegator :@view, :admin_conference_registration_toggle_attendance_path - def initialize(params, opts = {}) @view = opts[:view_context] super diff --git a/spec/services/embeddable_url_spec.rb b/spec/services/embeddable_url_spec.rb index 5e54fbc88..a8f506ec7 100644 --- a/spec/services/embeddable_url_spec.rb +++ b/spec/services/embeddable_url_spec.rb @@ -12,13 +12,13 @@ it 'transforms a Google Drive URL' do url = EmbeddableURL.new('https://docs.google.com/presentation/d/1eGbEQtcOPW2N2P5rKfBVfSo2zn4C307Sh6C7vpJsruE/edit#slide=id.g1088c029399_0_47').iframe_url expect(url).to include '/embed' - expect(url).to_not include('/edit') + expect(url).not_to include('/edit') end it 'transforms a Dropbox URL' do url = EmbeddableURL.new('https://www.dropbox.com/scl/fi/49gkp6ghfnxgqex64zvzd/Guzdial-SnapCon23.pdf?rlkey=ecwvmcmfscqtwfq21l3kzqcul&dl=1').iframe_url expect(url).to include('dl=0') - expect(url).to_not include('raw=') + expect(url).not_to include('raw=') end it 'transforms a Snap! Project URL' do From 815854bb4ecfcda3ff9a7b7f295cc6fdb6c836a6 Mon Sep 17 00:00:00 2001 From: Michael Ball Date: Sat, 20 Jul 2024 12:23:08 -0700 Subject: [PATCH 14/17] delint - regexp --- app/services/embeddable_url.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/services/embeddable_url.rb b/app/services/embeddable_url.rb index 396e26f07..a0e9e201c 100644 --- a/app/services/embeddable_url.rb +++ b/app/services/embeddable_url.rb @@ -16,7 +16,7 @@ def initialize(url) end def render_embed - return render_dropbox if url.match?(/dropbox\.com/) + return render_dropbox if url.include?('dropbox.com') "" end @@ -42,7 +42,7 @@ def render_dropbox private def optional_params - return '' unless url.match?(/snap\.berkeley/) + return '' unless url.include?('snap.berkeley') 'allow="geolocation;microphone;camera"' end From f2bead1416ceb91934e4384514532cee620567cb Mon Sep 17 00:00:00 2001 From: Michael Ball Date: Sat, 20 Jul 2024 12:45:09 -0700 Subject: [PATCH 15/17] Fix dropbox media embed params --- app/services/embeddable_url.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/services/embeddable_url.rb b/app/services/embeddable_url.rb index a0e9e201c..6ca31369a 100644 --- a/app/services/embeddable_url.rb +++ b/app/services/embeddable_url.rb @@ -18,6 +18,7 @@ def initialize(url) def render_embed return render_dropbox if url.include?('dropbox.com') + # TODO-A11Y: Set an iframe title "" end @@ -55,11 +56,11 @@ def google_docs(url) def dropbox(url) # debugger uri = URI.parse(url) - params = URI.decode_www_form(uri.query) + params = URI.decode_www_form(uri.query)&.to_h params.delete('raw') params['dl'] = '0' # params['rlkey'] = params['rlkey'] - uri.query = params + uri.query = params.to_query uri.to_s end From 1c0877cb6626c3ddf88974d222b86ead95b2850b Mon Sep 17 00:00:00 2001 From: Michael Ball Date: Sat, 20 Jul 2024 12:49:08 -0700 Subject: [PATCH 16/17] address nil URL case for media embeds --- app/models/commercial.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/models/commercial.rb b/app/models/commercial.rb index 49d09b95a..c62a34ab9 100644 --- a/app/models/commercial.rb +++ b/app/models/commercial.rb @@ -74,6 +74,8 @@ def self.read_file(file) private def valid_url + return unless url + result = Commercial.render_from_url(url) errors.add(:base, result[:error]) if result[:error] end From fa532b012778c82cd4c19a38679a5dfb185546e7 Mon Sep 17 00:00:00 2001 From: Michael Ball Date: Sat, 20 Jul 2024 13:08:19 -0700 Subject: [PATCH 17/17] exclude haml file --- .haml-lint_todo.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.haml-lint_todo.yml b/.haml-lint_todo.yml index 7b80c2d84..93b401d76 100644 --- a/.haml-lint_todo.yml +++ b/.haml-lint_todo.yml @@ -46,6 +46,7 @@ linters: - "app/views/admin/events/index.html.haml" - "app/views/admin/tracks/index.html.haml" - "app/views/admin/tracks/show.html.haml" + - "app/views/admin/registrations/index.html.haml" - "app/views/admin/versions/_object_desc_and_link.html.haml" - "app/views/conference_registrations/show.html.haml" - "app/views/layouts/_admin_sidebar.html.haml"