Skip to content

Commit

Permalink
Autofix rubocop remarks
Browse files Browse the repository at this point in the history
  • Loading branch information
TomNaessens committed Jul 2, 2015
1 parent 33e806c commit 3f0c530
Show file tree
Hide file tree
Showing 58 changed files with 320 additions and 397 deletions.
4 changes: 1 addition & 3 deletions app/controllers/access_levels_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
class AccessLevelsController < ApplicationController

before_filter :authenticate_user!, except: [:show, :new]

respond_to :html, :js
Expand Down Expand Up @@ -58,12 +57,11 @@ def toggle_visibility
@event = Event.find params.require(:event_id)
authorize! :update, @event
@access_level = AccessLevel.find params.require(:id)
@access_level.hidden = not(@access_level.hidden)
@access_level.hidden = not@access_level.hidden
@access_level.save
end

def parse_advanced
@advanced = params[:advanced] == 'true'
end

end
5 changes: 2 additions & 3 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class ApplicationController < ActionController::Base
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception

after_filter :store_location
after_action :store_location

def store_location
# store last url as long as it isn't a /users path
Expand All @@ -15,7 +15,7 @@ def store_location
redirect_to root_path
end

def after_sign_in_path_for(resource)
def after_sign_in_path_for(_resource)
session[:previous_url] || root_path
end

Expand All @@ -26,5 +26,4 @@ def current_ability
@current_ability ||= Ability.new(current_user)
end
end

end
28 changes: 12 additions & 16 deletions app/controllers/events_controller.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
# encoding: UTF-8

class EventsController < ApplicationController

# order is important here, we need to be authenticated before we can check permission
before_filter :authenticate_user!, except: [:show, :index]
before_action :authenticate_user!, except: [:show, :index]
load_and_authorize_resource only: [:new, :show, :update, :edit, :destroy]

respond_to :html, :js, :ics

def index
@events = Event.where('end_date > ?', DateTime.now).order(:name)
if user_signed_in?
@events += Event.accessible_by(current_ability).to_a
end
@events += Event.accessible_by(current_ability).to_a if user_signed_in?
@events.uniq!
end

Expand All @@ -34,7 +31,7 @@ def update
authorize! :update, @event

if @event.update params.require(:event).permit(:name, :club_id, :location, :website, :contact_email, :start_date, :end_date, :description, :bank_number, :registration_close_date, :registration_open_date, :show_ticket_count)
flash.now[:success] = "Successfully updated event."
flash.now[:success] = 'Successfully updated event.'
end

render action: :edit
Expand All @@ -61,17 +58,17 @@ def statistics
@event = Event.find params.require(:id)
authorize! :view_stats, @event

if not @event.tickets.empty?
if !@event.tickets.empty?

min, max = @event.tickets.pluck(:created_at).minmax
zeros = Hash[]
while min <= max
zeros[min.strftime("%Y-%m-%d")] = 0
zeros[min.strftime('%Y-%m-%d')] = 0
min += 1.day
end

@data = @event.access_levels.map do |al|
{name: al.name, data: zeros.merge(al.tickets.group('date(tickets.created_at)').count)}
{ name: al.name, data: zeros.merge(al.tickets.group('date(tickets.created_at)').count) }
end

else
Expand All @@ -92,17 +89,17 @@ def check_in
@ticket = @event.tickets.find_by_barcode barcode

if @ticket
if not @ticket.order.is_paid
flash.now[:warning] = "Person has not paid yet! Resting amount: €" + @ticket.order.to_pay.to_s
if !@ticket.order.is_paid
flash.now[:warning] = 'Person has not paid yet! Resting amount: €' + @ticket.order.to_pay.to_s
elsif @ticket.checked_in_at
flash.now[:warning] = "Person already checked in at " + view_context.nice_time(@ticket.checked_in_at) + "!"
flash.now[:warning] = 'Person already checked in at ' + view_context.nice_time(@ticket.checked_in_at) + '!'
else
flash.now[:success] = "Person has been scanned!"
flash.now[:success] = 'Person has been scanned!'
@ticket.checked_in_at = Time.now
@ticket.save!
end
else
flash.now[:error] = "Barcode not found"
flash.now[:error] = 'Barcode not found'
end

render action: :scan
Expand All @@ -121,9 +118,8 @@ def export_status
def generate_export
@event = Event.find params.require(:id)
authorize! :read, @event
@event.export_status = "generating"
@event.export_status = 'generating'
@event.save
@event.generate_xls
end

end
4 changes: 1 addition & 3 deletions app/controllers/orders/build_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ def update
@event = Event.find params.require(:event_id)
@order = @event.orders.find params.require(:order_id)


case step
when :add_tickets
@access_levels = @event.access_levels.find_all { |al| can? :show, al }
Expand All @@ -53,7 +52,7 @@ def update
when :add_ticket_info
@tickets = @order.tickets
params.require(:tickets).each do |id, ticket|
@tickets.find(id).update_columns ticket.merge({ status: 'filled_in' })
@tickets.find(id).update_columns ticket.merge(status: 'filled_in')
end
when :confirmation
@order.deliver
Expand All @@ -65,5 +64,4 @@ def update

render_wizard @order
end

end
18 changes: 6 additions & 12 deletions app/controllers/orders_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
class OrdersController < ApplicationController

before_action :authenticate_user!, only: [:index, :destroy, :resend, :update, :email, :upload]

require 'csv'
Expand All @@ -12,7 +11,7 @@ def index
authorize! :read, @event

@ordersgrid = OrdersGrid.new(params[:orders_grid]) do |scope|
scope.where(event_id: @event.id).order("orders.price - paid DESC")
scope.where(event_id: @event.id).order('orders.price - paid DESC')
end

@orders = @ordersgrid.assets
Expand Down Expand Up @@ -50,7 +49,7 @@ def create
# Check if the user can register
authorize! :register, @event

render "events/show"
render 'events/show'
end

def update
Expand All @@ -59,9 +58,7 @@ def update

paid = @order.paid
@order.update params.require(:order).permit(:to_pay)
if @order.paid != paid # Did the amount change?
@order.deliver
end
@order.deliver if @order.paid != paid # Did the amount change?

respond_with @order
end
Expand All @@ -87,7 +84,6 @@ def upload

begin
CSV.parse(params.require(:csv_file).read.upcase, col_sep: sep, headers: :first_row) do |row|

order = Order.find_payment_code_from_csv(row.to_s)
# If the order doesn't exist
unless order
Expand All @@ -113,10 +109,10 @@ def upload
counter += 1
end

success_msg = "Updated #{ActionController::Base.helpers.pluralize counter, "payment"} successfully."
success_msg = "Updated #{ActionController::Base.helpers.pluralize counter, 'payment'} successfully."
if fails.any?
flash.now[:success] = success_msg
flash.now[:error] = "The rows listed below contained an invalid code, please fix them by hand."
flash.now[:error] = 'The rows listed below contained an invalid code, please fix them by hand.'
@csvheaders = fails.first.headers
@csvfails = fails
render 'upload'
Expand All @@ -125,10 +121,8 @@ def upload
redirect_to action: :index
end
rescue CSV::MalformedCSVError
flash[:error] = "The file could not be parsed. Make sure that you uploaded the correct file and that the column seperator settings have been set to the correct seperator."
flash[:error] = 'The file could not be parsed. Make sure that you uploaded the correct file and that the column seperator settings have been set to the correct seperator.'
redirect_to action: :index
end

end

end
24 changes: 11 additions & 13 deletions app/controllers/partners_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
class PartnersController < ApplicationController

before_action :authenticate_user!, except: [:show, :confirm]
before_action :authenticate_partner!, only: [:show, :confirm]

Expand Down Expand Up @@ -79,29 +78,29 @@ def confirm
authorize! :register, @partner

if @partner.confirmed
flash.now[:error] = "You have already registered for this event. Please check your mailbox."
flash.now[:error] = 'You have already registered for this event. Please check your mailbox.'
else
@order = @event.orders.new(
name: @partner.name,
email: @partner.email,
price: @partner.access_level.price,
paid: 0,
paid: 0
)
@ticket = @order.tickets.new(
name: @partner.name,
email: @partner.email,
student_number: nil,
comment: nil,
access_level: @partner.access_level,
event: @event,
event: @event
)
@partner.confirmed = true

if @ticket.save and @order.save and @partner.save then
if @ticket.save && @order.save && @partner.save
@order.deliver
flash.now[:success] = "Your invitation has been confirmed. Your ticket should arrive shortly."
flash.now[:success] = 'Your invitation has been confirmed. Your ticket should arrive shortly.'
else
flash.now[:error] = "Is seems there already is someone with your name and/or email registered for this event. #{view_context.mail_to @event.contact_email, "Contact us"} if this is not correct.".html_safe
flash.now[:error] = "Is seems there already is someone with your name and/or email registered for this event. #{view_context.mail_to @event.contact_email, 'Contact us'} if this is not correct.".html_safe
end
end
end
Expand All @@ -110,7 +109,7 @@ def upload
@event = Event.find params.require(:event_id)
authorize! :update, @event

headers = ['name', 'email', 'error']
headers = %w(name email error)

sep = params.require(:upload).require(:separator)
al = @event.access_levels.find params.require(:upload).require(:access_level)
Expand All @@ -136,10 +135,10 @@ def upload
counter += 1
end

success_msg = "Added #{ActionController::Base.helpers.pluralize counter, "partners"} successfully."
success_msg = "Added #{ActionController::Base.helpers.pluralize counter, 'partners'} successfully."
if fails.any?
flash.now[:success] = success_msg unless counter == 0
flash.now[:error] = "The rows listed below contained errors, please fix them by hand."
flash.now[:error] = 'The rows listed below contained errors, please fix them by hand.'
@csvheaders = headers
@csvfails = fails
render 'upload'
Expand All @@ -149,12 +148,11 @@ def upload
end

rescue CSV::MalformedCSVError
flash[:error] = "The file could not be parsed. Make sure that you uploaded the correct file and that the column seperator settings have been set to the correct seperator."
flash[:error] = 'The file could not be parsed. Make sure that you uploaded the correct file and that the column seperator settings have been set to the correct seperator.'
redirect_to action: :index
rescue ActionController::ParameterMissing
flash[:error] = "Please upload a CSV file."
flash[:error] = 'Please upload a CSV file.'
redirect_to action: :index
end
end

end
6 changes: 2 additions & 4 deletions app/controllers/promos_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
class PromosController < ApplicationController

before_action :authenticate_user!, except: [:show, :confirm]

respond_to :html, :js
Expand Down Expand Up @@ -61,15 +60,14 @@ def generate
access_levels = @event.access_levels.find(params[:access_levels].split(',')) rescue []

if amount <= 0 || limit <= 0
flash[:error] = "Amount and Maximum uses should be greater than zero!"
flash[:error] = 'Amount and Maximum uses should be greater than zero!'
redirect_to event_promos_path(@event)
elsif access_levels.blank?
flash[:error] = "Tickets should be specified"
flash[:error] = 'Tickets should be specified'
redirect_to event_promos_path(@event)
else
Promo.generate_bulk(amount, limit, access_levels, @event)
redirect_to event_promos_path(@event)
end
end

end
8 changes: 3 additions & 5 deletions app/controllers/sign_in_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
class SignInController < ApplicationController

before_action :authenticate_partner_from_token!
before_action :authenticate_partner!

Expand All @@ -16,8 +15,8 @@ def authenticate_partner_from_token!

# Set the authentication token params if not already present,
# see http://stackoverflow.com/questions/11017348/rails-api-authentication-by-headers-token
params_token_name = "partner_token".to_sym
params_email_name = "partner_email".to_sym
params_token_name = 'partner_token'.to_sym
params_email_name = 'partner_email'.to_sym

email = params[params_email_name].presence
token = params[params_token_name].presence
Expand All @@ -27,8 +26,7 @@ def authenticate_partner_from_token!
if partner
sign_in partner, store: SimpleTokenAuthentication.sign_in_token
else
flash[:error] = "Something went wrong. Make sure you click the link or copy the whole link (including parameters)! #{view_context.mail_to @event.contact_email, "Contact us"} if the problem persists.".html_safe
flash[:error] = "Something went wrong. Make sure you click the link or copy the whole link (including parameters)! #{view_context.mail_to @event.contact_email, 'Contact us'} if the problem persists.".html_safe
end
end

end
2 changes: 0 additions & 2 deletions app/controllers/tickets_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
class TicketsController < ApplicationController

before_action :authenticate_user!, only: [:index, :destroy, :resend, :update, :email, :upload]

require 'csv'
Expand Down Expand Up @@ -64,5 +63,4 @@ def email
MassMailer.general_message(@event.contact_email, to, params['email']['subject'], params['email']['body']).deliver
redirect_to event_tickets_path(@event)
end

end
12 changes: 6 additions & 6 deletions app/grids/orders_grid.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ class OrdersGrid
end

# We use the lower() instead of ilike because SQLite dev doesn't like ilike
filter(:name) { |value| where("lower(orders.name) like ?", "%#{value.downcase}%") }
filter(:email) { |value| where("lower(orders.email) like ?", "%#{value.downcase}%") }
filter(:payment_code) { |value| where("orders.payment_code like ?","%#{value}%") }
filter(:only_paid) { |value| where("paid = price") if value == '1' }
filter(:only_unpaid) { |value| where.not("paid = price") if value == '1' }
filter(:name) { |value| where('lower(orders.name) like ?', "%#{value.downcase}%") }
filter(:email) { |value| where('lower(orders.email) like ?', "%#{value.downcase}%") }
filter(:payment_code) { |value| where('orders.payment_code like ?', "%#{value}%") }
filter(:only_paid) { |value| where('paid = price') if value == '1' }
filter(:only_unpaid) { |value| where.not('paid = price') if value == '1' }

column(:name)
column(:email)
column(:payment_code)
column(:to_pay, html: true, order: "orders.price - paid", descending: true) do |order|
column(:to_pay, html: true, order: 'orders.price - paid', descending: true) do |order|
render partial: 'order_payment_form', locals: { order: order }
end
column(:actions, html: true) do |order|
Expand Down
Loading

0 comments on commit 3f0c530

Please sign in to comment.