Skip to content

Commit

Permalink
Updated rubocop to latest version (0.59.2) and applied required changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
thorsteneckel committed Oct 9, 2018
1 parent 3d4d541 commit 9af50f2
Show file tree
Hide file tree
Showing 536 changed files with 1,327 additions and 340 deletions.
6 changes: 5 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Default enabled cops
# https://github.com/bbatsov/rubocop/blob/master/config/enabled.yml
# https://github.com/rubocop-hq/rubocop/blob/master/config/default.yml

inherit_from: .rubocop_todo.yml

Expand Down Expand Up @@ -144,6 +144,10 @@ Style/BracesAroundHashParameters:
Description: 'Enforce braces style around hash parameters.'
Enabled: false

Rails/BulkChangeTable:
Description: 'Check whether alter queries are combinable.'
Enabled: false

Rails/FindEach:
Description: 'Prefer all.find_each over all.find.'
Enabled: false
Expand Down
8 changes: 8 additions & 0 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ Rails/ApplicationRecord:
Description: 'Check that models subclass ApplicationRecord.'
Enabled: false

# Browser-Tests inherit from TestCase < Test::Unit::TestCase
# which does not provide assert_not
Rails/AssertNot:
Description: 'Use `assert_not` instead of `assert !`.'
Enabled: true
Exclude:
- "test/browser/*"

Rails/CreateTableWithTimestamps:
Description: >-
Checks the migration for which timestamps are not included
Expand Down
14 changes: 8 additions & 6 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ GEM
ice_cube (0.16.2)
inflection (1.0.0)
interception (0.5)
jaro_winkler (1.5.1)
json (2.1.0)
jwt (1.5.6)
kgio (2.11.0)
Expand Down Expand Up @@ -293,12 +294,12 @@ GEM
omniauth (~> 1.5)
omniauth-oauth2 (>= 1.4.0)
parallel (1.12.1)
parser (2.5.0.5)
parser (2.5.1.2)
ast (~> 2.4.0)
pg (0.21.0)
pluginator (1.5.0)
power_assert (1.1.1)
powerpack (0.1.1)
powerpack (0.1.2)
pre-commit (0.37.0)
pluginator (~> 1.5)
pry (0.11.3)
Expand Down Expand Up @@ -377,14 +378,15 @@ GEM
rspec-mocks (~> 3.8.0)
rspec-support (~> 3.8.0)
rspec-support (3.8.0)
rubocop (0.54.0)
rubocop (0.59.2)
jaro_winkler (~> 1.5.1)
parallel (~> 1.10)
parser (>= 2.5)
parser (>= 2.5, != 2.5.1.1)
powerpack (~> 0.1)
rainbow (>= 2.2.2, < 4.0)
ruby-progressbar (~> 1.7)
unicode-display_width (~> 1.0, >= 1.0.1)
ruby-progressbar (1.9.0)
ruby-progressbar (1.10.0)
ruby_dep (1.5.0)
rubyzip (1.2.2)
safe_yaml (1.0.4)
Expand Down Expand Up @@ -463,7 +465,7 @@ GEM
unf (0.1.4)
unf_ext
unf_ext (0.0.7.5)
unicode-display_width (1.3.0)
unicode-display_width (1.4.0)
unicorn (5.3.1)
kgio (~> 2.6)
raindrops (~> 0.7)
Expand Down
4 changes: 4 additions & 0 deletions app/controllers/application_controller/authenticates.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ def permission_check(key)
permission: key,
)
return false if user

raise Exceptions::NotAuthorized, 'Not authorized (token)!'
end

return false if current_user&.permissions?(key)

raise Exceptions::NotAuthorized, 'Not authorized (user)!'
end

Expand Down Expand Up @@ -68,6 +70,7 @@ def authentication_check_only(auth_param = {})
if Setting.get('api_password_access') == false
raise Exceptions::NotAuthorized, 'API password access disabled!'
end

user = User.authenticate(username, password)
return authentication_check_prerequesits(user, 'basic_auth', auth_param) if user
end
Expand All @@ -79,6 +82,7 @@ def authentication_check_only(auth_param = {})
if Setting.get('api_token_access') == false
raise Exceptions::NotAuthorized, 'API token access disabled!'
end

user = Token.check(
action: 'api',
name: token_string,
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/application_controller/checks_maintainance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ module ApplicationController::ChecksMaintainance

def check_maintenance(user)
return false if !check_maintenance_only(user)

raise Exceptions::NotAuthorized, 'Maintenance mode enabled!'
end

# check maintenance mode
def check_maintenance_only(user)
return false if Setting.get('maintenance_mode') != true
return false if user.permissions?('admin.maintenance')

Rails.logger.info "Maintenance mode enabled, denied login for user #{user.login}, it's no admin user."
true
end
Expand Down
3 changes: 3 additions & 0 deletions app/controllers/application_controller/handles_devices.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module ApplicationController::HandlesDevices

def user_device_check
return false if !user_device_log(current_user, 'session')

true
end

Expand Down Expand Up @@ -39,13 +40,15 @@ def user_device_log(user, type)
# if ip has not changed and ttl in still valid
remote_ip = ENV['TEST_REMOTE_IP'] || request.remote_ip
return true if time_to_check == false && session[:user_device_remote_ip] == remote_ip

session[:user_device_remote_ip] = remote_ip

# for sessions we need the fingperprint
if type == 'session'
if !session[:user_device_updated_at] && !params[:fingerprint] && !session[:user_device_fingerprint]
raise Exceptions::UnprocessableEntity, 'Need fingerprint param!'
end

if params[:fingerprint]
UserDevice.fingerprint_validation(params[:fingerprint])
session[:user_device_fingerprint] = params[:fingerprint]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def response_full?
return true if params[:full] == 'true'
return true if params[:full] == 1
return true if params[:full] == '1'

false
end

Expand All @@ -25,6 +26,7 @@ def response_all?
return true if params[:all] == 'true'
return true if params[:all] == 1
return true if params[:all] == '1'

false
end

Expand Down
5 changes: 5 additions & 0 deletions app/controllers/application_controller/has_user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module ApplicationController::HasUser
def current_user
user_on_behalf = current_user_on_behalf
return user_on_behalf if user_on_behalf

current_user_real
end

Expand All @@ -20,6 +21,7 @@ def current_user
def current_user_real
return @_current_user if @_current_user
return if !session[:user_id]

@_current_user = User.lookup(id: session[:user_id])
end

Expand Down Expand Up @@ -49,6 +51,7 @@ def current_user_on_behalf
search_attributes[field] = request.headers['X-On-Behalf-Of']
@_user_on_behalf = User.find_by(search_attributes)
next if !@_user_on_behalf

return @_user_on_behalf
end

Expand Down Expand Up @@ -89,11 +92,13 @@ def session_update

# fill user agent
return if session[:user_agent]

session[:user_agent] = request.env['HTTP_USER_AGENT']
end

def valid_session_with_user
return true if current_user

raise Exceptions::UnprocessableEntity, 'No session user!'
end
end
1 change: 1 addition & 0 deletions app/controllers/application_controller/logs_http_access.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def http_log
}
request.headers.each do |key, value|
next if key[0, 5] != 'HTTP_'

request_data[:content] += if key == 'HTTP_COOKIE'
"#{key}: xxxxx\n"
else
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/application_controller/prevents_csrf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module ApplicationController::PreventsCsrf

def set_csrf_token_headers
return true if @_auth_type.present? && @_auth_type != 'session'

headers['CSRF-TOKEN'] = form_authenticity_token
end

Expand All @@ -19,6 +20,7 @@ def verify_csrf_token
return true if request.head?
return true if %w[token_auth basic_auth].include?(@_auth_type)
return true if valid_authenticity_token?(session, params[:authenticity_token] || request.headers['X-CSRF-Token'])

logger.info 'CSRF token verification failed'
raise Exceptions::NotAuthorized, 'CSRF token verification failed!'
end
Expand Down
1 change: 1 addition & 0 deletions app/controllers/application_controller/renders_models.rb
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ def model_references_check(object, params)
generic_object = object.find(params[:id])
result = Models.references(object, generic_object.id)
return false if result.blank?

raise Exceptions::UnprocessableEntity, 'Can\'t delete, object has references.'
rescue => e
raise Exceptions::UnprocessableEntity, e
Expand Down
3 changes: 3 additions & 0 deletions app/controllers/application_controller/sets_headers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module ApplicationController::SetsHeaders
# For all responses in this controller, return the CORS access control headers.
def set_access_control_headers
return if @_auth_type != 'token_auth' && @_auth_type != 'basic_auth'

set_access_control_headers_execute
end

Expand All @@ -26,11 +27,13 @@ def set_access_control_headers_execute
# text/plain.
def cors_preflight_check
return true if @_auth_type != 'token_auth' && @_auth_type != 'basic_auth'

cors_preflight_check_execute
end

def cors_preflight_check_execute
return true if request.method != 'OPTIONS'

headers['Access-Control-Allow-Origin'] = '*'
headers['Access-Control-Allow-Methods'] = 'POST, GET, PUT, DELETE, PATCH, OPTIONS'
headers['Access-Control-Allow-Headers'] = 'Content-Type, Depth, User-Agent, X-File-Size, X-Requested-With, If-Modified-Since, X-File-Name, Cache-Control, Accept-Language'
Expand Down
3 changes: 3 additions & 0 deletions app/controllers/channels_email_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def index
end
EmailAddress.all.each do |email_address|
next if system_online_service && email_address.preferences && email_address.preferences['online_service_disable']

email_address_ids.push email_address.id
assets = email_address.assets(assets)
if !email_address.channel_id || !email_address.active || !Channel.find_by(id: email_address.channel_id)
Expand Down Expand Up @@ -256,6 +257,7 @@ def account_duplicate?(result, channel_id = nil)
next if channel.options[:inbound][:options][:user] != result[:setting][:inbound][:options][:user]
next if channel.options[:inbound][:options][:folder].to_s != result[:setting][:inbound][:options][:folder].to_s
next if channel.id.to_s == channel_id.to_s

render json: {
result: 'duplicate',
message: 'Account already exists!',
Expand All @@ -267,6 +269,7 @@ def account_duplicate?(result, channel_id = nil)

def check_online_service
return true if !Setting.get('system_online_service')

raise Exceptions::NotAuthorized
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def check_attributes_by_current_user_permission(params)
return true if params[:id].present?
return true if params[:role_ids]
return true if params[:roles]

params[:role_ids] = Role.signup_role_ids
true
end
Expand Down
4 changes: 4 additions & 0 deletions app/controllers/concerns/clones_ticket_article_attachments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,23 @@ def article_attachments_clone(article)
attachments = []
article.attachments.each do |new_attachment|
next if new_attachment.preferences['content-alternative'] == true

if article.content_type.present? && article.content_type =~ %r{text/html}i
next if new_attachment.preferences['content_disposition'].present? && new_attachment.preferences['content_disposition'] !~ /inline/

if new_attachment.preferences['Content-ID'].present? && article.body.present?
next if article.body.match?(/#{Regexp.quote(new_attachment.preferences['Content-ID'])}/i)
end
end
already_added = false
existing_attachments.each do |existing_attachment|
next if existing_attachment.filename != new_attachment.filename || existing_attachment.size != new_attachment.size

already_added = true
break
end
next if already_added == true

file = Store.add(
object: 'UploadCache',
o_id: params[:form_id],
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/concerns/creates_ticket_articles.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,14 @@ def article_create(ticket, params)
# validation
['mime-type', 'filename', 'data'].each do |key|
next if attachment[key]

raise Exceptions::UnprocessableEntity, "Attachment needs '#{key}' param for attachment with index '#{index}'"
end

preferences = {}
['charset', 'mime-type'].each do |key|
next if !attachment[key]

store_key = key.tr('-', '_').camelize.gsub(/(.+)([A-Z])/, '\1_\2').tr('_', '-')
preferences[store_key] = attachment[key]
end
Expand Down
1 change: 1 addition & 0 deletions app/controllers/external_credentials_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def permission_check
if params[:id].present? && ExternalCredential.exists?(params[:id])
external_credential = ExternalCredential.find(params[:id])
raise 'No such ExternalCredential!' if !external_credential

authentication_check(permission: ["admin.channel_#{external_credential.name}"])
return
end
Expand Down
3 changes: 3 additions & 0 deletions app/controllers/first_steps_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ def test_customer

def access?
return true if current_user.permissions?(['admin', 'ticket.agent'])

render json: []
false
end
Expand All @@ -243,10 +244,12 @@ def check_availability(result)
test_ticket_active = false
end
return result if test_ticket_active

result.each do |item|
items = []
item[:items].each do |local_item|
next if local_item[:name] == 'Create a Test Ticket'

items.push local_item
end
item[:items] = items
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/form_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ def limit_reached?

def fingerprint_exists?
return true if params[:fingerprint].present? && params[:fingerprint].length > 30

Rails.logger.info 'No fingerprint given!'
response_access_deny
false
Expand All @@ -238,6 +239,7 @@ def fingerprint_exists?
def enabled?
return true if params[:test] && current_user && current_user.permissions?('admin.channel_formular')
return true if Setting.get('form_ticket_create')

response_access_deny
false
end
Expand Down
Loading

0 comments on commit 9af50f2

Please sign in to comment.