Use Ruby safe navigation over Rails try
re: https://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Style/SafeNavigation
This commit is contained in:
parent
d8bd269a64
commit
24396d35c2
11 changed files with 26 additions and 27 deletions
|
|
@ -17,8 +17,6 @@ AllCops:
|
||||||
#################### Metrics ###############################
|
#################### Metrics ###############################
|
||||||
|
|
||||||
# Start with cops for Ruby >= 2.3 disabled
|
# Start with cops for Ruby >= 2.3 disabled
|
||||||
Style/SafeNavigation:
|
|
||||||
Enabled: false
|
|
||||||
Style/NumericPredicate:
|
Style/NumericPredicate:
|
||||||
Enabled: false
|
Enabled: false
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ class Ability
|
||||||
can [:index, :conferences, :code_of_conduct], Organization
|
can [:index, :conferences, :code_of_conduct], Organization
|
||||||
can [:index], Conference
|
can [:index], Conference
|
||||||
can [:show], Conference do |conference|
|
can [:show], Conference do |conference|
|
||||||
conference.splashpage && conference.splashpage.public == true
|
conference.splashpage&.public == true
|
||||||
end
|
end
|
||||||
# Can view the schedule
|
# Can view the schedule
|
||||||
can [:schedule, :events], Conference do |conference|
|
can [:schedule, :events], Conference do |conference|
|
||||||
|
|
|
||||||
|
|
@ -108,14 +108,18 @@ class Cfp < ApplicationRecord
|
||||||
private
|
private
|
||||||
|
|
||||||
def before_end_of_conference
|
def before_end_of_conference
|
||||||
if program && program.conference && program.conference.end_date && end_date && (end_date > program.conference.end_date)
|
if program&.conference&.end_date && end_date && (end_date > program.conference.end_date)
|
||||||
errors
|
errors.add(
|
||||||
.add(:end_date, "can't be after the conference end date (#{program.conference.end_date})")
|
:end_date,
|
||||||
|
"can't be after the conference end date (#{program.conference.end_date})"
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
if program && program.conference && program.conference.end_date && start_date && (start_date > program.conference.end_date)
|
if program&.conference&.end_date && start_date && (start_date > program.conference.end_date)
|
||||||
errors
|
errors.add(
|
||||||
.add(:start_date, "can't be after the conference end date (#{program.conference.end_date})")
|
:start_date,
|
||||||
|
"can't be after the conference end date (#{program.conference.end_date})"
|
||||||
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -154,7 +154,7 @@ class Conference < ApplicationRecord
|
||||||
def get_submissions_per_week
|
def get_submissions_per_week
|
||||||
result = []
|
result = []
|
||||||
|
|
||||||
if program && program.cfp && program.events
|
if program&.cfp && program&.events
|
||||||
submissions = program.events.select(:week).group(:week).order(:week).count
|
submissions = program.events.select(:week).group(:week).order(:week).count
|
||||||
start_week = program.cfp.start_week
|
start_week = program.cfp.start_week
|
||||||
weeks = program.cfp.weeks
|
weeks = program.cfp.weeks
|
||||||
|
|
@ -171,7 +171,7 @@ class Conference < ApplicationRecord
|
||||||
# * +Array+ -> e.g. 'Submitted' => [0, 3, 3, 5] -> first week 0 events, second week 3 events.
|
# * +Array+ -> e.g. 'Submitted' => [0, 3, 3, 5] -> first week 0 events, second week 3 events.
|
||||||
def get_submissions_data
|
def get_submissions_data
|
||||||
result = {}
|
result = {}
|
||||||
if program && program.cfp && program.events
|
if program&.cfp && program&.events
|
||||||
result = get_events_per_week_by_state
|
result = get_events_per_week_by_state
|
||||||
|
|
||||||
start_week = program.cfp.start_week
|
start_week = program.cfp.start_week
|
||||||
|
|
@ -272,9 +272,8 @@ class Conference < ApplicationRecord
|
||||||
def registration_weeks
|
def registration_weeks
|
||||||
result = 0
|
result = 0
|
||||||
weeks = 0
|
weeks = 0
|
||||||
if registration_period &&
|
if registration_period&.start_date &&
|
||||||
registration_period.start_date &&
|
registration_period&.end_date
|
||||||
registration_period.end_date
|
|
||||||
weeks = Date.new(registration_period.start_date.year, 12, 31)
|
weeks = Date.new(registration_period.start_date.year, 12, 31)
|
||||||
.strftime('%W').to_i
|
.strftime('%W').to_i
|
||||||
|
|
||||||
|
|
@ -346,7 +345,7 @@ class Conference < ApplicationRecord
|
||||||
tracks: tracks_set?,
|
tracks: tracks_set?,
|
||||||
event_types: event_types_set?,
|
event_types: event_types_set?,
|
||||||
difficulty_levels: difficulty_levels_set?,
|
difficulty_levels: difficulty_levels_set?,
|
||||||
splashpage: splashpage && splashpage.public?
|
splashpage: splashpage&.public?
|
||||||
}
|
}
|
||||||
|
|
||||||
result.update(
|
result.update(
|
||||||
|
|
|
||||||
|
|
@ -312,7 +312,7 @@ class Event < ApplicationRecord
|
||||||
|
|
||||||
def before_end_of_conference
|
def before_end_of_conference
|
||||||
errors
|
errors
|
||||||
.add(:created_at, "can't be after the conference end date!") if program.conference && program.conference.end_date &&
|
.add(:created_at, "can't be after the conference end date!") if program.conference&.end_date &&
|
||||||
(Date.today > program.conference.end_date)
|
(Date.today > program.conference.end_date)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -324,7 +324,7 @@ class Event < ApplicationRecord
|
||||||
# Allow only confirmed tracks that belong to the same program as the event
|
# Allow only confirmed tracks that belong to the same program as the event
|
||||||
#
|
#
|
||||||
def valid_track
|
def valid_track
|
||||||
return unless track && track.program && program
|
return unless track&.program && program
|
||||||
errors.add(:track, 'is invalid') unless track.confirmed? && track.program == program
|
errors.add(:track, 'is invalid') unless track.confirmed? && track.program == program
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,10 +13,10 @@ class RegistrationPeriod < ApplicationRecord
|
||||||
|
|
||||||
def before_end_of_conference
|
def before_end_of_conference
|
||||||
errors
|
errors
|
||||||
.add(:start_date, "can't be after the conference end date (#{conference.end_date})") if conference && conference.end_date && start_date && (start_date > conference.end_date)
|
.add(:start_date, "can't be after the conference end date (#{conference.end_date})") if conference&.end_date && start_date && (start_date > conference.end_date)
|
||||||
|
|
||||||
errors
|
errors
|
||||||
.add(:end_date, "can't be after the conference end date (#{conference.end_date})") if conference && conference.end_date && end_date && (end_date > conference.end_date)
|
.add(:end_date, "can't be after the conference end date (#{conference.end_date})") if conference&.end_date && end_date && (end_date > conference.end_date)
|
||||||
end
|
end
|
||||||
|
|
||||||
def start_date_before_end_date
|
def start_date_before_end_date
|
||||||
|
|
|
||||||
|
|
@ -115,10 +115,8 @@ class Track < ApplicationRecord
|
||||||
def revoke_role_and_cleanup
|
def revoke_role_and_cleanup
|
||||||
role = Role.find_by(name: 'track_organizer', resource: self)
|
role = Role.find_by(name: 'track_organizer', resource: self)
|
||||||
|
|
||||||
if role
|
role&.users&.each do |user|
|
||||||
role.users.each do |user|
|
user.remove_role 'track_organizer', self
|
||||||
user.remove_role 'track_organizer', self
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
self.selected_schedule_id = nil
|
self.selected_schedule_id = nil
|
||||||
|
|
|
||||||
|
|
@ -133,7 +133,7 @@ class User < ApplicationRecord
|
||||||
def self.for_ichain_username(username, attributes)
|
def self.for_ichain_username(username, attributes)
|
||||||
user = find_by(username: username)
|
user = find_by(username: username)
|
||||||
|
|
||||||
raise UserDisabled if user && user.is_disabled
|
raise UserDisabled if user&.is_disabled
|
||||||
|
|
||||||
if user
|
if user
|
||||||
user.update_attributes(email: attributes[:email],
|
user.update_attributes(email: attributes[:email],
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ class Venue < ApplicationRecord
|
||||||
|
|
||||||
def country_name
|
def country_name
|
||||||
name = ISO3166::Country[country]
|
name = ISO3166::Country[country]
|
||||||
name.name if name
|
name&.name
|
||||||
end
|
end
|
||||||
|
|
||||||
def location?
|
def location?
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,7 @@ class PictureUploader < CarrierWave::Uploader::Base
|
||||||
# Returns the id of the instance in a split path form. e.g. returns
|
# Returns the id of the instance in a split path form. e.g. returns
|
||||||
# 000/001/234 for an id of 1234. Stolen from paperclip...
|
# 000/001/234 for an id of 1234. Stolen from paperclip...
|
||||||
def id_partition
|
def id_partition
|
||||||
('%09d'.freeze % model.id).scan(/\d{3}/).join('/'.freeze)
|
format('%09d', model.id).scan(/\d{3}/).join('/')
|
||||||
end
|
end
|
||||||
|
|
||||||
# Override the directory where uploaded files will be stored.
|
# Override the directory where uploaded files will be stored.
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ class MigrateDataRemoveColumnIncludeCfpInSplashAddColumnIncludeCfp < ActiveRecor
|
||||||
TempConference.all.each do |conference|
|
TempConference.all.each do |conference|
|
||||||
cfp = TempCallForPaper.find_by(conference_id: conference.id)
|
cfp = TempCallForPaper.find_by(conference_id: conference.id)
|
||||||
|
|
||||||
if cfp && cfp.include_cfp_in_splash
|
if cfp&.include_cfp_in_splash
|
||||||
splashpage = TempSplashpage.find_or_initialize_by(conference_id: conference.id)
|
splashpage = TempSplashpage.find_or_initialize_by(conference_id: conference.id)
|
||||||
splashpage.include_cfp = cfp.include_cfp_in_splash # true
|
splashpage.include_cfp = cfp.include_cfp_in_splash # true
|
||||||
splashpage.save!
|
splashpage.save!
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue