Skip to content

Commit

Permalink
Update PublicBody#disclosure_log to be translatable
Browse files Browse the repository at this point in the history
Adds temp rake task to migrate existing data into the translation column
which already exists in the database.

Will need a migration to remove `PublicBody#disclosure_log` in a future
release.

Fixes #1264
  • Loading branch information
gbp committed Oct 11, 2023
1 parent f4ff17e commit 94b9f9c
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 10 deletions.
4 changes: 2 additions & 2 deletions app/controllers/admin_public_body_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,8 @@ def public_body_params
translatable_params(
params[:public_body],
translated_keys: [:locale, :name, :short_name, :request_email,
:publication_scheme],
general_keys: [:tag_string, :home_page, :disclosure_log,
:publication_scheme, :disclosure_log],
general_keys: [:tag_string, :home_page,
:last_edit_comment, :last_edit_editor]
)
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/public_body.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def self.admin_title
strip_attributes allow_empty: true, only: %i[request_email]

translates :name, :short_name, :request_email, :url_name, :first_letter,
:publication_scheme
:publication_scheme, :disclosure_log

# Cannot be grouped at top as it depends on the `translates` macro
include Translatable
Expand Down
7 changes: 0 additions & 7 deletions app/views/admin_public_body/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,6 @@
</div>
</div>

<div class="control-group">
<label for="public_body_disclosure_log" class="control-label">Disclosure log URL</label>
<div class="controls">
<%= f.url_field :disclosure_log, size: 60, class: 'span4' %>
</div>
</div>

<div class="control-group">
<label for="public_body_last_edit_comment" class="control-label"><strong>Comment</strong> for this edit</label>
<div class="controls">
Expand Down
7 changes: 7 additions & 0 deletions app/views/admin_public_body/_locale_fields.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,11 @@
<%= t.url_field :publication_scheme, size: 60, class: 'span4' %>
</div>
</div>

<div class="control-group">
<%= t.label :disclosure_log, 'Disclosure log URL', :class => 'control-label' %>
<div class="controls">
<%= t.url_field :disclosure_log, size: 60, class: 'span4' %>
</div>
</div>
</div>
25 changes: 25 additions & 0 deletions lib/tasks/temp.rake
Original file line number Diff line number Diff line change
@@ -1,4 +1,29 @@
namespace :temp do
desc 'Migrate PublicBody#disclosure_log to translation model'
task migrate_disclosure_log: :environment do
class PublicBodyWithoutTranslations < ApplicationRecord

Check warning on line 4 in lib/tasks/temp.rake

View workflow job for this annotation

GitHub Actions / build

[rubocop] reported by reviewdog 🐶 Style/Documentation: Missing top-level documentation comment for class PublicBodyWithoutTranslations. Raw Output: lib/tasks/temp.rake:4:5: C: Style/Documentation: Missing top-level documentation comment for class PublicBodyWithoutTranslations. class PublicBodyWithoutTranslations < ApplicationRecord ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
self.table_name = 'public_bodies'

def with_translation
AlaveteliLocalization.with_default_locale { PublicBody.find(id) }
end
end

scope = PublicBodyWithoutTranslations.where.not(disclosure_log: nil)
count = scope.count

scope.find_each.with_index do |pb, index|
pb.with_translation.update(disclosure_log: pb.disclosure_log)

erase_line
print "Migrate PublicBody#disclosure_log to " \
"PublicBody::Translation#disclosure_log #{index + 1}/#{count}"
end

erase_line
puts "Migrating to PublicBody::Translation#disclosure_log completed."
end

desc 'Migrate current User#url_name to new slug model'
task migrate_user_slugs: :environment do
scope = User.left_joins(:slugs).where(slugs: { id: nil })
Expand Down

0 comments on commit 94b9f9c

Please sign in to comment.