Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add decidim geo module #422

Merged
merged 10 commits into from
Mar 27, 2024
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
5 changes: 3 additions & 2 deletions .docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#
# Also we don't use -onbuild as they're deprecated
# https://github.com/docker-library/official-images/issues/2076
FROM ruby:3.0.2 as dev
FROM ruby:3.0.6 as dev
LABEL maintainer="[email protected]"

# Installs system dependencies
Expand Down Expand Up @@ -72,5 +72,6 @@ ENV LANG=C.UTF-8 \
BUNDLE_JOBS=20 \
BUNDLE_RETRY=5 \
PATH=${APP_HOME}/bin:${PATH}
RUN gem install bundler:2.4.5
RUN gem install bundler:2.5.6
RUN bundle update --bundler
RUN bundle install
2 changes: 1 addition & 1 deletion .github/workflows/rails-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:

services:
postgres:
image: 'postgres:11.6-alpine'
image: 'postgis/postgis:14-3.3-alpine'
env:
POSTGRES_PASSWORD: 'postgres'
ports: ['5432:5432']
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ RUN adduser --disabled-password --uid 1001 --gid 0 --gecos "" --shell /bin/bash

ARG BUNDLE_WITHOUT='development:metrics:test'
ARG BUNDLER_VERSION="2.3.22"
ARG RUN_PACKAGES="clamav clamav-daemon git graphicsmagick libicu-dev libpq5 nodejs poppler-utils"
ARG RUN_PACKAGES="clamav clamav-daemon git graphicsmagick libicu-dev libpq5 nodejs poppler-utils libgeos-dev"
ARG PS1='$SENTRY_CURRENT_ENV:$PWD$ '
ENV PS1=$PS1
ARG TZ="Europe/Zurich"
Expand Down
5 changes: 4 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ gem 'decidim-proposals', DECIDIM_VERSION
gem 'decidim-conferences', DECIDIM_VERSION
gem 'decidim-templates', DECIDIM_VERSION

gem 'decidim-antivirus', github: 'mainio/decidim-module-antivirus', branch: 'release/0.27-stable'
gem 'decidim-decidim_geo', github: 'octree-gva/decidim-module-geo', tag: "v0.2.1"
gem 'decidim-anonymous_proposals', github: 'puzzle/decidim-module-anonymous_proposals', branch: 'release/0.27-stable'
gem 'decidim-antivirus', github: 'mainio/decidim-module-antivirus', branch: 'release/0.27-stable'
gem 'decidim-cleaner', github: 'puzzle/decidim-module-cleaner', branch: 'release/0.27-stable'
gem 'decidim-decidim_awesome', github: 'decidim-ice/decidim-module-decidim_awesome'
gem 'decidim-participatory_documents', github: 'openpoke/decidim-module-participatory-documents', tag: '0.2.2'
Expand Down Expand Up @@ -60,5 +61,7 @@ group :production do
gem 'bleib'
end

gem 'rectify', '~> 0.13.0'

# Needs to be loaded after all other delayed_job gems
gem 'delayed_cron_job'
46 changes: 44 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,21 @@ GIT
omniauth (~> 2.0)
openid_connect (~> 1.2)

GIT
remote: https://github.com/octree-gva/decidim-module-geo.git
revision: c1636ba0ed742db8253dc456a93f22584af50d2b
tag: v0.2.1
specs:
decidim-decidim_geo (0.2.1)
activerecord-postgis-adapter (>= 6.0)
decidim-admin (>= 0.26, < 0.28)
decidim-core (>= 0.26, < 0.28)
deface (>= 1.8.1)
ffi-geos (~> 2.4)
rgeo (>= 3.0)
rgeo-geojson (>= 1.0)
rgeo-shapefile (>= 1.0)

GIT
remote: https://github.com/openpoke/decidim-module-participatory-documents.git
revision: 76957bf7bbceb3235eb912b64361ed4a4e521f8a
Expand Down Expand Up @@ -122,6 +137,9 @@ GEM
activerecord (6.1.7.6)
activemodel (= 6.1.7.6)
activesupport (= 6.1.7.6)
activerecord-postgis-adapter (7.1.1)
activerecord (~> 6.1)
rgeo-activerecord (~> 7.0.0)
activestorage (6.1.7.6)
actionpack (= 6.1.7.6)
activejob (= 6.1.7.6)
Expand Down Expand Up @@ -247,6 +265,7 @@ GEM
crass (1.0.6)
css_parser (1.16.0)
addressable
csv (3.3.0)
dalli (3.2.5)
date (3.3.4)
date_validator (0.12.0)
Expand All @@ -255,6 +274,8 @@ GEM
db-query-matchers (0.10.0)
activesupport (>= 4.0, < 7)
rspec (~> 3.0)
dbf (4.3.2)
csv
debug_inspector (1.1.0)
decidim (0.27.5)
decidim-accountability (= 0.27.5)
Expand Down Expand Up @@ -472,6 +493,7 @@ GEM
railties (>= 5)
doorkeeper-i18n (4.0.1)
dumb_delegator (1.0.0)
equalizer (0.0.11)
erb_lint (0.0.37)
activesupport
better_html (~> 1.0.7)
Expand Down Expand Up @@ -504,6 +526,8 @@ GEM
faraday-net_http (3.1.0)
net-http
ffi (1.16.3)
ffi-geos (2.4.0)
ffi (>= 1.0.0)
file_validators (3.0.0)
activemodel (>= 3.2)
mime-types (>= 1.0)
Expand Down Expand Up @@ -799,6 +823,12 @@ GEM
rb-fsevent (0.11.2)
rb-inotify (0.10.1)
ffi (~> 1.0)
rectify (0.13.0)
activemodel (>= 4.1.0)
activerecord (>= 4.1.0)
activesupport (>= 4.1.0)
virtus (~> 1.0.5)
wisper (>= 1.6.1)
redcarpet (3.6.0)
redis (4.8.1)
regexp_parser (2.9.0)
Expand All @@ -808,6 +838,15 @@ GEM
actionpack (>= 5.2)
railties (>= 5.2)
rexml (3.2.6)
rgeo (3.0.1)
rgeo-activerecord (7.0.1)
activerecord (>= 5.0)
rgeo (>= 1.0.0)
rgeo-geojson (2.1.1)
rgeo (>= 1.0.0)
rgeo-shapefile (3.1.0)
dbf (~> 4.0)
rgeo (>= 1.0)
rouge (4.1.3)
rspec (3.12.0)
rspec-core (~> 3.12.0)
Expand Down Expand Up @@ -935,10 +974,11 @@ GEM
activemodel (>= 3.0.0)
public_suffix
version_gem (1.1.3)
virtus (2.0.0)
virtus (1.0.5)
axiom-types (~> 0.1)
coercible (~> 1.0)
descendants_tracker (~> 0.0, >= 0.0.3)
equalizer (~> 0.0, >= 0.0.9)
w3c_rspec_validators (0.3.0)
rails
rspec
Expand Down Expand Up @@ -1000,6 +1040,7 @@ DEPENDENCIES
decidim-cleaner!
decidim-conferences (= 0.27.5)
decidim-decidim_awesome!
decidim-decidim_geo!
decidim-dev (= 0.27.5)
decidim-participatory_documents!
decidim-proposals (= 0.27.5)
Expand All @@ -1019,6 +1060,7 @@ DEPENDENCIES
pry-byebug
pry-rails
puma
rectify (~> 0.13.0)
sentry-raven
spring
spring-watcher-listen
Expand All @@ -1029,4 +1071,4 @@ RUBY VERSION
ruby 3.0.6p216

BUNDLED WITH
2.5.5
2.5.6
8 changes: 7 additions & 1 deletion config/database.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
---
default: &default
adapter: postgresql
adapter: postgis
encoding: unicode
pool: <%= ENV.fetch('RAILS_MAX_THREADS') { 5 } %>
host: <%= ENV.fetch('RAILS_DB_HOST') { 'localhost' } %>
port: <%= ENV.fetch('RAILS_DB_PORT') { '5432' } %>
username: <%= ENV.fetch('RAILS_DB_USERNAME') { 'decidim_zuerich' } %>
password: <%= ENV.fetch('RAILS_DB_PASSWORD') { 'dN5GH8y3lX' } %>

schema_search_path: <%= ENV.fetch('RAILS_DB_SCHEMA_SEARCH_PATH') { 'public' } %>
postgis_extension: <%= ENV.fetch('RAILS_DB_POSTGIS_EXTENSION') { 'postgis' } %>
postgis_schema: <%= ENV.fetch('RAILS_DB_POSTGIS_SCHEMA') { 'public' } %>
su_username: <%= ENV.fetch('RAILS_DB_SU_USERNAME') { 'postgres' } %>
su_password: <%= ENV.fetch('RAILS_DB_SU_PASSWORD') { 'postgres' } %>

development:
<<: *default
database: <%= ENV.fetch('RAILS_DB_NAME', 'decidim_zuerich_development') %>
Expand Down
16 changes: 15 additions & 1 deletion config/initializers/decidim.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,19 @@
config.available_locales = %i[en de fr it]

config.maps = {
provider: :osm,
api_key: false, #Rails.application.secrets.maps[:api_key],
dynamic: {
tile_layer: {
url: "https://tiles.example.org/{z}/{x}/{y}.png?key={apiKey}&{foo}",
api_key: true,
foo: "bar=baz",
attribution: %(
<a href="https://www.openstreetmap.org/copyright" target="_blank">&copy; OpenStreetMap</a> contributors
).strip
# Translatable attribution:
# attribution: -> { I18n.t("tile_layer_attribution") }
},
provider: :gis_zh,
# provider: :swisstopo,
default_center: {
Expand All @@ -37,8 +49,10 @@
},
}
},
static: false,
static: { url: "https://staticmap.example.org/" },
geocoding: {
host: "nominatim.example.org",
use_https: true,
provider: :osm,
timeout: 5,
units: :km,
Expand Down
3 changes: 1 addition & 2 deletions config/initializers/rack_attack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
# Rack::Attack.enabled = ENV.fetch('ENABLE_RACK_ATTACK', Rails.env.production?.to_s).in?(%w[true 1])
Rack::Attack.enabled = true


safelist_ips = ENV.fetch('RACK_ATTACK_SAFELIST_IPS', '').split(',').map(&:strip)

safelist_ips.each do |ip_or_subnet|
Expand All @@ -14,7 +13,7 @@
Rack::Attack.safelist_ip(ip_or_subnet)
end

Rack::Attack.throttle('requests by ip', limit: 5, period: 2, &:ip)
Rack::Attack.throttle('requests by ip', limit: 100, period: 10, &:ip)

Rack::Attack.blocklist('secure admin logins') do |req|
Rack::Attack::Allow2Ban.filter(req.ip, maxretry: 5, findtime: 10.minutes, bantime: 1.hour) do
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# This migration comes from decidim_geo (originally 20221019184712)
class AddPostgisExtensionToDatabase < ActiveRecord::Migration[6.0]
def change
raise "Postgis adapter not enabled" unless ActiveRecord::Base.connection.adapter_name == "PostGIS"
enable_extension 'postgis'
end
end
23 changes: 23 additions & 0 deletions db/migrate/20240303000156_create_decidim_geo.decidim_geo.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# This migration comes from decidim_geo (originally 20221025195520)
class CreateDecidimGeo < ActiveRecord::Migration[6.0]
def change
create_table :decidim_geo_shapefiles do |t|
t.string :title, null: false
t.string :description, null: true
t.string :shapefile, null: false
t.belongs_to :decidim_scope_types, index: true, foreign_key: true, null: true

t.timestamps
end

create_table :decidim_geo_shapefile_datas do |t|
t.belongs_to :decidim_geo_shapefiles, index: true, foreign_key: true
t.jsonb :data
t.multi_polygon :geom

t.belongs_to :decidim_scopes, index: true, foreign_key: true, null: true

t.timestamps
end
end
end
12 changes: 12 additions & 0 deletions db/migrate/20240327124210_create_decidim_geo_config.decidim_geo.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# This migration comes from decidim_geo (originally 20231013082325)
# This migration comes from decidim_geo (originally 20231012094655)
class CreateDecidimGeoConfig < ActiveRecord::Migration[6.0]
def change
create_table :decidim_geo_configs do |t|
t.float :longitude, null: true
t.float :latitude, null: true
t.integer :zoom, null: true
t.string :tile, null: true
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# This migration comes from decidim_geo (originally 20231206115531)
class AddSpacesConfigToDecidimGeoConfigs < ActiveRecord::Migration[6.1]
def change
add_column :decidim_geo_configs, :only_processes, :boolean, default: false, null: false
add_column :decidim_geo_configs, :only_assemblies, :boolean, default: false, null: false
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# This migration comes from decidim_geo (originally 20240309004347)
class AddOrganizationToShapefiles < ActiveRecord::Migration[6.1]
def change
add_reference :decidim_geo_shapefiles, :decidim_organization, foreign_key: true, null: true
remove_column :decidim_geo_shapefiles, :shapefile
end
end
19 changes: 19 additions & 0 deletions db/migrate/20240327124213_create_space_locations.decidim_geo.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# This migration comes from decidim_geo (originally 20240326052727)
class CreateSpaceLocations < ActiveRecord::Migration[6.1]
def change
create_table :decidim_geo_space_locations do |t|
t.bigint :decidim_geo_space_id
t.string :decidim_geo_space_type
t.string :address
t.float :latitude
t.float :longitude
t.timestamps
end

add_index :decidim_geo_space_locations,
[:decidim_geo_space_type, :decidim_geo_space_id],
unique: true,
name: "decidim_geo_space_poly_idx"

end
end
11 changes: 11 additions & 0 deletions db/migrate/20240327215408_revert_homepage_interactive_map.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class RevertHomepageInteractiveMap < ActiveRecord::Migration[6.1]
require_relative '20210429220804_add_geo_json_to_scopes.decidim_homepage_interactive_map.rb'
require_relative '20210429220805_add_geolocation_to_participatory_processes.decidim_homepage_interactive_map.rb'
require_relative '20210429220806_add_display_linked_assemblies_to_participatory_processes.decidim_homepage_interactive_map.rb'

def change
revert AddDisplayLinkedAssembliesToParticipatoryProcesses
revert AddGeolocationToParticipatoryProcesses
revert AddGeoJsonToScopes
end
end
Loading
Loading