Skip to content

Commit

Permalink
Fix newsletters and Decidim Votings (#9188)
Browse files Browse the repository at this point in the history
* Use the participatory space registry instead of directly constantizing

* Fix errors with votings when sending a newsletter

Co-authored-by: Andrés Pereira de Lucena <andreslucena@gmail.com>
  • Loading branch information
oriolgual and andreslucena committed May 6, 2022
1 parent 9fa85fe commit a58f371
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def organization_participatory_space(manifest_name)
.find_participatory_space_manifest(manifest_name)
.participatory_spaces.call(current_organization)
.published
.sort_by { |space| [space.closed? ? 1 : 0, space.title[current_locale]] }
.sort_by { |space| [space.try(:closed?) ? 1 : 0, space.title[current_locale]] }
end

def spaces_user_can_admin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,12 @@ def spaces
@spaces ||= @form.participatory_space_types.map do |type|
next if type.ids.blank?

object_class = "Decidim::#{type.manifest_name.classify}"
object_class = Decidim.participatory_space_registry.find(type.manifest_name).model_class_name.constantize

if type.ids.include?("all")
object_class.constantize.where(organization: @organization)
object_class.where(organization: @organization)
else
object_class.constantize.where(id: type.ids.reject(&:blank?))
object_class.where(id: type.ids.reject(&:blank?))
end
end.flatten.compact
end
Expand Down
5 changes: 4 additions & 1 deletion decidim-admin/spec/queries/newsletter_recipients_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,10 @@ module Decidim::Admin
"ids" => [] },
{ "id" => nil,
"manifest_name" => "initiatives",
"ids" => [] }
"ids" => [] },
{ "id" => nil,
"manifest_name" => "votings",
"ids" => [component.participatory_space.id.to_s] }
]
end

Expand Down
3 changes: 3 additions & 0 deletions decidim-elections/config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ en:
decidim/elections/question:
one: Question
other: Questions
decidim/voting:
one: Voting
other: Votings
decidim/votings/census/dataset:
one: Dataset
other: Datasets
Expand Down

0 comments on commit a58f371

Please sign in to comment.