Skip to content

Commit

Permalink
add migration for decidim-extended_socio_demographic_authorization_ha…
Browse files Browse the repository at this point in the history
…ndler data
  • Loading branch information
moustachu committed Dec 6, 2023
1 parent d10c173 commit 5501663
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# frozen_string_literal: true

class DeleteExtendedSocioDemographicAuthorizationHandlerSettingsOnInitiatives < ActiveRecord::Migration[6.1]
def change
Decidim::InitiativesType.where(document_number_authorization_handler: "extended_socio_demographic_authorization_handler").each do |initiatives_type|
initiatives_type.update!(document_number_authorization_handler: nil)
end

Decidim::ResourcePermission.all.each do |resource_permission|
next if resource_permission.permissions.blank?

resource_permission.permissions.each do |action, authorization|
if authorization.has_key?("authorization_handlers") && authorization["authorization_handlers"].has_key?("extended_socio_demographic_authorization_handler")
resource_permission.permissions.delete(action)
end
end

resource_permission.save! if resource_permission.changed?
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# frozen_string_literal: true

class MigrateExtendedSocioDemographicAuthorizationHandlerData < ActiveRecord::Migration[6.1]
def change
Decidim::Authorization.where(name: "extended_socio_demographic_authorization_handler").each do |authorization|
next if authorization.user.deleted?

# We don't migrate the email because we don't want to confirm it if needed
authorization.user.name = "#{authorization.metadata["first_mane"]} #{authorization.metadata["first_mane"]}"
authorization.user.extended_data = {
city: authorization.metadata["city"],
address: authorization.metadata["address"],
birth_date: authorization.metadata["birth_date"],
postal_code: authorization.metadata["postal_code"],
certification: authorization.metadata["certification"]
}
authorization.user.save
authorization.delete
end
end
end
66 changes: 64 additions & 2 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2023_05_12_092845) do
ActiveRecord::Schema.define(version: 2023_12_06_230804) do

# These are extensions that must be enabled in order to support this database
enable_extension "ltree"
Expand Down Expand Up @@ -577,6 +577,56 @@
t.index ["follows_count"], name: "index_decidim_debates_debates_on_follows_count"
end

create_table "decidim_dummy_resources_coauthorable_dummy_resources", force: :cascade do |t|
t.jsonb "translatable_text"
t.string "title"
t.string "body"
t.text "address"
t.float "latitude"
t.float "longitude"
t.datetime "published_at"
t.integer "coauthorships_count", default: 0, null: false
t.integer "endorsements_count", default: 0, null: false
t.integer "comments_count", default: 0, null: false
t.bigint "decidim_component_id"
t.bigint "decidim_category_id"
t.bigint "decidim_scope_id"
t.string "reference"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
end

create_table "decidim_dummy_resources_dummy_resources", force: :cascade do |t|
t.jsonb "translatable_text"
t.jsonb "title"
t.string "body"
t.text "address"
t.float "latitude"
t.float "longitude"
t.datetime "published_at"
t.integer "coauthorships_count", default: 0, null: false
t.integer "endorsements_count", default: 0, null: false
t.integer "comments_count", default: 0, null: false
t.integer "follows_count", default: 0, null: false
t.bigint "decidim_component_id"
t.integer "decidim_author_id"
t.string "decidim_author_type"
t.integer "decidim_user_group_id"
t.bigint "decidim_category_id"
t.bigint "decidim_scope_id"
t.string "reference"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
end

create_table "decidim_dummy_resources_nested_dummy_resources", force: :cascade do |t|
t.jsonb "translatable_text"
t.string "title"
t.bigint "dummy_resource_id"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
end

create_table "decidim_editor_images", force: :cascade do |t|
t.bigint "decidim_author_id", null: false
t.bigint "decidim_organization_id", null: false
Expand All @@ -591,7 +641,7 @@
t.bigint "resource_id"
t.string "decidim_author_type"
t.bigint "decidim_author_id"
t.integer "decidim_user_group_id"
t.integer "decidim_user_group_id", default: 0
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["decidim_author_type", "decidim_author_id"], name: "idx_endorsements_authors"
Expand Down Expand Up @@ -1681,6 +1731,18 @@
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.index ["decidim_organization_id"], name: "index_decidim_templates_organization"
t.index ["templatable_type", "templatable_id"], name: "index_decidim_templates_templatable"
end

create_table "decidim_term_customizer_constraints", force: :cascade do |t|
t.bigint "decidim_organization_id", null: false
t.string "subject_type"
Expand Down

0 comments on commit 5501663

Please sign in to comment.