Skip to content

Commit

Permalink
🧹 Rubocop'd lengths and other low hanging fruit
Browse files Browse the repository at this point in the history
Various length metrics were disabled in this commit.  Also other various
cops that were easy to fix.
  • Loading branch information
kirkkwang committed Dec 14, 2023
1 parent 6859d73 commit 59626ef
Show file tree
Hide file tree
Showing 34 changed files with 102 additions and 17 deletions.
2 changes: 2 additions & 0 deletions app/controllers/catalog_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# frozen_string_literal: true

# rubocop:disable Metrics/ClassLength, Metrics/BlockLength
class CatalogController < ApplicationController
include BlacklightAdvancedSearch::Controller
include BlacklightRangeLimit::ControllerOverride
Expand Down Expand Up @@ -449,3 +450,4 @@ def show
render json: @document.to_h
end
end
# rubocop:enable Metrics/ClassLength, Metrics/BlockLength
2 changes: 2 additions & 0 deletions app/controllers/concerns/hyrax/works_controller_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ def decide_layout
# hopefully this can be refactored to be more reusable.
#
# Add uploaded_files to the parameters received by the actor.
# rubocop:disable Metrics/MethodLength
def attributes_for_actor
raw_params = params[hash_key_for_curation_concern]
attributes = if raw_params
Expand Down Expand Up @@ -360,6 +361,7 @@ def attributes_for_actor
browse_everything_urls
attributes
end
# rubocop:enable Metrics/MethodLength

def after_create_response
respond_to do |wants|
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/hyku/invitations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ def after_invite_path_for(_resource)

# override the standard invite so that accounts are added properly
# if they already exist on another tenant and invited if they do not
# rubocop:disable Metrics/AbcSize
def create
authorize! :grant_admin_role, User if params[:user][:role] == ::RolesService::ADMIN_ROLE
self.resource = User.find_by(email: params[:user][:email]) || invite_resource
Expand All @@ -27,6 +28,7 @@ def create
respond_with resource, location: after_invite_path_for(current_inviter, resource)
end
end
# rubocop:enable Metrics/AbcSize

protected

Expand Down
2 changes: 2 additions & 0 deletions app/controllers/hyrax/contact_form_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def new
@announcement_text = ContentBlock.for(:announcement)
end

# rubocop:disable Metrics/MethodLength, Metrics/AbcSize
def create
# not spam, form is valid, and captcha is valid
@captcha.values[:category] = params[:contact_form][:category]
Expand All @@ -65,6 +66,7 @@ def create
rescue RuntimeError => exception
handle_create_exception(exception)
end
# rubocop:enable Metrics/MethodLength, Metrics/AbcSize

def handle_create_exception(exception)
logger.error("Contact form failed to send: #{exception.inspect}")
Expand Down
15 changes: 11 additions & 4 deletions app/controllers/hyrax/dashboard/collections_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def edit
form
collection_type
# Gets original filename of an uploaded thumbnail. See #update
if ::SolrDocument.find(@collection.id).thumbnail_path.include? "uploaded_collection_thumbnails" and uploaded_thumbnail?
if ::SolrDocument.find(@collection.id).thumbnail_path.include? "uploaded_collection_thumbnails" && uploaded_thumbnail?
@thumbnail_filename = File.basename(uploaded_thumbnail_files.reject { |f| File.basename(f).include? @collection.id }.first)
end
end
Expand Down Expand Up @@ -209,17 +209,21 @@ def collection
# Renders a JSON response with a list of files in this collection
# This is used by the edit form to populate the thumbnail_id dropdown
# OVERRIDE: Hyrax 2.9 to use work titles for collection thumbnail select & to add an option to reset to the default thumbnail
# rubocop:disable Metrics/MethodLength, Metrics/AbcSize
def files
params[:q] = '' unless params[:q]
builder = Hyrax::CollectionMemberSearchBuilder.new(scope: self, collection: collection, search_includes_models: :works)
# get the default work image because we do not want to show any works in this dropdown that only have the default work image. this indicates that they have no files attached, and will throw an error if selected.
# get the default work image because we do not want to show any works in this
# dropdown that only have the default work image. this indicates that they have
# no files attached, and will throw an error if selected.
default_work_thumbnail_path = Site.instance.default_work_image&.url.presence || ActionController::Base.helpers.image_path('default.png')
work_with_no_files_thumbnail_path = ActionController::Base.helpers.image_path('work.png')
response = repository.search(builder.where(params[:q]).query)
# only return the works that have files, because these will be the only ones with a viable thumbnail
result = response.documents.reject do |document|
document["thumbnail_path_ss"].blank? || document["thumbnail_path_ss"].include?(default_work_thumbnail_path) || document["thumbnail_path_ss"].include?(work_with_no_files_thumbnail_path)
end .map do |document|
document["thumbnail_path_ss"].blank? || document["thumbnail_path_ss"].include?(default_work_thumbnail_path) ||
document["thumbnail_path_ss"].include?(work_with_no_files_thumbnail_path)
end.map do |document|
{ id: document["thumbnail_path_ss"].split('/').last.gsub(/\?.*/, ''), text: document["title_tesim"].first }
end
reset_thumbnail_option = {
Expand All @@ -229,6 +233,7 @@ def files
result << reset_thumbnail_option
render json: result
end
# rubocop:enable Metrics/MethodLength, Metrics/AbcSize

private

Expand Down Expand Up @@ -704,6 +709,7 @@ def after_update_errors(errors) # for valkyrie
end
end

# rubocop:disable Metrics/MethodLength
def process_uploaded_thumbnail(uploaded_file)
dir_name = UploadedCollectionThumbnailPathService.upload_dir(@collection)
saved_file = Rails.root.join(dir_name, uploaded_file.original_filename)
Expand All @@ -723,6 +729,7 @@ def process_uploaded_thumbnail(uploaded_file)
File.chmod(0o664, "#{dir_name}/#{@collection.id}_thumbnail.jpg")
File.chmod(0o664, "#{dir_name}/#{@collection.id}_card.jpg")
end
# rubocop:enable Metrics/MethodLength

## OVERRIDE Hyrax 3.4.0 handle file locations
def process_file_location(f)
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/hyrax/homepage_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def search_builder_class
layout 'homepage'
helper Hyrax::ContentBlockHelper

# rubocop:disable Metrics/MethodLength
def index
# BEGIN copy Hyrax prime's Hyrax::HomepageController#index
@presenter = presenter_class.new(current_ability, collections)
Expand Down Expand Up @@ -77,6 +78,7 @@ def index
document_export_formats(format)
end
end
# rubocop:enable Metrics/MethodLength

def browserconfig; end

Expand Down
2 changes: 2 additions & 0 deletions app/controllers/proprietor/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ def ensure_admin!
authorize! :read, :admin_dashboard
end

# rubocop:disable Metrics/MethodLength
def user_params
# remove blank passwords
params[:user].delete(:password) if params[:user] && params[:user][:password].blank?
Expand Down Expand Up @@ -117,6 +118,7 @@ def user_params
:preferred_locale,
role_ids: [])
end
# rubocop:enable Metrics/MethodLength

def find_user
@user ||= ::User.from_url_component(params[:id])
Expand Down
2 changes: 2 additions & 0 deletions app/forms/hyrax/forms/admin/appearance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@ def update!
end

# A list of parameters that are related to customizations
# rubocop:disable Metrics/MethodLength
def self.customization_params
%i[
body_font
Expand Down Expand Up @@ -400,6 +401,7 @@ def self.customization_params
default_work_image_text
]
end
# rubocop:enable Metrics/MethodLength

def font_import_body_url
body = body_font.split('|').first.to_s.tr(" ", "+")
Expand Down
2 changes: 2 additions & 0 deletions app/models/account.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

# Customer organization account
# rubocop:disable Metrics/ClassLength
class Account < ApplicationRecord
include AccountEndpoints
include AccountSettings
Expand Down Expand Up @@ -144,3 +145,4 @@ def cache_api?
cache_api
end
end
# rubocop:enable Metrics/ClassLength
6 changes: 6 additions & 0 deletions app/models/concerns/account_settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# All settings have a presedence order as follows
# Per Tenant Setting > ENV['HYKU_SETTING_NAME'] > ENV['HYRAX_SETTING_NAME'] > default

# rubocop:disable Metrics/ModuleLength
module AccountSettings
extend ActiveSupport::Concern
# rubocop:disable Metrics/BlockLength
Expand Down Expand Up @@ -79,6 +80,7 @@ def setting(name, args)
end
end

# rubocop:disable Metrics/MethodLength
def solr_collection_options
{
async: nil,
Expand All @@ -99,6 +101,7 @@ def solr_collection_options
snitch: nil
}
end
# rubocop:disable Metrics/MethodLength
end
# rubocop:enable Metrics/BlockLength

Expand Down Expand Up @@ -154,6 +157,7 @@ def set_smtp_settings
)
end

# rubocop:disable Metrics/AbcSize
def reload_library_config
Hyrax.config do |config|
config.contact_email = contact_email
Expand Down Expand Up @@ -188,4 +192,6 @@ def reload_library_config
ActionMailer::Base.default_url_options ||= {}
ActionMailer::Base.default_url_options[:protocol] = 'https'
end
# rubocop:enable Metrics/AbcSize
end
# rubocop:enable Metrics/ModuleLength
4 changes: 3 additions & 1 deletion app/models/concerns/account_switch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
module AccountSwitch
extend ActiveSupport::Concern

DOMAIN_REGEXP = %r{^[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,8}(:[0-9]{1,5})?(/.*)?$}ix
DOMAIN_REGEXP = %r{^[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,8}(:[0-9]{1,5})?(/.*)?$}ix.freeze

class_methods do
# rubocop:disable Metrics/MethodLength
def switch!(cname_or_name_or_account)
account = if cname_or_name_or_account.is_a?(Account)
cname_or_name_or_account
Expand All @@ -26,6 +27,7 @@ def switch!(cname_or_name_or_account)
Rails.logger.info "It looks like we're in single tenant mode. No tenant found for #{cname_or_name_or_account}"
end
end
# rubocop:enable Metrics/MethodLength
end

def switch!(cname_or_name_or_account)
Expand Down
6 changes: 6 additions & 0 deletions app/models/concerns/hyrax/ability/collection_ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
# OVERRIDE Hyrax v3.4.2 Alter abilities for Groups with Roles feature
module Hyrax
module Ability
# rubocop:disable Metrics/ModuleLength
module CollectionAbility
# rubocop:disable Metrics/MethodLength
# rubocop:disable Metrics/BlockLength
# rubocop:disable Metrics/AbcSize
# rubocop:disable Metrics/PerceivedComplexity
# rubocop:disable Metrics/CyclomaticComplexity
def collection_abilities
models = [Hyrax::PcdmCollection, Hyrax.config.collection_class].uniq
if admin?
Expand Down Expand Up @@ -157,6 +160,9 @@ def collection_roles
# rubocop:enable Metrics/MethodLength
# rubocop:enable Metrics/BlockLength
# rubocop:enable Metrics/AbcSize
# rubocop:enable Metrics/PerceivedComplexity
# rubocop:enable Metrics/CyclomaticComplexity
end
# rubocop:enable Metrics/ModuleLength
end
end
2 changes: 2 additions & 0 deletions app/models/concerns/hyrax/ability/solr_document_ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
module Hyrax
module Ability
module SolrDocumentAbility
# rubocop:disable Metrics/MethodLength
def solr_document_abilities
if admin?
can [:manage], ::SolrDocument
Expand All @@ -27,6 +28,7 @@ def solr_document_abilities
end
end
end
# rubocop:enable Metrics/MethodLength
end
end
end
2 changes: 2 additions & 0 deletions app/models/content_block.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

# OVERRIDE Hyrax v3.4.0 to add home_text to registry
# and getter/setter methods - Adding themes
# rubocop:disable Metrics/ClassLength
class ContentBlock < ApplicationRecord
# The keys in this registry are "public" names for collaborator
# objects, and the values are reserved names of ContentBlock
Expand Down Expand Up @@ -159,3 +160,4 @@ def default_terms_text
end
end
end
# rubocop:enable Metrics/ClassLength
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def image_content
image_content_v3(url)
end

# rubocop:disable Metrics/MethodLength
def video_display_content(_url, label = '')
width = solr_document.width&.try(:to_i) || 320
height = solr_document.height&.try(:to_i) || 240
Expand All @@ -55,6 +56,7 @@ def video_display_content(_url, label = '')
format: solr_document.mime_type
)
end
# rubocop:enable Metrics/MethodLength

def audio_display_content(_url, label = '')
duration = conformed_duration_in_seconds
Expand Down
2 changes: 2 additions & 0 deletions app/services/hyrax/collection_types/create_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ def self.create_user_collection_type
# The same values can be retrieved directly from a passed in ability.
# If calling from Abilities, pass the ability.
# If you try to get the ability from the user, you end up in an infinite loop.
# rubocop:disable Metrics/MethodLength
def self.add_default_participants(collection_type_id)
return unless collection_type_id
default_participants = [{ agent_type: Hyrax::CollectionTypeParticipant::GROUP_TYPE,
Expand All @@ -233,6 +234,7 @@ def self.add_default_participants(collection_type_id)
end
add_participants(collection_type_id, default_participants)
end
# rubocop:enable Metrics/MethodLength

##
# @api public
Expand Down
12 changes: 7 additions & 5 deletions app/services/hyrax/workflow/permission_query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def scope_permitted_workflow_actions_available_for_current_state(user:, entity:)
# @param role [Object] that can be converted into a Sipity::Role
# @return [ActiveRecord::Relation<Sipity::Agent>] augmented with
#
def scope_agents_associated_with_entity_and_role(entity:, role:) # rubocop:disable Metrics/AbcSize
def scope_agents_associated_with_entity_and_role(entity:, role:) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
entity = Sipity::Entity(entity)
role = Sipity::Role(role)

Expand Down Expand Up @@ -196,7 +196,7 @@ def scope_processing_agents_for(user:)
#
# @return [ActiveRecord::Relation<Sipity::Entity>]
#
def scope_entities_for_the_user(user:) # rubocop:disable Metrics/AbcSize
def scope_entities_for_the_user(user:) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
entities = Sipity::Entity.arel_table
workflow_state_actions = Sipity::WorkflowStateAction.arel_table
workflow_states = Sipity::WorkflowState.arel_table
Expand Down Expand Up @@ -251,7 +251,7 @@ def scope_entities_for_the_user(user:) # rubocop:disable Metrics/AbcSize
# @param entity an object that can be converted into a Sipity::Entity
# @return [ActiveRecord::Relation<User>]
#
def scope_users_for_entity_and_roles(entity:, roles:) # rubocop:disable Metrics/AbcSize
def scope_users_for_entity_and_roles(entity:, roles:) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
entity = Sipity::Entity(entity)
role_ids = Array.wrap(roles).map { |role| Sipity::Role(role).id }
user_polymorphic_type = ::User.base_class
Expand Down Expand Up @@ -347,7 +347,7 @@ def scope_processing_workflow_roles_for_user_and_workflow(user:, workflow:)
# @param user [User]
# @param entity an object that can be converted into a Sipity::Entity
# @return [ActiveRecord::Relation<Sipity::WorkflowRole>]
def scope_processing_workflow_roles_for_user_and_entity_specific(user:, entity:)
def scope_processing_workflow_roles_for_user_and_entity_specific(user:, entity:) # rubocop:disable Metrics/MethodLength
entity = Sipity::Entity(entity)
agent_scope = scope_processing_agents_for(user: user)

Expand All @@ -366,6 +366,7 @@ def scope_processing_workflow_roles_for_user_and_entity_specific(user:, entity:)
)
)
end
# rubocop:enable Metrics/MethodLength

# @api private
#
Expand All @@ -386,7 +387,7 @@ def scope_processing_workflow_roles_for_user_and_entity_specific(user:, entity:)
# @param entity an object that can be converted into a Sipity::Entity
# @return [ActiveRecord::Relation<Sipity::WorkflowStateAction>]
#
def scope_permitted_entity_workflow_state_actions(user:, entity:)
def scope_permitted_entity_workflow_state_actions(user:, entity:) # rubocop:disable Metrics/MethodLength
entity = Sipity::Entity(entity)
workflow_state_actions = Sipity::WorkflowStateAction
permissions = Sipity::WorkflowStateActionPermission
Expand All @@ -408,6 +409,7 @@ def scope_permitted_entity_workflow_state_actions(user:, entity:)
)
)
end
# rubocop:enable Metrics/MethodLength

# @api public
#
Expand Down
Loading

0 comments on commit 59626ef

Please sign in to comment.