From 6cf0c610879678052e85c131bca53c5b0f05ee24 Mon Sep 17 00:00:00 2001 From: Harrison Hassig Date: Wed, 3 Jul 2024 13:17:24 +0200 Subject: [PATCH] add decidim templates gem (#8) --- Gemfile | 2 +- Gemfile.lock | 1 + ...ate_decidim_templates.decidim_templates.rb | 14 ++++++++++++ ..._to_decidim_templates.decidim_templates.rb | 22 +++++++++++++++++++ db/schema.rb | 16 +++++++++++++- 5 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20240703090226_create_decidim_templates.decidim_templates.rb create mode 100644 db/migrate/20240703090227_add_field_values_and_target_to_decidim_templates.decidim_templates.rb diff --git a/Gemfile b/Gemfile index aa1ebd3..85f00a6 100644 --- a/Gemfile +++ b/Gemfile @@ -9,7 +9,7 @@ gem "decidim", "0.28.1" # gem "decidim-design", "0.28.1" # gem "decidim-elections", "0.28.1" # gem "decidim-initiatives", "0.28.1" -# gem "decidim-templates", "0.28.1" +gem "decidim-templates", "0.28.1" gem "decidim-decidim_awesome", git: "https://github.com/decidim-ice/decidim-module-decidim_awesome", branch: "develop" diff --git a/Gemfile.lock b/Gemfile.lock index 447e259..757124a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -882,6 +882,7 @@ DEPENDENCIES decidim (= 0.28.1) decidim-decidim_awesome! decidim-dev (= 0.28.1) + decidim-templates (= 0.28.1) figaro (~> 1.2) letter_opener_web (~> 2.0) listen (~> 3.1) diff --git a/db/migrate/20240703090226_create_decidim_templates.decidim_templates.rb b/db/migrate/20240703090226_create_decidim_templates.decidim_templates.rb new file mode 100644 index 0000000..1eac5dd --- /dev/null +++ b/db/migrate/20240703090226_create_decidim_templates.decidim_templates.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true +# This migration comes from decidim_templates (originally 20200518093819) + +class CreateDecidimTemplates < ActiveRecord::Migration[5.2] + def change + create_table :decidim_templates_templates do |t| + t.integer :decidim_organization_id, null: false, index: { name: "index_decidim_templates_organization" } + t.references :templatable, polymorphic: true, index: { name: "index_decidim_templates_templatable" } + t.jsonb :name, null: false + t.jsonb :description + t.timestamps + end + end +end diff --git a/db/migrate/20240703090227_add_field_values_and_target_to_decidim_templates.decidim_templates.rb b/db/migrate/20240703090227_add_field_values_and_target_to_decidim_templates.decidim_templates.rb new file mode 100644 index 0000000..fd1afdb --- /dev/null +++ b/db/migrate/20240703090227_add_field_values_and_target_to_decidim_templates.decidim_templates.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true +# This migration comes from decidim_templates (originally 20221006055954) + +class AddFieldValuesAndTargetToDecidimTemplates < ActiveRecord::Migration[6.0] + class Template < ApplicationRecord + self.table_name = :decidim_templates_templates + end + + def change + add_column :decidim_templates_templates, :field_values, :json, default: {} + add_column :decidim_templates_templates, :target, :string + + reversible do |direction| + direction.up do + # rubocop:disable Rails/SkipsModelValidations + Template.where(templatable_type: "Decidim::Forms::Questionnaire").update_all(target: "questionnaire") + Template.where(templatable_type: "Decidim::Organization").update_all(target: "user_block") + # rubocop:enable Rails/SkipsModelValidations + end + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 13643ac..89c88bc 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2024_06_26_202513) do +ActiveRecord::Schema.define(version: 2024_07_03_090227) do # These are extensions that must be enabled in order to support this database enable_extension "ltree" @@ -1517,6 +1517,20 @@ t.index ["reset_password_token"], name: "index_decidim_system_admins_on_reset_password_token", unique: true end + create_table "decidim_templates_templates", force: :cascade do |t| + t.integer "decidim_organization_id", null: false + t.string "templatable_type" + t.bigint "templatable_id" + t.jsonb "name", null: false + t.jsonb "description" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.json "field_values", default: {} + t.string "target" + t.index ["decidim_organization_id"], name: "index_decidim_templates_organization" + t.index ["templatable_type", "templatable_id"], name: "index_decidim_templates_templatable" + end + create_table "decidim_user_blocks", force: :cascade do |t| t.bigint "decidim_user_id" t.integer "blocking_user_id"