decidim-apartment 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE-AGPLv3.txt +661 -0
- data/README.md +167 -0
- data/Rakefile +405 -0
- data/app/commands/decidim/apartment/create_tenant_command.rb +94 -0
- data/app/commands/decidim/apartment/noop_settings_tab_command.rb +13 -0
- data/app/commands/decidim/apartment/performance/create_seed_tentant.rb +194 -0
- data/app/controllers/decidim/apartment/tenants_controller.rb +29 -0
- data/app/forms/decidim/apartment/admin/organization_settings_form.rb +44 -0
- data/app/forms/decidim/apartment/tenant_form.rb +35 -0
- data/app/helpers/decidim/apartment/dashboard_helper.rb +17 -0
- data/app/models/decidim/apartment/distribution_host.rb +21 -0
- data/app/models/decidim/apartment/distribution_key.rb +91 -0
- data/app/overrides/apartment_edit_organization.rb +21 -0
- data/app/overrides/apartment_system_asset.rb +10 -0
- data/app/packs/entrypoints/apartment_system_styles.scss +1 -0
- data/app/packs/stylesheets/decidim/apartment/system/_apartment_system_styles.scss +95 -0
- data/app/services/active_storage/service/apartment_disk_storage_service.rb +14 -0
- data/app/services/active_storage/service/apartment_s3_storage_service.rb +24 -0
- data/app/views/decidim/apartment/dashboard/_apartment.html.erb +55 -0
- data/app/views/decidim/apartment/dashboard/show.html.erb +3 -0
- data/app/views/decidim/apartment/organizations/_organizations_list.html.erb +45 -0
- data/app/views/decidim/apartment/organizations/index.html.erb +9 -0
- data/app/views/decidim/apartment/organizations/new.html.erb +11 -0
- data/config/assets.rb +15 -0
- data/config/locales/decidim_apartment.en.yml +58 -0
- data/config/locales/decidim_apartment_toggle.en.yml +15 -0
- data/db/migrate/20250814075441_add_apartment_distribution_key.rb +15 -0
- data/db/migrate/20260907100000_add_apartment_distribution_hosts.rb +32 -0
- data/lib/decidim/apartment/active_storage_wrap.rb +51 -0
- data/lib/decidim/apartment/allowed_hosts.rb +78 -0
- data/lib/decidim/apartment/cache_namespace.rb +38 -0
- data/lib/decidim/apartment/config_registry.rb +102 -0
- data/lib/decidim/apartment/configuration.rb +11 -0
- data/lib/decidim/apartment/convert/attachment_integrity.rb +130 -0
- data/lib/decidim/apartment/convert/constraint_graph_pruner.rb +183 -0
- data/lib/decidim/apartment/convert/errors.rb +9 -0
- data/lib/decidim/apartment/convert/host_gate.rb +76 -0
- data/lib/decidim/apartment/convert/org_distribution_report.rb +106 -0
- data/lib/decidim/apartment/convert/org_metrics.rb +164 -0
- data/lib/decidim/apartment/convert/organization_converter.rb +154 -0
- data/lib/decidim/apartment/convert/organization_pruner.rb +210 -0
- data/lib/decidim/apartment/convert/organization_resolver.rb +386 -0
- data/lib/decidim/apartment/convert/paper_trail_report.rb +127 -0
- data/lib/decidim/apartment/convert/preflight.rb +140 -0
- data/lib/decidim/apartment/convert/schema_cloner.rb +157 -0
- data/lib/decidim/apartment/convert/storage_preconditions.rb +43 -0
- data/lib/decidim/apartment/convert/storage_relocator.rb +118 -0
- data/lib/decidim/apartment/convert/table_registry.rb +109 -0
- data/lib/decidim/apartment/convert.rb +20 -0
- data/lib/decidim/apartment/demo/blob.rb +31 -0
- data/lib/decidim/apartment/demo/city.rb +107 -0
- data/lib/decidim/apartment/demo/education.rb +83 -0
- data/lib/decidim/apartment/demo/foss.rb +153 -0
- data/lib/decidim/apartment/demo/homepage.rb +39 -0
- data/lib/decidim/apartment/demo/localized.rb +27 -0
- data/lib/decidim/apartment/demo/provision.rb +107 -0
- data/lib/decidim/apartment/demo/runner.rb +66 -0
- data/lib/decidim/apartment/demo/system_admin.rb +24 -0
- data/lib/decidim/apartment/demo.rb +19 -0
- data/lib/decidim/apartment/elevator.rb +20 -0
- data/lib/decidim/apartment/engine.rb +140 -0
- data/lib/decidim/apartment/excluded_model_pin.rb +40 -0
- data/lib/decidim/apartment/host_registry.rb +71 -0
- data/lib/decidim/apartment/import/confirm_prompt.rb +46 -0
- data/lib/decidim/apartment/import/database_restorer.rb +105 -0
- data/lib/decidim/apartment/import/dump_host_extractor.rb +67 -0
- data/lib/decidim/apartment/import/dump_preview.rb +96 -0
- data/lib/decidim/apartment/import/dump_transformer.rb +87 -0
- data/lib/decidim/apartment/import/errors.rb +9 -0
- data/lib/decidim/apartment/import/provision_tenant.rb +50 -0
- data/lib/decidim/apartment/import/schema_auditor.rb +118 -0
- data/lib/decidim/apartment/import/storage_migrator.rb +71 -0
- data/lib/decidim/apartment/import/tenant_context.rb +226 -0
- data/lib/decidim/apartment/import/tenant_importer.rb +73 -0
- data/lib/decidim/apartment/import/verifier.rb +58 -0
- data/lib/decidim/apartment/import.rb +15 -0
- data/lib/decidim/apartment/ops/attribute_cryptor.rb +68 -0
- data/lib/decidim/apartment/ops/ciphertext_rewriter.rb +230 -0
- data/lib/decidim/apartment/ops/encrypted_attribute_catalog.rb +106 -0
- data/lib/decidim/apartment/ops/encrypted_attribute_registry.rb +74 -0
- data/lib/decidim/apartment/ops/postgres_permissions.rb +179 -0
- data/lib/decidim/apartment/ops/secret_key_preflight.rb +94 -0
- data/lib/decidim/apartment/ops/secret_key_rotation.rb +226 -0
- data/lib/decidim/apartment/ops/storage_transfer.rb +188 -0
- data/lib/decidim/apartment/overrides/active_job_with_tenant.rb +38 -0
- data/lib/decidim/apartment/overrides/core_seeds.rb +31 -0
- data/lib/decidim/apartment/overrides/create_organization_command.rb +69 -0
- data/lib/decidim/apartment/overrides/dashboard_controller.rb +30 -0
- data/lib/decidim/apartment/overrides/decidim_seed.rb +16 -0
- data/lib/decidim/apartment/overrides/organizations_controller_overrides.rb +75 -0
- data/lib/decidim/apartment/overrides/postgresql_enable_extension.rb +15 -0
- data/lib/decidim/apartment/overrides/postgresql_schema_adapter.rb +34 -0
- data/lib/decidim/apartment/overrides/postgresql_schema_import.rb +35 -0
- data/lib/decidim/apartment/overrides/postgresql_schema_search_path.rb +15 -0
- data/lib/decidim/apartment/overrides/postgresql_schema_statements.rb +17 -0
- data/lib/decidim/apartment/overrides/seeds.rb +52 -0
- data/lib/decidim/apartment/overrides/tenant_init_without_database.rb +19 -0
- data/lib/decidim/apartment/overrides/update_organization_command.rb +38 -0
- data/lib/decidim/apartment/postgres_extensions.rb +198 -0
- data/lib/decidim/apartment/rake_replace.rb +21 -0
- data/lib/decidim/apartment/schema_search_path.rb +43 -0
- data/lib/decidim/apartment/system_organization.rb +67 -0
- data/lib/decidim/apartment/test/factories.rb +11 -0
- data/lib/decidim/apartment/test/seeds/association_1.jpg +0 -0
- data/lib/decidim/apartment/test/seeds/association_2.jpeg +0 -0
- data/lib/decidim/apartment/test/seeds/association_3.jpg +0 -0
- data/lib/decidim/apartment/test/seeds/association_4.jpg +0 -0
- data/lib/decidim/apartment/test/seeds/bg_Dusty Grass.png +0 -0
- data/lib/decidim/apartment/test/seeds/bg_Hyper Blue.png +0 -0
- data/lib/decidim/apartment/test/seeds/bg_Moonwalker.png +0 -0
- data/lib/decidim/apartment/test/seeds/bg_Neon Green.png +0 -0
- data/lib/decidim/apartment/test/seeds/bg_Visual Blue.png +0 -0
- data/lib/decidim/apartment/test/seeds/bg_hinehouse.png +0 -0
- data/lib/decidim/apartment/test/seeds/city_1.jpg +0 -0
- data/lib/decidim/apartment/test/seeds/city_2.jpg +0 -0
- data/lib/decidim/apartment/test/seeds/city_3.jpg +0 -0
- data/lib/decidim/apartment/test/seeds/city_4.webp +0 -0
- data/lib/decidim/apartment/test/seeds/city_5.jpg +0 -0
- data/lib/decidim/apartment/test/seeds/debian.jpeg +0 -0
- data/lib/decidim/apartment/test/seeds/democratic_school_1.jpg +0 -0
- data/lib/decidim/apartment/test/seeds/drupal.jpg +0 -0
- data/lib/decidim/apartment/test/seeds/foss.jpg +0 -0
- data/lib/decidim/apartment/test/seeds/immich.jpg +0 -0
- data/lib/decidim/apartment/test/seeds/kid_1.jpg +0 -0
- data/lib/decidim/apartment/test/seeds/kid_2.jpg +0 -0
- data/lib/decidim/apartment/test/seeds/montessori_1.jpg +0 -0
- data/lib/decidim/apartment/test/seeds/montessori_2.jpg +0 -0
- data/lib/decidim/apartment/test/seeds/neighboor_1.jpg +0 -0
- data/lib/decidim/apartment/test/seeds/neighbor_2.jpg +0 -0
- data/lib/decidim/apartment/test/seeds/neighbor_3.jpg +0 -0
- data/lib/decidim/apartment/test/seeds/pattern_cubes-3_4_2_0-0_0_1__hsla(240, 7_, 18_, 1.00)_hsla(47, 81_, 61_, 1.00).png +0 -0
- data/lib/decidim/apartment/test/seeds/pattern_cubes-3_4_2_0-0_55_1__hsla(240, 7_, 18_, 1.00)_hsla(47, 81_, 61_, 1.00)(1).png +0 -0
- data/lib/decidim/apartment/test/seeds/pattern_cubes-3_4_2_0-0_55_1__hsla(240, 7_, 18_, 1.00)_hsla(47, 81_, 61_, 1.00).png +0 -0
- data/lib/decidim/apartment/test/seeds/pattern_diamonds-1_1_10_0-0_0_1__hsla(240, 7_, 18_, 1.00)_hsla(174, 100_, 29_, 1.00).png +0 -0
- data/lib/decidim/apartment/test/seeds/pattern_diamonds-1_1_2_0-0_0_1__hsla(240, 7_, 18_, 1.00)_hsla(174, 100_, 29_, 1.00).png +0 -0
- data/lib/decidim/apartment/test/seeds/pattern_diamonds-1_5_10_0-0_0_1__hsla(240, 7_, 18_, 1.00)_hsla(174, 100_, 29_, 1.00).png +0 -0
- data/lib/decidim/apartment/test/seeds/pattern_diamonds-1_5_2_0-0_0_1__hsla(240, 7_, 18_, 1.00)_hsla(174, 100_, 29_, 1.00).png +0 -0
- data/lib/decidim/apartment/test/seeds/pattern_new_01.png +0 -0
- data/lib/decidim/apartment/test/seeds/pattern_new_02.png +0 -0
- data/lib/decidim/apartment/test/seeds/pattern_new_03.png +0 -0
- data/lib/decidim/apartment/test/seeds/pattern_squares_01.png +0 -0
- data/lib/decidim/apartment/test/seeds/pattern_squares_02.png +0 -0
- data/lib/decidim/apartment/test/seeds/pattern_squares_03.png +0 -0
- data/lib/decidim/apartment/test/seeds/pattern_squares_04.png +0 -0
- data/lib/decidim/apartment/test/seeds/pattern_squares_05.png +0 -0
- data/lib/decidim/apartment/test/seeds/pattern_squares_06.png +0 -0
- data/lib/decidim/apartment/test/seeds/pattern_squares_07.png +0 -0
- data/lib/decidim/apartment/test/seeds/pattern_squares_08.png +0 -0
- data/lib/decidim/apartment/test/seeds/pattern_squares_09.png +0 -0
- data/lib/decidim/apartment/test/seeds/pattern_squares_10.png +0 -0
- data/lib/decidim/apartment/test/seeds/pattern_squares_11.png +0 -0
- data/lib/decidim/apartment/test/seeds/pattern_squares_12.png +0 -0
- data/lib/decidim/apartment/test/seeds/pattern_squares_13.png +0 -0
- data/lib/decidim/apartment/test/seeds/pattern_squares_14.png +0 -0
- data/lib/decidim/apartment/test/seeds/pattern_squares_15.png +0 -0
- data/lib/decidim/apartment/test/seeds/pattern_squares_16.png +0 -0
- data/lib/decidim/apartment/test/seeds/pattern_squares_and_circles_01.png +0 -0
- data/lib/decidim/apartment/test/seeds/pattern_squares_and_circles_02.png +0 -0
- data/lib/decidim/apartment/test/seeds/pattern_squares_and_circles_03.png +0 -0
- data/lib/decidim/apartment/test/seeds/pattern_squares_and_circles_04.png +0 -0
- data/lib/decidim/apartment/test/seeds/pattern_squares_and_circles_05.png +0 -0
- data/lib/decidim/apartment/test/seeds/pattern_squares_and_circles_06.png +0 -0
- data/lib/decidim/apartment/test/seeds/pattern_squares_and_circles_07.png +0 -0
- data/lib/decidim/apartment/test/seeds/pattern_squares_and_circles_08.png +0 -0
- data/lib/decidim/apartment/test/seeds/pattern_squares_and_circles_09.png +0 -0
- data/lib/decidim/apartment/test/seeds/pattern_squares_and_circles_10.png +0 -0
- data/lib/decidim/apartment/test/seeds/pattern_squares_and_circles_11.png +0 -0
- data/lib/decidim/apartment/test/seeds/pattern_squares_and_circles_12.png +0 -0
- data/lib/decidim/apartment/test/seeds/pattern_squares_and_circles_13.png +0 -0
- data/lib/decidim/apartment/test/seeds/rails.jpg +0 -0
- data/lib/decidim/apartment/test/seeds/school_1.jpg +0 -0
- data/lib/decidim/apartment/test/seeds/school_3.jpg +0 -0
- data/lib/decidim/apartment/test/seeds/school_4.jpg +0 -0
- data/lib/decidim/apartment/test/seeds/school_5.jpg +0 -0
- data/lib/decidim/apartment/test/seeds/silverstripe.jpg +0 -0
- data/lib/decidim/apartment/test/seeds/street_1.jpg +0 -0
- data/lib/decidim/apartment/test/seeds/street_2.jpg +0 -0
- data/lib/decidim/apartment/test/seeds/street_3.jpg +0 -0
- data/lib/decidim/apartment/test/seeds/urban_agri_1.webp +0 -0
- data/lib/decidim/apartment/test/seeds/urban_agri_2.jpg +0 -0
- data/lib/decidim/apartment/test/seeds/urban_agri_3.jpg +0 -0
- data/lib/decidim/apartment/test/seeds/urban_agri_4.jpg +0 -0
- data/lib/decidim/apartment/test/seeds/world-map-colors.png +0 -0
- data/lib/decidim/apartment/version.rb +44 -0
- data/lib/decidim/apartment.rb +69 -0
- data/lib/tasks/decidim_apartment_check_install.rake +58 -0
- data/lib/tasks/decidim_apartment_convert.rake +60 -0
- data/lib/tasks/decidim_apartment_gem_manager.rake +62 -0
- data/lib/tasks/decidim_apartment_import.rake +39 -0
- data/lib/tasks/decidim_apartment_install_extension.rake +49 -0
- data/lib/tasks/decidim_apartment_performance_seed.rake +12 -0
- data/lib/tasks/decidim_apartment_rotate.rake +17 -0
- data/lib/tasks/decidim_apartment_storage.rake +27 -0
- data/lib/tasks/decidim_download_your_data_tasks.rake +121 -0
- data/lib/tasks/decidim_mailers.rake +38 -0
- data/lib/tasks/decidim_meetings.rake +30 -0
- data/lib/tasks/decidim_metrics_tasks.rake +29 -0
- data/lib/tasks/decidim_open_data_tasks.rake +24 -0
- data/lib/tasks/decidim_participatory_processes.rake +20 -0
- data/lib/tasks/decidim_reminders_tasks.rake +24 -0
- metadata +361 -0
data/README.md
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
# Decidim Apartment
|
|
2
|
+
|
|
3
|
+
Decidim Apartment integrates the [Apartment gem](https://github.com/rails-on-services/apartment) into Decidim. Each organization can use its own PostgreSQL schema and storage prefix on one Rails process. The gem also ships default wiring for cache, Active Storage, and Active Job across tenants.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
See the [documentation website](https://participa-gem-277819.gitlab.io).
|
|
8
|
+
|
|
9
|
+
## Contributing
|
|
10
|
+
|
|
11
|
+
Contributions are welcome. Read [CONTRIBUTING](./CONTRIBUTING) before opening a merge request.
|
|
12
|
+
|
|
13
|
+
## Run locally
|
|
14
|
+
|
|
15
|
+
Development uses Docker.
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
docker compose up
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
That command:
|
|
22
|
+
|
|
23
|
+
- Prepares the environment with system credentials
|
|
24
|
+
- email: `system@example.org`
|
|
25
|
+
- password: `decidim123456789`
|
|
26
|
+
- Installs files needed to run specs
|
|
27
|
+
- Starts a Rails server and a Shakapacker dev server
|
|
28
|
+
|
|
29
|
+
Available locales in Compose: `en`, `fr`, `pt-BR` (`DECIDIM_AVAILABLE_LOCALES`).
|
|
30
|
+
|
|
31
|
+
### Demo seed (default)
|
|
32
|
+
|
|
33
|
+
`rails db:seed` runs curated multi-tenant demos (not vanilla Decidim faker):
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
docker compose run --rm decidim-apartment bundle exec rails db:seed
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
| Host | Locale(s) | Content |
|
|
40
|
+
| ---- | --------- | ------- |
|
|
41
|
+
| `tenanta.localhost` | EN | Process group **Our city** + 2 processes |
|
|
42
|
+
| `tenantb.localhost` | FR | Assembly **Education Humaniste** + 2 children |
|
|
43
|
+
| `tenantc.localhost` | FR+EN | FOSS conference (needs `decidim-conferences` migrations) |
|
|
44
|
+
|
|
45
|
+
Org admin on each tenant: `admin@example.org` / `decidim123456789`.
|
|
46
|
+
|
|
47
|
+
Browsers resolve `*.localhost` without `/etc/hosts`. Screenshots for docs live under `website/static/screens`.
|
|
48
|
+
|
|
49
|
+
To restore upstream single-tenant faker seeds:
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
DECIDIM_APARTMENT_VANILLA_SEED=1 docker compose run --rm decidim-apartment bundle exec rails db:seed
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Notes:
|
|
56
|
+
|
|
57
|
+
- Your files are bind-mounted into the `/module` folder
|
|
58
|
+
- The Rails application comes from the participa Dockerfile (Brazilian University Decidim image) and is not bind-mounted
|
|
59
|
+
|
|
60
|
+
## Tests (Decidim 0.31)
|
|
61
|
+
|
|
62
|
+
Specs run in Docker. Appraisal gemfiles (queue adapter stays `:test` so `perform_later` specs still run in-process):
|
|
63
|
+
|
|
64
|
+
| Suite | Compose | `BUNDLE_GEMFILE` | Database |
|
|
65
|
+
| ----- | ------- | ---------------- | -------- |
|
|
66
|
+
| default | `docker-compose.test.yml` | `gemfiles/decidim_0.31.gemfile` | `postgres:17` |
|
|
67
|
+
| sidekiq | `docker-compose.test.yml` | `gemfiles/decidim_0.31_sidekiq.gemfile` | `postgres:17` |
|
|
68
|
+
| goodjob | `docker-compose.test.yml` | `gemfiles/decidim_0.31_goodjob.gemfile` | `postgres:17` |
|
|
69
|
+
| geo | `docker-compose.test.yml` + `docker-compose.geo.yml` | `gemfiles/decidim_0.31_geo.gemfile` | `postgis/postgis:17-3.5` |
|
|
70
|
+
| geo + sidekiq | `docker-compose.test.yml` + `docker-compose.geo.yml` | `gemfiles/decidim_0.31_geo_sidekiq.gemfile` | `postgis/postgis:17-3.5` |
|
|
71
|
+
| geo + goodjob | `docker-compose.test.yml` + `docker-compose.geo.yml` | `gemfiles/decidim_0.31_geo_goodjob.gemfile` | `postgis/postgis:17-3.5` |
|
|
72
|
+
|
|
73
|
+
Geo uses [decidim-module-geo](https://gitlab.com/octree_gva/decidim/vocacity/decidim-modules/decidim-module-geo) on branch `233-update-decidim-geo-compat-with-decidim-031` via Bundler git (see `Appraisals`).
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
docker compose -f docker-compose.test.yml build rspec
|
|
77
|
+
|
|
78
|
+
docker compose -f docker-compose.test.yml run --rm rspec \
|
|
79
|
+
"bundle install && bundle exec rake test_app && bundle exec rspec"
|
|
80
|
+
|
|
81
|
+
docker compose -f docker-compose.test.yml run --rm \
|
|
82
|
+
-e BUNDLE_GEMFILE=gemfiles/decidim_0.31_sidekiq.gemfile rspec \
|
|
83
|
+
"bundle install && bundle exec rake test_app && bundle exec rspec"
|
|
84
|
+
|
|
85
|
+
docker compose -f docker-compose.test.yml run --rm \
|
|
86
|
+
-e BUNDLE_GEMFILE=gemfiles/decidim_0.31_goodjob.gemfile rspec \
|
|
87
|
+
"bundle install && bundle exec rake test_app && bundle exec rspec"
|
|
88
|
+
|
|
89
|
+
docker compose -f docker-compose.test.yml -f docker-compose.geo.yml run --rm rspec \
|
|
90
|
+
"bundle install && bundle exec rake test_app && bundle exec rspec"
|
|
91
|
+
|
|
92
|
+
docker compose -f docker-compose.test.yml -f docker-compose.geo.yml run --rm \
|
|
93
|
+
-e BUNDLE_GEMFILE=gemfiles/decidim_0.31_geo_sidekiq.gemfile rspec \
|
|
94
|
+
"bundle install && bundle exec rake test_app && bundle exec rspec"
|
|
95
|
+
|
|
96
|
+
docker compose -f docker-compose.test.yml -f docker-compose.geo.yml run --rm \
|
|
97
|
+
-e BUNDLE_GEMFILE=gemfiles/decidim_0.31_geo_goodjob.gemfile rspec \
|
|
98
|
+
"bundle install && bundle exec rake test_app && bundle exec rspec"
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### Convert QA (seed → convert → Capybara)
|
|
102
|
+
|
|
103
|
+
Realistic convert coverage is tagged `convert_qa` and excluded from the default suite. Set `CONVERT_QA=1` and install Chromium (bundled in `Dockerfile.rspec`).
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
docker compose -f docker-compose.test.yml run --rm rspec \
|
|
107
|
+
"bundle install && bundle exec rake test_app && CONVERT_QA=1 bundle exec rspec --tag convert_qa --tag ~geo"
|
|
108
|
+
|
|
109
|
+
docker compose \
|
|
110
|
+
-f docker-compose.test.yml -f docker-compose.geo.yml run --rm rspec \
|
|
111
|
+
"bundle install && bundle exec rake test_app && CONVERT_QA=1 bundle exec rspec --tag convert_qa --tag geo"
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
The geo convert QA matrix also enables `activerecord-session_store` and seeds a CC BY 4.0 Switzerland shapefile from `spec/fixtures/geo/` (see `license_gis.txt`).
|
|
115
|
+
|
|
116
|
+
## GitLab CI on your laptop
|
|
117
|
+
|
|
118
|
+
If you are reproducing a GitLab test or lint job on your laptop, use `docker-compose.ci.yml`. Daily specs stay on `docker-compose.test.yml` above. This path does not run `bench::build`, `docusaurus::publish`, `ruby::rubygem`, or `crowdin::*`.
|
|
119
|
+
|
|
120
|
+
Infrastructure: Docker Compose. Ruby jobs build `Dockerfile.rspec` (image `decidim-apartment-rspec`). Docusaurus uses `node:18`. Postgres is `postgres:17` (`POSTGRES_DB=decidim_test`). Geo jobs use `postgis/postgis:17-3.5` on host `postgis` (GitLab aliases that service as `postgres`). Redis is `redis:7-alpine`. Do not set `DECIDIM_GEO_PATH`; the geo gemfile git-pins `decidim-decidim_geo`.
|
|
121
|
+
|
|
122
|
+
```bash
|
|
123
|
+
docker compose -f docker-compose.ci.yml build rspec
|
|
124
|
+
|
|
125
|
+
docker compose -f docker-compose.ci.yml run --rm rubocop
|
|
126
|
+
docker compose -f docker-compose.ci.yml run --rm erblint
|
|
127
|
+
docker compose -f docker-compose.ci.yml run --rm rspec
|
|
128
|
+
docker compose -f docker-compose.ci.yml run --rm rspec_029
|
|
129
|
+
docker compose -f docker-compose.ci.yml run --rm rspec_sidekiq
|
|
130
|
+
docker compose -f docker-compose.ci.yml run --rm rspec_goodjob
|
|
131
|
+
docker compose -f docker-compose.ci.yml run --rm rspec_geo
|
|
132
|
+
docker compose -f docker-compose.ci.yml run --rm rspec_geo_sidekiq
|
|
133
|
+
docker compose -f docker-compose.ci.yml run --rm rspec_geo_goodjob
|
|
134
|
+
docker compose -f docker-compose.ci.yml run --rm convert_qa
|
|
135
|
+
docker compose -f docker-compose.ci.yml run --rm convert_qa_geo
|
|
136
|
+
docker compose -f docker-compose.ci.yml run --rm docusaurus
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
Each `run --rm <job>` already runs the full GitLab script. Do not pass an extra command (unlike `docker-compose.test.yml`, which sleeps until you pass `bundle exec rspec`).
|
|
140
|
+
|
|
141
|
+
| Variable | Default in `docker-compose.ci.yml` |
|
|
142
|
+
| -------- | ---------------------------------- |
|
|
143
|
+
| `DATABASE_HOST` | `postgres` (`postgis` for `rspec_geo` and `convert_qa_geo`) |
|
|
144
|
+
| `DATABASE_USERNAME` | `decidim` |
|
|
145
|
+
| `DATABASE_PASSWORD` | `TEST-insecure_password` |
|
|
146
|
+
| `POSTGRES_DB` / `POSTGRES_USER` / `POSTGRES_PASSWORD` | `decidim_test` / `decidim` / `TEST-insecure_password` |
|
|
147
|
+
| `DISABLED_DOCKER_COMPOSE` | `true` |
|
|
148
|
+
| `NODE_MAJOR` | `18` |
|
|
149
|
+
| `SIMPLECOV` | `1` |
|
|
150
|
+
| `CI` | `1` |
|
|
151
|
+
| `RAILS_ENV` | `test` |
|
|
152
|
+
| `REDIS_URL` | `redis://redis:6379/1` |
|
|
153
|
+
| `DECIDIM_DEFAULT_LOCALE` | `en` |
|
|
154
|
+
| `DECIDIM_AVAILABLE_LOCALES` | `en,pt-BR` |
|
|
155
|
+
| `DISABLE_SPRING` | `true` |
|
|
156
|
+
| `SECRET_KEY_BASE` | 128 zeros |
|
|
157
|
+
| `CHROME_BIN` / `GOOGLE_CHROME_SHIM` | `/usr/bin/chromium` |
|
|
158
|
+
| `BUNDLE_GEMFILE` | `gemfiles/decidim_0.31.gemfile` (0.29: `gemfiles/decidim_0.29.gemfile` on Ruby 3.2 image `rspec_029`; sidekiq: `gemfiles/decidim_0.31_sidekiq.gemfile`; goodjob: `gemfiles/decidim_0.31_goodjob.gemfile`; geo jobs: `gemfiles/decidim_0.31_geo.gemfile`; geo+sidekiq: `gemfiles/decidim_0.31_geo_sidekiq.gemfile`; geo+goodjob: `gemfiles/decidim_0.31_geo_goodjob.gemfile`) |
|
|
159
|
+
| `CONVERT_QA` | unset; `1` on `convert_qa` and `convert_qa_geo` |
|
|
160
|
+
|
|
161
|
+
If Postgres is not ready, wait for the healthcheck (Compose `depends_on` already does). Bind-mount ports are not published, so this stack does not collide with `docker compose up` on 5432/6379.
|
|
162
|
+
|
|
163
|
+
## License
|
|
164
|
+
|
|
165
|
+
This engine is distributed under the [GNU AFFERO GENERAL PUBLIC LICENSE](LICENSE-AGPLv3.txt)
|
|
166
|
+
|
|
167
|
+
<br /><br />
|
data/Rakefile
ADDED
|
@@ -0,0 +1,405 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "decidim/dev/common_rake"
|
|
4
|
+
require "rake/file_utils"
|
|
5
|
+
require "yaml"
|
|
6
|
+
|
|
7
|
+
module DummyAppPrep
|
|
8
|
+
class << self
|
|
9
|
+
include FileUtils
|
|
10
|
+
|
|
11
|
+
def dummy_path
|
|
12
|
+
"spec/decidim_dummy_app"
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def geo_loaded?
|
|
16
|
+
Gem.loaded_specs.has_key?("decidim-decidim_geo")
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def session_store_loaded?
|
|
20
|
+
Gem.loaded_specs.has_key?("activerecord-session_store")
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def good_job_loaded?
|
|
24
|
+
Gem.loaded_specs.has_key?("good_job")
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def sidekiq_loaded?
|
|
28
|
+
Gem.loaded_specs.has_key?("sidekiq")
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def test_adapter
|
|
32
|
+
geo_loaded? ? "postgis" : "postgresql"
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
OPTIONAL_DEMO_FILES = %w(
|
|
38
|
+
app/services/dummy_signature_handler.rb
|
|
39
|
+
app/services/dummy_sms_mobile_phone_validator.rb
|
|
40
|
+
).freeze
|
|
41
|
+
|
|
42
|
+
def pin_dummy_test_queue_adapter
|
|
43
|
+
path = File.join(DummyAppPrep.dummy_path, "config/environments/test.rb")
|
|
44
|
+
File.open(path, "a") do |file|
|
|
45
|
+
file.puts <<~RUBY
|
|
46
|
+
|
|
47
|
+
Rails.application.configure do
|
|
48
|
+
config.active_job.queue_adapter = :test
|
|
49
|
+
end
|
|
50
|
+
RUBY
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def set_dummy_secret_key_base
|
|
55
|
+
path = File.join(DummyAppPrep.dummy_path, "config/environments/test.rb")
|
|
56
|
+
File.open(path, "a") do |file|
|
|
57
|
+
file.puts <<~RUBY
|
|
58
|
+
|
|
59
|
+
Rails.application.configure do
|
|
60
|
+
config.secret_key_base = "0" * 128
|
|
61
|
+
end
|
|
62
|
+
RUBY
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def strip_optional_demo_files
|
|
67
|
+
OPTIONAL_DEMO_FILES.each do |relative_path|
|
|
68
|
+
FileUtils.rm_f(File.join(DummyAppPrep.dummy_path, relative_path))
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def without_appraisal_gemfile
|
|
73
|
+
gemfile = ENV.delete("BUNDLE_GEMFILE")
|
|
74
|
+
original = Bundler::ORIGINAL_ENV.delete("BUNDLE_GEMFILE")
|
|
75
|
+
yield
|
|
76
|
+
ensure
|
|
77
|
+
ENV["BUNDLE_GEMFILE"] = gemfile if gemfile
|
|
78
|
+
Bundler::ORIGINAL_ENV["BUNDLE_GEMFILE"] = original if original
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def install_module(path)
|
|
82
|
+
Dir.chdir(path) do
|
|
83
|
+
without_appraisal_gemfile { install_apartment_migrations }
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def install_apartment_migrations
|
|
88
|
+
system("bundle", "exec", "rails", "decidim_apartment:install:migrations", exception: true)
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def install_toggle_migrations
|
|
92
|
+
system("bundle", "exec", "rails", "decidim_toggle:install:migrations", exception: true)
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def install_geo_migrations
|
|
96
|
+
system("bundle", "exec", "rails", "decidim_geo:install:migrations", exception: true)
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def install_good_job_migrations
|
|
100
|
+
return unless DummyAppPrep.good_job_loaded?
|
|
101
|
+
|
|
102
|
+
system("bundle", "exec", "rails", "generate", "good_job:install", exception: true)
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def seed_db(path)
|
|
106
|
+
Dir.chdir(path) do
|
|
107
|
+
system("bundle exec rails db:seed")
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
def test_database_yml
|
|
112
|
+
{
|
|
113
|
+
"test" => {
|
|
114
|
+
"adapter" => DummyAppPrep.test_adapter,
|
|
115
|
+
"encoding" => "unicode",
|
|
116
|
+
"host" => ENV.fetch("DATABASE_HOST", "localhost"),
|
|
117
|
+
"port" => ENV.fetch("DATABASE_PORT", "5432").to_i,
|
|
118
|
+
"username" => ENV.fetch("DATABASE_USERNAME", "decidim"),
|
|
119
|
+
"password" => ENV.fetch("DATABASE_PASSWORD", "insecure-password"),
|
|
120
|
+
"database" => "participa_test<%= ENV.fetch('TEST_ENV_NUMBER', '') %>",
|
|
121
|
+
"schema_search_path" => "public"
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
def dummy_extra_gems
|
|
127
|
+
[apartment_dummy_gems, dummy_geo_gems, dummy_session_store_gems, dummy_sidekiq_gems, dummy_good_job_gems].join
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
def apartment_dummy_gems
|
|
131
|
+
<<~GEMFILE
|
|
132
|
+
gem 'ros-apartment', require: 'apartment'
|
|
133
|
+
gem 'deface', git: 'https://github.com/froger/deface', branch: 'fix/js-overrides'
|
|
134
|
+
GEMFILE
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
def dummy_geo_gems
|
|
138
|
+
return "" unless DummyAppPrep.geo_loaded?
|
|
139
|
+
|
|
140
|
+
<<~GEMFILE
|
|
141
|
+
gem 'decidim-decidim_geo', git: 'https://gitlab.com/octree_gva/decidim/vocacity/decidim-modules/decidim-module-geo', branch: '233-update-decidim-geo-compat-with-decidim-031'
|
|
142
|
+
gem 'activerecord-postgis-adapter'
|
|
143
|
+
GEMFILE
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
def dummy_session_store_gems
|
|
147
|
+
return "" unless DummyAppPrep.session_store_loaded?
|
|
148
|
+
|
|
149
|
+
"gem 'activerecord-session_store'\n"
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
def dummy_sidekiq_gems
|
|
153
|
+
return "" unless DummyAppPrep.sidekiq_loaded?
|
|
154
|
+
|
|
155
|
+
"gem 'sidekiq'\n"
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
def dummy_good_job_gems
|
|
159
|
+
return "" unless DummyAppPrep.good_job_loaded?
|
|
160
|
+
|
|
161
|
+
"gem 'good_job', '~> 4.19'\n"
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
def write_session_store_initializer
|
|
165
|
+
return unless DummyAppPrep.session_store_loaded?
|
|
166
|
+
|
|
167
|
+
File.write("#{DummyAppPrep.dummy_path}/config/initializers/session_store.rb", session_store_initializer)
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
def session_store_initializer
|
|
171
|
+
<<~RUBY
|
|
172
|
+
# frozen_string_literal: true
|
|
173
|
+
|
|
174
|
+
Rails.application.config.session_store :active_record_store, key: "_decidim_session"
|
|
175
|
+
RUBY
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
def write_sessions_migration
|
|
179
|
+
return unless DummyAppPrep.session_store_loaded?
|
|
180
|
+
|
|
181
|
+
File.write("#{DummyAppPrep.dummy_path}/db/migrate/#{sessions_migration_version}_create_sessions.rb", sessions_migration)
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
def sessions_migration_version
|
|
185
|
+
versions = Dir["#{DummyAppPrep.dummy_path}/db/migrate/*.rb"].map { |path| File.basename(path).to_i }
|
|
186
|
+
next_version = [versions.max.to_i, Time.now.utc.strftime("%Y%m%d%H%M%S").to_i].max + 1
|
|
187
|
+
next_version.to_s
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
def sessions_migration
|
|
191
|
+
<<~RUBY
|
|
192
|
+
# frozen_string_literal: true
|
|
193
|
+
|
|
194
|
+
class CreateSessions < ActiveRecord::Migration[7.0]
|
|
195
|
+
def change
|
|
196
|
+
create_table :sessions do |t|
|
|
197
|
+
t.string :session_id, null: false
|
|
198
|
+
t.text :data
|
|
199
|
+
t.timestamps
|
|
200
|
+
end
|
|
201
|
+
add_index :sessions, :session_id, unique: true
|
|
202
|
+
add_index :sessions, :updated_at
|
|
203
|
+
end
|
|
204
|
+
end
|
|
205
|
+
RUBY
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
def write_dummy_database_yml
|
|
209
|
+
File.open("#{DummyAppPrep.dummy_path}/config/database.yml", "w") do |file|
|
|
210
|
+
YAML.dump(test_database_yml, file)
|
|
211
|
+
end
|
|
212
|
+
end
|
|
213
|
+
|
|
214
|
+
def append_dummy_gemfile
|
|
215
|
+
File.open("#{DummyAppPrep.dummy_path}/Gemfile", "a") { |file| file.puts dummy_extra_gems }
|
|
216
|
+
end
|
|
217
|
+
|
|
218
|
+
def dummy_bundle_install
|
|
219
|
+
system("bundle", "config", "set", "--local", "path", "vendor/bundle", exception: true)
|
|
220
|
+
system("bundle check || bundle install", exception: true)
|
|
221
|
+
end
|
|
222
|
+
|
|
223
|
+
def dummy_migrate
|
|
224
|
+
%w(db:drop db:create db:migrate db:schema:dump).each do |task|
|
|
225
|
+
system("bin/rails", task, exception: true)
|
|
226
|
+
end
|
|
227
|
+
end
|
|
228
|
+
|
|
229
|
+
def install_geo_npm
|
|
230
|
+
system("bash", "-lc", "yes | bundle exec rails decidim_geo:webpacker:install", exception: true)
|
|
231
|
+
end
|
|
232
|
+
|
|
233
|
+
def dummy_assets(geo)
|
|
234
|
+
install_geo_npm if geo
|
|
235
|
+
system("npm", "install", exception: true)
|
|
236
|
+
system("bin/rails", "assets:precompile", exception: true)
|
|
237
|
+
end
|
|
238
|
+
|
|
239
|
+
def dummy_prepare_steps(geo)
|
|
240
|
+
ENV["RAILS_ENV"] = "test"
|
|
241
|
+
dummy_bundle_install
|
|
242
|
+
install_toggle_migrations
|
|
243
|
+
install_apartment_migrations
|
|
244
|
+
install_geo_migrations if geo
|
|
245
|
+
install_good_job_migrations
|
|
246
|
+
dummy_migrate
|
|
247
|
+
dummy_assets(geo)
|
|
248
|
+
end
|
|
249
|
+
|
|
250
|
+
def dummy_unbundled_install(geo)
|
|
251
|
+
Bundler.with_unbundled_env do
|
|
252
|
+
without_appraisal_gemfile { dummy_prepare_steps(geo) }
|
|
253
|
+
end
|
|
254
|
+
end
|
|
255
|
+
|
|
256
|
+
def prepare_dummy_database
|
|
257
|
+
geo = DummyAppPrep.geo_loaded?
|
|
258
|
+
Dir.chdir(DummyAppPrep.dummy_path) { dummy_unbundled_install(geo) }
|
|
259
|
+
end
|
|
260
|
+
|
|
261
|
+
def write_ignore_overrides_initializer
|
|
262
|
+
dest = "#{DummyAppPrep.dummy_path}/config/initializers/ignore_gem_overrides.rb"
|
|
263
|
+
File.write(dest, ignore_overrides_initializer)
|
|
264
|
+
end
|
|
265
|
+
|
|
266
|
+
def ignore_overrides_initializer
|
|
267
|
+
<<~RUBY
|
|
268
|
+
# frozen_string_literal: true
|
|
269
|
+
dirs = Gem.loaded_specs.values.map { |s| File.join(s.full_gem_path, "app/overrides") }
|
|
270
|
+
dirs << Rails.root.join("app/overrides").to_s
|
|
271
|
+
Rails.autoloaders.each { |a| dirs.each { |p| a.ignore(p) if Dir.exist?(p) } }
|
|
272
|
+
RUBY
|
|
273
|
+
end
|
|
274
|
+
|
|
275
|
+
def dummy_decidim_constraint
|
|
276
|
+
segs = Gem.loaded_specs.fetch("decidim").version.segments
|
|
277
|
+
"~> #{segs[0]}.#{segs[1]}.0"
|
|
278
|
+
end
|
|
279
|
+
|
|
280
|
+
def pin_gemfile_decidim_version(path)
|
|
281
|
+
File.write(
|
|
282
|
+
path,
|
|
283
|
+
File.read(path).sub(
|
|
284
|
+
/ENV\.fetch\("DECIDIM_VERSION", "[^"]+"\)/,
|
|
285
|
+
%(ENV.fetch("DECIDIM_VERSION", "#{dummy_decidim_constraint}"))
|
|
286
|
+
)
|
|
287
|
+
)
|
|
288
|
+
end
|
|
289
|
+
|
|
290
|
+
def appraisal_lockfile_path
|
|
291
|
+
gemfile = ENV.fetch("BUNDLE_GEMFILE", nil)
|
|
292
|
+
return unless gemfile
|
|
293
|
+
|
|
294
|
+
path = "#{gemfile}.lock"
|
|
295
|
+
path if File.exist?(path)
|
|
296
|
+
end
|
|
297
|
+
|
|
298
|
+
def lockfile_with_dummy_path(contents)
|
|
299
|
+
contents.sub(/^PATH\n remote: \.$/, "PATH\n remote: ../..")
|
|
300
|
+
end
|
|
301
|
+
|
|
302
|
+
def stage_root_files_for_dummy
|
|
303
|
+
pin_gemfile_decidim_version("Gemfile")
|
|
304
|
+
lock = appraisal_lockfile_path
|
|
305
|
+
File.write("Gemfile.lock", lockfile_with_dummy_path(File.read(lock))) if lock
|
|
306
|
+
end
|
|
307
|
+
|
|
308
|
+
def with_staged_root_files
|
|
309
|
+
gemfile = File.read("Gemfile")
|
|
310
|
+
lockfile = File.exist?("Gemfile.lock") ? File.read("Gemfile.lock") : nil
|
|
311
|
+
stage_root_files_for_dummy
|
|
312
|
+
yield
|
|
313
|
+
ensure
|
|
314
|
+
File.write("Gemfile", gemfile) if gemfile
|
|
315
|
+
File.write("Gemfile.lock", lockfile) if lockfile
|
|
316
|
+
end
|
|
317
|
+
|
|
318
|
+
def prepare_test_files
|
|
319
|
+
ENV["RAILS_ENV"] = "test"
|
|
320
|
+
pin_gemfile_decidim_version(File.join(DummyAppPrep.dummy_path, "Gemfile"))
|
|
321
|
+
write_dummy_database_yml
|
|
322
|
+
append_dummy_gemfile
|
|
323
|
+
write_session_store_initializer
|
|
324
|
+
write_sessions_migration
|
|
325
|
+
write_ignore_overrides_initializer
|
|
326
|
+
prepare_dummy_database
|
|
327
|
+
end
|
|
328
|
+
|
|
329
|
+
desc "Generates a decidim_dummy_app app for testing"
|
|
330
|
+
task :test_app do
|
|
331
|
+
ENV["RAILS_ENV"] = "test"
|
|
332
|
+
with_staged_root_files do
|
|
333
|
+
Bundler.with_original_env do
|
|
334
|
+
without_appraisal_gemfile do
|
|
335
|
+
generate_decidim_app(
|
|
336
|
+
DummyAppPrep.dummy_path,
|
|
337
|
+
"--app_name",
|
|
338
|
+
"DecidimApartment",
|
|
339
|
+
"--path",
|
|
340
|
+
"../..",
|
|
341
|
+
"--skip_spring",
|
|
342
|
+
"--demo",
|
|
343
|
+
"--force_ssl",
|
|
344
|
+
"false",
|
|
345
|
+
"--locales",
|
|
346
|
+
"pt-BR,en"
|
|
347
|
+
)
|
|
348
|
+
end
|
|
349
|
+
end
|
|
350
|
+
end
|
|
351
|
+
strip_optional_demo_files
|
|
352
|
+
set_dummy_secret_key_base
|
|
353
|
+
pin_dummy_test_queue_adapter
|
|
354
|
+
prepare_test_files
|
|
355
|
+
end
|
|
356
|
+
|
|
357
|
+
##
|
|
358
|
+
# Tasks for developement_app
|
|
359
|
+
##
|
|
360
|
+
|
|
361
|
+
desc "Prepare for development"
|
|
362
|
+
task prepare_dev: :environment do
|
|
363
|
+
# Remove previous existing db, and recreate one.
|
|
364
|
+
Dir.chdir("development_app") do
|
|
365
|
+
system("bundle exec rake db:drop")
|
|
366
|
+
system("bundle exec rake db:create")
|
|
367
|
+
end
|
|
368
|
+
ENV["RAILS_ENV"] = "development"
|
|
369
|
+
database_yml = {
|
|
370
|
+
"development" => {
|
|
371
|
+
"adapter" => "postgis",
|
|
372
|
+
"encoding" => "unicode",
|
|
373
|
+
"host" => ENV.fetch("DATABASE_HOST", "localhost"),
|
|
374
|
+
"port" => ENV.fetch("DATABASE_PORT", "5432").to_i,
|
|
375
|
+
"username" => ENV.fetch("DATABASE_USERNAME", "decidim"),
|
|
376
|
+
"password" => ENV.fetch("DATABASE_PASSWORD", "insecure-password"),
|
|
377
|
+
"database" => "participa_test\#{ENV.fetch('TEST_ENV_NUMBER', '')}"
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
File.open("development_app/config/database.yml", "w") { |f| YAML.dump(database_yml, f) }
|
|
381
|
+
Dir.chdir("development_app") do
|
|
382
|
+
system("bundle exec rake db:migrate")
|
|
383
|
+
end
|
|
384
|
+
end
|
|
385
|
+
|
|
386
|
+
desc "Generates a development app"
|
|
387
|
+
task development_app: :prepare_dev do
|
|
388
|
+
Bundler.with_original_env do
|
|
389
|
+
generate_decidim_app(
|
|
390
|
+
"development_app",
|
|
391
|
+
"--app_name",
|
|
392
|
+
"DecidimApartment",
|
|
393
|
+
"recreate_db",
|
|
394
|
+
"--path",
|
|
395
|
+
"..",
|
|
396
|
+
"--skip_spring",
|
|
397
|
+
"--demo",
|
|
398
|
+
"--force_ssl",
|
|
399
|
+
"false",
|
|
400
|
+
"--demo"
|
|
401
|
+
)
|
|
402
|
+
end
|
|
403
|
+
|
|
404
|
+
install_module("development_app")
|
|
405
|
+
end
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Decidim
|
|
4
|
+
module Apartment
|
|
5
|
+
##
|
|
6
|
+
# Command to create a new tenant.
|
|
7
|
+
# This command creates a new distribution key and then create a new tenant.
|
|
8
|
+
# It handles rollback in case of error.
|
|
9
|
+
class CreateTenantCommand < ::Decidim::Command
|
|
10
|
+
attr_reader :form
|
|
11
|
+
|
|
12
|
+
def initialize(form)
|
|
13
|
+
super()
|
|
14
|
+
@form = form
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def call
|
|
18
|
+
return broadcast(:invalid, form.errors.full_messages.join(", ")) if form.invalid?
|
|
19
|
+
|
|
20
|
+
distribution_key = ::Apartment::Tenant.switch("public") do
|
|
21
|
+
create_tenant!
|
|
22
|
+
end
|
|
23
|
+
broadcast(:ok, distribution_key)
|
|
24
|
+
rescue StandardError => e
|
|
25
|
+
broadcast(:invalid, e.message)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
private
|
|
29
|
+
|
|
30
|
+
##
|
|
31
|
+
# Create a distribution key and then create a new Tenant
|
|
32
|
+
def create_tenant!
|
|
33
|
+
match = ::Decidim::Apartment::DistributionKey.where(host: form.host).first
|
|
34
|
+
if match
|
|
35
|
+
ensure_tenant_schema!(match.key)
|
|
36
|
+
return match
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
distribution_key = ::Decidim::Apartment::DistributionKey.create!(host: form.host)
|
|
40
|
+
distribution_key.sync_hosts!(primary_host: form.host)
|
|
41
|
+
ensure_tenant_schema!(distribution_key.key)
|
|
42
|
+
distribution_key
|
|
43
|
+
rescue StandardError => e
|
|
44
|
+
rollback_tenant!(distribution_key.key) if distribution_key.present?
|
|
45
|
+
raise e
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def ensure_tenant_schema!(tenant_key)
|
|
49
|
+
# Check the real PostgreSQL schema — not tenant_names (DistributionKey is
|
|
50
|
+
# inserted first, so the key would already appear in tenant_names).
|
|
51
|
+
# Also recreate empty schemas left behind by a failed pg_dump import.
|
|
52
|
+
return if tenant_schema_ready?(tenant_key)
|
|
53
|
+
|
|
54
|
+
drop_tenant_schema_if_present!(tenant_key)
|
|
55
|
+
::Apartment::Tenant.create(tenant_key)
|
|
56
|
+
drop_postgis_catalog!(tenant_key)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def drop_postgis_catalog!(tenant_key)
|
|
60
|
+
ActiveRecord::Base.connection.execute(
|
|
61
|
+
%(DROP TABLE IF EXISTS "#{tenant_key}"."spatial_ref_sys" CASCADE)
|
|
62
|
+
)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def tenant_schema_ready?(tenant_key)
|
|
66
|
+
connection = ActiveRecord::Base.connection
|
|
67
|
+
return false unless connection.schema_exists?(tenant_key.to_s)
|
|
68
|
+
|
|
69
|
+
connection.select_value(<<~SQL.squish).to_i.positive?
|
|
70
|
+
SELECT COUNT(*)
|
|
71
|
+
FROM information_schema.tables
|
|
72
|
+
WHERE table_schema = #{connection.quote(tenant_key.to_s)}
|
|
73
|
+
SQL
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def drop_tenant_schema_if_present!(tenant_key)
|
|
77
|
+
connection = ActiveRecord::Base.connection
|
|
78
|
+
return unless connection.schema_exists?(tenant_key.to_s)
|
|
79
|
+
|
|
80
|
+
connection.execute(%(DROP SCHEMA "#{tenant_key}" CASCADE))
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
# Something went wrong, drop the tenant
|
|
84
|
+
# We must handle this manually, because we can't create new schema in a transaction
|
|
85
|
+
def rollback_tenant!(tenant_key)
|
|
86
|
+
::Apartment::Tenant.switch("public") do
|
|
87
|
+
match = ::Decidim::Apartment::DistributionKey.find_by(key: tenant_key)
|
|
88
|
+
match.destroy if match
|
|
89
|
+
drop_tenant_schema_if_present!(tenant_key)
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
end
|