Skip to content

Commit

Permalink
Address mass-assignment in controllers
Browse files Browse the repository at this point in the history
Two instances where we were `permit!`-ing all params, and really didn't
need to.
  • Loading branch information
werebus committed Feb 12, 2025
1 parent 9e4ef69 commit c07d402
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions app/controllers/bus_stops_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def search_for_stop
end

def stop_params
# no attributes that people aren't supposed to be able to edit
params.require(:bus_stop).permit!
fields = BusStop::Options::COMBINED.values.flat_map(&:keys)
params.require(:bus_stop).permit(:garage_responsible, :state_road, :needs_work, :completed, *fields)
end
end
10 changes: 5 additions & 5 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ def find_user
end

def user_params
attrs = params.require(:user).permit!
if attrs[:password].blank?
attrs.delete :password
attrs.delete :password_confirmation
params.require(:user).permit(:name, :email, :password, :password_confirmation, :admin).tap do |p|
if p[:password].blank?
p.delete :password
p.delete :password_confirmation
end
end
attrs
end
end

0 comments on commit c07d402

Please sign in to comment.