-
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.
Modify decorators to updated version of zeitwek
- Loading branch information
Showing
3 changed files
with
48 additions
and
42 deletions.
There are no files selected for viewing
46 changes: 20 additions & 26 deletions
46
app/decorators/decidim/admin/import/importer_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,35 +1,29 @@ | ||
# frozen_string_literal: true | ||
|
||
Decidim::Admin::Import::Importer.class_eval do | ||
def import! | ||
finished_collection = collection.map { |elem| object_to_manage_without_notify_uniquely?(elem) ? elem.finish_without_notif! : elem.finish! } | ||
if collection.any? { |elem| elem.is_a? Decidim::Proposals::Import::ProposalCreator } | ||
notify_collection(finished_collection, :proposals) | ||
elsif collection.any? { |elem| elem.is_a? Decidim::Proposals::Import::ProposalAnswerCreator } | ||
notify_collection(finished_collection, :answers) | ||
end | ||
end | ||
|
||
def notify_collection(collection, type) | ||
recipients = collection.map { |elem| elem.participatory_space.followers.uniq }.flatten.uniq | ||
case type | ||
when :proposals | ||
recipients.each do |recipient| | ||
next unless ["all", "followed-only"].include?(recipient.notification_types) | ||
module Decidim::Admin::Import::ImporterDecorator | ||
def self.decorate | ||
Decidim::Admin::Import::Importer.class_eval do | ||
def import! | ||
finished_collection = collection.map { |elem| object_to_manage_without_notify_uniquely?(elem) ? elem.finish_without_notif! : elem.finish! } | ||
notify_collection(finished_collection, collection.first) | ||
end | ||
|
||
ProposalsMailer.notify_massive_import(collection, recipient).deliver_later | ||
def notify_collection(collection, klass) | ||
recipients = collection.flat_map { |elem| elem.participatory_space.followers.where(notification_types: %w(all followed-only)).uniq }.uniq | ||
case klass | ||
when Decidim::Proposals::Import::ProposalCreator | ||
recipients.each { |recipient| ProposalsMailer.notify_massive_import(collection, recipient).deliver_later } | ||
when Decidim::Proposals::Import::ProposalAnswerCreator | ||
recipients.each { |recipient| ProposalsAnswersMailer.notify_massive_import(collection, recipient).deliver_later } | ||
end | ||
end | ||
when :answers | ||
recipients.each do |recipient| | ||
next unless ["all", "followed-only"].include?(recipient.notification_types) | ||
|
||
ProposalsAnswersMailer.notify_massive_import(collection, recipient).deliver_later | ||
def object_to_manage_without_notify_uniquely?(obj) | ||
# These types of object must be notified in group, not uniquely | ||
[Decidim::Proposals::Import::ProposalCreator, Decidim::Proposals::Import::ProposalAnswerCreator].include? obj.class | ||
end | ||
end | ||
end | ||
|
||
def object_to_manage_without_notify_uniquely?(obj) | ||
# These types of object must be notified in group, not uniquely | ||
[Decidim::Proposals::Import::ProposalCreator, Decidim::Proposals::Import::ProposalAnswerCreator].include? obj.class | ||
end | ||
end | ||
|
||
::Decidim::Admin::Import::ImporterDecorator.decorate |
24 changes: 15 additions & 9 deletions
24
app/decorators/decidim/proposals/import/proposal_answer_creator_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::Proposals::Import::ProposalAnswerCreator.class_eval do | ||
def finish_without_notif! | ||
Decidim.traceability.perform_action!( | ||
"answer", | ||
resource, | ||
current_user | ||
) do | ||
resource.try(:save!) | ||
module Decidim::Proposals::Import::ProposalAnswerCreatorDecorator | ||
def self.decorate | ||
Decidim::Proposals::Import::ProposalAnswerCreator.class_eval do | ||
def finish_without_notif! | ||
Decidim.traceability.perform_action!( | ||
"answer", | ||
resource, | ||
current_user | ||
) do | ||
resource.try(:save!) | ||
end | ||
resource | ||
end | ||
end | ||
resource | ||
end | ||
end | ||
|
||
Decidim::Proposals::Import::ProposalAnswerCreatorDecorator.decorate |
20 changes: 13 additions & 7 deletions
20
app/decorators/decidim/proposals/import/proposal_creator_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,12 +1,18 @@ | ||
# frozen_string_literal: true | ||
|
||
Decidim::Proposals::Import::ProposalCreator.class_eval do | ||
def finish_without_notif! | ||
Decidim.traceability.perform_action!(:create, self.class.resource_klass, context[:current_user], visibility: "admin-only") do | ||
resource.save! | ||
resource | ||
module Decidim::Proposals::Import::ProposalCreatorDecorator | ||
def self.decorate | ||
Decidim::Proposals::Import::ProposalCreator.class_eval do | ||
def finish_without_notif! | ||
Decidim.traceability.perform_action!(:create, self.class.resource_klass, context[:current_user], visibility: "admin-only") do | ||
resource.save! | ||
resource | ||
end | ||
publish(resource) | ||
resource | ||
end | ||
end | ||
publish(resource) | ||
resource | ||
end | ||
end | ||
|
||
::Decidim::Proposals::Import::ProposalCreatorDecorator.decorate |