From 70b6b56bcb4d682b08d7fea81123e691d789884f Mon Sep 17 00:00:00 2001 From: danigb Date: Tue, 21 Nov 2017 15:10:05 +0100 Subject: [PATCH] decidim-census: Authorise via census using a CSV file (engine) (#15) Fixes #7 --- .gitignore | 2 + Gemfile | 8 +- Gemfile.lock | 19 + config/routes.rb | 5 + ...dd_reference_to_results.decidim_results.rb | 3 +- ..._authorizations_to_organization.decidim.rb | 3 +- ...im_census_census_datum.decidim_censuses.rb | 16 + db/schema.rb | 11 +- decidim-census/.gitignore | 8 + decidim-census/Gemfile | 14 + decidim-census/Gemfile.lock | 575 +++++++++++++++ decidim-census/LICENSE | 661 ++++++++++++++++++ decidim-census/README.md | 47 ++ decidim-census/Rakefile | 3 + .../census/admin/application_controller.rb | 17 + .../census/admin/censuses_controller.rb | 45 ++ .../decidim/census/application_controller.rb | 9 + .../jobs/decidim/census/application_job.rb | 6 + .../decidim/census/remove_duplicates_job.rb | 29 + .../decidim/census/abilities/admin_ability.rb | 18 + .../decidim/census/application_record.rb | 9 + .../app/models/decidim/census/census_datum.rb | 50 ++ .../app/models/decidim/census/csv_data.rb | 33 + .../app/models/decidim/census/status.rb | 28 + .../services/census_authorization_handler.rb | 48 ++ .../views/census_authorization/_form.html.erb | 20 + .../admin/censuses/instructions.html.erb | 10 + .../census/admin/censuses/show.html.erb | 43 ++ .../views/layouts/census/application.html.erb | 14 + decidim-census/bin/rails | 13 + decidim-census/config/locales/ca.yml | 46 ++ decidim-census/config/locales/en.yml | 46 ++ decidim-census/config/locales/es.yml | 46 ++ decidim-census/config/routes.rb | 2 + decidim-census/config/spring.rb | 4 + ...20821_create_decidim_census_census_data.rb | 14 + decidim-census/decidim-census.gemspec | 27 + ...iputaci\303\263 de barcelona - Sheet1.csv" | 4 + decidim-census/examples/generate.rb | 11 + decidim-census/lib/decidim/census.rb | 12 + decidim-census/lib/decidim/census/admin.rb | 10 + .../lib/decidim/census/admin_engine.rb | 33 + decidim-census/lib/decidim/census/engine.rb | 29 + .../census/extensions/authorize_with_age.rb | 44 ++ decidim-census/lib/decidim/census/version.rb | 6 + .../controllers/censuses_controller_spec.rb | 57 ++ .../extensions/authorize_with_age_spec.rb | 44 ++ decidim-census/spec/factories/census_datum.rb | 7 + decidim-census/spec/factories/factories.rb | 2 + decidim-census/spec/fixtures/files/data1.csv | 4 + .../spec/fixtures/files/with-errors.csv | 7 + .../spec/jobs/remove_duplicates_job_spec.rb | 20 + .../spec/models/census_datum_spec.rb | 42 ++ decidim-census/spec/models/csv_data_spec.rb | 19 + decidim-census/spec/models/status_spec.rb | 19 + .../census_authorization_handler_spec.rb | 38 + decidim-census/spec/spec_helper.rb | 22 + spec/decidim_dummy_app/.gitignore | 22 + spec/decidim_dummy_app/Dockerfile | 26 + spec/decidim_dummy_app/Gemfile | 35 + spec/decidim_dummy_app/Gemfile.lock | 591 ++++++++++++++++ spec/decidim_dummy_app/README.md | 26 + spec/decidim_dummy_app/Rakefile | 6 + .../app/assets/config/manifest.js | 3 + .../decidim_dummy_app/app/assets/images/.keep | 0 .../app/assets/javascripts/application.js | 16 + .../app/assets/javascripts/cable.js | 13 + .../app/assets/javascripts/channels/.keep | 0 .../app/assets/stylesheets/application.css | 16 + .../app/assets/stylesheets/decidim.scss | 18 + .../app/channels/application_cable/channel.rb | 4 + .../channels/application_cable/connection.rb | 4 + .../app/controllers/application_controller.rb | 5 + .../app/controllers/concerns/.keep | 0 .../app/controllers/decidim_controller.rb | 5 + .../app/helpers/application_helper.rb | 2 + .../app/jobs/application_job.rb | 2 + .../app/mailers/application_mailer.rb | 6 + .../app/models/application_record.rb | 5 + .../app/models/concerns/.keep | 0 .../decidim/dummy_authorization_handler.rb | 29 + .../app/views/layouts/mailer.html.erb | 13 + spec/decidim_dummy_app/bin/bundle | 3 + spec/decidim_dummy_app/bin/rails | 4 + spec/decidim_dummy_app/bin/rake | 4 + spec/decidim_dummy_app/bin/setup | 37 + spec/decidim_dummy_app/bin/update | 29 + spec/decidim_dummy_app/bin/yarn | 11 + spec/decidim_dummy_app/config.ru | 5 + spec/decidim_dummy_app/config/application.rb | 20 + spec/decidim_dummy_app/config/boot.rb | 4 + spec/decidim_dummy_app/config/cable.yml | 9 + spec/decidim_dummy_app/config/database.yml | 87 +++ spec/decidim_dummy_app/config/environment.rb | 5 + .../config/environments/development.rb | 54 ++ .../config/environments/production.rb | 112 +++ .../config/environments/test.rb | 42 ++ .../application_controller_renderer.rb | 8 + .../config/initializers/assets.rb | 14 + .../initializers/backtrace_silencers.rb | 7 + .../config/initializers/carrierwave.rb | 28 + .../config/initializers/cookies_serializer.rb | 5 + .../config/initializers/decidim.rb | 48 ++ .../initializers/filter_parameter_logging.rb | 4 + .../config/initializers/inflections.rb | 16 + .../config/initializers/mime_types.rb | 4 + .../initializers/social_share_button.rb | 8 + .../config/initializers/wrap_parameters.rb | 14 + spec/decidim_dummy_app/config/locales/en.yml | 33 + spec/decidim_dummy_app/config/puma.rb | 56 ++ spec/decidim_dummy_app/config/routes.rb | 4 + spec/decidim_dummy_app/config/secrets.yml | 62 ++ spec/decidim_dummy_app/config/spring.rb | 9 + spec/decidim_dummy_app/db/seeds.rb | 9 + spec/decidim_dummy_app/docker-compose.yml | 28 + spec/decidim_dummy_app/lib/assets/.keep | 0 spec/decidim_dummy_app/lib/tasks/.keep | 0 spec/decidim_dummy_app/log/.keep | 0 spec/decidim_dummy_app/package.json | 5 + spec/decidim_dummy_app/public/422.html | 67 ++ .../public/apple-touch-icon-precomposed.png | 0 .../public/apple-touch-icon.png | 0 spec/decidim_dummy_app/public/favicon.ico | 0 spec/decidim_dummy_app/public/robots.txt | 1 + .../test/application_system_test_case.rb | 7 + spec/decidim_dummy_app/test/controllers/.keep | 0 spec/decidim_dummy_app/test/fixtures/.keep | 0 .../test/fixtures/files/.keep | 0 spec/decidim_dummy_app/test/helpers/.keep | 0 spec/decidim_dummy_app/test/integration/.keep | 0 spec/decidim_dummy_app/test/mailers/.keep | 0 spec/decidim_dummy_app/test/models/.keep | 0 spec/decidim_dummy_app/test/system/.keep | 0 spec/decidim_dummy_app/test/test_helper.rb | 11 + spec/decidim_dummy_app/tmp/.keep | 0 spec/decidim_dummy_app/vendor/.keep | 0 136 files changed, 4096 insertions(+), 7 deletions(-) create mode 100644 db/migrate/20171120130226_create_decidim_census_census_datum.decidim_censuses.rb create mode 100644 decidim-census/.gitignore create mode 100644 decidim-census/Gemfile create mode 100644 decidim-census/Gemfile.lock create mode 100644 decidim-census/LICENSE create mode 100644 decidim-census/README.md create mode 100644 decidim-census/Rakefile create mode 100644 decidim-census/app/controllers/decidim/census/admin/application_controller.rb create mode 100644 decidim-census/app/controllers/decidim/census/admin/censuses_controller.rb create mode 100644 decidim-census/app/controllers/decidim/census/application_controller.rb create mode 100644 decidim-census/app/jobs/decidim/census/application_job.rb create mode 100644 decidim-census/app/jobs/decidim/census/remove_duplicates_job.rb create mode 100644 decidim-census/app/models/decidim/census/abilities/admin_ability.rb create mode 100644 decidim-census/app/models/decidim/census/application_record.rb create mode 100644 decidim-census/app/models/decidim/census/census_datum.rb create mode 100644 decidim-census/app/models/decidim/census/csv_data.rb create mode 100644 decidim-census/app/models/decidim/census/status.rb create mode 100644 decidim-census/app/services/census_authorization_handler.rb create mode 100644 decidim-census/app/views/census_authorization/_form.html.erb create mode 100644 decidim-census/app/views/decidim/census/admin/censuses/instructions.html.erb create mode 100644 decidim-census/app/views/decidim/census/admin/censuses/show.html.erb create mode 100644 decidim-census/app/views/layouts/census/application.html.erb create mode 100755 decidim-census/bin/rails create mode 100644 decidim-census/config/locales/ca.yml create mode 100644 decidim-census/config/locales/en.yml create mode 100644 decidim-census/config/locales/es.yml create mode 100644 decidim-census/config/routes.rb create mode 100644 decidim-census/config/spring.rb create mode 100644 decidim-census/db/migrate/20171110120821_create_decidim_census_census_data.rb create mode 100644 decidim-census/decidim-census.gemspec create mode 100644 "decidim-census/examples/Exemple de dades de cens per diputaci\303\263 de barcelona - Sheet1.csv" create mode 100644 decidim-census/examples/generate.rb create mode 100644 decidim-census/lib/decidim/census.rb create mode 100644 decidim-census/lib/decidim/census/admin.rb create mode 100644 decidim-census/lib/decidim/census/admin_engine.rb create mode 100644 decidim-census/lib/decidim/census/engine.rb create mode 100644 decidim-census/lib/decidim/census/extensions/authorize_with_age.rb create mode 100644 decidim-census/lib/decidim/census/version.rb create mode 100644 decidim-census/spec/controllers/censuses_controller_spec.rb create mode 100644 decidim-census/spec/extensions/authorize_with_age_spec.rb create mode 100644 decidim-census/spec/factories/census_datum.rb create mode 100644 decidim-census/spec/factories/factories.rb create mode 100644 decidim-census/spec/fixtures/files/data1.csv create mode 100644 decidim-census/spec/fixtures/files/with-errors.csv create mode 100644 decidim-census/spec/jobs/remove_duplicates_job_spec.rb create mode 100644 decidim-census/spec/models/census_datum_spec.rb create mode 100644 decidim-census/spec/models/csv_data_spec.rb create mode 100644 decidim-census/spec/models/status_spec.rb create mode 100644 decidim-census/spec/services/census_authorization_handler_spec.rb create mode 100644 decidim-census/spec/spec_helper.rb create mode 100644 spec/decidim_dummy_app/.gitignore create mode 100644 spec/decidim_dummy_app/Dockerfile create mode 100644 spec/decidim_dummy_app/Gemfile create mode 100644 spec/decidim_dummy_app/Gemfile.lock create mode 100644 spec/decidim_dummy_app/README.md create mode 100644 spec/decidim_dummy_app/Rakefile create mode 100644 spec/decidim_dummy_app/app/assets/config/manifest.js create mode 100644 spec/decidim_dummy_app/app/assets/images/.keep create mode 100644 spec/decidim_dummy_app/app/assets/javascripts/application.js create mode 100644 spec/decidim_dummy_app/app/assets/javascripts/cable.js create mode 100644 spec/decidim_dummy_app/app/assets/javascripts/channels/.keep create mode 100644 spec/decidim_dummy_app/app/assets/stylesheets/application.css create mode 100644 spec/decidim_dummy_app/app/assets/stylesheets/decidim.scss create mode 100644 spec/decidim_dummy_app/app/channels/application_cable/channel.rb create mode 100644 spec/decidim_dummy_app/app/channels/application_cable/connection.rb create mode 100644 spec/decidim_dummy_app/app/controllers/application_controller.rb create mode 100644 spec/decidim_dummy_app/app/controllers/concerns/.keep create mode 100644 spec/decidim_dummy_app/app/controllers/decidim_controller.rb create mode 100644 spec/decidim_dummy_app/app/helpers/application_helper.rb create mode 100644 spec/decidim_dummy_app/app/jobs/application_job.rb create mode 100644 spec/decidim_dummy_app/app/mailers/application_mailer.rb create mode 100644 spec/decidim_dummy_app/app/models/application_record.rb create mode 100644 spec/decidim_dummy_app/app/models/concerns/.keep create mode 100644 spec/decidim_dummy_app/app/services/decidim/dummy_authorization_handler.rb create mode 100644 spec/decidim_dummy_app/app/views/layouts/mailer.html.erb create mode 100755 spec/decidim_dummy_app/bin/bundle create mode 100755 spec/decidim_dummy_app/bin/rails create mode 100755 spec/decidim_dummy_app/bin/rake create mode 100755 spec/decidim_dummy_app/bin/setup create mode 100755 spec/decidim_dummy_app/bin/update create mode 100755 spec/decidim_dummy_app/bin/yarn create mode 100644 spec/decidim_dummy_app/config.ru create mode 100644 spec/decidim_dummy_app/config/application.rb create mode 100644 spec/decidim_dummy_app/config/boot.rb create mode 100644 spec/decidim_dummy_app/config/cable.yml create mode 100644 spec/decidim_dummy_app/config/database.yml create mode 100644 spec/decidim_dummy_app/config/environment.rb create mode 100644 spec/decidim_dummy_app/config/environments/development.rb create mode 100644 spec/decidim_dummy_app/config/environments/production.rb create mode 100644 spec/decidim_dummy_app/config/environments/test.rb create mode 100644 spec/decidim_dummy_app/config/initializers/application_controller_renderer.rb create mode 100644 spec/decidim_dummy_app/config/initializers/assets.rb create mode 100644 spec/decidim_dummy_app/config/initializers/backtrace_silencers.rb create mode 100644 spec/decidim_dummy_app/config/initializers/carrierwave.rb create mode 100644 spec/decidim_dummy_app/config/initializers/cookies_serializer.rb create mode 100644 spec/decidim_dummy_app/config/initializers/decidim.rb create mode 100644 spec/decidim_dummy_app/config/initializers/filter_parameter_logging.rb create mode 100644 spec/decidim_dummy_app/config/initializers/inflections.rb create mode 100644 spec/decidim_dummy_app/config/initializers/mime_types.rb create mode 100644 spec/decidim_dummy_app/config/initializers/social_share_button.rb create mode 100644 spec/decidim_dummy_app/config/initializers/wrap_parameters.rb create mode 100644 spec/decidim_dummy_app/config/locales/en.yml create mode 100644 spec/decidim_dummy_app/config/puma.rb create mode 100644 spec/decidim_dummy_app/config/routes.rb create mode 100644 spec/decidim_dummy_app/config/secrets.yml create mode 100644 spec/decidim_dummy_app/config/spring.rb create mode 100644 spec/decidim_dummy_app/db/seeds.rb create mode 100644 spec/decidim_dummy_app/docker-compose.yml create mode 100644 spec/decidim_dummy_app/lib/assets/.keep create mode 100644 spec/decidim_dummy_app/lib/tasks/.keep create mode 100644 spec/decidim_dummy_app/log/.keep create mode 100644 spec/decidim_dummy_app/package.json create mode 100644 spec/decidim_dummy_app/public/422.html create mode 100644 spec/decidim_dummy_app/public/apple-touch-icon-precomposed.png create mode 100644 spec/decidim_dummy_app/public/apple-touch-icon.png create mode 100644 spec/decidim_dummy_app/public/favicon.ico create mode 100644 spec/decidim_dummy_app/public/robots.txt create mode 100644 spec/decidim_dummy_app/test/application_system_test_case.rb create mode 100644 spec/decidim_dummy_app/test/controllers/.keep create mode 100644 spec/decidim_dummy_app/test/fixtures/.keep create mode 100644 spec/decidim_dummy_app/test/fixtures/files/.keep create mode 100644 spec/decidim_dummy_app/test/helpers/.keep create mode 100644 spec/decidim_dummy_app/test/integration/.keep create mode 100644 spec/decidim_dummy_app/test/mailers/.keep create mode 100644 spec/decidim_dummy_app/test/models/.keep create mode 100644 spec/decidim_dummy_app/test/system/.keep create mode 100644 spec/decidim_dummy_app/test/test_helper.rb create mode 100644 spec/decidim_dummy_app/tmp/.keep create mode 100644 spec/decidim_dummy_app/vendor/.keep diff --git a/.gitignore b/.gitignore index dce3439b..4c48bd1d 100644 --- a/.gitignore +++ b/.gitignore @@ -25,3 +25,5 @@ public/uploads # Ignore env variables .env .env.* +.vscode/ +.DS_Store diff --git a/Gemfile b/Gemfile index 87e449a1..8caa1d63 100644 --- a/Gemfile +++ b/Gemfile @@ -3,9 +3,12 @@ source 'https://rubygems.org' ruby '2.4.0' gem 'decidim', '~> 0.7.2' -gem 'sidekiq' +gem 'decidim-census', path: 'decidim-census' +gem 'letter_opener_web' gem 'puma', '~> 3.10' +gem 'sidekiq' +gem 'tzinfo-data', platforms: %i(mingw mswin x64_mingw jruby) gem 'uglifier', '>= 1.3.0' group :development, :test do @@ -28,6 +31,3 @@ group :development do gem 'spring-watcher-listen', '~> 2.0.0' gem 'web-console' end - -# Windows does not include zoneinfo files, so bundle the tzinfo-data gem -gem 'tzinfo-data', platforms: %i(mingw mswin x64_mingw jruby) diff --git a/Gemfile.lock b/Gemfile.lock index 7b7cb244..c928891a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,3 +1,12 @@ +PATH + remote: decidim-census + specs: + decidim-census (0.7.2) + decidim (= 0.7.2) + decidim-admin (= 0.7.2) + rails (~> 5.1.4) + virtus-multiparams (~> 0.1.1) + GEM remote: https://rubygems.org/ specs: @@ -326,6 +335,12 @@ GEM kaminari-core (1.0.1) launchy (2.4.3) addressable (~> 2.3) + letter_opener (1.4.1) + launchy (~> 2.2) + letter_opener_web (1.3.1) + actionmailer (>= 3.2) + letter_opener (~> 1.0) + railties (>= 3.2) listen (3.1.5) rb-fsevent (~> 0.9, >= 0.9.4) rb-inotify (~> 0.9, >= 0.9.7) @@ -564,6 +579,8 @@ GEM coercible (~> 1.0) descendants_tracker (~> 0.0, >= 0.0.3) equalizer (~> 0.0, >= 0.0.9) + virtus-multiparams (0.1.1) + virtus (~> 1.0) warden (1.2.7) rack (>= 1.0) web-console (3.5.0) @@ -589,9 +606,11 @@ PLATFORMS DEPENDENCIES byebug decidim (~> 0.7.2) + decidim-census! decidim-dev (~> 0.7.2) factory_girl_rails faker (~> 1.7.3) + letter_opener_web listen (~> 3.1.0) pry-byebug pry-coolline diff --git a/config/routes.rb b/config/routes.rb index ce0ba365..89bdcf91 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,10 @@ Rails.application.routes.draw do mount Decidim::Core::Engine => '/' + mount Decidim::Census::AdminEngine => '/admin' + + if Rails.env.development? + mount LetterOpenerWeb::Engine, at: '/letter_opener' + end resource :system_status, only: :show end diff --git a/db/migrate/20170309156014_add_reference_to_results.decidim_results.rb b/db/migrate/20170309156014_add_reference_to_results.decidim_results.rb index f743b82a..156cdeae 100644 --- a/db/migrate/20170309156014_add_reference_to_results.decidim_results.rb +++ b/db/migrate/20170309156014_add_reference_to_results.decidim_results.rb @@ -2,7 +2,8 @@ class AddReferenceToResults < ActiveRecord::Migration[5.0] def change add_column :decidim_results_results, :reference, :string - Decidim::Results::Result.find_each(&:save) + # FIXME: why + # Decidim::Results::Result.find_each(&:save) change_column_null :decidim_results_results, :reference, false end end diff --git a/db/migrate/20170328072011_add_available_authorizations_to_organization.decidim.rb b/db/migrate/20170328072011_add_available_authorizations_to_organization.decidim.rb index d2a8f10e..b8facb51 100644 --- a/db/migrate/20170328072011_add_available_authorizations_to_organization.decidim.rb +++ b/db/migrate/20170328072011_add_available_authorizations_to_organization.decidim.rb @@ -3,7 +3,8 @@ class AddAvailableAuthorizationsToOrganization < ActiveRecord::Migration[5.0] def change add_column :decidim_organizations, :available_authorizations, :string, array: true, default: [] - handlers = Decidim.authorization_handlers.map(&:name) + # TODO: create a PR in the decidim project + handlers = Decidim.authorization_handlers # .map(&:name) Decidim::Organization.find_each do |org| org.update_attributes(available_authorizations: handlers) end diff --git a/db/migrate/20171120130226_create_decidim_census_census_datum.decidim_censuses.rb b/db/migrate/20171120130226_create_decidim_census_census_datum.decidim_censuses.rb new file mode 100644 index 00000000..4b3c0d62 --- /dev/null +++ b/db/migrate/20171120130226_create_decidim_census_census_datum.decidim_censuses.rb @@ -0,0 +1,16 @@ +# This migration comes from decidim_census (originally 20171110102910) +class CreateDecidimCensusCensusDatum < ActiveRecord::Migration[5.1] + + def change + create_table :decidim_census_census_data do |t| + t.references :decidim_organization, foreign_key: true, index: true + t.string :id_document + t.date :birthdate + + # The rows in this table are immutable (insert or delete, not update) + # To explicitly reflect this fact there is no `updated_at` column + t.datetime 'created_at', null: false + end + end + +end diff --git a/db/schema.rb b/db/schema.rb index 59239a33..cef5d0ef 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20171107144186) do +ActiveRecord::Schema.define(version: 20171120130226) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -132,6 +132,14 @@ t.index ["decidim_category_id"], name: "index_decidim_categorizations_on_decidim_category_id" end + create_table "decidim_census_census_data", force: :cascade do |t| + t.bigint "decidim_organization_id" + t.string "id_document" + t.date "birthdate" + t.datetime "created_at", null: false + t.index ["decidim_organization_id"], name: "index_decidim_census_census_data_on_decidim_organization_id" + end + create_table "decidim_comments_comment_votes", id: :serial, force: :cascade do |t| t.integer "weight", null: false t.integer "decidim_comment_id", null: false @@ -607,6 +615,7 @@ add_foreign_key "decidim_authorizations", "decidim_users" add_foreign_key "decidim_categorizations", "decidim_categories" + add_foreign_key "decidim_census_census_data", "decidim_organizations" add_foreign_key "decidim_identities", "decidim_organizations" add_foreign_key "decidim_newsletters", "decidim_users", column: "author_id" add_foreign_key "decidim_participatory_process_steps", "decidim_participatory_processes" diff --git a/decidim-census/.gitignore b/decidim-census/.gitignore new file mode 100644 index 00000000..1881d366 --- /dev/null +++ b/decidim-census/.gitignore @@ -0,0 +1,8 @@ +.bundle/ +log/*.log +pkg/ +test/dummy/db/*.sqlite3 +test/dummy/db/*.sqlite3-journal +test/dummy/log/*.log +test/dummy/tmp/ +examples/example.csv diff --git a/decidim-census/Gemfile b/decidim-census/Gemfile new file mode 100644 index 00000000..9a725132 --- /dev/null +++ b/decidim-census/Gemfile @@ -0,0 +1,14 @@ +source 'https://rubygems.org' + +# Declare your gem's dependencies in decidim-census.gemspec. +# Bundler will treat runtime dependencies like base dependencies, and +# development dependencies will be added by default to the :development group. +gemspec + +# Declare any dependencies that are still in development here instead of in +# your gemspec. These might include edge Rails or gems from your path or +# Git. Remember to move these dependencies to your gemspec before releasing +# your gem to rubygems.org. + +# To use a debugger +gem 'pry-byebug', group: %i(development test) diff --git a/decidim-census/Gemfile.lock b/decidim-census/Gemfile.lock new file mode 100644 index 00000000..6728e0b1 --- /dev/null +++ b/decidim-census/Gemfile.lock @@ -0,0 +1,575 @@ +PATH + remote: . + specs: + decidim-census (0.7.2) + decidim (= 0.7.2) + decidim-admin (= 0.7.2) + rails (~> 5.1.4) + virtus-multiparams (~> 0.1.1) + +GEM + remote: https://rubygems.org/ + specs: + actioncable (5.1.4) + actionpack (= 5.1.4) + nio4r (~> 2.0) + websocket-driver (~> 0.6.1) + actionmailer (5.1.4) + actionpack (= 5.1.4) + actionview (= 5.1.4) + activejob (= 5.1.4) + mail (~> 2.5, >= 2.5.4) + rails-dom-testing (~> 2.0) + actionpack (5.1.4) + actionview (= 5.1.4) + activesupport (= 5.1.4) + rack (~> 2.0) + rack-test (>= 0.6.3) + rails-dom-testing (~> 2.0) + rails-html-sanitizer (~> 1.0, >= 1.0.2) + actionview (5.1.4) + activesupport (= 5.1.4) + builder (~> 3.1) + erubi (~> 1.4) + rails-dom-testing (~> 2.0) + rails-html-sanitizer (~> 1.0, >= 1.0.3) + active_link_to (1.0.5) + actionpack + addressable + activejob (5.1.4) + activesupport (= 5.1.4) + globalid (>= 0.3.6) + activemodel (5.1.4) + activesupport (= 5.1.4) + activerecord (5.1.4) + activemodel (= 5.1.4) + activesupport (= 5.1.4) + arel (~> 8.0) + activesupport (5.1.4) + concurrent-ruby (~> 1.0, >= 1.0.2) + i18n (~> 0.7) + minitest (~> 5.1) + tzinfo (~> 1.1) + addressable (2.5.2) + public_suffix (>= 2.0.2, < 4.0) + arel (8.0.0) + ast (2.3.0) + autoprefixer-rails (7.1.6) + execjs + axiom-types (0.1.1) + descendants_tracker (~> 0.0.4) + ice_nine (~> 0.11.0) + thread_safe (~> 0.3, >= 0.3.1) + babel-source (5.8.35) + babel-transpiler (0.7.0) + babel-source (>= 4.0, < 6) + execjs (~> 2.0) + bcrypt (3.1.11) + builder (3.2.3) + byebug (9.1.0) + cancancan (2.0.0) + capybara (2.15.4) + addressable + mini_mime (>= 0.1.3) + nokogiri (>= 1.3.3) + rack (>= 1.0.0) + rack-test (>= 0.5.4) + xpath (~> 2.0) + capybara-screenshot (1.0.18) + capybara (>= 1.0, < 3) + launchy + carrierwave (1.1.0) + activemodel (>= 4.0.0) + activesupport (>= 4.0.0) + mime-types (>= 1.16) + cliver (0.3.2) + codecov (0.1.10) + json + simplecov + url + coderay (1.1.2) + coercible (1.0.0) + descendants_tracker (~> 0.0.1) + coffee-rails (4.2.2) + coffee-script (>= 2.2.0) + railties (>= 4.0.0) + coffee-script (2.4.1) + coffee-script-source + execjs + coffee-script-source (1.12.2) + concurrent-ruby (1.0.5) + crack (0.4.3) + safe_yaml (~> 1.0.0) + crass (1.0.2) + css_parser (1.6.0) + addressable + database_cleaner (1.6.2) + date_validator (0.9.0) + activemodel + activesupport + db-query-matchers (0.9.0) + activesupport (>= 4.0, <= 6.0) + rspec (~> 3.0) + decidim (0.7.2) + decidim-accountability (= 0.7.2) + decidim-admin (= 0.7.2) + decidim-api (= 0.7.2) + decidim-budgets (= 0.7.2) + decidim-comments (= 0.7.2) + decidim-core (= 0.7.2) + decidim-meetings (= 0.7.2) + decidim-pages (= 0.7.2) + decidim-participatory_processes (= 0.7.2) + decidim-proposals (= 0.7.2) + decidim-surveys (= 0.7.2) + decidim-system (= 0.7.2) + decidim-accountability (0.7.2) + decidim-comments (= 0.7.2) + decidim-core (= 0.7.2) + kaminari (~> 1.0.1) + searchlight (~> 4.1.0) + decidim-admin (0.7.2) + active_link_to (~> 1.0.0) + decidim-core (= 0.7.2) + devise (~> 4.2) + devise-i18n (~> 1.2.0) + devise_invitable (~> 1.7.0) + foundation_rails_helper (~> 3.0.0.rc) + jquery-rails (~> 4.3.1) + sassc-rails (~> 1.3.0) + select2-rails (~> 4.0.3) + decidim-api (0.7.2) + graphiql-rails (~> 1.4.2, < 1.4.5) + graphql (~> 1.6.0) + rack-cors (~> 1.0.1) + sprockets-es6 (~> 0.9.2) + decidim-budgets (0.7.2) + decidim-comments (= 0.7.2) + decidim-core (= 0.7.2) + kaminari (~> 1.0.1) + searchlight (~> 4.1.0) + decidim-comments (0.7.2) + decidim-core (= 0.7.2) + jquery-rails (~> 4.0) + decidim-core (0.7.2) + active_link_to (~> 1.0.4) + autoprefixer-rails (~> 7.1.1) + cancancan (~> 2.0.0) + carrierwave (~> 1.1.0) + date_validator (~> 0.9.0) + decidim-api (= 0.7.2) + devise (~> 4.3) + devise-i18n (~> 1.2.0) + file_validators (~> 2.1.0) + foundation-rails (~> 6.3.0) + foundation_rails_helper (~> 3.0.0.rc) + geocoder (~> 1.4.2) + high_voltage (~> 3.0.0) + invisible_captcha (~> 0.9.2) + jquery-rails (~> 4.3.1) + mini_magick (~> 4.8.0) + omniauth (~> 1.6.1) + omniauth-facebook (~> 4.0.0) + omniauth-google-oauth2 (~> 0.5.0) + omniauth-twitter (~> 1.4.0) + pg (~> 0.21.0) + premailer-rails (~> 1.9.5) + rails (~> 5.1.3) + rails-i18n + rectify (~> 0.10.0) + redis (~> 3.2) + rubyzip (= 1.2.1) + sassc-rails (~> 1.3.0) + select2-rails (~> 4.0.3) + spreadsheet (~> 1.1) + sprockets-es6 (~> 0.9.2) + truncato (~> 0.7.10) + wisper (~> 2.0.0) + decidim-dev (0.7.2) + byebug + capybara (~> 2.15) + capybara-screenshot (~> 1.0) + codecov (~> 0.1.9) + database_cleaner (~> 1.6) + db-query-matchers (~> 0.9.0) + decidim (= 0.7.2) + factory_girl_rails + i18n-tasks (= 0.9.18) + listen (~> 3.1) + nokogiri (~> 1.8) + poltergeist (~> 1.16) + puma (~> 3.10) + rails-controller-testing (~> 1.0) + rspec-html-matchers (~> 0.9.1) + rspec-rails (~> 3.6) + rspec-repeat (~> 1.0) + rubocop (~> 0.50.0) + simplecov (~> 0.13) + webmock (~> 3.0) + wisper-rspec (~> 0.0.3) + decidim-meetings (0.7.2) + date_validator (~> 0.9) + decidim-core (= 0.7.2) + httparty (~> 0.15.0) + icalendar (~> 2.4.1) + jquery-tmpl-rails (~> 1.1.0) + kaminari (~> 1.0.1) + searchlight (~> 4.1.0) + decidim-pages (0.7.2) + decidim-core (= 0.7.2) + decidim-participatory_processes (0.7.2) + decidim-core (= 0.7.2) + decidim-proposals (0.7.2) + decidim-comments (= 0.7.2) + decidim-core (= 0.7.2) + kaminari (~> 1.0.1) + social-share-button (~> 1.0.0) + decidim-surveys (0.7.2) + decidim-core (= 0.7.2) + jquery-tmpl-rails (~> 1.1.0) + decidim-system (0.7.2) + active_link_to (~> 1.0.0) + decidim-core (= 0.7.2) + devise (~> 4.2) + devise-i18n (~> 1.2.0) + devise_invitable (~> 1.7.1) + foundation_rails_helper (~> 3.0.0) + jquery-rails (~> 4.3.1) + sassc-rails (~> 1.3.0) + descendants_tracker (0.0.4) + thread_safe (~> 0.3, >= 0.3.1) + devise (4.3.0) + bcrypt (~> 3.0) + orm_adapter (~> 0.1) + railties (>= 4.1.0, < 5.2) + responders + warden (~> 1.2.3) + devise-i18n (1.2.0) + devise_invitable (1.7.2) + actionmailer (>= 4.1.0) + devise (>= 4.0.0) + diff-lcs (1.3) + docile (1.1.5) + easy_translate (0.5.0) + json + thread + thread_safe + equalizer (0.0.11) + erubi (1.7.0) + execjs (2.7.0) + factory_girl (4.9.0) + activesupport (>= 3.0.0) + factory_girl_rails (4.9.0) + factory_girl (~> 4.9.0) + railties (>= 3.0.0) + faker (1.8.4) + i18n (~> 0.5) + faraday (0.12.2) + multipart-post (>= 1.2, < 3) + ffi (1.9.18) + file_validators (2.1.0) + activemodel (>= 3.0) + mime-types (>= 1.0) + foundation-rails (6.3.1.0) + railties (>= 3.1.0) + sass (>= 3.3.0, < 3.5) + sprockets-es6 (>= 0.9.0) + foundation_rails_helper (3.0.0) + actionpack (>= 4.1, < 6.0) + activemodel (>= 4.1, < 6.0) + activesupport (>= 4.1, < 6.0) + railties (>= 4.1, < 6.0) + tzinfo (~> 1.2, >= 1.2.2) + geocoder (1.4.4) + globalid (0.4.1) + activesupport (>= 4.2.0) + graphiql-rails (1.4.4) + rails + graphql (1.6.8) + hashdiff (0.3.7) + hashie (3.5.6) + high_voltage (3.0.0) + highline (1.7.8) + htmlentities (4.3.4) + httparty (0.15.6) + multi_xml (>= 0.5.2) + i18n (0.9.1) + concurrent-ruby (~> 1.0) + i18n-tasks (0.9.18) + activesupport (>= 4.0.2) + ast (>= 2.1.0) + easy_translate (>= 0.5.0) + erubi + highline (>= 1.7.3) + i18n + parser (>= 2.2.3.0) + rainbow (~> 2.2) + terminal-table (>= 1.5.1) + icalendar (2.4.1) + ice_nine (0.11.2) + invisible_captcha (0.9.3) + rails (>= 3.2.0) + jquery-rails (4.3.1) + rails-dom-testing (>= 1, < 3) + railties (>= 4.2.0) + thor (>= 0.14, < 2.0) + jquery-tmpl-rails (1.1.0) + rails (>= 3.1.0) + json (2.1.0) + jwt (1.5.6) + kaminari (1.0.1) + activesupport (>= 4.1.0) + kaminari-actionview (= 1.0.1) + kaminari-activerecord (= 1.0.1) + kaminari-core (= 1.0.1) + kaminari-actionview (1.0.1) + actionview + kaminari-core (= 1.0.1) + kaminari-activerecord (1.0.1) + activerecord + kaminari-core (= 1.0.1) + kaminari-core (1.0.1) + launchy (2.4.3) + addressable (~> 2.3) + listen (3.1.5) + rb-fsevent (~> 0.9, >= 0.9.4) + rb-inotify (~> 0.9, >= 0.9.7) + ruby_dep (~> 1.2) + loofah (2.1.1) + crass (~> 1.0.2) + nokogiri (>= 1.5.9) + mail (2.7.0) + mini_mime (>= 0.1.1) + method_source (0.9.0) + mime-types (3.1) + mime-types-data (~> 3.2015) + mime-types-data (3.2016.0521) + mini_magick (4.8.0) + mini_mime (1.0.0) + mini_portile2 (2.3.0) + minitest (5.10.3) + multi_json (1.12.2) + multi_xml (0.6.0) + multipart-post (2.0.0) + nio4r (2.1.0) + nokogiri (1.8.1) + mini_portile2 (~> 2.3.0) + oauth (0.5.3) + oauth2 (1.4.0) + faraday (>= 0.8, < 0.13) + jwt (~> 1.0) + multi_json (~> 1.3) + multi_xml (~> 0.5) + rack (>= 1.2, < 3) + omniauth (1.6.1) + hashie (>= 3.4.6, < 3.6.0) + rack (>= 1.6.2, < 3) + omniauth-facebook (4.0.0) + omniauth-oauth2 (~> 1.2) + omniauth-google-oauth2 (0.5.2) + jwt (~> 1.5) + multi_json (~> 1.3) + omniauth (>= 1.1.1) + omniauth-oauth2 (>= 1.3.1) + omniauth-oauth (1.1.0) + oauth + omniauth (~> 1.0) + omniauth-oauth2 (1.4.0) + oauth2 (~> 1.0) + omniauth (~> 1.2) + omniauth-twitter (1.4.0) + omniauth-oauth (~> 1.1) + rack + orm_adapter (0.5.0) + parallel (1.12.0) + parser (2.4.0.0) + ast (~> 2.2) + pg (0.21.0) + poltergeist (1.16.0) + capybara (~> 2.1) + cliver (~> 0.3.1) + websocket-driver (>= 0.2.0) + powerpack (0.1.1) + premailer (1.11.0) + addressable + css_parser (>= 1.6.0) + htmlentities (>= 4.0.0) + premailer-rails (1.9.7) + actionmailer (>= 3, < 6) + premailer (~> 1.7, >= 1.7.9) + pry (0.11.2) + coderay (~> 1.1.0) + method_source (~> 0.9.0) + pry-byebug (3.5.0) + byebug (~> 9.1) + pry (~> 0.10) + public_suffix (3.0.0) + puma (3.10.0) + rack (2.0.3) + rack-cors (1.0.2) + rack-test (0.7.0) + rack (>= 1.0, < 3) + rails (5.1.4) + actioncable (= 5.1.4) + actionmailer (= 5.1.4) + actionpack (= 5.1.4) + actionview (= 5.1.4) + activejob (= 5.1.4) + activemodel (= 5.1.4) + activerecord (= 5.1.4) + activesupport (= 5.1.4) + bundler (>= 1.3.0) + railties (= 5.1.4) + sprockets-rails (>= 2.0.0) + rails-controller-testing (1.0.2) + actionpack (~> 5.x, >= 5.0.1) + actionview (~> 5.x, >= 5.0.1) + activesupport (~> 5.x) + rails-dom-testing (2.0.3) + activesupport (>= 4.2.0) + nokogiri (>= 1.6) + rails-html-sanitizer (1.0.3) + loofah (~> 2.0) + rails-i18n (5.0.4) + i18n (~> 0.7) + railties (~> 5.0) + railties (5.1.4) + actionpack (= 5.1.4) + activesupport (= 5.1.4) + method_source + rake (>= 0.8.7) + thor (>= 0.18.1, < 2.0) + rainbow (2.2.2) + rake + rake (12.2.1) + rb-fsevent (0.10.2) + rb-inotify (0.9.10) + ffi (>= 0.5.0, < 2) + rectify (0.10.0) + activemodel (>= 4.1.0) + activerecord (>= 4.1.0) + activesupport (>= 4.1.0) + virtus (~> 1.0.5) + wisper (>= 1.6.1) + redis (3.3.5) + responders (2.4.0) + actionpack (>= 4.2.0, < 5.3) + railties (>= 4.2.0, < 5.3) + rspec (3.7.0) + rspec-core (~> 3.7.0) + rspec-expectations (~> 3.7.0) + rspec-mocks (~> 3.7.0) + rspec-core (3.7.0) + rspec-support (~> 3.7.0) + rspec-expectations (3.7.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.7.0) + rspec-html-matchers (0.9.1) + nokogiri (~> 1) + rspec (>= 3.0.0.a, < 4) + rspec-mocks (3.7.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.7.0) + rspec-rails (3.7.1) + actionpack (>= 3.0) + activesupport (>= 3.0) + railties (>= 3.0) + rspec-core (~> 3.7.0) + rspec-expectations (~> 3.7.0) + rspec-mocks (~> 3.7.0) + rspec-support (~> 3.7.0) + rspec-repeat (1.0.2) + rspec (~> 3.0) + rspec-support (3.7.0) + rubocop (0.50.0) + parallel (~> 1.10) + parser (>= 2.3.3.1, < 3.0) + powerpack (~> 0.1) + rainbow (>= 2.2.2, < 3.0) + ruby-progressbar (~> 1.7) + unicode-display_width (~> 1.0, >= 1.0.1) + ruby-ole (1.2.12.1) + ruby-progressbar (1.9.0) + ruby_dep (1.5.0) + rubyzip (1.2.1) + safe_yaml (1.0.4) + sass (3.4.25) + sassc (1.11.4) + bundler + ffi (~> 1.9.6) + sass (>= 3.3.0) + sassc-rails (1.3.0) + railties (>= 4.0.0) + sass + sassc (~> 1.9) + sprockets (> 2.11) + sprockets-rails + tilt + searchlight (4.1.0) + select2-rails (4.0.3) + thor (~> 0.14) + simplecov (0.15.1) + docile (~> 1.1.0) + json (>= 1.8, < 3) + simplecov-html (~> 0.10.0) + simplecov-html (0.10.2) + social-share-button (1.0.0) + coffee-rails + spreadsheet (1.1.4) + ruby-ole (>= 1.0) + sprockets (3.7.1) + concurrent-ruby (~> 1.0) + rack (> 1, < 3) + sprockets-es6 (0.9.2) + babel-source (>= 5.8.11) + babel-transpiler + sprockets (>= 3.0.0) + sprockets-rails (3.2.1) + actionpack (>= 4.0) + activesupport (>= 4.0) + sprockets (>= 3.0.0) + terminal-table (1.8.0) + unicode-display_width (~> 1.1, >= 1.1.1) + thor (0.20.0) + thread (0.2.2) + thread_safe (0.3.6) + tilt (2.0.8) + truncato (0.7.10) + htmlentities (~> 4.3.1) + nokogiri (~> 1.8.0, >= 1.7.0) + tzinfo (1.2.4) + thread_safe (~> 0.1) + unicode-display_width (1.3.0) + url (0.3.2) + virtus (1.0.5) + axiom-types (~> 0.1) + coercible (~> 1.0) + descendants_tracker (~> 0.0, >= 0.0.3) + equalizer (~> 0.0, >= 0.0.9) + virtus-multiparams (0.1.1) + virtus (~> 1.0) + warden (1.2.7) + rack (>= 1.0) + webmock (3.1.0) + addressable (>= 2.3.6) + crack (>= 0.3.2) + hashdiff + websocket-driver (0.6.5) + websocket-extensions (>= 0.1.0) + websocket-extensions (0.1.2) + wisper (2.0.0) + wisper-rspec (0.0.3) + xpath (2.1.0) + nokogiri (~> 1.3) + +PLATFORMS + ruby + +DEPENDENCIES + decidim-census! + decidim-dev (= 0.7.2) + faker + pry-byebug + +BUNDLED WITH + 1.16.0 diff --git a/decidim-census/LICENSE b/decidim-census/LICENSE new file mode 100644 index 00000000..dbbe3558 --- /dev/null +++ b/decidim-census/LICENSE @@ -0,0 +1,661 @@ + GNU AFFERO GENERAL PUBLIC LICENSE + Version 3, 19 November 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU Affero General Public License is a free, copyleft license for +software and other kinds of works, specifically designed to ensure +cooperation with the community in the case of network server software. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +our General Public Licenses are intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + Developers that use our General Public Licenses protect your rights +with two steps: (1) assert copyright on the software, and (2) offer +you this License which gives you legal permission to copy, distribute +and/or modify the software. + + A secondary benefit of defending all users' freedom is that +improvements made in alternate versions of the program, if they +receive widespread use, become available for other developers to +incorporate. Many developers of free software are heartened and +encouraged by the resulting cooperation. However, in the case of +software used on network servers, this result may fail to come about. +The GNU General Public License permits making a modified version and +letting the public access it on a server without ever releasing its +source code to the public. + + The GNU Affero General Public License is designed specifically to +ensure that, in such cases, the modified source code becomes available +to the community. It requires the operator of a network server to +provide the source code of the modified version running there to the +users of that server. Therefore, public use of a modified version, on +a publicly accessible server, gives the public access to the source +code of the modified version. + + An older license, called the Affero General Public License and +published by Affero, was designed to accomplish similar goals. This is +a different license, not a version of the Affero GPL, but Affero has +released a new version of the Affero GPL which permits relicensing under +this license. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU Affero General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Remote Network Interaction; Use with the GNU General Public License. + + Notwithstanding any other provision of this License, if you modify the +Program, your modified version must prominently offer all users +interacting with it remotely through a computer network (if your version +supports such interaction) an opportunity to receive the Corresponding +Source of your version by providing access to the Corresponding Source +from a network server at no charge, through some standard or customary +means of facilitating copying of software. This Corresponding Source +shall include the Corresponding Source for any work covered by version 3 +of the GNU General Public License that is incorporated pursuant to the +following paragraph. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the work with which it is combined will remain governed by version +3 of the GNU General Public License. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU Affero General Public License from time to time. Such new versions +will be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU Affero General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU Affero General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU Affero General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If your software can interact with users remotely through a computer +network, you should also make sure that it provides a way for users to +get its source. For example, if your program is a web application, its +interface could display a "Source" link that leads users to an archive +of the code. There are many ways you could offer source, and different +solutions will be better for different programs; see section 13 for the +specific requirements. + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU AGPL, see +. diff --git a/decidim-census/README.md b/decidim-census/README.md new file mode 100644 index 00000000..a807be29 --- /dev/null +++ b/decidim-census/README.md @@ -0,0 +1,47 @@ +# Census + +> Add census authorization to Decidim platform + +Allows to upload a census CSV file to perform authorizations against +real users parameterised by their age. + +## Usage + +This module provides a model `Decidim::Census::Census` to store census information (identity document and birth date). + +It has an admin controller to upload CSV files with the information. When importing files all records are inserted and the duplicates are removed in a background job for performance reasons. + +## Installation + +Add this line to your application's Gemfile: + +```ruby +gem 'decidim-census' +``` + +And then execute: + +```bash +bundle +bin/rails decidim_census:install:migrations +bin/rails db:migrate +``` + +## Run tests + +Create a dummy app in your application (if not present): + +```bash +bin/rails decidim:generate_test_app +``` + +And run tests: + +```bash +cd decidim-census +rspec +``` + +## License + +AGPLv3 (same as Decidim) \ No newline at end of file diff --git a/decidim-census/Rakefile b/decidim-census/Rakefile new file mode 100644 index 00000000..a5ef10d7 --- /dev/null +++ b/decidim-census/Rakefile @@ -0,0 +1,3 @@ +# frozen_string_literal: true + +require 'decidim/dev/common_rake' diff --git a/decidim-census/app/controllers/decidim/census/admin/application_controller.rb b/decidim-census/app/controllers/decidim/census/admin/application_controller.rb new file mode 100644 index 00000000..98aa5e10 --- /dev/null +++ b/decidim-census/app/controllers/decidim/census/admin/application_controller.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +module Decidim + module Census + module Admin + # This controller is the abstract class from which all other controllers of + # this engine inherit. + # + # Note that it inherits from `Decidim::Features::BaseController`, which + # override its layout and provide all kinds of useful methods. + # class ApplicationController < Decidim::Admin::Features::BaseController + + class ApplicationController < Decidim::Admin::ApplicationController + end + end + end +end diff --git a/decidim-census/app/controllers/decidim/census/admin/censuses_controller.rb b/decidim-census/app/controllers/decidim/census/admin/censuses_controller.rb new file mode 100644 index 00000000..f02bd5f3 --- /dev/null +++ b/decidim-census/app/controllers/decidim/census/admin/censuses_controller.rb @@ -0,0 +1,45 @@ + +module Decidim + module Census + module Admin + class CensusesController < Decidim::Admin::ApplicationController + + before_action :show_instructions, unless: :census_authorization_active_in_organization? + + def show + authorize! :show, CensusDatum + @status = Status.new(current_organization) + end + + def create + authorize! :create, CensusDatum + if params[:file] + data = CsvData.new(params[:file].path) + CensusDatum.insert_all(current_organization, data.values) + RemoveDuplicatesJob.perform_later(current_organization) + flash[:notice] = t('.success', count: data.values.count, + errors: data.errors.count) + end + redirect_to censuses_path + end + + def destroy + authorize! :destroy, CensusDatum + CensusDatum.clear(current_organization) + redirect_to censuses_path, notice: t('.success') + end + + private + + def show_instructions + render :instructions + end + + def census_authorization_active_in_organization? + current_organization.available_authorizations.include? 'CensusAuthorizationHandler' + end + + end + end + end +end diff --git a/decidim-census/app/controllers/decidim/census/application_controller.rb b/decidim-census/app/controllers/decidim/census/application_controller.rb new file mode 100644 index 00000000..d3a504c4 --- /dev/null +++ b/decidim-census/app/controllers/decidim/census/application_controller.rb @@ -0,0 +1,9 @@ +module Decidim + module Census + class ApplicationController < ActionController::Base + + protect_from_forgery with: :exception + + end + end +end diff --git a/decidim-census/app/jobs/decidim/census/application_job.rb b/decidim-census/app/jobs/decidim/census/application_job.rb new file mode 100644 index 00000000..ab0c7c55 --- /dev/null +++ b/decidim-census/app/jobs/decidim/census/application_job.rb @@ -0,0 +1,6 @@ +module Decidim + module Census + class ApplicationJob < ActiveJob::Base + end + end +end diff --git a/decidim-census/app/jobs/decidim/census/remove_duplicates_job.rb b/decidim-census/app/jobs/decidim/census/remove_duplicates_job.rb new file mode 100644 index 00000000..57a0af81 --- /dev/null +++ b/decidim-census/app/jobs/decidim/census/remove_duplicates_job.rb @@ -0,0 +1,29 @@ + +module Decidim + module Census + class RemoveDuplicatesJob < ApplicationJob + + queue_as :default + + def perform(organization) + duplicated_census(organization).pluck(:id_document).each do |id_document| + CensusDatum.inside(organization) + .where(id_document: id_document) + .order(id: :desc) + .all[1..-1] + .each(&:delete) + end + end + + private + + def duplicated_census(organization) + CensusDatum.inside(organization) + .select(:id_document) + .group(:id_document) + .having('count(id_document)>1') + end + + end + end +end diff --git a/decidim-census/app/models/decidim/census/abilities/admin_ability.rb b/decidim-census/app/models/decidim/census/abilities/admin_ability.rb new file mode 100644 index 00000000..598a4d1a --- /dev/null +++ b/decidim-census/app/models/decidim/census/abilities/admin_ability.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +module Decidim + module Census + module Abilities + # Defines the abilities related to surveys for a logged in admin user. + # Intended to be used with `cancancan`. + class AdminAbility < Decidim::Abilities::AdminAbility + + def define_abilities + super + can :manage, Decidim::Census::CensusDatum + end + + end + end + end +end diff --git a/decidim-census/app/models/decidim/census/application_record.rb b/decidim-census/app/models/decidim/census/application_record.rb new file mode 100644 index 00000000..afa81335 --- /dev/null +++ b/decidim-census/app/models/decidim/census/application_record.rb @@ -0,0 +1,9 @@ +module Decidim + module Census + class ApplicationRecord < ActiveRecord::Base + + self.abstract_class = true + + end + end +end diff --git a/decidim-census/app/models/decidim/census/census_datum.rb b/decidim-census/app/models/decidim/census/census_datum.rb new file mode 100644 index 00000000..e5951796 --- /dev/null +++ b/decidim-census/app/models/decidim/census/census_datum.rb @@ -0,0 +1,50 @@ +module Decidim + module Census + class CensusDatum < ApplicationRecord + + belongs_to :organization, foreign_key: :decidim_organization_id, class_name: 'Decidim::Organization' + + # An organzation scope + def self.inside(organization) + where(decidim_organization_id: organization.id) + end + + # Search for a specific document id inside a organization + def self.search_id_document(organization, id_document) + CensusDatum.inside(organization) + .where(id_document: normalize_id_document(id_document)) + .order(created_at: :desc, id: :desc) + .first + end + + # Normalizes a id document string (remove invalid characters) + def self.normalize_id_document(string) + return '' unless string + string.gsub(/[^A-z0-9]/, '').upcase + end + + # Convert a date from string to a Date object + def self.parse_date(string) + Date.strptime((string || '').strip, '%d/%m/%Y') + rescue StandardError + nil + end + + # Insert a collectiojn of values + def self.insert_all(organization, values) + table_name = CensusDatum.table_name + columns = %w[id_document birthdate decidim_organization_id created_at].join(',') + now = Time.current + values = values.map { |row| "('#{row[0]}', '#{row[1]}', '#{organization.id}', '#{now}')" } + sql = "INSERT INTO #{table_name} (#{columns}) VALUES #{values.join(',')}" + ActiveRecord::Base.connection.execute(sql) + end + + # Clear all census data for a given organization + def self.clear(organization) + CensusDatum.inside(organization).delete_all + end + + end + end +end diff --git a/decidim-census/app/models/decidim/census/csv_data.rb b/decidim-census/app/models/decidim/census/csv_data.rb new file mode 100644 index 00000000..718958a7 --- /dev/null +++ b/decidim-census/app/models/decidim/census/csv_data.rb @@ -0,0 +1,33 @@ +require 'csv' + +module Decidim + module Census + class CsvData + + attr_reader :errors, :values + + def initialize(file) + @file = file + @errors = [] + @values = [] + + CSV.foreach(@file, headers: true, col_sep: ';') do |row| + process_row(row) + end + end + + private + + def process_row(row) + id_document = Decidim::Census::CensusDatum.normalize_id_document(row[0]) + date = Decidim::Census::CensusDatum.parse_date(row[1]) + if id_document.present? && !date.nil? + values << [id_document, date] + else + errors << row + end + end + + end + end +end diff --git a/decidim-census/app/models/decidim/census/status.rb b/decidim-census/app/models/decidim/census/status.rb new file mode 100644 index 00000000..f2106563 --- /dev/null +++ b/decidim-census/app/models/decidim/census/status.rb @@ -0,0 +1,28 @@ + +module Decidim + module Census + # Provides information about the current status of the census data + # for a given organization + class Status + + def initialize(organization) + @organization = organization + end + + # Returns the date of the last import + def last_import_at + @last ||= CensusDatum.inside(@organization) + .order(created_at: :desc).first + @last ? @last.created_at : nil + end + + # Returns the number of unique census + def count + @count ||= CensusDatum.inside(@organization) + .distinct.count(:id_document) + @count + end + + end + end +end diff --git a/decidim-census/app/services/census_authorization_handler.rb b/decidim-census/app/services/census_authorization_handler.rb new file mode 100644 index 00000000..501d16cb --- /dev/null +++ b/decidim-census/app/services/census_authorization_handler.rb @@ -0,0 +1,48 @@ +# frozen_string_literal: true + +require 'virtus/multiparams' + +# An AuthorizationHandler that uses information uploaded from a CSV file +# to authorize against the age of the user +class CensusAuthorizationHandler < Decidim::AuthorizationHandler + + # Virtus Multiparams allows the Date and DateTime attributes + # to be expressed in days, months and years (see documentation) + include Virtus::Multiparams + + # This is the input (from the user) to validate against + attribute :id_document, String + attribute :birthdate, Date + + # This is the validation to perform + # If passed, an authorization is created + validates :id_document, presence: true + validates :birthdate, presence: true + validate :censed + + def metadata + { birthdate: census_for_user&.birthdate&.strftime('%Y/%m/%d') } + end + + # Checks if the id_document belongs to the census + def censed + return if census_for_user&.birthdate == birthdate + errors.add(:id_document, I18n.t('decidim.census.errors.messages.not_censed')) + end + + def authorized? + return true if census_for_user + end + + def unique_id + census_for_user.id_document + end + + private + + def census_for_user + @census_for_user ||= Decidim::Census::CensusDatum + .search_id_document(user.organization, id_document) + end + +end diff --git a/decidim-census/app/views/census_authorization/_form.html.erb b/decidim-census/app/views/census_authorization/_form.html.erb new file mode 100644 index 00000000..cf67b125 --- /dev/null +++ b/decidim-census/app/views/census_authorization/_form.html.erb @@ -0,0 +1,20 @@ + +
+ <%= form.text_field :id_document %> +
+ +
+ <%= form.date_select :birthdate, start_year: 1900, + end_year: Date.current.year, + default: 35.years.ago, prompt: { + day: t(".date_select.day"), + month: t(".date_select.month"), + year: t(".date_select.year") + } %> +
+ +<%= form.hidden_field :handler_name %> + +
+ <%= form.submit t("authorize", scope: "decidim.authorizations.new"), class: "button expanded" %> +
diff --git a/decidim-census/app/views/decidim/census/admin/censuses/instructions.html.erb b/decidim-census/app/views/decidim/census/admin/censuses/instructions.html.erb new file mode 100644 index 00000000..76d30f7f --- /dev/null +++ b/decidim-census/app/views/decidim/census/admin/censuses/instructions.html.erb @@ -0,0 +1,10 @@ +
+
+

+ <%= t('admin.instructions.title', scope: 'decidim.census') %> +

+
+
+

<%= t('admin.instructions.body', scope: 'decidim.census') %>

+
+
diff --git a/decidim-census/app/views/decidim/census/admin/censuses/show.html.erb b/decidim-census/app/views/decidim/census/admin/censuses/show.html.erb new file mode 100644 index 00000000..e1601501 --- /dev/null +++ b/decidim-census/app/views/decidim/census/admin/censuses/show.html.erb @@ -0,0 +1,43 @@ + +
+
+

+ <%= t('admin.show.title', scope: 'decidim.census') %> +

+
+
+ <% if @status.count > 0 %> +

<%= t('decidim.census.admin.show.data', count: @status.count, + due_date: l(@status.last_import_at, format: :long)) %> +

+ <%= link_to t('decidim.census.admin.destroy.title'), + censuses_path, + method: :delete, + class: 'button alert', + data: { confirm: t('decidim.census.admin.destroy.confirm') } %> + <% else %> +

<%= t('admin.show.empty', scope: 'decidim.census') %>

+ <% end %> +
+
+ + +
+
+

+ <%= t('admin.new.title', scope: 'decidim.census') %> +

+
+
+

<%= t('decidim.census.admin.new.info') %>

+ <%= form_tag censuses_path, multipart: true, class: 'form' do %> + <%= label_tag :name, t('admin.new.file', scope: 'decidim.census') %> + <%= file_field_tag :file %> + <%= submit_tag t('admin.new.submit', scope: 'decidim.census'), class: 'button' %> + <% end %> +
+
+ + + + diff --git a/decidim-census/app/views/layouts/census/application.html.erb b/decidim-census/app/views/layouts/census/application.html.erb new file mode 100644 index 00000000..0a9c3faf --- /dev/null +++ b/decidim-census/app/views/layouts/census/application.html.erb @@ -0,0 +1,14 @@ + + + + Census + <%= stylesheet_link_tag "census/application", media: "all" %> + <%= javascript_include_tag "census/application" %> + <%= csrf_meta_tags %> + + + +<%= yield %> + + + diff --git a/decidim-census/bin/rails b/decidim-census/bin/rails new file mode 100755 index 00000000..18333ba1 --- /dev/null +++ b/decidim-census/bin/rails @@ -0,0 +1,13 @@ +#!/usr/bin/env ruby +# This command will automatically be run when you run "rails" with Rails gems +# installed from the root of your application. + +ENGINE_ROOT = File.expand_path('../..', __FILE__) +ENGINE_PATH = File.expand_path('../../lib/decidim/census/engine', __FILE__) + +# Set up gems listed in the Gemfile. +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) +require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE']) + +require 'rails/all' +require 'rails/engine/commands' diff --git a/decidim-census/config/locales/ca.yml b/decidim-census/config/locales/ca.yml new file mode 100644 index 00000000..4dd83bb8 --- /dev/null +++ b/decidim-census/config/locales/ca.yml @@ -0,0 +1,46 @@ +ca: + activemodel: + attributes: + census_authorization_handler: + id_document: Document d'identitat (DNI, NIF, Passaport o Targeta de Residència) + birthdate: Data de naixement + census_authorization: + form: + date_select: + day: Dia + month: Mes + year: Any + decidim: + authorization_handlers: + census_authorization_handler: + name: Padró Municipal + fields: + birthdate: Data de naixement + census: + errors: + messages: + not_censed: No hem pogut trobar el teu document d'identitat amb aquesta data de naixement al padró municipal. Si les dades són correctes i el problema persisteix, siusplau, posa't en contacte amb un administrador. + younger_than_minimum_age: Hauries de ser major de %{age} anys + admin: + destroy: + title: Esborrar totes les dades del cens + confirm: Aquesta acció no es pot desfer. Estàs segur/a que voleu continuar? + censuses: + create: + success: S'han importat amb èxit %{count} elements (%{errors} errors) + destroy: + success: S'han esborrat totes les dades censals + instructions: + title: Necessites activar el mòdul de censos per a aquesta organització + body: Per a això has d'entrar en administració del sistema i afegir "CensusAuthorizationHandler" a la llista d'autoritzacions + menu: + census: Pujar cens + show: + title: Dades del cens carregat + data: Hi ha un total de %{count} registres carregats. La última càrrega va ser el dia %{due_date} + empty: Encara no hi ha dades censals carregades. Utilitza el següent formulari per importar-lo utilitzant un fitxer CSV. + new: + info: "Ha de ser un fitxer generat en excel i exportat en CSV amb dues columnes: document d'identitat i data de naixement" + title: Pujar un nou cens + file: Arxiu excel .csv amb les dades del cens + submit: Carrega diff --git a/decidim-census/config/locales/en.yml b/decidim-census/config/locales/en.yml new file mode 100644 index 00000000..7b9f7429 --- /dev/null +++ b/decidim-census/config/locales/en.yml @@ -0,0 +1,46 @@ +en: + activemodel: + attributes: + census_authorization_handler: + id_document: Identification document (DNI, NIF, Password or Residence Card) + birthdate: Date of birth + census_authorization: + form: + date_select: + day: Day + month: Month + year: Year + decidim: + authorization_handlers: + census_authorization_handler: + name: Municipality Census + fields: + birthdate: Birthdate + census: + errors: + messages: + not_censed: We could not find your document ID matching with this birthdate in our Census. If the data entered is correct and the problem persists, please, contact an administrator. + younger_than_minimum_age: You should be older than %{age} years + admin: + destroy: + title: Delete all census data + confirm: Delete all the census can not be undone. Are you sure you want to continue? + censuses: + create: + success: Successfully imported %{count} items (%{errors} errors) + destroy: + success: All census data have been deleted + instructions: + title: You need to activate the census module for this organization + body: To do this you must enter system administration and add "CensusAuthorizationHandler" to the list of authorizations + menu: + census: Upload census + show: + title: Current census data + data: There are %{count} records loaded in total. Last upload date was on %{due_date} + empty: There are no census data. Use the form below to import it using a CSV file. + new: + info: 'Must be a file generated by excel and exported with CSV format with two columns: identity document and date of birth' + title: Upload a new census + file: Excel .csv file with census data + submit: Upload file diff --git a/decidim-census/config/locales/es.yml b/decidim-census/config/locales/es.yml new file mode 100644 index 00000000..0c0ddd84 --- /dev/null +++ b/decidim-census/config/locales/es.yml @@ -0,0 +1,46 @@ +es: + activemodel: + attributes: + census_authorization_handler: + id_document: Documento de identidad (DNI, NIF, Pasaporte o Targeta de Residencia) + birthdate: Fecha de nacimiento + census_authorization: + form: + date_select: + day: Día + month: Mes + year: Año + decidim: + authorization_handlers: + census_authorization_handler: + name: Padrón Municipal + fields: + birthdate: Fecha de nacimiento + census: + errors: + messages: + not_censed: No hemos podido encontrar tu documento de identidad con esta fecha de nacimiento en el padrón municipal. Si tus datos son correctos y el problema persiste, por favor, ponte en contacto con un administrador + younger_than_minimum_age: Deberías ser mayor de %{age} años + admin: + destroy: + title: Borrar todos los datos de censo + confirm: Borrar el censo no se puede deshacer. ¿Estás seguro/a que deseas continuar? + censuses: + create: + success: Se han importado con éxito %{count} elementos (%{errors} errores) + destroy: + success: Se han borrado todos los datos censales + instructions: + title: Necesitas activar el módulo de censos para esta organización + body: Para ello debes entrar en administración del sistema y añadir "CensusAuthorizationHandler" a la lista de autorizaciones + menu: + census: Subir censo + show: + title: Datos de censo actuales + data: Hay un total de %{count} registros cargados. La última carga fue el día %{due_date} + empty: No hay datos censales. Usa el formulario a continuación para importar usando un fichero CSV. + new: + info: 'Debe ser un fichero generado por excel y exportado en formato CSV con dos columnas: documento de identidad y fecha de nacimiento' + title: Subir un nuevo censo + file: Archivo excel .csv con los datos del censo + submit: Subir archivo diff --git a/decidim-census/config/routes.rb b/decidim-census/config/routes.rb new file mode 100644 index 00000000..0408e32a --- /dev/null +++ b/decidim-census/config/routes.rb @@ -0,0 +1,2 @@ +Decidim::Census::AdminEngine.routes.draw do +end diff --git a/decidim-census/config/spring.rb b/decidim-census/config/spring.rb new file mode 100644 index 00000000..42b616e0 --- /dev/null +++ b/decidim-census/config/spring.rb @@ -0,0 +1,4 @@ +# Try to execute engine's rspec tests with Spring +# See: https://github.com/rails/spring/issues/323#issuecomment-68302270 + +Spring.application_root = '../spec/decidim_dummy_app' diff --git a/decidim-census/db/migrate/20171110120821_create_decidim_census_census_data.rb b/decidim-census/db/migrate/20171110120821_create_decidim_census_census_data.rb new file mode 100644 index 00000000..38e0b9ed --- /dev/null +++ b/decidim-census/db/migrate/20171110120821_create_decidim_census_census_data.rb @@ -0,0 +1,14 @@ +class CreateDecidimCensusCensusDatum < ActiveRecord::Migration[5.1] + + def change + create_table :decidim_census_census do |t| + t.string :id_document + t.date :birthdate + + # The rows in this table are immutable (insert or delete, not update) + # To explicitly reflect this fact there is no `updated_at` column + t.datetime 'created_at', null: false + end + end + +end diff --git a/decidim-census/decidim-census.gemspec b/decidim-census/decidim-census.gemspec new file mode 100644 index 00000000..2808bbeb --- /dev/null +++ b/decidim-census/decidim-census.gemspec @@ -0,0 +1,27 @@ +$:.push File.expand_path('../lib', __FILE__) + +# Maintain your gem's version: +require 'decidim/census/version' + +# Describe your gem and declare its dependencies: +Gem::Specification.new do |s| + s.name = 'decidim-census' + s.version = Decidim::Census::VERSION + s.authors = ['Daniel Gómez'] + s.email = ['daniel.gomez@marsbased.com'] + s.summary = 'Census support for Decidim Diputació de Barcelona' + s.description = 'Census uploads via csv files and API integration' + s.homepage = 'https://github.com/marsbased/' + s.license = 'AGPLv3' + + s.files = Dir['{app,config,db,lib}/**/*', 'MIT-LICENSE', 'Rakefile', 'README.md'] + s.test_files = Dir['spec/**/*'] + + s.add_dependency 'rails', '~> 5.1.4' + s.add_dependency 'decidim', Decidim::Census::VERSION + s.add_dependency 'decidim-admin', Decidim::Census::VERSION + s.add_dependency 'virtus-multiparams', '~> 0.1.1' + + s.add_development_dependency 'decidim-dev', Decidim::Census::VERSION + s.add_development_dependency 'faker' +end diff --git "a/decidim-census/examples/Exemple de dades de cens per diputaci\303\263 de barcelona - Sheet1.csv" "b/decidim-census/examples/Exemple de dades de cens per diputaci\303\263 de barcelona - Sheet1.csv" new file mode 100644 index 00000000..4b6e9da4 --- /dev/null +++ "b/decidim-census/examples/Exemple de dades de cens per diputaci\303\263 de barcelona - Sheet1.csv" @@ -0,0 +1,4 @@ +Document d'identitat;Data de naixement (dd/mm/aaaa) +1111A;01/01/2001 +2222B;02/02/2002 +3333C;03/12/1970 \ No newline at end of file diff --git a/decidim-census/examples/generate.rb b/decidim-census/examples/generate.rb new file mode 100644 index 00000000..4810115e --- /dev/null +++ b/decidim-census/examples/generate.rb @@ -0,0 +1,11 @@ +require 'csv' +require 'faker' + +CSV.open('example.csv', 'wb', col_sep: ';') do |csv| + csv << ['DNI', 'Data (mm/dd/aaaa)'] + 1.upto(50 * 1000) do + dni = Faker::Number.number(8) + date = Faker::Date.birthday(10, 80).strftime('%d/%m/%Y') + csv << [dni, date] + end +end diff --git a/decidim-census/lib/decidim/census.rb b/decidim-census/lib/decidim/census.rb new file mode 100644 index 00000000..ca4c7cda --- /dev/null +++ b/decidim-census/lib/decidim/census.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +require 'decidim/census/admin' +require 'decidim/census/engine' +require 'decidim/census/admin_engine' +require 'decidim/census/extensions/authorize_with_age' + +module Decidim + # Base module for this engine. + module Census + end +end diff --git a/decidim-census/lib/decidim/census/admin.rb b/decidim-census/lib/decidim/census/admin.rb new file mode 100644 index 00000000..073478f0 --- /dev/null +++ b/decidim-census/lib/decidim/census/admin.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +module Decidim + module Census + # This module contains all the domain logic associated to Decidim's Census + # component admin panel. + module Admin + end + end +end diff --git a/decidim-census/lib/decidim/census/admin_engine.rb b/decidim-census/lib/decidim/census/admin_engine.rb new file mode 100644 index 00000000..378d395d --- /dev/null +++ b/decidim-census/lib/decidim/census/admin_engine.rb @@ -0,0 +1,33 @@ +# frozen_string_literal: true + +module Decidim + module Census + class AdminEngine < ::Rails::Engine + + isolate_namespace Decidim::Census::Admin + + routes do + resource :censuses, only: %i(show create destroy) + end + + initializer 'decidim_census.add_admin_authorizations' do |_app| + Decidim.configure do |config| + config.admin_abilities += [ + 'Decidim::Census::Abilities::AdminAbility' + ] + end + end + + initializer 'decidim_census.add_admin_menu' do + Decidim.menu :admin_menu do |menu| + menu.item I18n.t('menu.census', scope: 'decidim.census.admin'), + decidim_census_admin.censuses_path, + icon_name: 'spreadsheet', + position: 6, + active: :inclusive + end + end + + end + end +end diff --git a/decidim-census/lib/decidim/census/engine.rb b/decidim-census/lib/decidim/census/engine.rb new file mode 100644 index 00000000..12a98a33 --- /dev/null +++ b/decidim-census/lib/decidim/census/engine.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +module Decidim + module Census + # Census have no public app (see AdminEngine) + class Engine < ::Rails::Engine + + isolate_namespace Decidim::Census + + initializer 'decidim_census.add_irregular_inflection' do |_app| + ActiveSupport::Inflector.inflections(:en) do |inflect| + inflect.irregular 'census', 'census' + end + end + + initializer 'decidim_census.add_authorization_handlers' do |_app| + Decidim.configure do |config| + # WARNING: Some migrations requires this to be a class + # But it seems that the rest of the project requires to be a string + config.authorization_handlers += [ + 'CensusAuthorizationHandler' + ] + end + Decidim::ActionAuthorizer.prepend Decidim::Census::Extensions::AuthorizeWithAge + end + + end + end +end diff --git a/decidim-census/lib/decidim/census/extensions/authorize_with_age.rb b/decidim-census/lib/decidim/census/extensions/authorize_with_age.rb new file mode 100644 index 00000000..5f404c0c --- /dev/null +++ b/decidim-census/lib/decidim/census/extensions/authorize_with_age.rb @@ -0,0 +1,44 @@ +module Decidim + module Census + module Extensions + module AuthorizeWithAge + def authorize + if authorization_handler_name == 'census_authorization_handler' + authorize_with_age + else + super + end + end + + private + + def authorize_with_age + return status(:missing) unless valid_metadata? + return status(:invalid, fields: [:birthdate]) unless valid_age? + status(:ok) + end + + def valid_metadata? + !authorization.metadata['birthdate'].nil? + end + + def valid_age? + (birthdate + minimum_age.years) <= Date.current + end + + def birthdate + @birthdate ||= Date.strptime(authorization.metadata['birthdate'], '%Y/%m/%d') + end + + def minimum_age + @minimum_age ||= begin + Integer(permission_options['edad'].to_s, 10) + rescue ArgumentError + 18 + end + @minimum_age + end + end + end + end +end diff --git a/decidim-census/lib/decidim/census/version.rb b/decidim-census/lib/decidim/census/version.rb new file mode 100644 index 00000000..158a16b7 --- /dev/null +++ b/decidim-census/lib/decidim/census/version.rb @@ -0,0 +1,6 @@ +module Decidim + module Census + # Uses the latest matching Decidim version + VERSION = '0.7.2'.freeze + end +end diff --git a/decidim-census/spec/controllers/censuses_controller_spec.rb b/decidim-census/spec/controllers/censuses_controller_spec.rb new file mode 100644 index 00000000..16ca4619 --- /dev/null +++ b/decidim-census/spec/controllers/censuses_controller_spec.rb @@ -0,0 +1,57 @@ +require 'spec_helper' + +# rubocop:disable Metrics/BlockLength +RSpec.describe Decidim::Census::Admin::CensusesController, + type: :controller do + + include Warden::Test::Helpers + + routes { Decidim::Census::AdminEngine.routes } + + let(:organization) do + FactoryGirl.create :organization, available_authorizations: ['CensusAuthorizationHandler'] + end + + let(:user) do + FactoryGirl.create :user, :confirmed, organization: organization, admin: true + end + + before :each do + controller.request.env['decidim.current_organization'] = organization + end + + describe 'GET #show' do + it 'returns http success' do + sign_in user + get :show + expect(response).to have_http_status(:success) + end + end + + describe 'POST #create' do + it 'imports the csv data' do + sign_in user + + # Don't know why don't prepend with `spec/fixtures` automatically + file = fixture_file_upload('spec/fixtures/files/data1.csv') + post :create, params: { file: file } + expect(response).to have_http_status(:redirect) + + expect(Decidim::Census::CensusDatum.count).to be 3 + expect(Decidim::Census::CensusDatum.first.id_document).to eq '1111A' + expect(Decidim::Census::CensusDatum.last.id_document).to eq '3333C' + end + end + + describe 'POST #delete_all' do + it 'clear all census data' do + sign_in user + + 5.times { FactoryGirl.create :census_datum, organization: organization } + delete :destroy + expect(response).to have_http_status(:redirect) + + expect(Decidim::Census::CensusDatum.count).to be 0 + end + end +end diff --git a/decidim-census/spec/extensions/authorize_with_age_spec.rb b/decidim-census/spec/extensions/authorize_with_age_spec.rb new file mode 100644 index 00000000..1d4406a4 --- /dev/null +++ b/decidim-census/spec/extensions/authorize_with_age_spec.rb @@ -0,0 +1,44 @@ +require 'spec_helper' + +class AuthorizerStub + + def initialize(date, age) + @date = date + @age = age + end + + def authorization_handler_name + 'census_authorization_handler' + end + + def authorization + OpenStruct.new(metadata: { 'birthdate' => @date }) + end + + def permission_options + @age ? { 'edad' => @age } : {} + end + + def status(code, options = nil) + { code: code, options: options } + end + +end +AuthorizerStub.prepend Decidim::Census::Extensions::AuthorizeWithAge + +RSpec.describe Decidim::Census::Extensions::AuthorizeWithAge do + it 'authorizes with age metadata' do + authorizer = AuthorizerStub.new('1970/11/21', '20') + expect(authorizer.authorize[:code]).to be :ok + end + + it 'uses 18 as default age when not present' do + old = 18.years.ago.strftime('%Y/%m/%d') + auth_old = AuthorizerStub.new(old, nil) + expect(auth_old.authorize[:code]).to be :ok + + young = 17.years.ago.strftime('%Y/%m/%d') + auth_young = AuthorizerStub.new(young, nil) + expect(auth_young.authorize[:code]).to be :invalid + end +end diff --git a/decidim-census/spec/factories/census_datum.rb b/decidim-census/spec/factories/census_datum.rb new file mode 100644 index 00000000..407675ad --- /dev/null +++ b/decidim-census/spec/factories/census_datum.rb @@ -0,0 +1,7 @@ +FactoryGirl.define do + factory :census_datum, class: Decidim::Census::CensusDatum do + id_document '123456789A' + birthdate 20.years.ago + organization + end +end diff --git a/decidim-census/spec/factories/factories.rb b/decidim-census/spec/factories/factories.rb new file mode 100644 index 00000000..ec47a026 --- /dev/null +++ b/decidim-census/spec/factories/factories.rb @@ -0,0 +1,2 @@ +require 'decidim/dev/test/rspec_support/feature' +require 'decidim/core/test/factories' diff --git a/decidim-census/spec/fixtures/files/data1.csv b/decidim-census/spec/fixtures/files/data1.csv new file mode 100644 index 00000000..f48c76ed --- /dev/null +++ b/decidim-census/spec/fixtures/files/data1.csv @@ -0,0 +1,4 @@ +DNI;Data de naixement +1111A;1/1/1981 + 2222-b ; 2/2/1982 +33 33 C;1/1/2017 \ No newline at end of file diff --git a/decidim-census/spec/fixtures/files/with-errors.csv b/decidim-census/spec/fixtures/files/with-errors.csv new file mode 100644 index 00000000..3e12198f --- /dev/null +++ b/decidim-census/spec/fixtures/files/with-errors.csv @@ -0,0 +1,7 @@ +DNI;Data de naixement +1111A;1/1/1981 + 2222B ; 2/2/1982 +;1/6/1989 +12323B;fecha-no-valida +sasd +3333A;3/3/1983 \ No newline at end of file diff --git a/decidim-census/spec/jobs/remove_duplicates_job_spec.rb b/decidim-census/spec/jobs/remove_duplicates_job_spec.rb new file mode 100644 index 00000000..72cf3a81 --- /dev/null +++ b/decidim-census/spec/jobs/remove_duplicates_job_spec.rb @@ -0,0 +1,20 @@ +require 'spec_helper' + +RSpec.describe Decidim::Census::RemoveDuplicatesJob do + let(:org1) { FactoryGirl.create :organization } + let(:org2) { FactoryGirl.create :organization } + + it 'remove duplicates in the database' do + %w[AAA BBB AAA AAA].each do |doc| + FactoryGirl.create(:census_datum, id_document: doc, organization: org1) + end + %w[AAA BBB AAA AAA].each do |doc| + FactoryGirl.create(:census_datum, id_document: doc, organization: org2) + end + expect(Decidim::Census::CensusDatum.count).to be 8 + Decidim::Census::RemoveDuplicatesJob.new.perform org1 + expect(Decidim::Census::CensusDatum.count).to be 6 + Decidim::Census::RemoveDuplicatesJob.new.perform org2 + expect(Decidim::Census::CensusDatum.count).to be 4 + end +end diff --git a/decidim-census/spec/models/census_datum_spec.rb b/decidim-census/spec/models/census_datum_spec.rb new file mode 100644 index 00000000..0ace339d --- /dev/null +++ b/decidim-census/spec/models/census_datum_spec.rb @@ -0,0 +1,42 @@ +require 'spec_helper' + +# rubocop:disable Metrics/BlockLength +RSpec.describe Decidim::Census::CensusDatum, type: :model do + let(:organization) { FactoryGirl.create :organization } + CensusDatum = Decidim::Census::CensusDatum + + describe 'get census for a given identity document' do + it 'returns the last inserted when duplicates' do + FactoryGirl.create(:census_datum, id_document: 'AAA') + last = FactoryGirl.create(:census_datum, id_document: 'AAA', organization: organization) + expect(CensusDatum.search_id_document(organization, 'AAA')).to eq(last) + end + + it 'normalizes the document' do + census = FactoryGirl.create(:census_datum, id_document: 'AAA', organization: organization) + expect(CensusDatum.search_id_document(organization, 'a-a-a')).to eq(census) + end + end + + it 'inserts a collection of values' do + CensusDatum.insert_all(organization, [['1111A', '1990/12/1'], ['2222B', '1990/12/2']]) + expect(CensusDatum.count).to be 2 + CensusDatum.insert_all(organization, [['1111A', '2001/12/1'], ['3333C', '1990/12/3']]) + expect(CensusDatum.count).to be 4 + end + + describe 'normalization methods' do + it 'normalizes id document' do + expect(CensusDatum.normalize_id_document('1234a')).to eq '1234A' + expect(CensusDatum.normalize_id_document(' 1234a ')).to eq '1234A' + expect(CensusDatum.normalize_id_document(')($·$')).to eq '' + expect(CensusDatum.normalize_id_document(nil)).to eq '' + end + + it 'normalizes dates' do + expect(CensusDatum.parse_date('20/3/1992')).to eq Date.strptime('1992/03/20', '%Y/%m/%d') + expect(CensusDatum.parse_date('1/20/1992')).to be nil + expect(CensusDatum.parse_date('n/3/1992')).to be nil + end + end +end diff --git a/decidim-census/spec/models/csv_data_spec.rb b/decidim-census/spec/models/csv_data_spec.rb new file mode 100644 index 00000000..0f08c3dd --- /dev/null +++ b/decidim-census/spec/models/csv_data_spec.rb @@ -0,0 +1,19 @@ +RSpec.describe Decidim::Census::CsvData do + it 'loads from files' do + file = file_fixture('data1.csv') + data = Decidim::Census::CsvData.new(file) + expect(data.values.length).to be 3 + expect(data.values[0]).to eq ['1111A', Date.strptime('1981/01/01', '%Y/%m/%d')] + expect(data.values[1]).to eq ['2222B', Date.strptime('1982/02/02', '%Y/%m/%d')] + expect(data.values[2]).to eq ['3333C', Date.strptime('2017/01/01', '%Y/%m/%d')] + end + + it 'returns the number of errored rows' do + file = file_fixture('data1.csv') + data = Decidim::Census::CsvData.new(file) + expect(data.errors.count).to be 0 + file = file_fixture('with-errors.csv') + data = Decidim::Census::CsvData.new(file) + expect(data.errors.count).to be 3 + end +end diff --git a/decidim-census/spec/models/status_spec.rb b/decidim-census/spec/models/status_spec.rb new file mode 100644 index 00000000..3d39a5d4 --- /dev/null +++ b/decidim-census/spec/models/status_spec.rb @@ -0,0 +1,19 @@ +require 'spec_helper' + +RSpec.describe Decidim::Census::Status, type: :model do + let(:organization) { FactoryGirl.create :organization } + + it 'returns last import date' do + last = FactoryGirl.create :census_datum, organization: organization + status = Decidim::Census::Status.new(organization) + expect(status.last_import_at).to eq(last.created_at) + end + + it 'retrieve the number of unique documents' do + %w[AAA BBB AAA AAA].each do |doc| + FactoryGirl.create(:census_datum, id_document: doc, organization: organization) + end + status = Decidim::Census::Status.new(organization) + expect(status.count).to be 2 + end +end diff --git a/decidim-census/spec/services/census_authorization_handler_spec.rb b/decidim-census/spec/services/census_authorization_handler_spec.rb new file mode 100644 index 00000000..bd234892 --- /dev/null +++ b/decidim-census/spec/services/census_authorization_handler_spec.rb @@ -0,0 +1,38 @@ +require 'spec_helper' + +# rubocop:disable Metrics/BlockLength +RSpec.describe CensusAuthorizationHandler do + let(:organization) { FactoryGirl.create(:organization) } + let(:user) { FactoryGirl.create(:user, organization: organization) } + let(:dni) { '1234A' } + let(:date) { Date.strptime('1990/11/21', '%Y/%m/%d') } + let(:handler) do + CensusAuthorizationHandler.new(id_document: dni, birthdate: date, user: user) + end + + it 'validates against database' do + expect(handler.valid?).to be false + FactoryGirl.create(:census_datum, id_document: dni, + birthdate: date, + organization: organization) + expect(handler.valid?).to be true + end + + it 'normalizes the id document' do + FactoryGirl.create(:census_datum, id_document: dni, + birthdate: date, + organization: organization) + normalizer = CensusAuthorizationHandler.new( + user: user, id_document: '12-34-a', birthdate: date + ) + expect(normalizer.valid?).to be true + end + + it 'generates birthdate metadata' do + FactoryGirl.create(:census_datum, id_document: dni, + birthdate: date, + organization: organization) + expect(handler.valid?).to be true + expect(handler.metadata).to eq(birthdate: '1990/11/21') + end +end diff --git a/decidim-census/spec/spec_helper.rb b/decidim-census/spec/spec_helper.rb new file mode 100644 index 00000000..cf26d784 --- /dev/null +++ b/decidim-census/spec/spec_helper.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +ENV['RAILS_ENV'] ||= 'test' + +require 'decidim/dev' +require 'decidim/admin' + +ENV['ENGINE_NAME'] = File.dirname(File.dirname(__FILE__)).split('/').last + +Decidim::Dev.dummy_app_path = File.expand_path(File.join('..', 'spec', 'decidim_dummy_app')) + +require 'decidim/dev/test/base_spec_helper' + +RSpec.configure do |config| + config.before(:each) do + I18n.available_locales = %i(en ca es) + I18n.default_locale = :es + I18n.locale = :es + Decidim.available_locales = %i(en ca es) + Decidim.default_locale = :es + end +end diff --git a/spec/decidim_dummy_app/.gitignore b/spec/decidim_dummy_app/.gitignore new file mode 100644 index 00000000..7e783eb9 --- /dev/null +++ b/spec/decidim_dummy_app/.gitignore @@ -0,0 +1,22 @@ +# See https://help.github.com/articles/ignoring-files for more about ignoring files. +# +# If you find yourself ignoring temporary files generated by your text editor +# or operating system, you probably want to add a global ignore instead: +# git config --global core.excludesfile '~/.gitignore_global' + +# Ignore bundler config. +/.bundle + +# Ignore all logfiles and tempfiles. +/log/* +/tmp/* +!/log/.keep +!/tmp/.keep + +/node_modules +/yarn-error.log + +.byebug_history + +# Ignore public uploads +public/uploads \ No newline at end of file diff --git a/spec/decidim_dummy_app/Dockerfile b/spec/decidim_dummy_app/Dockerfile new file mode 100644 index 00000000..a0f0dde8 --- /dev/null +++ b/spec/decidim_dummy_app/Dockerfile @@ -0,0 +1,26 @@ +FROM ruby:2.4.0 +MAINTAINER david.morcillo@codegram.com + +ARG rails_env=production +ARG secret_key_base= + +ENV APP_HOME /code +ENV RAILS_ENV $rails_env +ENV SECRET_KEY_BASE $secret_key_base + +RUN apt-get update + +RUN curl -sL https://deb.nodesource.com/setup_8.x | bash && \ + apt-get install -y nodejs + +ADD Gemfile /tmp/Gemfile +ADD Gemfile.lock /tmp/Gemfile.lock +RUN cd /tmp && bundle install + +RUN mkdir -p $APP_HOME +WORKDIR $APP_HOME +ADD . $APP_HOME + +RUN bundle exec rake DATABASE_URL=postgresql://user:pass@127.0.0.1/dbname assets:precompile + +CMD ["bundle", "exec", "rails", "s", "-b0.0.0.0"] diff --git a/spec/decidim_dummy_app/Gemfile b/spec/decidim_dummy_app/Gemfile new file mode 100644 index 00000000..ab780bd8 --- /dev/null +++ b/spec/decidim_dummy_app/Gemfile @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +source 'https://rubygems.org' + +ruby RUBY_VERSION + +# This is the original line, but it doesn't work +# gem "decidim", path: "../.." +gem 'decidim', '~> 0.7.2' +gem 'decidim-admin', '~> 0.7.2' + +# Uncomment the following line if you want to use decidim-assemblies plugin +# gem "decidim-assemblies", path: "../.." + +gem 'bootsnap', require: false + +gem 'puma', '~> 3.0' +gem 'uglifier', '>= 1.3.0' + +gem 'faker', '~> 1.8.4' + +group :development, :test do + gem 'byebug', platform: :mri + + # gem "decidim-dev", path: "../.." + gem 'decidim-dev', '~> 0.7.2' +end + +group :development do + gem 'letter_opener_web', '~> 1.3.0' + gem 'listen', '~> 3.1.0' + gem 'spring' + gem 'spring-watcher-listen', '~> 2.0.0' + gem 'web-console' +end diff --git a/spec/decidim_dummy_app/Gemfile.lock b/spec/decidim_dummy_app/Gemfile.lock new file mode 100644 index 00000000..b343e8dd --- /dev/null +++ b/spec/decidim_dummy_app/Gemfile.lock @@ -0,0 +1,591 @@ +GEM + remote: https://rubygems.org/ + specs: + actioncable (5.1.4) + actionpack (= 5.1.4) + nio4r (~> 2.0) + websocket-driver (~> 0.6.1) + actionmailer (5.1.4) + actionpack (= 5.1.4) + actionview (= 5.1.4) + activejob (= 5.1.4) + mail (~> 2.5, >= 2.5.4) + rails-dom-testing (~> 2.0) + actionpack (5.1.4) + actionview (= 5.1.4) + activesupport (= 5.1.4) + rack (~> 2.0) + rack-test (>= 0.6.3) + rails-dom-testing (~> 2.0) + rails-html-sanitizer (~> 1.0, >= 1.0.2) + actionview (5.1.4) + activesupport (= 5.1.4) + builder (~> 3.1) + erubi (~> 1.4) + rails-dom-testing (~> 2.0) + rails-html-sanitizer (~> 1.0, >= 1.0.3) + active_link_to (1.0.5) + actionpack + addressable + activejob (5.1.4) + activesupport (= 5.1.4) + globalid (>= 0.3.6) + activemodel (5.1.4) + activesupport (= 5.1.4) + activerecord (5.1.4) + activemodel (= 5.1.4) + activesupport (= 5.1.4) + arel (~> 8.0) + activesupport (5.1.4) + concurrent-ruby (~> 1.0, >= 1.0.2) + i18n (~> 0.7) + minitest (~> 5.1) + tzinfo (~> 1.1) + addressable (2.5.2) + public_suffix (>= 2.0.2, < 4.0) + arel (8.0.0) + ast (2.3.0) + autoprefixer-rails (7.1.6) + execjs + axiom-types (0.1.1) + descendants_tracker (~> 0.0.4) + ice_nine (~> 0.11.0) + thread_safe (~> 0.3, >= 0.3.1) + babel-source (5.8.35) + babel-transpiler (0.7.0) + babel-source (>= 4.0, < 6) + execjs (~> 2.0) + bcrypt (3.1.11) + bindex (0.5.0) + bootsnap (1.1.5) + msgpack (~> 1.0) + builder (3.2.3) + byebug (9.1.0) + cancancan (2.0.0) + capybara (2.15.4) + addressable + mini_mime (>= 0.1.3) + nokogiri (>= 1.3.3) + rack (>= 1.0.0) + rack-test (>= 0.5.4) + xpath (~> 2.0) + capybara-screenshot (1.0.18) + capybara (>= 1.0, < 3) + launchy + carrierwave (1.1.0) + activemodel (>= 4.0.0) + activesupport (>= 4.0.0) + mime-types (>= 1.16) + cliver (0.3.2) + codecov (0.1.10) + json + simplecov + url + coercible (1.0.0) + descendants_tracker (~> 0.0.1) + coffee-rails (4.2.2) + coffee-script (>= 2.2.0) + railties (>= 4.0.0) + coffee-script (2.4.1) + coffee-script-source + execjs + coffee-script-source (1.12.2) + concurrent-ruby (1.0.5) + crack (0.4.3) + safe_yaml (~> 1.0.0) + crass (1.0.2) + css_parser (1.6.0) + addressable + database_cleaner (1.6.2) + date_validator (0.9.0) + activemodel + activesupport + db-query-matchers (0.9.0) + activesupport (>= 4.0, <= 6.0) + rspec (~> 3.0) + decidim (0.7.2) + decidim-accountability (= 0.7.2) + decidim-admin (= 0.7.2) + decidim-api (= 0.7.2) + decidim-budgets (= 0.7.2) + decidim-comments (= 0.7.2) + decidim-core (= 0.7.2) + decidim-meetings (= 0.7.2) + decidim-pages (= 0.7.2) + decidim-participatory_processes (= 0.7.2) + decidim-proposals (= 0.7.2) + decidim-surveys (= 0.7.2) + decidim-system (= 0.7.2) + decidim-accountability (0.7.2) + decidim-comments (= 0.7.2) + decidim-core (= 0.7.2) + kaminari (~> 1.0.1) + searchlight (~> 4.1.0) + decidim-admin (0.7.2) + active_link_to (~> 1.0.0) + decidim-core (= 0.7.2) + devise (~> 4.2) + devise-i18n (~> 1.2.0) + devise_invitable (~> 1.7.0) + foundation_rails_helper (~> 3.0.0.rc) + jquery-rails (~> 4.3.1) + sassc-rails (~> 1.3.0) + select2-rails (~> 4.0.3) + decidim-api (0.7.2) + graphiql-rails (~> 1.4.2, < 1.4.5) + graphql (~> 1.6.0) + rack-cors (~> 1.0.1) + sprockets-es6 (~> 0.9.2) + decidim-budgets (0.7.2) + decidim-comments (= 0.7.2) + decidim-core (= 0.7.2) + kaminari (~> 1.0.1) + searchlight (~> 4.1.0) + decidim-comments (0.7.2) + decidim-core (= 0.7.2) + jquery-rails (~> 4.0) + decidim-core (0.7.2) + active_link_to (~> 1.0.4) + autoprefixer-rails (~> 7.1.1) + cancancan (~> 2.0.0) + carrierwave (~> 1.1.0) + date_validator (~> 0.9.0) + decidim-api (= 0.7.2) + devise (~> 4.3) + devise-i18n (~> 1.2.0) + file_validators (~> 2.1.0) + foundation-rails (~> 6.3.0) + foundation_rails_helper (~> 3.0.0.rc) + geocoder (~> 1.4.2) + high_voltage (~> 3.0.0) + invisible_captcha (~> 0.9.2) + jquery-rails (~> 4.3.1) + mini_magick (~> 4.8.0) + omniauth (~> 1.6.1) + omniauth-facebook (~> 4.0.0) + omniauth-google-oauth2 (~> 0.5.0) + omniauth-twitter (~> 1.4.0) + pg (~> 0.21.0) + premailer-rails (~> 1.9.5) + rails (~> 5.1.3) + rails-i18n + rectify (~> 0.10.0) + redis (~> 3.2) + rubyzip (= 1.2.1) + sassc-rails (~> 1.3.0) + select2-rails (~> 4.0.3) + spreadsheet (~> 1.1) + sprockets-es6 (~> 0.9.2) + truncato (~> 0.7.10) + wisper (~> 2.0.0) + decidim-dev (0.7.2) + byebug + capybara (~> 2.15) + capybara-screenshot (~> 1.0) + codecov (~> 0.1.9) + database_cleaner (~> 1.6) + db-query-matchers (~> 0.9.0) + decidim (= 0.7.2) + factory_girl_rails + i18n-tasks (= 0.9.18) + listen (~> 3.1) + nokogiri (~> 1.8) + poltergeist (~> 1.16) + puma (~> 3.10) + rails-controller-testing (~> 1.0) + rspec-html-matchers (~> 0.9.1) + rspec-rails (~> 3.6) + rspec-repeat (~> 1.0) + rubocop (~> 0.50.0) + simplecov (~> 0.13) + webmock (~> 3.0) + wisper-rspec (~> 0.0.3) + decidim-meetings (0.7.2) + date_validator (~> 0.9) + decidim-core (= 0.7.2) + httparty (~> 0.15.0) + icalendar (~> 2.4.1) + jquery-tmpl-rails (~> 1.1.0) + kaminari (~> 1.0.1) + searchlight (~> 4.1.0) + decidim-pages (0.7.2) + decidim-core (= 0.7.2) + decidim-participatory_processes (0.7.2) + decidim-core (= 0.7.2) + decidim-proposals (0.7.2) + decidim-comments (= 0.7.2) + decidim-core (= 0.7.2) + kaminari (~> 1.0.1) + social-share-button (~> 1.0.0) + decidim-surveys (0.7.2) + decidim-core (= 0.7.2) + jquery-tmpl-rails (~> 1.1.0) + decidim-system (0.7.2) + active_link_to (~> 1.0.0) + decidim-core (= 0.7.2) + devise (~> 4.2) + devise-i18n (~> 1.2.0) + devise_invitable (~> 1.7.1) + foundation_rails_helper (~> 3.0.0) + jquery-rails (~> 4.3.1) + sassc-rails (~> 1.3.0) + descendants_tracker (0.0.4) + thread_safe (~> 0.3, >= 0.3.1) + devise (4.3.0) + bcrypt (~> 3.0) + orm_adapter (~> 0.1) + railties (>= 4.1.0, < 5.2) + responders + warden (~> 1.2.3) + devise-i18n (1.2.0) + devise_invitable (1.7.2) + actionmailer (>= 4.1.0) + devise (>= 4.0.0) + diff-lcs (1.3) + docile (1.1.5) + easy_translate (0.5.0) + json + thread + thread_safe + equalizer (0.0.11) + erubi (1.7.0) + execjs (2.7.0) + factory_girl (4.9.0) + activesupport (>= 3.0.0) + factory_girl_rails (4.9.0) + factory_girl (~> 4.9.0) + railties (>= 3.0.0) + faker (1.8.4) + i18n (~> 0.5) + faraday (0.12.2) + multipart-post (>= 1.2, < 3) + ffi (1.9.18) + file_validators (2.1.0) + activemodel (>= 3.0) + mime-types (>= 1.0) + foundation-rails (6.3.1.0) + railties (>= 3.1.0) + sass (>= 3.3.0, < 3.5) + sprockets-es6 (>= 0.9.0) + foundation_rails_helper (3.0.0) + actionpack (>= 4.1, < 6.0) + activemodel (>= 4.1, < 6.0) + activesupport (>= 4.1, < 6.0) + railties (>= 4.1, < 6.0) + tzinfo (~> 1.2, >= 1.2.2) + geocoder (1.4.4) + globalid (0.4.1) + activesupport (>= 4.2.0) + graphiql-rails (1.4.4) + rails + graphql (1.6.8) + hashdiff (0.3.7) + hashie (3.5.6) + high_voltage (3.0.0) + highline (1.7.8) + htmlentities (4.3.4) + httparty (0.15.6) + multi_xml (>= 0.5.2) + i18n (0.9.1) + concurrent-ruby (~> 1.0) + i18n-tasks (0.9.18) + activesupport (>= 4.0.2) + ast (>= 2.1.0) + easy_translate (>= 0.5.0) + erubi + highline (>= 1.7.3) + i18n + parser (>= 2.2.3.0) + rainbow (~> 2.2) + terminal-table (>= 1.5.1) + icalendar (2.4.1) + ice_nine (0.11.2) + invisible_captcha (0.9.3) + rails (>= 3.2.0) + jquery-rails (4.3.1) + rails-dom-testing (>= 1, < 3) + railties (>= 4.2.0) + thor (>= 0.14, < 2.0) + jquery-tmpl-rails (1.1.0) + rails (>= 3.1.0) + json (2.1.0) + jwt (1.5.6) + kaminari (1.0.1) + activesupport (>= 4.1.0) + kaminari-actionview (= 1.0.1) + kaminari-activerecord (= 1.0.1) + kaminari-core (= 1.0.1) + kaminari-actionview (1.0.1) + actionview + kaminari-core (= 1.0.1) + kaminari-activerecord (1.0.1) + activerecord + kaminari-core (= 1.0.1) + kaminari-core (1.0.1) + launchy (2.4.3) + addressable (~> 2.3) + letter_opener (1.4.1) + launchy (~> 2.2) + letter_opener_web (1.3.1) + actionmailer (>= 3.2) + letter_opener (~> 1.0) + railties (>= 3.2) + listen (3.1.5) + rb-fsevent (~> 0.9, >= 0.9.4) + rb-inotify (~> 0.9, >= 0.9.7) + ruby_dep (~> 1.2) + loofah (2.1.1) + crass (~> 1.0.2) + nokogiri (>= 1.5.9) + mail (2.7.0) + mini_mime (>= 0.1.1) + method_source (0.9.0) + mime-types (3.1) + mime-types-data (~> 3.2015) + mime-types-data (3.2016.0521) + mini_magick (4.8.0) + mini_mime (1.0.0) + mini_portile2 (2.3.0) + minitest (5.10.3) + msgpack (1.1.0) + multi_json (1.12.2) + multi_xml (0.6.0) + multipart-post (2.0.0) + nio4r (2.1.0) + nokogiri (1.8.1) + mini_portile2 (~> 2.3.0) + oauth (0.5.3) + oauth2 (1.4.0) + faraday (>= 0.8, < 0.13) + jwt (~> 1.0) + multi_json (~> 1.3) + multi_xml (~> 0.5) + rack (>= 1.2, < 3) + omniauth (1.6.1) + hashie (>= 3.4.6, < 3.6.0) + rack (>= 1.6.2, < 3) + omniauth-facebook (4.0.0) + omniauth-oauth2 (~> 1.2) + omniauth-google-oauth2 (0.5.2) + jwt (~> 1.5) + multi_json (~> 1.3) + omniauth (>= 1.1.1) + omniauth-oauth2 (>= 1.3.1) + omniauth-oauth (1.1.0) + oauth + omniauth (~> 1.0) + omniauth-oauth2 (1.4.0) + oauth2 (~> 1.0) + omniauth (~> 1.2) + omniauth-twitter (1.4.0) + omniauth-oauth (~> 1.1) + rack + orm_adapter (0.5.0) + parallel (1.12.0) + parser (2.4.0.0) + ast (~> 2.2) + pg (0.21.0) + poltergeist (1.16.0) + capybara (~> 2.1) + cliver (~> 0.3.1) + websocket-driver (>= 0.2.0) + powerpack (0.1.1) + premailer (1.11.0) + addressable + css_parser (>= 1.6.0) + htmlentities (>= 4.0.0) + premailer-rails (1.9.7) + actionmailer (>= 3, < 6) + premailer (~> 1.7, >= 1.7.9) + public_suffix (3.0.1) + puma (3.10.0) + rack (2.0.3) + rack-cors (1.0.2) + rack-test (0.7.0) + rack (>= 1.0, < 3) + rails (5.1.4) + actioncable (= 5.1.4) + actionmailer (= 5.1.4) + actionpack (= 5.1.4) + actionview (= 5.1.4) + activejob (= 5.1.4) + activemodel (= 5.1.4) + activerecord (= 5.1.4) + activesupport (= 5.1.4) + bundler (>= 1.3.0) + railties (= 5.1.4) + sprockets-rails (>= 2.0.0) + rails-controller-testing (1.0.2) + actionpack (~> 5.x, >= 5.0.1) + actionview (~> 5.x, >= 5.0.1) + activesupport (~> 5.x) + rails-dom-testing (2.0.3) + activesupport (>= 4.2.0) + nokogiri (>= 1.6) + rails-html-sanitizer (1.0.3) + loofah (~> 2.0) + rails-i18n (5.0.4) + i18n (~> 0.7) + railties (~> 5.0) + railties (5.1.4) + actionpack (= 5.1.4) + activesupport (= 5.1.4) + method_source + rake (>= 0.8.7) + thor (>= 0.18.1, < 2.0) + rainbow (2.2.2) + rake + rake (12.2.1) + rb-fsevent (0.10.2) + rb-inotify (0.9.10) + ffi (>= 0.5.0, < 2) + rectify (0.10.0) + activemodel (>= 4.1.0) + activerecord (>= 4.1.0) + activesupport (>= 4.1.0) + virtus (~> 1.0.5) + wisper (>= 1.6.1) + redis (3.3.5) + responders (2.4.0) + actionpack (>= 4.2.0, < 5.3) + railties (>= 4.2.0, < 5.3) + rspec (3.7.0) + rspec-core (~> 3.7.0) + rspec-expectations (~> 3.7.0) + rspec-mocks (~> 3.7.0) + rspec-core (3.7.0) + rspec-support (~> 3.7.0) + rspec-expectations (3.7.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.7.0) + rspec-html-matchers (0.9.1) + nokogiri (~> 1) + rspec (>= 3.0.0.a, < 4) + rspec-mocks (3.7.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.7.0) + rspec-rails (3.7.1) + actionpack (>= 3.0) + activesupport (>= 3.0) + railties (>= 3.0) + rspec-core (~> 3.7.0) + rspec-expectations (~> 3.7.0) + rspec-mocks (~> 3.7.0) + rspec-support (~> 3.7.0) + rspec-repeat (1.0.2) + rspec (~> 3.0) + rspec-support (3.7.0) + rubocop (0.50.0) + parallel (~> 1.10) + parser (>= 2.3.3.1, < 3.0) + powerpack (~> 0.1) + rainbow (>= 2.2.2, < 3.0) + ruby-progressbar (~> 1.7) + unicode-display_width (~> 1.0, >= 1.0.1) + ruby-ole (1.2.12.1) + ruby-progressbar (1.9.0) + ruby_dep (1.5.0) + rubyzip (1.2.1) + safe_yaml (1.0.4) + sass (3.4.25) + sassc (1.11.4) + bundler + ffi (~> 1.9.6) + sass (>= 3.3.0) + sassc-rails (1.3.0) + railties (>= 4.0.0) + sass + sassc (~> 1.9) + sprockets (> 2.11) + sprockets-rails + tilt + searchlight (4.1.0) + select2-rails (4.0.3) + thor (~> 0.14) + simplecov (0.15.1) + docile (~> 1.1.0) + json (>= 1.8, < 3) + simplecov-html (~> 0.10.0) + simplecov-html (0.10.2) + social-share-button (1.0.0) + coffee-rails + spreadsheet (1.1.4) + ruby-ole (>= 1.0) + spring (2.0.2) + activesupport (>= 4.2) + spring-watcher-listen (2.0.1) + listen (>= 2.7, < 4.0) + spring (>= 1.2, < 3.0) + sprockets (3.7.1) + concurrent-ruby (~> 1.0) + rack (> 1, < 3) + sprockets-es6 (0.9.2) + babel-source (>= 5.8.11) + babel-transpiler + sprockets (>= 3.0.0) + sprockets-rails (3.2.1) + actionpack (>= 4.0) + activesupport (>= 4.0) + sprockets (>= 3.0.0) + terminal-table (1.8.0) + unicode-display_width (~> 1.1, >= 1.1.1) + thor (0.20.0) + thread (0.2.2) + thread_safe (0.3.6) + tilt (2.0.8) + truncato (0.7.10) + htmlentities (~> 4.3.1) + nokogiri (~> 1.8.0, >= 1.7.0) + tzinfo (1.2.4) + thread_safe (~> 0.1) + uglifier (3.2.0) + execjs (>= 0.3.0, < 3) + unicode-display_width (1.3.0) + url (0.3.2) + virtus (1.0.5) + axiom-types (~> 0.1) + coercible (~> 1.0) + descendants_tracker (~> 0.0, >= 0.0.3) + equalizer (~> 0.0, >= 0.0.9) + warden (1.2.7) + rack (>= 1.0) + web-console (3.5.1) + actionview (>= 5.0) + activemodel (>= 5.0) + bindex (>= 0.4.0) + railties (>= 5.0) + webmock (3.1.0) + addressable (>= 2.3.6) + crack (>= 0.3.2) + hashdiff + websocket-driver (0.6.5) + websocket-extensions (>= 0.1.0) + websocket-extensions (0.1.3) + wisper (2.0.0) + wisper-rspec (0.0.3) + xpath (2.1.0) + nokogiri (~> 1.3) + +PLATFORMS + ruby + +DEPENDENCIES + bootsnap + byebug + decidim (~> 0.7.2) + decidim-admin (~> 0.7.2) + decidim-dev (~> 0.7.2) + faker (~> 1.8.4) + letter_opener_web (~> 1.3.0) + listen (~> 3.1.0) + puma (~> 3.0) + spring + spring-watcher-listen (~> 2.0.0) + uglifier (>= 1.3.0) + web-console + +RUBY VERSION + ruby 2.4.0p0 + +BUNDLED WITH + 1.16.0 diff --git a/spec/decidim_dummy_app/README.md b/spec/decidim_dummy_app/README.md new file mode 100644 index 00000000..1ad0be47 --- /dev/null +++ b/spec/decidim_dummy_app/README.md @@ -0,0 +1,26 @@ +# decidim_diba + +Citizen Participation and Open Government application. + +This is the open-source repository for decidim_diba, based on [Decidim](https://github.com/decidim/decidim). + +## Deploying the app + +An opinionated guide to deploy this app to Heroku can be found at [https://github.com/codegram/decidim-deploy-heroku](https://github.com/codegram/decidim-deploy-heroku). + +## Setting up the application + +You will need to do some steps before having the app working properly once you've deployed it: + +1. Open a Rails console in the server: `bundle exec rails console` +2. Create a System Admin user: +```ruby +user = Decidim::System::Admin.new(email: , password: , password_confirmation: ) +user.save! +``` +3. Visit `/system` and login with your system admin credentials +4. Create a new organization. Check the locales you want to use for that organization, and select a default locale. +5. Set the correct default host for the organization, otherwise the app will not work properly. Note that you need to include any subdomain you might be using. +6. Fill the rest of the form and submit it. + +You're good to go! diff --git a/spec/decidim_dummy_app/Rakefile b/spec/decidim_dummy_app/Rakefile new file mode 100644 index 00000000..e85f9139 --- /dev/null +++ b/spec/decidim_dummy_app/Rakefile @@ -0,0 +1,6 @@ +# Add your own tasks in files placed in lib/tasks ending in .rake, +# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. + +require_relative 'config/application' + +Rails.application.load_tasks diff --git a/spec/decidim_dummy_app/app/assets/config/manifest.js b/spec/decidim_dummy_app/app/assets/config/manifest.js new file mode 100644 index 00000000..b16e53d6 --- /dev/null +++ b/spec/decidim_dummy_app/app/assets/config/manifest.js @@ -0,0 +1,3 @@ +//= link_tree ../images +//= link_directory ../javascripts .js +//= link_directory ../stylesheets .css diff --git a/spec/decidim_dummy_app/app/assets/images/.keep b/spec/decidim_dummy_app/app/assets/images/.keep new file mode 100644 index 00000000..e69de29b diff --git a/spec/decidim_dummy_app/app/assets/javascripts/application.js b/spec/decidim_dummy_app/app/assets/javascripts/application.js new file mode 100644 index 00000000..308f0679 --- /dev/null +++ b/spec/decidim_dummy_app/app/assets/javascripts/application.js @@ -0,0 +1,16 @@ +// This is a manifest file that'll be compiled into application.js, which will include all the files +// listed below. +// +// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, or any plugin's +// vendor/assets/javascripts directory can be referenced here using a relative path. +// +// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the +// compiled file. JavaScript code in this file should be added after the last require_* statement. +// +// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details +// about supported directives. +// +//= require jquery +//= require jquery_ujs +//= require_tree . +//= require decidim \ No newline at end of file diff --git a/spec/decidim_dummy_app/app/assets/javascripts/cable.js b/spec/decidim_dummy_app/app/assets/javascripts/cable.js new file mode 100644 index 00000000..739aa5f0 --- /dev/null +++ b/spec/decidim_dummy_app/app/assets/javascripts/cable.js @@ -0,0 +1,13 @@ +// Action Cable provides the framework to deal with WebSockets in Rails. +// You can generate new channels where WebSocket features live using the `rails generate channel` command. +// +//= require action_cable +//= require_self +//= require_tree ./channels + +(function() { + this.App || (this.App = {}); + + App.cable = ActionCable.createConsumer(); + +}).call(this); diff --git a/spec/decidim_dummy_app/app/assets/javascripts/channels/.keep b/spec/decidim_dummy_app/app/assets/javascripts/channels/.keep new file mode 100644 index 00000000..e69de29b diff --git a/spec/decidim_dummy_app/app/assets/stylesheets/application.css b/spec/decidim_dummy_app/app/assets/stylesheets/application.css new file mode 100644 index 00000000..c64fd7be --- /dev/null +++ b/spec/decidim_dummy_app/app/assets/stylesheets/application.css @@ -0,0 +1,16 @@ +/* + * This is a manifest file that'll be compiled into application.css, which will include all the files + * listed below. + * + * Any CSS and SCSS file within this directory, lib/assets/stylesheets, or any plugin's + * vendor/assets/stylesheets directory can be referenced here using a relative path. + * + * You're free to add application-wide styles to this file and they'll appear at the bottom of the + * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS + * files in this directory. Styles in this file should be added after the last require_* statement. + * It is generally better to create a new file per style scope. + * + *= require decidim + *= require_tree . + *= require_self + */ diff --git a/spec/decidim_dummy_app/app/assets/stylesheets/decidim.scss b/spec/decidim_dummy_app/app/assets/stylesheets/decidim.scss new file mode 100644 index 00000000..7781d503 --- /dev/null +++ b/spec/decidim_dummy_app/app/assets/stylesheets/decidim.scss @@ -0,0 +1,18 @@ +// // Variables +// +// $primary: #ef604d; +// $secondary: #599aa6; +// $success: #57d685; +// $warning: #ffae00; +// $alert: #ec5840; +// +// $proposals: #238FF7; +// $actions: #57D685; +// $debates: #FA6C96; +// $meetings: #FABC6C; +// +// $twitter: #55acee; +// $facebook: #3b5998; +// $google: #dd4b39; + +@import "decidim/application"; diff --git a/spec/decidim_dummy_app/app/channels/application_cable/channel.rb b/spec/decidim_dummy_app/app/channels/application_cable/channel.rb new file mode 100644 index 00000000..d6726972 --- /dev/null +++ b/spec/decidim_dummy_app/app/channels/application_cable/channel.rb @@ -0,0 +1,4 @@ +module ApplicationCable + class Channel < ActionCable::Channel::Base + end +end diff --git a/spec/decidim_dummy_app/app/channels/application_cable/connection.rb b/spec/decidim_dummy_app/app/channels/application_cable/connection.rb new file mode 100644 index 00000000..0ff5442f --- /dev/null +++ b/spec/decidim_dummy_app/app/channels/application_cable/connection.rb @@ -0,0 +1,4 @@ +module ApplicationCable + class Connection < ActionCable::Connection::Base + end +end diff --git a/spec/decidim_dummy_app/app/controllers/application_controller.rb b/spec/decidim_dummy_app/app/controllers/application_controller.rb new file mode 100644 index 00000000..da51d11a --- /dev/null +++ b/spec/decidim_dummy_app/app/controllers/application_controller.rb @@ -0,0 +1,5 @@ +class ApplicationController < ActionController::Base + + protect_from_forgery with: :exception + +end diff --git a/spec/decidim_dummy_app/app/controllers/concerns/.keep b/spec/decidim_dummy_app/app/controllers/concerns/.keep new file mode 100644 index 00000000..e69de29b diff --git a/spec/decidim_dummy_app/app/controllers/decidim_controller.rb b/spec/decidim_dummy_app/app/controllers/decidim_controller.rb new file mode 100644 index 00000000..d61ffd09 --- /dev/null +++ b/spec/decidim_dummy_app/app/controllers/decidim_controller.rb @@ -0,0 +1,5 @@ +# Entry point for Decidim. It will use the `DecidimController` as +# entry point, but you can change what controller it inherits from +# so you can customize some methods. +class DecidimController < ApplicationController +end diff --git a/spec/decidim_dummy_app/app/helpers/application_helper.rb b/spec/decidim_dummy_app/app/helpers/application_helper.rb new file mode 100644 index 00000000..de6be794 --- /dev/null +++ b/spec/decidim_dummy_app/app/helpers/application_helper.rb @@ -0,0 +1,2 @@ +module ApplicationHelper +end diff --git a/spec/decidim_dummy_app/app/jobs/application_job.rb b/spec/decidim_dummy_app/app/jobs/application_job.rb new file mode 100644 index 00000000..a009ace5 --- /dev/null +++ b/spec/decidim_dummy_app/app/jobs/application_job.rb @@ -0,0 +1,2 @@ +class ApplicationJob < ActiveJob::Base +end diff --git a/spec/decidim_dummy_app/app/mailers/application_mailer.rb b/spec/decidim_dummy_app/app/mailers/application_mailer.rb new file mode 100644 index 00000000..aad51335 --- /dev/null +++ b/spec/decidim_dummy_app/app/mailers/application_mailer.rb @@ -0,0 +1,6 @@ +class ApplicationMailer < ActionMailer::Base + + default from: 'from@example.com' + layout 'mailer' + +end diff --git a/spec/decidim_dummy_app/app/models/application_record.rb b/spec/decidim_dummy_app/app/models/application_record.rb new file mode 100644 index 00000000..c6ae68f2 --- /dev/null +++ b/spec/decidim_dummy_app/app/models/application_record.rb @@ -0,0 +1,5 @@ +class ApplicationRecord < ActiveRecord::Base + + self.abstract_class = true + +end diff --git a/spec/decidim_dummy_app/app/models/concerns/.keep b/spec/decidim_dummy_app/app/models/concerns/.keep new file mode 100644 index 00000000..e69de29b diff --git a/spec/decidim_dummy_app/app/services/decidim/dummy_authorization_handler.rb b/spec/decidim_dummy_app/app/services/decidim/dummy_authorization_handler.rb new file mode 100644 index 00000000..53e798bf --- /dev/null +++ b/spec/decidim_dummy_app/app/services/decidim/dummy_authorization_handler.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +module Decidim + # An example implementation of an AuthorizationHandler to be used in tests. + class DummyAuthorizationHandler < AuthorizationHandler + + attribute :document_number, String + attribute :postal_code, String + attribute :birthday, Date + + validates :document_number, presence: true + validate :valid_document_number + + def metadata + super.merge(document_number: document_number) + end + + def unique_id + document_number + end + + private + + def valid_document_number + errors.add(:document_number, :invalid) unless document_number.to_s.end_with?('X') + end + + end +end diff --git a/spec/decidim_dummy_app/app/views/layouts/mailer.html.erb b/spec/decidim_dummy_app/app/views/layouts/mailer.html.erb new file mode 100644 index 00000000..cbd34d2e --- /dev/null +++ b/spec/decidim_dummy_app/app/views/layouts/mailer.html.erb @@ -0,0 +1,13 @@ + + + + + + + + + <%= yield %> + + diff --git a/spec/decidim_dummy_app/bin/bundle b/spec/decidim_dummy_app/bin/bundle new file mode 100755 index 00000000..66e9889e --- /dev/null +++ b/spec/decidim_dummy_app/bin/bundle @@ -0,0 +1,3 @@ +#!/usr/bin/env ruby +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) +load Gem.bin_path('bundler', 'bundle') diff --git a/spec/decidim_dummy_app/bin/rails b/spec/decidim_dummy_app/bin/rails new file mode 100755 index 00000000..07396602 --- /dev/null +++ b/spec/decidim_dummy_app/bin/rails @@ -0,0 +1,4 @@ +#!/usr/bin/env ruby +APP_PATH = File.expand_path('../config/application', __dir__) +require_relative '../config/boot' +require 'rails/commands' diff --git a/spec/decidim_dummy_app/bin/rake b/spec/decidim_dummy_app/bin/rake new file mode 100755 index 00000000..17240489 --- /dev/null +++ b/spec/decidim_dummy_app/bin/rake @@ -0,0 +1,4 @@ +#!/usr/bin/env ruby +require_relative '../config/boot' +require 'rake' +Rake.application.run diff --git a/spec/decidim_dummy_app/bin/setup b/spec/decidim_dummy_app/bin/setup new file mode 100755 index 00000000..ca842c11 --- /dev/null +++ b/spec/decidim_dummy_app/bin/setup @@ -0,0 +1,37 @@ +#!/usr/bin/env ruby +require 'pathname' +require 'fileutils' +include FileUtils + +# path to your application root. +APP_ROOT = Pathname.new File.expand_path('../../', __FILE__) + +def system!(*args) + system(*args) || abort("\n== Command #{args} failed ==") +end + +chdir APP_ROOT do + # This script is a starting point to setup your application. + # Add necessary setup steps to this file. + + puts '== Installing dependencies ==' + system! 'gem install bundler --conservative' + system('bundle check') || system!('bundle install') + + # Install JavaScript dependencies if using Yarn + # system('bin/yarn') + + # puts "\n== Copying sample files ==" + # unless File.exist?('config/database.yml') + # cp 'config/database.yml.sample', 'config/database.yml' + # end + + puts "\n== Preparing database ==" + system! 'bin/rails db:setup' + + puts "\n== Removing old logs and tempfiles ==" + system! 'bin/rails log:clear tmp:clear' + + puts "\n== Restarting application server ==" + system! 'bin/rails restart' +end diff --git a/spec/decidim_dummy_app/bin/update b/spec/decidim_dummy_app/bin/update new file mode 100755 index 00000000..a8e4462f --- /dev/null +++ b/spec/decidim_dummy_app/bin/update @@ -0,0 +1,29 @@ +#!/usr/bin/env ruby +require 'pathname' +require 'fileutils' +include FileUtils + +# path to your application root. +APP_ROOT = Pathname.new File.expand_path('../../', __FILE__) + +def system!(*args) + system(*args) || abort("\n== Command #{args} failed ==") +end + +chdir APP_ROOT do + # This script is a way to update your development environment automatically. + # Add necessary update steps to this file. + + puts '== Installing dependencies ==' + system! 'gem install bundler --conservative' + system('bundle check') || system!('bundle install') + + puts "\n== Updating database ==" + system! 'bin/rails db:migrate' + + puts "\n== Removing old logs and tempfiles ==" + system! 'bin/rails log:clear tmp:clear' + + puts "\n== Restarting application server ==" + system! 'bin/rails restart' +end diff --git a/spec/decidim_dummy_app/bin/yarn b/spec/decidim_dummy_app/bin/yarn new file mode 100755 index 00000000..329aee94 --- /dev/null +++ b/spec/decidim_dummy_app/bin/yarn @@ -0,0 +1,11 @@ +#!/usr/bin/env ruby +VENDOR_PATH = File.expand_path('..', __dir__) +Dir.chdir(VENDOR_PATH) do + begin + exec "yarnpkg #{ARGV.join(' ')}" + rescue Errno::ENOENT + $stderr.puts 'Yarn executable was not detected in the system.' + $stderr.puts 'Download Yarn at https://yarnpkg.com/en/docs/install' + exit 1 + end +end diff --git a/spec/decidim_dummy_app/config.ru b/spec/decidim_dummy_app/config.ru new file mode 100644 index 00000000..f7ba0b52 --- /dev/null +++ b/spec/decidim_dummy_app/config.ru @@ -0,0 +1,5 @@ +# This file is used by Rack-based servers to start the application. + +require_relative 'config/environment' + +run Rails.application diff --git a/spec/decidim_dummy_app/config/application.rb b/spec/decidim_dummy_app/config/application.rb new file mode 100644 index 00000000..fe41bcb0 --- /dev/null +++ b/spec/decidim_dummy_app/config/application.rb @@ -0,0 +1,20 @@ +require_relative 'boot' + +require 'rails/all' + +# Require the gems listed in Gemfile, including any gems +# you've limited to :test, :development, or :production. +Bundler.require(*Rails.groups) + +module DummyApplication + class Application < Rails::Application + + # Initialize configuration defaults for originally generated Rails version. + config.load_defaults 5.1 + + # Settings in config/environments/* take precedence over those specified here. + # Application configuration should go into files in config/initializers + # -- all .rb files in that directory are automatically loaded. + + end +end diff --git a/spec/decidim_dummy_app/config/boot.rb b/spec/decidim_dummy_app/config/boot.rb new file mode 100644 index 00000000..ca9445d5 --- /dev/null +++ b/spec/decidim_dummy_app/config/boot.rb @@ -0,0 +1,4 @@ +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) + +require 'bundler/setup' # Set up gems listed in the Gemfile. +# require 'bootsnap/setup' diff --git a/spec/decidim_dummy_app/config/cable.yml b/spec/decidim_dummy_app/config/cable.yml new file mode 100644 index 00000000..dc9270f1 --- /dev/null +++ b/spec/decidim_dummy_app/config/cable.yml @@ -0,0 +1,9 @@ +development: + adapter: async + +test: + adapter: async + +production: + adapter: redis + url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %> diff --git a/spec/decidim_dummy_app/config/database.yml b/spec/decidim_dummy_app/config/database.yml new file mode 100644 index 00000000..6f5bd166 --- /dev/null +++ b/spec/decidim_dummy_app/config/database.yml @@ -0,0 +1,87 @@ +# PostgreSQL. Versions 9.1 and up are supported. +# +# Install the pg driver: +# gem install pg +# On OS X with Homebrew: +# gem install pg -- --with-pg-config=/usr/local/bin/pg_config +# On OS X with MacPorts: +# gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config +# On Windows: +# gem install pg +# Choose the win32 build. +# Install PostgreSQL and put its /bin directory on your path. +# +# Configure Using Gemfile +# gem 'pg' +# +# On Linux, the 'host: "localhost"' line below should be commented out to avoid 'password required' error. +# +default: &default + adapter: postgresql + encoding: unicode + # For details on connection pooling, see rails configuration guide + # http://guides.rubyonrails.org/configuring.html#database-pooling + pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> + host: <%= ENV.fetch("DATABASE_HOST") { "localhost" } %> + username: <%= ENV.fetch("DATABASE_USERNAME") { "" } %> + password: <%= ENV.fetch("DATABASE_PASSWORD") { "" } %> + +development: + <<: *default + database: <%= ENV.fetch("DATABASE_NAME") { "decidim-diba_development" } %> + + # The specified database role being used to connect to postgres. + # To create additional roles in postgres see `$ createuser --help`. + # When left blank, postgres will use the default role. This is + # the same name as the operating system user that initialized the database. + #username: decidim-diba + + # The password associated with the postgres role (username). + #password: + + # Connect on a TCP socket. Omitted by default since the client uses a + # domain socket that doesn't need configuration. Windows does not have + # domain sockets, so uncomment these lines. + #host: localhost + + # The TCP port the server listens on. Defaults to 5432. + # If your server runs on a different port number, change accordingly. + #port: 5432 + + # Schema search path. The server defaults to $user,public + #schema_search_path: myapp,sharedapp,public + + # Minimum log levels, in increasing order: + # debug5, debug4, debug3, debug2, debug1, + # log, notice, warning, error, fatal, and panic + # Defaults to warning. + #min_messages: notice + +# Warning: The database defined as "test" will be erased and +# re-generated from your development database when you run "rake". +# Do not set this db to the same as development or production. +test: + <<: *default + database: <%= ENV.fetch("DATABASE_NAME") { "decidim-diba_test" } %> + +# As with config/secrets.yml, you never want to store sensitive information, +# like your database password, in your source code. If your source code is +# ever seen by anyone, they now have access to your database. +# +# Instead, provide the password as a unix environment variable when you boot +# the app. Read http://guides.rubyonrails.org/configuring.html#configuring-a-database +# for a full rundown on how to provide these environment variables in a +# production deployment. +# +# On Heroku and other platform providers, you may have a full connection URL +# available as an environment variable. For example: +# +# DATABASE_URL="postgres://myuser:mypass@localhost/somedatabase" +# +# You can use this database configuration with: +# +# production: +# url: <%= ENV['DATABASE_URL'] %> +# +production: + url: <%= ENV['DATABASE_URL'] %> diff --git a/spec/decidim_dummy_app/config/environment.rb b/spec/decidim_dummy_app/config/environment.rb new file mode 100644 index 00000000..426333bb --- /dev/null +++ b/spec/decidim_dummy_app/config/environment.rb @@ -0,0 +1,5 @@ +# Load the Rails application. +require_relative 'application' + +# Initialize the Rails application. +Rails.application.initialize! diff --git a/spec/decidim_dummy_app/config/environments/development.rb b/spec/decidim_dummy_app/config/environments/development.rb new file mode 100644 index 00000000..5187e221 --- /dev/null +++ b/spec/decidim_dummy_app/config/environments/development.rb @@ -0,0 +1,54 @@ +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # In the development environment your application's code is reloaded on + # every request. This slows down response time but is perfect for development + # since you don't have to restart the web server when you make code changes. + config.cache_classes = false + + # Do not eager load code on boot. + config.eager_load = false + + # Show full error reports. + config.consider_all_requests_local = true + + # Enable/disable caching. By default caching is disabled. + if Rails.root.join('tmp/caching-dev.txt').exist? + config.action_controller.perform_caching = true + + config.cache_store = :memory_store + config.public_file_server.headers = { + 'Cache-Control' => "public, max-age=#{2.days.seconds.to_i}" + } + else + config.action_controller.perform_caching = false + + config.cache_store = :null_store + end + + # Don't care if the mailer can't send. + config.action_mailer.raise_delivery_errors = false + + config.action_mailer.perform_caching = false + + # Print deprecation notices to the Rails logger. + config.active_support.deprecation = :log + + # Raise an error on page load if there are pending migrations. + config.active_record.migration_error = :page_load + + # Debug mode disables concatenation and preprocessing of assets. + # This option may cause significant delays in view rendering with a large + # number of complex assets. + config.assets.debug = true + + # Suppress logger output for asset requests. + config.assets.quiet = true + + # Raises error for missing translations + # config.action_view.raise_on_missing_translations = true + + # Use an evented file watcher to asynchronously detect changes in source code, + # routes, locales, etc. This feature depends on the listen gem. + config.file_watcher = ActiveSupport::EventedFileUpdateChecker +end diff --git a/spec/decidim_dummy_app/config/environments/production.rb b/spec/decidim_dummy_app/config/environments/production.rb new file mode 100644 index 00000000..ad1eee6d --- /dev/null +++ b/spec/decidim_dummy_app/config/environments/production.rb @@ -0,0 +1,112 @@ +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # Code is not reloaded between requests. + config.cache_classes = true + + # Eager load code on boot. This eager loads most of Rails and + # your application in memory, allowing both threaded web servers + # and those relying on copy on write to perform better. + # Rake tasks automatically ignore this option for performance. + config.eager_load = true + + # Full error reports are disabled and caching is turned on. + config.consider_all_requests_local = false + config.action_controller.perform_caching = true + + # Attempt to read encrypted secrets from `config/secrets.yml.enc`. + # Requires an encryption key in `ENV["RAILS_MASTER_KEY"]` or + # `config/secrets.yml.key`. + config.read_encrypted_secrets = true + + # Disable serving static files from the `/public` folder by default since + # Apache or NGINX already handles this. + config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present? + + # Compress JavaScripts and CSS. + config.assets.js_compressor = :uglifier + # config.assets.css_compressor = :sass + + # Do not fallback to assets pipeline if a precompiled asset is missed. + config.assets.compile = false + + # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb + + # Enable serving of images, stylesheets, and JavaScripts from an asset server. + # config.action_controller.asset_host = 'http://assets.example.com' + + # Specifies the header that your server uses for sending files. + # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache + # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX + + # Mount Action Cable outside main process or domain + # config.action_cable.mount_path = nil + # config.action_cable.url = 'wss://example.com/cable' + # config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ] + + # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. + # config.force_ssl = true + + # Use the lowest log level to ensure availability of diagnostic information + # when problems arise. + config.log_level = :debug + + # Prepend all log lines with the following tags. + config.log_tags = [:request_id] + + # Use a different cache store in production. + # config.cache_store = :mem_cache_store + + # Use a real queuing backend for Active Job (and separate queues per environment) + # config.active_job.queue_adapter = :resque + # config.active_job.queue_name_prefix = "decidim_diba_#{Rails.env}" + config.action_mailer.perform_caching = false + + # Ignore bad email addresses and do not raise email delivery errors. + # Set this to true and configure the email server for immediate delivery to raise delivery errors. + # config.action_mailer.raise_delivery_errors = false + + # Enable locale fallbacks for I18n (makes lookups for any locale fall back to + # the I18n.default_locale when a translation cannot be found). + config.i18n.fallbacks = true + + # Send deprecation notices to registered listeners. + config.active_support.deprecation = :notify + + # Use default logging formatter so that PID and timestamp are not suppressed. + config.log_formatter = ::Logger::Formatter.new + config.action_mailer.smtp_settings = { + address: Rails.application.secrets.smtp_address, + port: Rails.application.secrets.smtp_port, + authentication: Rails.application.secrets.smtp_authentication, + user_name: Rails.application.secrets.smtp_username, + password: Rails.application.secrets.smtp_password, + domain: Rails.application.secrets.smtp_domain, + enable_starttls_auto: Rails.application.secrets.smtp_starttls_auto, + openssl_verify_mode: 'none' + } + + if Rails.application.secrets.sendgrid + config.action_mailer.default_options = { + 'X-SMTPAPI' => { + filters: { + clicktrack: { settings: { enable: 0 } }, + opentrack: { settings: { enable: 0 } } + } + }.to_json + } + end + + # Use a different logger for distributed setups. + # require 'syslog/logger' + # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name') + + if ENV['RAILS_LOG_TO_STDOUT'].present? + logger = ActiveSupport::Logger.new(STDOUT) + logger.formatter = config.log_formatter + config.logger = ActiveSupport::TaggedLogging.new(logger) + end + + # Do not dump schema after migrations. + config.active_record.dump_schema_after_migration = false +end diff --git a/spec/decidim_dummy_app/config/environments/test.rb b/spec/decidim_dummy_app/config/environments/test.rb new file mode 100644 index 00000000..8e5cbde5 --- /dev/null +++ b/spec/decidim_dummy_app/config/environments/test.rb @@ -0,0 +1,42 @@ +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # The test environment is used exclusively to run your application's + # test suite. You never need to work with it otherwise. Remember that + # your test database is "scratch space" for the test suite and is wiped + # and recreated between test runs. Don't rely on the data there! + config.cache_classes = true + + # Do not eager load code on boot. This avoids loading your whole application + # just for the purpose of running a single test. If you are using a tool that + # preloads Rails for running tests, you may have to set it to true. + config.eager_load = false + + # Configure public file server for tests with Cache-Control for performance. + config.public_file_server.enabled = true + config.public_file_server.headers = { + 'Cache-Control' => "public, max-age=#{1.hour.seconds.to_i}" + } + + # Show full error reports and disable caching. + config.consider_all_requests_local = true + config.action_controller.perform_caching = false + + # Raise exceptions instead of rendering exception templates. + config.action_dispatch.show_exceptions = false + + # Disable request forgery protection in test environment. + config.action_controller.allow_forgery_protection = false + config.action_mailer.perform_caching = false + + # Tell Action Mailer not to deliver emails to the real world. + # The :test delivery method accumulates sent emails in the + # ActionMailer::Base.deliveries array. + config.action_mailer.delivery_method = :test + + # Print deprecation notices to the stderr. + config.active_support.deprecation = :stderr + + # Raises error for missing translations + # config.action_view.raise_on_missing_translations = true +end diff --git a/spec/decidim_dummy_app/config/initializers/application_controller_renderer.rb b/spec/decidim_dummy_app/config/initializers/application_controller_renderer.rb new file mode 100644 index 00000000..89d2efab --- /dev/null +++ b/spec/decidim_dummy_app/config/initializers/application_controller_renderer.rb @@ -0,0 +1,8 @@ +# Be sure to restart your server when you modify this file. + +# ActiveSupport::Reloader.to_prepare do +# ApplicationController.renderer.defaults.merge!( +# http_host: 'example.org', +# https: false +# ) +# end diff --git a/spec/decidim_dummy_app/config/initializers/assets.rb b/spec/decidim_dummy_app/config/initializers/assets.rb new file mode 100644 index 00000000..4b828e80 --- /dev/null +++ b/spec/decidim_dummy_app/config/initializers/assets.rb @@ -0,0 +1,14 @@ +# Be sure to restart your server when you modify this file. + +# Version of your assets, change this if you want to expire all your assets. +Rails.application.config.assets.version = '1.0' + +# Add additional assets to the asset load path. +# Rails.application.config.assets.paths << Emoji.images_path +# Add Yarn node_modules folder to the asset load path. +Rails.application.config.assets.paths << Rails.root.join('node_modules') + +# Precompile additional assets. +# application.js, application.css, and all non-JS/CSS in the app/assets +# folder are already added. +# Rails.application.config.assets.precompile += %w( admin.js admin.css ) diff --git a/spec/decidim_dummy_app/config/initializers/backtrace_silencers.rb b/spec/decidim_dummy_app/config/initializers/backtrace_silencers.rb new file mode 100644 index 00000000..59385cdf --- /dev/null +++ b/spec/decidim_dummy_app/config/initializers/backtrace_silencers.rb @@ -0,0 +1,7 @@ +# Be sure to restart your server when you modify this file. + +# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. +# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ } + +# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code. +# Rails.backtrace_cleaner.remove_silencers! diff --git a/spec/decidim_dummy_app/config/initializers/carrierwave.rb b/spec/decidim_dummy_app/config/initializers/carrierwave.rb new file mode 100644 index 00000000..d45ae8fd --- /dev/null +++ b/spec/decidim_dummy_app/config/initializers/carrierwave.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +# Default CarrierWave setup. +# +CarrierWave.configure do |config| + config.permissions = 0o666 + config.directory_permissions = 0o777 + config.storage = :file + config.enable_processing = !Rails.env.test? +end + +# Setup CarrierWave to use Amazon S3. Add `gem "fog-aws" to your Gemfile. +# +# CarrierWave.configure do |config| +# config.storage = :fog +# config.fog_provider = 'fog/aws' # required +# config.fog_credentials = { +# provider: 'AWS', # required +# aws_access_key_id: Rails.application.secrets.aws_access_key_id, # required +# aws_secret_access_key: Rails.application.secrets.aws_secret_access_key, # required +# region: 'eu-west-1', # optional, defaults to 'us-east-1' +# host: 's3.example.com', # optional, defaults to nil +# endpoint: 'https://s3.example.com:8080' # optional, defaults to nil +# } +# config.fog_directory = 'name_of_directory' # required +# config.fog_public = false # optional, defaults to true +# config.fog_attributes = { 'Cache-Control' => "max-age=#{365.day.to_i}" } # optional, defaults to {} +# end diff --git a/spec/decidim_dummy_app/config/initializers/cookies_serializer.rb b/spec/decidim_dummy_app/config/initializers/cookies_serializer.rb new file mode 100644 index 00000000..5a6a32d3 --- /dev/null +++ b/spec/decidim_dummy_app/config/initializers/cookies_serializer.rb @@ -0,0 +1,5 @@ +# Be sure to restart your server when you modify this file. + +# Specify a serializer for the signed and encrypted cookie jars. +# Valid options are :json, :marshal, and :hybrid. +Rails.application.config.action_dispatch.cookies_serializer = :json diff --git a/spec/decidim_dummy_app/config/initializers/decidim.rb b/spec/decidim_dummy_app/config/initializers/decidim.rb new file mode 100644 index 00000000..20a1aa14 --- /dev/null +++ b/spec/decidim_dummy_app/config/initializers/decidim.rb @@ -0,0 +1,48 @@ +# frozen_string_literal: true + +Decidim.configure do |config| + config.application_name = 'My Application Name' + config.mailer_sender = 'change-me@domain.org' + config.authorization_handlers = ['Decidim::DummyAuthorizationHandler'] + + # Change these lines to set your preferred locales + config.default_locale = :en + config.available_locales = %i(en ca es) + + # Geocoder configuration + # config.geocoder = { + # static_map_url: "https://image.maps.cit.api.here.com/mia/1.6/mapview", + # here_app_id: Rails.application.secrets.geocoder[:here_app_id], + # here_app_code: Rails.application.secrets.geocoder[:here_app_code] + # } + + # Custom resource reference generator method + # config.resource_reference_generator = lambda do |resource, feature| + # # Implement your custom method to generate resources references + # "1234-#{resource.id}" + # end + + # Currency unit + # config.currency_unit = "€" + + # The number of reports which an object can receive before hiding it + # config.max_reports_before_hiding = 3 + + # Custom HTML Header snippets + # + # The most common use is to integrate third-party services that require some + # extra JavaScript or CSS. Also, you can use it to add extra meta tags to the + # HTML. Note that this will only be rendered in public pages, not in the admin + # section. + # + # Before enabling this you should ensure that any tracking that might be done + # is in accordance with the rules and regulations that apply to your + # environment and usage scenarios. This feature also comes with the risk + # that an organization's administrator injects malicious scripts to spy on or + # take over user accounts. + # + config.enable_html_header_snippets = false +end + +Rails.application.config.i18n.available_locales = Decidim.available_locales +Rails.application.config.i18n.default_locale = Decidim.default_locale diff --git a/spec/decidim_dummy_app/config/initializers/filter_parameter_logging.rb b/spec/decidim_dummy_app/config/initializers/filter_parameter_logging.rb new file mode 100644 index 00000000..4a994e1e --- /dev/null +++ b/spec/decidim_dummy_app/config/initializers/filter_parameter_logging.rb @@ -0,0 +1,4 @@ +# Be sure to restart your server when you modify this file. + +# Configure sensitive parameters which will be filtered from the log file. +Rails.application.config.filter_parameters += [:password] diff --git a/spec/decidim_dummy_app/config/initializers/inflections.rb b/spec/decidim_dummy_app/config/initializers/inflections.rb new file mode 100644 index 00000000..ac033bf9 --- /dev/null +++ b/spec/decidim_dummy_app/config/initializers/inflections.rb @@ -0,0 +1,16 @@ +# Be sure to restart your server when you modify this file. + +# Add new inflection rules using the following format. Inflections +# are locale specific, and you may define rules for as many different +# locales as you wish. All of these examples are active by default: +# ActiveSupport::Inflector.inflections(:en) do |inflect| +# inflect.plural /^(ox)$/i, '\1en' +# inflect.singular /^(ox)en/i, '\1' +# inflect.irregular 'person', 'people' +# inflect.uncountable %w( fish sheep ) +# end + +# These inflection rules are supported but not enabled by default: +# ActiveSupport::Inflector.inflections(:en) do |inflect| +# inflect.acronym 'RESTful' +# end diff --git a/spec/decidim_dummy_app/config/initializers/mime_types.rb b/spec/decidim_dummy_app/config/initializers/mime_types.rb new file mode 100644 index 00000000..dc189968 --- /dev/null +++ b/spec/decidim_dummy_app/config/initializers/mime_types.rb @@ -0,0 +1,4 @@ +# Be sure to restart your server when you modify this file. + +# Add new mime types for use in respond_to blocks: +# Mime::Type.register "text/richtext", :rtf diff --git a/spec/decidim_dummy_app/config/initializers/social_share_button.rb b/spec/decidim_dummy_app/config/initializers/social_share_button.rb new file mode 100644 index 00000000..a05aef11 --- /dev/null +++ b/spec/decidim_dummy_app/config/initializers/social_share_button.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +# Further information on how to configure the SocialShareButton gem can be +# found here: https://github.com/huacnlee/social-share-button#configure +# +# SocialShareButton.configure do |config| +# config.allow_sites = %w[twitter facebook google_plus] +# end diff --git a/spec/decidim_dummy_app/config/initializers/wrap_parameters.rb b/spec/decidim_dummy_app/config/initializers/wrap_parameters.rb new file mode 100644 index 00000000..bbfc3961 --- /dev/null +++ b/spec/decidim_dummy_app/config/initializers/wrap_parameters.rb @@ -0,0 +1,14 @@ +# Be sure to restart your server when you modify this file. + +# This file contains settings for ActionController::ParamsWrapper which +# is enabled by default. + +# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. +ActiveSupport.on_load(:action_controller) do + wrap_parameters format: [:json] +end + +# To enable root element in JSON for ActiveRecord objects. +# ActiveSupport.on_load(:active_record) do +# self.include_root_in_json = true +# end diff --git a/spec/decidim_dummy_app/config/locales/en.yml b/spec/decidim_dummy_app/config/locales/en.yml new file mode 100644 index 00000000..decc5a85 --- /dev/null +++ b/spec/decidim_dummy_app/config/locales/en.yml @@ -0,0 +1,33 @@ +# Files in the config/locales directory are used for internationalization +# and are automatically loaded by Rails. If you want to use locales other +# than English, add the necessary files in this directory. +# +# To use the locales, use `I18n.t`: +# +# I18n.t 'hello' +# +# In views, this is aliased to just `t`: +# +# <%= t('hello') %> +# +# To use a different locale, set it with `I18n.locale`: +# +# I18n.locale = :es +# +# This would use the information in config/locales/es.yml. +# +# The following keys must be escaped otherwise they will not be retrieved by +# the default I18n backend: +# +# true, false, on, off, yes, no +# +# Instead, surround them with single quotes. +# +# en: +# 'true': 'foo' +# +# To learn more, please read the Rails Internationalization guide +# available at http://guides.rubyonrails.org/i18n.html. + +en: + hello: "Hello world" diff --git a/spec/decidim_dummy_app/config/puma.rb b/spec/decidim_dummy_app/config/puma.rb new file mode 100644 index 00000000..ccda173c --- /dev/null +++ b/spec/decidim_dummy_app/config/puma.rb @@ -0,0 +1,56 @@ +# Puma can serve each request in a thread from an internal thread pool. +# The `threads` method setting takes two numbers: a minimum and maximum. +# Any libraries that use thread pools should be configured to match +# the maximum value specified for Puma. Default is set to 5 threads for minimum +# and maximum; this matches the default thread size of Active Record. +# +threads_count = ENV.fetch('RAILS_MAX_THREADS') { 5 } +threads threads_count, threads_count + +# Specifies the `port` that Puma will listen on to receive requests; default is 3000. +# +port ENV.fetch('PORT') { 3000 } + +# Specifies the `environment` that Puma will run in. +# +environment ENV.fetch('RAILS_ENV') { 'development' } + +# Specifies the number of `workers` to boot in clustered mode. +# Workers are forked webserver processes. If using threads and workers together +# the concurrency of the application would be max `threads` * `workers`. +# Workers do not work on JRuby or Windows (both of which do not support +# processes). +# +# workers ENV.fetch("WEB_CONCURRENCY") { 2 } + +# Use the `preload_app!` method when specifying a `workers` number. +# This directive tells Puma to first boot the application and load code +# before forking the application. This takes advantage of Copy On Write +# process behavior so workers use less memory. If you use this option +# you need to make sure to reconnect any threads in the `on_worker_boot` +# block. +# +# preload_app! + +# If you are preloading your application and using Active Record, it's +# recommended that you close any connections to the database before workers +# are forked to prevent connection leakage. +# +# before_fork do +# ActiveRecord::Base.connection_pool.disconnect! if defined?(ActiveRecord) +# end + +# The code in the `on_worker_boot` will be called if you are using +# clustered mode by specifying a number of `workers`. After each worker +# process is booted, this block will be run. If you are using the `preload_app!` +# option, you will want to use this block to reconnect to any threads +# or connections that may have been created at application boot, as Ruby +# cannot share connections between processes. +# +# on_worker_boot do +# ActiveRecord::Base.establish_connection if defined?(ActiveRecord) +# end +# + +# Allow puma to be restarted by `rails restart` command. +plugin :tmp_restart diff --git a/spec/decidim_dummy_app/config/routes.rb b/spec/decidim_dummy_app/config/routes.rb new file mode 100644 index 00000000..e156c01d --- /dev/null +++ b/spec/decidim_dummy_app/config/routes.rb @@ -0,0 +1,4 @@ +Rails.application.routes.draw do + mount Decidim::Core::Engine => '/' + # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html +end diff --git a/spec/decidim_dummy_app/config/secrets.yml b/spec/decidim_dummy_app/config/secrets.yml new file mode 100644 index 00000000..aea71b70 --- /dev/null +++ b/spec/decidim_dummy_app/config/secrets.yml @@ -0,0 +1,62 @@ +# Be sure to restart your server when you modify this file. + +# Your secret key is used for verifying the integrity of signed cookies. +# If you change this key, all old signed cookies will become invalid! + +# Make sure the secret is at least 30 characters and all random, +# no regular words or you'll be exposed to dictionary attacks. +# You can use `rails secret` to generate a secure secret key. + +# Make sure the secrets in this file are kept private +# if you're sharing your code publicly. + +default: &default + omniauth: + facebook: + # It must be a boolean. Remember ENV variables doesn't support booleans. + enabled: false + app_id: <%= ENV["OMNIAUTH_FACEBOOK_APP_ID"] %> + app_secret: <%= ENV["OMNIAUTH_FACEBOOK_APP_SECRET"] %> + twitter: + enabled: false + api_key: <%= ENV["OMNIAUTH_TWITTER_API_KEY"] %> + api_secret: <%= ENV["OMNIAUTH_TWITTER_API_SECRET"] %> + google_oauth2: + enabled: false + client_id: <%= ENV["OMNIAUTH_GOOGLE_CLIENT_ID"] %> + client_secret: <%= ENV["OMNIAUTH_GOOGLE_CLIENT_SECRET"] %> + geocoder: + here_app_id: <%= ENV["GEOCODER_LOOKUP_APP_ID"] %> + here_app_code: <%= ENV["GEOCODER_LOOKUP_APP_CODE"] %> + +development: + <<: *default + secret_key_base: fd986b818bd8d43d25cb43a6a53a1682efa19a87b4803e4726f346ed090ec32e2b211d38591a619f3ecf8d5ca81e2a82970303ce44e884eb335b0760eb545e8e + omniauth: + developer: + enabled: true + +test: + <<: *default + secret_key_base: fb2e200f386f979aa8032276ac8c7ebf60fb9aed9366b6bcfa5d7dfebcd2632f46d48cf5c04dddfe53b0c649b0777a5e0ee44f7a13038fbecc3c3a565e932070 + omniauth: + facebook: + enabled: true + twitter: + enabled: true + google_oauth2: + enabled: true + +# Do not keep production secrets in the repository, +# instead read values from the environment. +production: + <<: *default + secret_key_base: <%= ENV["SECRET_KEY_BASE"] %> + sendgrid: <%= !ENV["SENDGRID_USERNAME"].blank? %> + smtp_username: <%= ENV["SMTP_USERNAME"] || ENV["SENDGRID_USERNAME"] %> + smtp_password: <%= ENV["SMTP_PASSWORD"] || ENV["SENDGRID_PASSWORD"] %> + smtp_address: <%= ENV["SMTP_ADDRESS"] || "smtp.sendgrid.net" %> + smtp_domain: <%= ENV["SMTP_DOMAIN"] || "heroku.com" %> + smtp_port: "587" + smtp_starttls_auto: true + smtp_authentication: "plain" diff --git a/spec/decidim_dummy_app/config/spring.rb b/spec/decidim_dummy_app/config/spring.rb new file mode 100644 index 00000000..832394d8 --- /dev/null +++ b/spec/decidim_dummy_app/config/spring.rb @@ -0,0 +1,9 @@ +# https://github.com/rails/spring/issues/323#issuecomment-68302270 +Spring.application_root = '' + +%w[ + .ruby-version + .rbenv-vars + tmp/restart.txt + tmp/caching-dev.txt +].each { |path| Spring.watch(path) } diff --git a/spec/decidim_dummy_app/db/seeds.rb b/spec/decidim_dummy_app/db/seeds.rb new file mode 100644 index 00000000..4d3602ea --- /dev/null +++ b/spec/decidim_dummy_app/db/seeds.rb @@ -0,0 +1,9 @@ +# This file should contain all the record creation needed to seed the database with its default values. +# The data can then be loaded with the rails db:seed command (or created alongside the database with db:setup). +# +# Examples: +# +# movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }]) +# Character.create(name: 'Luke', movie: movies.first) +# You can remove the 'faker' gem if you don't want Decidim seeds. +Decidim.seed! diff --git a/spec/decidim_dummy_app/docker-compose.yml b/spec/decidim_dummy_app/docker-compose.yml new file mode 100644 index 00000000..f4872f96 --- /dev/null +++ b/spec/decidim_dummy_app/docker-compose.yml @@ -0,0 +1,28 @@ +version: '2' +services: + app: + build: + context: . + args: + rails_env: development + volumes: + - .:/code + environment: + - DATABASE_HOST=pg + - DATABASE_USERNAME=postgres + ports: + - 3000:3000 + links: + - pg + - redis + pg: + image: postgres + volumes: + - pg-data:/var/lib/postgresql/data + redis: + image: redis + volumes: + - redis-data:/data +volumes: + pg-data: {} + redis-data: {} diff --git a/spec/decidim_dummy_app/lib/assets/.keep b/spec/decidim_dummy_app/lib/assets/.keep new file mode 100644 index 00000000..e69de29b diff --git a/spec/decidim_dummy_app/lib/tasks/.keep b/spec/decidim_dummy_app/lib/tasks/.keep new file mode 100644 index 00000000..e69de29b diff --git a/spec/decidim_dummy_app/log/.keep b/spec/decidim_dummy_app/log/.keep new file mode 100644 index 00000000..e69de29b diff --git a/spec/decidim_dummy_app/package.json b/spec/decidim_dummy_app/package.json new file mode 100644 index 00000000..b6d7109a --- /dev/null +++ b/spec/decidim_dummy_app/package.json @@ -0,0 +1,5 @@ +{ + "name": "decidim_diba", + "private": true, + "dependencies": {} +} diff --git a/spec/decidim_dummy_app/public/422.html b/spec/decidim_dummy_app/public/422.html new file mode 100644 index 00000000..c08eac0d --- /dev/null +++ b/spec/decidim_dummy_app/public/422.html @@ -0,0 +1,67 @@ + + + + The change you wanted was rejected (422) + + + + + + +
+
+

The change you wanted was rejected.

+

Maybe you tried to change something you didn't have access to.

+
+

If you are the application owner check the logs for more information.

+
+ + diff --git a/spec/decidim_dummy_app/public/apple-touch-icon-precomposed.png b/spec/decidim_dummy_app/public/apple-touch-icon-precomposed.png new file mode 100644 index 00000000..e69de29b diff --git a/spec/decidim_dummy_app/public/apple-touch-icon.png b/spec/decidim_dummy_app/public/apple-touch-icon.png new file mode 100644 index 00000000..e69de29b diff --git a/spec/decidim_dummy_app/public/favicon.ico b/spec/decidim_dummy_app/public/favicon.ico new file mode 100644 index 00000000..e69de29b diff --git a/spec/decidim_dummy_app/public/robots.txt b/spec/decidim_dummy_app/public/robots.txt new file mode 100644 index 00000000..37b576a4 --- /dev/null +++ b/spec/decidim_dummy_app/public/robots.txt @@ -0,0 +1 @@ +# See http://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file diff --git a/spec/decidim_dummy_app/test/application_system_test_case.rb b/spec/decidim_dummy_app/test/application_system_test_case.rb new file mode 100644 index 00000000..022d3f61 --- /dev/null +++ b/spec/decidim_dummy_app/test/application_system_test_case.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class ApplicationSystemTestCase < ActionDispatch::SystemTestCase + + driven_by :selenium, using: :chrome, screen_size: [1400, 1400] + +end diff --git a/spec/decidim_dummy_app/test/controllers/.keep b/spec/decidim_dummy_app/test/controllers/.keep new file mode 100644 index 00000000..e69de29b diff --git a/spec/decidim_dummy_app/test/fixtures/.keep b/spec/decidim_dummy_app/test/fixtures/.keep new file mode 100644 index 00000000..e69de29b diff --git a/spec/decidim_dummy_app/test/fixtures/files/.keep b/spec/decidim_dummy_app/test/fixtures/files/.keep new file mode 100644 index 00000000..e69de29b diff --git a/spec/decidim_dummy_app/test/helpers/.keep b/spec/decidim_dummy_app/test/helpers/.keep new file mode 100644 index 00000000..e69de29b diff --git a/spec/decidim_dummy_app/test/integration/.keep b/spec/decidim_dummy_app/test/integration/.keep new file mode 100644 index 00000000..e69de29b diff --git a/spec/decidim_dummy_app/test/mailers/.keep b/spec/decidim_dummy_app/test/mailers/.keep new file mode 100644 index 00000000..e69de29b diff --git a/spec/decidim_dummy_app/test/models/.keep b/spec/decidim_dummy_app/test/models/.keep new file mode 100644 index 00000000..e69de29b diff --git a/spec/decidim_dummy_app/test/system/.keep b/spec/decidim_dummy_app/test/system/.keep new file mode 100644 index 00000000..e69de29b diff --git a/spec/decidim_dummy_app/test/test_helper.rb b/spec/decidim_dummy_app/test/test_helper.rb new file mode 100644 index 00000000..1ad44c33 --- /dev/null +++ b/spec/decidim_dummy_app/test/test_helper.rb @@ -0,0 +1,11 @@ +require File.expand_path('../../config/environment', __FILE__) +require 'rails/test_help' + +class ActiveSupport::TestCase + + # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order. + fixtures :all + + # Add more helper methods to be used by all tests here... + +end diff --git a/spec/decidim_dummy_app/tmp/.keep b/spec/decidim_dummy_app/tmp/.keep new file mode 100644 index 00000000..e69de29b diff --git a/spec/decidim_dummy_app/vendor/.keep b/spec/decidim_dummy_app/vendor/.keep new file mode 100644 index 00000000..e69de29b