Showing 208 of 208 total issues
Class Event
has 40 methods (exceeds 20 allowed). Consider refactoring. Open
class Event < ActiveRecord::Base
UNREASONABLY_LONG_DATE_SPAN = 300
TRUNCATE_DESCRIPTION_TEXT_LENGTH = 250
serialize :custom_application_fields, Array
Method download_agreement_letters
has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring. Open
def download_agreement_letters
@event = Event.find(params[:id])
unless params.key?(:selected_participants)
redirect_to(event_participants_url(@event), notice: I18n.t('events.agreement_letters_download.notices.no_participants_selected')) && return
end
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Class EventsController
has 25 methods (exceeds 20 allowed). Consider refactoring. Open
class EventsController < ApplicationController
include EventImageUploadHelper
load_and_authorize_resource
skip_authorize_resource only: %i(badges download_agreement_letters send_participants_email)
before_action :set_event, only: %i(show edit update destroy participants
File events_controller.rb
has 255 lines of code (exceeds 250 allowed). Consider refactoring. Open
require 'pdf_generation/badges_pdf'
require 'pdf_generation/applications_pdf'
require 'pdf_generation/participants_pdf'
require 'rubygems'
require 'zip'
Method download_agreement_letters
has 48 lines of code (exceeds 25 allowed). Consider refactoring. Open
def download_agreement_letters
@event = Event.find(params[:id])
unless params.key?(:selected_participants)
redirect_to(event_participants_url(@event), notice: I18n.t('events.agreement_letters_download.notices.no_participants_selected')) && return
end
Method initialize
has 35 lines of code (exceeds 25 allowed). Consider refactoring. Open
def initialize(user)
# Define abilities for the passed in user here. For example:
#
# user ||= User.new # guest user (not logged in)
# if user.admin?
Function _init
has 34 lines of code (exceeds 25 allowed). Consider refactoring. Open
_init : function() {
var callback = this.options.callback;
var selectValue = this.$select.val();
Method compare_participants_by_agreement
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
def compare_participants_by_agreement(participant1, participant2)
unless participant1.requires_agreement_letter_for_event?(self)
unless participant2.requires_agreement_letter_for_event?(self)
return participant1.email <=> participant2.email
end
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method create
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
def create
@application_letter = ApplicationLetter.new(application_params)
# event must be param to new_application_letter_path
seminar_name = ''
if params[:event_id]
Method new
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
def new
if !current_user
message = I18n.t('application_letters.login_before_creation')
flash[:event_id] = params[:event_id]
flash.keep(:event_id)
Consider simplifying this complex logical expression. Open
if event.phase == :execution
(status_was == 'accepted' && status == 'canceled') || (status_was == 'alternative' && status == 'accepted') || (status_was == 'rejected' && status == 'accepted' && !event.has_alternative_application_letters?)
elsif event.phase == :selection && event.participant_selection_locked
false
else
Method status_change_allowed?
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def status_change_allowed?
if event.phase == :execution
(status_was == 'accepted' && status == 'canceled') || (status_was == 'alternative' && status == 'accepted') || (status_was == 'rejected' && status == 'accepted' && !event.has_alternative_application_letters?)
elsif event.phase == :selection && event.participant_selection_locked
false
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method add_missing_permission_flashes
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def add_missing_permission_flashes
if current_user
flash.now[:warning] ||= []
current_user.events_with_missing_agreement_letters.each do |event|
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method send_generic_email
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
def self.send_generic_email(hide_recipients, recipients, reply_to, subject, content, attachments = [])
Method generic_email
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def generic_email(recipients, reply_to, subject, content, attached_files = [])
Method initialize
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def initialize(user)
# Define abilities for the passed in user here. For example:
#
# user ||= User.new # guest user (not logged in)
# if user.admin?
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function ajaxUpdateApplicationStatus
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
function ajaxUpdateApplicationStatus(form, errorMessage) {
if (!window.FormData)
return form.submit();
var xhr = new XMLHttpRequest();
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Model attribute used in file name Open
zip_data = File.read(temp_file.path)
- Read upRead up
- Exclude checks
Using user input when accessing files (local or remote) will raise a warning in Brakeman.
For example
File.open("/tmp/#{cookie[:file]}")
will raise an error like
Cookie value used in file name near line 4: File.open("/tmp/#{cookie[:file]}")
This type of vulnerability can be used to access arbitrary files on a server (including /etc/passwd
.
Avoid too many return
statements within this method. Open
return -1 if participant2.agreement_letter_for_event?(self)
Potentially dangerous key allowed for mass assignment Open
user_params.permit(:email, :name, :password, :password_confirmation, :role, :current_password)
- Read upRead up
- Exclude checks
Mass assignment is a feature of Rails which allows an application to create a record from the values of a hash.
Example:
User.new(params[:user])
Unfortunately, if there is a user field called admin
which controls administrator access, now any user can make themselves an administrator.
attr_accessible
and attr_protected
can be used to limit mass assignment. However, Brakeman will warn unless attr_accessible
is used, or mass assignment is completely disabled.
There are two different mass assignment warnings which can arise. The first is when mass assignment actually occurs, such as the example above. This results in a warning like
Unprotected mass assignment near line 61: User.new(params[:user])
The other warning is raised whenever a model is found which does not use attr_accessible
. This produces generic warnings like
Mass assignment is not restricted using attr_accessible
with a list of affected models.
In Rails 3.1 and newer, mass assignment can easily be disabled:
config.active_record.whitelist_attributes = true
Unfortunately, it can also easily be bypassed:
User.new(params[:user], :without_protection => true)
Brakeman will warn on uses of without_protection
.