Unverified Commit cf21b931 authored by azul's avatar azul
Browse files

style: rubocop autocorrect

parent 22345d04
AllCops:
Exclude:
- 'bin/*'
DisplayCopNames: true
Layout/IndentHeredoc:
EnforcedStyle: active_support
Style/AndOr:
AutoCorrect: false
Style/EmptyElse:
AutoCorrect: false
Style/RaiseArgs:
AutoCorrect: false
......@@ -3,6 +3,6 @@ load 'deploy' if respond_to?(:namespace) # cap2 differentiator
# Uncomment if you are using Rails' asset pipeline
# load 'deploy/assets'
Dir['vendor/gems/*/recipes/*.rb','vendor/plugins/*/recipes/*.rb'].each { |plugin| load(plugin) }
Dir['vendor/gems/*/recipes/*.rb', 'vendor/plugins/*/recipes/*.rb'].each { |plugin| load(plugin) }
load 'config/deploy' # remove this line to skip loading any of the default tasks
\ No newline at end of file
load 'config/deploy' # remove this line to skip loading any of the default tasks
......@@ -2,11 +2,10 @@ source 'https://rubygems.org'
# ensure github urls use https rather than insecure git protocol.
git_source(:github) do |repo_name|
repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?('/')
"https://github.com/#{repo_name}.git"
end
##
# Core components
##
......@@ -55,7 +54,7 @@ gem 'prototype-rails', github: 'rails/prototype-rails', branch: '4.2'
# legacy helper for form_remote_for and link_to_remote
# there's only a 0.0.0 version out there it seems
gem 'prototype_legacy_helper', '0.0.0',
github: 'rails/prototype_legacy_helper'
github: 'rails/prototype_legacy_helper'
##
# Upgrade pending
......@@ -101,7 +100,7 @@ gem 'will_paginate', '~> 3.1'
# state-machine for requests
# locking in to latest major to fix API
gem 'aasm' , '~> 3.4'
gem 'aasm', '~> 3.4'
# lists used for tasks and choices in votes so far
# continuation of the old standart rails plugin
......@@ -128,7 +127,7 @@ gem 'RedCloth', '~> 4.2'
# extension of the redcloth markup lang
gem 'greencloth', require: 'greencloth',
path: 'vendor/gems/riseuplabs-greencloth-0.1'
path: 'vendor/gems/riseuplabs-greencloth-0.1'
# media upload post processing has it's own repo
# version is rather strict for now as api may still change.
......@@ -190,7 +189,6 @@ group :test, :development do
end
group :test, :ci do
##
## TESTS
##
......@@ -224,4 +222,3 @@ group :test, :ci do
end
gem 'bundler-audit'
......@@ -6,7 +6,7 @@ unless Vagrant.has_plugin?('vagrant-vbguest')
end
VAGRANTFILE_API_VERSION = 2
SPHINX_DEV_CONF_PATH = 'config/sphinx/development.conf'
SPHINX_DEV_CONF_PATH = 'config/sphinx/development.conf'.freeze
ruby_version_file = File.join(File.dirname(__FILE__), '.ruby-version')
RUBY_VER = File.exist?(ruby_version_file) ? File.read(ruby_version_file) : '2.1.5'
......@@ -56,7 +56,7 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
SHELL
config.vm.provision "Install RVM and Ruby #{RUBY_VER} and Bundler",
type: 'shell', privileged: false, inline: <<-SHELL
type: 'shell', privileged: false, inline: <<-SHELL
gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 > /dev/null 2>&1
curl -sSL https://get.rvm.io | bash -s stable > /dev/null 2>&1
source $HOME/.rvm/scripts/rvm
......@@ -111,13 +111,13 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
SHELL
config.vm.provision 'Start Thinking Sphinx', run: 'always', type: 'shell',
privileged: false, inline: <<-SHELL
privileged: false, inline: <<-SHELL
cd /vagrant/
rake ts:start > /dev/null 2>&1
SHELL
config.vm.provision 'PROVISIONING COMPLETE!', run: 'always', type: 'shell',
privileged: false, inline: <<-SHELL
privileged: false, inline: <<-SHELL
echo -e '\nTo run the server:\n'
echo -e '\n vagrant ssh\n'
echo -e '\n cd /vagrant/\n'
......@@ -127,4 +127,3 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vbguest.auto_reboot = true
config.vbguest.auto_update = true
end
......@@ -7,7 +7,6 @@
#
class AccountsController < ApplicationController
layout 'notice'
##
......@@ -43,9 +42,6 @@ class AccountsController < ApplicationController
# removed
##
## PASSWORD RESET
##
......@@ -81,7 +77,7 @@ class AccountsController < ApplicationController
user_params[:email] = session[:signup_email_address]
end
user_params.permit :login, :email, :password, :password_confirmation,
:language, :display_name
:language, :display_name
end
def reset_password_form
......@@ -100,7 +96,7 @@ class AccountsController < ApplicationController
return
end
sleep(rand*3) # an attempt to make timing attacks harder
sleep(rand * 3) # an attempt to make timing attacks harder
user = User.find_by_email params[:email]
if user
......@@ -147,5 +143,4 @@ class AccountsController < ApplicationController
return false
end
end
end
......@@ -2,10 +2,9 @@
# Likewise, all the methods added will be available for all controllers.
class ApplicationController < ActionController::Base
protect_from_forgery
layout proc{ |c| c.request.xhr? ? false : 'application' } # skip layout for ajax
layout proc { |c| c.request.xhr? ? false : 'application' } # skip layout for ajax
hide_action :_layout_from_proc
include_controllers 'common/application'
......@@ -20,7 +19,9 @@ class ApplicationController < ActionController::Base
# this is used by the code that is included for both controllers and helpers.
# this way, they don't need to know if they are in a view or a controller,
# they can always just reference controller().
def controller(); self; end
def controller
self
end
# view() method lets controllers have access to the view helpers.
def view
......@@ -29,7 +30,7 @@ class ApplicationController < ActionController::Base
# proxy for view's content_tag
def content_tag(*args, &block)
view.content_tag(*args,&block)
view.content_tag(*args, &block)
end
#
......@@ -37,18 +38,19 @@ class ApplicationController < ActionController::Base
# overridden, but these defaults are pretty good. See models/mailer.rb.
#
def mailer_options
from_address = current_site.email_sender.
sub('$current_host',request.host)
from_name = current_site.email_sender_name.
sub('$user_name', current_user.display_name).
sub('$site_title', current_site.title)
from_address = current_site.email_sender
.sub('$current_host', request.host)
from_name = current_site.email_sender_name
.sub('$user_name', current_user.display_name)
.sub('$site_title', current_site.title)
opts = {
site: current_site, current_user: current_user,
host: request.host, protocol: request.protocol,
page: @page, from_address: from_address,
from_name: from_name }
opts[:port] = request.port_string.sub(':','') if request.port_string.present?
return opts
site: current_site, current_user: current_user,
host: request.host, protocol: request.protocol,
page: @page, from_address: from_address,
from_name: from_name
}
opts[:port] = request.port_string.sub(':', '') if request.port_string.present?
opts
end
##
......@@ -76,7 +78,7 @@ class ApplicationController < ActionController::Base
# as needed stylesheets are kept in public/stylesheets/as_needed
#
def self.stylesheet(*css_files)
self.stylesheets = merge_requirements(self.stylesheets, *css_files)
self.stylesheets = merge_requirements(stylesheets, *css_files)
end
# We currently include all javascript in application.js as it's cached,
......@@ -93,7 +95,7 @@ class ApplicationController < ActionController::Base
# They'll be accessible in the class_attribute javascripts
#
def self.javascript(*js_files)
self.javascripts = merge_requirements(self.javascripts, *js_files)
self.javascripts = merge_requirements(javascripts, *js_files)
end
def self.merge_requirements(current, *new_files)
......@@ -104,5 +106,4 @@ class ApplicationController < ActionController::Base
value += new_files
current.merge index => value.uniq
end
end
class AssetsController < ApplicationController
before_filter :authorization_required
before_filter :symlink_public_asset, only: :show
permissions 'assets'
permission_helper 'pages'
guard :may_ACTION_asset?
prepend_before_filter :fetch_asset, only: [:show, :destroy]
prepend_before_filter :fetch_asset, only: %i[show destroy]
def show
file = file_to_send
send_file private_filename(file),
type: file.content_type,
disposition: disposition(file)
type: file.content_type,
disposition: disposition(file)
end
def destroy
@asset.destroy
current_user.updated(@page)
respond_to do |format|
format.js {render 'common/assets/destroy' }
format.js { render 'common/assets/destroy' }
format.html do
success ['attachment deleted']
redirect_to(page_url(@page))
......@@ -76,13 +75,13 @@ class AssetsController < ApplicationController
def thumb_name
if params[:path] =~ /#{THUMBNAIL_SEPARATOR}(?<thumb>[a-z]+)$/
$~['thumb'].to_sym
$LAST_MATCH_INFO['thumb'].to_sym
end
end
# returns 'inline' for formats that web browsers can display, 'attachment' otherwise.
def disposition(asset)
if ['image/png','image/jpeg','image/gif'].include? asset.content_type
if ['image/png', 'image/jpeg', 'image/gif'].include? asset.content_type
'inline'
else
'attachment'
......@@ -94,6 +93,4 @@ class AssetsController < ApplicationController
def private_filename(asset_or_thumbnail)
asset_or_thumbnail.private_filename
end
end
......@@ -14,12 +14,12 @@ class AvatarsController < ApplicationController
@image = Avatar.find_by_id params[:id]
if @image.nil?
size = Avatar.pixels(params[:size])
size.sub!(/^\d*x/,'')
size.sub!(/^\d*x/, '')
filename = "#{File.dirname(__FILE__)}/../../public/images/default/#{size}.jpg"
send_data(IO.read(filename), type: 'image/jpeg', disposition: 'inline')
else
content_type = 'image/jpeg'
data = @image.resize(params[:size], content_type);
data = @image.resize(params[:size], content_type)
response.headers['Cache-Control'] = 'public, max-age=86400'
send_data data, type: content_type, disposition: 'inline'
end
......@@ -30,8 +30,7 @@ class AvatarsController < ApplicationController
# if public/avatars is a symlink resolve it and use it's parent dir
def self.page_cache_directory
default = super
cache_dir = (Pathname.new(default) + self.controller_name)
cache_dir = (Pathname.new(default) + controller_name)
cache_dir.exist? ? cache_dir.realpath.dirname : default
end
end
......@@ -14,5 +14,4 @@ module Common::AlwaysPerformCaching
true
end
end
end
......@@ -48,8 +48,6 @@
require 'active_support/multibyte/chars'
module Common::Application::AlertMessages
def self.included(base)
base.class_eval do
helper_method :translate_exception
......@@ -79,13 +77,13 @@ module Common::Application::AlertMessages
end
def alert_message(*args)
options = Hash[args.collect {|i| [i, true] if i.is_a?(Symbol)}.compact]
options = Hash[args.collect { |i| [i, true] if i.is_a?(Symbol) }.compact]
type = determine_type(options)
flsh = determine_flash(type, options)
flsh[:messages] ||= []
add_flash(type, *args).each do |msg|
# allow options to override the defaults
flsh[:messages] << msg.merge(options);
flsh[:messages] << msg.merge(options)
end
end
......@@ -93,7 +91,7 @@ module Common::Application::AlertMessages
# forces the alert messages to come later, even if we previously said :now.
# this is used in case we did :now but then redirected later.
#
def force_later_alert()
def force_later_alert
flash[:messages] = flash.now[:messages]
end
......@@ -110,7 +108,7 @@ module Common::Application::AlertMessages
# At the same time redirect would alter the url in the users browser.
# Maybe they just typed it wrong. So we better leave it there.
#
def raise_not_found(thing=nil)
def raise_not_found(thing = nil)
raise ErrorNotFound.new(thing)
end
......@@ -121,13 +119,13 @@ module Common::Application::AlertMessages
##
def add_flash(type, *args)
if exception = args.detect{|a|a.is_a? Exception}
if exception = args.detect { |a| a.is_a? Exception }
add_flash_exception(exception)
elsif record = args.detect{|a|a.is_a? ActiveRecord::Base}
elsif record = args.detect { |a| a.is_a? ActiveRecord::Base }
add_flash_record(record, args.extract_options!)
elsif (messages = args.select{|a| a.is_a?(String) or a.is_a?(ActiveSupport::Multibyte::Chars)}).any?
elsif (messages = args.select { |a| a.is_a?(String) or a.is_a?(ActiveSupport::Multibyte::Chars) }).any?
add_flash_message(type, messages)
elsif message_array = args.detect{|a| a.is_a?(Array)}
elsif message_array = args.detect { |a| a.is_a?(Array) }
add_flash_message(type, message_array)
else
add_flash_default(type)
......@@ -135,41 +133,41 @@ module Common::Application::AlertMessages
end
def add_flash_message(type, message)
[{type: type, text: message}]
[{ type: type, text: message }]
end
def add_flash_default(type)
msg = if(type == :error or type == :warning)
:alert_not_saved.t;
else
:alert_saved.t;
msg = if type == :error or type == :warning
:alert_not_saved.t
else
:alert_saved.t
end
add_flash_message(type, msg)
end
def add_flash_exception(exception)
if exception.is_a? PermissionDenied
[{type: :warning, text: [:alert_permission_denied.t, :permission_denied_description.t]}]
[{ type: :warning, text: [:alert_permission_denied.t, :permission_denied_description.t] }]
elsif exception.is_a? AuthenticationRequired
[{type: :notice, text: [:login_required.t, :login_required_description.t]}]
[{ type: :notice, text: [:login_required.t, :login_required_description.t] }]
elsif exception.is_a? ErrorMessages
exception.errors.collect do |msg|
{type: :error, text: msg}
{ type: :error, text: msg }
end
elsif exception.is_a? ActiveRecord::RecordInvalid
add_flash_record(exception.record)
elsif exception.is_a? CrabgrassException
[{type: exception.options[:type] || :error, text: exception.message}]
[{ type: exception.options[:type] || :error, text: exception.message }]
else
text = exception.respond_to?(:message) ? exception.message : exception
[{type: :error, text: text.to_s}]
text = exception.respond_to?(:message) ? exception.message : exception
[{ type: :error, text: text.to_s }]
end
end
def add_flash_record(record, options = {})
if record.respond_to?(:flash_message) && record.flash_message
options[:count] ||= 1
[ record.flash_message(options) ]
[record.flash_message(options)]
elsif record.errors.any?
[{ type: :error,
text: [:alert_not_saved.t, :alert_field_errors.t],
......@@ -217,27 +215,26 @@ module Common::Application::AlertMessages
I18n.t key, scope: scope, thing: thing, cascade: true
end
# def exception_detailed_message(exception=nil)
# return "Warning: Trying to get detailed message but no exception given." unless exception
# message = exception.clean_message
# file, line = exception.backtrace.first.split(":")[0, 2]
# if File.exists?(file)
# message << "\n\n"
# code = File.readlines(file)
# line = line.to_i
# min = [line - 2, 0].max
# max = line + 2
# (min..max).each do |n|
# if n == line
# message << "=> "
# else
# message << " "
# end
# message << ("%4d" % n)
# message << code[n].to_s
# end
# end
# message
# end
# def exception_detailed_message(exception=nil)
# return "Warning: Trying to get detailed message but no exception given." unless exception
# message = exception.clean_message
# file, line = exception.backtrace.first.split(":")[0, 2]
# if File.exists?(file)
# message << "\n\n"
# code = File.readlines(file)
# line = line.to_i
# min = [line - 2, 0].max
# max = line + 2
# (min..max).each do |n|
# if n == line
# message << "=> "
# else
# message << " "
# end
# message << ("%4d" % n)
# message << code[n].to_s
# end
# end
# message
# end
end
module Common::Application::Authentication
def self.included(base)
base.send :helper_method, :current_user, :logged_in?
end
......@@ -80,8 +79,8 @@ module Common::Application::Authentication
if user && user.remember_token?
user.remember_me
self.current_user = user
cookies[:auth_token] = { value: self.current_user.remember_token , expires: self.current_user.remember_token_expires_at }
flash[:notice] = "Logged in successfully"
cookies[:auth_token] = { value: current_user.remember_token, expires: current_user.remember_token_expires_at }
flash[:notice] = 'Logged in successfully'
end
end
......@@ -103,20 +102,17 @@ module Common::Application::Authentication
private
@@http_auth_headers = %w(X-HTTP_AUTHORIZATION HTTP_AUTHORIZATION Authorization)
@@http_auth_headers = %w[X-HTTP_AUTHORIZATION HTTP_AUTHORIZATION Authorization]
# gets BASIC auth info
def get_auth_data
auth_key = @@http_auth_headers.detect { |h| request.env.has_key?(h) }
auth_key = @@http_auth_headers.detect { |h| request.env.key?(h) }
auth_data = request.env[auth_key].to_s.split unless auth_key.blank?
return auth_data && auth_data[0] == 'Basic' ? Base64.decode64(auth_data[1]).split(':')[0..1] : [nil, nil]
auth_data && auth_data[0] == 'Basic' ? Base64.decode64(auth_data[1]).split(':')[0..1] : [nil, nil]
end
def load_user(id)
user = User.find_by_id(id)
if user
user.seen!
end
return user
user.seen! if user
user
end
end
......@@ -84,9 +84,7 @@ module Common::Application::BeforeFilters
# sets the current locale
#
def set_session_locale
if !language_allowed?(session[:language_code])
session[:language_code] = nil
end
session[:language_code] = nil unless language_allowed?(session[:language_code])
session[:language_code] ||= discover_language_code
I18n.locale = session[:language_code].to_sym
end
......@@ -153,9 +151,9 @@ module Common::Application::BeforeFilters
'en'
elsif !logged_in? || current_user.language.empty?
if Conf.enabled_languages.any?
code = http_accept_language.compatible_language_from(Conf.enabled_languages)
code = http_accept_language.compatible_language_from(Conf.enabled_languages)
else
code = http_accept_language.user_preferred_languages.first
code = http_accept_language.user_preferred_languages.first
end
code ||= current_site.default_language
code ||= 'en'
......@@ -166,6 +164,4 @@ module Common::Application::BeforeFilters
'en'
end
end
end
......@@ -4,8 +4,6 @@
#
module Common::Application::ContextNavigation
def self.included(base)
base.class_eval do
helper_method :setup_navigation
......@@ -19,8 +17,7 @@ module Common::Application::ContextNavigation
##
def setup_navigation(nav)
return nav
nav
# this can be implemented by controller subclasses
end
end
module Common::Application::CurrentSite
def self.included(base)
base.class_eval do
# make current_site available to the views
helper_method :current_site
if Rails.env.test?
hide_action :disable_current_site, :enable_current_site
end
hide_action :disable_current_site, :enable_current_site if Rails.env.test?
end
end
......@@ -36,5 +33,4 @@ module Common::Application::CurrentSite
@current_site_disabled = false
end
end
end
......@@ -6,9 +6,7 @@
#
# See the +guard+ method for details.
module Common::Application::Guard
ACTION_ALIASES = HashWithIndifferentAccess.new(update: :edit,
new: :create)
......@@ -47,7 +45,7 @@ module Common::Application::Guard
def permission_for_action(action)
method = action_map[action]
if !method
unless method
if Rails.env.development?
raise ArgumentError.new("No Permission defined for #{action}")
end
......@@ -68,20 +66,20 @@ module Common::Application::Guard
if actions = options[:actions]
action_map</