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.
Files changed (202) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE-AGPLv3.txt +661 -0
  3. data/README.md +167 -0
  4. data/Rakefile +405 -0
  5. data/app/commands/decidim/apartment/create_tenant_command.rb +94 -0
  6. data/app/commands/decidim/apartment/noop_settings_tab_command.rb +13 -0
  7. data/app/commands/decidim/apartment/performance/create_seed_tentant.rb +194 -0
  8. data/app/controllers/decidim/apartment/tenants_controller.rb +29 -0
  9. data/app/forms/decidim/apartment/admin/organization_settings_form.rb +44 -0
  10. data/app/forms/decidim/apartment/tenant_form.rb +35 -0
  11. data/app/helpers/decidim/apartment/dashboard_helper.rb +17 -0
  12. data/app/models/decidim/apartment/distribution_host.rb +21 -0
  13. data/app/models/decidim/apartment/distribution_key.rb +91 -0
  14. data/app/overrides/apartment_edit_organization.rb +21 -0
  15. data/app/overrides/apartment_system_asset.rb +10 -0
  16. data/app/packs/entrypoints/apartment_system_styles.scss +1 -0
  17. data/app/packs/stylesheets/decidim/apartment/system/_apartment_system_styles.scss +95 -0
  18. data/app/services/active_storage/service/apartment_disk_storage_service.rb +14 -0
  19. data/app/services/active_storage/service/apartment_s3_storage_service.rb +24 -0
  20. data/app/views/decidim/apartment/dashboard/_apartment.html.erb +55 -0
  21. data/app/views/decidim/apartment/dashboard/show.html.erb +3 -0
  22. data/app/views/decidim/apartment/organizations/_organizations_list.html.erb +45 -0
  23. data/app/views/decidim/apartment/organizations/index.html.erb +9 -0
  24. data/app/views/decidim/apartment/organizations/new.html.erb +11 -0
  25. data/config/assets.rb +15 -0
  26. data/config/locales/decidim_apartment.en.yml +58 -0
  27. data/config/locales/decidim_apartment_toggle.en.yml +15 -0
  28. data/db/migrate/20250814075441_add_apartment_distribution_key.rb +15 -0
  29. data/db/migrate/20260907100000_add_apartment_distribution_hosts.rb +32 -0
  30. data/lib/decidim/apartment/active_storage_wrap.rb +51 -0
  31. data/lib/decidim/apartment/allowed_hosts.rb +78 -0
  32. data/lib/decidim/apartment/cache_namespace.rb +38 -0
  33. data/lib/decidim/apartment/config_registry.rb +102 -0
  34. data/lib/decidim/apartment/configuration.rb +11 -0
  35. data/lib/decidim/apartment/convert/attachment_integrity.rb +130 -0
  36. data/lib/decidim/apartment/convert/constraint_graph_pruner.rb +183 -0
  37. data/lib/decidim/apartment/convert/errors.rb +9 -0
  38. data/lib/decidim/apartment/convert/host_gate.rb +76 -0
  39. data/lib/decidim/apartment/convert/org_distribution_report.rb +106 -0
  40. data/lib/decidim/apartment/convert/org_metrics.rb +164 -0
  41. data/lib/decidim/apartment/convert/organization_converter.rb +154 -0
  42. data/lib/decidim/apartment/convert/organization_pruner.rb +210 -0
  43. data/lib/decidim/apartment/convert/organization_resolver.rb +386 -0
  44. data/lib/decidim/apartment/convert/paper_trail_report.rb +127 -0
  45. data/lib/decidim/apartment/convert/preflight.rb +140 -0
  46. data/lib/decidim/apartment/convert/schema_cloner.rb +157 -0
  47. data/lib/decidim/apartment/convert/storage_preconditions.rb +43 -0
  48. data/lib/decidim/apartment/convert/storage_relocator.rb +118 -0
  49. data/lib/decidim/apartment/convert/table_registry.rb +109 -0
  50. data/lib/decidim/apartment/convert.rb +20 -0
  51. data/lib/decidim/apartment/demo/blob.rb +31 -0
  52. data/lib/decidim/apartment/demo/city.rb +107 -0
  53. data/lib/decidim/apartment/demo/education.rb +83 -0
  54. data/lib/decidim/apartment/demo/foss.rb +153 -0
  55. data/lib/decidim/apartment/demo/homepage.rb +39 -0
  56. data/lib/decidim/apartment/demo/localized.rb +27 -0
  57. data/lib/decidim/apartment/demo/provision.rb +107 -0
  58. data/lib/decidim/apartment/demo/runner.rb +66 -0
  59. data/lib/decidim/apartment/demo/system_admin.rb +24 -0
  60. data/lib/decidim/apartment/demo.rb +19 -0
  61. data/lib/decidim/apartment/elevator.rb +20 -0
  62. data/lib/decidim/apartment/engine.rb +140 -0
  63. data/lib/decidim/apartment/excluded_model_pin.rb +40 -0
  64. data/lib/decidim/apartment/host_registry.rb +71 -0
  65. data/lib/decidim/apartment/import/confirm_prompt.rb +46 -0
  66. data/lib/decidim/apartment/import/database_restorer.rb +105 -0
  67. data/lib/decidim/apartment/import/dump_host_extractor.rb +67 -0
  68. data/lib/decidim/apartment/import/dump_preview.rb +96 -0
  69. data/lib/decidim/apartment/import/dump_transformer.rb +87 -0
  70. data/lib/decidim/apartment/import/errors.rb +9 -0
  71. data/lib/decidim/apartment/import/provision_tenant.rb +50 -0
  72. data/lib/decidim/apartment/import/schema_auditor.rb +118 -0
  73. data/lib/decidim/apartment/import/storage_migrator.rb +71 -0
  74. data/lib/decidim/apartment/import/tenant_context.rb +226 -0
  75. data/lib/decidim/apartment/import/tenant_importer.rb +73 -0
  76. data/lib/decidim/apartment/import/verifier.rb +58 -0
  77. data/lib/decidim/apartment/import.rb +15 -0
  78. data/lib/decidim/apartment/ops/attribute_cryptor.rb +68 -0
  79. data/lib/decidim/apartment/ops/ciphertext_rewriter.rb +230 -0
  80. data/lib/decidim/apartment/ops/encrypted_attribute_catalog.rb +106 -0
  81. data/lib/decidim/apartment/ops/encrypted_attribute_registry.rb +74 -0
  82. data/lib/decidim/apartment/ops/postgres_permissions.rb +179 -0
  83. data/lib/decidim/apartment/ops/secret_key_preflight.rb +94 -0
  84. data/lib/decidim/apartment/ops/secret_key_rotation.rb +226 -0
  85. data/lib/decidim/apartment/ops/storage_transfer.rb +188 -0
  86. data/lib/decidim/apartment/overrides/active_job_with_tenant.rb +38 -0
  87. data/lib/decidim/apartment/overrides/core_seeds.rb +31 -0
  88. data/lib/decidim/apartment/overrides/create_organization_command.rb +69 -0
  89. data/lib/decidim/apartment/overrides/dashboard_controller.rb +30 -0
  90. data/lib/decidim/apartment/overrides/decidim_seed.rb +16 -0
  91. data/lib/decidim/apartment/overrides/organizations_controller_overrides.rb +75 -0
  92. data/lib/decidim/apartment/overrides/postgresql_enable_extension.rb +15 -0
  93. data/lib/decidim/apartment/overrides/postgresql_schema_adapter.rb +34 -0
  94. data/lib/decidim/apartment/overrides/postgresql_schema_import.rb +35 -0
  95. data/lib/decidim/apartment/overrides/postgresql_schema_search_path.rb +15 -0
  96. data/lib/decidim/apartment/overrides/postgresql_schema_statements.rb +17 -0
  97. data/lib/decidim/apartment/overrides/seeds.rb +52 -0
  98. data/lib/decidim/apartment/overrides/tenant_init_without_database.rb +19 -0
  99. data/lib/decidim/apartment/overrides/update_organization_command.rb +38 -0
  100. data/lib/decidim/apartment/postgres_extensions.rb +198 -0
  101. data/lib/decidim/apartment/rake_replace.rb +21 -0
  102. data/lib/decidim/apartment/schema_search_path.rb +43 -0
  103. data/lib/decidim/apartment/system_organization.rb +67 -0
  104. data/lib/decidim/apartment/test/factories.rb +11 -0
  105. data/lib/decidim/apartment/test/seeds/association_1.jpg +0 -0
  106. data/lib/decidim/apartment/test/seeds/association_2.jpeg +0 -0
  107. data/lib/decidim/apartment/test/seeds/association_3.jpg +0 -0
  108. data/lib/decidim/apartment/test/seeds/association_4.jpg +0 -0
  109. data/lib/decidim/apartment/test/seeds/bg_Dusty Grass.png +0 -0
  110. data/lib/decidim/apartment/test/seeds/bg_Hyper Blue.png +0 -0
  111. data/lib/decidim/apartment/test/seeds/bg_Moonwalker.png +0 -0
  112. data/lib/decidim/apartment/test/seeds/bg_Neon Green.png +0 -0
  113. data/lib/decidim/apartment/test/seeds/bg_Visual Blue.png +0 -0
  114. data/lib/decidim/apartment/test/seeds/bg_hinehouse.png +0 -0
  115. data/lib/decidim/apartment/test/seeds/city_1.jpg +0 -0
  116. data/lib/decidim/apartment/test/seeds/city_2.jpg +0 -0
  117. data/lib/decidim/apartment/test/seeds/city_3.jpg +0 -0
  118. data/lib/decidim/apartment/test/seeds/city_4.webp +0 -0
  119. data/lib/decidim/apartment/test/seeds/city_5.jpg +0 -0
  120. data/lib/decidim/apartment/test/seeds/debian.jpeg +0 -0
  121. data/lib/decidim/apartment/test/seeds/democratic_school_1.jpg +0 -0
  122. data/lib/decidim/apartment/test/seeds/drupal.jpg +0 -0
  123. data/lib/decidim/apartment/test/seeds/foss.jpg +0 -0
  124. data/lib/decidim/apartment/test/seeds/immich.jpg +0 -0
  125. data/lib/decidim/apartment/test/seeds/kid_1.jpg +0 -0
  126. data/lib/decidim/apartment/test/seeds/kid_2.jpg +0 -0
  127. data/lib/decidim/apartment/test/seeds/montessori_1.jpg +0 -0
  128. data/lib/decidim/apartment/test/seeds/montessori_2.jpg +0 -0
  129. data/lib/decidim/apartment/test/seeds/neighboor_1.jpg +0 -0
  130. data/lib/decidim/apartment/test/seeds/neighbor_2.jpg +0 -0
  131. data/lib/decidim/apartment/test/seeds/neighbor_3.jpg +0 -0
  132. 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
  133. 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
  134. 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
  135. 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
  136. 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
  137. 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
  138. 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
  139. data/lib/decidim/apartment/test/seeds/pattern_new_01.png +0 -0
  140. data/lib/decidim/apartment/test/seeds/pattern_new_02.png +0 -0
  141. data/lib/decidim/apartment/test/seeds/pattern_new_03.png +0 -0
  142. data/lib/decidim/apartment/test/seeds/pattern_squares_01.png +0 -0
  143. data/lib/decidim/apartment/test/seeds/pattern_squares_02.png +0 -0
  144. data/lib/decidim/apartment/test/seeds/pattern_squares_03.png +0 -0
  145. data/lib/decidim/apartment/test/seeds/pattern_squares_04.png +0 -0
  146. data/lib/decidim/apartment/test/seeds/pattern_squares_05.png +0 -0
  147. data/lib/decidim/apartment/test/seeds/pattern_squares_06.png +0 -0
  148. data/lib/decidim/apartment/test/seeds/pattern_squares_07.png +0 -0
  149. data/lib/decidim/apartment/test/seeds/pattern_squares_08.png +0 -0
  150. data/lib/decidim/apartment/test/seeds/pattern_squares_09.png +0 -0
  151. data/lib/decidim/apartment/test/seeds/pattern_squares_10.png +0 -0
  152. data/lib/decidim/apartment/test/seeds/pattern_squares_11.png +0 -0
  153. data/lib/decidim/apartment/test/seeds/pattern_squares_12.png +0 -0
  154. data/lib/decidim/apartment/test/seeds/pattern_squares_13.png +0 -0
  155. data/lib/decidim/apartment/test/seeds/pattern_squares_14.png +0 -0
  156. data/lib/decidim/apartment/test/seeds/pattern_squares_15.png +0 -0
  157. data/lib/decidim/apartment/test/seeds/pattern_squares_16.png +0 -0
  158. data/lib/decidim/apartment/test/seeds/pattern_squares_and_circles_01.png +0 -0
  159. data/lib/decidim/apartment/test/seeds/pattern_squares_and_circles_02.png +0 -0
  160. data/lib/decidim/apartment/test/seeds/pattern_squares_and_circles_03.png +0 -0
  161. data/lib/decidim/apartment/test/seeds/pattern_squares_and_circles_04.png +0 -0
  162. data/lib/decidim/apartment/test/seeds/pattern_squares_and_circles_05.png +0 -0
  163. data/lib/decidim/apartment/test/seeds/pattern_squares_and_circles_06.png +0 -0
  164. data/lib/decidim/apartment/test/seeds/pattern_squares_and_circles_07.png +0 -0
  165. data/lib/decidim/apartment/test/seeds/pattern_squares_and_circles_08.png +0 -0
  166. data/lib/decidim/apartment/test/seeds/pattern_squares_and_circles_09.png +0 -0
  167. data/lib/decidim/apartment/test/seeds/pattern_squares_and_circles_10.png +0 -0
  168. data/lib/decidim/apartment/test/seeds/pattern_squares_and_circles_11.png +0 -0
  169. data/lib/decidim/apartment/test/seeds/pattern_squares_and_circles_12.png +0 -0
  170. data/lib/decidim/apartment/test/seeds/pattern_squares_and_circles_13.png +0 -0
  171. data/lib/decidim/apartment/test/seeds/rails.jpg +0 -0
  172. data/lib/decidim/apartment/test/seeds/school_1.jpg +0 -0
  173. data/lib/decidim/apartment/test/seeds/school_3.jpg +0 -0
  174. data/lib/decidim/apartment/test/seeds/school_4.jpg +0 -0
  175. data/lib/decidim/apartment/test/seeds/school_5.jpg +0 -0
  176. data/lib/decidim/apartment/test/seeds/silverstripe.jpg +0 -0
  177. data/lib/decidim/apartment/test/seeds/street_1.jpg +0 -0
  178. data/lib/decidim/apartment/test/seeds/street_2.jpg +0 -0
  179. data/lib/decidim/apartment/test/seeds/street_3.jpg +0 -0
  180. data/lib/decidim/apartment/test/seeds/urban_agri_1.webp +0 -0
  181. data/lib/decidim/apartment/test/seeds/urban_agri_2.jpg +0 -0
  182. data/lib/decidim/apartment/test/seeds/urban_agri_3.jpg +0 -0
  183. data/lib/decidim/apartment/test/seeds/urban_agri_4.jpg +0 -0
  184. data/lib/decidim/apartment/test/seeds/world-map-colors.png +0 -0
  185. data/lib/decidim/apartment/version.rb +44 -0
  186. data/lib/decidim/apartment.rb +69 -0
  187. data/lib/tasks/decidim_apartment_check_install.rake +58 -0
  188. data/lib/tasks/decidim_apartment_convert.rake +60 -0
  189. data/lib/tasks/decidim_apartment_gem_manager.rake +62 -0
  190. data/lib/tasks/decidim_apartment_import.rake +39 -0
  191. data/lib/tasks/decidim_apartment_install_extension.rake +49 -0
  192. data/lib/tasks/decidim_apartment_performance_seed.rake +12 -0
  193. data/lib/tasks/decidim_apartment_rotate.rake +17 -0
  194. data/lib/tasks/decidim_apartment_storage.rake +27 -0
  195. data/lib/tasks/decidim_download_your_data_tasks.rake +121 -0
  196. data/lib/tasks/decidim_mailers.rake +38 -0
  197. data/lib/tasks/decidim_meetings.rake +30 -0
  198. data/lib/tasks/decidim_metrics_tasks.rake +29 -0
  199. data/lib/tasks/decidim_open_data_tasks.rake +24 -0
  200. data/lib/tasks/decidim_participatory_processes.rake +20 -0
  201. data/lib/tasks/decidim_reminders_tasks.rake +24 -0
  202. metadata +361 -0
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "import/errors"
4
+ require_relative "import/confirm_prompt"
5
+ require_relative "ops/postgres_permissions"
6
+ require_relative "convert/errors"
7
+ require_relative "convert/table_registry"
8
+ require_relative "convert/organization_resolver"
9
+ require_relative "convert/schema_cloner"
10
+ require_relative "convert/org_distribution_report"
11
+ require_relative "convert/org_metrics"
12
+ require_relative "convert/storage_preconditions"
13
+ require_relative "convert/storage_relocator"
14
+ require_relative "convert/host_gate"
15
+ require_relative "convert/paper_trail_report"
16
+ require_relative "convert/attachment_integrity"
17
+ require_relative "convert/constraint_graph_pruner"
18
+ require_relative "convert/organization_pruner"
19
+ require_relative "convert/preflight"
20
+ require_relative "convert/organization_converter"
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Apartment
5
+ module Demo
6
+ # Uploads CC images from lib/decidim/apartment/test/seeds.
7
+ # Prefer images ≤3840px on the longest side (Decidim ImageUploader limit).
8
+ module Blob
9
+ module_function
10
+
11
+ def upload!(filename)
12
+ path = File.join(Demo::SEEDS_ROOT, filename)
13
+ raise ArgumentError, "missing seed image: #{filename}" unless File.exist?(path)
14
+
15
+ ActiveStorage::Blob.create_and_upload!(
16
+ io: File.open(path),
17
+ filename: File.basename(filename),
18
+ content_type: content_type_for(filename),
19
+ metadata: nil
20
+ )
21
+ end
22
+
23
+ def content_type_for(filename)
24
+ ext = File.extname(filename).delete(".").downcase
25
+ { "jpg" => "image/jpeg", "jpeg" => "image/jpeg", "png" => "image/png",
26
+ "webp" => "image/webp" }[ext] || "application/octet-stream"
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,107 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Apartment
5
+ module Demo
6
+ # tenantA: EN city process group + two classical participatory processes.
7
+ class City
8
+ STEPS = [
9
+ { en: "Information" },
10
+ { en: "Diagnosis" },
11
+ { en: "Proposals" },
12
+ { en: "Voting" },
13
+ { en: "Feedback" }
14
+ ].freeze
15
+
16
+ def self.call(organization)
17
+ new(organization).call
18
+ end
19
+
20
+ def initialize(organization)
21
+ @organization = organization
22
+ @locales = organization.available_locales
23
+ end
24
+
25
+ def call
26
+ Homepage.hero_background!(@organization, "bg_Dusty Grass.png", welcome: Localized.text(@locales, en: "Welcome to Our city"))
27
+ Homepage.highlight!(@organization, :highlighted_processes, weight: 31)
28
+ group = create_group!
29
+ create_process!(group, "neighborhood-streets", "Neighborhood streets", "street_1.jpg")
30
+ create_process!(group, "urban-agriculture", "Urban agriculture", "urban_agri_3.jpg")
31
+ end
32
+
33
+ private
34
+
35
+ def create_group!
36
+ Decidim::ParticipatoryProcessGroup.create!(
37
+ title: Localized.text(@locales, en: "Our city"),
38
+ description: Localized.html(@locales, en: "Local participation for our neighborhoods."),
39
+ organization: @organization,
40
+ hero_image: Blob.upload!("city_1.jpg")
41
+ ).tap { |group| Decidim::ContentBlocksCreator.new(group).create_default! }
42
+ end
43
+
44
+ def create_process!(group, slug, title, image)
45
+ process = publish_process!(group, slug, title, image)
46
+ create_steps!(process)
47
+ light_components!(process)
48
+ Decidim::ContentBlocksCreator.new(process).create_default!
49
+ process
50
+ end
51
+
52
+ def publish_process!(group, slug, title, image)
53
+ params = process_params(group, slug, title, image)
54
+ Decidim.traceability.perform_action!(
55
+ "publish", Decidim::ParticipatoryProcess, admin_user, visibility: "all"
56
+ ) { Decidim::ParticipatoryProcess.create!(params) }.tap(&:add_to_index_as_search_resource)
57
+ end
58
+
59
+ def process_params(group, slug, title, image)
60
+ {
61
+ title: Localized.text(@locales, en: title),
62
+ slug:,
63
+ subtitle: Localized.text(@locales, en: title),
64
+ short_description: Localized.html(@locales, en: "#{title} short description"),
65
+ description: Localized.html(@locales, en: "#{title} full description"),
66
+ organization: @organization,
67
+ hero_image: Blob.upload!(image),
68
+ promoted: true,
69
+ published_at: 2.weeks.ago,
70
+ start_date: Date.current,
71
+ end_date: 2.months.from_now,
72
+ participatory_process_group: group
73
+ }
74
+ end
75
+
76
+ def create_steps!(process)
77
+ STEPS.each_with_index do |step, index|
78
+ Decidim::ParticipatoryProcessStep.create!(
79
+ title: Localized.text(@locales, **step),
80
+ description: Localized.html(@locales, en: "#{step[:en]} phase"),
81
+ participatory_process: process,
82
+ active: index.zero?,
83
+ position: index,
84
+ start_date: index.weeks.ago,
85
+ end_date: (index + 2).weeks.from_now
86
+ )
87
+ end
88
+ end
89
+
90
+ def light_components!(process)
91
+ %w(pages proposals).each do |manifest|
92
+ Decidim::Component.create!(
93
+ name: Localized.text(@locales, en: manifest.titleize),
94
+ manifest_name: manifest,
95
+ participatory_space: process,
96
+ published_at: Time.current
97
+ )
98
+ end
99
+ end
100
+
101
+ def admin_user
102
+ Decidim::User.find_by!(email: "admin@example.org", organization: @organization)
103
+ end
104
+ end
105
+ end
106
+ end
107
+ end
@@ -0,0 +1,83 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Apartment
5
+ module Demo
6
+ # tenantB: FR humanist education parent assembly + two children.
7
+ class Education
8
+ def self.call(organization)
9
+ new(organization).call
10
+ end
11
+
12
+ def initialize(organization)
13
+ @organization = organization
14
+ @locales = organization.available_locales
15
+ end
16
+
17
+ def call
18
+ Homepage.hero_background!(
19
+ @organization, "bg_Neon Green.png",
20
+ welcome: Localized.text(@locales, fr: "Bienvenue à Education Humaniste")
21
+ )
22
+ Homepage.highlight!(@organization, :highlighted_assemblies, weight: 32)
23
+ parent = create_assembly!(
24
+ slug: "education-humaniste",
25
+ title: "Education Humaniste",
26
+ hero: "school_1.jpg",
27
+ banner: "association_1.jpg"
28
+ )
29
+ create_assembly!(
30
+ slug: "ecoles-democratiques",
31
+ title: "Écoles démocratiques",
32
+ hero: "school_3.jpg",
33
+ banner: "association_2.jpeg",
34
+ parent:
35
+ )
36
+ create_assembly!(
37
+ slug: "montessori",
38
+ title: "Montessori",
39
+ hero: "montessori_1.jpg",
40
+ banner: "montessori_2.jpg",
41
+ parent:
42
+ )
43
+ end
44
+
45
+ private
46
+
47
+ def create_assembly!(slug:, title:, hero:, banner:, parent: nil)
48
+ assembly = publish_assembly!(slug, title, hero, banner, parent)
49
+ Decidim::ContentBlocksCreator.new(assembly).create_default!
50
+ assembly
51
+ end
52
+
53
+ def publish_assembly!(slug, title, hero, banner, parent)
54
+ params = assembly_params(slug, title, hero, banner, parent)
55
+ Decidim.traceability.perform_action!(
56
+ "publish", Decidim::Assembly, admin_user, visibility: "all"
57
+ ) { Decidim::Assembly.create!(params) }.tap(&:add_to_index_as_search_resource)
58
+ end
59
+
60
+ def assembly_params(slug, title, hero, banner, parent)
61
+ {
62
+ title: Localized.text(@locales, fr: title),
63
+ slug:,
64
+ subtitle: Localized.text(@locales, fr: title),
65
+ short_description: Localized.html(@locales, fr: "Présentation de #{title}"),
66
+ description: Localized.html(@locales, fr: "Description de #{title}"),
67
+ organization: @organization,
68
+ hero_image: Blob.upload!(hero),
69
+ banner_image: Blob.upload!(banner),
70
+ promoted: true,
71
+ published_at: 2.weeks.ago,
72
+ parent:,
73
+ is_transparent: true
74
+ }
75
+ end
76
+
77
+ def admin_user
78
+ Decidim::User.find_by!(email: "admin@example.org", organization: @organization)
79
+ end
80
+ end
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,153 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Apartment
5
+ module Demo
6
+ # tenantC: FR+EN FOSS conference with partners and ten software events.
7
+ class Foss
8
+ EVENTS = [
9
+ ["Debian", "debian.jpeg"],
10
+ ["Drupal", "drupal.jpg"],
11
+ ["Immich", "immich.jpg"],
12
+ ["Silverstripe", "silverstripe.jpg"],
13
+ ["Firefox", "foss.jpg"],
14
+ ["PostgreSQL", "pattern_diamonds-1_1_10_0-0_0_1__hsla(240, 7_, 18_, 1.00)_hsla(174, 100_, 29_, 1.00).png"],
15
+ ["Redis", "pattern_cubes-3_4_2_0-0_0_1__hsla(240, 7_, 18_, 1.00)_hsla(47, 81_, 61_, 1.00).png"],
16
+ ["Linux", "rails.jpg"],
17
+ ["GIMP", "bg_Hyper Blue.png"],
18
+ ["Nextcloud", "bg_Visual Blue.png"]
19
+ ].freeze
20
+
21
+ def self.call(organization)
22
+ new(organization).call
23
+ end
24
+
25
+ def initialize(organization)
26
+ @organization = organization
27
+ @locales = organization.available_locales
28
+ end
29
+
30
+ def call
31
+ return skip_conferences! unless conferences_available?
32
+
33
+ Homepage.hero_background!(
34
+ @organization, "bg_Moonwalker.png",
35
+ welcome: Localized.text(@locales, fr: "Logiciel libre", en: "Free and Open Source Software")
36
+ )
37
+ Homepage.highlight!(@organization, :highlighted_conferences, weight: 33)
38
+ conference = create_conference!
39
+ create_partners!(conference)
40
+ create_events!(conference)
41
+ end
42
+
43
+ private
44
+
45
+ def conferences_available?
46
+ return false unless Gem.loaded_specs.has_key?("decidim-conferences")
47
+
48
+ ActiveRecord::Base.connection.data_source_exists?("decidim_conferences")
49
+ end
50
+
51
+ def skip_conferences!
52
+ Rails.logger.info("[decidim-apartment] skip FOSS conference: decidim-conferences unavailable")
53
+ Homepage.hero_background!(
54
+ @organization, "bg_Moonwalker.png",
55
+ welcome: Localized.text(@locales, fr: "Logiciel libre", en: "Free and Open Source Software")
56
+ )
57
+ end
58
+
59
+ def create_conference!
60
+ params = conference_params
61
+ Decidim.traceability.perform_action!(
62
+ "publish", Decidim::Conference, admin_user, visibility: "all"
63
+ ) { Decidim::Conference.create!(params) }.tap(&:add_to_index_as_search_resource)
64
+ end
65
+
66
+ def conference_params
67
+ {
68
+ title: Localized.text(@locales, fr: "Conférence logiciel libre", en: "Free and Open Source Software"),
69
+ slogan: Localized.text(@locales, fr: "Communs numériques", en: "Digital commons"),
70
+ slug: "foss-conference",
71
+ short_description: Localized.html(@locales, fr: "Événement FOSS", en: "FOSS conference"),
72
+ description: Localized.html(@locales, fr: "Rencontres autour du libre", en: "Meetups around free software"),
73
+ objectives: Localized.html(@locales, fr: "Partager le libre", en: "Share free software"),
74
+ organization: @organization,
75
+ hero_image: Blob.upload!("foss.jpg"),
76
+ banner_image: Blob.upload!("world-map-colors.png"),
77
+ promoted: true,
78
+ published_at: 2.weeks.ago,
79
+ start_date: Date.current,
80
+ end_date: 2.months.from_now
81
+ }
82
+ end
83
+
84
+ def create_partners!(conference)
85
+ create_partner!(conference, "Mozilla", "main_promotor", "bg_hinehouse.png")
86
+ create_partner!(conference, "Open Source Foundation", "collaborator", "bg_Neon Green.png")
87
+ end
88
+
89
+ def create_partner!(conference, name, partner_type, logo)
90
+ Decidim::Conferences::Partner.create!(
91
+ name:,
92
+ weight: 1,
93
+ link: "https://example.org/#{name.parameterize}",
94
+ partner_type:,
95
+ conference:,
96
+ logo: Blob.upload!(logo)
97
+ )
98
+ end
99
+
100
+ def create_events!(conference)
101
+ component = meetings_component!(conference)
102
+ EVENTS.each_with_index { |(software, image), index| create_meeting!(component, software, image, index) }
103
+ end
104
+
105
+ def meetings_component!(conference)
106
+ Decidim::Component.create!(
107
+ name: Localized.text(@locales, fr: "Événements", en: "Events"),
108
+ manifest_name: "meetings",
109
+ participatory_space: conference,
110
+ published_at: Time.current
111
+ )
112
+ end
113
+
114
+ def create_meeting!(component, software, image, index)
115
+ meeting_class.create!(
116
+ component:,
117
+ title: Localized.text(@locales, fr: "Atelier #{software}", en: "#{software} workshop"),
118
+ description: Localized.html(@locales, fr: "Découvrir #{software}", en: "Discover #{software}"),
119
+ location: Localized.text(@locales, fr: "En ligne", en: "Online"),
120
+ location_hints: Localized.text(@locales, fr: "Visio", en: "Video call"),
121
+ start_time: (index + 1).days.from_now.change(hour: 10),
122
+ end_time: (index + 1).days.from_now.change(hour: 12),
123
+ address: "Online",
124
+ published_at: Time.current,
125
+ author: admin_user,
126
+ registration_type: "registration_disabled"
127
+ ).tap { |meeting| attach_photo!(meeting, image) }
128
+ end
129
+
130
+ def meeting_class
131
+ return Decidim::ConferenceMeeting if Gem.loaded_specs.has_key?("decidim-conferences")
132
+
133
+ Decidim::Meetings::Meeting
134
+ end
135
+
136
+ def attach_photo!(meeting, image)
137
+ return unless meeting.respond_to?(:attachments)
138
+
139
+ Decidim::Attachment.create!(
140
+ title: Localized.text(@locales, en: File.basename(image), fr: File.basename(image)),
141
+ attached_to: meeting,
142
+ content_type: Blob.content_type_for(image),
143
+ file: Blob.upload!(image)
144
+ )
145
+ end
146
+
147
+ def admin_user
148
+ Decidim::User.find_by!(email: "admin@example.org", organization: @organization)
149
+ end
150
+ end
151
+ end
152
+ end
153
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Apartment
5
+ module Demo
6
+ # Homepage content blocks for participatory spaces.
7
+ module Homepage
8
+ module_function
9
+
10
+ def highlight!(organization, manifest_name, weight:)
11
+ Decidim::ContentBlock.find_or_create_by!(
12
+ organization:,
13
+ scope_name: :homepage,
14
+ manifest_name:
15
+ ) do |block|
16
+ block.weight = weight
17
+ block.published_at = Time.current
18
+ end
19
+ end
20
+
21
+ def hero_background!(organization, filename, welcome:)
22
+ block = Decidim::ContentBlock.find_by(organization:, manifest_name: :hero, scope_name: :homepage)
23
+ return unless block
24
+
25
+ block.images_container.background_image = Blob.upload!(filename)
26
+ apply_welcome!(block, welcome)
27
+ block.save!
28
+ end
29
+
30
+ def apply_welcome!(block, welcome)
31
+ settings = welcome.transform_keys do |locale|
32
+ "welcome_text_#{locale}"
33
+ end
34
+ block.settings = settings
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Apartment
5
+ module Demo
6
+ # Builds locale hashes limited to the organization locales.
7
+ module Localized
8
+ module_function
9
+
10
+ def text(locales, en: nil, fr: nil)
11
+ values = { "en" => en, "fr" => fr }.compact
12
+ Array(locales).index_with { |locale| values[locale.to_s] || values.values.first }
13
+ end
14
+
15
+ def html(locales, en: nil, fr: nil)
16
+ text(locales, en: wrap(en), fr: wrap(fr))
17
+ end
18
+
19
+ def wrap(value)
20
+ return if value.blank?
21
+
22
+ "<p>#{value}</p>"
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,107 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Apartment
5
+ module Demo
6
+ # Creates an Apartment tenant + Decidim organization for a demo host.
7
+ class Provision
8
+ ADMIN_PASSWORD = "decidim123456789"
9
+
10
+ def self.call(**)
11
+ new(**).call
12
+ end
13
+
14
+ def initialize(host:, name:, locales:, default_locale:)
15
+ @host = host.to_s.downcase
16
+ @name = name
17
+ @locales = filter_locales(locales)
18
+ @default_locale = pick_default(default_locale)
19
+ end
20
+
21
+ def call
22
+ create_organization!
23
+ finalize_organization!
24
+ end
25
+
26
+ private
27
+
28
+ def filter_locales(locales)
29
+ available = Decidim.available_locales.map(&:to_s)
30
+ selected = Array(locales).map(&:to_s) & available
31
+ selected.presence || available.first(1)
32
+ end
33
+
34
+ def pick_default(default_locale)
35
+ locale = default_locale.to_s
36
+ return locale if @locales.include?(locale)
37
+
38
+ @locales.first
39
+ end
40
+
41
+ def create_organization!
42
+ host = @host
43
+ form = Decidim::System::RegisterOrganizationForm.new(form_params)
44
+ raise "invalid org form: #{form.errors.full_messages}" unless form.valid?
45
+
46
+ ok = false
47
+ Decidim::System::CreateOrganization.call(form) do
48
+ on(:ok) { ok = true }
49
+ on(:invalid) { raise "CreateOrganization invalid for #{host}: #{form.errors.full_messages}" }
50
+ end
51
+ raise "CreateOrganization failed for #{host}" unless ok
52
+ end
53
+
54
+ def form_params
55
+ {
56
+ name: @name,
57
+ host: @host,
58
+ available_locales: @locales,
59
+ default_locale: @default_locale,
60
+ reference_prefix: @name.parameterize.upcase[0, 8],
61
+ organization_admin_email: "admin@example.org",
62
+ organization_admin_name: "Demo Admin",
63
+ users_registration_mode: "enabled",
64
+ force_users_to_authenticate_before_access_organization: "false",
65
+ file_upload_settings: upload_settings
66
+ }.merge(short_name_param)
67
+ end
68
+
69
+ def short_name_param
70
+ return {} unless Gem.loaded_specs["decidim-core"].version >= Gem::Version.new("0.31")
71
+
72
+ { short_name: @name.to_s[0, 12] }
73
+ end
74
+
75
+ def upload_settings
76
+ Decidim::OrganizationSettings.default(:upload).transform_values do |value|
77
+ value.is_a?(Array) ? value.join(",") : value
78
+ end
79
+ end
80
+
81
+ def finalize_organization!
82
+ key = Decidim::Apartment::DistributionKey.for_host(@host)
83
+ key.switch { polish!(Decidim::Organization.first) }
84
+ key.organization
85
+ end
86
+
87
+ def polish!(organization)
88
+ organization.update!(file_upload_settings: Decidim::OrganizationSettings.default(:upload))
89
+ admin = Decidim::User.find_by!(email: "admin@example.org", organization:)
90
+ admin.skip_confirmation!
91
+ accept_demo_admin!(admin)
92
+ end
93
+
94
+ def accept_demo_admin!(admin)
95
+ admin.update!(
96
+ password: ADMIN_PASSWORD,
97
+ password_confirmation: ADMIN_PASSWORD,
98
+ admin_terms_accepted_at: Time.current,
99
+ invitation_accepted_at: Time.current,
100
+ invitation_token: nil,
101
+ nickname: "demo_admin"
102
+ )
103
+ end
104
+ end
105
+ end
106
+ end
107
+ end
@@ -0,0 +1,66 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Apartment
5
+ module Demo
6
+ # Orchestrates curated demo tenants instead of vanilla Decidim faker seeds.
7
+ class Runner
8
+ TENANTS = [
9
+ { host: "tenanta.localhost", name: "Our city", locales: %w(en), default_locale: "en", catalog: :city },
10
+ { host: "tenantb.localhost", name: "Education Humaniste", locales: %w(fr), default_locale: "fr", catalog: :education },
11
+ { host: "tenantc.localhost", name: "FOSS Conference", locales: %w(fr en), default_locale: "fr", catalog: :foss }
12
+ ].freeze
13
+
14
+ def self.call
15
+ new.call
16
+ end
17
+
18
+ def call
19
+ with_inline_jobs { seed_tenants }
20
+ end
21
+
22
+ private
23
+
24
+ def seed_tenants
25
+ ensure_locales!
26
+ SystemAdmin.ensure!
27
+ TENANTS.each { |tenant| seed_tenant!(tenant) }
28
+ end
29
+
30
+ def with_inline_jobs
31
+ previous = ActiveJob::Base.queue_adapter
32
+ ActiveJob::Base.queue_adapter = :inline
33
+ yield
34
+ ensure
35
+ ActiveJob::Base.queue_adapter = previous
36
+ end
37
+
38
+ def ensure_locales!
39
+ needed = [:en, :fr]
40
+ I18n.available_locales = (I18n.available_locales.map(&:to_sym) | needed).uniq
41
+ end
42
+
43
+ def seed_tenant!(tenant)
44
+ return if already_seeded?(tenant[:host])
45
+
46
+ organization = Provision.call(**tenant.slice(:host, :name, :locales, :default_locale))
47
+ key = Decidim::Apartment::DistributionKey.for_host(tenant[:host])
48
+ key.switch { catalog_for(tenant[:catalog]).call(organization) }
49
+ end
50
+
51
+ def already_seeded?(host)
52
+ key = Decidim::Apartment::DistributionKey.for_host(host)
53
+ return false unless key
54
+
55
+ key.organization?
56
+ rescue ActiveRecord::StatementInvalid
57
+ false
58
+ end
59
+
60
+ def catalog_for(name)
61
+ { city: City, education: Education, foss: Foss }.fetch(name)
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Apartment
5
+ module Demo
6
+ # Ensures the Decidim system admin exists (same as decidim-system seeds).
7
+ module SystemAdmin
8
+ module_function
9
+
10
+ def ensure!
11
+ ::Apartment::Tenant.switch("public") { upsert! }
12
+ end
13
+
14
+ def upsert!
15
+ password = ENV.fetch("DECIDIM_SYSTEM_USER_PASSWORD", "decidim123456789")
16
+ admin = Decidim::System::Admin.find_or_initialize_by(email: "system@example.org")
17
+ admin.password = password
18
+ admin.password_confirmation = password
19
+ admin.save!
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "demo/blob"
4
+ require_relative "demo/localized"
5
+ require_relative "demo/provision"
6
+ require_relative "demo/system_admin"
7
+ require_relative "demo/homepage"
8
+ require_relative "demo/city"
9
+ require_relative "demo/education"
10
+ require_relative "demo/foss"
11
+ require_relative "demo/runner"
12
+
13
+ module Decidim
14
+ module Apartment
15
+ module Demo
16
+ SEEDS_ROOT = File.expand_path("test/seeds", __dir__).freeze
17
+ end
18
+ end
19
+ end