Apply Rails/SafeNavigation rubocop rule
This commit is contained in:
@@ -153,9 +153,6 @@ Rails/RedundantReceiverInWithOptions:
|
||||
Rails/ReversibleMigration:
|
||||
Enabled: true
|
||||
|
||||
Rails/SafeNavigation:
|
||||
Enabled: true
|
||||
|
||||
Rails/SaveBang:
|
||||
Enabled: true
|
||||
|
||||
|
||||
@@ -141,6 +141,10 @@ Rails/RelativeDateConstant:
|
||||
Rails/RequestReferer:
|
||||
Enabled: true
|
||||
|
||||
Rails/SafeNavigation:
|
||||
Enabled: true
|
||||
ConvertTry: true
|
||||
|
||||
Rails/TimeZone:
|
||||
Enabled: true
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ class Admin::BaseController < ApplicationController
|
||||
private
|
||||
|
||||
def verify_administrator
|
||||
raise CanCan::AccessDenied unless current_user.try(:administrator?)
|
||||
raise CanCan::AccessDenied unless current_user&.administrator?
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -21,7 +21,7 @@ class Admin::Poll::QuestionsController < Admin::Poll::BaseController
|
||||
end
|
||||
|
||||
def create
|
||||
@question.author = @question.proposal.try(:author) || current_user
|
||||
@question.author = @question.proposal&.author || current_user
|
||||
@question.votation_type = VotationType.build_by_type(@question, params[:votation_type])
|
||||
|
||||
if @question.save
|
||||
|
||||
@@ -110,9 +110,9 @@ class ApplicationController < ActionController::Base
|
||||
end
|
||||
|
||||
def set_default_budget_filter
|
||||
if @budget.try(:balloting?) || @budget.try(:publishing_prices?)
|
||||
if @budget&.balloting? || @budget&.publishing_prices?
|
||||
params[:filter] ||= "selected"
|
||||
elsif @budget.try(:finished?)
|
||||
elsif @budget&.finished?
|
||||
params[:filter] ||= "winners"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -141,7 +141,7 @@ module Budgets
|
||||
def load_heading
|
||||
if params[:heading_id].present?
|
||||
@heading = @budget.headings.find_by_slug_or_id! params[:heading_id]
|
||||
@assigned_heading = @ballot.try(:heading_for_group, @heading.try(:group))
|
||||
@assigned_heading = @ballot&.heading_for_group(@heading&.group)
|
||||
load_map
|
||||
end
|
||||
end
|
||||
|
||||
@@ -85,7 +85,7 @@ class CommentsController < ApplicationController
|
||||
|
||||
def add_notification(comment)
|
||||
notifiable = comment.reply? ? comment.parent : comment.commentable
|
||||
notifiable_author_id = notifiable.try(:author_id)
|
||||
notifiable_author_id = notifiable&.author_id
|
||||
if notifiable_author_id.present? && notifiable_author_id != comment.author_id
|
||||
Notification.add(notifiable.author, notifiable)
|
||||
end
|
||||
|
||||
@@ -27,13 +27,13 @@ class Management::SessionsController < ActionController::Base
|
||||
end
|
||||
|
||||
def admin?
|
||||
if current_user.try(:administrator?)
|
||||
if current_user&.administrator?
|
||||
session[:manager] = { login: "admin_user_#{current_user.id}" }
|
||||
end
|
||||
end
|
||||
|
||||
def manager?
|
||||
if current_user.try(:manager?)
|
||||
if current_user&.manager?
|
||||
session[:manager] = { login: "manager_user_#{current_user.id}" }
|
||||
end
|
||||
end
|
||||
|
||||
@@ -9,7 +9,7 @@ class Moderation::BaseController < ApplicationController
|
||||
private
|
||||
|
||||
def verify_moderator
|
||||
raise CanCan::AccessDenied unless current_user.try(:moderator?) || current_user.try(:administrator?)
|
||||
raise CanCan::AccessDenied unless current_user&.moderator? || current_user&.administrator?
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -10,7 +10,7 @@ class Officing::BaseController < ApplicationController
|
||||
private
|
||||
|
||||
def verify_officer
|
||||
raise CanCan::AccessDenied unless current_user.try(:poll_officer?)
|
||||
raise CanCan::AccessDenied unless current_user&.poll_officer?
|
||||
end
|
||||
|
||||
def check_officer_assignment
|
||||
|
||||
@@ -25,7 +25,7 @@ class PollsController < ApplicationController
|
||||
.where.not(description: "").order(:given_order)
|
||||
|
||||
@answers_by_question_id = {}
|
||||
poll_answers = ::Poll::Answer.by_question(@poll.question_ids).by_author(current_user.try(:id))
|
||||
poll_answers = ::Poll::Answer.by_question(@poll.question_ids).by_author(current_user&.id)
|
||||
|
||||
@last_pair_question_answers = {}
|
||||
@questions.each do |question|
|
||||
|
||||
@@ -9,7 +9,7 @@ class Tracking::BaseController < ApplicationController
|
||||
private
|
||||
|
||||
def verify_tracker
|
||||
raise CanCan::AccessDenied unless current_user.try(:tracker?) || current_user.try(:administrator?)
|
||||
raise CanCan::AccessDenied unless current_user&.tracker? || current_user&.administrator?
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -47,8 +47,7 @@ class Tracking::BudgetInvestmentsController < Tracking::BaseController
|
||||
end
|
||||
|
||||
def heading_filters
|
||||
investments = @budget.investments.by_tracker(current_user.tracker.try(:id))
|
||||
.distinct
|
||||
investments = @budget.investments.by_tracker(current_user.tracker&.id).distinct
|
||||
investment_headings = Budget::Heading.where(id: investments.pluck(:heading_id).uniq)
|
||||
.order(name: :asc)
|
||||
all_headings_filter = [
|
||||
|
||||
@@ -9,7 +9,7 @@ class Valuation::BaseController < ApplicationController
|
||||
private
|
||||
|
||||
def verify_valuator
|
||||
raise CanCan::AccessDenied unless current_user.try(:valuator?) || current_user.try(:administrator?)
|
||||
raise CanCan::AccessDenied unless current_user&.valuator? || current_user&.administrator?
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -73,8 +73,7 @@ class Valuation::BudgetInvestmentsController < Valuation::BaseController
|
||||
end
|
||||
|
||||
def heading_filters
|
||||
investments = @budget.investments.by_valuator(current_user.valuator.try(:id))
|
||||
.visible_to_valuators.distinct
|
||||
investments = @budget.investments.by_valuator(current_user.valuator&.id).visible_to_valuators.distinct
|
||||
investment_headings = Budget::Heading.where(id: investments.pluck(:heading_id)).sort_by(&:name)
|
||||
|
||||
all_headings_filter = [
|
||||
|
||||
@@ -8,7 +8,7 @@ module BudgetHeadingsHelper
|
||||
|
||||
def heading_link(assigned_heading = nil, budget = nil)
|
||||
return nil unless assigned_heading && budget
|
||||
heading_path = budget_investments_path(budget, heading_id: assigned_heading.try(:id))
|
||||
heading_path = budget_investments_path(budget, heading_id: assigned_heading&.id)
|
||||
link_to(assigned_heading.name, heading_path)
|
||||
end
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ module SiteCustomizationHelper
|
||||
I18nContentTranslation.where(
|
||||
i18n_content_id: content.id,
|
||||
locale: locale
|
||||
).first.try(:value)
|
||||
).first&.value
|
||||
else
|
||||
false
|
||||
end
|
||||
|
||||
@@ -72,7 +72,7 @@ module Abilities
|
||||
can [:create, :destroy], Follow
|
||||
|
||||
can [:destroy], Document do |document|
|
||||
document.documentable.try(:author_id) == user.id
|
||||
document.documentable&.author_id == user.id
|
||||
end
|
||||
|
||||
can [:destroy], Image, imageable: { author_id: user.id }
|
||||
|
||||
@@ -25,7 +25,7 @@ class AdminNotification < ApplicationRecord
|
||||
end
|
||||
|
||||
def list_of_recipients_count
|
||||
list_of_recipients.try(:count) || 0
|
||||
list_of_recipients&.count || 0
|
||||
end
|
||||
|
||||
def deliver
|
||||
|
||||
@@ -79,7 +79,7 @@ class Budget < ApplicationRecord
|
||||
if phases.exists? && phases.send(phase).description.present?
|
||||
phases.send(phase).description
|
||||
else
|
||||
send("description_#{phase}").try(:html_safe)
|
||||
send("description_#{phase}")&.html_safe
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -34,9 +34,9 @@ class Budget
|
||||
private
|
||||
|
||||
def set_denormalized_ids
|
||||
self.heading_id ||= investment.try(:heading_id)
|
||||
self.group_id ||= investment.try(:group_id)
|
||||
self.budget_id ||= investment.try(:budget_id)
|
||||
self.heading_id ||= investment&.heading_id
|
||||
self.group_id ||= investment&.group_id
|
||||
self.budget_id ||= investment&.budget_id
|
||||
end
|
||||
|
||||
def store_user_heading
|
||||
|
||||
@@ -319,7 +319,7 @@ class Budget
|
||||
end
|
||||
|
||||
def set_responsible_name
|
||||
self.responsible_name = author.try(:document_number) if author.try(:document_number).present?
|
||||
self.responsible_name = author&.document_number if author&.document_number.present?
|
||||
end
|
||||
|
||||
def should_show_aside?
|
||||
@@ -400,8 +400,8 @@ class Budget
|
||||
private
|
||||
|
||||
def set_denormalized_ids
|
||||
self.group_id = heading.try(:group_id) if heading_id_changed?
|
||||
self.budget_id ||= heading.try(:group).try(:budget_id)
|
||||
self.group_id = heading&.group_id if heading_id_changed?
|
||||
self.budget_id ||= heading&.group&.budget_id
|
||||
end
|
||||
|
||||
def change_log
|
||||
|
||||
@@ -10,7 +10,7 @@ module Globalizable
|
||||
after_validation :copy_error_to_current_translation, on: :update
|
||||
|
||||
def description
|
||||
self.read_attribute(:description).try :html_safe
|
||||
self.read_attribute(:description)&.html_safe
|
||||
end
|
||||
|
||||
def locales_not_marked_for_destruction
|
||||
|
||||
@@ -12,7 +12,7 @@ module Mappable
|
||||
def map_must_be_valid
|
||||
return true if skip_map?
|
||||
|
||||
unless map_location.try(:available?)
|
||||
unless map_location&.available?
|
||||
skip_map_error = I18n.t("activerecord.errors.models.map_location.attributes.map.invalid")
|
||||
errors.add(:skip_map, skip_map_error)
|
||||
end
|
||||
|
||||
@@ -7,7 +7,7 @@ module Sanitizable
|
||||
|
||||
unless included_modules.include? Globalizable
|
||||
def description
|
||||
super.try :html_safe
|
||||
super&.html_safe
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -74,7 +74,7 @@ class Debate < ApplicationRecord
|
||||
{
|
||||
author.username => "B",
|
||||
tag_list.join(" ") => "B",
|
||||
geozone.try(:name) => "B",
|
||||
geozone&.name => "B",
|
||||
}.merge!(searchable_globalized_values)
|
||||
end
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ class Flag < ApplicationRecord
|
||||
|
||||
def self.flagged?(user, flaggable)
|
||||
return false unless user
|
||||
!!by_user_and_flaggable(user, flaggable).try(:first)
|
||||
!!by_user_and_flaggable(user, flaggable)&.first
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -59,7 +59,7 @@ class Legislation::Proposal < ApplicationRecord
|
||||
{ title => "A",
|
||||
author.username => "B",
|
||||
tag_list.join(" ") => "B",
|
||||
geozone.try(:name) => "B",
|
||||
geozone&.name => "B",
|
||||
summary => "C",
|
||||
description => "D" }
|
||||
end
|
||||
|
||||
@@ -44,10 +44,10 @@ class Poll::Question < ApplicationRecord
|
||||
end
|
||||
|
||||
def searchable_values
|
||||
{ title => "A",
|
||||
proposal.try(:title) => "A",
|
||||
author.username => "C",
|
||||
author_visible_name => "C" }
|
||||
{ title => "A",
|
||||
proposal&.title => "A",
|
||||
author.username => "C",
|
||||
author_visible_name => "C" }
|
||||
end
|
||||
|
||||
def copy_attributes_from_proposal(proposal)
|
||||
|
||||
@@ -20,7 +20,7 @@ class Poll::Question::Answer < ApplicationRecord
|
||||
scope :visibles, -> { where(hidden: false) }
|
||||
|
||||
def description
|
||||
self[:description].try :html_safe
|
||||
self[:description]&.html_safe
|
||||
end
|
||||
|
||||
def self.order_answers(ordered_array)
|
||||
|
||||
@@ -42,7 +42,7 @@ class Poll
|
||||
private
|
||||
|
||||
def set_denormalized_booth_assignment_id
|
||||
self.booth_assignment_id ||= officer_assignment.try(:booth_assignment_id)
|
||||
self.booth_assignment_id ||= officer_assignment&.booth_assignment_id
|
||||
end
|
||||
|
||||
def in_census?
|
||||
@@ -56,7 +56,7 @@ class Poll
|
||||
def fill_stats_fields
|
||||
if in_census?
|
||||
self.gender = census_api_response.gender
|
||||
self.geozone_id = Geozone.select(:id).where(census_code: census_api_response.district_code).first.try(:id)
|
||||
self.geozone_id = Geozone.select(:id).where(census_code: census_api_response.district_code).first&.id
|
||||
self.age = voter_age(census_api_response.date_of_birth)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -135,7 +135,7 @@ class Proposal < ApplicationRecord
|
||||
{
|
||||
author.username => "B",
|
||||
tag_list.join(" ") => "B",
|
||||
geozone.try(:name) => "B"
|
||||
geozone&.name => "B"
|
||||
}.merge!(searchable_globalized_values)
|
||||
end
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ class ProposalNotification < ApplicationRecord
|
||||
after_create :set_author
|
||||
|
||||
def minimum_interval
|
||||
return true if proposal.try(:notifications).blank?
|
||||
return true if proposal&.notifications.blank?
|
||||
interval = Setting[:proposal_notification_minimum_interval_in_days]
|
||||
minimum_interval = (Time.current - interval.to_i.days).to_datetime
|
||||
if proposal.notifications.last.created_at > minimum_interval
|
||||
|
||||
@@ -6,6 +6,6 @@ class SiteCustomization::ContentBlock < ApplicationRecord
|
||||
|
||||
def self.block_for(name, locale)
|
||||
locale ||= I18n.default_locale
|
||||
find_by(name: name, locale: locale).try(:body)
|
||||
find_by(name: name, locale: locale)&.body
|
||||
end
|
||||
end
|
||||
|
||||
@@ -29,11 +29,11 @@ class SiteCustomization::Image < ApplicationRecord
|
||||
end
|
||||
|
||||
def required_width
|
||||
VALID_IMAGES[name].try(:first)
|
||||
VALID_IMAGES[name]&.first
|
||||
end
|
||||
|
||||
def required_height
|
||||
VALID_IMAGES[name].try(:second)
|
||||
VALID_IMAGES[name]&.second
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
@@ -18,7 +18,7 @@ class Valuator < ApplicationRecord
|
||||
end
|
||||
|
||||
def assigned_investment_ids
|
||||
investment_ids + [valuator_group.try(:investment_ids)].flatten
|
||||
investment_ids + [valuator_group&.investment_ids].flatten
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -8,7 +8,7 @@ class Verification::Email
|
||||
|
||||
def initialize(verified_user)
|
||||
@verified_user = verified_user
|
||||
@recipient = @verified_user.try(:email)
|
||||
@recipient = @verified_user&.email
|
||||
end
|
||||
|
||||
def save
|
||||
|
||||
@@ -28,7 +28,7 @@ class Verification::Letter
|
||||
|
||||
def validate_correct_code
|
||||
return if errors.include?(:verification_code)
|
||||
if user.try(:letter_verification_code).to_i != verification_code.to_i
|
||||
if user&.letter_verification_code.to_i != verification_code.to_i
|
||||
errors.add(:verification_code, I18n.t("verification.letter.errors.incorrect_code"))
|
||||
end
|
||||
end
|
||||
|
||||
@@ -54,7 +54,7 @@ module Users
|
||||
end
|
||||
|
||||
def confirm_email
|
||||
body = ActionMailer::Base.deliveries.last.try(:body)
|
||||
body = ActionMailer::Base.deliveries.last&.body
|
||||
expect(body).to be_present
|
||||
|
||||
sent_token = /.*confirmation_token=(.*)".*/.match(body.to_s)[1]
|
||||
|
||||
Reference in New Issue
Block a user