From 3d7c84bcfcafa436e2a19af920508a23b80a33b6 Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Tue, 10 Jun 2025 18:54:51 +0100 Subject: [PATCH] Fix new rubocop warnings --- .rubocop.yml | 5 +++++ app/controllers/api_controller.rb | 9 ++------- app/controllers/application_controller.rb | 15 +++------------ app/controllers/confirmations_controller.rb | 4 ++-- app/controllers/notes_controller.rb | 2 +- app/models/user.rb | 2 +- 6 files changed, 14 insertions(+), 23 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 893f4645a..de2f97c44 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -42,6 +42,11 @@ Naming/FileName: Naming/MethodParameterName: Enabled: false +# AllowedMethods can be replaced with AllowBangMethods after release of +# https://github.com/rubocop/rubocop/pull/14270 +Naming/PredicateMethod: + AllowedMethods: gravatar_enable! + # This conflicts with Strong Migrations, which can't check `change_table` Rails/BulkChangeTable: Enabled: false diff --git a/app/controllers/api_controller.rb b/app/controllers/api_controller.rb index 9b2ee9b53..e99d0ffac 100644 --- a/app/controllers/api_controller.rb +++ b/app/controllers/api_controller.rb @@ -53,13 +53,8 @@ class ApiController < ApplicationController # make the current_user object from any auth sources we have setup_user_auth(:skip_blocks => skip_blocks, :skip_terms => skip_terms) - # handle authenticate pass/fail - unless current_user - # no auth, the user does not exist or the password was wrong - render :plain => errormessage, :status => :unauthorized - - false - end + # error if we could not authenticate the user + render :plain => errormessage, :status => :unauthorized unless current_user end def current_ability diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index b10eec7d3..8e2754836 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -124,17 +124,11 @@ class ApplicationController < ActionController::Base end def check_api_readable - if api_status == "offline" - report_error "Database offline for maintenance", :service_unavailable - false - end + report_error "Database offline for maintenance", :service_unavailable if api_status == "offline" end def check_api_writable - unless api_status == "online" - report_error "Database offline for maintenance", :service_unavailable - false - end + report_error "Database offline for maintenance", :service_unavailable unless api_status == "online" end def database_status @@ -162,10 +156,7 @@ class ApplicationController < ActionController::Base end def require_public_data - unless current_user.data_public? - report_error "You must make your edits public to upload new data", :forbidden - false - end + report_error "You must make your edits public to upload new data", :forbidden unless current_user.data_public? end # Report and error to the user diff --git a/app/controllers/confirmations_controller.rb b/app/controllers/confirmations_controller.rb index 964f0cc4f..2567d895c 100644 --- a/app/controllers/confirmations_controller.rb +++ b/app/controllers/confirmations_controller.rb @@ -28,7 +28,7 @@ class ConfirmationsController < ApplicationController else user.activate user.email_valid = true - flash[:notice] = gravatar_status_message(user) if user.gravatar_enable + flash[:notice] = gravatar_status_message(user) if user.gravatar_enable! user.save! cookies.delete :_osm_anonymous_notes_count referer = safe_referer(params[:referer]) if params[:referer] @@ -73,7 +73,7 @@ class ConfirmationsController < ApplicationController current_user.email = current_user.new_email current_user.new_email = nil current_user.email_valid = true - gravatar_enabled = current_user.gravatar_enable + gravatar_enabled = current_user.gravatar_enable! if current_user.save flash[:notice] = if gravatar_enabled "#{t('.success')} #{gravatar_status_message(current_user)}" diff --git a/app/controllers/notes_controller.rb b/app/controllers/notes_controller.rb index fbeb01b76..05c54459a 100644 --- a/app/controllers/notes_controller.rb +++ b/app/controllers/notes_controller.rb @@ -49,7 +49,7 @@ class NotesController < ApplicationController end def new - @anonymous_notes_count = request.cookies["_osm_anonymous_notes_count"].to_i || 0 + @anonymous_notes_count = request.cookies["_osm_anonymous_notes_count"].to_i render :action => :new_readonly if api_status != "online" end end diff --git a/app/models/user.rb b/app/models/user.rb index e7a886029..5d1ed4d03 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -463,7 +463,7 @@ class User < ApplicationRecord ## # check if this user has a gravatar and set the user pref is true - def gravatar_enable + def gravatar_enable! # code from example https://en.gravatar.com/site/implement/images/ruby/ return false if avatar.attached? -- 2.39.5