diff --git a/Gemfile b/Gemfile index b25cf8ad..4bbddc27 100644 --- a/Gemfile +++ b/Gemfile @@ -116,8 +116,8 @@ end gem 'bootstrap3-datetimepicker-rails', '~> 4.17.47' # data tables -gem 'jquery-datatables' gem 'ajax-datatables-rails' +gem 'jquery-datatables' # for charts gem 'chartkick' diff --git a/app/controllers/admin/reports_controller.rb b/app/controllers/admin/reports_controller.rb index 5d9eabf4..a4eb9f60 100644 --- a/app/controllers/admin/reports_controller.rb +++ b/app/controllers/admin/reports_controller.rb @@ -9,7 +9,7 @@ module Admin def index @events = Event.accessible_by(current_ability).where(program: @program, - state: [:confirmed, :unconfirmed]) + state: [:confirmed, :unconfirmed]) @events_commercials = Commercial.where(commercialable_type: 'Event', commercialable_id: @events.pluck(:id)) @events_missing_commercial = @events.where.not(id: @events_commercials.pluck(:commercialable_id)) @events_with_requirements = @events.where.not(description: ['', nil]) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 7b868e83..c9f93a30 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -10,22 +10,22 @@ class ApplicationController < ActionController::Base check_authorization unless: :devise_controller? skip_authorization_check if: - def store_location - # store last url - this is needed for post-login redirect to whatever the user last visited. - return unless request.get? + def store_location + # store last url - this is needed for post-login redirect to whatever the user last visited. + return unless request.get? - if (request.path != '/accounts/sign_in' && - request.path != '/accounts/sign_up' && - request.path != '/accounts/password/new' && - request.path != '/accounts/password/edit' && - request.path != '/accounts/confirmation' && - request.path != '/accounts/sign_out' && - request.path != '/users/ichain_registration/ichain_sign_up' && - !request.path.starts_with?(Devise.ichain_base_url) && - !request.xhr?) # don't store ajax calls - session[:return_to] = request.fullpath - end - end + if (request.path != '/accounts/sign_in' && + request.path != '/accounts/sign_up' && + request.path != '/accounts/password/new' && + request.path != '/accounts/password/edit' && + request.path != '/accounts/confirmation' && + request.path != '/accounts/sign_out' && + request.path != '/users/ichain_registration/ichain_sign_up' && + !request.path.starts_with?(Devise.ichain_base_url) && + !request.xhr?) # don't store ajax calls + session[:return_to] = request.fullpath + end + end def after_sign_in_path_for(_resource) if (can? :view, Conference) && diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index e69a52aa..55af84df 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -27,11 +27,13 @@ class UsersController < ApplicationController def user_params params.require(:user).permit(:name, :biography, :nickname, :affiliation, - :picture, :picture_cache) + :picture, :picture_cache) end # Somewhat of a hack: users/current/edit + # rubocop:disable Naming/MemoizedInstanceVariableName def load_user @user ||= (params[:id] && params[:id] != 'current' && User.find(params[:id]) || current_user) end + # rubocop:enable Naming/MemoizedInstanceVariableName end diff --git a/app/datatables/user_datatable.rb b/app/datatables/user_datatable.rb index c21aa2ff..45200ebb 100644 --- a/app/datatables/user_datatable.rb +++ b/app/datatables/user_datatable.rb @@ -1,4 +1,3 @@ - # frozen_string_literal: true class UserDatatable < AjaxDatatablesRails::Base diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 6984f304..80ea92c0 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -112,7 +112,7 @@ module ApplicationHelper concurrent_events << other_event_schedule.event end end - concurrent_events.sort_by { |event_schedule| event_schedule.room&.order } + concurrent_events.sort_by { |schedule| schedule.room&.order } end def speaker_links(event) @@ -188,7 +188,7 @@ module ApplicationHelper 'hidden' if Date.today > conference.end_date end - # TODO:Snap!Con: Replace this with a search for a conference logo. + # TODO: Snap!Con: Replace this with a search for a conference logo. def nav_root_link_for(conference = nil) path = conference&.id.present? ? conference_path(conference) : root_path link_to( @@ -201,8 +201,8 @@ module ApplicationHelper def nav_link_text(conference) conference.try(:organization).try(:name) || - ENV['OSEM_NAME'] || - 'OSEM' + ENV['OSEM_NAME'] || + 'OSEM' end # returns the url to be used for logo on basis of sponsorship level position diff --git a/app/helpers/conference_helper.rb b/app/helpers/conference_helper.rb index 39316f9f..85ead390 100644 --- a/app/helpers/conference_helper.rb +++ b/app/helpers/conference_helper.rb @@ -24,6 +24,7 @@ module ConferenceHelper def short_ticket_description(ticket) return unless ticket.description + markdown(ticket.description.split("\n").first&.strip) end end diff --git a/app/helpers/events_helper.rb b/app/helpers/events_helper.rb index 0c135c32..eebaa4fe 100644 --- a/app/helpers/events_helper.rb +++ b/app/helpers/events_helper.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true +# TODO: Split this module into smaller modules +# rubocop:disable Metrics/ModuleLength module EventsHelper ## # Includes functions related to events @@ -164,7 +166,7 @@ module EventsHelper conference_id, event.id, event.send(attribute), - url: admin_conference_program_event_path( + url: admin_conference_program_event_path( conference_id, event, event: { attribute => nil } @@ -183,7 +185,7 @@ module EventsHelper if current_user.roles.where(id: conference.roles).any? # Show Pre-Event links for any memeber of the conference team. link_to("Join Live Event #{'(Admin link)' unless is_now}", - event.url, target: '_blank') + event.url, target: '_blank') elsif current_user.registered_to_event?(conference) if is_now link_to('Join Live Event', event.url, target: '_blank') @@ -193,7 +195,7 @@ module EventsHelper end end - def calendar_timestamp(timestamp, timezone) + def calendar_timestamp(timestamp, _timezone) timestamp = timestamp.in_time_zone('GMT') timestamp -= timestamp.utc_offset timestamp.strftime('%Y%m%dT%H%M%S') @@ -206,12 +208,12 @@ module EventsHelper start_timestamp = calendar_timestamp(event_schedule.start_time, conference.timezone) end_timestamp = calendar_timestamp(event_schedule.end_time, conference.timezone) event_details = { - action: 'TEMPLATE', - text: "#{event.title} at #{conference.title}", - details: calendar_event_text(event, event_schedule, conference), + action: 'TEMPLATE', + text: "#{event.title} at #{conference.title}", + details: calendar_event_text(event, event_schedule, conference), location: "#{event.room.name} #{event.url}", - dates: "#{start_timestamp}/#{end_timestamp}", - ctz: event_schedule.timezone + dates: "#{start_timestamp}/#{end_timestamp}", + ctz: event_schedule.timezone } "#{calendar_base}?#{event_details.to_param}" end @@ -220,13 +222,13 @@ module EventsHelper def calendar_event_text(event, event_schedule, conference) <<~TEXT - #{conference.title} - #{event.title} - #{event_schedule.start_time.strftime("%Y %B %e - %H:%M")} #{event_schedule.timezone} + #{conference.title} - #{event.title} + #{event_schedule.start_time.strftime('%Y %B %e - %H:%M')} #{event_schedule.timezone} - More Info: #{conference_program_proposal_url(conference, event)} - Join: #{event.url} + More Info: #{conference_program_proposal_url(conference, event)} + Join: #{event.url} - #{truncate(event.abstract, length: 200)} + #{truncate(event.abstract, length: 200)} TEXT end @@ -256,3 +258,4 @@ module EventsHelper end end end +# rubocop:enable Metrics/ModuleLength diff --git a/app/helpers/format_helper.rb b/app/helpers/format_helper.rb index 6aa198d6..418fa93a 100644 --- a/app/helpers/format_helper.rb +++ b/app/helpers/format_helper.rb @@ -184,12 +184,12 @@ module FormatHelper return '' if text.nil? options = { - autolink: true, + autolink: true, space_after_headers: true, - tables: true, - strikethrough: true, - footnotes: true, - superscript: true + tables: true, + strikethrough: true, + footnotes: true, + superscript: true } markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML.new(escape_html: escape_html), options) markdown.render(text).html_safe diff --git a/app/models/ability.rb b/app/models/ability.rb index 9db7bacf..ec17e14c 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -68,6 +68,8 @@ class Ability end # Abilities for signed in users + # TODO: Refactor into multiple functions + # rubocop:disable Metrics/AbcSize def signed_in(user) # Abilities from not_signed_in user are also inherited not_signed_in @@ -140,6 +142,7 @@ class Ability user == track.submitter && !(track.accepted? || track.confirmed?) end end + # rubocop:enable Metrics/AbcSize # Abilities for users with roles wandering around in non-admin views. def common_abilities_for_admins(user) diff --git a/app/models/commercial.rb b/app/models/commercial.rb index 51f8b7f5..ee514459 100644 --- a/app/models/commercial.rb +++ b/app/models/commercial.rb @@ -17,7 +17,7 @@ class Commercial < ApplicationRecord begin resource = OEmbed::Providers.get(url, maxwidth: 560, maxheight: 315) { html: resource.html.html_safe } - rescue StandardError => exception + rescue StandardError { html: iframe_fallback(url) } # { error: exception.message } end diff --git a/app/models/conference.rb b/app/models/conference.rb index c91939ae..73e56210 100644 --- a/app/models/conference.rb +++ b/app/models/conference.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true +# rubocop:disable Metrics/ClassLength class Conference < ApplicationRecord include RevisionCount require 'uri' @@ -1199,3 +1200,4 @@ class Conference < ApplicationRecord ] end end +# rubocop:enable Metrics/ClassLength diff --git a/app/models/event.rb b/app/models/event.rb index 2007dec6..72a1917f 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -281,7 +281,6 @@ class Event < ApplicationRecord event_schedules.find_by(schedule_id: selected_schedule_id).try(:happening_now?) end - ## # Returns true or false, if the event is already over or not # diff --git a/app/models/event_user.rb b/app/models/event_user.rb index f8a2b66a..44f9d78b 100644 --- a/app/models/event_user.rb +++ b/app/models/event_user.rb @@ -2,7 +2,7 @@ class EventUser < ApplicationRecord ROLES = [%w[Speaker speaker], %w[Submitter submitter], %w[Moderator moderator], - %w[Volunteer volunteer]] + %w[Volunteer volunteer]] belongs_to :event, touch: true belongs_to :user diff --git a/app/models/payment.rb b/app/models/payment.rb index 870e82cc..fba15138 100644 --- a/app/models/payment.rb +++ b/app/models/payment.rb @@ -23,7 +23,7 @@ class Payment < ApplicationRecord end def stripe_description - #"ticket purchases(#{user.username})" + # "ticket purchases(#{user.username})" "Tickets for #{conference.title} #{user.name} #{user.email}" end diff --git a/app/models/ticket_purchase.rb b/app/models/ticket_purchase.rb index 1eaa9cf5..924ee2a1 100644 --- a/app/models/ticket_purchase.rb +++ b/app/models/ticket_purchase.rb @@ -107,6 +107,7 @@ end def count_purchased_registration_tickets(conference, purchases) # TODO: WHAT CAUSED THIS??? return 0 unless purchases + conference.tickets.for_registration.inject(0) do |sum, registration_ticket| sum + purchases[registration_ticket.id.to_s].to_i end diff --git a/app/models/user.rb b/app/models/user.rb index d7f23779..2967b542 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -56,8 +56,7 @@ class User < ApplicationRecord :recoverable, :rememberable, :trackable, :validatable, :confirmable, :omniauthable, # omniauth_providers: [:suse, :google, :facebook, :github, :discourse] - omniauth_providers: [:google, :discourse] - ] + omniauth_providers: [:google, :discourse]] end devise(*devise_modules) @@ -160,6 +159,7 @@ class User < ApplicationRecord # Partials should *not* directly call `gravatar_url` def profile_picture(opts = {}) return gravatar_url(opts) unless picture.present? + size = (opts[:size] || 0).to_i if size < 50 picture.tiny.url @@ -259,7 +259,7 @@ class User < ApplicationRecord # TODO: Use a real authorization in the right place.... def manages_volunteers?(conference) organizer_roles = get_roles['organizer'] - organizer_roles&.include?(conference.short_title) # TODO or Volunteer Coorinator. + organizer_roles&.include?(conference.short_title) # TODO: or Volunteer Coorinator. end def registered @@ -300,7 +300,6 @@ class User < ApplicationRecord events.where(program_id: conference.program.id, 'event_users.event_role': 'volunteer') end - def self.empty? User.count == 1 && User.first.email == 'deleted@localhost.osem' end diff --git a/config/application.rb b/config/application.rb index 874f4456..18f917aa 100644 --- a/config/application.rb +++ b/config/application.rb @@ -68,9 +68,11 @@ module Osem config.before_configuration do env_file = File.join(Rails.root, 'config', 'local_env.yml') - YAML.load(File.open(env_file)).each do |key, value| - ENV[key.to_s] = value - end if File.exists?(env_file) + if File.exist?(env_file) + YAML.safe_load(File.open(env_file)).each do |key, value| + ENV[key.to_s] = value + end + end end end end diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb index 101f0c3d..d00b17f0 100644 --- a/config/initializers/devise.rb +++ b/config/initializers/devise.rb @@ -15,7 +15,7 @@ Devise.setup do |config| scope: 'email' config.omniauth :discourse, - sso_url: 'https://forum.snap.berkeley.edu/session/sso_provider', + sso_url: 'https://forum.snap.berkeley.edu/session/sso_provider', sso_secret: ENV['OSEM_DISCOURSE_SECRET'] config.omniauth :facebook, diff --git a/config/puma.rb b/config/puma.rb index 1d43c487..400b5d03 100644 --- a/config/puma.rb +++ b/config/puma.rb @@ -46,9 +46,9 @@ end lowlevel_error_handler do |ex, env| Raven.capture_exception( ex, - :message => ex.message, - :extra => { :puma => env }, - :transaction => "Puma" + message: ex.message, + extra: { puma: env }, + transaction: "Puma" ) # note the below is just a Rack response [500, {}, ["An error has occurred, and engineers have been informed. Please reload the page. If you continue to have problems, contact conference@snap.berkeley.edu\n"]] diff --git a/config/routes.rb b/config/routes.rb index ef984ca9..362b762c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,6 +1,6 @@ Osem::Application.routes.draw do - mount LetterOpenerWeb::Engine, at: "/letter_opener" if Rails.env.development? + mount LetterOpenerWeb::Engine, at: '/letter_opener' if Rails.env.development? if ENV['OSEM_ICHAIN_ENABLED'] == 'true' devise_for :users, controllers: { registrations: :registrations } diff --git a/db/migrate/20180409170433_add_visible_to_tickets.rb b/db/migrate/20180409170433_add_visible_to_tickets.rb index 199f7a48..2286a065 100644 --- a/db/migrate/20180409170433_add_visible_to_tickets.rb +++ b/db/migrate/20180409170433_add_visible_to_tickets.rb @@ -2,7 +2,7 @@ class AddVisibleToTickets < ActiveRecord::Migration[5.0] def up add_column :tickets, :visible, :boolean, default: true Ticket.reset_column_information - Ticket.update_all(visible: true) # rubocop:disable Rails/SkipsModelValidations + Ticket.update_all(visible: true) end def down diff --git a/lib/tasks/db.rake b/lib/tasks/db.rake index 3c9cded7..bed74e53 100644 --- a/lib/tasks/db.rake +++ b/lib/tasks/db.rake @@ -13,24 +13,24 @@ namespace :db do end end - desc "Import a given file into the database" + desc 'Import a given file into the database' task :import, [:path] => :environment do |_t, args| dump_path = args.path connection_config = ActiveRecord::Base.connection_config case connection_config[:adapter] - when "postgresql" + when 'postgresql' system("PGPASSWORD=#{connection_config[:password]} pg_restore " \ - "--verbose --clean --no-acl --no-owner " \ + '--verbose --clean --no-acl --no-owner ' \ "--username=#{connection_config[:username]} " \ "-d #{connection_config[:database]} #{dump_path}") - when "mysql", "mysql2" + when 'mysql', 'mysql2' system("mysql -u #{connection_config[:username]} " \ "-p#{connection_config[:password]} " \ "#{connection_config[:database]} < #{dump_path}") else - raise NotImplementedError, "An importer hasn't been implemented for: " \ - "#{connection_config[:adapter]}" + raise NotImplementedError.new("An importer hasn't been implemented for: " \ + "#{connection_config[:adapter]}") end end end diff --git a/lib/tasks/registrations.rake b/lib/tasks/registrations.rake index f94bb3ae..709e13e0 100644 --- a/lib/tasks/registrations.rake +++ b/lib/tasks/registrations.rake @@ -1,17 +1,17 @@ # frozen_string_literal: true namespace :registrations do - desc "Create missing registrations for those how have a registration ticket." - task :create_missing, [:conference] => :environment do |t, args| + desc 'Create missing registrations for those how have a registration ticket.' + task :create_missing, [:conference] => :environment do |_t, args| - fail 'Please supply a conference short name.' unless args.conference + raise 'Please supply a conference short name.' unless args.conference conf = Conference.find_by(short_title: args.conference) # Check if a user is found based on the supplied email address - fail "Coud not find conference #{args.conference}" unless conf + raise "Coud not find conference #{args.conference}" unless conf purchases = conf.ticket_purchases.where(ticket: conf.registration_tickets, paid: true) - unregistered = purchases.select { |tp| !conf.user_registered?(tp.user) } + unregistered = purchases.reject { |tp| conf.user_registered?(tp.user) } puts "Found #{unregistered.count} unregistered users for #{purchases.count} ticket purchases." puts "There are currently #{conf.participants.count} registered users." @@ -19,17 +19,17 @@ namespace :registrations do puts "Creating registration for #{tp.user.email}" Registration.create(user: tp.user, conference: conf) end - puts "Done." + puts 'Done.' end - desc "Show User emails who have not paid, but did register" - task :list_unpaid, [:conference] => :environment do |t, args| + desc 'Show User emails who have not paid, but did register' + task :list_unpaid, [:conference] => :environment do |_t, args| - fail 'Please supply a conference short name.' unless args.conference + raise 'Please supply a conference short name.' unless args.conference conf = Conference.find_by(short_title: args.conference) # Check if a user is found based on the supplied email address - fail "Coud not find conference #{args.conference}" unless conf + raise "Coud not find conference #{args.conference}" unless conf registered = conf.participants unpaid = registered.select do |user| @@ -41,6 +41,6 @@ namespace :registrations do unpaid.each do |user| puts "'#{user.name}'<#{user.email}>, " end - puts "" + puts '' end end diff --git a/spec/controllers/admin/tickets_controller_spec.rb b/spec/controllers/admin/tickets_controller_spec.rb index 6f09070c..d2efb9ee 100644 --- a/spec/controllers/admin/tickets_controller_spec.rb +++ b/spec/controllers/admin/tickets_controller_spec.rb @@ -69,8 +69,8 @@ describe Admin::TicketsController do it 'creates new ticket' do expect do post :create, params: { - ticket: attributes_for(:ticket), - conference_id: conference + ticket: attributes_for(:ticket), + conference_id: conference } end.to change{ conference.tickets.count }.from(ticket_count).to(ticket_count + 1) end diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb index edadc869..3a3c53ea 100644 --- a/spec/helpers/application_helper_spec.rb +++ b/spec/helpers/application_helper_spec.rb @@ -65,7 +65,7 @@ describe ApplicationHelper, type: :helper do describe 'navigation title link' do it 'should default to OSEM' do ENV.delete('OSEM_NAME') - # TODO:Snap!Con: expect(nav_root_link_for(nil)).to match 'OSEM' + # TODO: Snap!Con: expect(nav_root_link_for(nil)).to match 'OSEM' expect(nav_root_link_for(nil)).to match image_tag('snapcon_logo.png') end diff --git a/spec/helpers/format_helper_spec.rb b/spec/helpers/format_helper_spec.rb index 9d611ccb..cd1940e0 100644 --- a/spec/helpers/format_helper_spec.rb +++ b/spec/helpers/format_helper_spec.rb @@ -13,12 +13,12 @@ describe FormatHelper, type: :helper do expect(Redcarpet::Markdown).to receive(:new) .with( Redcarpet::Render::HTML, - autolink: true, + autolink: true, space_after_headers: true, - tables: true, - strikethrough: true, - footnotes: true, - superscript: true + tables: true, + strikethrough: true, + footnotes: true, + superscript: true ) .and_call_original