Commit d5f9a1b9 authored by Mario Manno's avatar Mario Manno

add rubocop config and clean up code style

parent f3b432ab
# old ruby style syntax may still be needed
Style/HashSyntax:
Enabled: false
# never break line due to length, except in data
# vim: set wrap
Metrics/LineLength:
Max: 1024
# use and/or for flow control, but not in boolean assignments
# http://devblog.avdi.org/2010/08/02/using-and-and-or-in-ruby/
Style/AndOr:
Enabled: false
# use not with .select and flow control
Style/Not:
Enabled: false
# use self for clarity (args?)
Style/RedundantSelf:
Enabled: false
# Good cop, but to spammy
Style/StringLiterals:
Enabled: false
# use { only for single line blocks, but allow block content on its own line to keep line length short
# each { |l|
# l.apply_long_method_name
# }
Style/BlockDelimiters:
Enabled: false
# Do not use lambda
Style/Lambda:
Enabled: false
# allow TODO instead of requiring TODO:
Style/CommentAnnotation:
Enabled: false
# Can't decide on alignment, vim prefers fixed indent
Style/AlignParameters:
Enabled: false
EnforcedStyle: with_fixed_indentation
# Do not write 1234 as 1_234
Style/NumericLiterals:
Enabled: false
# Relax for controllers with multiple formats
Metrics/AbcSize:
Max: 40
# to spammy
Style/Documentation:
Enabled: false
jQuery ->
$("a[rel=popover]").popover()
$(".tooltip").tooltip()
$("a[rel=tooltip]").tooltip()
\ No newline at end of file
$("a[rel=tooltip]").tooltip()
......@@ -123,11 +123,11 @@ a.assoc {
textarea { height: auto; width: 420px; }
ul#unscheduled-events {
ul#unscheduled-events {
height: 400px;
}
}
div#add-event-modal {
overflow: auto;
overflow: auto;
}
p.availability span {
......@@ -160,4 +160,4 @@ p.availability span {
.dl-horizontal dd {
margin-left: 180px;
}
\ No newline at end of file
}
class ApplicationController < ActionController::Base
protect_from_forgery
before_filter :set_locale
before_action :set_locale
prepend_before_filter :load_conference
helper_method :current_user
......@@ -28,7 +28,7 @@ class ApplicationController < ActionController::Base
end
def set_locale
if %w{en de}.include?( params[:locale] )
if %w(en de).include?(params[:locale])
I18n.locale = params[:locale]
else
I18n.locale = 'en'
......@@ -39,29 +39,25 @@ class ApplicationController < ActionController::Base
def load_conference
if params[:conference_acronym]
@conference = Conference.find_by_acronym(params[:conference_acronym])
raise ActionController::RoutingError.new("Not found") unless @conference
elsif session.has_key?(:conference_acronym)
fail ActionController::RoutingError.new("Not found") unless @conference
elsif session.key?(:conference_acronym)
@conference = Conference.find_by_acronym(session[:conference_acronym])
elsif Conference.count > 0
@conference = Conference.current
end
unless @conference.nil?
session[:conference_acronym] = @conference.acronym
end
session[:conference_acronym] = @conference.acronym unless @conference.nil?
Time.zone = @conference.timezone if @conference
end
def info_for_paper_trail
{conference_id: @conference.id} if @conference
{ conference_id: @conference.id } if @conference
end
def default_url_options
result = {locale: params[:locale]}
if @conference
result.merge!(conference_acronym: @conference.acronym)
end
result = { locale: params[:locale] }
result.merge!(conference_acronym: @conference.acronym) if @conference
result
end
......
class AvailabilitiesController < ApplicationController
before_filter :authenticate_user!
before_filter :not_submitter!
before_filter :find_person
before_action :authenticate_user!
before_action :not_submitter!
before_action :find_person
def new
@availabilities = Availability.build_for(@conference)
......
class CallForParticipationsController < ApplicationController
before_filter :authenticate_user!
before_filter :not_submitter!
before_action :authenticate_user!
before_action :not_submitter!
load_and_authorize_resource
def show
......
class Cfp::AvailabilitiesController < ApplicationController
layout 'cfp'
before_filter :authenticate_user!
before_action :authenticate_user!
def new
authorize! :create, current_user.person
......@@ -16,7 +15,7 @@ class Cfp::AvailabilitiesController < ApplicationController
def update
authorize! :update, current_user.person
if params.has_key? :person
if params.key? :person
current_user.person.update_attributes_from_slider_form(person_params)
end
redirect_to cfp_root_path, notice: t("cfp.update_availability_notice")
......@@ -27,5 +26,4 @@ class Cfp::AvailabilitiesController < ApplicationController
def person_params
params.require(:person).permit(:first_name, :last_name, :public_name, :email, :email_public, :gender, :avatar, :abstract, :description, :include_in_mailings, availabilities_attributes: %i(id start_date end_date conference_id day_id))
end
end
class Cfp::ConfirmationsController < ApplicationController
layout "signup"
def new
......@@ -14,7 +13,7 @@ class Cfp::ConfirmationsController < ApplicationController
if @user and @user.send_confirmation_instructions(@conference)
redirect_to new_cfp_session_path, notice: t(:"cfp.confirmation_instructions_sent")
else
redirect_to new_cfp_user_confirmation_path, flash: {error: t(:"cfp.error_sending_confirmation_instructions")}
redirect_to new_cfp_user_confirmation_path, flash: { error: t(:"cfp.error_sending_confirmation_instructions") }
end
end
......@@ -28,5 +27,4 @@ class Cfp::ConfirmationsController < ApplicationController
redirect_to new_cfp_user_confirmation_path, error: t("cfp.error_confirming")
end
end
end
class Cfp::EventsController < ApplicationController
layout "cfp"
before_filter :authenticate_user!, except: :confirm
before_action :authenticate_user!, except: :confirm
# GET /cfp/events
# GET /cfp/events.xml
......@@ -10,9 +9,7 @@ class Cfp::EventsController < ApplicationController
authorize! :submit, Event
@events = current_user.person.events
unless @events.nil?
@events.map { |event| event.clean_event_attributes! }
end
@events.map(&:clean_event_attributes!) unless @events.nil?
respond_to do |format|
format.html { redirect_to cfp_person_path }
......@@ -72,9 +69,7 @@ class Cfp::EventsController < ApplicationController
@event = current_user.person.events.readonly(false).find(params[:id])
params[:event].delete('recording_license')
@event.recording_license = @event.conference.default_recording_license unless @event.recording_license
if @event.accepted?
params[:event].delete('do_not_record')
end
params[:event].delete('do_not_record') if @event.accepted?
respond_to do |format|
if @event.update_attributes(event_params)
......@@ -100,18 +95,16 @@ class Cfp::EventsController < ApplicationController
# Catch undefined method `person' for nil:NilClass exception if no confirmation token is found.
if event_person.nil?
return redirect_to cfp_root_path, flash:{ error: t('cfp.no_confirmation_token') }
return redirect_to cfp_root_path, flash: { error: t('cfp.no_confirmation_token') }
end
event_people = event_person.person.event_people.where(event_id: params[:id])
login_as(event_person.person.user) if event_person.person.user
else
raise "Unauthenticated" unless current_user
fail "Unauthenticated" unless current_user
event_people = current_user.person.event_people.where(event_id: params[:id])
end
event_people.each do |event_person|
event_person.confirm!
end
event_people.each(&:confirm!)
if current_user
redirect_to cfp_person_path, notice: t("cfp.thanks_for_confirmation")
else
......@@ -128,5 +121,4 @@ class Cfp::EventsController < ApplicationController
links_attributes: %i(id title url _destroy)
)
end
end
class Cfp::PasswordsController < ApplicationController
layout "signup"
def new
......@@ -40,5 +39,4 @@ class Cfp::PasswordsController < ApplicationController
render action: "edit"
end
end
end
class Cfp::PeopleController < ApplicationController
layout "cfp"
before_filter :authenticate_user!
before_filter :check_cfp_open
before_action :authenticate_user!
before_action :check_cfp_open
def show
@person = current_user.person
......@@ -79,5 +78,4 @@ class Cfp::PeopleController < ApplicationController
phone_numbers_attributes: %i(id phone_type phone_number _destroy)
)
end
end
class Cfp::SessionsController < SessionsController
layout 'signup'
before_filter :check_cfp_open
before_action :check_cfp_open
protected
def successful_sign_in_path
cfp_person_path
end
end
class Cfp::UsersController < ApplicationController
layout 'signup'
before_filter :authenticate_user!, only: [:edit, :update]
before_action :authenticate_user!, only: [:edit, :update]
def new
@user = User.new
......@@ -40,5 +39,4 @@ class Cfp::UsersController < ApplicationController
def user_params
params.require(:user).permit(:email, :password, :password_confirmation)
end
end
class Cfp::WelcomeController < ApplicationController
layout 'cfp'
def not_existing
@user = User.new
unless @conference.call_for_participation.nil?
redirect_to new_cfp_session_path
redirect_to new_cfp_session_path
end
end
def open_soon
@user = User.new
unless @conference.call_for_participation.start_date > Date.today
redirect_to new_cfp_session_path
redirect_to new_cfp_session_path
end
end
end
class ConferencesController < ApplicationController
# these methods don't need a conference
skip_before_filter :load_conference, only: [:new, :index, :create]
skip_before_action :load_conference, only: [:new, :index, :create]
before_filter :authenticate_user!
before_filter :not_submitter!
before_action :authenticate_user!
before_action :not_submitter!
load_and_authorize_resource
# GET /conferences
......@@ -77,7 +76,7 @@ class ConferencesController < ApplicationController
def default_notifications
locale = params[:code]
@notification = Notification.new(locale: locale)
@notification.set_default_text(locale)
@notification.default_text = locale
end
# DELETE /conferences/1
......@@ -99,20 +98,20 @@ class ConferencesController < ApplicationController
next if attribs.nil?
next unless attribs > 0
test = name.gsub("_attributes", '')
next unless %w{rooms days schedule tracks ticket_server }.include?(test)
next unless %w(rooms days schedule tracks ticket_server ).include?(test)
return "edit_#{test}"
}
return "edit"
"edit"
end
def search(params)
if params.has_key?(:term) and not params[:term].empty?
if params.key?(:term) and not params[:term].empty?
term = params[:term]
sort = params[:q][:s] rescue nil
@search = Event.ransack(title_cont: term,
acronym_cont: term,
m: 'or',
s: sort)
acronym_cont: term,
m: 'or',
s: sort)
else
@search = Conference.ransack(params[:q])
end
......@@ -131,5 +130,4 @@ class ConferencesController < ApplicationController
notifications_attributes: %i(id locale accept_subject accept_body reject_subject reject_body _destroy)
)
end
end
class EventFeedbacksController < ApplicationController
before_filter :authenticate_user!
before_filter :not_submitter!
before_action :authenticate_user!
before_action :not_submitter!
def index
authorize! :access, :event_feedback
@event = Event.find(params[:event_id])
@event_feedbacks = @event.event_feedbacks
end
end
class EventRatingsController < ApplicationController
before_filter :authenticate_user!
before_filter :not_submitter!
before_filter :find_event
before_action :authenticate_user!
before_action :not_submitter!
before_action :find_event
def show
authorize! :read, EventRating
......@@ -48,13 +47,11 @@ class EventRatingsController < ApplicationController
# filter according to users abilities
def find_event
@event = Event.find(params[:event_id])
if @event_ratings.nil?
@event_ratings = @event.event_ratings.accessible_by(current_ability)
end
return if @event_ratings
@event_ratings = @event.event_ratings.accessible_by(current_ability)
end
def event_rating_params
params.require(:event_rating).permit(:rating, :comment, :text)
end
end
class EventsController < ApplicationController
before_filter :authenticate_user!
before_filter :not_submitter!
after_filter :restrict_events
before_action :authenticate_user!
before_action :not_submitter!
after_action :restrict_events
# GET /events
# GET /events.xml
......@@ -52,7 +51,7 @@ class EventsController < ApplicationController
# total ratings:
@events_total = @conference.events.count
@events_reviewed_total = @conference.events.select{|e| e.event_ratings_count != nil and e.event_ratings_count > 0 }.count
@events_reviewed_total = @conference.events.count { |e| !e.event_ratings_count.nil? and e.event_ratings_count > 0 }
@events_no_review_total = @events_total - @events_reviewed_total
# current_user rated:
......@@ -175,7 +174,7 @@ class EventsController < ApplicationController
return redirect_to(@event, alert: "Cannot send mails: Please specify an email address for this conference.") unless @conference.email
return redirect_to(@event, alert: "Cannot send mails: Not all speakers have email addresses.") unless @event.speakers.all?{|s| s.email}
return redirect_to(@event, alert: "Cannot send mails: Not all speakers have email addresses.") unless @event.speakers.all?(&:email)
end
begin
......@@ -203,23 +202,17 @@ class EventsController < ApplicationController
private
def restrict_events
unless @events.nil?
@events = @events.accessible_by(current_ability)
end
@events = @events.accessible_by(current_ability) unless @events.nil?
end
def clean_events_attributes
return if can? :crud, Event
unless @event.nil?
@event.clean_event_attributes!
end
unless @events.nil?
@events.map { |event| event.clean_event_attributes! }
end
@event.clean_event_attributes! unless @event.nil?
@events.map(&:clean_event_attributes!) unless @events.nil?
end
def search(events, params)
if params.has_key?(:term) and not params[:term].empty?
if params.key?(:term) and not params[:term].empty?
term = params[:term]
sort = params[:q][:s] rescue nil
@search = events.ransack(title_cont: term,
......@@ -245,5 +238,4 @@ class EventsController < ApplicationController
event_people_attributes: %i(id person_id event_role role_state _destroy)
)
end
end
class HomeController < ApplicationController
before_filter :authenticate_user!
before_filter :not_submitter!
before_action :authenticate_user!
before_action :not_submitter!
def index
if Conference.count == 0
return redirect_to new_conference_path
end
return redirect_to new_conference_path if Conference.count == 0
if cannot? :read, Conference
# maybe a crew user tries to login to the wrong conference?
if current_user.is_crew?
conference = current_user.conference_users.map { |cu| cu.conference }.last
conference = current_user.conference_users.map(&:conference).last
return redirect_to conference_home_path(conference_acronym: conference.acronym) if conference.present?
end
return redirect_to cfp_root_path
......
class PeopleController < ApplicationController
before_filter :authenticate_user!
before_filter :not_submitter!
after_filter :restrict_people
before_action :authenticate_user!
before_action :not_submitter!
after_action :restrict_people
# GET /people
# GET /people.xml
......@@ -41,8 +40,8 @@ class PeopleController < ApplicationController
@current_events = @person.events_as_presenter_in(@conference)
@other_events = @person.events_as_presenter_not_in(@conference)
if cannot? :manage, Event
@current_events.map { |event| event.clean_event_attributes! }
@other_events.map { |event| event.clean_event_attributes! }
@current_events.map(&:clean_event_attributes!)
@other_events.map(&:clean_event_attributes!)
end
@availabilities = @person.availabilities.where("conference_id = #{@conference.id}")
......@@ -62,7 +61,7 @@ class PeopleController < ApplicationController
def attend
@person = Person.find(params[:id])
@person.set_role_state(@conference, 'attending')
return redirect_to action: :show
redirect_to action: :show
end
# GET /people/new
......@@ -137,13 +136,11 @@ class PeopleController < ApplicationController
private
def restrict_people
unless @people.nil?
@people = @people.accessible_by(current_ability)
end
@people = @people.accessible_by(current_ability) unless @people.nil?
end
def search(people, params)
if params.has_key?(:term) and not params[:term].empty?
if params.key?(:term) and not params[:term].empty?
term = params[:term]
sort = params[:q][:s] rescue nil
@search = people.ransack(first_name_cont: term,
......@@ -171,5 +168,4 @@ class PeopleController < ApplicationController
phone_numbers_attributes: %i(id phone_type phone_number _destroy)
)
end
end
class Public::FeedbackController < ApplicationController
layout "public_schedule"
def new
......@@ -24,5 +23,4 @@ class Public::FeedbackController < ApplicationController
def event_feedback_params
params.require(:event_feedback).permit(:rating, :comment)
end
end
class Public::ScheduleController < ApplicationController
layout 'public_schedule'
before_filter :maybe_authenticate_user!
before_action :maybe_authenticate_user!
def index
@days = @conference.days
......@@ -53,14 +52,14 @@ class Public::ScheduleController < ApplicationController
end
def events
@events = @conference.events.is_public.confirmed.scheduled.sort {|a,b|
@events = @conference.events.is_public.confirmed.scheduled.sort {|a, b|
a.to_sortable <=> b.to_sortable
}
end
def event
@event = @conference.events.is_public.confirmed.scheduled.find(params[:id])
@concurrent_events = @conference.events.is_public.confirmed.scheduled.where( start_time: @event.start_time )
@concurrent_events = @conference.events.is_public.confirmed.scheduled.where(start_time: @event.start_time)
respond_to do |format|
format.html
format.ics
......@@ -84,5 +83,4 @@ class Public::ScheduleController < ApplicationController
def maybe_authenticate_user!
authenticate_user! unless @conference.schedule_public
end
end
class RecentChangesController < ApplicationController
before_filter :authenticate_user!
before_filter :not_submitter!
before_action :authenticate_user!
before_action :not_submitter!
def index
authorize! :manage, CallForParticipation
......@@ -12,7 +11,7 @@ class RecentChangesController < ApplicationController
)
respond_to do |format|
format.html
format.xml { render xml: @all_versions }
format.xml { render xml: @all_versions }
end
end
......@@ -20,5 +19,4 @@ class RecentChangesController < ApplicationController
authorize! :manage, CallForParticipation
@version = PaperTrail::Version.where(conference_id: @conference.id, id: params[:id]).first
end
end
class ReportsController < ApplicationController
before_filter :authenticate_user!
before_filter :not_submitter!
before_action :authenticate_user!
before_action :not_submitter!
def index
end
......@@ -22,8 +21,8 @@ class ReportsController < ApplicationController
when 'lectures_with_speaker'
r</