decidim-assemblies 0.17.2 → 0.18.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/app/cells/decidim/assemblies/assembly_m/footer.erb +1 -1
  3. data/app/cells/decidim/assemblies/assembly_m_cell.rb +24 -1
  4. data/app/commands/decidim/assemblies/admin/copy_assembly.rb +1 -0
  5. data/app/controllers/decidim/assemblies/admin/application_controller.rb +5 -4
  6. data/app/controllers/decidim/assemblies/admin/assemblies_controller.rb +20 -10
  7. data/app/controllers/decidim/assemblies/admin/concerns/assembly_admin.rb +6 -4
  8. data/app/controllers/decidim/assemblies/application_controller.rb +6 -5
  9. data/app/controllers/decidim/assemblies/assemblies_controller.rb +18 -22
  10. data/app/forms/decidim/assemblies/admin/assembly_member_form.rb +1 -1
  11. data/app/helpers/decidim/assemblies/assemblies_helper.rb +6 -0
  12. data/app/helpers/decidim/assemblies/filter_assemblies_helper.rb +18 -7
  13. data/app/models/decidim/assembly.rb +36 -10
  14. data/app/permissions/decidim/assemblies/permissions.rb +1 -1
  15. data/app/queries/decidim/assemblies/admin/admin_users.rb +8 -1
  16. data/app/queries/decidim/assemblies/organization_published_assemblies.rb +2 -2
  17. data/app/queries/decidim/assemblies/visible_assemblies.rb +1 -8
  18. data/app/services/decidim/assemblies/assembly_search.rb +18 -0
  19. data/app/views/decidim/assemblies/_filter_by_type.html.erb +13 -12
  20. data/app/views/decidim/assemblies/admin/assemblies/_form.html.erb +133 -73
  21. data/app/views/decidim/assemblies/admin/assemblies/index.html.erb +29 -10
  22. data/app/views/decidim/assemblies/assemblies/_count.html.erb +1 -1
  23. data/app/views/decidim/assemblies/assemblies/_parent_assemblies.html.erb +2 -1
  24. data/app/views/decidim/assemblies/assemblies/_promoted_assembly.html.erb +1 -1
  25. data/app/views/decidim/assemblies/assemblies/index.html.erb +1 -0
  26. data/app/views/decidim/assemblies/assemblies/index.js.erb +2 -1
  27. data/app/views/decidim/assemblies/assemblies/show.html.erb +42 -36
  28. data/config/locales/ar-SA.yml +9 -2
  29. data/config/locales/ar.yml +386 -0
  30. data/config/locales/ca.yml +9 -2
  31. data/config/locales/cs.yml +8 -2
  32. data/config/locales/de.yml +8 -2
  33. data/config/locales/en.yml +9 -2
  34. data/config/locales/es-MX.yml +9 -2
  35. data/config/locales/es-PY.yml +9 -2
  36. data/config/locales/es.yml +9 -2
  37. data/config/locales/eu.yml +8 -2
  38. data/config/locales/fi-plain.yml +9 -2
  39. data/config/locales/fi.yml +9 -2
  40. data/config/locales/fr.yml +8 -2
  41. data/config/locales/gl.yml +8 -2
  42. data/config/locales/hu.yml +9 -2
  43. data/config/locales/id-ID.yml +8 -2
  44. data/config/locales/it.yml +9 -2
  45. data/config/locales/nl.yml +8 -2
  46. data/config/locales/pl.yml +8 -2
  47. data/config/locales/pt-BR.yml +8 -2
  48. data/config/locales/pt.yml +8 -2
  49. data/config/locales/ru.yml +1 -2
  50. data/config/locales/sv.yml +8 -2
  51. data/config/locales/tr-TR.yml +9 -2
  52. data/config/locales/uk.yml +1 -2
  53. data/lib/decidim/assemblies/version.rb +1 -1
  54. metadata +9 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7c0f24943af63649276875cef491e3886e5e018e16a770e50ef601a8bb6a37c9
4
- data.tar.gz: c236863c629a10f674a7a89f1933c709184305e5f3d41d3281f902182f50194d
3
+ metadata.gz: 99efc61ca1742e63f78a52fa33da8866b60669bbeca04b039814da09cfa148c4
4
+ data.tar.gz: 7ab6f6d231c564795a4319ddb527824f728108b7ee43f057ed86f68e277d682b
5
5
  SHA512:
6
- metadata.gz: 4916c1abd79855781ea8fa6ea5827e9116b3627057845439c77fed5de121692332b5952b45db5ba96af194c1b29a882dc8494ef629ede6da84c8c361fa10ef88
7
- data.tar.gz: 5e8312841a18b16513c2939e7f985624851dacd71cfb38ee79a4e24decf906626d9fa0366289f05a3b015a373dd512bf6907c0f3f53f34b37f1874ddb0aebdf5
6
+ metadata.gz: 8bfc9691a80e376d750ca2aef2895d8b1eb4aa60fbd5059498676e6c5fcb7815b46dd62ab3e2059e20c38d5ed9fa6b5acd409a07478cd982f43838d7d9c4f26f
7
+ data.tar.gz: bc458c5c4ef271e1ffa85d988849111d0002d6e362b2c55b0df0da105d88b4bd9ae18d92b480c91c485553fc6c6ba99100f7c5564bd8f4ba31b71569c5e2e385
@@ -7,7 +7,7 @@
7
7
  </div>
8
8
  <% end %>
9
9
  <%= link_to(
10
- t("layouts.decidim.assemblies.assembly.take_part"),
10
+ t(model.cta_button_text_key, scope: "layouts.decidim.assemblies.assembly"),
11
11
  resource_path,
12
12
  class: "card__button button button--sc secondary light small"
13
13
  ) %>
@@ -18,6 +18,10 @@ module Decidim
18
18
  true
19
19
  end
20
20
 
21
+ def has_children?
22
+ model.children.any?
23
+ end
24
+
21
25
  def resource_path
22
26
  Decidim::Assemblies::Engine.routes.url_helpers.assembly_path(model)
23
27
  end
@@ -27,7 +31,26 @@ module Decidim
27
31
  end
28
32
 
29
33
  def statuses
30
- [:creation_date, :follow]
34
+ return super unless has_children?
35
+ [:creation_date, :follow, :children_count]
36
+ end
37
+
38
+ def children_count_status
39
+ content_tag(
40
+ :strong,
41
+ t("layouts.decidim.assemblies.index.children")
42
+ ) + " " + children_assemblies_visible_for_user
43
+ end
44
+
45
+ def children_assemblies_visible_for_user
46
+ assemblies = model.children.published
47
+
48
+ if current_user
49
+ return assemblies.count.to_s if current_user.admin
50
+ assemblies.visible_for(current_user).count.to_s
51
+ else
52
+ assemblies.public_spaces.count.to_s
53
+ end
31
54
  end
32
55
 
33
56
  def resource_icon
@@ -53,6 +53,7 @@ module Decidim
53
53
  parent: @assembly.parent,
54
54
  developer_group: @assembly.developer_group,
55
55
  local_area: @assembly.local_area,
56
+ area: @assembly.area,
56
57
  target: @assembly.target,
57
58
  participatory_scope: @assembly.participatory_scope,
58
59
  participatory_structure: @assembly.participatory_structure,
@@ -5,6 +5,10 @@ module Decidim
5
5
  module Admin
6
6
  # The main admin application controller for assemblies
7
7
  class ApplicationController < Decidim::Admin::ApplicationController
8
+ register_permissions(::Decidim::Assemblies::Admin::ApplicationController,
9
+ Decidim::Assemblies::Permissions,
10
+ Decidim::Admin::Permissions)
11
+
8
12
  private
9
13
 
10
14
  def permissions_context
@@ -14,10 +18,7 @@ module Decidim
14
18
  end
15
19
 
16
20
  def permission_class_chain
17
- [
18
- Decidim::Assemblies::Permissions,
19
- Decidim::Admin::Permissions
20
- ]
21
+ ::Decidim.permissions_registry.chain_for(::Decidim::Assemblies::Admin::ApplicationController)
21
22
  end
22
23
  end
23
24
  end
@@ -6,7 +6,8 @@ module Decidim
6
6
  # Controller that allows managing assemblies.
7
7
  #
8
8
  class AssembliesController < Decidim::Assemblies::Admin::ApplicationController
9
- helper_method :current_assembly, :parent_assembly, :parent_assemblies, :current_participatory_space
9
+ include Decidim::Paginable
10
+ helper_method :current_assembly, :parent_assembly, :parent_assemblies, :current_participatory_space, :query
10
11
  layout "decidim/admin/assemblies"
11
12
 
12
13
  before_action :set_all_assemblies, except: [:index]
@@ -71,12 +72,26 @@ module Decidim
71
72
 
72
73
  private
73
74
 
75
+ def organization_assemblies
76
+ @organization_assemblies ||= OrganizationAssemblies.new(current_user.organization).query
77
+ end
78
+
79
+ def query
80
+ organization_assemblies
81
+ .where(parent_id: params[:parent_id])
82
+ .ransack(params[:q])
83
+ end
84
+
85
+ def collection
86
+ @collection ||= paginate(query.result)
87
+ end
88
+
74
89
  def set_all_assemblies
75
- @all_assemblies = OrganizationAssemblies.new(current_user.organization).query
90
+ @all_assemblies = organization_assemblies
76
91
  end
77
92
 
78
93
  def current_assembly
79
- scope = OrganizationAssemblies.new(current_user.organization).query
94
+ scope = organization_assemblies
80
95
  @current_assembly ||= scope.where(slug: params[:slug]).or(
81
96
  scope.where(id: params[:slug])
82
97
  ).first
@@ -85,16 +100,11 @@ module Decidim
85
100
  alias current_participatory_space current_assembly
86
101
 
87
102
  def parent_assembly
88
- @parent_assembly ||= OrganizationAssemblies.new(current_organization).query.find_by(id: params[:parent_id])
103
+ @parent_assembly ||= organization_assemblies.find_by(id: params[:parent_id])
89
104
  end
90
105
 
91
106
  def parent_assemblies
92
- @parent_assemblies ||= OrganizationAssemblies.new(current_user.organization).query.where(parent_id: nil)
93
- end
94
-
95
- def collection
96
- parent_id = params[:parent_id].presence
97
- @collection ||= OrganizationAssemblies.new(current_user.organization).query.where(parent_id: parent_id)
107
+ @parent_assemblies ||= organization_assemblies.where(parent_id: nil)
98
108
  end
99
109
 
100
110
  def assembly_params
@@ -12,6 +12,11 @@ module Decidim
12
12
  module AssemblyAdmin
13
13
  extend ActiveSupport::Concern
14
14
 
15
+ RegistersPermissions
16
+ .register_permissions(::Decidim::Assemblies::Admin::Concerns::AssemblyAdmin,
17
+ Decidim::Assemblies::Permissions,
18
+ Decidim::Admin::Permissions)
19
+
15
20
  included do
16
21
  include Decidim::Admin::ParticipatorySpaceAdminContext
17
22
  participatory_space_admin_layout
@@ -35,10 +40,7 @@ module Decidim
35
40
  end
36
41
 
37
42
  def permission_class_chain
38
- [
39
- Decidim::Assemblies::Permissions,
40
- Decidim::Admin::Permissions
41
- ]
43
+ PermissionsRegistry.chain_for(AssemblyAdmin)
42
44
  end
43
45
  end
44
46
  end
@@ -8,6 +8,11 @@ module Decidim
8
8
  helper Decidim::Assemblies::AssembliesHelper
9
9
  include NeedsPermission
10
10
 
11
+ register_permissions(Decidim::Assemblies::ApplicationController,
12
+ ::Decidim::Assemblies::Permissions,
13
+ ::Decidim::Admin::Permissions,
14
+ ::Decidim::Permissions)
15
+
11
16
  private
12
17
 
13
18
  def permissions_context
@@ -17,11 +22,7 @@ module Decidim
17
22
  end
18
23
 
19
24
  def permission_class_chain
20
- [
21
- Decidim::Assemblies::Permissions,
22
- Decidim::Admin::Permissions,
23
- Decidim::Permissions
24
- ]
25
+ ::Decidim.permissions_registry.chain_for(::Decidim::Assemblies::ApplicationController)
25
26
  end
26
27
 
27
28
  def permission_scope
@@ -2,19 +2,13 @@
2
2
 
3
3
  module Decidim
4
4
  module Assemblies
5
- # A controller that holds the logic to show Assemblies in a
6
- # public layout.
5
+ # A controller that holds the logic to show Assemblies in a public layout.
7
6
  class AssembliesController < Decidim::Assemblies::ApplicationController
8
7
  include ParticipatorySpaceContext
9
8
  participatory_space_layout only: :show
9
+ include FilterResource
10
10
 
11
- helper Decidim::AttachmentsHelper
12
- helper Decidim::IconHelper
13
- helper Decidim::WidgetUrlsHelper
14
- helper Decidim::SanitizeHelper
15
- helper Decidim::ResourceReferenceHelper
16
-
17
- helper_method :collection, :parent_assemblies, :promoted_assemblies, :assemblies, :stats, :assembly_participatory_processes
11
+ helper_method :parent_assemblies, :promoted_assemblies, :stats, :assembly_participatory_processes
18
12
 
19
13
  def index
20
14
  enforce_permission_to :list, :assembly
@@ -54,6 +48,18 @@ module Decidim
54
48
 
55
49
  private
56
50
 
51
+ def search_klass
52
+ AssemblySearch
53
+ end
54
+
55
+ def default_filter_params
56
+ {
57
+ scope_id: nil,
58
+ area_id: nil,
59
+ assembly_type: "all"
60
+ }
61
+ end
62
+
57
63
  def current_participatory_space
58
64
  return unless params[:slug]
59
65
 
@@ -66,18 +72,12 @@ module Decidim
66
72
  @published_assemblies ||= OrganizationPublishedAssemblies.new(current_organization, current_user)
67
73
  end
68
74
 
69
- def assemblies
70
- @assemblies ||= OrganizationPrioritizedAssemblies.new(current_organization, current_user)
75
+ def promoted_assemblies
76
+ @promoted_assemblies ||= published_assemblies | PromotedAssemblies.new
71
77
  end
72
78
 
73
79
  def parent_assemblies
74
- @parent_assemblies ||= assemblies | ParentAssemblies.new | FilteredAssemblies.new(current_filter)
75
- end
76
-
77
- alias collection parent_assemblies
78
-
79
- def promoted_assemblies
80
- @promoted_assemblies ||= assemblies | PromotedAssemblies.new
80
+ search.results.parent_assemblies.order(promoted: :desc)
81
81
  end
82
82
 
83
83
  def stats
@@ -87,10 +87,6 @@ module Decidim
87
87
  def assembly_participatory_processes
88
88
  @assembly_participatory_processes ||= @current_participatory_space.linked_participatory_space_resources(:participatory_processes, "included_participatory_processes")
89
89
  end
90
-
91
- def current_filter
92
- params[:filter] || "all"
93
- end
94
90
  end
95
91
  end
96
92
  end
@@ -23,7 +23,7 @@ module Decidim
23
23
 
24
24
  validates :designation_date, presence: true
25
25
  validates :full_name, presence: true, unless: proc { |object| object.existing_user }
26
- validates :position, inclusion: { in: Decidim::AssemblyMember::POSITIONS }
26
+ validates :position, presence: true, inclusion: { in: Decidim::AssemblyMember::POSITIONS }
27
27
  validates :position_other, presence: true, if: ->(form) { form.position == "other" }
28
28
  validates :ceased_date, date: { after: :designation_date, allow_blank: true }
29
29
  validates :user, presence: true, if: proc { |object| object.existing_user }
@@ -5,6 +5,12 @@ module Decidim
5
5
  # Helpers related to the Assemblies layout.
6
6
  module AssembliesHelper
7
7
  include Decidim::ResourceHelper
8
+ include Decidim::AttachmentsHelper
9
+ include Decidim::IconHelper
10
+ include Decidim::WidgetUrlsHelper
11
+ include Decidim::SanitizeHelper
12
+ include Decidim::ResourceReferenceHelper
13
+ include Decidim::FiltersHelper
8
14
  include FilterAssembliesHelper
9
15
 
10
16
  # Public: Returns the characteristics of an assembly in a readable format like
@@ -3,25 +3,36 @@
3
3
  module Decidim
4
4
  module Assemblies
5
5
  # Helpers related to the Assemblies filter by type.
6
+ #
7
+ # `filter` returns a Filter object from Decidim::FilterResource
6
8
  module FilterAssembliesHelper
7
9
  def available_filters
8
- %w(all government executive consultative_advisory participatory working_group commission others)
10
+ %w(all) + Assembly::ASSEMBLY_TYPES
9
11
  end
10
12
 
11
- def filter_link(filter)
12
- link_to t(filter, scope: "decidim.assemblies.filter"), url_for(params.to_unsafe_h.merge(page: nil, filter: filter)), data: { filter: filter }, remote: true
13
+ def filter_link(filter_name)
14
+ Decidim::Assemblies::Engine
15
+ .routes
16
+ .url_helpers
17
+ .assemblies_path(
18
+ filter: {
19
+ scope_id: filter.scope_id,
20
+ area_id: filter.area_id,
21
+ assembly_type: filter_name
22
+ }
23
+ )
13
24
  end
14
25
 
15
26
  def help_text
16
27
  t("help", scope: "decidim.assemblies.filter")
17
28
  end
18
29
 
19
- def filter
20
- params[:filter] || "all"
30
+ def filter_name(filter_key)
31
+ t(filter_key, scope: "decidim.assemblies.filter")
21
32
  end
22
33
 
23
- def current_filter_text
24
- t(filter, scope: "decidim.assemblies.filter")
34
+ def current_filter_name
35
+ filter_name(filter.assembly_type)
25
36
  end
26
37
  end
27
38
  end
@@ -68,12 +68,25 @@ module Decidim
68
68
  after_create :set_parents_path
69
69
  after_update :set_parents_path, :update_children_paths, if: :saved_change_to_parent_id?
70
70
 
71
- scope :visible_for, lambda { |user|
72
- joins("LEFT JOIN decidim_participatory_space_private_users ON
73
- decidim_participatory_space_private_users.privatable_to_id = #{table_name}.id")
74
- .where("(private_space = ? and decidim_participatory_space_private_users.decidim_user_id = ?)
75
- or private_space = ? or (private_space = ? and is_transparent = ?)", true, user, false, true, true).distinct
76
- }
71
+ # Overwriting existing method Decidim::HasPrivateUsers.visible_for
72
+ def self.visible_for(user)
73
+ if user
74
+ return all if user.admin?
75
+
76
+ left_outer_joins(:participatory_space_private_users).where(
77
+ %{private_space = false OR
78
+ (private_space = true AND is_transparent = true) OR
79
+ decidim_participatory_space_private_users.decidim_user_id = ?}, user.id
80
+ ).distinct
81
+ else
82
+ public_spaces
83
+ end
84
+ end
85
+
86
+ # Overwriting existing method Decidim::HasPrivateUsers.public_spaces
87
+ def self.public_spaces
88
+ where(private_space: false).or(where(private_space: true).where(is_transparent: true))
89
+ end
77
90
 
78
91
  # Scope to return only the promoted assemblies.
79
92
  #
@@ -82,12 +95,14 @@ module Decidim
82
95
  where(promoted: true)
83
96
  end
84
97
 
85
- def self.private_assemblies
86
- where(private_space: true)
98
+ # Return parent assemblies.
99
+ def self.parent_assemblies
100
+ where(parent_id: nil)
87
101
  end
88
102
 
89
- def self.public_spaces
90
- super.where(private_space: false).or(Decidim::Assembly.where(private_space: true).where(is_transparent: true))
103
+ # Return child assemblies.
104
+ def self.child_assemblies
105
+ where.not(parent_id: nil)
91
106
  end
92
107
 
93
108
  def self.log_presenter_class_for(_log)
@@ -121,6 +136,12 @@ module Decidim
121
136
  Decidim::AssemblyPresenter.new(self).translated_title
122
137
  end
123
138
 
139
+ def closed?
140
+ return false if closing_date.blank?
141
+
142
+ closing_date < Date.current
143
+ end
144
+
124
145
  private
125
146
 
126
147
  # When an assembly changes their parent, we need to update the parents_path attribute
@@ -171,5 +192,10 @@ module Decidim
171
192
  )
172
193
  end
173
194
  # rubocop:enable Rails/SkipsModelValidations
195
+
196
+ # Allow ransacker to search for a key in a hstore column (`title`.`en`)
197
+ ransacker :title do |parent|
198
+ Arel::Nodes::InfixOperation.new("->", parent.table[:title], Arel::Nodes.build_quoted(I18n.locale.to_s))
199
+ end
174
200
  end
175
201
  end
@@ -171,7 +171,7 @@ module Decidim
171
171
  allow! if permission_action.action == :read || permission_action.action == :preview
172
172
  end
173
173
 
174
- # Process admins can eprform everything *inside* that assembly. They cannot
174
+ # Process admins can perform everything *inside* that assembly. They cannot
175
175
  # create a assembly or perform actions on assembly groups or other
176
176
  # assemblies.
177
177
  def assembly_admin_action?
@@ -23,7 +23,7 @@ module Decidim
23
23
  #
24
24
  # Returns an ActiveRecord::Relation.
25
25
  def query
26
- Decidim::User.where(id: organization_admins)
26
+ Decidim::User.where(id: organization_admins).or(assembly_user_admins)
27
27
  end
28
28
 
29
29
  private
@@ -33,6 +33,13 @@ module Decidim
33
33
  def organization_admins
34
34
  assembly.organization.admins
35
35
  end
36
+
37
+ def assembly_user_admins
38
+ assembly_user_admin_ids = Decidim::AssemblyUserRole
39
+ .where(assembly: assembly, role: :admin)
40
+ .pluck(:decidim_user_id)
41
+ Decidim::User.where(id: assembly_user_admin_ids)
42
+ end
36
43
  end
37
44
  end
38
45
  end