Rebuild rubocop TODOs after auto-correcting

This commit is contained in:
James Mason 2018-04-04 10:18:51 -07:00
parent 31c50255e9
commit 84dbb52d11
No known key found for this signature in database
GPG key ID: 1B3951886C449023
580 changed files with 3689 additions and 3133 deletions

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Admin
class BaseController < ApplicationController
before_action :verify_user_admin
@ -9,7 +11,7 @@ module Admin
end
def verify_user_admin
if (current_user.nil?)
if current_user.nil?
redirect_to sign_in_path
return false
end
@ -17,7 +19,7 @@ module Admin
(current_user.has_cached_role? :info_desk, :any) || (current_user.has_cached_role? :organization_admin, :any) ||
(current_user.has_cached_role? :volunteers_coordinator, :any) ||
(current_user.has_cached_role? :track_organizer, :any) || current_user.is_admin
raise CanCan::AccessDenied.new('You are not authorized to access this page.')
raise CanCan::AccessDenied, 'You are not authorized to access this page.'
end
end
end

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Admin
class BoothsController < Admin::BaseController
load_and_authorize_resource :conference, find_by: :short_title
@ -51,7 +53,7 @@ module Admin
def update
@url = admin_conference_booth_path(@conference.short_title, @booth.id)
@booth.update_attributes(booth_params)
@booth.update(booth_params)
if @booth.save
redirect_to admin_conference_booths_path,
@ -67,9 +69,7 @@ module Admin
@booth.accept!
if @booth.save
if @conference.email_settings.send_on_booths_acceptance
Mailbot.conference_booths_acceptance_mail(@booth).deliver
end
Mailbot.conference_booths_acceptance_mail(@booth).deliver if @conference.email_settings.send_on_booths_acceptance
redirect_to admin_conference_booths_path(conference_id: @conference.short_title),
notice: 'Booth successfully accepted!'
else

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Admin
class CampaignsController < Admin::BaseController
load_and_authorize_resource :conference, find_by: :short_title
@ -25,7 +27,7 @@ module Admin
def edit; end
def update
if @campaign.update_attributes(campaign_params)
if @campaign.update(campaign_params)
redirect_to admin_conference_campaigns_path(conference_id: @conference.short_title),
notice: "Campaign '#{@campaign.name}' successfully updated."
else

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Admin
class CfpsController < Admin::BaseController
load_and_authorize_resource :conference, find_by: :short_title
@ -33,7 +35,7 @@ module Admin
send_mail_on_cfp_dates_updates = @cfp.notify_on_cfp_date_update?
if @cfp.update_attributes(cfp_params)
if @cfp.update(cfp_params)
ConferenceCfpUpdateMailJob.perform_later(@conference) if send_mail_on_cfp_dates_updates
redirect_to admin_conference_program_cfps_path(@conference.short_title),
notice: 'Call for papers successfully updated.'

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Admin
class CommentsController < Admin::BaseController
load_and_authorize_resource
@ -20,9 +22,9 @@ module Admin
Comment.accessible_by(current_ability).joins('INNER JOIN events ON commentable_id = events.id').order('events.title', 'comments.created_at DESC')
end
# Grouping all comments by conference, and by event. It returns {:conference => {:event => [{comment_2}, {comment_1 }]}}
# Grouping all comments by conference, and by event. It returns {:conference => {:event => [{comment_2}, {comment_1 }]}}
def grouped_comments(remarks)
remarks.group_by{ |comment| comment.commentable.program.conference }.map {|conference, comments| [conference, comments.group_by{|comment| comment.commentable}]}.to_h
remarks.group_by { |comment| comment.commentable.program.conference }.map { |conference, comments| [conference, comments.group_by(&:commentable)] }.to_h
end
end
end

View file

@ -1,7 +1,9 @@
# frozen_string_literal: true
module Admin
class CommercialsController < Admin::BaseController
load_and_authorize_resource :conference, find_by: :short_title
load_and_authorize_resource through: :conference, except: [:new, :create]
load_and_authorize_resource through: :conference, except: %i[new create]
def index
@commercials = @conference.commercials
@ -43,7 +45,7 @@ module Admin
def render_commercial
result = Commercial.render_from_url(params[:url])
if result[:error]
render text: result[:error], status: 400
render text: result[:error], status: :bad_request
else
render text: result[:html]
end

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Admin
class ConferencesController < Admin::BaseController
load_and_authorize_resource :conference, find_by: :short_title
@ -22,11 +24,11 @@ module Admin
@total_withdrawn = Event.where(state: :withdrawn).count
@new_withdrawn = Event
.where('state = ? and created_at > ?', 'withdrawn', current_user.last_sign_in_at).count
.where('state = ? and created_at > ?', 'withdrawn', current_user.last_sign_in_at).count
@active_conferences = Conference.get_active_conferences_for_dashboard # pending or the last two
@deactive_conferences = Conference
.get_conferences_without_active_for_dashboard(@active_conferences) # conferences without active
.get_conferences_without_active_for_dashboard(@active_conferences) # conferences without active
@conferences = @active_conferences + @deactive_conferences
@recent_users = User.limit(5).order(created_at: :desc)
@ -99,7 +101,7 @@ module Admin
@conference.assign_attributes(conference_params)
send_mail_on_conf_update = @conference.notify_on_dates_changed?
if @conference.update_attributes(conference_params)
if @conference.update(conference_params)
ConferenceDateUpdateMailJob.perform_later(@conference) if send_mail_on_conf_update
redirect_to edit_admin_conference_path(id: @conference.short_title),
notice: 'Conference was successfully updated.'
@ -121,7 +123,7 @@ module Admin
@total_submissions = @all_events.count
@new_submissions = @all_events
.where('created_at > ?', current_user.last_sign_in_at).count
.where('created_at > ?', current_user.last_sign_in_at).count
@program_length = @conference.current_program_hours
@new_program_length = @conference.new_program_hours(current_user.last_sign_in_at)
@ -136,7 +138,7 @@ module Admin
@conference_progress = @conference.get_status
# Line charts
@registrations = {@conference.short_title => @conference.get_registrations_per_week}
@registrations = { @conference.short_title => @conference.get_registrations_per_week }
@registration_weeks = [0]
@registration_weeks.push(@registrations[@conference.short_title].length)
@ -173,9 +175,9 @@ module Admin
@difficulty_levels_distribution = @conference.difficulty_levels_distribution
@difficulty_levels_distribution_confirmed = @conference
.difficulty_levels_distribution(:confirmed)
.difficulty_levels_distribution(:confirmed)
@difficulty_levels_distribution_withdrawn = @conference
.difficulty_levels_distribution(:withdrawn)
.difficulty_levels_distribution(:withdrawn)
@tracks_distribution = @conference.tracks_distribution
@tracks_distribution_confirmed = @conference.tracks_distribution(:confirmed)

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Admin
class ContactsController < Admin::BaseController
load_and_authorize_resource :conference, find_by: :short_title

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Admin
class DifficultyLevelsController < Admin::BaseController
load_and_authorize_resource :conference, find_by: :short_title
@ -5,7 +7,7 @@ module Admin
load_and_authorize_resource through: :program
def index
# authorize! :index, DifficultyLevel.new(program_id: @program.id)
# authorize! :index, DifficultyLevel.new(program_id: @program.id)
end
def edit; end
@ -26,7 +28,7 @@ module Admin
end
def update
if @difficulty_level.update_attributes(difficulty_level_params)
if @difficulty_level.update(difficulty_level_params)
redirect_to admin_conference_program_difficulty_levels_path(conference_id: @conference.short_title),
notice: 'Difficulty level successfully updated.'
else

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Admin
class EmailsController < Admin::BaseController
load_and_authorize_resource :conference, find_by: :short_title
@ -6,11 +8,13 @@ module Admin
def update
if @conference.email_settings.update(email_params)
redirect_to admin_conference_emails_path(
@conference.short_title),
@conference.short_title
),
notice: 'Email settings have been successfully updated.'
else
redirect_to admin_conference_emails_path(
@conference.short_title),
@conference.short_title
),
error: "Updating email settings failed. #{@conference.email_settings.errors.to_a.join('. ')}."
end
end

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Admin
class EventSchedulesController < Admin::BaseController
load_and_authorize_resource :event_schedule
@ -6,7 +8,7 @@ module Admin
if @event_schedule.save
render json: { event_schedule_id: @event_schedule.id }
else
render json: { errors: "The event couldn't be scheduled. #{@event_schedule.errors.full_messages.join('. ')}" }, status: 422
render json: { errors: "The event couldn't be scheduled. #{@event_schedule.errors.full_messages.join('. ')}" }, status: :unprocessable_entity
end
end
@ -14,7 +16,7 @@ module Admin
if @event_schedule.update(event_schedule_params)
render json: { event_schedule_id: @event_schedule.id }
else
render json: { errors: "The event couldn't be scheduled. #{@event_schedule.errors.full_messages.join('. ')}" }, status: 422
render json: { errors: "The event couldn't be scheduled. #{@event_schedule.errors.full_messages.join('. ')}" }, status: :unprocessable_entity
end
end
@ -22,7 +24,7 @@ module Admin
if @event_schedule.destroy
render json: {}
else
render json: { errors: "The event couldn't be unscheduled. #{@event_schedule.errors.full_messages.join('. ')}" }, status: 422
render json: { errors: "The event couldn't be unscheduled. #{@event_schedule.errors.full_messages.join('. ')}" }, status: :unprocessable_entity
end
end

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Admin
class EventTypesController < Admin::BaseController
load_and_authorize_resource :conference, find_by: :short_title
@ -24,7 +26,7 @@ module Admin
end
def update
if @event_type.update_attributes(event_type_params)
if @event_type.update(event_type_params)
redirect_to admin_conference_program_event_types_path(conference_id: @conference.short_title),
notice: 'Event type successfully updated.'
else

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Admin
class EventsController < Admin::BaseController
load_and_authorize_resource :conference, find_by: :short_title
@ -7,7 +9,7 @@ module Admin
# For some reason this doesn't work, so a workaround is used
# load_and_authorize_resource :track, through: :program, only: [:index, :show, :edit]
before_action :assign_tracks, only: [:index, :show, :edit]
before_action :assign_tracks, only: %i[index show edit]
def index
@difficulty_levels = @program.difficulty_levels
@ -17,7 +19,7 @@ module Admin
@scheduled_event_distribution = @conference.scheduled_event_distribution
@file_name = "events_for_#{@conference.short_title}"
@event_export_option = params[:event_export_option]
@export_formats = [:pdf, :csv, :xlsx]
@export_formats = %i[pdf csv xlsx]
respond_to do |format|
format.html
@ -69,7 +71,7 @@ module Admin
def update
@languages = @program.languages_list
if @event.update_attributes(event_params)
if @event.update(event_params)
if request.xhr?
render js: 'index'
@ -139,8 +141,8 @@ module Admin
def vote
@votes = @event.votes.includes(:user)
if (votes = current_user.votes.find_by_event_id(params[:id]))
votes.update_attributes(rating: params[:rating])
if (votes = current_user.votes.find_by(event_id: params[:id]))
votes.update(rating: params[:rating])
else
@myvote = @event.votes.build
@myvote.user = current_user
@ -172,13 +174,14 @@ module Admin
def event_params
params.require(:event).permit(
# Set also in proposals controller
:title, :subtitle, :event_type_id, :abstract, :description, :require_registration, :difficulty_level_id,
# Set only in admin/events controller
:track_id, :state, :language, :is_highlight, :max_attendees,
# Not used anymore?
:proposal_additional_speakers, :user, :users_attributes,
speaker_ids: [])
# Set also in proposals controller
:title, :subtitle, :event_type_id, :abstract, :description, :require_registration, :difficulty_level_id,
# Set only in admin/events controller
:track_id, :state, :language, :is_highlight, :max_attendees,
# Not used anymore?
:proposal_additional_speakers, :user, :users_attributes,
speaker_ids: []
)
end
def comment_params

View file

@ -1,10 +1,11 @@
# frozen_string_literal: true
module Admin
class LodgingsController < Admin::BaseController
load_and_authorize_resource :conference, find_by: :short_title
load_and_authorize_resource :lodging, through: :conference
def index
end
def index; end
def new
@lodging = @conference.lodgings.new
@ -24,7 +25,7 @@ module Admin
def edit; end
def update
if @lodging.update_attributes(lodging_params)
if @lodging.update(lodging_params)
redirect_to admin_conference_lodgings_path(conference_id: @conference.short_title),
notice: 'Lodging successfully updated.'
else

View file

@ -1,7 +1,9 @@
# frozen_string_literal: true
module Admin
class OrganizationsController < Admin::BaseController
load_and_authorize_resource :organization
before_action :verify_user, only: [:assign_org_admins, :unassign_org_admins]
before_action :verify_user, only: %i[assign_org_admins unassign_org_admins]
def index
@organizations = Organization.all
@ -25,7 +27,7 @@ module Admin
def edit; end
def update
if @organization.update_attributes(organization_params)
if @organization.update(organization_params)
redirect_to admin_organizations_path,
notice: 'Organization successfully updated'
else

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Admin
class PhysicalTicketsController < Admin::BaseController
before_action :authenticate_user!

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Admin
class ProgramsController < Admin::BaseController
load_and_authorize_resource :conference, find_by: :short_title
@ -14,7 +16,7 @@ module Admin
send_mail_on_schedule_public = @program.notify_on_schedule_public?
event_schedules_count_was = @program.event_schedules.count
if @program.update_attributes(program_params)
if @program.update(program_params)
ConferenceScheduleUpdateMailJob.perform_later(@conference) if send_mail_on_schedule_public
respond_to do |format|
format.html do
@ -30,7 +32,7 @@ module Admin
flash.now[:error] = "Updating program failed. #{@program.errors.to_a.join('. ')}."
render :new
end
format.js { render json: { errors: "The selected schedule couldn't be updated #{@program.errors.to_a.join('. ')}" }, status: 422 }
format.js { render json: { errors: "The selected schedule couldn't be updated #{@program.errors.to_a.join('. ')}" }, status: :unprocessable_entity }
end
end
end

View file

@ -1,7 +1,9 @@
# frozen_string_literal: true
module Admin
class QuestionsController < Admin::BaseController
load_and_authorize_resource :conference, find_by: :short_title
load_and_authorize_resource through: :conference, except: [:new, :create]
load_and_authorize_resource through: :conference, except: %i[new create]
def index
authorize! :index, Question.new(conference_id: @conference.id)
@ -24,9 +26,7 @@ module Admin
@question.conference_id = @conference.id
authorize! :create, @question
if @question.question_type_id == QuestionType.find_by(title: 'Yes/No').id
@question.answers = [Answer.find_by(title: 'Yes'), Answer.find_by(title: 'No')]
end
@question.answers = [Answer.find_by(title: 'Yes'), Answer.find_by(title: 'No')] if @question.question_type_id == QuestionType.find_by(title: 'Yes/No').id
respond_to do |format|
if @conference.save
@ -39,14 +39,12 @@ module Admin
# GET questions/1/edit
def edit
if @question.global
redirect_to admin_conference_questions_path(conference_id: @conference.short_title), error: 'Sorry, you cannot edit global questions. Create a new one.'
end
redirect_to admin_conference_questions_path(conference_id: @conference.short_title), error: 'Sorry, you cannot edit global questions. Create a new one.' if @question.global
end
# PUT questions/1
def update
if @question.update_attributes(question_params)
if @question.update(question_params)
redirect_to admin_conference_questions_path(conference_id: @conference.short_title), notice: "Question '#{@question.title}' for #{@conference.short_title} successfully updated."
else
redirect_to admin_conference_questions_path(conference_id: @conference.short_title), notice: "Update of questions for #{@conference.short_title} failed. #{@question.errors.full_messages.join('. ')}"
@ -56,7 +54,7 @@ module Admin
# Update questions used for the conference
def update_conference
authorize! :update, Question.new(conference_id: @conference.id)
if @conference.update_attributes(conference_params)
if @conference.update(conference_params)
redirect_to admin_conference_questions_path(conference_id: @conference.short_title), notice: "Questions for #{@conference.short_title} successfully updated."
else
redirect_to admin_conference_questions_path(conference_id: @conference.short_title), notice: "Update of questions for #{@conference.short_title} failed."
@ -73,12 +71,9 @@ module Admin
# Delete question and its answers
begin
Question.transaction do
@question.destroy
@question.answers.each do |a|
a.destroy
end
flash[:notice] = "Deleted question: #{@question.title} and its answers: #{@question.answers.map {|a| a.title}.join ','}"
@question.answers.each(&:destroy)
flash[:notice] = "Deleted question: #{@question.title} and its answers: #{@question.answers.map(&:title).join ','}"
end
rescue ActiveRecord::RecordInvalid
flash[:error] = 'Could not delete question.'
@ -95,7 +90,7 @@ module Admin
private
def question_params
params.require(:question).permit(:title, :global, :answer_ids, :question_type_id, :conference_id, answers_attributes: [:id, :title])
params.require(:question).permit(:title, :global, :answer_ids, :question_type_id, :conference_id, answers_attributes: %i[id title])
end
def conference_params

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Admin
class RegistrationPeriodsController < Admin::BaseController
load_and_authorize_resource :conference, find_by: :short_title
@ -21,11 +23,9 @@ module Admin
end
end
def edit
end
def edit; end
def show
end
def show; end
def update
@registration_period.assign_attributes(registration_period_params)

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Admin
class RegistrationsController < Admin::BaseController
load_and_authorize_resource :conference, find_by: :short_title
@ -17,9 +19,9 @@ module Admin
def edit; end
def update
@user.update_attributes(user_params)
@user.update(user_params)
@registration.update_attributes(registration_params)
@registration.update(registration_params)
if @registration.save
redirect_to admin_conference_registrations_path(@conference.short_title),
notice: "Successfully updated registration for #{@registration.user.email}!"

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Admin
class ReportsController < Admin::BaseController
load_and_authorize_resource :conference, find_by: :short_title
@ -13,9 +15,9 @@ module Admin
attended_registrants_ids = @conference.registrations.where(attended: true).pluck(:user_id)
@missing_event_speakers = EventUser.joins(:event)
.where('event_role = ? and program_id = ?', 'submitter', @program.id)
.where.not(user_id: attended_registrants_ids)
.includes(:user, :event)
.where('event_role = ? and program_id = ?', 'submitter', @program.id)
.where.not(user_id: attended_registrants_ids)
.includes(:user, :event)
end
end
end

View file

@ -1,7 +1,9 @@
# frozen_string_literal: true
module Admin
class ResourcesController < Admin::BaseController
load_and_authorize_resource :conference, find_by: :short_title
load_and_authorize_resource :resource, only: [:show, :edit, :update, :destroy]
load_and_authorize_resource :resource, only: %i[show edit update destroy]
def index; end
@ -23,7 +25,7 @@ module Admin
end
def update
if @resource.update_attributes(resource_params)
if @resource.update(resource_params)
redirect_to admin_conference_resources_path(conference_id: @conference.short_title),
notice: 'Resource successfully updated.'
else

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Admin
class RolesController < Admin::BaseController
load_and_authorize_resource :conference, find_by: :short_title
@ -34,7 +36,7 @@ module Admin
def update
role_name = @role.name
if @role.update_attributes(role_params)
if @role.update(role_params)
url = if @track
admin_conference_program_track_role_path(@conference.short_title, @track, @role.name)
else

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Admin
class RoomsController < Admin::BaseController
load_and_authorize_resource :conference, find_by: :short_title
@ -24,7 +26,7 @@ module Admin
end
def update
if @room.update_attributes(room_params)
if @room.update(room_params)
redirect_to admin_conference_venue_rooms_path(conference_id: @conference.short_title),
notice: 'Room successfully updated.'
else

View file

@ -1,10 +1,12 @@
# frozen_string_literal: true
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
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: [:new, :create]
load_and_authorize_resource :schedule, through: :program, except: %i[new create]
load_resource :event_schedules, through: :schedule
load_resource :selected_schedule, through: :program, singleton: true
load_resource :venue, through: :conference, singleton: true

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Admin
class SplashpagesController < Admin::BaseController
load_and_authorize_resource :conference, find_by: :short_title
@ -23,7 +25,7 @@ module Admin
end
def update
if @splashpage.update_attributes(splashpage_params)
if @splashpage.update(splashpage_params)
redirect_to admin_conference_splashpage_path,
notice: 'Splashpage successfully updated.'
else

View file

@ -1,8 +1,10 @@
# frozen_string_literal: true
module Admin
class SponsorsController < Admin::BaseController
load_and_authorize_resource :conference, find_by: :short_title
load_and_authorize_resource :sponsor, through: :conference
before_action :sponsorship_level_required, only: [:index, :new]
before_action :sponsorship_level_required, only: %i[index new]
def index
authorize! :index, Sponsor.new(conference_id: @conference.id)
@ -26,9 +28,10 @@ module Admin
end
def update
if @sponsor.update_attributes(sponsor_params)
if @sponsor.update(sponsor_params)
redirect_to admin_conference_sponsors_path(
conference_id: @conference.short_title),
conference_id: @conference.short_title
),
notice: 'Sponsor successfully updated.'
else
flash.now[:error] = "Update sponsor failed: #{@sponsor.errors.full_messages.join('. ')}."

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Admin
class SponsorshipLevelsController < Admin::BaseController
load_and_authorize_resource :conference, find_by: :short_title
@ -25,9 +27,10 @@ module Admin
end
def update
if @sponsorship_level.update_attributes(sponsorship_level_params)
if @sponsorship_level.update(sponsorship_level_params)
redirect_to admin_conference_sponsorship_levels_path(
conference_id: @conference.short_title),
conference_id: @conference.short_title
),
notice: 'Sponsorship level successfully updated.'
else
flash.now[:error] = "Update Sponsorship level failed: #{@sponsorship_level.errors.full_messages.join('. ')}."

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Admin
class TargetsController < Admin::BaseController
load_and_authorize_resource :conference, find_by: :short_title
@ -23,7 +25,7 @@ module Admin
def edit; end
def update
if @target.update_attributes(target_params)
if @target.update(target_params)
redirect_to admin_conference_targets_path(conference_id: @conference.short_title),
notice: 'Target successfully updated.'
else

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Admin
class TicketScanningsController < Admin::BaseController
before_action :authenticate_user!

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Admin
class TicketsController < Admin::BaseController
load_and_authorize_resource :conference, find_by: :short_title
@ -27,7 +29,7 @@ module Admin
def edit; end
def update
if @ticket.update_attributes(ticket_params)
if @ticket.update(ticket_params)
redirect_to admin_conference_tickets_path(conference_id: @conference.short_title),
notice: 'Ticket successfully updated.'
else

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Admin
class TracksController < Admin::BaseController
load_and_authorize_resource :conference, find_by: :short_title
@ -54,7 +56,7 @@ module Admin
def edit; end
def update
if @track.update_attributes(track_params)
if @track.update(track_params)
redirect_to admin_conference_program_tracks_path(conference_id: @conference.short_title),
notice: 'Track successfully updated.'
else
@ -120,13 +122,13 @@ module Admin
end
def update_selected_schedule
if @track.update_attributes(params.require(:track).permit(:selected_schedule_id))
if @track.update(params.require(:track).permit(:selected_schedule_id))
respond_to do |format|
format.js { render json: {} }
end
else
respond_to do |format|
format.js { render json: { errors: "The selected schedule couldn't be updated #{@track.errors.to_a.join('. ')}" }, status: 422 }
format.js { render json: { errors: "The selected schedule couldn't be updated #{@track.errors.to_a.join('. ')}" }, status: :unprocessable_entity }
end
end
end

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Admin
class UsersController < Admin::BaseController
load_and_authorize_resource
@ -36,9 +38,9 @@ module Admin
# Variable @show_attributes holds the attributes that are visible for the 'show' action
# If you want to change the attributes that are shown in the 'show' action of users
# add/remove the attributes in the following string array
@show_attributes = %w(name email username nickname affiliation biography registered attended roles created_at
@show_attributes = %w[name email username nickname affiliation biography registered attended roles created_at
updated_at sign_in_count current_sign_in_at last_sign_in_at
current_sign_in_ip last_sign_in_ip)
current_sign_in_ip last_sign_in_ip]
end
def update
@ -49,7 +51,7 @@ module Admin
end
end
if @user.update_attributes(user_params)
if @user.update(user_params)
redirect_to admin_users_path, notice: "Updated #{@user.name} (#{@user.email})!" + message
else
redirect_to admin_users_path, error: "Could not update #{@user.name} (#{@user.email}). #{@user.errors.full_messages.join('. ')}."

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Admin
class VenueCommercialsController < Admin::BaseController
load_and_authorize_resource :conference, find_by: :short_title
@ -38,7 +40,7 @@ module Admin
def render_commercial
result = Commercial.render_from_url(params[:url])
if result[:error]
render text: result[:error], status: 400
render text: result[:error], status: :bad_request
else
render text: result[:html]
end

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Admin
class VenuesController < Admin::BaseController
load_and_authorize_resource :conference, find_by: :short_title
@ -23,7 +25,7 @@ module Admin
end
def update
if @venue.update_attributes(venue_params)
if @venue.update(venue_params)
redirect_to admin_conference_venue_path(conference_id: @conference.short_title),
notice: 'Venue was successfully updated.'
else

View file

@ -1,14 +1,14 @@
# frozen_string_literal: true
module Admin
class VersionsController < Admin::BaseController
load_resource :conference, find_by: :short_title, only: :index
load_and_authorize_resource class: PaperTrail::Version
def index
@conferences_with_role = current_user.is_admin? ? Conference.pluck(:short_title) : Conference.with_role([:organizer, :cfp, :info_desk], current_user).pluck(:short_title)
@conferences_with_role = current_user.is_admin? ? Conference.pluck(:short_title) : Conference.with_role(%i[organizer cfp info_desk], current_user).pluck(:short_title)
if current_user.has_cached_role? :organization_admin, :any
@conferences_with_role = Organization.with_role('organization_admin', current_user).map { |org| org.conferences.pluck :short_title }.flatten
end
@conferences_with_role = Organization.with_role('organization_admin', current_user).map { |org| org.conferences.pluck :short_title }.flatten if current_user.has_cached_role? :organization_admin, :any
@conferences_with_role.uniq!
return if @conference.blank?
@ -16,7 +16,7 @@ module Admin
end
def revert_attribute
if params[:attribute] && @version.changeset.reject{ |_, values| values[0].blank? && values[1].blank? }.keys.include?(params[:attribute])
if params[:attribute] && @version.changeset.reject { |_, values| values[0].blank? && values[1].blank? }.keys.include?(params[:attribute])
if @version.item[params[:attribute]] == @version.changeset[params[:attribute]][0]
flash[:error] = 'The item is already in the state that you are trying to revert it back to'

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Admin
class VolunteersController < Admin::BaseController
include VolunteersHelper
@ -24,7 +26,7 @@ module Admin
end
def update
if @conference.update_attributes(conference_params)
if @conference.update(conference_params)
redirect_to admin_conference_volunteers_info_path(conference_id: params[:conference_id]), notice: 'Volunteering options were successfully updated.'
else
redirect_to admin_conference_volunteers_info_path(conference_id: params[:conference_id]), error: "Volunteering options update failed: #{@conference.errors.full_messages.join '. '}"

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Api
class BaseController < ActionController::Base
protect_from_forgery with: :exception

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Api
module V1
class ConferencesController < Api::BaseController

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Api
module V1
class EventsController < Api::BaseController
@ -10,9 +12,7 @@ module Api
def index
events = Event.includes(:track, :event_type, event_users: :user)
if @conference
events = events.where(program: @conference.program)
end
events = events.where(program: @conference.program) if @conference
respond_with events.confirmed, callback: params[:callback]
end

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Api
module V1
class RoomsController < Api::BaseController

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Api
module V1
class SpeakersController < Api::BaseController
@ -9,13 +11,13 @@ module Api
def index
if @conference
users = User.joins(event_users: { event: { program: :conference} })
users = User.joins(event_users: { event: { program: :conference } })
users = users.where(conferences: { short_title: @conference.short_title })
else
users = User.joins(:event_users)
end
users = users.where(event_users: {event_role: :speaker}).uniq
users = users.where(event_users: { event_role: :speaker }).uniq
render json: users, each_serializer: SpeakerSerializer, callback: params['callback']
end
end

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Api
module V1
class TracksController < Api::BaseController

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
class ApplicationController < ActionController::Base
before_action :set_paper_trail_whodunnit
include ApplicationHelper
@ -11,24 +13,24 @@ class ApplicationController < ActionController::Base
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
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) &&
(!session[:return_to] ||
session[:return_to] &&
session[:return_to] == root_path)
(!session[:return_to] ||
session[:return_to] &&
session[:return_to] == root_path)
admin_conferences_path
else
session[:return_to] || root_path
@ -61,10 +63,10 @@ class ApplicationController < ActionController::Base
Rails.logger.debug('User is disabled!')
sign_out(current_user)
mail = User.admin.first ? User.admin.first.email : 'the admin!'
redirect_to User.ichain_logout_url, error: "This User is disabled. Please contact #{mail}!"
redirect_to User.ichain_logout_url, error: "This User is disabled. Please contact #{mail}!"
end
def not_found
raise ActionController::RoutingError.new('Not Found')
raise ActionController::RoutingError, 'Not Found'
end
end

View file

@ -1,8 +1,10 @@
# frozen_string_literal: true
class BoothsController < ApplicationController
before_action :authenticate_user!
load_resource :conference, find_by: :short_title
load_and_authorize_resource through: :conference
skip_authorize_resource only: [:withdraw, :confirm, :restart]
skip_authorize_resource only: %i[withdraw confirm restart]
def index
@booths = current_user.booths.where(conference_id: @conference.id).uniq
@ -34,7 +36,7 @@ class BoothsController < ApplicationController
def update
@url = conference_booth_path(@conference.short_title, @booth.id)
@booth.update_attributes(booth_params)
@booth.update(booth_params)
if @booth.save
redirect_to conference_booths_path,

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
class CommercialsController < ApplicationController
load_resource :conference, find_by: :short_title
before_action :set_event
@ -35,7 +37,7 @@ class CommercialsController < ApplicationController
def render_commercial
result = Commercial.render_from_url(params[:url])
if result[:error]
render text: result[:error], status: 400
render text: result[:error], status: :bad_request
else
render text: result[:html]
end

View file

@ -1,8 +1,10 @@
# frozen_string_literal: true
class ConferenceRegistrationsController < ApplicationController
before_action :authenticate_user!, except: [:new, :create]
before_action :authenticate_user!, except: %i[new create]
load_resource :conference, find_by: :short_title
authorize_resource :conference_registrations, class: Registration, except: [:new, :create]
before_action :set_registration, only: [:edit, :update, :destroy, :show]
authorize_resource :conference_registrations, class: Registration, except: %i[new create]
before_action :set_registration, only: %i[edit update destroy show]
def new
@registration = Registration.new(conference_id: @conference.id)
@ -54,9 +56,7 @@ class ConferenceRegistrationsController < ApplicationController
ahoy.track 'Registered', title: 'New registration'
# Sign in the new user
unless current_user
sign_in(@registration.user)
end
sign_in(@registration.user) unless current_user
if @conference.tickets.any? && !current_user.supports?(@conference)
redirect_to conference_tickets_path(@conference.short_title),
@ -73,7 +73,7 @@ class ConferenceRegistrationsController < ApplicationController
end
def update
if @registration.update_attributes(registration_params)
if @registration.update(registration_params)
redirect_to conference_conference_registration_path(@conference.short_title),
notice: 'Registration was successfully updated.'
else
@ -110,14 +110,15 @@ class ConferenceRegistrationsController < ApplicationController
def registration_params
params.require(:registration)
.permit(
:conference_id, :arrival, :departure,
:volunteer,
vchoice_ids: [], qanswer_ids: [],
qanswers_attributes: [],
event_ids: [],
user_attributes: [
:username, :email, :name, :password, :password_confirmation]
)
.permit(
:conference_id, :arrival, :departure,
:volunteer,
vchoice_ids: [], qanswer_ids: [],
qanswers_attributes: [],
event_ids: [],
user_attributes: %i[
username email name password password_confirmation
]
)
end
end

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
class ConferencesController < ApplicationController
protect_from_forgery with: :null_session
before_action :respond_to_options
@ -21,9 +23,7 @@ class ConferencesController < ApplicationController
splashpage = @conference.splashpage
unless splashpage.present?
redirect_to admin_conference_splashpage_path(@conference.short_title) && return
end
redirect_to admin_conference_splashpage_path(@conference.short_title) && return if splashpage.blank?
if splashpage.include_cfp
cfps = @conference.program.cfps
@ -42,16 +42,10 @@ class ConferencesController < ApplicationController
:room
).order('tracks.name')
end
if splashpage.include_booths
@booths = @conference.confirmed_booths.order('title')
end
end
if splashpage.include_registrations || splashpage.include_tickets
@tickets = @conference.tickets.order('price_cents')
end
if splashpage.include_lodgings
@lodgings = @conference.lodgings.order('name')
@booths = @conference.confirmed_booths.order('title') if splashpage.include_booths
end
@tickets = @conference.tickets.order('price_cents') if splashpage.include_registrations || splashpage.include_tickets
@lodgings = @conference.lodgings.order('name') if splashpage.include_lodgings
if splashpage.include_sponsors
@sponsorship_levels = @conference.sponsorship_levels.eager_load(
:sponsors
@ -71,8 +65,10 @@ class ConferencesController < ApplicationController
end
def respond_to_options
respond_to do |format|
format.html { head :ok }
end if request.options?
if request.options?
respond_to do |format|
format.html { head :ok }
end
end
end
end

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
class ConfirmationsController < Devise::ConfirmationsController
protected

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
class OpenidsController < ApplicationController
load_and_authorize_resource :user
load_and_authorize_resource through: :user

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
class OrganizationsController < ApplicationController
load_and_authorize_resource :organization

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
class PaymentsController < ApplicationController
before_action :authenticate_user!
load_and_authorize_resource
@ -10,9 +12,7 @@ class PaymentsController < ApplicationController
def new
@total_amount_to_pay = Ticket.total_price(@conference, current_user, paid: false)
if @total_amount_to_pay.zero?
raise CanCan::AccessDenied.new('Nothing to pay for!', :new, Payment)
end
raise CanCan::AccessDenied.new('Nothing to pay for!', :new, Payment) if @total_amount_to_pay.zero?
@unpaid_ticket_purchases = current_user.ticket_purchases.unpaid.by_conference(@conference)
end

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
class PhysicalTicketsController < ApplicationController
before_action :authenticate_user!
load_resource :conference, find_by: :short_title

View file

@ -1,10 +1,12 @@
# frozen_string_literal: true
class ProposalsController < ApplicationController
before_action :authenticate_user!, except: [:show, :new, :create]
before_action :authenticate_user!, except: %i[show new create]
load_resource :conference, find_by: :short_title
load_resource :program, through: :conference, singleton: true
load_and_authorize_resource :event, parent: false, through: :program
# We authorize manually in these actions
skip_authorize_resource :event, only: [:confirm, :restart, :withdraw]
skip_authorize_resource :event, only: %i[confirm restart withdraw]
def index
@event = @program.events.new
@ -168,8 +170,7 @@ class ProposalsController < ApplicationController
params.require(:event).permit(:event_type_id, :track_id, :difficulty_level_id,
:title, :subtitle, :abstract, :description,
:require_registration, :max_attendees, :language,
speaker_ids: []
)
speaker_ids: [])
end
def user_params

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
class RegistrationsController < Devise::RegistrationsController
prepend_before_action :check_captcha, only: [:create]

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
class SchedulesController < ApplicationController
load_and_authorize_resource
protect_from_forgery with: :null_session
@ -8,11 +10,9 @@ class SchedulesController < ApplicationController
def show
@rooms = @conference.venue.rooms if @conference.venue
schedules = @program.selected_event_schedules
unless schedules
redirect_to events_conference_schedule_path(@conference.short_title)
end
redirect_to events_conference_schedule_path(@conference.short_title) unless schedules
@events_xml = schedules.map(&:event).group_by{ |event| event.time.to_date } if schedules
@events_xml = schedules.map(&:event).group_by { |event| event.time.to_date } if schedules
@dates = @conference.start_date..@conference.end_date
@step_minutes = @program.schedule_interval.minutes
@conf_start = @conference.start_hour
@ -20,7 +20,7 @@ class SchedulesController < ApplicationController
# the schedule takes you to today if it is a date of the schedule
@current_day = @conference.current_conference_day
@day = @current_day.present? ? @current_day : @dates.first
@day = @current_day.presence || @dates.first
unless @current_day
# the schedule takes you to the current time if it is beetween the start and the end time.
@hour_column = @conference.hours_from_start_time(@conf_start, @conference.end_hour)
@ -37,7 +37,7 @@ class SchedulesController < ApplicationController
@dates = @conference.start_date..@conference.end_date
@events_schedules = @program.selected_event_schedules
@events_schedules = [] unless @events_schedules
@events_schedules ||= []
@unscheduled_events = @program.events.confirmed - @events_schedules.map(&:event)
@ -48,8 +48,10 @@ class SchedulesController < ApplicationController
private
def respond_to_options
respond_to do |format|
format.html { head :ok }
end if request.options?
if request.options?
respond_to do |format|
format.html { head :ok }
end
end
end
end

View file

@ -1,7 +1,9 @@
# frozen_string_literal: true
class SubscriptionsController < ApplicationController
before_action :authenticate_user!
load_resource :conference, find_by: :short_title
load_and_authorize_resource only: [:create, :destroy], through: :conference
load_and_authorize_resource only: %i[create destroy], through: :conference
def create
@subscription = current_user.subscriptions.build(conference_id: @conference.id)

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
class TicketPurchasesController < ApplicationController
before_action :authenticate_user!
load_resource :conference, find_by: :short_title

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
class TicketsController < ApplicationController
before_action :authenticate_user!
load_resource :conference, find_by: :short_title
@ -8,8 +10,6 @@ class TicketsController < ApplicationController
def index; end
def check_load_resource
if @tickets.empty?
redirect_to root_path, notice: "There are no tickets available for #{@conference.title}!"
end
redirect_to root_path, notice: "There are no tickets available for #{@conference.title}!" if @tickets.empty?
end
end

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
class TracksController < ApplicationController
load_resource :conference, find_by: :short_title
load_resource :program, through: :conference, singleton: true
@ -29,7 +31,7 @@ class TracksController < ApplicationController
end
def update
if @track.update_attributes(track_params)
if @track.update(track_params)
redirect_to conference_program_tracks_path(conference_id: @conference.short_title),
notice: 'Track request successfully updated.'
else

View file

@ -1,6 +1,8 @@
# frozen_string_literal: true
module Users
class OmniauthCallbacksController < Devise::OmniauthCallbacksController
skip_before_filter :verify_authenticity_token
skip_before_action :verify_authenticity_token
skip_authorization_check
User.omniauth_providers.each do |provider|
@ -11,7 +13,7 @@ module Users
def handle(provider)
auth_hash = request.env['omniauth.auth']
unless auth_hash.info.email.present?
if auth_hash.info.email.blank?
flash[:error] = "Email field is missing in your #{provider} account"
redirect_to new_user_registration_path
return
@ -27,15 +29,13 @@ module Users
begin
user.save!
if openid.user != user
openid.user = user
end
openid.user = user if openid.user != user
openid.save!
sign_in user
redirect_to request.env['omniauth.origin'] || root_path,
notice: "#{user.email} signed in successfully with #{provider}"
rescue => e
rescue StandardError => e
flash[:error] = e.message
redirect_back_or_to new_user_registration_path
end

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
class UsersController < ApplicationController
load_and_authorize_resource
@ -7,8 +9,7 @@ class UsersController < ApplicationController
end
# GET /users/1/edit
def edit
end
def edit; end
# PATCH/PUT /users/1
def update
@ -22,8 +23,8 @@ class UsersController < ApplicationController
private
# Only allow a trusted parameter "white list" through.
def user_params
params.require(:user).permit(:name, :biography, :nickname, :affiliation)
end
# Only allow a trusted parameter "white list" through.
def user_params
params.require(:user).permit(:name, :biography, :nickname, :affiliation)
end
end

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Admin
module VolunteersHelper
def can_manage_volunteers?(conference)

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module ApplicationHelper
# Returns a string build from the start and end date of the given conference.
#
@ -60,7 +62,7 @@ module ApplicationHelper
end
def difficulty_levels(conference)
all = conference.program.difficulty_levels.map {|t| t.title}
all = conference.program.difficulty_levels.map(&:title)
first = all[0...-1]
last = all[-1]
ts = ''
@ -83,16 +85,14 @@ module ApplicationHelper
# Output will be 'title, description and conference'
def updated_attributes(version)
version.changeset
.reject{ |_, values| values[0].blank? && values[1].blank? }
.keys.map{ |key| key.gsub('_id', '').tr('_', ' ')}.join(', ')
.reverse.sub(',', ' dna ').reverse
.reject { |_, values| values[0].blank? && values[1].blank? }
.keys.map { |key| key.gsub('_id', '').tr('_', ' ') }.join(', ')
.reverse.sub(',', ' dna ').reverse
end
def normalize_array_length(hashmap, length)
hashmap.each_value do |value|
if value.length < length
value.fill(value[-1], value.length...length)
end
value.fill(value[-1], value.length...length) if value.length < length
end
end
@ -115,28 +115,26 @@ module ApplicationHelper
other_event_schedules.each do |other_event_schedule|
next unless other_event_schedule.event.confirmed?
other_event_time_range = (other_event_schedule.start_time.strftime '%Y-%m-%d %H:%M')...(other_event_schedule.end_time.strftime '%Y-%m-%d %H:%M')
if (event_time_range.to_a & other_event_time_range.to_a).present?
concurrent_events << other_event_schedule.event
end
concurrent_events << other_event_schedule.event if (event_time_range.to_a & other_event_time_range.to_a).present?
end
concurrent_events
end
def speaker_links(event)
safe_join(event.speakers.map{ |speaker| link_to speaker.name, admin_user_path(speaker) }, ',')
safe_join(event.speakers.map { |speaker| link_to speaker.name, admin_user_path(speaker) }, ',')
end
def speaker_selector_input(form)
users = User.active.pluck(:id, :name, :username, :email).map { |user| [user[0], user[1].blank? ? user[2] : user[1], user[2], user[3]] }.sort_by { |user| user[1].downcase }
users = User.active.pluck(:id, :name, :username, :email).map { |user| [user[0], user[1].presence || user[2], user[2], user[3]] }.sort_by { |user| user[1].downcase }
form.input :speakers, as: :select,
collection: options_for_select(users.map {|user| ["#{user[1]} (#{user[2]}) #{user[3]}", user[0]]}, @event.speakers.map(&:id)),
collection: options_for_select(users.map { |user| ["#{user[1]} (#{user[2]}) #{user[3]}", user[0]] }, @event.speakers.map(&:id)),
include_blank: false, label: 'Speakers', input_html: { class: 'select-help-toggle', multiple: 'true' }
end
def responsibles_selector_input(form)
users = User.active.pluck(:id, :name, :username, :email).map { |user| [user[0], user[1].blank? ? user[2] : user[1], user[2], user[3]] }.sort_by { |user| user[1].downcase }
users = User.active.pluck(:id, :name, :username, :email).map { |user| [user[0], user[1].presence || user[2], user[2], user[3]] }.sort_by { |user| user[1].downcase }
form.input :responsibles, as: :select,
collection: options_for_select(users.map {|user| ["#{user[1]} (#{user[2]}) #{user[3]}", user[0]]}, @booth.responsibles.map(&:id)),
collection: options_for_select(users.map { |user| ["#{user[1]} (#{user[2]}) #{user[3]}", user[0]] }, @booth.responsibles.map(&:id)),
include_blank: false, label: 'Responsibles', input_html: { class: 'select-help-toggle', multiple: 'true' },
hint: 'The people responsible for the booth. You can only select existing users.'
end
@ -154,9 +152,7 @@ module ApplicationHelper
end
def rescheduling_hint(affected_event_count)
if affected_event_count > 0
"You have #{affected_event_count} scheduled #{'event'.pluralize(affected_event_count)}. Changing the conference hours will unschedule those scheduled outside the conference hours."
end
"You have #{affected_event_count} scheduled #{'event'.pluralize(affected_event_count)}. Changing the conference hours will unschedule those scheduled outside the conference hours." if affected_event_count > 0
end
##

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module ConferenceHelper
# Return true if only call_for_papers or call_for_tracks or call_for_booths is open
def one_call_open(*calls)
@ -6,7 +8,7 @@ module ConferenceHelper
# Return true if exactly two of those calls are open: call_for_papers , call_for_tracks , call_for_booths
def two_calls_open(*calls)
calls.count{ |call| call.try(:open?) } == 2
calls.count { |call| call.try(:open?) } == 2
end
# URL for sponsorship emails

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module DateTimeHelper
##
# Includes functions related to date or time manipulations

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module EventsHelper
##
# Includes functions related to events

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module FormatHelper
##
# Includes functions related to formatting (like adding classes, colors)
@ -44,24 +46,23 @@ module FormatHelper
def target_progress_color(progress)
progress = progress.to_i
result =
case
when progress >= 90 then 'green'
when progress < 90 && progress >= 80 then 'orange'
else 'red'
end
if progress >= 90 then 'green'
elsif progress < 90 && progress >= 80 then 'orange'
else 'red'
end
result
end
def days_left_color(days_left)
days_left = days_left.to_i
if days_left > 30
result = 'green'
elsif days_left < 30 && days_left > 10
result = 'orange'
else
result = 'red'
end
result = if days_left > 30
'green'
elsif days_left < 30 && days_left > 10
'orange'
else
'red'
end
result
end
@ -116,7 +117,7 @@ module FormatHelper
end
def word_pluralize(count, singular, plural = nil)
word = if (count == 1 || count =~ /^1(\.0+)?$/)
word = if count == 1 || count =~ /^1(\.0+)?$/
singular
else
plural || singular.pluralize
@ -134,7 +135,7 @@ module FormatHelper
g = hexcolor[3..4].to_i(16)
b = hexcolor[5..6].to_i(16)
yiq = ((r * 299) + (g * 587) + (b * 114)) / 1000
(yiq >= 128) ? 'black' : 'white'
yiq >= 128 ? 'black' : 'white'
end
def td_height(rooms)
@ -178,17 +179,15 @@ module FormatHelper
item_class = 'item'
item_class += ' first' if number == 0
item_class += ' last' if number == (carousel_number - 1)
if (col && ((col / num_cols) == number)) || (!col && number == 0)
item_class += ' active'
end
item_class += ' active' if (col && ((col / num_cols) == number)) || (!col && number == 0)
item_class
end
def selected_scheduled?(schedule)
(schedule == @selected_schedule) ? 'Yes' : 'No'
schedule == @selected_schedule ? 'Yes' : 'No'
end
def markdown(text, escape_html=true)
def markdown(text, escape_html = true)
return '' if text.nil?
options = {
@ -200,7 +199,7 @@ module FormatHelper
markdown.render(text).html_safe
end
def markdown_hint(text='')
def markdown_hint(text = '')
markdown("#{text} Please look at #{link_to '**Markdown Syntax**', 'https://daringfireball.net/projects/markdown/syntax', target: '_blank'} to format your text", false)
end

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module PathsHelper
##
# Includes functions related to links or redirects

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module UsersHelper
##
# Includes functions related to users
@ -12,10 +14,8 @@ module UsersHelper
Devise.omniauth_providers.each do |provider|
provider_key = "#{provider}_key"
provider_secret = "#{provider}_secret"
unless Rails.application.secrets.send(provider_key).blank? || Rails.application.secrets.send(provider_secret).blank?
providers << provider
end
providers << provider if !ENV["OSEM_#{provider.upcase}_KEY"].blank? && !ENV["OSEM_#{provider.upcase}_SECRET"].blank?
providers << provider unless Rails.application.secrets.send(provider_key).blank? || Rails.application.secrets.send(provider_secret).blank?
providers << provider if ENV["OSEM_#{provider.upcase}_KEY"].present? && ENV["OSEM_#{provider.upcase}_SECRET"].present?
end
providers.uniq
@ -25,6 +25,6 @@ module UsersHelper
# Outputs the roles of a user, including the conferences for which the user has the roles
# Eg. organizer(oSC13, oSC14), cfp(oSC12, oSC13)
def show_roles(roles)
roles.map{ |x| x[0].titleize + ' (' + x[1].join(', ') + ')' }.join ', '
roles.map { |x| x[0].titleize + ' (' + x[1].join(', ') + ')' }.join ', '
end
end

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module VersionsHelper
##
# Groups functions related to change description
@ -119,10 +121,9 @@ module VersionsHelper
end
def event_change_description(version)
case
when version.event == 'create' then 'submitted new'
if version.event == 'create' then 'submitted new'
when version.changeset['state']
elsif version.changeset['state']
case version.changeset['state'][1]
when 'unconfirmed' then 'accepted'
when 'withdrawn' then 'withdrew'

View file

@ -1,2 +1,4 @@
# frozen_string_literal: true
class ApplicationJob < ActiveJob::Base
end

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
class ConferenceCfpUpdateMailJob < ApplicationJob
queue_as :default

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
class ConferenceDateUpdateMailJob < ApplicationJob
queue_as :default

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
class ConferenceRegistrationDateUpdateMailJob < ApplicationJob
queue_as :default

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
class ConferenceScheduleUpdateMailJob < ApplicationJob
queue_as :default

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
class ConferenceVenueUpdateMailJob < ApplicationJob
queue_as :default

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
class EventCommentMailJob < ApplicationJob
queue_as :default

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
class Mailbot < ActionMailer::Base
def registration_mail(conference, user)
mail(to: user.email,

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
class Ability
include CanCan::Ability
@ -15,7 +17,7 @@ class Ability
# Abilities for not signed in users (guests)
def not_signed_in
can [:index, :conferences], Organization
can %i[index conferences], Organization
can [:index], Conference
can [:show], Conference do |conference|
conference.splashpage && conference.splashpage.public == true
@ -31,20 +33,16 @@ class Ability
# can view Commercials of confirmed Events
can :show, Commercial, commercialable_type: 'Event', commercialable_id: Event.where(state: 'confirmed').pluck(:id)
can [:show, :create], User
can %i[show create], User
unless ENV['OSEM_ICHAIN_ENABLED'] == 'true'
can :show, Registration do |registration|
registration.new_record?
end
can :show, Registration, &:new_record?
can [:new, :create], Registration do |registration|
conference = registration.conference
conference.registration_open? && registration.new_record? && !conference.registration_limit_exceeded?
end
can :show, Event do |event|
event.new_record?
end
can :show, Event, &:new_record?
can [:new, :create], Event do |event|
event.program.cfp_open? && event.new_record?
@ -78,8 +76,8 @@ class Ability
can :index, Organization
can :index, Ticket
can :manage, TicketPurchase, user_id: user.id
can [:new, :create], Payment, user_id: user.id
can [:index, :show], PhysicalTicket, user: user
can %i[new create], Payment, user_id: user.id
can %i[index show], PhysicalTicket, user: user
can [:new, :create], Booth do |booth|
booth.new_record? && booth.conference.program.cfps.for_booths.try(:open?)
@ -89,7 +87,7 @@ class Ability
booth.users.include?(user)
end
can [:create, :destroy], Subscription, user_id: user.id
can %i[create destroy], Subscription, user_id: user.id
can [:new, :create], Event do |event|
event.program.cfp_open? && event.new_record?
@ -108,7 +106,7 @@ class Ability
track.new_record? && track.program.cfps.for_tracks.try(:open?)
end
can [:index, :show, :restart, :confirm, :withdraw], Track, submitter_id: user.id
can %i[index show restart confirm withdraw], Track, submitter_id: user.id
can [:edit, :update], Track do |track|
user == track.submitter && !(track.accepted? || track.confirmed?)

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
class AdminAbility
include CanCan::Ability
@ -28,12 +30,12 @@ class AdminAbility
conference.registration_open? && !conference.registration_limit_exceeded? || conference.program.speakers.confirmed.include?(user)
end
can [:index, :admins], Organization
can %i[index admins], Organization
can :index, Ticket
can :manage, TicketPurchase, user_id: user.id
can [:new, :create], Payment, user_id: user.id
can %i[new create], Payment, user_id: user.id
can [:create, :destroy], Subscription, user_id: user.id
can %i[create destroy], Subscription, user_id: user.id
can [:new, :create], Event do |event|
event.program.cfp_open? && event.new_record?
@ -45,11 +47,11 @@ class AdminAbility
can [:destroy], Openid
can :access, Admin
can :index, Commercial, commercialable_type: 'Conference'
cannot [:edit, :update, :destroy], Question, global: true
cannot %i[edit update destroy], Question, global: true
# for admins
can :manage, :all if user.is_admin
# even admin cannot create new users with ICHAIN enabled
cannot [:new, :create], User if ENV['OSEM_ICHAIN_ENABLED'] == 'true'
cannot %i[new create], User if ENV['OSEM_ICHAIN_ENABLED'] == 'true'
cannot :revert_object, PaperTrail::Version do |version|
(version.event == 'create' && %w[Conference User Event].include?(version.item_type))
end
@ -67,9 +69,7 @@ class AdminAbility
end
# Prevent requests for tracks from being destroyed
cannot :destroy, Track do |track|
track.self_organized?
end
cannot :destroy, Track, &:self_organized?
# Can't accept a booth when booth_limit is reached
cannot :accept, Booth do |booth|
conference = booth.conference
@ -92,10 +92,10 @@ class AdminAbility
org_ids_for_organization_admin = Organization.with_role(:organization_admin, user).pluck(:id)
conf_ids_for_organization_admin = Conference.where(organization_id: org_ids_for_organization_admin).pluck(:id)
can [:read, :update, :destroy, :assign_org_admins, :unassign_org_admins, :admins], Organization, id: org_ids_for_organization_admin
can %i[read update destroy assign_org_admins unassign_org_admins admins], Organization, id: org_ids_for_organization_admin
can :new, Conference
can :manage, Conference, organization_id: org_ids_for_organization_admin
can [:index, :show], Role
can %i[index show], Role
signed_in_with_organizer_role(user, conf_ids_for_organization_admin)
end
@ -108,7 +108,7 @@ class AdminAbility
track_ids = Track.joins(:program).where('programs.conference_id IN (?)', conf_ids).pluck(:id)
can :manage, Resource, conference_id: conf_ids
can [:read, :update, :destroy], Conference, id: conf_ids
can %i[read update destroy], Conference, id: conf_ids
can :manage, Splashpage, conference_id: conf_ids
can :manage, Contact, conference_id: conf_ids
can :manage, EmailSettings, conference_id: conf_ids
@ -163,8 +163,8 @@ class AdminAbility
role.resource_type == 'Track' && (track_ids.include? role.resource_id)
end
can [:index, :revert_object, :revert_attribute], PaperTrail::Version, item_type: 'User'
can [:index, :revert_object, :revert_attribute], PaperTrail::Version, conference_id: conf_ids
can %i[index revert_object revert_attribute], PaperTrail::Version, item_type: 'User'
can %i[index revert_object revert_attribute], PaperTrail::Version, conference_id: conf_ids
end
def signed_in_with_cfp_role(user)
@ -174,7 +174,7 @@ class AdminAbility
can :show, Conference do |conf|
conf_ids_for_cfp.include?(conf.id)
end
can [:index, :show, :update], Resource, conference_id: conf_ids_for_cfp
can %i[index show update], Resource, conference_id: conf_ids_for_cfp
can :manage, Booth, conference_id: conf_ids_for_cfp
can :manage, Event, program: { conference_id: conf_ids_for_cfp }
can :manage, EventType, program: { conference_id: conf_ids_for_cfp }
@ -203,7 +203,7 @@ class AdminAbility
(Conference.with_role(:cfp, user).pluck(:id).include? role.resource_id)
end
can [:index, :revert_object, :revert_attribute], PaperTrail::Version,
can %i[index revert_object revert_attribute], PaperTrail::Version,
item_type: %w[Event EventType Track DifficultyLevel EmailSettings Room Cfp Program Comment], conference_id: conf_ids_for_cfp
can [:index, :revert_object, :revert_attribute], PaperTrail::Version,
["item_type = 'Commercial' AND conference_id IN (?) AND (object LIKE '%Event%' OR object_changes LIKE '%Event%')", conf_ids_for_cfp] do |version|
@ -219,7 +219,7 @@ class AdminAbility
can :show, Conference do |conf|
conf_ids_for_info_desk.include?(conf.id)
end
can [:index, :show, :update], Resource, conference_id: conf_ids_for_info_desk
can %i[index show update], Resource, conference_id: conf_ids_for_info_desk
can :manage, Registration, conference_id: conf_ids_for_info_desk
can :manage, Question, conference_id: conf_ids_for_info_desk
can :manage, Question do |question|
@ -240,7 +240,7 @@ class AdminAbility
role.resource_type == 'Conference' && role.name == 'info_desk' &&
(Conference.with_role(:info_desk, user).pluck(:id).include? role.resource_id)
end
can [:index, :revert_object, :revert_attribute], PaperTrail::Version, item_type: 'Registration', conference_id: conf_ids_for_info_desk
can %i[index revert_object revert_attribute], PaperTrail::Version, item_type: 'Registration', conference_id: conf_ids_for_info_desk
end
def signed_in_with_volunteers_coordinator_role(user)
@ -250,7 +250,7 @@ class AdminAbility
can :show, Conference do |conf|
conf_ids_for_volunteers_coordinator.include?(conf.id)
end
can [:index, :show, :update], Resource, conference_id: conf_ids_for_volunteers_coordinator
can %i[index show update], Resource, conference_id: conf_ids_for_volunteers_coordinator
can :manage, Vposition, conference_id: conf_ids_for_volunteers_coordinator
can :manage, Vday, conference_id: conf_ids_for_volunteers_coordinator
@ -286,9 +286,7 @@ class AdminAbility
can :manage, Track, id: track_ids_for_track_organizer
cannot [:edit, :update], Track do |track|
track.self_organized_and_accepted_or_confirmed?
end
cannot %i[edit update], Track, &:self_organized_and_accepted_or_confirmed?
# Show Roles in the admin sidebar and allow authorization of the index action
can [:index, :show], Role do |role|

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Ahoy
class Event < ApplicationRecord
self.table_name = 'ahoy_events'

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
class Answer < ApplicationRecord
has_many :qanswers
has_many :questions, through: :qanswers

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
end

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
class Booth < ApplicationRecord
include ActiveRecord::Transitions
has_paper_trail ignore: [:updated_at], meta: { conference_id: :conference_id }
@ -41,28 +43,28 @@ class Booth < ApplicationRecord
state :confirmed
event :restart do
transitions to: :new, from: [:withdrawn, :rejected, :canceled]
transitions to: :new, from: %i[withdrawn rejected canceled]
end
event :withdraw do
transitions to: :withdrawn, from: [:new, :to_accept, :accepted, :to_reject, :rejected, :confirmed]
transitions to: :withdrawn, from: %i[new to_accept accepted to_reject rejected confirmed]
end
event :confirm do
transitions to: :confirmed, from: [:accepted]
end
event :to_accept do
transitions to: :to_accept, from: [:new, :to_reject]
transitions to: :to_accept, from: %i[new to_reject]
end
event :to_reject do
transitions to: :to_reject, from: [:new, :to_accept]
transitions to: :to_reject, from: %i[new to_accept]
end
event :accept do
transitions to: :accepted, from: [:new, :to_accept]
transitions to: :accepted, from: %i[new to_accept]
end
event :reject do
transitions to: :rejected, from: [:new, :to_reject]
transitions to: :rejected, from: %i[new to_reject]
end
event :cancel do
transitions to: :canceled, from: [:accepted, :rejected, :to_accept, :to_reject, :confirmed]
transitions to: :canceled, from: %i[accepted rejected to_accept to_reject confirmed]
end
end

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
class BoothRequest < ApplicationRecord
belongs_to :booth
belongs_to :user

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
class Campaign < ApplicationRecord
validates :name, :utm_campaign, presence: true
@ -66,11 +68,11 @@ class Campaign < ApplicationRecord
# * +Hash+ -> parameter => value
def get_parameters
conditions = {}
conditions[:utm_source] = self[:utm_source] unless self[:utm_source].blank?
conditions[:utm_medium] = self[:utm_medium] unless self[:utm_medium].blank?
conditions[:utm_term] = self[:utm_term] unless self[:utm_term].blank?
conditions[:utm_content] = self[:utm_content] unless self[:utm_content].blank?
conditions[:utm_campaign] = self[:utm_campaign] unless self[:utm_campaign].blank?
conditions[:utm_source] = self[:utm_source] if self[:utm_source].present?
conditions[:utm_medium] = self[:utm_medium] if self[:utm_medium].present?
conditions[:utm_term] = self[:utm_term] if self[:utm_term].present?
conditions[:utm_content] = self[:utm_content] if self[:utm_content].present?
conditions[:utm_campaign] = self[:utm_campaign] if self[:utm_campaign].present?
conditions
end
end

View file

@ -1,7 +1,9 @@
# frozen_string_literal: true
# cannot delete program if there are events submitted
class Cfp < ApplicationRecord
TYPES = %w(events booths tracks).freeze
TYPES = %w[events booths tracks].freeze
has_paper_trail ignore: [:updated_at], meta: { conference_id: :conference_id }
belongs_to :program
@ -27,11 +29,11 @@ class Cfp < ApplicationRecord
# * +True+ -> If cfp dates is updated and all other parameters are set
# * +False+ -> Either cfp date is not updated or one or more parameter is not set
def notify_on_cfp_date_update?
!end_date.blank? && !start_date.blank?\
end_date.present? && start_date.present?\
&& (start_date_changed? || end_date_changed?)\
&& program.conference.email_settings.send_on_cfp_dates_updated\
&& !program.conference.email_settings.cfp_dates_updated_subject.blank?\
&& !program.conference.email_settings.cfp_dates_updated_body.blank?
&& program.conference.email_settings.cfp_dates_updated_subject.present?\
&& program.conference.email_settings.cfp_dates_updated_body.present?
end
##
@ -106,20 +108,22 @@ class Cfp < ApplicationRecord
private
def before_end_of_conference
if program && program.conference && program.conference.end_date && end_date && (end_date > program.conference.end_date)
if program&.conference && program.conference.end_date && end_date && (end_date > program.conference.end_date)
errors
.add(:end_date, "can't be after the conference end date (#{program.conference.end_date})")
.add(:end_date, "can't be after the conference end date (#{program.conference.end_date})")
end
if program && program.conference && program.conference.end_date && start_date && (start_date > program.conference.end_date)
if program&.conference && program.conference.end_date && start_date && (start_date > program.conference.end_date)
errors
.add(:start_date, "can't be after the conference end date (#{program.conference.end_date})")
.add(:start_date, "can't be after the conference end date (#{program.conference.end_date})")
end
end
def start_after_end_date
errors
.add(:start_date, "can't be after the end date") if start_date && end_date && start_date > end_date
if start_date && end_date && start_date > end_date
errors
.add(:start_date, "can't be after the end date")
end
end
def conference_id

View file

@ -1,19 +1,21 @@
# frozen_string_literal: true
class Comment < ApplicationRecord
acts_as_nested_set scope: %i(commentable_id commentable_type)
acts_as_nested_set scope: %i[commentable_id commentable_type]
validates :body, presence: true
validates :user, presence: true
after_create :send_notification
# NOTE: install the acts_as_votable plugin if you
# want user to vote on the quality of comments.
#acts_as_votable
# acts_as_votable
belongs_to :commentable, counter_cache: true, polymorphic: true
# NOTE: Comments belong to a user
belongs_to :user
has_paper_trail on: %i(create destroy), meta: { conference_id: :conference_id }
has_paper_trail on: %i[create destroy], meta: { conference_id: :conference_id }
# Helper class method that allows you to build a comment
# by passing a commentable object, a user_id, and comment text
@ -25,7 +27,7 @@ class Comment < ApplicationRecord
user_id: user_id
end
#helper method to check if a comment has children
# helper method to check if a comment has children
def has_children?
children.any?
end

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
class Commercial < ApplicationRecord
require 'oembed'
@ -6,7 +8,7 @@ class Commercial < ApplicationRecord
has_paper_trail ignore: [:updated_at], meta: { conference_id: :conference_id }
validates :url, presence: true, uniqueness: { scope: :commercialable }
validates :url, format: URI::regexp(%w(http https))
validates :url, format: URI.regexp(%w[http https])
validate :valid_url
@ -36,9 +38,7 @@ class Commercial < ApplicationRecord
errors[:no_event] << id && next unless event
commercial = event.commercials.new(url: url)
unless commercial.save
errors[:validation_errors] << "Could not create commercial for event with ID #{event.id} (" + commercial.errors.full_messages.to_sentence + ')'
end
errors[:validation_errors] << "Could not create commercial for event with ID #{event.id} (" + commercial.errors.full_messages.to_sentence + ')' unless commercial.save
end
errors
end
@ -47,9 +47,7 @@ class Commercial < ApplicationRecord
def valid_url
result = Commercial.render_from_url(url)
if result[:error]
errors.add(:base, result[:error])
end
errors.add(:base, result[:error]) if result[:error]
end
def self.register_provider
@ -58,12 +56,12 @@ class Commercial < ApplicationRecord
speakerdeck << 'http://speakerdeck.com/*'
OEmbed::Providers.register(
OEmbed::Providers::Youtube,
OEmbed::Providers::Vimeo,
OEmbed::Providers::Slideshare,
OEmbed::Providers::Flickr,
OEmbed::Providers::Instagram,
speakerdeck
OEmbed::Providers::Youtube,
OEmbed::Providers::Vimeo,
OEmbed::Providers::Slideshare,
OEmbed::Providers::Flickr,
OEmbed::Providers::Instagram,
speakerdeck
)
end

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module RevisionCount
extend ActiveSupport::Concern

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
class Conference < ApplicationRecord
include RevisionCount
require 'uri'
@ -12,7 +14,7 @@ class Conference < ApplicationRecord
belongs_to :organization
has_paper_trail ignore: %i(updated_at guid revision events_per_week), meta: { conference_id: :id }
has_paper_trail ignore: %i[updated_at guid revision events_per_week], meta: { conference_id: :id }
has_and_belongs_to_many :questions
@ -91,7 +93,7 @@ class Conference < ApplicationRecord
after_create :create_free_ticket
after_update :delete_event_schedules
enum ticket_layout: [:portrait, :landscape]
enum ticket_layout: %i[portrait landscape]
##
# Checks if the user is registered to the conference
@ -101,7 +103,7 @@ class Conference < ApplicationRecord
# ====Returns
# * +false+ -> If the user is registered
# * +true+ - If the user isn't registered
def user_registered? user
def user_registered?(user)
user.present? && registrations.where(user_id: user.id).count > 0
end
@ -112,8 +114,8 @@ class Conference < ApplicationRecord
if start_hour_changed? || end_hour_changed?
event_schedules = program.event_schedules.select do |event_schedule|
event_schedule.start_time.hour < start_hour ||
event_schedule.end_time.hour > end_hour ||
(event_schedule.end_time.hour == end_hour && event_schedule.end_time.minute > 0)
event_schedule.end_time.hour > end_hour ||
(event_schedule.end_time.hour == end_hour && event_schedule.end_time.minute > 0)
end
event_schedules.each(&:destroy)
end
@ -151,7 +153,7 @@ class Conference < ApplicationRecord
def get_submissions_per_week
result = []
if program && program.cfp && program.events
if program&.cfp && program.events
submissions = program.events.select(:week).group(:week).order(:week).count
start_week = program.cfp.start_week
weeks = program.cfp.weeks
@ -168,7 +170,7 @@ class Conference < ApplicationRecord
# * +Array+ -> e.g. 'Submitted' => [0, 3, 3, 5] -> first week 0 events, second week 3 events.
def get_submissions_data
result = {}
if program && program.cfp && program.events
if program&.cfp && program.events
result = get_events_per_week_by_state
start_week = program.cfp.start_week
@ -196,9 +198,9 @@ class Conference < ApplicationRecord
result = []
if registrations &&
registration_period &&
registration_period.start_date &&
registration_period.end_date
registration_period &&
registration_period.start_date &&
registration_period.end_date
reg = registrations.group(:week).order(:week).count
start_week = get_registration_start_week
@ -269,11 +271,10 @@ class Conference < ApplicationRecord
def registration_weeks
result = 0
weeks = 0
if registration_period &&
registration_period.start_date &&
registration_period.end_date
if registration_period&.start_date &&
registration_period.end_date
weeks = Date.new(registration_period.start_date.year, 12, 31)
.strftime('%W').to_i
.strftime('%W').to_i
result = get_registration_end_week - get_registration_start_week + 1
end
@ -343,7 +344,7 @@ class Conference < ApplicationRecord
tracks: tracks_set?,
event_types: event_types_set?,
difficulty_levels: difficulty_levels_set?,
splashpage: splashpage && splashpage.public?
splashpage: splashpage&.public?
}
result.update(
@ -370,8 +371,8 @@ class Conference < ApplicationRecord
# * +hash+ -> user: submissions
def get_top_submitter(limit = 5)
submitter = EventUser.joins(:event).select(:user_id)
.where('event_role = ? and program_id = ?', 'submitter', Conference.find(id).program.id)
.limit(limit).group(:user_id)
.where('event_role = ? and program_id = ?', 'submitter', Conference.find(id).program.id)
.limit(limit).group(:user_id)
counter = submitter.order('count_all desc').count(:all)
Conference.calculate_user_submission_hash(submitter, counter)
end
@ -595,12 +596,12 @@ class Conference < ApplicationRecord
# * +ActiveRecord+
def self.get_active_conferences_for_dashboard
result = Conference.where('start_date > ?', Time.now)
.select('id, short_title, color, start_date, organization_id')
.select('id, short_title, color, start_date, organization_id')
if result.empty?
result = Conference
.select('id, short_title, color, start_date, organization_id').limit(2)
.order(start_date: :desc)
.select('id, short_title, color, start_date, organization_id').limit(2)
.order(start_date: :desc)
end
result
end
@ -671,9 +672,7 @@ class Conference < ApplicationRecord
result[state.name] = count
end
unless conference.events_per_week
conference.events_per_week = {}
end
conference.events_per_week = {} unless conference.events_per_week
# Write to database
conference.events_per_week[week] = result
@ -785,7 +784,7 @@ class Conference < ApplicationRecord
# the color. We make use of big prime numbers to avoid repetition and to make
# consecutive colors clearly different.
def next_color_component(component, i)
big_prime_numbers = {r: 113, g: 67, b: 151}
big_prime_numbers = { r: 113, g: 67, b: 151 }
((i * big_prime_numbers[component]) % 239 + 16).to_s(16)
end
@ -861,12 +860,9 @@ class Conference < ApplicationRecord
# Completed weeks
events_per_week.each do |week, values|
values.each do |state, value|
if %i(confirmed unconfirmed).include?(state)
unless result[state.to_s.capitalize]
result[state.to_s.capitalize] = {}
end
result[state.to_s.capitalize][week.strftime('%W').to_i] = value
end
next unless %i[confirmed unconfirmed].include?(state)
result[state.to_s.capitalize] = {} unless result[state.to_s.capitalize]
result[state.to_s.capitalize][week.strftime('%W').to_i] = value
end
end
@ -923,9 +919,7 @@ class Conference < ApplicationRecord
# * +Array+
def pad_left(first_week, start_week)
left = []
if first_week > start_week
left = Array.new(first_week - start_week - 1, 0)
end
left = Array.new(first_week - start_week - 1, 0) if first_week > start_week
left
end
@ -938,9 +932,7 @@ class Conference < ApplicationRecord
def assert_keys_are_continuously(hash)
keys = hash.keys
(keys.min..keys.max).each do |key|
unless hash[key]
hash[key] = 0
end
hash[key] = 0 unless hash[key]
end
Hash[hash.sort]
end
@ -1048,12 +1040,11 @@ class Conference < ApplicationRecord
grouped.each do |event|
object = event.send(symbol)
if object
result[object.title] = {
'value' => counter[object.id],
'color' => object.color
}
end
next unless object
result[object.title] = {
'value' => counter[object.id],
'color' => object.color
}
end
result
end
@ -1067,12 +1058,11 @@ class Conference < ApplicationRecord
def calculate_track_distribution_hash(tracks_grouped, tracks_counter)
result = {}
tracks_grouped.each do |event|
if event.track
result[event.track.name] = {
'value' => tracks_counter[event.track_id],
'color' => event.track.color
}
end
next unless event.track
result[event.track.name] = {
'value' => tracks_counter[event.track_id],
'color' => event.track.color
}
end
result
end
@ -1127,10 +1117,10 @@ class Conference < ApplicationRecord
result = {}
states.each do |key, value|
result[key.capitalize] =
{
'value' => value,
'color' => Event.get_state_color(key)
}
{
'value' => value,
'color' => Event.get_state_color(key)
}
end
result
end
@ -1145,9 +1135,7 @@ class Conference < ApplicationRecord
counter.each do |key, value|
# make PG happy by including the user_id in ORDER
submitter = submitters.where(user_id: key).order(:user_id).first
if submitter
result[submitter.user] = value
end
result[submitter.user] = value if submitter
end
result
end
@ -1165,9 +1153,9 @@ class Conference < ApplicationRecord
#
def generate_guid
guid = SecureRandom.urlsafe_base64
# begin
# guid = SecureRandom.urlsafe_base64
# end while User.where(:guid => guid).exists?
# begin
# guid = SecureRandom.urlsafe_base64
# end while User.where(:guid => guid).exists?
self.guid = guid
end
@ -1175,19 +1163,17 @@ class Conference < ApplicationRecord
# Adds a random color to the conference
#
def add_color
unless color
self.color = get_color
end
self.color = get_color unless color
end
def get_color
%w(
#000000 #0000FF #00FF00 #FF0000 #FFFF00 #9900CC
#CC0066 #00FFFF #FF00FF #C0C0C0 #00008B #FFD700
#FFA500 #FF1493 #FF00FF #F0FFFF #EE82EE #D2691E
#C0C0C0 #A52A2A #9ACD32 #9400D3 #8B008B #8B0000
#87CEEB #808080 #800080 #008B8B #006400
).sample
%w[
#000000 #0000FF #00FF00 #FF0000 #FFFF00 #9900CC
#CC0066 #00FFFF #FF00FF #C0C0C0 #00008B #FFD700
#FFA500 #FF1493 #FF00FF #F0FFFF #EE82EE #D2691E
#C0C0C0 #A52A2A #9ACD32 #9400D3 #8B008B #8B0000
#87CEEB #808080 #800080 #008B8B #006400
].sample
end
# Calculates items per week from a hash.
@ -1206,9 +1192,7 @@ class Conference < ApplicationRecord
items.each do |key, value|
# Padding
if last_key < (key.to_i - 1)
result += Array.new(key.to_i - last_key - 1, sum)
end
result += Array.new(key.to_i - last_key - 1, sum) if last_key < (key.to_i - 1)
sum += value
result.push(sum)
@ -1216,9 +1200,7 @@ class Conference < ApplicationRecord
end
# Padding right
if result.length < weeks
result += Array.new(weeks - result.length, sum)
end
result += Array.new(weeks - result.length, sum) if result.length < weeks
result
end

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
class Contact < ApplicationRecord
has_paper_trail on: [:update], ignore: [:updated_at], meta: { conference_id: :conference_id }
@ -6,7 +8,7 @@ class Contact < ApplicationRecord
validates :conference, presence: true
# Conferences only have one contact
validates :facebook, :twitter, :googleplus, :instagram, :mastodon,
format: URI::regexp(%w(http https)), allow_blank: true
format: URI.regexp(%w[http https]), allow_blank: true
def has_social_media?
return true if facebook.present? || twitter.present? || googleplus.present? || instagram.present? || mastodon.present? || email.present?

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
class DifficultyLevel < ApplicationRecord
belongs_to :program, touch: true
has_many :events, dependent: :nullify

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
class EmailSettings < ApplicationRecord
belongs_to :conference
@ -11,12 +13,15 @@ class EmailSettings < ApplicationRecord
'conference_start_date' => conference.start_date,
'conference_end_date' => conference.end_date,
'registrationlink' => Rails.application.routes.url_helpers.conference_conference_registration_url(
conference.short_title, host: (ENV['OSEM_HOSTNAME'] || 'localhost:3000')),
conference.short_title, host: (ENV['OSEM_HOSTNAME'] || 'localhost:3000')
),
'conference_splash_link' => Rails.application.routes.url_helpers.conference_url(
conference.short_title, host: (ENV['OSEM_HOSTNAME'] || 'localhost:3000')),
conference.short_title, host: (ENV['OSEM_HOSTNAME'] || 'localhost:3000')
),
'schedule_link' => Rails.application.routes.url_helpers.conference_schedule_url(
conference.short_title, host: (ENV['OSEM_HOSTNAME'] || 'localhost:3000'))
conference.short_title, host: (ENV['OSEM_HOSTNAME'] || 'localhost:3000')
)
}
if conference.program.cfp
@ -43,12 +48,11 @@ class EmailSettings < ApplicationRecord
if event
h['eventtitle'] = event.title
h['proposalslink'] = Rails.application.routes.url_helpers.conference_program_proposals_url(
conference.short_title, host: (ENV['OSEM_HOSTNAME'] || 'localhost:3000'))
conference.short_title, host: (ENV['OSEM_HOSTNAME'] || 'localhost:3000')
)
end
if booth
h['booth_title'] = booth.title
end
h['booth_title'] = booth.title if booth
h
end
@ -71,8 +75,8 @@ class EmailSettings < ApplicationRecord
def parse_template(text, values)
values.each do |key, value|
if value.kind_of?(Date)
text = text.gsub "{#{key}}", value.strftime('%Y-%m-%d') unless text.blank?
if value.is_a?(Date)
text = text.gsub "{#{key}}", value.strftime('%Y-%m-%d') if text.present?
else
text = text.gsub "{#{key}}", value unless text.blank? || value.blank?
end

View file

@ -1,7 +1,9 @@
# frozen_string_literal: true
class Event < ApplicationRecord
include ActiveRecord::Transitions
include RevisionCount
has_paper_trail on: [:create, :update], ignore: [:updated_at, :guid, :week], meta: { conference_id: :conference_id }
has_paper_trail on: %i[create update], ignore: %i[updated_at guid week], meta: { conference_id: :conference_id }
acts_as_commentable
@ -61,10 +63,10 @@ class Event < ApplicationRecord
state :rejected
event :restart do
transitions to: :new, from: [:rejected, :withdrawn, :canceled]
transitions to: :new, from: %i[rejected withdrawn canceled]
end
event :withdraw do
transitions to: :withdrawn, from: [:new, :unconfirmed, :confirmed]
transitions to: :withdrawn, from: %i[new unconfirmed confirmed]
end
event :accept do
transitions to: :unconfirmed, from: [:new], on_transition: :process_acceptance
@ -73,7 +75,7 @@ class Event < ApplicationRecord
transitions to: :confirmed, from: :unconfirmed, on_transition: :process_confirmation
end
event :cancel do
transitions to: :canceled, from: [:unconfirmed, :confirmed]
transitions to: :canceled, from: %i[unconfirmed confirmed]
end
event :reject do
transitions to: :rejected, from: [:new], on_transition: :process_rejection
@ -108,7 +110,7 @@ class Event < ApplicationRecord
# ====Returns
# * +true+ -> If the event has votes (optionally, by the user)
# * +false+ -> If the event does not have any votes (optionally, by the user)
def voted?(user=nil)
def voted?(user = nil)
return votes.where(user: user).any? if user
votes.any?
@ -128,9 +130,7 @@ class Event < ApplicationRecord
def speakers_ordered
speakers_list = speakers.to_a
if speakers_list.reject! { |speaker| speaker == submitter }
speakers_list.unshift(submitter)
end
speakers_list.unshift(submitter) if speakers_list.reject! { |speaker| speaker == submitter }
speakers_list
end
@ -141,28 +141,26 @@ class Event < ApplicationRecord
def process_confirmation
if program.conference.email_settings.send_on_confirmed_without_registration? &&
program.conference.email_settings.confirmed_without_registration_body &&
program.conference.email_settings.confirmed_without_registration_subject
if program.conference.registrations.where(user_id: submitter.id).first.nil?
Mailbot.confirm_reminder_mail(self).deliver_later
end
program.conference.email_settings.confirmed_without_registration_body &&
program.conference.email_settings.confirmed_without_registration_subject
Mailbot.confirm_reminder_mail(self).deliver_later if program.conference.registrations.where(user_id: submitter.id).first.nil?
end
end
def process_acceptance(options)
if program.conference.email_settings.send_on_accepted &&
program.conference.email_settings.accepted_body &&
program.conference.email_settings.accepted_subject &&
!options[:send_mail].blank?
program.conference.email_settings.accepted_body &&
program.conference.email_settings.accepted_subject &&
options[:send_mail].present?
Mailbot.acceptance_mail(self).deliver_later
end
end
def process_rejection(options)
if program.conference.email_settings.send_on_rejected &&
program.conference.email_settings.rejected_body &&
program.conference.email_settings.rejected_subject &&
!options[:send_mail].blank?
program.conference.email_settings.rejected_body &&
program.conference.email_settings.rejected_subject &&
options[:send_mail].present?
Mailbot.rejection_mail(self).deliver_later
end
end
@ -186,28 +184,26 @@ class Event < ApplicationRecord
def update_state(transition, mail = false, subject = false, send_mail = false, send_mail_param)
alert = ''
if mail && send_mail_param && subject && send_mail
alert = 'Update Email Subject before Sending Mails'
end
begin
if mail
send(transition,
send_mail: send_mail_param)
else
send(transition)
end
save
# If the event was previously scheduled, and then withdrawn or cancelled
# its event_schedule will have enabled set to false
# If the event is now confirmed again, we want it to be available for scheduling
Rails.logger.debug "transition is #{transition}"
if transition == :confirm
Rails.logger.debug "schedules #{EventSchedule.unscoped.where(event: self, enabled: false)}"
EventSchedule.unscoped.where(event: self, enabled: false).destroy_all
end
rescue Transitions::InvalidTransition => e
alert = "Update state failed. #{e.message}"
alert = 'Update Email Subject before Sending Mails' if mail && send_mail_param && subject && send_mail
begin
if mail
send(transition,
send_mail: send_mail_param)
else
send(transition)
end
save
# If the event was previously scheduled, and then withdrawn or cancelled
# its event_schedule will have enabled set to false
# If the event is now confirmed again, we want it to be available for scheduling
Rails.logger.debug "transition is #{transition}"
if transition == :confirm
Rails.logger.debug "schedules #{EventSchedule.unscoped.where(event: self, enabled: false)}"
EventSchedule.unscoped.where(event: self, enabled: false).destroy_all
end
rescue Transitions::InvalidTransition => e
alert = "Update state failed. #{e.message}"
end
alert
end
@ -227,10 +223,10 @@ class Event < ApplicationRecord
{
registered: speakers.all? { |speaker| program.conference.user_registered? speaker },
commercials: commercials.any?,
biographies: speakers.all? { |speaker| !speaker.biography.blank? },
subtitle: !subtitle.blank?,
track: (!track.blank? unless program.tracks.empty?),
difficulty_level: !difficulty_level.blank?,
biographies: speakers.all? { |speaker| speaker.biography.present? },
subtitle: subtitle.present?,
track: (track.present? unless program.tracks.empty?),
difficulty_level: difficulty_level.present?,
title: true,
abstract: true
}.with_indifferent_access
@ -266,9 +262,7 @@ class Event < ApplicationRecord
event_schedules.find_by(schedule_id: selected_schedule_id).try(:start_time)
end
def conference
program.conference
end
delegate :conference, to: :program
private
@ -309,9 +303,11 @@ class Event < ApplicationRecord
end
def before_end_of_conference
errors
.add(:created_at, "can't be after the conference end date!") if program.conference && program.conference.end_date &&
(Date.today > program.conference.end_date)
if program.conference&.end_date &&
(Date.today > program.conference.end_date)
errors
.add(:created_at, "can't be after the conference end date!")
end
end
def conference_id
@ -322,7 +318,7 @@ class Event < ApplicationRecord
# Allow only confirmed tracks that belong to the same program as the event
#
def valid_track
return unless track && track.program && program
return unless track&.program && program
errors.add(:track, 'is invalid') unless track.confirmed? && track.program == program
end

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
class EventSchedule < ApplicationRecord
default_scope { where(enabled: true) }
belongs_to :schedule
@ -71,13 +73,9 @@ class EventSchedule < ApplicationRecord
def during_track
return unless event.try(:track) && start_time
if event.track.try(:start_date) && event.track.start_date > start_time
errors.add(:start_time, "can't be before the track's start date (#{event.track.start_date})")
end
errors.add(:start_time, "can't be before the track's start date (#{event.track.start_date})") if event.track.try(:start_date) && event.track.start_date > start_time
if event.track.try(:end_date) && event.track.end_date + 1.day < end_time
errors.add(:end_time, "can't be after the track's end date (#{event.track.end_date})")
end
errors.add(:end_time, "can't be after the track's end date (#{event.track.end_date})") if event.track.try(:end_date) && event.track.end_date + 1.day < end_time
end
##

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
class EventType < ApplicationRecord
belongs_to :program, touch: true
has_many :events, dependent: :restrict_with_error
@ -6,7 +8,7 @@ class EventType < ApplicationRecord
ignore: %i[updated_at]
validates :title, presence: true
validates :length, numericality: {greater_than: 0}
validates :length, numericality: { greater_than: 0 }
validates :minimum_abstract_length, presence: true
validates :maximum_abstract_length, presence: true
validate :length_step

View file

@ -1,6 +1,8 @@
# frozen_string_literal: true
class EventUser < ApplicationRecord
# TODO: Do we need these roles?
ROLES = [%w[Speaker speaker], %w[Submitter submitter], %w[Moderator moderator]]
ROLES = [%w[Speaker speaker], %w[Submitter submitter], %w[Moderator moderator]].freeze
belongs_to :event, touch: true
belongs_to :user

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
class EventsRegistration < ApplicationRecord
belongs_to :registration
belongs_to :event

Some files were not shown because too many files have changed in this diff Show more