decidim-assemblies 0.31.7 → 0.31.9

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 (31) hide show
  1. checksums.yaml +4 -4
  2. data/app/commands/decidim/assemblies/admin/update_assembly.rb +1 -1
  3. data/app/controllers/decidim/assemblies/admin/assemblies_controller.rb +28 -3
  4. data/app/controllers/decidim/assemblies/admin/assembly_attachment_collections_controller.rb +2 -0
  5. data/app/controllers/decidim/assemblies/admin/assembly_attachments_controller.rb +2 -0
  6. data/app/controllers/decidim/assemblies/admin/assembly_exports_controller.rb +2 -0
  7. data/app/controllers/decidim/assemblies/admin/assembly_landing_page_controller.rb +8 -2
  8. data/app/controllers/decidim/assemblies/admin/assembly_share_tokens_controller.rb +2 -0
  9. data/app/controllers/decidim/assemblies/admin/assembly_user_roles_controller.rb +2 -0
  10. data/app/controllers/decidim/assemblies/admin/component_share_tokens_controller.rb +2 -0
  11. data/app/controllers/decidim/assemblies/admin/concerns/assembly_admin.rb +6 -3
  12. data/app/controllers/decidim/assemblies/admin/participatory_space_private_users_controller.rb +2 -0
  13. data/app/controllers/decidim/assemblies/admin/participatory_space_private_users_csv_imports_controller.rb +2 -0
  14. data/app/controllers/decidim/assemblies/participatory_space_private_users_controller.rb +9 -0
  15. data/app/packs/src/decidim/assemblies/admin/assemblies_list.js +30 -0
  16. data/app/packs/src/decidim/assemblies/admin/assemblies_list.test.js +85 -0
  17. data/app/permissions/decidim/assemblies/permissions.rb +5 -2
  18. data/app/views/decidim/assemblies/admin/assemblies/_assembly_row.html.erb +4 -3
  19. data/app/views/decidim/assemblies/admin/assemblies/index.js.erb +5 -0
  20. data/app/views/decidim/assemblies/participatory_space_private_users/index.html.erb +2 -0
  21. data/config/locales/ca.yml +1 -1
  22. data/config/locales/de.yml +134 -129
  23. data/config/locales/eu.yml +17 -17
  24. data/config/locales/fr-CA.yml +3 -0
  25. data/config/locales/fr.yml +3 -0
  26. data/config/locales/gl.yml +209 -34
  27. data/config/locales/he-IL.yml +0 -3
  28. data/config/locales/pt-BR.yml +3 -3
  29. data/config/locales/sv.yml +6 -0
  30. data/lib/decidim/assemblies/version.rb +1 -1
  31. metadata +13 -12
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: acc2bc05070130c13318e3d1b79efe6d3f9fae92879c4b2a2df6d6ef3403c308
4
- data.tar.gz: c257f029c0733e2189a10a68552a293589cb1535d304e919c0a698997ba9ebf8
3
+ metadata.gz: c355385975141ed89177cf462dbdc83d7a69bc860069bb314ef75127d2aae741
4
+ data.tar.gz: 0be2c8cc342429ba868b82619c5e2c6dfc154ceb600049b3cd4bdb98bd00090c
5
5
  SHA512:
6
- metadata.gz: b51f37e764f9997d6c1b08973e6ab881f9b6035d7e5d07078fe94fbb22d506749b776cd0754b5742fd2c9c68b40b7c456ae3cb32b88c6e48578897fabf05b516
7
- data.tar.gz: a11efbfa7b70a9a9dfacde3b29c3721cdebf5ee3f4e58059ca91e0020111d1acdc8d8f9b57359f23ce328b4184ce951598af8c40428244d5b1e47323100927c2
6
+ metadata.gz: 7f50ed3c1efa227a4916b1720171e31bd08c8cdfaf94359a6cbfb8ca058b07c7c0ab8f185bc33ce9a6cf40e8f9ca0892573d8dc2235bf6ad6e8c4922c9361732
7
+ data.tar.gz: 03d2e5753e7fcd402450a17e7a0029fda33790dd0579ee7070219a6a1c2345a7e34121fa4592996fcf5b9583d0146fae49cc6b355b54897874d53c1d7335176b
@@ -24,7 +24,7 @@ module Decidim
24
24
  end
25
25
 
26
26
  def parent
27
- @parent ||= Assembly.find_by(id: resource.parent)
27
+ @parent ||= resource.participatory_space_sibling_scope(:assemblies).find_by(id: resource.parent_id)
28
28
  end
29
29
 
30
30
  def participatory_processes
@@ -10,7 +10,7 @@ module Decidim
10
10
  include Decidim::Admin::ParticipatorySpaceAdminContext
11
11
  include Decidim::Admin::HasTrashableResources
12
12
 
13
- helper_method :current_assembly, :parent_assembly, :parent_assembly_id, :current_participatory_space
13
+ helper_method :current_assembly, :parent_assembly, :parent_assembly_id, :parent_ids_with_children, :assembly_depth, :current_participatory_space
14
14
 
15
15
  layout "decidim/admin/assemblies"
16
16
 
@@ -74,6 +74,12 @@ module Decidim
74
74
 
75
75
  private
76
76
 
77
+ def filtered_collection
78
+ return query.result if request.format.js? && ransack_params[:parent_id_eq].present?
79
+
80
+ paginate(query.result)
81
+ end
82
+
77
83
  def collection
78
84
  @collection ||= OrganizationAssemblies.new(current_user.organization).query
79
85
  end
@@ -91,7 +97,10 @@ module Decidim
91
97
  end
92
98
 
93
99
  def current_assembly
94
- @current_assembly ||= collection.with_deleted.where(slug: params[:slug]).or(
100
+ return if params[:slug].blank?
101
+ return @current_assembly if defined?(@current_assembly)
102
+
103
+ @current_assembly = collection.with_deleted.where(slug: params[:slug]).or(
95
104
  collection.where(id: params[:slug])
96
105
  ).first
97
106
  end
@@ -99,7 +108,10 @@ module Decidim
99
108
  alias current_participatory_space current_assembly
100
109
 
101
110
  def parent_assembly
102
- @parent_assembly ||= collection.find_by(id: parent_assembly_id)
111
+ return if parent_assembly_id.blank?
112
+ return @parent_assembly if defined?(@parent_assembly)
113
+
114
+ @parent_assembly = collection.find_by(id: parent_assembly_id)
103
115
  end
104
116
 
105
117
  def parent_assembly_id
@@ -113,6 +125,19 @@ module Decidim
113
125
  return params[:parent_id]
114
126
  end
115
127
 
128
+ # Returns the depth of the given assembly in the hierarchy based on its
129
+ # parents_path. Root assemblies have a depth of 0.
130
+ def assembly_depth(assembly)
131
+ [assembly.parents_path.to_s.split(".").size - 1, 0].max
132
+ end
133
+
134
+ # IDs of the assemblies that have at least one visible (non soft-deleted)
135
+ # child. This avoids a per-row `children.count` query in the row partial
136
+ # while keeping soft-deleted children from showing the expand arrow.
137
+ def parent_ids_with_children
138
+ @parent_ids_with_children ||= collection.reorder(nil).where.not(parent_id: nil).distinct.pluck(:parent_id).to_set
139
+ end
140
+
116
141
  def assembly_parent_id
117
142
  params[:assembly][:parent_id]
118
143
  end
@@ -10,6 +10,8 @@ module Decidim
10
10
  include Decidim::Admin::Concerns::HasAttachmentCollections
11
11
  include Decidim::Admin::Concerns::HasTabbedMenu
12
12
 
13
+ protected
14
+
13
15
  def after_destroy_path
14
16
  assembly_attachment_collections_path(current_assembly)
15
17
  end
@@ -11,6 +11,8 @@ module Decidim
11
11
  include Decidim::Admin::Concerns::HasAttachments
12
12
  include Decidim::Admin::Concerns::HasTabbedMenu
13
13
 
14
+ protected
15
+
14
16
  def after_destroy_path
15
17
  assembly_attachments_path(current_assembly)
16
18
  end
@@ -7,6 +7,8 @@ module Decidim
7
7
  include Concerns::AssemblyAdmin
8
8
  include Decidim::Admin::ParticipatorySpaceExport
9
9
 
10
+ protected
11
+
10
12
  def exportable_space
11
13
  current_assembly
12
14
  end
@@ -10,12 +10,18 @@ module Decidim
10
10
 
11
11
  layout "decidim/admin/assembly"
12
12
 
13
+ helper_method :scoped_resource
14
+
15
+ def scoped_resource
16
+ current_participatory_space
17
+ end
18
+
19
+ protected
20
+
13
21
  def content_block_scope
14
22
  current_participatory_space_manifest.content_blocks_scope_name
15
23
  end
16
24
 
17
- alias scoped_resource current_participatory_space
18
-
19
25
  def enforce_permission_to_update_resource
20
26
  enforce_permission_to :update, :assembly, assembly: scoped_resource
21
27
  end
@@ -9,6 +9,8 @@ module Decidim
9
9
  class AssemblyShareTokensController < Decidim::Admin::ShareTokensController
10
10
  include Concerns::AssemblyAdmin
11
11
 
12
+ protected
13
+
12
14
  def resource
13
15
  current_assembly
14
16
  end
@@ -8,6 +8,8 @@ module Decidim
8
8
  class AssemblyUserRolesController < Decidim::Admin::ParticipatorySpace::UserRoleController
9
9
  include Concerns::AssemblyAdmin
10
10
 
11
+ protected
12
+
11
13
  def authorization_scope = :assembly_user_role
12
14
 
13
15
  def resource_form = form(AssemblyUserRoleForm)
@@ -9,6 +9,8 @@ module Decidim
9
9
  class ComponentShareTokensController < Decidim::Admin::ShareTokensController
10
10
  include Concerns::AssemblyAdmin
11
11
 
12
+ protected
13
+
12
14
  def resource
13
15
  @resource ||= current_participatory_space.components.find(params[:component_id])
14
16
  end
@@ -19,19 +19,22 @@ module Decidim
19
19
 
20
20
  included do
21
21
  include Decidim::Admin::ParticipatorySpaceAdminContext
22
- helper_method :current_assembly
22
+
23
+ helper_method :current_assembly, :current_participatory_space
23
24
  add_breadcrumb_item_from_menu :admin_assembly_menu
24
25
 
25
26
  participatory_space_admin_layout
26
27
 
28
+ def current_participatory_space = current_assembly
29
+
30
+ protected
31
+
27
32
  def current_assembly
28
33
  @current_assembly ||= organization_assemblies.find_by!(
29
34
  slug: params[:assembly_slug] || params[:slug]
30
35
  )
31
36
  end
32
37
 
33
- alias_method :current_participatory_space, :current_assembly
34
-
35
38
  def organization_assemblies
36
39
  @organization_assemblies ||= OrganizationAssemblies.new(current_organization).query
37
40
  end
@@ -9,6 +9,8 @@ module Decidim
9
9
  include Concerns::AssemblyAdmin
10
10
  include Decidim::Admin::Concerns::HasPrivateUsers
11
11
 
12
+ protected
13
+
12
14
  def after_destroy_path
13
15
  participatory_space_private_users_path(current_assembly)
14
16
  end
@@ -9,6 +9,8 @@ module Decidim
9
9
  include Concerns::AssemblyAdmin
10
10
  include Decidim::Admin::Concerns::HasPrivateUsersCsvImport
11
11
 
12
+ protected
13
+
12
14
  def after_import_path
13
15
  participatory_space_private_users_path(current_assembly)
14
16
  end
@@ -5,10 +5,12 @@ module Decidim
5
5
  class ParticipatorySpacePrivateUsersController < Decidim::Assemblies::ApplicationController
6
6
  include ParticipatorySpaceContext
7
7
  include Decidim::HasMembersPage
8
+ include Paginable
8
9
 
9
10
  def index
10
11
  raise ActionController::RoutingError, "No members for this assembly" if members.none?
11
12
 
13
+ @members = paginate(members)
12
14
  enforce_permission_to :list, :members
13
15
  redirect_to decidim_assemblies.assembly_path(current_participatory_space) unless can_visit_index?
14
16
  end
@@ -22,6 +24,13 @@ module Decidim
22
24
  OrganizationAssemblies.new(current_organization).query.where(id: params[:assembly_slug])
23
25
  ).first!
24
26
  end
27
+
28
+ def page_params
29
+ {
30
+ per_page:,
31
+ page: params[:page]
32
+ }
33
+ end
25
34
  end
26
35
  end
27
36
  end
@@ -16,6 +16,7 @@ class AdminAssembliesListComponent {
16
16
  });
17
17
  document.querySelectorAll("[data-arrow-down]").forEach((element) => {
18
18
  element.addEventListener("click", this._onClickDownArrow);
19
+ element.addEventListener("ajax:error", this._onAjaxError);
19
20
  });
20
21
  }
21
22
 
@@ -25,6 +26,7 @@ class AdminAssembliesListComponent {
25
26
  });
26
27
  document.querySelectorAll("[data-arrow-down]").forEach((element) => {
27
28
  element.removeEventListener("click", this._onClickDownArrow);
29
+ element.removeEventListener("ajax:error", this._onAjaxError);
28
30
  });
29
31
  }
30
32
 
@@ -33,6 +35,16 @@ class AdminAssembliesListComponent {
33
35
 
34
36
  const target = event.currentTarget;
35
37
  const assembly = target.closest("[data-assembly-id]");
38
+
39
+ if (assembly.dataset.loading === "true") {
40
+ event.stopImmediatePropagation();
41
+ return;
42
+ }
43
+
44
+ assembly.dataset.loading = "true";
45
+ assembly.setAttribute("aria-busy", "true");
46
+ assembly.classList.add("spinner-container");
47
+
36
48
  const upArrow = assembly.querySelector("[data-arrow-up]");
37
49
 
38
50
  target.classList.toggle("hidden");
@@ -44,6 +56,12 @@ class AdminAssembliesListComponent {
44
56
 
45
57
  const target = event.currentTarget;
46
58
  const assembly = target.closest("[data-assembly-id]");
59
+
60
+ if (assembly.dataset.loading === "true") {
61
+ event.stopImmediatePropagation();
62
+ return;
63
+ }
64
+
47
65
  const parentLevel = assembly.dataset.level;
48
66
  const downArrow = assembly.querySelector("[data-arrow-down]");
49
67
 
@@ -64,6 +82,18 @@ class AdminAssembliesListComponent {
64
82
  nextElement = nextSibling;
65
83
  }
66
84
  }
85
+
86
+ _onAjaxError(event) {
87
+ const assembly = event.currentTarget.closest("[data-assembly-id]");
88
+
89
+ if (!assembly) {
90
+ return;
91
+ }
92
+
93
+ assembly.classList.remove("spinner-container");
94
+ assembly.removeAttribute("aria-busy");
95
+ assembly.dataset.loading = "false";
96
+ }
67
97
  }
68
98
 
69
99
  window.Decidim.AdminAssembliesListComponent = AdminAssembliesListComponent;
@@ -0,0 +1,85 @@
1
+ /* global jest */
2
+
3
+ window.Decidim = window.Decidim || {};
4
+
5
+ describe("AdminAssembliesListComponent", () => {
6
+ let assemblyRow = null;
7
+ let downArrow = null;
8
+ let upArrow = null;
9
+
10
+ const click = (element) => {
11
+ const event = new MouseEvent("click", { bubbles: true, cancelable: true });
12
+ element.dispatchEvent(event);
13
+ return event;
14
+ };
15
+
16
+ beforeEach(() => {
17
+ jest.resetModules();
18
+ document.body.innerHTML = `
19
+ <table>
20
+ <tbody>
21
+ <tr data-assembly-id="1" data-level="0">
22
+ <td>
23
+ <a href="/assemblies?q%5Bparent_id_eq%5D=1" data-remote="true" data-arrow-down>Down</a>
24
+ <a href="#" class="hidden" data-arrow-up>Up</a>
25
+ </td>
26
+ </tr>
27
+ </tbody>
28
+ </table>
29
+ `;
30
+ // eslint-disable-next-line global-require
31
+ require("./assemblies_list");
32
+
33
+ assemblyRow = document.querySelector('[data-assembly-id="1"]');
34
+ downArrow = assemblyRow.querySelector("[data-arrow-down]");
35
+ upArrow = assemblyRow.querySelector("[data-arrow-up]");
36
+ });
37
+
38
+ afterEach(() => {
39
+ document.body.innerHTML = "";
40
+ });
41
+
42
+ it("adds the spinner and loading state when expanding", () => {
43
+ click(downArrow);
44
+
45
+ expect(assemblyRow.classList.contains("spinner-container")).toBe(true);
46
+ expect(assemblyRow.dataset.loading).toBe("true");
47
+ expect(assemblyRow.getAttribute("aria-busy")).toBe("true");
48
+ expect(downArrow.classList.contains("hidden")).toBe(true);
49
+ expect(upArrow.classList.contains("hidden")).toBe(false);
50
+ });
51
+
52
+ it("ignores repeated and collapse clicks while loading", () => {
53
+ click(downArrow);
54
+
55
+ const repeatClick = click(downArrow);
56
+ const collapseClick = click(upArrow);
57
+
58
+ expect(repeatClick.defaultPrevented).toBe(true);
59
+ expect(collapseClick.defaultPrevented).toBe(true);
60
+ expect(assemblyRow.classList.contains("spinner-container")).toBe(true);
61
+ expect(assemblyRow.dataset.loading).toBe("true");
62
+ expect(downArrow.classList.contains("hidden")).toBe(true);
63
+ expect(upArrow.classList.contains("hidden")).toBe(false);
64
+ });
65
+
66
+ it("clears the spinner and loading state on ajax:error", () => {
67
+ click(downArrow);
68
+
69
+ downArrow.dispatchEvent(new CustomEvent("ajax:error", { bubbles: true }));
70
+
71
+ expect(assemblyRow.classList.contains("spinner-container")).toBe(false);
72
+ expect(assemblyRow.dataset.loading).toBe("false");
73
+ expect(assemblyRow.hasAttribute("aria-busy")).toBe(false);
74
+ });
75
+
76
+ it("allows collapsing after an ajax error", () => {
77
+ click(downArrow);
78
+ downArrow.dispatchEvent(new CustomEvent("ajax:error", { bubbles: true }));
79
+
80
+ click(upArrow);
81
+
82
+ expect(upArrow.classList.contains("hidden")).toBe(true);
83
+ expect(downArrow.classList.contains("hidden")).toBe(false);
84
+ });
85
+ });
@@ -22,7 +22,7 @@ module Decidim
22
22
 
23
23
  return permission_action unless user
24
24
 
25
- if !has_manageable_assemblies? && !user.admin?
25
+ if !user.admin? && !has_manageable_assemblies?
26
26
  disallow!
27
27
  return permission_action
28
28
  end
@@ -214,6 +214,7 @@ module Decidim
214
214
  # A moderator needs to be able to read the assembly they are assigned to,
215
215
  # and needs to perform all actions for the moderations of that assembly.
216
216
  def moderator_action?
217
+ return if user.admin?
217
218
  return unless can_manage_assembly?(role: :moderator)
218
219
 
219
220
  allow! if permission_action.subject == :moderation
@@ -221,6 +222,7 @@ module Decidim
221
222
 
222
223
  # Collaborators can read/preview everything inside their assembly.
223
224
  def collaborator_action?
225
+ return if user.admin?
224
226
  return unless can_manage_assembly?(role: :collaborator)
225
227
  return if permission_action.subject == :space_private_user
226
228
 
@@ -229,6 +231,7 @@ module Decidim
229
231
 
230
232
  # Evaluators can only read the assembly components
231
233
  def evaluator_action?
234
+ return if user.admin?
232
235
  return unless can_manage_assembly?(role: :evaluator)
233
236
 
234
237
  allow! if permission_action.action == :read && permission_action.subject == :component
@@ -238,8 +241,8 @@ module Decidim
238
241
  # Process admins can perform everything *inside* that assembly. They cannot
239
242
  # perform actions on assembly groups or other assemblies.
240
243
  def assembly_admin_action?
241
- return unless can_manage_assembly?(role: :admin)
242
244
  return if user.admin?
245
+ return unless can_manage_assembly?(role: :admin)
243
246
 
244
247
  is_allowed = [
245
248
  :attachment,
@@ -1,7 +1,8 @@
1
- <tr data-assembly-id="<%= assembly.id %>" data-parent-id="<%= assembly.parent_id %>" data-level="<%= assembly.ancestors.count %>">
1
+ <% depth = assembly_depth(assembly) %>
2
+ <tr data-assembly-id="<%= assembly.id %>" data-parent-id="<%= assembly.parent_id %>" data-level="<%= depth %>">
2
3
  <td class="whitespace-nowrap" data-label="<%= t("models.assembly.fields.title", scope: "decidim.admin") %>">
3
4
  <% if parent_assembly_id %>
4
- <% [assembly.ancestors.count - 1, 0].max.times do |index| %>
5
+ <% [depth - 1, 0].max.times do |index| %>
5
6
  <span class="px-3"></span>
6
7
  <% end %>
7
8
  <span class="px-3 text-xl text-secondary opacity-10">|</span>
@@ -21,7 +22,7 @@
21
22
  <% end %>
22
23
  </span>
23
24
 
24
- <% if assembly.children.count.positive? %>
25
+ <% if parent_ids_with_children.include?(assembly.id) %>
25
26
  <%= link_to url_for(query_params_with(parent_id_eq: assembly.id)), remote: true, data: { arrow_down: true } do %>
26
27
  <%= icon "arrow-down-s-line", class: "w-4 h-4 ml-2" %>
27
28
  <% end %>
@@ -5,6 +5,11 @@ $('[data-assembly-id="<%= parent_assembly_id %>"]').after(
5
5
  locals: { view: :index }).strip.html_safe %>'
6
6
  );
7
7
 
8
+ $('[data-assembly-id="<%= parent_assembly_id %>"]')
9
+ .removeClass("spinner-container")
10
+ .removeAttr("aria-busy")
11
+ .attr("data-loading", "false");
12
+
8
13
  // Dispatch the `ajax:loaded` event with the newly inserted element
9
14
  var insertedElement = $('[data-assembly-id="<%= parent_assembly_id %>"]').next()[0];
10
15
  document.dispatchEvent(new CustomEvent("ajax:loaded", { detail: insertedElement }));
@@ -20,4 +20,6 @@ edit_link(
20
20
  <div id="assembly_members-grid" class="grid grid-cols-1 md:grid-cols-3 gap-4 md:gap-12">
21
21
  <%= render(collection) %>
22
22
  </div>
23
+
24
+ <%= decidim_paginate @members %>
23
25
  </div>
@@ -364,7 +364,7 @@ ca:
364
364
  assemblies:
365
365
  create_assembly_member:
366
366
  email_intro: Una administradora de l'assemblea <a href="%{resource_url}">%{resource_name}</a> t'ha afegit com a un dels seus membres.
367
- email_outro: Reps aquesta notificació perquè t'han convidat a una assemblea. Entra en <a href="%{resource_url}">assembly page</a> per a contribuir-hi!
367
+ email_outro: Reps aquesta notificació perquè t'han convidat a una assemblea. Entra en <a href="%{resource_url}">pàgina de l'assemblea</a> per a contribuir-hi!
368
368
  email_subject: T'han convidat a ser membre de l'assemblea %{resource_name}!
369
369
  notification_title: T'han registrat com a membre de l'assemblea <a href="%{resource_path}">%{resource_name}</a>. Entra a <a href="%{resource_path}">la pàgina de l'assemblea</a> per a contribuir-hi!
370
370
  assembly: