diff --git a/app/controllers/admin/budgets_controller.rb b/app/controllers/admin/budgets_controller.rb
index ab2050d46..00d238260 100644
--- a/app/controllers/admin/budgets_controller.rb
+++ b/app/controllers/admin/budgets_controller.rb
@@ -59,7 +59,6 @@ class Admin::BudgetsController < Admin::BaseController
valid_attributes = [:phase,
:currency_symbol,
:voting_style,
- :main_link_url,
administrator_ids: [],
valuator_ids: [],
image_attributes: image_attributes
diff --git a/app/controllers/admin/budgets_wizard/budgets_controller.rb b/app/controllers/admin/budgets_wizard/budgets_controller.rb
index d10ea0a27..92003fe5a 100644
--- a/app/controllers/admin/budgets_wizard/budgets_controller.rb
+++ b/app/controllers/admin/budgets_wizard/budgets_controller.rb
@@ -37,7 +37,7 @@ class Admin::BudgetsWizard::BudgetsController < Admin::BudgetsWizard::BaseContro
end
def allowed_params
- valid_attributes = [:currency_symbol, :voting_style, :main_link_url, administrator_ids: [],
+ valid_attributes = [:currency_symbol, :voting_style, administrator_ids: [],
valuator_ids: [], image_attributes: image_attributes]
valid_attributes + [translation_params(Budget)]
diff --git a/app/controllers/concerns/admin/budget_phases_actions.rb b/app/controllers/concerns/admin/budget_phases_actions.rb
index 5d0ce53e2..83efdf2df 100644
--- a/app/controllers/concerns/admin/budget_phases_actions.rb
+++ b/app/controllers/concerns/admin/budget_phases_actions.rb
@@ -40,7 +40,7 @@ module Admin::BudgetPhasesActions
end
def budget_phase_params
- valid_attributes = [:starts_at, :ends_at, :enabled, :main_link_url,
+ valid_attributes = [:starts_at, :ends_at, :enabled,
image_attributes: image_attributes]
params.require(:budget_phase).permit(*valid_attributes, translation_params(Budget::Phase))
end
diff --git a/app/models/budget.rb b/app/models/budget.rb
index 43105de14..6fe8ad07e 100644
--- a/app/models/budget.rb
+++ b/app/models/budget.rb
@@ -5,7 +5,7 @@ class Budget < ApplicationRecord
include Reportable
include Imageable
- translates :name, :main_link_text, touch: true
+ translates :name, :main_link_text, :main_link_url, touch: true
include Globalizable
class Translation
@@ -24,11 +24,11 @@ class Budget < ApplicationRecord
VOTING_STYLES = %w[knapsack approval].freeze
validates_translation :name, presence: true
+ validates_translation :main_link_url, presence: true, unless: -> { main_link_text.blank? }
validates :phase, inclusion: { in: Budget::Phase::PHASE_KINDS }
validates :currency_symbol, presence: true
validates :slug, presence: true, format: /\A[a-z0-9\-_]+\z/
validates :voting_style, inclusion: { in: VOTING_STYLES }
- validates :main_link_url, presence: true, if: -> { main_link_text.present? }
has_many :investments, dependent: :destroy
has_many :ballots, dependent: :destroy
diff --git a/app/models/budget/phase.rb b/app/models/budget/phase.rb
index 0b27209f7..ae0c37634 100644
--- a/app/models/budget/phase.rb
+++ b/app/models/budget/phase.rb
@@ -9,6 +9,7 @@ class Budget
translates :summary, touch: true
translates :description, touch: true
translates :main_link_text, touch: true
+ translates :main_link_url, touch: true
include Globalizable
include Sanitizable
include Imageable
@@ -19,9 +20,9 @@ class Budget
validates_translation :name, presence: true
validates_translation :description, length: { maximum: DESCRIPTION_MAX_LENGTH }
+ validates_translation :main_link_url, presence: true, unless: -> { main_link_text.blank? }
validates :budget, presence: true
validates :kind, presence: true, uniqueness: { scope: :budget }, inclusion: { in: ->(*) { PHASE_KINDS }}
- validates :main_link_url, presence: true, if: -> { main_link_text.present? }
validate :invalid_dates_range?
validate :prev_phase_dates_valid?
validate :next_phase_dates_valid?
diff --git a/config/locales/en/activerecord.yml b/config/locales/en/activerecord.yml
index 2613671b5..ce7e4f199 100644
--- a/config/locales/en/activerecord.yml
+++ b/config/locales/en/activerecord.yml
@@ -160,9 +160,9 @@ en:
voting_style: "Final voting style"
voting_style_knapsack: "Knapsack"
voting_style_approval: "Approval"
- main_link_url: "The link takes you to (add a link)"
budget/translation:
main_link_text: "Text on the link"
+ main_link_url: "The link takes you to (add a link)"
name: "Name"
budget/investment:
heading_id: "Heading"
@@ -231,12 +231,12 @@ en:
enabled: "Phase enabled"
ends_at: "End date"
starts_at: "Start date"
- main_link_url: "The link takes you to (add a link)"
budget/phase/translation:
name: "Name"
description: "Description"
summary: "Summary"
main_link_text: "Text on the link"
+ main_link_url: "The link takes you to (add a link)"
comment:
body: "Comment"
user: "User"
diff --git a/config/locales/es/activerecord.yml b/config/locales/es/activerecord.yml
index 8af18867c..74d03742a 100644
--- a/config/locales/es/activerecord.yml
+++ b/config/locales/es/activerecord.yml
@@ -160,9 +160,9 @@ es:
voting_style: "Estilo de la votación final"
voting_style_knapsack: Bolsa de dinero
voting_style_approval: Por aprobación
- main_link_url: "El enlace te lleva a (añade un enlace)"
budget/translation:
main_link_text: "Texto del enlace"
+ main_link_url: "El enlace te lleva a (añade un enlace)"
name: "Nombre"
budget/investment:
heading_id: "Partida presupuestaria"
@@ -231,12 +231,12 @@ es:
enabled: "Fase habilitada"
ends_at: "Fecha de fin"
starts_at: "Fecha de inicio"
- main_link_url: "El enlace te lleva a (añade un enlace)"
budget/phase/translation:
name: "Nombre"
description: "Descripción"
summary: "Resumen"
main_link_text: "Texto del enlace"
+ main_link_url: "El enlace te lleva a (añade un enlace)"
comment:
body: "Comentario"
user: "Usuario"
diff --git a/db/migrate/20211103090940_translate_budget_main_link_url.rb b/db/migrate/20211103090940_translate_budget_main_link_url.rb
new file mode 100644
index 000000000..8be6484a0
--- /dev/null
+++ b/db/migrate/20211103090940_translate_budget_main_link_url.rb
@@ -0,0 +1,6 @@
+class TranslateBudgetMainLinkUrl < ActiveRecord::Migration[5.2]
+ def change
+ add_column :budget_translations, :main_link_url, :string
+ remove_column :budgets, :main_link_url, :string
+ end
+end
diff --git a/db/migrate/20211103112944_translate_budget_phase_main_link_url.rb b/db/migrate/20211103112944_translate_budget_phase_main_link_url.rb
new file mode 100644
index 000000000..e92b7c52b
--- /dev/null
+++ b/db/migrate/20211103112944_translate_budget_phase_main_link_url.rb
@@ -0,0 +1,6 @@
+class TranslateBudgetPhaseMainLinkUrl < ActiveRecord::Migration[5.2]
+ def change
+ add_column :budget_phase_translations, :main_link_url, :string
+ remove_column :budget_phases, :main_link_url, :string
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 755e3b417..9758897cc 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: 2021_08_25_152739) do
+ActiveRecord::Schema.define(version: 2021_11_03_112944) do
# These are extensions that must be enabled in order to support this database
enable_extension "pg_trgm"
@@ -316,6 +316,7 @@ ActiveRecord::Schema.define(version: 2021_08_25_152739) do
t.text "summary"
t.string "name"
t.string "main_link_text"
+ t.string "main_link_url"
t.index ["budget_phase_id"], name: "index_budget_phase_translations_on_budget_phase_id"
t.index ["locale"], name: "index_budget_phase_translations_on_locale"
end
@@ -327,7 +328,6 @@ ActiveRecord::Schema.define(version: 2021_08_25_152739) do
t.datetime "starts_at"
t.datetime "ends_at"
t.boolean "enabled", default: true
- t.string "main_link_url"
t.index ["ends_at"], name: "index_budget_phases_on_ends_at"
t.index ["kind"], name: "index_budget_phases_on_kind"
t.index ["next_phase_id"], name: "index_budget_phases_on_next_phase_id"
@@ -349,6 +349,7 @@ ActiveRecord::Schema.define(version: 2021_08_25_152739) do
t.datetime "updated_at", null: false
t.string "name"
t.string "main_link_text"
+ t.string "main_link_url"
t.index ["budget_id"], name: "index_budget_translations_on_budget_id"
t.index ["locale"], name: "index_budget_translations_on_locale"
end
@@ -393,7 +394,6 @@ ActiveRecord::Schema.define(version: 2021_08_25_152739) do
t.text "description_informing"
t.string "voting_style", default: "knapsack"
t.boolean "published"
- t.string "main_link_url"
end
create_table "campaigns", id: :serial, force: :cascade do |t|