Skip to content

Commit

Permalink
Upgrade rails_admin gem to 3.x
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-hank committed Dec 8, 2022
1 parent a9d072a commit 7b66634
Show file tree
Hide file tree
Showing 26 changed files with 186 additions and 71 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ gem 'rack-attack'
# we fall back to the earlier enable_rails_patches behavior.
gem 'rack-mini-profiler', require: ['enable_rails_patches', 'rack-mini-profiler']
gem 'rails', '~> 6.1.0'
gem 'rails_admin', '~> 2.x'
gem 'rails_admin', '~> 3.x'
gem 'rails_admin_tag_list', '~> 0.2.1'
gem 'recaptcha'
gem 'recipient_interceptor', require: false
Expand Down
39 changes: 17 additions & 22 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ GEM
builder (3.2.4)
byebug (11.1.3)
cancancan (3.4.0)
capybara (3.37.1)
capybara (3.38.0)
addressable
matrix
mini_mime (>= 0.1.3)
Expand Down Expand Up @@ -224,8 +224,9 @@ GEM
ffi (~> 1.0)
globalid (1.0.0)
activesupport (>= 5.0)
haml (5.2.2)
temple (>= 0.8.0)
haml (6.0.12)
temple (>= 0.8.2)
thor
tilt
haml-rails (2.1.0)
actionpack (>= 5.1)
Expand All @@ -240,7 +241,7 @@ GEM
i18n (1.12.0)
concurrent-ruby (~> 1.0)
jquery-placeholder-rails (2.1.2)
jquery-rails (4.5.0)
jquery-rails (4.5.1)
rails-dom-testing (>= 1, < 3)
railties (>= 4.2.0)
thor (>= 0.14, < 2.0)
Expand Down Expand Up @@ -327,17 +328,14 @@ GEM
pry-rails (0.3.9)
pry (>= 0.10.4)
public_suffix (5.0.0)
racc (1.6.0)
racc (1.6.1)
rack (2.2.4)
rack-accept (0.4.5)
rack (>= 0.4)
rack-attack (6.6.1)
rack (>= 1.0, < 3)
rack-mini-profiler (3.0.0)
rack (>= 1.2.0)
rack-pjax (1.1.0)
nokogiri (~> 1.5)
rack (>= 1.1)
rack-test (2.0.2)
rack (>= 1.3)
rails (6.1.7)
Expand Down Expand Up @@ -367,18 +365,12 @@ GEM
rails-i18n (7.0.5)
i18n (>= 0.7, < 2)
railties (>= 6.0.0, < 8)
rails_admin (2.2.1)
rails_admin (3.1.0)
activemodel-serializers-xml (>= 1.0)
builder (~> 3.1)
haml (>= 4.0, < 6)
jquery-rails (>= 3.0, < 5)
jquery-ui-rails (>= 5.0, < 7)
kaminari (>= 0.14, < 2.0)
nested_form (~> 0.3)
rack-pjax (>= 0.7)
rails (>= 5.0, < 7)
remotipart (~> 1.3)
sassc-rails (>= 1.3, < 3)
rails (>= 6.0, < 8)
turbo-rails (~> 1.0)
rails_admin_tag_list (0.2.1)
rails_admin (>= 0.6)
railties (6.1.7)
Expand All @@ -398,8 +390,7 @@ GEM
record_tag_helper (1.0.1)
actionview (>= 5)
redcarpet (3.5.1)
regexp_parser (2.6.0)
remotipart (1.4.4)
regexp_parser (2.6.1)
responders (3.0.1)
actionpack (>= 5.0)
railties (>= 5.0)
Expand Down Expand Up @@ -479,7 +470,7 @@ GEM
sprockets (>= 3.0.0)
stackprof (0.2.22)
sync (0.5.0)
temple (0.8.2)
temple (0.9.1)
term-ansicolor (1.7.1)
tins (~> 1.0)
terrapin (0.6.0)
Expand All @@ -492,6 +483,10 @@ GEM
timecop (0.9.5)
tins (1.31.1)
sync
turbo-rails (1.3.2)
actionpack (>= 6.0.0)
activejob (>= 6.0.0)
railties (>= 6.0.0)
turnout (2.5.0)
i18n (>= 0.7, < 2)
rack (>= 1.3, < 3)
Expand All @@ -517,7 +512,7 @@ GEM
websocket-extensions (0.1.5)
xpath (3.2.0)
nokogiri (~> 1.8)
zeitwerk (2.6.1)
zeitwerk (2.6.6)

PLATFORMS
ruby
Expand Down Expand Up @@ -572,7 +567,7 @@ DEPENDENCIES
rack-test
rails (~> 6.1.0)
rails-controller-testing
rails_admin (~> 2.x)
rails_admin (~> 3.x)
rails_admin_tag_list (~> 0.2.1)
recaptcha
recipient_interceptor
Expand Down
2 changes: 0 additions & 2 deletions app/assets/config/manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,5 @@
//= link_tree ../images
//= link_directory ../javascripts .js
//= link_directory ../stylesheets .css
//= link rails_admin/rails_admin.css
//= link rails_admin/rails_admin.js
//= link rails_admin/custom/ui.js
//= link piwik.js
14 changes: 13 additions & 1 deletion app/assets/javascripts/rails_admin/custom/notice_edit_form.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class NoticeEditForm {
constructor() {
let that = this;

$(document).on('pjax:complete', function(event, request) {
$(document).on('turbo:render', function(event, request) {
that.notice_form_actions();
});

Expand Down Expand Up @@ -49,6 +49,10 @@ class NoticeEditForm {
set_works_editor() {
let field_name = `${this.form_model_type}_works_json`;

if (document.querySelector(`#${field_name}_field`) == null) {
return;
}

let editor = new JSONEditor(document.querySelector(`#${field_name}_field > div`), {
...this.notice_edit_form_default_editor_params,
required_by_default: true,
Expand Down Expand Up @@ -134,6 +138,10 @@ class NoticeEditForm {
let input_field_id = `${that.form_model_type}_${type}_list`;
let field_id = `${type}_list_field`;

if (document.querySelector(`#${input_field_id}_field`) == null) {
return;
}

let editor = new JSONEditor(document.querySelector(`#${input_field_id}_field > div`), {
...that.notice_edit_form_default_editor_params,
schema: {
Expand Down Expand Up @@ -165,6 +173,10 @@ class NoticeEditForm {
set_customizations_editor() {
let field_name = `${this.form_model_type}_customizations`;

if (document.querySelector(`#${field_name}_field`) == null) {
return;
}

let editor = new JSONEditor(document.querySelector(`#${field_name}_field > div`), {
...this.notice_edit_form_default_editor_params,
required_by_default: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,5 @@ requireType = ->

$(document).ready -> addHandlers()
$(document).ready -> requireType()
$(document).on 'pjax:end', -> addHandlers()
$(document).on 'pjax:end', -> requireType()
$(document).on 'turbo:render', -> addHandlers()
$(document).on 'turbo:render', -> requireType()
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
$(document).on('pjax:complete', function(event, request) {
$(document).on('turbo:render', function(event, request) {
edit_user_form_actions();
});

Expand Down
4 changes: 0 additions & 4 deletions app/assets/stylesheets/rails_admin/custom/theming.scss
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,6 @@ aside#redaction-tools {
[id$='_jurisdiction_list_field'],
[id$='_regulation_list_field'],
[id$='_customizations_field'] {
.form-group {
margin-left: auto;
}

h3, .card {
font-size: 14px;
}
Expand Down
10 changes: 10 additions & 0 deletions app/assets/stylesheets/rails_admin/custom/variables.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Keep info and primary colors the same as Bootstrap 3
$primary: #019CE0;
$info: #5bc0de;

// Force light color for top-nav links
$navbar-dark-color: #ffffff;

// Contrast ratio used to calculate color for text within elements (ie. buttons)
// https://getbootstrap.com/docs/5.0/customize/sass/#color-contrast
$min-contrast-ratio: 2;
2 changes: 2 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ def resource_not_found(exception = false)
def layout_by_resource
if devise_controller?
'sessions'
elsif self.class.name.include? 'RailsAdmin'
'rails_admin/application'
else
'application'
end
Expand Down
32 changes: 6 additions & 26 deletions app/models/notice.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,26 +70,6 @@ class Notice < ApplicationRecord

VALID_ACTIONS = %w[Yes No Partial Unspecified].freeze

OTHER_TOPIC = 'Uncategorized'.freeze

TYPES_TO_TOPICS = {
'DMCA' => 'Copyright',
'Counterfeit' => 'Counterfeit',
'Counternotice' => 'Copyright',
'CourtOrder' => 'Court Orders',
'DataProtection' => 'EU - Right to Be Forgotten',
'Defamation' => 'Defamation',
'GovernmentRequest' => 'Government Requests',
'LawEnforcementRequest' => 'Law Enforcement Requests',
'PrivateInformation' => 'Right of Publicity',
'Trademark' => 'Trademark',
'Other' => OTHER_TOPIC,
'Placeholder' => OTHER_TOPIC
}.freeze

TYPES = TYPES_TO_TOPICS.keys
TOPICS = TYPES_TO_TOPICS.values

# == Relationships ========================================================
belongs_to :reviewer, class_name: 'User'

Expand All @@ -109,7 +89,7 @@ class Notice < ApplicationRecord
# == Attributes ===========================================================
delegate :country_code, to: :recipient, allow_nil: true

%i[sender principal recipient submitter attorney] .each do |entity|
%i[sender principal recipient submitter attorney].each do |entity|
delegate :name, :country_code, to: entity, prefix: true, allow_nil: true
end

Expand Down Expand Up @@ -156,11 +136,11 @@ def self.label
end

def self.type_models
(TYPES - ['Counternotice']).map(&:constantize).freeze
(Lumen::TYPES - ['Counternotice']).map(&:constantize).freeze
end

def self.display_models
(TYPES - ['Placeholder']).map(&:constantize).freeze
(Lumen::TYPES - ['Placeholder']).map(&:constantize).freeze
end

def self.available_for_review
Expand Down Expand Up @@ -221,14 +201,14 @@ def reset_type
end

def reset_type=(value)
unless value.in?(TYPES)
unless value.in?(Lumen::TYPES)
fail ActiveModel::MissingAttributeError.new("Cannot reset Notice type to: #{value}")
end
self[:type] = value
end

def reset_type_enum
TYPES
Lumen::TYPES
end

def language_enum
Expand Down Expand Up @@ -370,7 +350,7 @@ def set_published!
end

def notice_topic_map
topic = TYPES_TO_TOPICS.key?(self.type) ? TYPES_TO_TOPICS[self.type] : OTHER_TOPIC
topic = Lumen::TYPES_TO_TOPICS.key?(self.type) ? Lumen::TYPES_TO_TOPICS[self.type] : Lumen::OTHER_TOPIC
Topic.find_or_create_by(name: topic)
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
name: 'redact_everywhere',
id: "redact-selected-everywhere",
class: 'btn btn-danger',
confirm: "Redact selected text in all notices that are under review?"
data: {
confirm: "Redact selected text in all notices that are under review?"
}
)
%>
<% end %>
17 changes: 17 additions & 0 deletions config/initializers/lumen_settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,20 @@
Lumen.const_set :UNKNOWN_WORK, Work.unknown rescue nil
Lumen.const_set :TRUNCATION_TOKEN_URLS_ACTIVE_PERIOD, 24.hours
Lumen.const_set :REDACTION_MASK, '[REDACTED]'.freeze
Lumen.const_set :OTHER_TOPIC, 'Uncategorized'.freeze
Lumen.const_set :TYPES_TO_TOPICS, {
'DMCA' => 'Copyright',
'Counterfeit' => 'Counterfeit',
'Counternotice' => 'Copyright',
'CourtOrder' => 'Court Orders',
'DataProtection' => 'EU - Right to Be Forgotten',
'Defamation' => 'Defamation',
'GovernmentRequest' => 'Government Requests',
'LawEnforcementRequest' => 'Law Enforcement Requests',
'PrivateInformation' => 'Right of Publicity',
'Trademark' => 'Trademark',
'Other' => Lumen::OTHER_TOPIC,
'Placeholder' => Lumen::OTHER_TOPIC
}.freeze
Lumen.const_set :TYPES, Lumen::TYPES_TO_TOPICS.keys
Lumen.const_set :TOPICS, Lumen::TYPES_TO_TOPICS.values
17 changes: 16 additions & 1 deletion config/initializers/rails_admin.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require 'lumen'
require 'rails_admin/config/actions/redact_queue'
require 'rails_admin/config/actions/redact_notice'
require 'rails_admin/config/actions/pdf_requests'
Expand All @@ -6,6 +7,7 @@
require 'rails_admin/config/actions/reject_api_submitter_request'
require 'rails_admin/config/actions/top_notices_token_urls'
require 'rails_admin/config/fields/types/datetime_timezoned'
require 'rails_admin/extensions/history'

# Monkeypatches
RailsAdmin::Config::Fields::Types::Datetime.prepend RailsAdmin::Config::Fields::Types::DatetimeTimezoned
Expand All @@ -20,6 +22,8 @@

config.authorize_with :cancancan

config.asset_source = :sprockets

config.audit_with :history, 'User'
config.audit_with :history, 'Role'
config.audit_with :history, 'Notice'
Expand Down Expand Up @@ -57,7 +61,7 @@
top_notices_token_urls
end

['Notice', Notice::TYPES].flatten.each do |notice_type|
['Notice', Lumen::TYPES].flatten.each do |notice_type|
config.audit_with :history, notice_type

config.model notice_type do
Expand Down Expand Up @@ -209,6 +213,10 @@
configure(:works) do
hide
end

configure :documents_update_notification_notice do
hide
end
end
end
end
Expand Down Expand Up @@ -307,6 +315,10 @@
%w[original supporting]
end
end

configure :youtube_import_file_location do
hide
end
end
end

Expand Down Expand Up @@ -538,6 +550,9 @@ def custom_work_label
config.model 'Comfy::Cms::Translation' do
visible false
end
config.model 'RailsAdmin::History' do
visible false
end
# == END ============================================================

def notice_token_urls_count_links(bindings, perm = false)
Expand Down
Loading

0 comments on commit 7b66634

Please sign in to comment.