decidim-assemblies 0.29.1 → 0.30.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (141) hide show
  1. checksums.yaml +4 -4
  2. data/app/cells/decidim/assemblies/assembly_metadata_g_cell.rb +1 -14
  3. data/app/cells/decidim/assemblies/content_blocks/extra_data_cell.rb +2 -12
  4. data/app/cells/decidim/assemblies/content_blocks/highlighted_assemblies_settings_form/show.erb +1 -1
  5. data/app/commands/decidim/assemblies/admin/copy_assembly.rb +2 -14
  6. data/app/commands/decidim/assemblies/admin/create_assembly.rb +2 -2
  7. data/app/commands/decidim/assemblies/admin/import_assembly.rb +0 -2
  8. data/app/commands/decidim/assemblies/admin/update_assembly.rb +2 -2
  9. data/app/controllers/concerns/decidim/assemblies/admin/filterable.rb +2 -11
  10. data/app/controllers/decidim/assemblies/admin/assemblies_controller.rb +19 -4
  11. data/app/controllers/decidim/assemblies/admin/assembly_copies_controller.rb +1 -1
  12. data/app/controllers/decidim/assemblies/admin/assembly_landing_page_content_blocks_controller.rb +6 -0
  13. data/app/controllers/decidim/assemblies/admin/assembly_share_tokens_controller.rb +18 -0
  14. data/app/controllers/decidim/assemblies/admin/component_share_tokens_controller.rb +18 -0
  15. data/app/controllers/decidim/assemblies/assemblies_controller.rb +1 -3
  16. data/app/controllers/decidim/assemblies/{assembly_members_controller.rb → participatory_space_private_users_controller.rb} +3 -11
  17. data/app/forms/decidim/assemblies/admin/assembly_copy_form.rb +0 -1
  18. data/app/forms/decidim/assemblies/admin/assembly_form.rb +13 -48
  19. data/app/forms/decidim/assemblies/admin/assembly_import_form.rb +0 -1
  20. data/app/helpers/decidim/assemblies/admin/assemblies_helper.rb +26 -4
  21. data/app/helpers/decidim/assemblies/assemblies_helper.rb +4 -4
  22. data/app/helpers/decidim/assemblies/filter_assemblies_helper.rb +11 -15
  23. data/app/models/decidim/assembly.rb +26 -11
  24. data/app/packs/entrypoints/decidim_assemblies_admin.js +0 -1
  25. data/app/packs/entrypoints/decidim_assemblies_admin_list.js +1 -0
  26. data/app/packs/src/decidim/assemblies/admin/assemblies_list.js +72 -0
  27. data/app/permissions/decidim/assemblies/permissions.rb +9 -20
  28. data/app/presenters/decidim/assemblies/admin_log/assembly_presenter.rb +1 -1
  29. data/app/presenters/decidim/assemblies/assembly_presenter.rb +2 -8
  30. data/app/queries/decidim/assemblies/metrics/assemblies_metric_manage.rb +2 -2
  31. data/app/serializers/decidim/assemblies/assembly_importer.rb +0 -35
  32. data/app/serializers/decidim/assemblies/assembly_serializer.rb +11 -135
  33. data/app/serializers/decidim/assemblies/open_data_assembly_serializer.rb +59 -0
  34. data/app/views/decidim/assemblies/admin/assemblies/_assemblies_thead.html.erb +19 -0
  35. data/app/views/decidim/assemblies/admin/assemblies/_assembly_row.html.erb +101 -0
  36. data/app/views/decidim/assemblies/admin/assemblies/_form.html.erb +29 -41
  37. data/app/views/decidim/assemblies/admin/assemblies/index.html.erb +18 -92
  38. data/app/views/decidim/assemblies/admin/assemblies/index.js.erb +10 -0
  39. data/app/views/decidim/assemblies/admin/assemblies/manage_trash.html.erb +20 -0
  40. data/app/views/decidim/assemblies/admin/assembly_copies/_form.html.erb +0 -4
  41. data/app/views/decidim/assemblies/admin/assembly_imports/_form.html.erb +0 -3
  42. data/app/views/decidim/assemblies/assemblies/index.html.erb +3 -1
  43. data/app/views/decidim/assemblies/assemblies/show.html.erb +5 -6
  44. data/app/views/decidim/assemblies/{assembly_members → participatory_space_private_users}/index.html.erb +6 -5
  45. data/config/assets.rb +2 -1
  46. data/config/locales/ar.yml +1 -72
  47. data/config/locales/bg.yml +0 -74
  48. data/config/locales/bn-BD.yml +1 -0
  49. data/config/locales/bs-BA.yml +29 -0
  50. data/config/locales/ca.yml +70 -74
  51. data/config/locales/cs.yml +70 -74
  52. data/config/locales/de.yml +72 -76
  53. data/config/locales/el.yml +0 -72
  54. data/config/locales/en.yml +71 -75
  55. data/config/locales/es-MX.yml +70 -74
  56. data/config/locales/es-PY.yml +70 -74
  57. data/config/locales/es.yml +70 -74
  58. data/config/locales/eu.yml +108 -112
  59. data/config/locales/fi-plain.yml +71 -75
  60. data/config/locales/fi.yml +75 -79
  61. data/config/locales/fr-CA.yml +22 -74
  62. data/config/locales/fr.yml +22 -74
  63. data/config/locales/ga-IE.yml +0 -23
  64. data/config/locales/gl.yml +0 -70
  65. data/config/locales/he-IL.yml +143 -23
  66. data/config/locales/hu.yml +0 -74
  67. data/config/locales/id-ID.yml +0 -58
  68. data/config/locales/is-IS.yml +0 -45
  69. data/config/locales/it.yml +0 -71
  70. data/config/locales/ja.yml +70 -74
  71. data/config/locales/kaa.yml +0 -9
  72. data/config/locales/ko.yml +0 -13
  73. data/config/locales/lb.yml +0 -66
  74. data/config/locales/lt.yml +0 -72
  75. data/config/locales/lv.yml +0 -69
  76. data/config/locales/nl.yml +0 -70
  77. data/config/locales/no.yml +0 -70
  78. data/config/locales/pl.yml +0 -75
  79. data/config/locales/pt-BR.yml +0 -74
  80. data/config/locales/pt.yml +0 -70
  81. data/config/locales/ro-RO.yml +5 -72
  82. data/config/locales/ru.yml +0 -57
  83. data/config/locales/sk.yml +0 -28
  84. data/config/locales/sl.yml +0 -39
  85. data/config/locales/sq-AL.yml +0 -74
  86. data/config/locales/sr-CS.yml +0 -15
  87. data/config/locales/sv.yml +75 -79
  88. data/config/locales/tr-TR.yml +0 -75
  89. data/config/locales/uk.yml +0 -57
  90. data/config/locales/zh-CN.yml +0 -69
  91. data/config/locales/zh-TW.yml +0 -72
  92. data/db/migrate/20190215093700_reset_negative_children_count_counters.rb +2 -2
  93. data/db/migrate/20210310120444_add_followable_counter_cache_to_assemblies.rb +1 -1
  94. data/db/migrate/20240822161222_add_deleted_at_to_decidim_assemblies.rb +8 -0
  95. data/db/migrate/20241016101151_migrate_assembly_members_to_private_users.rb +53 -0
  96. data/db/migrate/20241108141651_remove_column_show_statistics_from_assemblies.rb +7 -0
  97. data/decidim-assemblies.gemspec +2 -2
  98. data/lib/decidim/api/assemblies_type_type.rb +2 -2
  99. data/lib/decidim/api/assembly_type.rb +32 -34
  100. data/lib/decidim/assemblies/admin_engine.rb +77 -54
  101. data/lib/decidim/assemblies/api.rb +0 -1
  102. data/lib/decidim/assemblies/content_blocks/registry_manager.rb +11 -0
  103. data/lib/decidim/assemblies/engine.rb +9 -3
  104. data/lib/decidim/assemblies/menu.rb +9 -22
  105. data/lib/decidim/assemblies/participatory_space.rb +7 -3
  106. data/lib/decidim/assemblies/seeds.rb +9 -33
  107. data/lib/decidim/assemblies/test/factories.rb +15 -36
  108. data/lib/decidim/assemblies/version.rb +1 -1
  109. metadata +31 -49
  110. data/app/cells/decidim/assemblies/assembly_member/data.erb +0 -19
  111. data/app/cells/decidim/assemblies/assembly_member/name_and_position.erb +0 -11
  112. data/app/cells/decidim/assemblies/assembly_member/show.erb +0 -9
  113. data/app/cells/decidim/assemblies/assembly_member_cell.rb +0 -21
  114. data/app/commands/decidim/assemblies/admin/create_assembly_member.rb +0 -55
  115. data/app/commands/decidim/assemblies/admin/destroy_assembly_member.rb +0 -24
  116. data/app/commands/decidim/assemblies/admin/update_assembly_member.rb +0 -29
  117. data/app/controllers/concerns/decidim/assemblies/admin/assembly_members/filterable.rb +0 -39
  118. data/app/controllers/decidim/assemblies/admin/assemblies_types_controller.rb +0 -107
  119. data/app/controllers/decidim/assemblies/admin/assembly_members_controller.rb +0 -83
  120. data/app/controllers/decidim/assemblies/admin/categories_controller.rb +0 -13
  121. data/app/events/decidim/assemblies/create_assembly_member_event.rb +0 -17
  122. data/app/forms/decidim/assemblies/admin/assembly_member_form.rb +0 -64
  123. data/app/helpers/decidim/assemblies/admin/assembly_members_helper.rb +0 -11
  124. data/app/models/decidim/assembly_member.rb +0 -34
  125. data/app/packs/src/decidim/assemblies/admin/assembly_members.js +0 -47
  126. data/app/packs/src/decidim/assemblies/orgchart.js +0 -0
  127. data/app/presenters/decidim/admin/assembly_member_presenter.rb +0 -24
  128. data/app/presenters/decidim/assemblies/admin_log/assembly_member_presenter.rb +0 -51
  129. data/app/presenters/decidim/assemblies/admin_log/value_types/member_position_presenter.rb +0 -22
  130. data/app/presenters/decidim/assembly_member_presenter.rb +0 -68
  131. data/app/views/decidim/assemblies/admin/assemblies_types/_form.html.erb +0 -9
  132. data/app/views/decidim/assemblies/admin/assemblies_types/edit.html.erb +0 -13
  133. data/app/views/decidim/assemblies/admin/assemblies_types/index.html.erb +0 -44
  134. data/app/views/decidim/assemblies/admin/assemblies_types/new.html.erb +0 -18
  135. data/app/views/decidim/assemblies/admin/assembly_members/_form.html.erb +0 -62
  136. data/app/views/decidim/assemblies/admin/assembly_members/edit.html.erb +0 -18
  137. data/app/views/decidim/assemblies/admin/assembly_members/index.html.erb +0 -55
  138. data/app/views/decidim/assemblies/admin/assembly_members/new.html.erb +0 -18
  139. data/app/views/decidim/assembly_members/_assembly_member.html.erb +0 -1
  140. data/app/views/layouts/decidim/admin/assemblies_types.html.erb +0 -17
  141. data/lib/decidim/api/assembly_member_type.rb +0 -27
@@ -24,6 +24,7 @@ module Decidim
24
24
  include Decidim::HasAttachmentCollections
25
25
  include Decidim::Participable
26
26
  include Decidim::Publicable
27
+ include Decidim::Taxonomizable
27
28
  include Decidim::ScopableParticipatorySpace
28
29
  include Decidim::Followable
29
30
  include Decidim::HasReference
@@ -36,6 +37,8 @@ module Decidim
36
37
  include Decidim::TranslatableResource
37
38
  include Decidim::HasArea
38
39
  include Decidim::FilterableResource
40
+ include Decidim::SoftDeletable
41
+ include Decidim::ShareableWithToken
39
42
 
40
43
  CREATED_BY = %w(city_council public others).freeze
41
44
 
@@ -60,11 +63,6 @@ module Decidim
60
63
  dependent: :destroy,
61
64
  as: :participatory_space
62
65
 
63
- has_many :members,
64
- foreign_key: "decidim_assembly_id",
65
- class_name: "Decidim::AssemblyMember",
66
- dependent: :destroy
67
-
68
66
  has_many :components, as: :participatory_space, dependent: :destroy
69
67
 
70
68
  has_many :children, foreign_key: "parent_id", class_name: "Decidim::Assembly", inverse_of: :parent, dependent: :destroy
@@ -82,8 +80,6 @@ module Decidim
82
80
  after_create :set_parents_path
83
81
  after_update :set_parents_path, :update_children_paths, if: :saved_change_to_parent_id?
84
82
 
85
- scope :with_any_type, ->(*type_ids) { where(decidim_assemblies_type_id: type_ids) }
86
-
87
83
  searchable_fields({
88
84
  scope_id: :decidim_scope_id,
89
85
  participatory_space: :itself,
@@ -122,6 +118,11 @@ module Decidim
122
118
  Decidim::Assemblies::AdminLog::AssemblyPresenter
123
119
  end
124
120
 
121
+ # This is a overwrite for Decidim::ParticipatorySpaceResourceable.visible?
122
+ def visible?
123
+ published? && (!private_space? || (private_space? && is_transparent?))
124
+ end
125
+
125
126
  def hashtag
126
127
  attributes["hashtag"].to_s.delete("#")
127
128
  end
@@ -160,7 +161,23 @@ module Decidim
160
161
  end
161
162
 
162
163
  def self.ransackable_scopes(_auth_object = nil)
163
- [:with_any_area, :with_any_scope, :with_any_type]
164
+ [:with_any_taxonomies]
165
+ end
166
+
167
+ def shareable_url(share_token)
168
+ EngineRouter.main_proxy(self).assembly_url(self, share_token: share_token.token)
169
+ end
170
+
171
+ def self.ransackable_attributes(auth_object = nil)
172
+ base = %w(title short_description description id)
173
+
174
+ return base unless auth_object&.admin?
175
+
176
+ base + %w(published_at private_space parent_id)
177
+ end
178
+
179
+ def self.ransackable_associations(_auth_object = nil)
180
+ %w(parent children taxonomies)
164
181
  end
165
182
 
166
183
  private
@@ -181,7 +198,7 @@ module Decidim
181
198
  #
182
199
  # rubocop:disable Rails/SkipsModelValidations
183
200
  def set_parents_path
184
- update_column(:parents_path, [parent&.parents_path, id].select(&:present?).join("."))
201
+ update_column(:parents_path, [parent&.parents_path, id].compact_blank.join("."))
185
202
  end
186
203
  # rubocop:enable Rails/SkipsModelValidations
187
204
 
@@ -216,7 +233,5 @@ module Decidim
216
233
 
217
234
  # Allow ransacker to search for a key in a hstore column (`title`.`en`)
218
235
  ransacker_i18n :title
219
-
220
- ransack_alias :type_id, :decidim_assemblies_type_id
221
236
  end
222
237
  end
@@ -1,3 +1,2 @@
1
1
  import "src/decidim/assemblies/admin/assemblies"
2
- import "src/decidim/assemblies/admin/assembly_members"
3
2
  import "src/decidim/slug_form"
@@ -0,0 +1 @@
1
+ import "src/decidim/assemblies/admin/assemblies_list"
@@ -0,0 +1,72 @@
1
+ /* eslint-disable require-jsdoc */
2
+
3
+ class AdminAssembliesListComponent {
4
+ run() {
5
+ this.rebindArrows();
6
+ }
7
+
8
+ rebindArrows() {
9
+ this.unbindArrows();
10
+ this.bindArrows();
11
+ }
12
+
13
+ bindArrows() {
14
+ document.querySelectorAll("[data-arrow-up]").forEach((element) => {
15
+ element.addEventListener("click", this._onClickUpArrow);
16
+ });
17
+ document.querySelectorAll("[data-arrow-down]").forEach((element) => {
18
+ element.addEventListener("click", this._onClickDownArrow);
19
+ });
20
+ }
21
+
22
+ unbindArrows() {
23
+ document.querySelectorAll("[data-arrow-up]").forEach((element) => {
24
+ element.removeEventListener("click", this._onClickUpArrow);
25
+ });
26
+ document.querySelectorAll("[data-arrow-down]").forEach((element) => {
27
+ element.removeEventListener("click", this._onClickDownArrow);
28
+ });
29
+ }
30
+
31
+ _onClickDownArrow(event) {
32
+ event.preventDefault();
33
+
34
+ const target = event.currentTarget;
35
+ const assembly = target.closest("[data-assembly-id]");
36
+ const upArrow = assembly.querySelector("[data-arrow-up]");
37
+
38
+ target.classList.toggle("hidden");
39
+ upArrow.classList.toggle("hidden");
40
+ }
41
+
42
+ _onClickUpArrow(event) {
43
+ event.preventDefault();
44
+
45
+ const target = event.currentTarget;
46
+ const assembly = target.closest("[data-assembly-id]");
47
+ const parentLevel = assembly.dataset.level;
48
+ const downArrow = assembly.querySelector("[data-arrow-down]");
49
+
50
+ target.classList.toggle("hidden");
51
+ downArrow.classList.toggle("hidden");
52
+
53
+ // Get all following tr elements
54
+ let nextElement = assembly.nextElementSibling;
55
+ while (nextElement) {
56
+ const currentLevel = nextElement.dataset.level;
57
+ const nextSibling = nextElement.nextElementSibling;
58
+
59
+ if (currentLevel > parentLevel) {
60
+ nextElement.remove();
61
+ } else {
62
+ break;
63
+ }
64
+ nextElement = nextSibling;
65
+ }
66
+ }
67
+ }
68
+
69
+ window.Decidim.AdminAssembliesListComponent = AdminAssembliesListComponent;
70
+ const component = new AdminAssembliesListComponent();
71
+
72
+ component.run();
@@ -37,7 +37,6 @@ module Decidim
37
37
 
38
38
  # org admins and space admins can do everything in the admin section
39
39
  org_admin_action?
40
- assemblies_type_action?
41
40
 
42
41
  return permission_action unless assembly
43
42
 
@@ -60,21 +59,6 @@ module Decidim
60
59
  toggle_allow(user.admin? || can_manage_assembly?(role: :admin) || can_manage_assembly?(role: :collaborator))
61
60
  end
62
61
 
63
- def assemblies_type_action?
64
- return unless [:assembly_type, :assemblies_type].include? permission_action.subject
65
- return disallow! unless user.admin?
66
-
67
- assembly_type = context.fetch(:assembly_type, nil)
68
- case permission_action.action
69
- when :destroy
70
- assemblies_is_empty = assembly_type && assembly_type.assemblies.empty?
71
-
72
- toggle_allow(assemblies_is_empty)
73
- else
74
- allow!
75
- end
76
- end
77
-
78
62
  # It is an admin user if it is an organization admin or is a space admin
79
63
  # for the current `assembly`.
80
64
  def admin_user?
@@ -126,6 +110,7 @@ module Decidim
126
110
  return disallow! unless can_view_private_space?
127
111
  return allow! if user&.admin?
128
112
  return allow! if assembly.published?
113
+ return allow! if user_can_preview_space?
129
114
 
130
115
  toggle_allow(can_manage_assembly?)
131
116
  end
@@ -258,14 +243,13 @@ module Decidim
258
243
  is_allowed = [
259
244
  :attachment,
260
245
  :attachment_collection,
261
- :category,
262
246
  :component,
263
247
  :component_data,
264
248
  :moderation,
265
249
  :assembly,
266
250
  :assembly_user_role,
267
- :assembly_member,
268
251
  :export_space,
252
+ :share_tokens,
269
253
  :import
270
254
  ].include?(permission_action.subject)
271
255
  allow! if is_allowed
@@ -277,19 +261,24 @@ module Decidim
277
261
  is_allowed = [
278
262
  :attachment,
279
263
  :attachment_collection,
280
- :category,
281
264
  :component,
282
265
  :component_data,
283
266
  :moderation,
284
267
  :assembly,
285
268
  :assembly_user_role,
286
- :assembly_member,
287
269
  :export_space,
270
+ :share_tokens,
288
271
  :import
289
272
  ].include?(permission_action.subject)
290
273
  allow! if is_allowed
291
274
  end
292
275
 
276
+ def user_can_preview_space?
277
+ context[:share_token].present? && Decidim::ShareToken.use!(token_for: assembly, token: context[:share_token], user:)
278
+ rescue ActiveRecord::RecordNotFound, StandardError
279
+ nil
280
+ end
281
+
293
282
  # Checks if the permission_action is to read the admin assemblies list or
294
283
  # not.
295
284
  def read_assembly_list_permission_action?
@@ -62,7 +62,7 @@ module Decidim
62
62
 
63
63
  def action_string
64
64
  case action
65
- when "create", "publish", "unpublish", "update", "duplicate", "export", "import"
65
+ when "create", "publish", "unpublish", "update", "duplicate", "export", "import", "soft_delete", "restore"
66
66
  "decidim.admin_log.assembly.#{action}"
67
67
  else
68
68
  super
@@ -6,11 +6,11 @@ module Decidim
6
6
  include Decidim::TranslationsHelper
7
7
 
8
8
  def hero_image_url
9
- assembly.attached_uploader(:hero_image).url(host: assembly.organization.host)
9
+ assembly.attached_uploader(:hero_image).url
10
10
  end
11
11
 
12
12
  def banner_image_url
13
- assembly.attached_uploader(:banner_image).url(host: assembly.organization.host)
13
+ assembly.attached_uploader(:banner_image).url
14
14
  end
15
15
 
16
16
  def area_name
@@ -37,12 +37,6 @@ module Decidim
37
37
  formatted_date(date)
38
38
  end
39
39
 
40
- def assembly_type
41
- return if assembly.assembly_type.blank?
42
-
43
- translated_attribute(assembly.assembly_type.title)
44
- end
45
-
46
40
  def formatted_date(date)
47
41
  return if date.blank?
48
42
 
@@ -14,12 +14,12 @@ module Decidim
14
14
  return @query if @query
15
15
 
16
16
  @query = Decidim::Assembly.where(organization: @organization)
17
- @query = @query.where("decidim_assemblies.published_at <= ?", end_time)
17
+ @query = @query.where(decidim_assemblies: { published_at: ..end_time })
18
18
  @query
19
19
  end
20
20
 
21
21
  def quantity
22
- @quantity ||= query.where("decidim_assemblies.published_at >= ?", start_time).count
22
+ @quantity ||= query.where(decidim_assemblies: { published_at: start_time.. }).count
23
23
  end
24
24
  end
25
25
  end
@@ -36,14 +36,12 @@ module Decidim
36
36
  target: attributes["target"],
37
37
  participatory_scope: attributes["participatory_scope"],
38
38
  participatory_structure: attributes["participatory_structure"],
39
- scopes_enabled: attributes["scopes_enabled"],
40
39
  private_space: attributes["private_space"],
41
40
  reference: attributes["reference"],
42
41
  purpose_of_action: attributes["purpose_of_action"],
43
42
  composition: attributes["composition"],
44
43
  duration: attributes["duration"],
45
44
  creation_date: attributes["creation_date"],
46
- decidim_scope_id: attributes["decidim_scope_id"],
47
45
  closing_date_reason: attributes["closing_date_reason"],
48
46
  included_at: attributes["included_at"],
49
47
  closing_date: attributes["closing_date"],
@@ -68,39 +66,6 @@ module Decidim
68
66
  end
69
67
  end
70
68
 
71
- def import_assemblies_type(type_id)
72
- return if Decidim::AssembliesType.find_by(id: type_id).nil?
73
-
74
- @imported_assembly.decidim_assemblies_type_id = type_id
75
- end
76
-
77
- def import_categories(categories)
78
- return if categories.nil?
79
-
80
- categories.map do |category_attributes|
81
- category = Decidim.traceability.create!(
82
- Category,
83
- @user,
84
- name: category_attributes["name"],
85
- description: category_attributes["description"],
86
- parent_id: category_attributes["parent_id"],
87
- participatory_space: @imported_assembly
88
- )
89
- next if category_attributes["subcategories"].nil?
90
-
91
- category_attributes["subcategories"].map do |subcategory_attributes|
92
- Decidim.traceability.create!(
93
- Category,
94
- @user,
95
- name: subcategory_attributes["name"],
96
- description: subcategory_attributes["description"],
97
- parent_id: category.id,
98
- participatory_space: @imported_assembly
99
- )
100
- end
101
- end
102
- end
103
-
104
69
  def import_folders_and_attachments(attachments)
105
70
  return if attachments["files"].nil?
106
71
 
@@ -3,146 +3,22 @@
3
3
  module Decidim
4
4
  module Assemblies
5
5
  # This class serializes an Assembly so it can be exported to CSV, JSON or other formats.
6
- class AssemblySerializer < Decidim::Exporters::Serializer
7
- include Decidim::ApplicationHelper
8
- include Decidim::ResourceHelper
9
- include Decidim::TranslationsHelper
10
-
11
- # Public: Initializes the serializer with an Assembly instance.
12
- def initialize(assembly)
13
- @assembly = assembly
14
- end
15
-
6
+ class AssemblySerializer < Decidim::Assemblies::OpenDataAssemblySerializer
16
7
  # Public: Exports a hash with the serialized data for this assembly.
17
8
  def serialize
18
- {
19
- id: assembly.id,
20
- slug: assembly.slug,
21
- hashtag: assembly.hashtag,
22
- decidim_organization_id: assembly.decidim_organization_id,
23
- title: assembly.title,
24
- subtitle: assembly.subtitle,
25
- weight: assembly.weight,
26
- short_description: assembly.short_description,
27
- description: assembly.description,
28
- remote_hero_image_url: Decidim::Assemblies::AssemblyPresenter.new(assembly).hero_image_url,
29
- remote_banner_image_url: Decidim::Assemblies::AssemblyPresenter.new(assembly).banner_image_url,
30
- promoted: assembly.promoted,
31
- developer_group: assembly.developer_group,
32
- meta_scope: assembly.meta_scope,
33
- local_area: assembly.local_area,
34
- target: assembly.target,
35
- decidim_scope_id: assembly.decidim_scope_id,
36
- paticipatory_scope: assembly.participatory_scope, # intentionally misspelled
37
- participatory_structure: assembly.participatory_structure,
38
- scopes_enabled: assembly.scopes_enabled,
39
- private_space: assembly.private_space,
40
- reference: assembly.reference,
41
- purpose_of_action: assembly.purpose_of_action,
42
- composition: assembly.composition,
43
- duration: assembly.duration,
44
- participatory_scope: assembly.participatory_scope,
45
- included_at: assembly.included_at,
46
- closing_date: assembly.closing_date,
47
- created_by: assembly.created_by,
48
- creation_date: assembly.creation_date,
49
- closing_date_reason: assembly.closing_date_reason,
50
- internal_organisation: assembly.internal_organisation,
51
- is_transparent: assembly.is_transparent,
52
- special_features: assembly.special_features,
53
- twitter_handler: assembly.twitter_handler,
54
- instagram_handler: assembly.instagram_handler,
55
- facebook_handler: assembly.facebook_handler,
56
- youtube_handler: assembly.youtube_handler,
57
- github_handler: assembly.github_handler,
58
- created_by_other: assembly.created_by_other,
59
- decidim_assemblies_type_id: assembly.decidim_assemblies_type_id,
60
- area: {
61
- id: assembly.area.try(:id),
62
- name: assembly.area.try(:name) || empty_translatable
63
- },
64
- scope: {
65
- id: assembly.scope.try(:id),
66
- name: assembly.scope.try(:name) || empty_translatable
67
- },
68
-
69
- assembly_categories: serialize_categories,
70
- attachments: {
71
- attachment_collections: serialize_attachment_collections,
72
- files: serialize_attachments
73
- },
74
- components: serialize_components,
75
- announcement: assembly.announcement
76
- }
77
- end
78
-
79
- private
80
-
81
- attr_reader :assembly
82
- alias resource assembly
83
-
84
- def serialize_categories
85
- return unless assembly.categories.first_class.any?
86
-
87
- assembly.categories.first_class.map do |category|
88
- {
89
- id: category.try(:id),
90
- name: category.try(:name),
91
- description: category.try(:description),
92
- parent_id: category.try(:parent_id),
93
- subcategories: serialize_subcategories(category.subcategories)
94
- }
95
- end
96
- end
97
-
98
- def serialize_subcategories(subcategories)
99
- return unless subcategories.any?
100
-
101
- subcategories.map do |subcategory|
9
+ super.merge(
102
10
  {
103
- id: subcategory.try(:id),
104
- name: subcategory.try(:name),
105
- description: subcategory.try(:description),
106
- parent_id: subcategory.try(:parent_id)
107
- }
108
- end
109
- end
110
-
111
- def serialize_attachment_collections
112
- return unless assembly.attachment_collections.any?
113
-
114
- assembly.attachment_collections.map do |collection|
115
- {
116
- id: collection.try(:id),
117
- name: collection.try(:name),
118
- weight: collection.try(:weight),
119
- description: collection.try(:description)
120
- }
121
- end
122
- end
123
-
124
- def serialize_attachments
125
- return unless assembly.attachments.any?
126
-
127
- assembly.attachments.map do |attachment|
128
- {
129
- id: attachment.try(:id),
130
- title: attachment.try(:title),
131
- weight: attachment.try(:weight),
132
- description: attachment.try(:description),
133
- attachment_collection: {
134
- name: attachment.attachment_collection.try(:name),
135
- weight: attachment.attachment_collection.try(:weight),
136
- description: attachment.attachment_collection.try(:description)
11
+ categories: serialize_categories,
12
+ taxonomies:,
13
+ attachments: {
14
+ attachment_collections: serialize_attachment_collections,
15
+ files: serialize_attachments
137
16
  },
138
- remote_file_url: Decidim::AttachmentPresenter.new(attachment).attachment_file_url
17
+ private_space: resource.private_space,
18
+ weight: resource.weight,
19
+ components: serialize_components
139
20
  }
140
- end
141
- end
142
-
143
- def serialize_components
144
- serializer = Decidim::Exporters::ParticipatorySpaceComponentsSerializer.new(@assembly)
145
- serializer.run
21
+ )
146
22
  end
147
23
  end
148
24
  end
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Assemblies
5
+ # This class serializes an Assembly so it can be exported to CSV for the Open Data feature.
6
+ class OpenDataAssemblySerializer < Decidim::Exporters::ParticipatorySpaceSerializer
7
+ # Public: Exports a hash with the serialized data for this assembly.
8
+ #
9
+ def serialize
10
+ super.merge(
11
+ {
12
+ url: EngineRouter.main_proxy(resource).assembly_url(resource),
13
+ subtitle: resource.subtitle,
14
+ remote_hero_image_url: Decidim::ParticipatoryProcesses::ParticipatoryProcessPresenter.new(resource).hero_image_url,
15
+ remote_banner_image_url: Decidim::Assemblies::AssemblyPresenter.new(resource).banner_image_url,
16
+ announcement: resource.announcement,
17
+ developer_group: resource.developer_group,
18
+ local_area: resource.local_area,
19
+ meta_scope: resource.meta_scope,
20
+ participatory_scope: resource.participatory_scope,
21
+ purpose_of_action: resource.purpose_of_action,
22
+ composition: resource.composition,
23
+ duration: resource.duration,
24
+ participatory_structure: resource.participatory_structure,
25
+ target: resource.target,
26
+ decidim_scope_id: resource.decidim_scope_id,
27
+ area: {
28
+ id: resource.area.try(:id),
29
+ name: resource.area.try(:name) || empty_translatable
30
+ },
31
+ scope: {
32
+ id: resource.scope.try(:id),
33
+ name: resource.scope.try(:name) || empty_translatable
34
+ },
35
+ scopes_enabled: resource.scopes_enabled,
36
+ included_at: resource.included_at,
37
+ closing_date: resource.closing_date,
38
+ created_by: resource.created_by,
39
+ creation_date: resource.creation_date,
40
+ closing_date_reason: resource.closing_date_reason,
41
+ internal_organisation: resource.internal_organisation,
42
+ is_transparent: resource.is_transparent,
43
+ special_features: resource.special_features,
44
+ twitter_handler: resource.twitter_handler,
45
+ instagram_handler: resource.instagram_handler,
46
+ facebook_handler: resource.facebook_handler,
47
+ youtube_handler: resource.youtube_handler,
48
+ github_handler: resource.github_handler,
49
+ created_by_other: resource.created_by_other,
50
+ assembly_type: {
51
+ id: resource.assembly_type.try(:id),
52
+ title: resource.assembly_type.try(:title) || empty_translatable
53
+ }
54
+ }
55
+ )
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,19 @@
1
+ <thead>
2
+ <tr>
3
+ <th>
4
+ <%= sort_link(query, :title, t("models.assembly.fields.title", scope: "decidim.admin")) %>
5
+ </th>
6
+ <th>
7
+ <%= sort_link(query, :created_at, t("models.assembly.fields.created_at", scope: "decidim.admin"), default_order: :desc) %>
8
+ </th>
9
+ <th>
10
+ <%= sort_link(query, :private_space, t("models.assembly.fields.private", scope: "decidim.admin")) %>
11
+ </th>
12
+ <th class="table-list__actions">
13
+ <%= sort_link(query, :published_at, t("models.assembly.fields.published", scope: "decidim.admin")) %>
14
+ </th>
15
+ <th>
16
+ <%= t("models.assembly.fields.actions", scope: "decidim.admin") %>
17
+ </th>
18
+ </tr>
19
+ </thead>