Skip to content

Commit

Permalink
SRCH-2057 remove Super Admin controls for legacy SERP features (#731)
Browse files Browse the repository at this point in the history
- add Rubocop configs for ActiveScaffold controllers
- resolve some Rubocop offenses
  • Loading branch information
MothOnMars authored Jun 3, 2021
1 parent b4d1b56 commit 0a297ef
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 164 deletions.
31 changes: 19 additions & 12 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,34 @@ AllCops:
- app/controllers/sites/templated_font_and_colors_controller.rb
- app/controllers/sites/templates_controller.rb

Metrics/BlockLength:
Exclude:
# Exclude ActiveScaffold-based controllers
- app/controllers/admin/**/*

Style/LambdaCall:
Exclude:
# Exclude files relying on Jbuilder DSL
# https://github.com/rubocop-hq/rubocop/issues/3402
- 'app/models/elastic_data/*'
- 'app/models/custom_index_queries/*'
- 'app/models/logstash_queries/*'
- 'app/models/watcher.rb'
- 'lib/analytics_dsl.rb'
- 'lib/watcher_dsl.rb'
- app/models/elastic_data/*
- app/models/custom_index_queries/*
- app/models/logstash_queries/*
- app/models/watcher.rb
- lib/analytics_dsl.rb
- lib/watcher_dsl.rb

Style/MethodCallWithArgsParentheses:
IgnoreMacros: true
Exclude:
# Exclude files relying on Jbuilder DSL
- 'app/models/elastic_data/*'
- 'app/models/custom_index_queries/*'
- 'app/models/logstash_queries/*'
- 'app/models/watcher.rb'
- 'lib/analytics_dsl.rb'
- 'lib/watcher_dsl.rb'
- app/models/elastic_data/*
- app/models/custom_index_queries/*
- app/models/logstash_queries/*
- app/models/watcher.rb
- lib/analytics_dsl.rb
- lib/watcher_dsl.rb
# Exclude ActiveScaffold-based controllers
- app/controllers/admin/**/*

Style/NumericLiterals:
Exclude:
Expand Down
168 changes: 81 additions & 87 deletions app/controllers/admin/affiliates_controller.rb
Original file line number Diff line number Diff line change
@@ -1,105 +1,112 @@
class Admin::AffiliatesController < Admin::AdminController
# frozen_string_literal: true

class Admin::AffiliatesController < Admin::AdminController
active_scaffold :affiliate do |config|
config.label = 'Sites'
config.actions.exclude :delete, :search
config.actions.add :field_search
config.field_search.columns = :id, :name, :display_name, :website

attribute_columns = config.columns.reject do |column|
column.association or column.name =~ /(_created_at|_updated_at|agency_id|css_properties|content_type|file_name|_image|json|label|_logo|_mappings|scope_ids|size|uses_managed_header_footer|active_template_id|template_schema|template_id)\z/
# These columns will be dropped after the legacy SERP is removed
# https://cm-jira.usa.gov/browse/SRCH-2107
legacy_columns = %i[
external_css_url
force_mobile_format
has_staged_content
uses_managed_header_footer
]
# These columns will be dropped after all Search Consumer code is removed
# https://cm-jira.usa.gov/browse/SRCH-1080
sc_template_columns = %i[
active_template_id
search_consumer_search_enabled
template_id
template_schema
]
deprecated_columns = (legacy_columns + sc_template_columns).join('|')
column.association or column.name =~ /(_created_at|_updated_at|agency_id|css_properties|content_type|file_name|_image|json|label|_logo|_mappings|scope_ids|size|#{deprecated_columns})\z/
end.map(&:name)
attribute_columns << :agency
attribute_columns.sort!

all_columns = attribute_columns
all_columns |= %i(mobile_logo_url header_image_url uses_managed_header_footer staged_uses_managed_header_footer)

virtual_columns = %i(dc_contributor dc_subject dc_publisher
last_month_query_count
header_footer_css staged_header_footer_css header staged_header footer staged_footer
features external_tracking_code submitted_external_tracking_code
header_tagline_font_family header_tagline_font_size header_tagline_font_style
related_sites_dropdown_label footer_fragment)
all_columns |= %i[mobile_logo_url]

virtual_columns = %i[last_month_query_count
features
external_tracking_code
submitted_external_tracking_code
header_tagline_font_family
header_tagline_font_size
header_tagline_font_style
related_sites_dropdown_label
footer_fragment]
all_columns |= virtual_columns
config.columns = all_columns

list_columns = %i(id display_name name website site_domains search_engine created_at updated_at recent_user_activity)
list_columns = %i[id display_name name website site_domains search_engine created_at updated_at recent_user_activity]
config.list.columns = list_columns

export_columns = [list_columns, all_columns].flatten.uniq
actions.add :export
config.export.columns = export_columns
config.export.default_deselected_columns = %i(api_access_key
config.export.default_deselected_columns = %i[api_access_key
dc_contributor
dc_subject
dc_publisher
external_css_url
external_tracking_code
fetch_concurrency
footer
footer_fragment
ga_web_property_id
has_staged_content
header
header_footer_css
header_tagline_font_family
header_tagline_font_size
header_tagline_font_style
last_month_query_count
navigation_dropdown_label
related_sites_dropdown_label
staged_footer
staged_header
staged_header_footer_css
submitted_external_tracking_code
staged_uses_managed_header_footer
theme
uses_managed_header_footer)

theme]

config.list.sorting = { :created_at => :desc }
config.list.sorting = { created_at: :desc }

[:header_footer_css, :staged_header_footer_css,
:header, :staged_header, :footer, :staged_footer,
:external_tracking_code, :submitted_external_tracking_code].each do |c|
[:external_tracking_code, :submitted_external_tracking_code].each do |c|
config.columns[c].form_ui = :textarea
end

update_columns = %i[
active
agency
bing_v5_key
dap_enabled
display_name
domain_control_validation_code
fetch_concurrency
force_mobile_format
ga_web_property_id
gets_blended_results
gets_commercial_results_on_blended_search
gets_i14y_results
google_cx
google_key
i14y_date_stamp_enabled
is_bing_image_search_enabled
is_federal_register_document_govbox_enabled
is_medline_govbox_enabled
is_photo_govbox_enabled
is_related_searches_enabled
is_rss_govbox_enabled
is_sayt_enabled
is_video_govbox_enabled
jobs_enabled
locale
name
raw_log_access_enabled
search_consumer_search_enabled
search_engine
website
]
active
agency
bing_v5_key
dap_enabled
display_name
domain_control_validation_code
fetch_concurrency
ga_web_property_id
gets_blended_results
gets_commercial_results_on_blended_search
gets_i14y_results
google_cx
google_key
i14y_date_stamp_enabled
is_bing_image_search_enabled
is_federal_register_document_govbox_enabled
is_medline_govbox_enabled
is_photo_govbox_enabled
is_related_searches_enabled
is_rss_govbox_enabled
is_sayt_enabled
is_video_govbox_enabled
jobs_enabled
locale
name
raw_log_access_enabled
search_consumer_search_enabled
search_engine
website
]
config.update.columns = []
enable_disable_column_regex = /^(is\_|dap_enabled|force_mobile_format|gets_blended_results|gets_commercial_results_on_blended_search|jobs_enabled|raw_log_access_enabled|search_consumer_search_enabled|gets_i14y_results)/.freeze
enable_disable_column_regex = /^(is_|dap_enabled|gets_blended_results|gets_commercial_results_on_blended_search|jobs_enabled|raw_log_access_enabled|search_consumer_search_enabled|gets_i14y_results)/.freeze

config.update.columns.add_subgroup 'Settings' do |name_group|
name_group.add *update_columns.reject { |column| column =~ enable_disable_column_regex }
Expand All @@ -108,52 +115,41 @@ class Admin::AffiliatesController < Admin::AdminController
end

config.update.columns.add_subgroup 'Enable/disable Settings' do |name_group|
name_group.add *update_columns.reject { |column| column !~ enable_disable_column_regex }
name_group.add *update_columns.select { |column| column =~ enable_disable_column_regex }
name_group.collapsed = true
end

config.update.columns.add_subgroup 'Display Settings' do |name_group|
display_columns = %i(footer_fragment
display_columns = %i[footer_fragment
header_tagline_font_family
header_tagline_font_size
header_tagline_font_style
no_results_pointer
page_one_more_results_pointer
navigation_dropdown_label
related_sites_dropdown_label)
related_sites_dropdown_label]
name_group.add *display_columns
name_group.collapsed = true
end


config.update.columns.add_subgroup 'Analytics-Tracking Code' do |name_group|
name_group.add :ga_web_property_id, :domain_control_validation_code,
:external_tracking_code, :submitted_external_tracking_code
name_group.collapsed = true
end

config.update.columns.add_subgroup 'Dublin Core Mappings' do |name_group|
name_group.add :dc_contributor, :dc_subject, :dc_publisher
name_group.collapsed = true
end
config.action_links.add 'analytics', label: 'Analytics', type: :member, page: true

config.update.columns.add_subgroup 'Legacy Display Settings' do |name_group|
name_group.add :has_staged_content,
:uses_managed_header_footer, :staged_uses_managed_header_footer,
:header_footer_css, :staged_header_footer_css,
:header, :staged_header, :footer, :staged_footer,
:external_css_url
name_group.collapsed = true
end

config.action_links.add "analytics", :label => "Analytics", :type => :member, :page => true

excluded_show_columns = %i(footer header header_footer_css staged_footer staged_header staged_header_footer_css)
show_columns = list_columns
show_columns |= all_columns.reject { |column| excluded_show_columns.include? column }
show_columns |= all_columns
config.show.columns = show_columns

config.create.columns = [:display_name, :name, :website, :locale]
config.create.columns = %i[
display_name
name
website
locale
]

config.columns[:agency].form_ui = :select

Expand All @@ -162,23 +158,21 @@ class Admin::AffiliatesController < Admin::AdminController

config.columns[:footer_fragment].form_ui = :textarea

config.columns[:header_image_url].label = 'Legacy Logo URL'

config.columns[:header_tagline_font_family].form_ui = :select
config.columns[:header_tagline_font_family].options = { options: HeaderTaglineFontFamily::ALL }

config.columns[:header_tagline_font_size].description = 'Value should be in em. Default value: 1.3em'

config.columns[:header_tagline_font_style].form_ui = :select
config.columns[:header_tagline_font_style].options = { options: %w(italic normal) }
config.columns[:header_tagline_font_style].options = { options: %w[italic normal] }

config.columns[:locale].form_ui = :select
config.columns[:locale].options = { options: Language.order(:name).pluck(:code) }

config.columns[:mobile_logo_url].label = 'Logo URL'

config.columns[:search_engine].form_ui = :select
config.columns[:search_engine].options = { :options => SEARCH_ENGINES }
config.columns[:search_engine].options = { options: SEARCH_ENGINES }

config.columns[:theme].form_ui = :select
config.columns[:theme].options = { include_blank: '- select -',
Expand All @@ -188,6 +182,6 @@ class Admin::AffiliatesController < Admin::AdminController
end

def analytics
redirect_to new_site_queries_path(Affiliate.find params[:id])
redirect_to new_site_queries_path(Affiliate.find(params[:id]))
end
end
4 changes: 0 additions & 4 deletions app/models/affiliate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -429,10 +429,6 @@ def mobile_logo_url
mobile_logo.url rescue 'unable to retrieve mobile logo url' if mobile_logo_file_name.present?
end

def header_image_url
header_image.url rescue 'unable to retrieve header image url' if header_image_file_name.present?
end

def last_month_query_count
prev_month = Date.current.prev_month
count_query = CountQuery.new(name, 'search')
Expand Down
2 changes: 0 additions & 2 deletions features/admin.feature
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ Feature: Administration
And I should see "Enable/disable Settings (Show)"
And I should see "Display Settings (Show)"
And I should see "Analytics-Tracking Code (Show)"
And I should see "Dublin Core Mappings (Show)"
And I should see "Legacy Display Settings (Show)"
When I follow "Show" within the first subsection row
And I fill in "Display name" with "New Name"
And I press "Update"
Expand Down
Loading

0 comments on commit 0a297ef

Please sign in to comment.