Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
20 changes: 10 additions & 10 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions app/controllers/admin/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/attachments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion app/controllers/audits_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/concerns/importable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/distributions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/donation_sites_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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

Expand Down
4 changes: 2 additions & 2 deletions app/controllers/items_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down
6 changes: 3 additions & 3 deletions app/controllers/kits_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions app/controllers/organizations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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

Expand Down
13 changes: 6 additions & 7 deletions app/controllers/partner_users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -49,17 +48,17 @@ 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

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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
11 changes: 5 additions & 6 deletions app/controllers/storage_locations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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

Expand Down
10 changes: 4 additions & 6 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -27,21 +27,19 @@ 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

user = User.with_role(:partner, partner)
.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
Loading
Loading