Skip to content

Commit

Permalink
Rework decorators
Browse files Browse the repository at this point in the history
  • Loading branch information
laurajaime committed Jul 23, 2024
1 parent 0fc1171 commit 9a30c8f
Show file tree
Hide file tree
Showing 20 changed files with 439 additions and 350 deletions.
3 changes: 1 addition & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
source "https://rubygems.org"

ruby RUBY_VERSION
# DECIDIM_VERSION = { git: "https://github.com/CodiTramuntana/decidim", branch: "release/0.27-stable" }.freeze
DECIDIM_VERSION = { path: "/home/laurajv/decidim_fork" }.freeze
DECIDIM_VERSION = { git: "https://github.com/CodiTramuntana/decidim", branch: "release/0.27-stable" }.freeze

gem "decidim", DECIDIM_VERSION
gem "decidim-templates", DECIDIM_VERSION
Expand Down
94 changes: 48 additions & 46 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,51 +1,7 @@
GIT
remote: https://github.com/gencat/decidim-module-challenges.git
revision: 2f3f8c983544e0d73512c8f6a5f93318ecee01ad
tag: v0.3.3
specs:
decidim-challenges (0.3.3)
decidim-core (~> 0.27)

GIT
remote: https://github.com/gencat/decidim-module-department_admin.git
revision: a202f8a49b19157eb1b2a455b82f33ce8d955c23
branch: upgrade/0.27
specs:
decidim-department_admin (0.7.0)
decidim-admin (~> 0.27.0)
decidim-core (~> 0.27.0)

GIT
remote: https://github.com/gencat/decidim-module-idcat_mobil.git
revision: 406054a9ed7b83d4c6e542661e0b2200b064fe32
branch: upgrade/0.27
specs:
decidim-idcat_mobil (0.4.0)
decidim (>= 0.27.0)
decidim-core (>= 0.27.0)
omniauth-idcat_mobil (~> 0.5.0)

GIT
remote: https://github.com/gencat/decidim-verifications-members_picker.git
revision: c6d9c4ee27262803491380c45032a16370040862
branch: downgrade_ruby
specs:
decidim-verifications-members_picker (0.0.6)
decidim-core (>= 0.27.5)
decidim-verifications (>= 0.27.5)
psych (< 4)

GIT
remote: https://github.com/mainio/decidim-module-term_customizer.git
revision: abbf0c69e1bcaafebc5aa4f8da22fdb64ce62149
remote: https://github.com/CodiTramuntana/decidim
revision: e9d5cd060a191c5d557549462314fbdf3a3ef2a8
branch: release/0.27-stable
specs:
decidim-term_customizer (0.27.0)
decidim-admin (~> 0.27.0)
decidim-core (~> 0.27.0)

PATH
remote: /home/laurajv/decidim_fork
specs:
decidim (0.27.7)
decidim-accountability (= 0.27.7)
Expand Down Expand Up @@ -214,6 +170,52 @@ PATH
decidim-verifications (0.27.7)
decidim-core (= 0.27.7)

GIT
remote: https://github.com/gencat/decidim-module-challenges.git
revision: 2f3f8c983544e0d73512c8f6a5f93318ecee01ad
tag: v0.3.3
specs:
decidim-challenges (0.3.3)
decidim-core (~> 0.27)

GIT
remote: https://github.com/gencat/decidim-module-department_admin.git
revision: a202f8a49b19157eb1b2a455b82f33ce8d955c23
branch: upgrade/0.27
specs:
decidim-department_admin (0.7.0)
decidim-admin (~> 0.27.0)
decidim-core (~> 0.27.0)

GIT
remote: https://github.com/gencat/decidim-module-idcat_mobil.git
revision: 406054a9ed7b83d4c6e542661e0b2200b064fe32
branch: upgrade/0.27
specs:
decidim-idcat_mobil (0.4.0)
decidim (>= 0.27.0)
decidim-core (>= 0.27.0)
omniauth-idcat_mobil (~> 0.5.0)

GIT
remote: https://github.com/gencat/decidim-verifications-members_picker.git
revision: c6d9c4ee27262803491380c45032a16370040862
branch: downgrade_ruby
specs:
decidim-verifications-members_picker (0.0.6)
decidim-core (>= 0.27.5)
decidim-verifications (>= 0.27.5)
psych (< 4)

GIT
remote: https://github.com/mainio/decidim-module-term_customizer.git
revision: abbf0c69e1bcaafebc5aa4f8da22fdb64ce62149
branch: release/0.27-stable
specs:
decidim-term_customizer (0.27.0)
decidim-admin (~> 0.27.0)
decidim-core (~> 0.27.0)

PATH
remote: decidim-admin-extended
specs:
Expand Down
101 changes: 56 additions & 45 deletions app/decorators/decidim/admin/newsletters_helper_decorator.rb
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 app/decorators/decidim/admin/selective_newsletter_form_decorator.rb
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
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
22 changes: 14 additions & 8 deletions app/decorators/decidim/organization_decorator.rb
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 app/decorators/decidim/participatory_space_context_decorator.rb
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
2 changes: 1 addition & 1 deletion config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Application < Rails::Application
config.railties_order = [:main_app, Decidim::DepartmentAdmin::Engine, :all]

# Initialize configuration defaults for originally generated Rails version.
config.load_defaults 5.2
config.load_defaults 6.0
config.i18n.available_locales = %w(en ca es oc)
config.time_zone = "Madrid"

Expand Down
1 change: 0 additions & 1 deletion config/locales/oc_core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -970,7 +970,6 @@ oc:
show:
allow_public_contact: Permetre que qualsevol participant m'envïi missatges directes, encara que no la segueixi.
direct_messages: Rebre missatges directes de qualsevol
email_on_notification: Vull rebre un correu electrònic cada vegada que rebi una notificació.
everything_followed: Tot el que segueixo
newsletter_notifications: Voi arrecéber informacion sus l'activitat considerabla e es novetats deth portau.
newsletters: Butlletins informatius
Expand Down
1 change: 0 additions & 1 deletion decidim-home/config/locales/oc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,6 @@ oc:
no_notifications: Encara no hi ha notificacions.
notifications_settings:
show:
email_on_notification: Vull rebre un correu electrònic cada vegada que rebi una notificació.
newsletter_notifications: Vull rebre butlletins
update_notifications_settings: Guardar canvis
update:
Expand Down
Loading

0 comments on commit 9a30c8f

Please sign in to comment.