Merge branch 'master' into submission-reviewer-comments

* master: (246 commits)
  merge master
  Skip datatable spec because github actions is weird.
  Add devise view files for email messages
  Make the _mailbot_* files not depend on @conference
  Tweak devise text for confirm emails
  Run database migrations on release
  [fix]Add mailbot.css to assets.rb
  [fix]Fix empty string check
  [fix]Fix program#any_event_for_this_date?
  Add newline at end of show.js.erb file
  [feat]Display happening now only if program is also displayed
  [feat]Add brief version of event partial; fix style
  [feat]Description / happening now takes the entire row if the other is empty
  [feat]Use Ajax for paginating happening_now
  [style]Fix style
  [refactor]Delete unused javascript; Move about-and-happening-now to partial
  [feat]Add bootstrap style to pagination navbar
  [fix]Fix style; Re-enable checking happening now
  items per page
  pagination
  ...
This commit is contained in:
Michael Ball 2021-04-15 22:22:52 -07:00
commit 6ce36c0fca
60 changed files with 878 additions and 152 deletions

View file

@ -54,6 +54,7 @@
//= require selectize
//= require bootstrap-select
//= require osem-survey
//= require pagy
$(document).ready(function() {
$('a[disabled=disabled]').click(function(event){
@ -63,4 +64,6 @@ $(document).ready(function() {
$('body').smoothScroll({
delegateSelector: 'a.smoothscroll'
});
window.addEventListener("load", Pagy.init);
});

View file

@ -149,13 +149,23 @@ function word_count(text, divId, maxcount) {
});
};
function fill_if_empty(text_area, filler) {
let area = $('#' + text_area);
function replace_defaut_submission_text(input_selector, new_text, valid_defaults) {
let $area = $(input_selector);
let current_text = $area.val();
if (!area.val()) {
area.val(filler);
area.trigger('change');
if (!current_text) {
$area.val(new_text);
$area.trigger('change');
return;
}
valid_defaults.some(default_text => {
if (current_text == default_text) {
$area.val(new_text);
$area.trigger('change');
return true;
}
});
}
/* Wait for the DOM to be ready before attaching events to the elements */
@ -166,8 +176,13 @@ $( document ).ready(function() {
var max = $selected.data("max-words");
var min = $selected.data("min-words");
// Set the filler text for the submission text
fill_if_empty('event_submission_text', $selected.data("instructions"));
// We replace the default text only if the current field is empty,
// or is set to the default text of another event type.
replace_defaut_submission_text(
'#event_submission_text',
$selected.data("instructions"),
$("#event_event_type_id option").toArray().map(e => $(e).data('instructions'))
);
$("#abstract-maximum-word-count").text(max);
$("#submission-maximum-word-count").text(max);

View file

@ -50,7 +50,7 @@ module Admin
:include_venue, :include_registrations,
:include_tickets, :include_lodgings,
:include_sponsors, :include_social_media,
:include_booths)
:include_booths, :include_happening_now)
end
end
end

View file

@ -3,6 +3,7 @@
class ApplicationController < ActionController::Base
before_action :set_paper_trail_whodunnit
include ApplicationHelper
include Pagy::Backend
add_flash_types :error
protect_from_forgery with: :exception, prepend: true
before_action :store_location

View file

@ -57,6 +57,8 @@ class ConferenceRegistrationsController < ApplicationController
sign_in(@registration.user)
end
MailblusterEditLeadJob.perform_later(@user, add_tags: ["snapcon-#{@conference.short_title}"])
if @conference.tickets.visible.any? && !current_user.supports?(@conference)
redirect_to conference_tickets_path(@conference.short_title),
notice: 'You are now registered and will be receiving E-Mail notifications.'
@ -87,6 +89,7 @@ class ConferenceRegistrationsController < ApplicationController
def destroy
if @registration.destroy
MailblusterEditLeadJob.perform_later(@user, remove_tags: ["snapcon-#{@conference.short_title}"])
redirect_to root_path,
notice: "You are not registered for #{@conference.title} anymore!"
else

View file

@ -1,6 +1,10 @@
# frozen_string_literal: true
EVENTS_PER_PAGE = Rails.configuration.conference[:events_per_page]
class ConferencesController < ApplicationController
include ConferenceHelper
protect_from_forgery with: :null_session
before_action :respond_to_options
load_and_authorize_resource find_by: :short_title, except: :show
@ -56,6 +60,13 @@ class ConferencesController < ApplicationController
if splashpage.include_booths
@booths = @conference.confirmed_booths.order('title')
end
if splashpage.include_happening_now
events_schedules_list = get_happening_now_events_schedules(@conference)
@events_schedules_limit = EVENTS_PER_PAGE
@events_schedules_length = events_schedules_list.length
@pagy, @events_schedules = pagy_array(events_schedules_list, items: @events_schedules_limit, link_extra: 'data-remote="true"')
@happening_now_url = happening_now_conference_schedule_path(conference_id: @conference.short_title, format: :json)
end
end
if splashpage.include_registrations || splashpage.include_tickets
@tickets = @conference.tickets.visible.order('price_cents')

View file

@ -1,6 +1,8 @@
# frozen_string_literal: true
class SchedulesController < ApplicationController
include ConferenceHelper
load_and_authorize_resource
before_action :respond_to_options
load_resource :conference, find_by: :short_title
@ -67,11 +69,13 @@ class SchedulesController < ApplicationController
end
def happening_now
@events_schedules = @program.selected_event_schedules(
includes: [:room, { event: %i[track event_type speakers submitter] }]
).select(&:happening_now?)
@events_schedules = [] unless @events_schedules
@events_schedules = get_happening_now_events_schedules(@conference)
@current_time = Time.now.in_time_zone(@conference.timezone)
respond_to do |format|
format.html
format.json { render json: @events_schedules.to_json(root: false, include: :event) }
end
end
def app

View file

@ -1,6 +1,7 @@
# frozen_string_literal: true
module ApplicationHelper
include Pagy::Frontend
# Returns a string build from the start and end date of the given conference.
#
# If the conference is only one day long

View file

@ -1,7 +1,7 @@
# frozen_string_literal: true
DEFAULT_LOGO = 'snapcon_logo.png'
DEFAULT_COLOR = '#0B3559'
DEFAULT_LOGO = Rails.configuration.conference[:default_logo_filename]
DEFAULT_COLOR = Rails.configuration.conference[:default_color]
module ConferenceHelper
# Return true if only call_for_papers or call_for_tracks or call_for_booths is open
@ -77,4 +77,12 @@ module ConferenceHelper
end
calendar
end
def get_happening_now_events_schedules(conference)
events_schedules = conference.program.selected_event_schedules(
includes: [:room, { event: %i[track event_type speakers submitter] }]
).select(&:happening_now?)
events_schedules ||= []
events_schedules
end
end

View file

@ -0,0 +1,9 @@
# frozen_string_literal: true
class MailblusterCreateLeadJob < ApplicationJob
queue_as :default
def perform(user)
MailblusterManager.create_lead(user)
end
end

View file

@ -0,0 +1,7 @@
class MailblusterDeleteLeadJob < ApplicationJob
queue_as :default
def perform(user)
MailblusterManager.delete_lead(user)
end
end

View file

@ -0,0 +1,9 @@
# frozen_string_literal: true
class MailblusterEditLeadJob < ApplicationJob
queue_as :default
def perform(user, add_tags: [], remove_tags: [], old_email: nil)
MailblusterManager.edit_lead(user, add_tags: add_tags, remove_tags: remove_tags, old_email: old_email)
end
end

View file

@ -1,8 +1,9 @@
# frozen_string_literal: true
SNAPCON_BCC_ADDRESS = 'messages@snap.berkeley.edu'
EMAIL_TEMPLATE = 'email_template'
YTLF_TICKET_ID = 50
SNAPCON_BCC_ADDRESS = Rails.configuration.mailbot[:bcc_address]
YTLF_TICKET_ID = Rails.configuration.mailbot[:ytlf_ticket_id]
class Mailbot < ActionMailer::Base
helper ConferenceHelper

View file

@ -0,0 +1,48 @@
# https://github.com/ccmcbeck/after-commit
module TrackSavedChanges
extend ActiveSupport::Concern
included do
# expose the details if consumer wants to do more
# attr_reader :ts_saved_changes_history, :ts_saved_changes_unfiltered
after_initialize :ts_reset_saved_changes
after_save :ts_track_saved_changes
end
# on initalize, but useful for fine grain control
def ts_reset_saved_changes
@ts_saved_changes_unfiltered = {}
@ts_saved_changes_history = []
end
# filter out any changes that result in the original value
def ts_saved_changes
@ts_saved_changes_unfiltered.reject { |_k, v| v[0] == v[1] }
end
private
# on save
def ts_track_saved_changes
# maintain an array of ActiveModel::Dirty.changes
@ts_saved_changes_history << previous_changes.dup
# accumulate the most recent changes
@ts_saved_changes_history.last.each_pair { |k, v| ts_track_saved_change k, v }
end
# v is an an array of [prev, current]
def ts_track_saved_change(key, value)
if @ts_saved_changes_unfiltered.key? key
@ts_saved_changes_unfiltered[key][1] = ts_track_saved_value value[1]
else
@ts_saved_changes_unfiltered[key] = value.dup
end
end
# type safe dup inspred by http://stackoverflow.com/a/20955038
def ts_track_saved_value(value)
value.dup
rescue TypeError
value
end
end

View file

@ -34,6 +34,8 @@
class Event < ApplicationRecord
include ActiveRecord::Transitions
include RevisionCount
include FormatHelper
has_paper_trail on: [:create, :update], ignore: [:updated_at, :guid, :week], meta: { conference_id: :conference_id }
acts_as_commentable
@ -338,6 +340,10 @@ class Event < ApplicationRecord
time <=> other.time
end
def serializable_hash(options = {})
super(options).merge('rendered_abstract' => markdown(abstract))
end
private
##

View file

@ -55,16 +55,19 @@ class EventSchedule < ApplicationRecord
# True within `threshold` before and after the event.
#
def happening_now?(threshold = 30.minutes)
# TODO: Save start_time with local timezone info when making an event schedule
in_tz_start = start_time.in_time_zone(timezone)
in_tz_end = end_time.in_time_zone(timezone)
in_tz_start -= in_tz_start.utc_offset
in_tz_end -= in_tz_end.utc_offset
return false if in_tz_end < Time.now
begin_range = Time.now - threshold
end_range = Time.now + threshold
event_time_range = in_tz_start..in_tz_end
now_range = begin_range..end_range
# TODO: There's probably better logic.
event_time_range.overlaps?(now_range) && (in_tz_end > Time.now)
event_time_range.overlaps?(now_range)
end
def self.withdrawn_or_canceled_event_schedules(schedule_ids)

View file

@ -195,6 +195,7 @@ class Program < ApplicationRecord
# * +True+ -> If there is any event for the given date
# * +False+ -> If there is not any event for the given date
def any_event_for_this_date?(date)
return false if date.nil? || date == ''
return false unless selected_schedule.present?
parsed_date = DateTime.parse("#{date} 00:00").utc

View file

@ -11,6 +11,7 @@
# banner_photo_updated_at :datetime
# include_booths :boolean
# include_cfp :boolean default(FALSE)
# include_happening_now :boolean
# include_lodgings :boolean
# include_program :boolean
# include_registrations :boolean

View file

@ -53,6 +53,7 @@ class UserDisabled < StandardError
end
class User < ApplicationRecord
include TrackSavedChanges
rolify
# prevent N+1 queries with has_cached_role? by preloading roles *always*
default_scope { preload(:roles) }
@ -80,6 +81,12 @@ class User < ApplicationRecord
after_save :touch_events
# Note that using after_create_commit and after_update_commit does not work.
# See https://github.com/CactusPuppy/snapcon/pull/43#discussion_r609458034
after_commit :mailbluster_create_lead, on: :create
after_commit :mailbluster_delete_lead, on: :destroy
after_commit :mailbluster_update_lead, on: :update, if: ->(user){ ['name', 'email'].any? { |key| user.ts_saved_changes.key? key } }
# add scope
scope :comment_notifiable, ->(conference) {joins(:roles).where('roles.name IN (?)', [:organizer, :cfp]).where('roles.resource_type = ? AND roles.resource_id = ?', 'Conference', conference.id)}
@ -361,12 +368,32 @@ class User < ApplicationRecord
User.count == 1 && User.first.email == 'deleted@localhost.osem'
end
# TODO: email_hash function for mailbluster
# def email_hash
# Digest::MD5.hexdigest user.email
# end
private
def setup_role
self.is_admin = true if User.empty?
end
def mailbluster_create_lead
MailblusterCreateLeadJob.perform_later self
ts_reset_saved_changes
end
def mailbluster_delete_lead
MailblusterDeleteLeadJob.perform_later email
ts_reset_saved_changes
end
def mailbluster_update_lead
MailblusterEditLeadJob.perform_later(self, old_email: ts_saved_changes.fetch('email', [nil])[0])
ts_reset_saved_changes
end
def touch_events
event_users.each(&:touch)
end

View file

@ -0,0 +1,40 @@
class MailblusterManager
include HTTParty
base_uri 'https://api.mailbluster.com/api/leads/'
@auth_headers = {
headers: {
'Content-Type' => 'application/json',
'Authorization' => ENV['MAILBLUSTER_API_KEY']
}
}
def self.query_api(method, path, body: {})
options = @auth_headers.merge(body: body.to_json)
send(method, path, options).parsed_response
end
def self.create_lead(user)
query_api(:post, '/', body: {
'email' => user.email,
'firstName' => user.name,
'overrideExisting' => true,
'subscribed' => true,
'tags' => [ENV['OSEM_NAME'] || 'snapcon']
})
end
def self.edit_lead(user, add_tags: [], remove_tags: [], old_email: nil)
email_hash = Digest::MD5.hexdigest(old_email.presence || user.email)
query_api(:put, "/#{email_hash}", body: {
'email' => user.email,
'firstName' => user.name,
'addTags' => add_tags,
'removeTags' => remove_tags
})
end
def self.delete_lead(email)
email_hash = Digest::MD5.hexdigest email
query_api(:delete, "/#{email_hash}")
end
end

View file

@ -20,7 +20,7 @@
combined_data: @registration_distribution
.row
.col-md-12
%div.margin-event-table
.margin-event-table
%table.datatable#registrations{ data: { source: admin_conference_registrations_path(conference_id: @conference, format: :json) } }
%thead
%tr

View file

@ -25,6 +25,8 @@
= f.input :include_tracks, label: 'Include confirmed tracks', input_html: { checked: params[:action] == 'new' || @splashpage.try(:include_tracks) }
%li
= f.input :include_booths, label: "Include confirmed #{(t'booth').pluralize}", input_html: { checked: params[:action] == 'new' || @splashpage.try(:include_booths) }
%li
= f.input :include_happening_now, label: 'Include events happening now', input_html: { checked: params[:action] == 'new' || @splashpage.try(:include_happening_now) }
%li
= f.input :include_registrations, label: 'Display the registration period', input_html: { checked: params[:action] == 'new' || @splashpage.try(:include_registrations) }

View file

@ -27,6 +27,9 @@
%li
%i{ class: "fa-li #{icon_for_todo @splashpage.include_booths?}" }
Include confirmed #{(t'booth').pluralize}
%li
%i{ class: "fa-li #{icon_for_todo @splashpage.include_happening_now?}" }
Include events happening now
%li
%i{ class: "fa-li #{icon_for_todo @splashpage.include_registrations?}" }
Display the registration period

View file

@ -0,0 +1,32 @@
= content_for :happening_now do
#happening-now
= render 'happening_now', conference: conference,
events_schedules: events_schedules, pagy: pagy,
events_schedules_length: events_schedules_length,
events_schedules_limit: events_schedules_limit
= content_for :about do
#about
.row
%h2.text-left{ style: 'margin-bottom:30px' } About the Conference
= markdown(conference.description, false)
%section#about-and-happening-now
.container
.row
-# happening now events are displayed second in md or lg view
- if conference.splashpage.include_happening_now && conference.splashpage.include_program
- if conference.description.present?
.col-md-6.col-md-push-6.col-lg-4.col-lg-push-8
= yield :happening_now
- else
.col-md-12
= yield :happening_now
- if conference.description.present?
- if conference.splashpage.include_happening_now && conference.splashpage.include_program
.col-md-6.col-md-pull-6.col-lg-8.col-lg-pull-4
= yield :about
- else
.col-md-12
= yield :about
.trapezoid

View file

@ -0,0 +1,12 @@
- if conference.splashpage.include_program && conference.splashpage.include_happening_now
- if events_schedules.any?
.row
%h2.text-center{ style: 'margin-bottom:30px' } Happening Now
- events_schedules.each do |event_schedule|
= render 'schedules/event', conference: conference, event_schedule: event_schedule, event: event_schedule.event, is_brief: true
- if events_schedules_length > events_schedules_limit
.container{ style: 'width:100%; text-align:center' }
!= pagy_bootstrap_nav_js(pagy)
- else
.row
%h3.text-center There are no events happening now.

View file

@ -26,11 +26,3 @@
- if venue.country != 'US'
&bull;
= venue.country_name
- unless conference.description.blank?
%section#about
.container
.row
.col-md-8.col-md-offset-2
= markdown(conference.description, escape_html=false)
.trapezoid

View file

@ -41,9 +41,16 @@
- if @conference.code_of_conduct.present?
= render 'code_of_conduct', organization: @conference.organization
-# header/description
-# header
= render 'header', conference: @conference, venue: @conference.venue
-# description / happening now
- if @conference.splashpage.include_happening_now? || @conference.description.present?
= render 'about_and_happening_now', conference: @conference,
events_schedules: @events_schedules, pagy: @pagy,
events_schedules_length: @events_schedules_length,
events_schedules_limit: @events_schedules_limit
-# calls for content, or program
- if @conference.splashpage.include_cfp
= render 'call_for_content', conference: @conference,

View file

@ -0,0 +1,5 @@
$('#happening-now').html("<%= j(render 'happening_now', conference: @conference,
events_schedules: @events_schedules, pagy: @pagy,
events_schedules_length: @events_schedules_length,
events_schedules_limit: @events_schedules_limit)%>");
Pagy.init(document.getElementById('happening-now'));

View file

@ -4,7 +4,7 @@
.panel.panel-default
.panel-heading
%h3.panel-title
Resend confirmation instructions
Resend account confirmation instructions
.panel-body
= semantic_form_for(resource, as: resource_name, url: confirmation_path(resource_name), method: :post) do |f|
= f.input :email, input_html: { autofocus: true, required: true }

View file

@ -0,0 +1,9 @@
<%= render partial: "layouts/mailbot_header" %>
<div id="content">
<p>Welcome to Snap!Con <%= @email %>!</p>
<p>You can confirm your account email through the link below:</p>
<p><%= link_to 'Confirm my account', confirmation_url(@resource, confirmation_token: @token) %></p>
</div>
<%= render partial: "layouts/mailbot_footer" %>

View file

@ -0,0 +1,7 @@
<p>Hello <%= @email %>!</p>
<% if @resource.try(:unconfirmed_email?) %>
<p>We're contacting you to notify you that your email is being changed to <%= @resource.unconfirmed_email %>.</p>
<% else %>
<p>We're contacting you to notify you that your email has been changed to <%= @resource.email %>.</p>
<% end %>

View file

@ -0,0 +1,3 @@
<p>Hello <%= @resource.email %>!</p>
<p>We're contacting you to notify you that your password has been changed.</p>

View file

@ -0,0 +1,8 @@
<p>Hello <%= @resource.email %>!</p>
<p>Someone has requested a link to change your password. You can do this through the link below.</p>
<p><%= link_to 'Change my password', edit_password_url(@resource, reset_password_token: @token) %></p>
<p>If you didn't request this, please ignore this email.</p>
<p>Your password won't change until you access the link above and create a new one.</p>

View file

@ -0,0 +1,7 @@
<p>Hello <%= @resource.email %>!</p>
<p>Your account has been locked due to an excessive number of unsuccessful sign in attempts.</p>
<p>Click the link below to unlock your account:</p>
<p><%= link_to 'Unlock my account', unlock_url(@resource, unlock_token: @token) %></p>

View file

@ -1,12 +1,7 @@
<html lang="en">
<head>
<meta charset="utf-8"/>
<meta content="width=device-width, initial-scale=1" name="viewport"/>
<meta content="Snap!Con -- A conference all about Snap!, a programing language from UC Berkeley." name="description"/>
<meta content="Michael Ball, Brian Harvey, Jens Moenig, Bernat Romagosa, Dan Garcia, Lauren Mock" name="author"/>
<%= stylesheet_link_tag "mailbot" %>
</head>
<body>
<div id="border" style="background-color: <%= conference_color(@conference) %>"></div>
<% if @conference.present? %>
<div id="border" style="background-color: <%= conference_color(@conference) %>">
<% else %>
<div id="border" style="background-color: #003262">
<% end %>
</body>
</html>
</html>

View file

@ -9,17 +9,21 @@
<meta content="Michael Ball, Brian Harvey, Jens Moenig, Bernat Romagosa, Dan Garcia, Lauren Mock" name="author"/>
<%= stylesheet_link_tag "mailbot" %>
</head>
<body>
<div id="border" style="background-color: <%= conference_color(@conference) %>">
<body>
<% if @conference.present? %>
<div id="border" style="background-color: <%= conference_color(@conference) %>">
<% else %>
<div id="border" style="background-color: #003262">
<% end %>
<div class="row">
<div class="col-md-2">
<% if @conference.present? %>
<%= image_tag(conference_logo_url(@conference), style: "display:block;height:70px;width:auto;", alt: @conference.title + ' logo') %>
<% else %>
<%= image_tag(Organization.first.picture_url, style: "display:block;height:70px;width:auto;", alt: ENV['OSEM_NAME'] + ' logo') %>
<% end %>
</div>
</div>
</div>
</body>

View file

@ -2,12 +2,18 @@
.row
.col-xs-6.col-xs-offset-3
%h1
Payment Summary :
Payment Summary :
= humanized_money_with_symbol @total_amount_to_pay
.col-xs-8.col-xs-offset-2.well
= render partial: 'payment'
.row
.col-md-13
%p.text-center
%strong
If you do not have a credit card, please reach out to use at
= mail_to(@conference.contact.email)
%hr
%p.text-muted.text-center
%small
All payments are handled securely by our payment processor,

View file

@ -2,8 +2,9 @@
- header_color = event.event_type&.color || '#f5f5f5'
.trapezoid{ style: 'color: white; top: 12px; z-index: 100;' }
.panel-heading{ style: "background-color: #{header_color}; color: #{ contrast_color(header_color) }; border-radius: 4px" }
- event.speakers_ordered.each do |speaker|
= image_tag speaker.profile_picture, class: 'img-circle pull-right', alt: speaker.name, style: 'padding: 2px;'
- if !defined?(is_brief) || is_brief == false
- event.speakers_ordered.each do |speaker|
= image_tag speaker.profile_picture, class: 'img-circle pull-right', alt: speaker.name, style: 'padding: 2px;'
%p
= canceled_replacement_event_label(event, event_schedule)
@ -14,7 +15,8 @@
%br
%small{ style: "color: #{contrast_color(header_color)}" }
= event.subtitle
.trapezoid{ style: "color: #{header_color}; top: 12px;" }
.trapezoid{ style: "color: #{header_color}; border-top-color: #{header_color}; top: 12px;" }
.panel-body
%h4
@ -26,20 +28,21 @@
= markdown(truncate(event.abstract, length: 400))
-# TODO: More informative text or aria-label.
= link_to 'more', conference_program_proposal_path(@conference.short_title, event.id) if event.abstract.length > 400
- if event_schedule.present?
= inyourtz(event_schedule.start_time) do
- if !defined?(is_brief) || is_brief == false
- if event_schedule.present?
= inyourtz(event_schedule.start_time) do
%span.track
%span.fa.fa-clock-o
%span.label{ style: 'background-color: grey' }
= event_schedule.start_time.strftime('%l:%M %P')
\-
= event_schedule.end_time.strftime('%l:%M %P')
%span.track
%span.fa.fa-clock-o
%span.fa.fa-map-marker
%span.label{ style: 'background-color: grey' }
= event_schedule.start_time.strftime('%l:%M %P')
\-
= event_schedule.end_time.strftime('%l:%M %P')
%span.track
%span.fa.fa-map-marker
%span.label{ style: 'background-color: grey' }
= event_schedule.room.name
- if event.track
%span.track
%span.fa.fa-road
%span.label{ style: "background-color: #{event.track.color}; color: #{ contrast_color(event.track.color) }" }
= event.track.name
= event_schedule.room.name
- if event.track
%span.track
%span.fa.fa-road
%span.label{ style: "background-color: #{event.track.color}; color: #{ contrast_color(event.track.color) }" }
= event.track.name