diff --git a/Gemfile.lock b/Gemfile.lock
index 82575858..8eda9360 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -39,7 +39,7 @@ GIT
GIT
remote: https://github.com/octree-gva/decidim-module-decidim_awesome.git
- revision: 21ce064a26837ba43835621ddb6f6773b14c59e8
+ revision: afa824a79faa42f99eee5c0dcb4944e3a78b4a1d
branch: feat/awesome_decidim_private_fields
specs:
decidim-decidim_awesome (0.9.2)
diff --git a/config/routes.rb b/config/routes.rb
index 37bec383..f7164ae2 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -8,8 +8,6 @@
mount Sidekiq::Web => "/sidekiq"
end
- get "/open-data/download", to: redirect("/404")
- post "/open-data/download", to: redirect("/404")
mount LetterOpenerWeb::Engine, at: "/letter_opener" if Rails.env.development?
mount Decidim::Core::Engine => "/"
diff --git a/db/migrate/20240314092535_create_private_proposal_fields.decidim_decidim_awesome.rb b/db/migrate/20240314092535_create_private_proposal_fields.decidim_decidim_awesome.rb
new file mode 100644
index 00000000..fb6fda6d
--- /dev/null
+++ b/db/migrate/20240314092535_create_private_proposal_fields.decidim_decidim_awesome.rb
@@ -0,0 +1,14 @@
+# frozen_string_literal: true
+
+# This migration comes from decidim_decidim_awesome (originally 20230309124413)
+
+class CreatePrivateProposalFields < ActiveRecord::Migration[5.2]
+ def up
+ create_table :decidim_awesome_private_proposal_fields do |t|
+ t.text :private_body, default: ""
+
+ t.references :proposal, null: false, foreign_key: { to_table: :decidim_proposals_proposals }, index: { name: "decidim_awesome_private_proposal_fields_idx" }
+ t.timestamps
+ end
+ end
+end
diff --git a/lib/tasks/decidim_app.rake b/lib/tasks/decidim_app.rake
index a2a55077..65e4f589 100644
--- a/lib/tasks/decidim_app.rake
+++ b/lib/tasks/decidim_app.rake
@@ -35,6 +35,7 @@ namespace :decidim_app do
task install: :environment do
puts "Running db:migrate"
Rake::Task["db:migrate"].invoke
+ Rake::Task["decidim:awesome:private_fields"].invoke
end
# This task is used to upgrade your decidim-app to the latest version
@@ -44,6 +45,7 @@ namespace :decidim_app do
task upgrade: :environment do
puts "Running db:migrate"
Rake::Task["db:migrate"].invoke
+ Rake::Task["decidim:awesome:private_fields"].invoke
end
desc "usage: bundle exec rails k8s:dump_db"
diff --git a/lib/tasks/repair_data.rake b/lib/tasks/repair_data.rake
index 9d0a527a..512b28a6 100644
--- a/lib/tasks/repair_data.rake
+++ b/lib/tasks/repair_data.rake
@@ -51,4 +51,35 @@ namespace :decidim do
end
end
end
+
+ namespace :awesome do
+ desc "Migrate private fields from old proposals to new ones"
+ task private_fields: :environment do
+ Rails.logger.info("Migrating private fields from old proposals to new ones")
+
+ proposals = Decidim::Proposals::Proposal.where(
+ "private_body != ? AND private_body != ?",
+ "", "{}"
+ ).pluck(:id, :private_body)
+
+ Rails.logger.info("Preparing to migrate #{proposals.count} proposals")
+ creations = proposals.map do |proposal_id, private_body|
+ creation = Decidim::DecidimAwesome::PrivateProposalField.create(
+ proposal_id: proposal_id,
+ private_body: private_body
+ )
+
+ [proposal_id, creation]
+ end
+
+ if creations.any? { |_, creation| creation.invalid? }
+ proposal_ids = creations.select { |ary| ary.last.invalid? }.map(&:first)
+ Rails.logger.error("Failed to migrate #{proposal_ids.count} proposals")
+ Rails.logger.error("Failed proposals ID : #{proposal_ids.join(", ")}")
+ return
+ end
+
+ Rails.logger.info("Migrated #{creations.count} proposals")
+ end
+ end
end