Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#1264] Update PublicBody#disclosure_log to be translatable #7947

Merged
merged 1 commit into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 # :nodoc:
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
Loading