diff --git a/Gemfile b/Gemfile index 3151b9abf1..b81e4a6d16 100644 --- a/Gemfile +++ b/Gemfile @@ -156,7 +156,7 @@ group :development, :test do gem "rubocop" # Rails add-on for static analysis. gem 'rubocop-performance' - gem "rubocop-rails", "~> 2.33.4" + gem "rubocop-rails", "~> 2.34.3" # More concise test ("should") matchers gem "shoulda-matchers", "~> 7.0" # Default rules for Rubocop. diff --git a/Gemfile.lock b/Gemfile.lock index d558cfb14c..aff2394937 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -124,7 +124,7 @@ GEM erubi (~> 1.4) parser (>= 2.4) smart_properties - bigdecimal (4.1.1) + bigdecimal (4.1.2) bindex (0.8.1) binding_of_caller (2.0.0) debug_inspector (>= 1.2.0) @@ -342,7 +342,7 @@ GEM actionview (>= 7.0.0) activesupport (>= 7.0.0) jmespath (1.6.2) - json (2.19.3) + json (2.19.4) jwt (3.1.2) base64 kaminari (1.2.2) @@ -398,7 +398,7 @@ GEM memory_profiler (1.1.0) method_source (1.1.0) mini_mime (1.1.5) - minitest (6.0.3) + minitest (6.0.6) drb (~> 2.0) prism (~> 1.5) monetize (2.0.0) @@ -472,7 +472,7 @@ GEM paper_trail (17.0.0) activerecord (>= 7.1) request_store (~> 1.4) - parallel (1.27.0) + parallel (1.28.0) parser (3.3.11.1) ast (~> 2.4.1) racc @@ -524,7 +524,7 @@ GEM puma (7.2.0) nio4r (~> 2.0) racc (1.8.1) - rack (3.2.5) + rack (3.2.6) rack-mini-profiler (4.0.1) rack (>= 1.2.0) rack-protection (4.2.1) @@ -586,7 +586,7 @@ GEM psych (>= 4.0.0) tsort recaptcha (5.21.1) - regexp_parser (2.11.3) + regexp_parser (2.12.0) reline (0.6.3) io-console (~> 0.5) request_store (1.7.0) @@ -636,7 +636,7 @@ GEM lint_roller (~> 1.1) rubocop (>= 1.75.0, < 2.0) rubocop-ast (>= 1.47.1, < 2.0) - rubocop-rails (2.33.4) + rubocop-rails (2.34.3) activesupport (>= 4.2.0) lint_roller (~> 1.1) rack (>= 1.1) @@ -710,9 +710,9 @@ GEM standard-performance (1.9.0) lint_roller (~> 1.1) rubocop-performance (~> 1.26.0) - standard-rails (1.5.0) + standard-rails (1.6.0) lint_roller (~> 1.0) - rubocop-rails (~> 2.33.4) + rubocop-rails (~> 2.34.0) stimulus-rails (1.3.4) railties (>= 6.0.0) stringio (3.2.0) @@ -838,7 +838,7 @@ DEPENDENCIES rspec-rails (~> 8.0.2) rubocop rubocop-performance - rubocop-rails (~> 2.33.4) + rubocop-rails (~> 2.34.3) sass-rails shoulda-matchers (~> 7.0) simple_form diff --git a/app/controllers/admin/users_controller.rb b/app/controllers/admin/users_controller.rb index 55528bbe32..84367bcd9c 100644 --- a/app/controllers/admin/users_controller.rb +++ b/app/controllers/admin/users_controller.rb @@ -24,7 +24,7 @@ def update redirect_to admin_users_path else flash[:error] = "Something didn't work quite right -- try again?" - redirect_back(fallback_location: edit_admin_user_path) + redirect_back_or_to(edit_admin_user_path) end end @@ -81,23 +81,23 @@ def add_role resource_type: params[:resource_type], resource_id: params[:resource_id]) rescue => e - redirect_back(fallback_location: admin_users_path, alert: e.message) + redirect_back_or_to(admin_users_path, alert: e.message) return end - redirect_back(fallback_location: admin_users_path, notice: "Role added!") + redirect_back_or_to(admin_users_path, notice: "Role added!") end def resend_invitation user = User.find(params[:user_id]) user.invite! - redirect_back(fallback_location: admin_users_path, notice: "#{user.name} reinvited!") + redirect_back_or_to(admin_users_path, notice: "#{user.name} reinvited!") end def remove_role RemoveRoleService.call(user_id: params[:user_id], role_id: params[:role_id]) - redirect_back(fallback_location: admin_users_path, notice: "Role removed!") + redirect_back_or_to(admin_users_path, notice: "Role removed!") rescue => e - redirect_back(fallback_location: admin_users_path, alert: e.message) + redirect_back_or_to(admin_users_path, alert: e.message) end private diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index aa200634b0..01e9f43918 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -19,7 +19,7 @@ class ApplicationController < ActionController::Base def session_expired flash[:error] = "Your session expired. This could be due to leaving a page open for a long time, or having multiple tabs open. Try resubmitting." - redirect_back fallback_location: root_path + redirect_back_or_to(root_path) end def current_organization diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index 31877f6ab1..e156714706 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -2,6 +2,6 @@ class AttachmentsController < ApplicationController def destroy ActiveStorage::Attachment.find(params[:id])&.purge - redirect_back fallback_location: partners_path + redirect_back_or_to(partners_path) end end diff --git a/app/controllers/audits_controller.rb b/app/controllers/audits_controller.rb index 6ef43c17ae..7d08c6949a 100644 --- a/app/controllers/audits_controller.rb +++ b/app/controllers/audits_controller.rb @@ -32,7 +32,7 @@ def finalize @audit.finalized! redirect_to audit_path(@audit), notice: "Audit is Finalized." rescue => e - redirect_back(fallback_location: audits_path, alert: "Could not finalize audit: #{e.message}") + redirect_back_or_to(audits_path, alert: "Could not finalize audit: #{e.message}") end def update diff --git a/app/controllers/concerns/importable.rb b/app/controllers/concerns/importable.rb index f2bd1515bb..10f58c097e 100644 --- a/app/controllers/concerns/importable.rb +++ b/app/controllers/concerns/importable.rb @@ -39,7 +39,7 @@ def import_csv else flash[:error] = "No file was attached!" end - redirect_back(fallback_location: { action: :index, organization_id: current_organization }) + redirect_back_or_to({ action: :index, organization_id: current_organization }) end private diff --git a/app/controllers/distributions_controller.rb b/app/controllers/distributions_controller.rb index 28051501da..474640a7d4 100644 --- a/app/controllers/distributions_controller.rb +++ b/app/controllers/distributions_controller.rb @@ -272,7 +272,7 @@ def picked_up flash[:error] = 'Sorry, we encountered an error when trying to mark this distribution as being completed' end - redirect_back(fallback_location: distribution_path) + redirect_back_or_to(distribution_path) end def pickup_day diff --git a/app/controllers/donation_sites_controller.rb b/app/controllers/donation_sites_controller.rb index ada764c432..5622a4330b 100644 --- a/app/controllers/donation_sites_controller.rb +++ b/app/controllers/donation_sites_controller.rb @@ -26,7 +26,7 @@ def create else flash.now[:error] = "Something didn't work quite right -- try again?" if request.format.turbo_stream? - format.html { render partial: "donation_sites/new_modal", status: :unprocessable_entity } + format.html { render partial: "donation_sites/new_modal", status: :unprocessable_content } end format.html do @@ -69,7 +69,7 @@ def deactivate donation_site.deactivate! rescue => e flash[:error] = e.message - redirect_back(fallback_location: donation_sites_path) + redirect_back_or_to(donation_sites_path) return end @@ -83,7 +83,7 @@ def reactivate donation_site.reactivate! rescue => e flash[:error] = e.message - redirect_back(fallback_location: donation_sites_path) + redirect_back_or_to(donation_sites_path) return end diff --git a/app/controllers/items_controller.rb b/app/controllers/items_controller.rb index 7c8bba423e..f17dcd6746 100644 --- a/app/controllers/items_controller.rb +++ b/app/controllers/items_controller.rb @@ -95,7 +95,7 @@ def deactivate item.deactivate! rescue => e flash[:error] = e.message - redirect_back(fallback_location: items_path) + redirect_back_or_to(items_path) return end @@ -108,7 +108,7 @@ def destroy item.destroy if item.errors.any? flash[:error] = item.errors.full_messages.join("\n") - redirect_back(fallback_location: items_path) + redirect_back_or_to(items_path) return end diff --git a/app/controllers/kits_controller.rb b/app/controllers/kits_controller.rb index e0257ffe7a..94f400334d 100644 --- a/app/controllers/kits_controller.rb +++ b/app/controllers/kits_controller.rb @@ -46,16 +46,16 @@ def create def deactivate @kit = current_organization.kits.find(params[:id]) @kit.deactivate - redirect_back(fallback_location: dashboard_path, notice: "Kit has been deactivated!") + redirect_back_or_to(dashboard_path, notice: "Kit has been deactivated!") end def reactivate @kit = current_organization.kits.find(params[:id]) if @kit.can_reactivate? @kit.reactivate - redirect_back(fallback_location: dashboard_path, notice: "Kit has been reactivated!") + redirect_back_or_to(dashboard_path, notice: "Kit has been reactivated!") else - redirect_back(fallback_location: dashboard_path, alert: "Cannot reactivate kit - it has inactive items! Please reactivate the items first.") + redirect_back_or_to(dashboard_path, alert: "Cannot reactivate kit - it has inactive items! Please reactivate the items first.") end end diff --git a/app/controllers/organizations_controller.rb b/app/controllers/organizations_controller.rb index ddb213e4f9..23677bc92f 100644 --- a/app/controllers/organizations_controller.rb +++ b/app/controllers/organizations_controller.rb @@ -51,7 +51,7 @@ def promote_to_org_admin resource_id: current_organization.id) redirect_to user_update_redirect_path, notice: "User has been promoted!" rescue => e - redirect_back(fallback_location: organization_path, alert: e.message) + redirect_back_or_to(organization_path, alert: e.message) end end @@ -64,7 +64,7 @@ def demote_to_user resource_id: current_organization.id) redirect_to user_update_redirect_path, notice: "User has been demoted!" rescue => e - redirect_back(fallback_location: organization_path, alert: e.message) + redirect_back_or_to(organization_path, alert: e.message) end end @@ -77,7 +77,7 @@ def remove_user resource_id: current_organization.id) redirect_to user_update_redirect_path, notice: "User has been removed!" rescue => e - redirect_back(fallback_location: organization_path, alert: e.message) + redirect_back_or_to(organization_path, alert: e.message) end end diff --git a/app/controllers/partner_users_controller.rb b/app/controllers/partner_users_controller.rb index 2b772458a8..c0df52cfe5 100644 --- a/app/controllers/partner_users_controller.rb +++ b/app/controllers/partner_users_controller.rb @@ -17,8 +17,7 @@ def create resource: @partner ) if @user.valid? - redirect_back(fallback_location: "/", - notice: "#{@user.name} has been invited. Invitation email sent to #{@user.email}") + redirect_back_or_to("/", notice: "#{@user.name} has been invited. Invitation email sent to #{@user.email}") else flash.now[:alert] = "Invitation failed. Check the form for errors." @users = @partner.users @@ -33,9 +32,9 @@ def destroy user = User.find(params[:id]) if user.remove_role(Role::PARTNER, @partner) - redirect_back(fallback_location: "/", notice: "Access to #{@partner.name} has been revoked for #{user.display_name}.") + redirect_back_or_to("/", notice: "Access to #{@partner.name} has been revoked for #{user.display_name}.") else - redirect_back(fallback_location: "/", alert: "Invitation failed. Check the form for errors.") + redirect_back_or_to("/", alert: "Invitation failed. Check the form for errors.") end end @@ -49,9 +48,9 @@ def resend_invitation end if user.errors.none? - redirect_back(fallback_location: "/", notice: "Invitation email sent to #{user.email}") + redirect_back_or_to("/", notice: "Invitation email sent to #{user.email}") else - redirect_back(fallback_location: "/", alert: user.errors.full_messages.to_sentence) + redirect_back_or_to("/", alert: user.errors.full_messages.to_sentence) end end @@ -59,7 +58,7 @@ def reset_password user = User.find(params[:id]) user.send_reset_password_instructions - redirect_back(fallback_location: root_path, notice: "Password e-mail sent!") + redirect_back_or_to(root_path, notice: "Password e-mail sent!") end private diff --git a/app/controllers/partners/authorized_family_members_controller.rb b/app/controllers/partners/authorized_family_members_controller.rb index 87ddc6b7fb..aa0746ca49 100644 --- a/app/controllers/partners/authorized_family_members_controller.rb +++ b/app/controllers/partners/authorized_family_members_controller.rb @@ -38,7 +38,7 @@ def destroy @authorized_family_member = current_partner.authorized_family_members.find_by(id: params[:id]) if @authorized_family_member.present? @authorized_family_member.destroy - redirect_back fallback_location: partners_families_url, notice: "Authorized family member removed." + redirect_back_or_to(partners_families_url, notice: "Authorized family member removed.") end end diff --git a/app/controllers/storage_locations_controller.rb b/app/controllers/storage_locations_controller.rb index 9b22e22836..4693c92c61 100644 --- a/app/controllers/storage_locations_controller.rb +++ b/app/controllers/storage_locations_controller.rb @@ -82,17 +82,17 @@ def show def import_inventory if params[:file].nil? - redirect_back(fallback_location: storage_locations_path) + redirect_back_or_to(storage_locations_path) flash[:error] = "No file was attached!" else filepath = params[:file].read StorageLocation.import_inventory(filepath, current_organization.id, params[:storage_location]) flash[:notice] = "Inventory imported successfully!" - redirect_back(fallback_location: storage_locations_path) + redirect_back_or_to(storage_locations_path) end rescue Errors::InventoryAlreadyHasItems => e flash[:error] = e.message - redirect_back(fallback_location: storage_locations_path(organization_id: current_organization)) + redirect_back_or_to(storage_locations_path(organization_id: current_organization)) end def update @@ -111,8 +111,7 @@ def deactivate if svc.call redirect_to storage_locations_path, notice: "Storage Location deactivated successfully" else - redirect_back(fallback_location: storage_locations_path, - error: "Cannot deactivate storage location containing inventory items with non-zero quantities") + redirect_back_or_to(storage_locations_path, error: "Cannot deactivate storage location containing inventory items with non-zero quantities") end end @@ -121,7 +120,7 @@ def reactivate if @storage_location.undiscard! redirect_to storage_locations_path, notice: "Storage Location reactivated successfully" else - redirect_back(fallback_location: storage_locations_path, error: "Something didn't work quite right -- try again?") + redirect_back_or_to(storage_locations_path, error: "Something didn't work quite right -- try again?") end end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 54a1f18189..b7debe7eeb 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -14,7 +14,7 @@ def switch_to_role role = Role.find(params[:role_id]) unless current_user.roles.include?(role) error_message = "Attempted to switch to a role that doesn't belong to you!" - redirect_back(fallback_location: root_path, alert: error_message) + redirect_back_or_to(root_path, alert: error_message) return end @@ -27,8 +27,7 @@ def switch_to_role def partner_user_reset_password partner = current_organization.partners.find_by(id: params[:partner_id]) if partner.nil? - redirect_back(fallback_location: root_path, - alert: "Could not find partner, or you do not have access to this partner!") + redirect_back_or_to(root_path, alert: "Could not find partner, or you do not have access to this partner!") return end @@ -36,12 +35,11 @@ def partner_user_reset_password .where("LOWER(email) = ?", params[:email].downcase) .first if user.nil? - redirect_back(fallback_location: root_path, - alert: "Could not find partner user for this partner with email #{params[:email]}!") + redirect_back_or_to(root_path, alert: "Could not find partner user for this partner with email #{params[:email]}!") return end user.send_reset_password_instructions - redirect_back(fallback_location: root_path, notice: "Password e-mail sent!") + redirect_back_or_to(root_path, notice: "Password e-mail sent!") end end diff --git a/app/controllers/vendors_controller.rb b/app/controllers/vendors_controller.rb index 585a98ac2f..8c41815602 100644 --- a/app/controllers/vendors_controller.rb +++ b/app/controllers/vendors_controller.rb @@ -68,7 +68,7 @@ def deactivate vendor.deactivate! rescue => e flash[:error] = e.message - redirect_back(fallback_location: vendors_path) + redirect_back_or_to(vendors_path) return end @@ -82,7 +82,7 @@ def reactivate vendor.reactivate! rescue => e flash[:error] = e.message - redirect_back(fallback_location: vendors_path) + redirect_back_or_to(vendors_path) return end