Skip to content

Commit

Permalink
fix: Handle GeoJSON FeatureCollection
Browse files Browse the repository at this point in the history
  • Loading branch information
moustachu committed Sep 11, 2024
1 parent 1ff2225 commit edb05d4
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions app/forms/decidim/admin/scope_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ScopeForm < Form
attribute :geolocalized, Boolean
jsonb_attribute :geojson, [
[:geometry, String],
[:parsed_geometry, String],
[:parsed_geometry, Hash],
[:color, String]
]

Expand Down Expand Up @@ -49,7 +49,14 @@ def parsable_json
return true if geolocalized.blank?

begin
self.parsed_geometry = JSON.parse(geometry)
self.parsed_geometry = JSON.parse(geometry).deep_symbolize_keys
if parsed_geometry[:type] = "FeatureCollection"
if parsed_geometry[:features]&.size > 1
errors.add(:geometry, "GeoJSON error : FeatureCollection with more than one feature are not valid")
else
self.parsed_geometry = parsed_geometry[:features]&.first
end
end
rescue StandardError
errors.add(:geometry, I18n.t("decidim.scope.errors.geojson_error"))
end
Expand Down

0 comments on commit edb05d4

Please sign in to comment.