-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0fc1171
commit 9a30c8f
Showing
20 changed files
with
439 additions
and
350 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 56 additions & 45 deletions
101
app/decorators/decidim/admin/newsletters_helper_decorator.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,62 @@ | ||
# frozen_string_literal: true | ||
|
||
Decidim::Admin::NewslettersHelper.class_eval do | ||
def participatory_space_types_form_object(form_object, space_type) | ||
return if spaces_user_can_admin[space_type.manifest_name.to_sym].blank? | ||
|
||
html = "" | ||
form_object.fields_for "participatory_space_types[#{space_type.manifest_name}]", space_type do |ff| | ||
html += ff.hidden_field :manifest_name, value: space_type.manifest_name | ||
html += select_tag_participatory_spaces(space_type, spaces_for_select(space_type), ff) | ||
# rubocop:disable Metrics/CyclomaticComplexity | ||
# rubocop:disable Metrics/PerceivedComplexity | ||
module Decidim::Admin::NewslettersHelperDecorator | ||
def self.decorate | ||
Decidim::Admin::NewslettersHelper.class_eval do | ||
def participatory_space_types_form_object(form_object, space_type) | ||
return if spaces_user_can_admin[space_type.manifest_name.to_sym].blank? | ||
|
||
html = "" | ||
form_object.fields_for "participatory_space_types[#{space_type.manifest_name}]", space_type do |ff| | ||
html += ff.hidden_field :manifest_name, value: space_type.manifest_name | ||
html += select_tag_participatory_spaces(space_type, spaces_for_select(space_type), ff) | ||
end | ||
html.html_safe | ||
end | ||
|
||
def select_tag_participatory_spaces(space_type, spaces, child_form) | ||
return unless spaces | ||
|
||
tag.div(class: "#{space_type.manifest_name}-block spaces-block-tag cell small-12 medium-6") do | ||
child_form.select :ids, options_for_select(spaces), | ||
{ prompt: t("select_recipients_to_deliver.none", scope: "decidim.admin.newsletters"), | ||
label: label_text_for(space_type), | ||
include_hidden: false }, | ||
multiple: true, size: spaces.size > 10 ? 10 : spaces.size, class: "chosen-select" | ||
end | ||
end | ||
|
||
def label_text_for(space_type) | ||
if space_type.process_group_id | ||
Decidim::ParticipatoryProcessGroup.find(space_type.process_group_id).title[current_locale] | ||
else | ||
t("activerecord.models.decidim/#{space_type.manifest_name.singularize}.other") | ||
end | ||
end | ||
|
||
def spaces_for_select(space_type) | ||
return unless Decidim.participatory_space_manifests.map(&:name).include?(space_type.manifest_name.to_sym) | ||
|
||
collection = filter_spaces_by_process_group(space_type) | ||
return collection unless current_user.admin? | ||
|
||
[[I18n.t("select_recipients_to_deliver.all_spaces", scope: "decidim.admin.newsletters"), "all"]] + collection | ||
end | ||
|
||
def filter_spaces_by_process_group(space_type) | ||
manifest_name = space_type.manifest_name.to_sym | ||
return spaces_user_can_admin[manifest_name] unless manifest_name == :participatory_processes | ||
|
||
processes_ids = Decidim::ParticipatoryProcessGroup.find(space_type.process_group_id).participatory_processes.ids | ||
spaces_user_can_admin[manifest_name].select { |arr| arr[1].in? processes_ids } | ||
end | ||
end | ||
html.html_safe | ||
end | ||
|
||
def select_tag_participatory_spaces(space_type, spaces, child_form) | ||
return unless spaces | ||
|
||
tag.div(class: "#{space_type.manifest_name}-block spaces-block-tag cell small-12 medium-6") do | ||
child_form.select :ids, options_for_select(spaces), | ||
{ prompt: t("select_recipients_to_deliver.none", scope: "decidim.admin.newsletters"), | ||
label: label_text_for(space_type), | ||
include_hidden: false }, | ||
multiple: true, size: spaces.size > 10 ? 10 : spaces.size, class: "chosen-select" | ||
end | ||
end | ||
|
||
def label_text_for(space_type) | ||
if space_type.process_group_id | ||
Decidim::ParticipatoryProcessGroup.find(space_type.process_group_id).title[current_locale] | ||
else | ||
t("activerecord.models.decidim/#{space_type.manifest_name.singularize}.other") | ||
end | ||
end | ||
|
||
def spaces_for_select(space_type) | ||
return unless Decidim.participatory_space_manifests.map(&:name).include?(space_type.manifest_name.to_sym) | ||
|
||
collection = filter_spaces_by_process_group(space_type) | ||
return collection unless current_user.admin? | ||
|
||
[[I18n.t("select_recipients_to_deliver.all_spaces", scope: "decidim.admin.newsletters"), "all"]] + collection | ||
end | ||
end | ||
|
||
def filter_spaces_by_process_group(space_type) | ||
manifest_name = space_type.manifest_name.to_sym | ||
return spaces_user_can_admin[manifest_name] unless manifest_name == :participatory_processes | ||
::Decidim::Admin::NewslettersHelperDecorator.decorate | ||
|
||
processes_ids = Decidim::ParticipatoryProcessGroup.find(space_type.process_group_id).participatory_processes.ids | ||
spaces_user_can_admin[manifest_name].select { |arr| arr[1].in? processes_ids } | ||
end | ||
end | ||
# rubocop:enable Metrics/CyclomaticComplexity | ||
# rubocop:enable Metrics/PerceivedComplexity |
38 changes: 22 additions & 16 deletions
38
app/decorators/decidim/admin/selective_newsletter_form_decorator.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,29 @@ | ||
# frozen_string_literal: true | ||
|
||
Decidim::Admin::SelectiveNewsletterForm.class_eval do | ||
def map_model(_newsletter) | ||
self.participatory_space_types = Decidim.participatory_space_manifests.map do |manifest| | ||
Decidim::Admin::SelectiveNewsletterParticipatorySpaceTypeForm.from_model(manifest: manifest) | ||
end | ||
participatory_space_types.unshift(additional_participatory_space_manifest) | ||
end | ||
module Decidim::Admin::SelectiveNewsletterFormDecorator | ||
def self.decorate | ||
Decidim::Admin::SelectiveNewsletterForm.class_eval do | ||
def map_model(_newsletter) | ||
self.participatory_space_types = Decidim.participatory_space_manifests.map do |manifest| | ||
Decidim::Admin::SelectiveNewsletterParticipatorySpaceTypeForm.from_model(manifest: manifest) | ||
end | ||
participatory_space_types.unshift(additional_participatory_space_manifest) | ||
end | ||
|
||
private | ||
private | ||
|
||
def additional_participatory_space_manifest | ||
Decidim::Admin::SelectiveNewsletterParticipatorySpaceTypeForm.from_model( | ||
manifest: Decidim.participatory_space_manifests.find { |m| m.name == :participatory_processes }, | ||
process_group_id: process_group_id | ||
) | ||
end | ||
def additional_participatory_space_manifest | ||
Decidim::Admin::SelectiveNewsletterParticipatorySpaceTypeForm.from_model( | ||
manifest: Decidim.participatory_space_manifests.find { |m| m.name == :participatory_processes }, | ||
process_group_id: process_group_id | ||
) | ||
end | ||
|
||
def process_group_id | ||
Rails.application.config.process | ||
def process_group_id | ||
Rails.application.config.process | ||
end | ||
end | ||
end | ||
end | ||
|
||
::Decidim::Admin::SelectiveNewsletterFormDecorator.decorate |
30 changes: 18 additions & 12 deletions
30
app/decorators/decidim/admin/selective_newsletter_participatory_space_type_form_decorator.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,26 @@ | ||
# frozen_string_literal: true | ||
|
||
Decidim::Admin::SelectiveNewsletterParticipatorySpaceTypeForm.class_eval do | ||
attribute :process_group_id, Integer | ||
module Decidim::Admin::SelectiveNewsletterParticipatorySpaceTypeFormDecorator | ||
def self.decorate | ||
Decidim::Admin::SelectiveNewsletterParticipatorySpaceTypeForm.class_eval do | ||
attribute :process_group_id, Integer | ||
|
||
def map_model(model_hash) | ||
manifest = model_hash[:manifest] | ||
process_group_id = model_hash[:process_group_id] | ||
process_group_id ||= regulations_group_id if manifest.name == :participatory_processes | ||
def map_model(model_hash) | ||
manifest = model_hash[:manifest] | ||
process_group_id = model_hash[:process_group_id] | ||
process_group_id ||= regulations_group_id if manifest.name == :participatory_processes | ||
|
||
self.manifest_name = manifest.name.to_s | ||
self.process_group_id = process_group_id | ||
end | ||
self.manifest_name = manifest.name.to_s | ||
self.process_group_id = process_group_id | ||
end | ||
|
||
private | ||
private | ||
|
||
def regulations_group_id | ||
Rails.application.config.regulation | ||
def regulations_group_id | ||
Rails.application.config.regulation | ||
end | ||
end | ||
end | ||
end | ||
|
||
::Decidim::Admin::SelectiveNewsletterParticipatorySpaceTypeFormDecorator.decorate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,17 @@ | ||
# frozen_string_literal: true | ||
|
||
Decidim::Organization.class_eval do | ||
# rubocop:disable Layout/LineLength | ||
# This association is an override to Decidim::Organization.users_with_any_role | ||
has_many :users_with_any_role, lambda { | ||
where.not(roles: []).or(where('"decidim_users"."id" in (select "decidim_participatory_process_user_roles"."decidim_user_id" from "decidim_participatory_process_user_roles")' \ | ||
' or "decidim_users"."id" in (select "decidim_assembly_user_roles"."decidim_user_id" from "decidim_assembly_user_roles")')) | ||
}, foreign_key: "decidim_organization_id", class_name: "Decidim::User", dependent: :destroy | ||
# rubocop:enable Layout/LineLength | ||
module Decidim::OrganizationDecorator | ||
def self.decorate | ||
Decidim::Organization.class_eval do | ||
# rubocop:disable Layout/LineLength | ||
# This association is an override to Decidim::Organization.users_with_any_role | ||
has_many :users_with_any_role, lambda { | ||
where.not(roles: []).or(where('"decidim_users"."id" in (select "decidim_participatory_process_user_roles"."decidim_user_id" from "decidim_participatory_process_user_roles")' \ | ||
' or "decidim_users"."id" in (select "decidim_assembly_user_roles"."decidim_user_id" from "decidim_assembly_user_roles")')) | ||
}, foreign_key: "decidim_organization_id", class_name: "Decidim::User", dependent: :destroy | ||
# rubocop:enable Layout/LineLength | ||
end | ||
end | ||
end | ||
|
||
::Decidim::OrganizationDecorator.decorate |
24 changes: 15 additions & 9 deletions
24
app/decorators/decidim/participatory_space_context_decorator.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,20 @@ | ||
# frozen_string_literal: true | ||
|
||
Decidim::ParticipatorySpaceContext.class_eval do | ||
# Method for current user can visit the space (assembly or proces) | ||
def current_user_can_visit_space? | ||
return true unless current_participatory_space.try(:private_space?) && | ||
!current_participatory_space.try(:is_transparent?) | ||
return false unless current_user | ||
module Decidim::ParticipatorySpaceContextDecorator | ||
def self.decorate | ||
Decidim::ParticipatorySpaceContext.class_eval do | ||
# Method for current user can visit the space (assembly or proces) | ||
def current_user_can_visit_space? | ||
return true unless current_participatory_space.try(:private_space?) && | ||
!current_participatory_space.try(:is_transparent?) | ||
return false unless current_user | ||
|
||
current_user.admin || | ||
current_participatory_space.users.include?(current_user) || | ||
current_participatory_space.participatory_space_private_users.exists?(decidim_user_id: current_user.id) | ||
current_user.admin || | ||
current_participatory_space.users.include?(current_user) || | ||
current_participatory_space.participatory_space_private_users.exists?(decidim_user_id: current_user.id) | ||
end | ||
end | ||
end | ||
end | ||
|
||
::Decidim::ParticipatorySpaceContextDecorator.decorate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.