mirror of
https://github.com/openSUSE/osem.git
synced 2026-08-13 19:54:02 +00:00
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 ###############################
|
||||
|
||||
# Start with cops for Ruby >= 2.3 disabled
|
||||
Style/SafeNavigation:
|
||||
Enabled: false
|
||||
Style/NumericPredicate:
|
||||
Enabled: false
|
||||
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ class Ability
|
|||
can [:index, :conferences, :code_of_conduct], Organization
|
||||
can [:index], Conference
|
||||
can [:show], Conference do |conference|
|
||||
conference.splashpage && conference.splashpage.public == true
|
||||
conference.splashpage&.public == true
|
||||
end
|
||||
# Can view the schedule
|
||||
can [:schedule, :events], Conference do |conference|
|
||||
|
|
|
|||
|
|
@ -108,14 +108,18 @@ class Cfp < ApplicationRecord
|
|||
private
|
||||
|
||||
def before_end_of_conference
|
||||
if program && program.conference && program.conference.end_date && end_date && (end_date > program.conference.end_date)
|
||||
errors
|
||||
.add(:end_date, "can't be after the conference end date (#{program.conference.end_date})")
|
||||
if program&.conference&.end_date && end_date && (end_date > program.conference.end_date)
|
||||
errors.add(
|
||||
:end_date,
|
||||
"can't be after the conference end date (#{program.conference.end_date})"
|
||||
)
|
||||
end
|
||||
|
||||
if program && program.conference && program.conference.end_date && start_date && (start_date > program.conference.end_date)
|
||||
errors
|
||||
.add(:start_date, "can't be after the conference end date (#{program.conference.end_date})")
|
||||
if program&.conference&.end_date && start_date && (start_date > program.conference.end_date)
|
||||
errors.add(
|
||||
:start_date,
|
||||
"can't be after the conference end date (#{program.conference.end_date})"
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -154,7 +154,7 @@ class Conference < ApplicationRecord
|
|||
def get_submissions_per_week
|
||||
result = []
|
||||
|
||||
if program && program.cfp && program.events
|
||||
if program&.cfp && program&.events
|
||||
submissions = program.events.select(:week).group(:week).order(:week).count
|
||||
start_week = program.cfp.start_week
|
||||
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.
|
||||
def get_submissions_data
|
||||
result = {}
|
||||
if program && program.cfp && program.events
|
||||
if program&.cfp && program&.events
|
||||
result = get_events_per_week_by_state
|
||||
|
||||
start_week = program.cfp.start_week
|
||||
|
|
@ -272,9 +272,8 @@ class Conference < ApplicationRecord
|
|||
def registration_weeks
|
||||
result = 0
|
||||
weeks = 0
|
||||
if registration_period &&
|
||||
registration_period.start_date &&
|
||||
registration_period.end_date
|
||||
if registration_period&.start_date &&
|
||||
registration_period&.end_date
|
||||
weeks = Date.new(registration_period.start_date.year, 12, 31)
|
||||
.strftime('%W').to_i
|
||||
|
||||
|
|
@ -346,7 +345,7 @@ class Conference < ApplicationRecord
|
|||
tracks: tracks_set?,
|
||||
event_types: event_types_set?,
|
||||
difficulty_levels: difficulty_levels_set?,
|
||||
splashpage: splashpage && splashpage.public?
|
||||
splashpage: splashpage&.public?
|
||||
}
|
||||
|
||||
result.update(
|
||||
|
|
|
|||
|
|
@ -312,7 +312,7 @@ class Event < ApplicationRecord
|
|||
|
||||
def before_end_of_conference
|
||||
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)
|
||||
end
|
||||
|
||||
|
|
@ -324,7 +324,7 @@ class Event < ApplicationRecord
|
|||
# Allow only confirmed tracks that belong to the same program as the event
|
||||
#
|
||||
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
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -13,10 +13,10 @@ class RegistrationPeriod < ApplicationRecord
|
|||
|
||||
def before_end_of_conference
|
||||
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
|
||||
.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
|
||||
|
||||
def start_date_before_end_date
|
||||
|
|
|
|||
|
|
@ -115,10 +115,8 @@ class Track < ApplicationRecord
|
|||
def revoke_role_and_cleanup
|
||||
role = Role.find_by(name: 'track_organizer', resource: self)
|
||||
|
||||
if role
|
||||
role.users.each do |user|
|
||||
user.remove_role 'track_organizer', self
|
||||
end
|
||||
role&.users&.each do |user|
|
||||
user.remove_role 'track_organizer', self
|
||||
end
|
||||
|
||||
self.selected_schedule_id = nil
|
||||
|
|
|
|||
|
|
@ -133,7 +133,7 @@ class User < ApplicationRecord
|
|||
def self.for_ichain_username(username, attributes)
|
||||
user = find_by(username: username)
|
||||
|
||||
raise UserDisabled if user && user.is_disabled
|
||||
raise UserDisabled if user&.is_disabled
|
||||
|
||||
if user
|
||||
user.update_attributes(email: attributes[:email],
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ class Venue < ApplicationRecord
|
|||
|
||||
def country_name
|
||||
name = ISO3166::Country[country]
|
||||
name.name if name
|
||||
name&.name
|
||||
end
|
||||
|
||||
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
|
||||
# 000/001/234 for an id of 1234. Stolen from paperclip...
|
||||
def id_partition
|
||||
('%09d'.freeze % model.id).scan(/\d{3}/).join('/'.freeze)
|
||||
format('%09d', model.id).scan(/\d{3}/).join('/')
|
||||
end
|
||||
|
||||
# Override the directory where uploaded files will be stored.
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ class MigrateDataRemoveColumnIncludeCfpInSplashAddColumnIncludeCfp < ActiveRecor
|
|||
TempConference.all.each do |conference|
|
||||
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.include_cfp = cfp.include_cfp_in_splash # true
|
||||
splashpage.save!
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue