diff --git a/.rubocop.yml b/.rubocop.yml index 2f73bd1f0e..f89f1bcc53 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,12 +1,9 @@ inherit_from: - - .rubocop_todo.yml - .rubocop_fixme.yml inherit_gem: bixby: bixby_default.yml - - AllCops: TargetRubyVersion: 2.4 DisplayCopNames: true @@ -21,6 +18,10 @@ Lint/ImplicitStringConcatenation: Exclude: - 'lib/generators/hyrax/**/*' +Rails/Output: + Exclude: + - 'lib/generators/**/*' + Metrics/BlockLength: ExcludedMethods: ['included'] Exclude: diff --git a/.rubocop_fixme.yml b/.rubocop_fixme.yml index 99fb555ace..1bea3fb219 100644 --- a/.rubocop_fixme.yml +++ b/.rubocop_fixme.yml @@ -21,11 +21,6 @@ Metrics/ParameterLists: Exclude: - 'app/jobs/batch_create_job.rb' -Metrics/AbcSize: - Exclude: - - 'app/indexers/hyrax/file_set_indexer.rb' - - 'app/services/hyrax/workflow/permission_query.rb' - Metrics/ModuleLength: Exclude: - 'app/controllers/concerns/hyrax/works_controller_behavior.rb' @@ -36,33 +31,6 @@ Metrics/ModuleLength: # TODO: extract CollectionAccessControls or something, so we don't have to skip this check? - 'app/models/concerns/hyrax/collection_behavior.rb' -Metrics/MethodLength: - Exclude: - - 'app/controllers/concerns/hyrax/api.rb' - - 'app/controllers/concerns/hyrax/works_controller_behavior.rb' - - 'app/indexers/hyrax/file_set_indexer.rb' - - 'app/inputs/multi_value_select_input.rb' - - 'app/models/concerns/hyrax/solr_document/export.rb' - - 'app/services/hyrax/workflow/permission_query.rb' - - 'lib/hyrax/rails/routes.rb' - - 'spec/support/**/*' - - -Naming/PredicateName: - Exclude: - - 'app/helpers/hyrax/collections_helper.rb' - -Style/DateTime: - Enabled: false - -Style/SpecialGlobalVars: - Exclude: - - 'tasks/hyrax_dev.rake' - -Rails/Output: - Exclude: - - 'lib/generators/**/*' - RSpec/NamedSubject: Enabled: false @@ -118,6 +86,7 @@ RSpec/ExampleLength: - 'spec/services/hyrax/workflow/workflow_importer_spec.rb' - 'spec/views/**/*' - 'spec/wings/valkyrie/persister_spec.rb' + RSpec/VerifiedDoubles: Enabled: false @@ -129,6 +98,13 @@ RSpec/SubjectStub: - 'spec/models/hyrax/work_behavior_spec.rb' - 'spec/search_builders/hyrax/file_set_search_builder_spec.rb' - 'spec/models/hyrax/operation_spec.rb' + - 'spec/controllers/hyrax/accepts_batches_controller_spec.rb' + - 'spec/indexers/hyrax/repository_reindexer_spec.rb' + - 'spec/jobs/content_depositor_change_event_job_spec.rb' + - 'spec/lib/hyrax/analytics_spec.rb' + - 'spec/models/job_io_wrapper_spec.rb' + - 'spec/search_builders/hyrax/abstract_type_relation_spec.rb' + - 'spec/services/hyrax/database_migrator_spec.rb' RSpec/AnyInstance: Exclude: @@ -173,3 +149,30 @@ RSpec/ReturnFromStub: - 'spec/views/hyrax/base/file_manager.html.erb_spec.rb' - 'spec/views/hyrax/dashboard/profiles/edit.html.erb_spec.rb' - 'spec/views/hyrax/users/_user_info.html.erb_spec.rb' + +# Offense count: 26 +RSpec/RepeatedDescription: + Exclude: + - 'spec/models/sipity/agent_spec.rb' + - 'spec/models/sipity/comment_spec.rb' + - 'spec/models/sipity/entity_spec.rb' + - 'spec/models/sipity/entity_specific_responsibility_spec.rb' + - 'spec/models/sipity/role_spec.rb' + - 'spec/models/sipity/workflow_action_spec.rb' + - 'spec/models/sipity/workflow_responsibility_spec.rb' + - 'spec/models/sipity/workflow_role_spec.rb' + - 'spec/models/sipity/workflow_state_action_permission_spec.rb' + - 'spec/models/sipity/workflow_state_action_spec.rb' + - 'spec/models/sipity/workflow_state_spec.rb' + +# Offense count: 1 +# Configuration parameters: Include. +# Include: app/models/**/*.rb +Rails/HasManyOrHasOneDependent: + Exclude: + - 'app/models/admin_set.rb' + +# Offense count: 1 +Style/MethodMissingSuper: + Exclude: + - 'app/models/concerns/hyrax/file_set/characterization.rb' diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml deleted file mode 100644 index 29041b2295..0000000000 --- a/.rubocop_todo.yml +++ /dev/null @@ -1,52 +0,0 @@ -# This configuration was generated by -# `rubocop --auto-gen-config` -# on 2020-06-10 10:12:49 -0700 using RuboCop version 0.85.1. -# The point is for the user to remove these configuration records -# one by one as the offenses are removed from the code base. -# Note that changes in the inspected code, or installation of new -# versions of RuboCop, may require this file to be generated again. - -# Offense count: 26 -RSpec/RepeatedDescription: - Exclude: - - 'spec/models/sipity/agent_spec.rb' - - 'spec/models/sipity/comment_spec.rb' - - 'spec/models/sipity/entity_spec.rb' - - 'spec/models/sipity/entity_specific_responsibility_spec.rb' - - 'spec/models/sipity/role_spec.rb' - - 'spec/models/sipity/workflow_action_spec.rb' - - 'spec/models/sipity/workflow_responsibility_spec.rb' - - 'spec/models/sipity/workflow_role_spec.rb' - - 'spec/models/sipity/workflow_state_action_permission_spec.rb' - - 'spec/models/sipity/workflow_state_action_spec.rb' - - 'spec/models/sipity/workflow_state_spec.rb' - -# Offense count: 17 -RSpec/SubjectStub: - Enabled: false # for semo reason excluding these files individually - # doesn't work? RuboCop bug? - # - 'spec/actors/hyrax/actors/generic_work_actor_spec.rb' - # - 'spec/controllers/hyrax/file_sets_controller_spec.rb' - # - 'spec/models/file_set_spec.rb' - # - 'spec/models/hyrax/work_behavior_spec.rb' - # - 'spec/search_builders/hyrax/file_set_search_builder_spec.rb' - # - 'spec/models/hyrax/operation_spec.rb' - # - 'spec/controllers/hyrax/accepts_batches_controller_spec.rb' - # - 'spec/indexers/hyrax/repository_reindexer_spec.rb' - # - 'spec/jobs/content_depositor_change_event_job_spec.rb' - # - 'spec/lib/hyrax/analytics_spec.rb' - # - 'spec/models/job_io_wrapper_spec.rb' - # - 'spec/search_builders/hyrax/abstract_type_relation_spec.rb' - # - 'spec/services/hyrax/database_migrator_spec.rb' - -# Offense count: 1 -# Configuration parameters: Include. -# Include: app/models/**/*.rb -Rails/HasManyOrHasOneDependent: - Exclude: - - 'app/models/admin_set.rb' - -# Offense count: 1 -Style/MethodMissingSuper: - Exclude: - - 'app/models/concerns/hyrax/file_set/characterization.rb' diff --git a/app/controllers/concerns/hyrax/api.rb b/app/controllers/concerns/hyrax/api.rb index 19923e9e61..303281358c 100644 --- a/app/controllers/concerns/hyrax/api.rb +++ b/app/controllers/concerns/hyrax/api.rb @@ -1,66 +1,68 @@ module Hyrax module API # Generate appropriate json response for +response_type+ - - def self.generate_response_body(response_type: :success, message: nil, options: {}) - json_body = default_responses[response_type].merge(options) - json_body[:description] = message if message - json_body - end - - # Default (json) responses for various response types - def self.default_responses + DEFAULT_RESPONSES = { success: { code: 200, message: "Request Succeeded", description: I18n.t('hyrax.api.success.default') - }, + }.freeze, deleted: { code: 200, message: I18n.t('hyrax.api.deleted.default') - }, + }.freeze, created: { code: 201, message: "Created the Resource" - }, + }.freeze, accepted: { code: 202, message: "Accepted", description: I18n.t('hyrax.api.accepted.default') - }, + }.freeze, bad_request: { code: 400, message: "Bad Request", description: I18n.t('hyrax.api.bad_request.default') - }, + }.freeze, unauthorized: { code: 401, message: "Authentication Required", description: I18n.t('hyrax.api.unauthorized.default') - }, + }.freeze, forbidden: { code: 403, message: "Not Authorized", description: I18n.t('hyrax.api.forbidden.default') - }, + }.freeze, not_found: { code: 404, message: "Resource not found", description: I18n.t('hyrax.api.not_found.default') - }, + }.freeze, unprocessable_entity: { code: 422, message: "Unprocessable Entity", description: I18n.t('hyrax.api.unprocessable_entity.default'), errors: {} - }, + }.freeze, internal_error: { code: 500, message: "Internal Server Error", description: I18n.t('hyrax.api.internal_error.default') - } - } + }.freeze + }.freeze + + def self.generate_response_body(response_type: :success, message: nil, options: {}) + json_body = default_responses[response_type].merge(options) + json_body[:description] = message if message + json_body + end + + # Default (json) responses for various response types + def self.default_responses + DEFAULT_RESPONSES end end end diff --git a/app/controllers/concerns/hyrax/works_controller_behavior.rb b/app/controllers/concerns/hyrax/works_controller_behavior.rb index 8aff599c84..1fcdcd45c7 100644 --- a/app/controllers/concerns/hyrax/works_controller_behavior.rb +++ b/app/controllers/concerns/hyrax/works_controller_behavior.rb @@ -78,15 +78,9 @@ def show render :show, status: :ok end additional_response_formats(wants) - wants.ttl do - render body: presenter.export_as_ttl, mime_type: Mime[:ttl] - end - wants.jsonld do - render body: presenter.export_as_jsonld, mime_type: Mime[:jsonld] - end - wants.nt do - render body: presenter.export_as_nt, mime_type: Mime[:nt] - end + wants.ttl { render body: presenter.export_as_ttl, mime_type: Mime[:ttl] } + wants.jsonld { render body: presenter.export_as_jsonld, mime_type: Mime[:jsonld] } + wants.nt { render body: presenter.export_as_nt, mime_type: Mime[:nt] } end end @@ -231,19 +225,11 @@ def render_unavailable flash[:notice] = message render 'unavailable', status: :unauthorized end - wants.json do - render plain: message, status: :unauthorized - end + wants.json { render plain: message, status: :unauthorized } additional_response_formats(wants) - wants.ttl do - render plain: message, status: :unauthorized - end - wants.jsonld do - render plain: message, status: :unauthorized - end - wants.nt do - render plain: message, status: :unauthorized - end + wants.ttl { render plain: message, status: :unauthorized } + wants.jsonld { render plain: message, status: :unauthorized } + wants.nt { render plain: message, status: :unauthorized } end end @@ -261,8 +247,12 @@ def decide_layout File.join(theme, layout) end + ## + # @todo should the controller know so much about browse_everything? + # hopefully this can be refactored to be more reusable. + # # Add uploaded_files to the parameters received by the actor. - def attributes_for_actor + def attributes_for_actor # rubocop:disable Metrics/MethodLength raw_params = params[hash_key_for_curation_concern] attributes = if raw_params work_form_service.form_class(curation_concern).model_attributes(raw_params) diff --git a/app/helpers/hyrax/collections_helper.rb b/app/helpers/hyrax/collections_helper.rb index 24c318cf4f..93e723d639 100644 --- a/app/helpers/hyrax/collections_helper.rb +++ b/app/helpers/hyrax/collections_helper.rb @@ -50,11 +50,20 @@ def append_collection_type_url(url, collection_type_id) uri.to_s end + ## # @return [Boolean] - def has_collection_search_parameters? + def collection_search_parameters? params[:cq].present? end + ## + # @deprecated + # @return [Boolean] + def has_collection_search_parameters? # rubocop:disable Naming/PredicateName: + Deprecation.warn('use #collection_search_parameters? helper instead') + collection_search_parameters? + end + def button_for_remove_from_collection(collection, document, label: 'Remove From Collection', btn_class: 'btn-primary') render 'hyrax/dashboard/collections/button_remove_from_collection', collection: collection, label: label, document: document, btn_class: btn_class end diff --git a/app/indexers/hyrax/file_set_indexer.rb b/app/indexers/hyrax/file_set_indexer.rb index 1401e32810..c31b801230 100644 --- a/app/indexers/hyrax/file_set_indexer.rb +++ b/app/indexers/hyrax/file_set_indexer.rb @@ -4,7 +4,7 @@ class FileSetIndexer < ActiveFedora::IndexingService include Hyrax::IndexesBasicMetadata STORED_LONG = ActiveFedora::Indexing::Descriptor.new(:long, :stored) - def generate_solr_document + def generate_solr_document # rubocop:disable Metrics/AbcSize, Metrics/MethodLength super.tap do |solr_doc| solr_doc['hasRelatedMediaFragment_ssim'] = object.representative_id solr_doc['hasRelatedImage_ssim'] = object.thumbnail_id diff --git a/app/inputs/multi_value_select_input.rb b/app/inputs/multi_value_select_input.rb index f598557984..3998358d32 100644 --- a/app/inputs/multi_value_select_input.rb +++ b/app/inputs/multi_value_select_input.rb @@ -14,7 +14,7 @@ def select_options end end - def build_field_options(value) + def build_field_options(value) # rubocop:disable Metrics/MethodLength (builder method) field_options = input_html_options.dup field_options[:value] = value diff --git a/app/models/concerns/hyrax/solr_document/export.rb b/app/models/concerns/hyrax/solr_document/export.rb index 6be60aea5a..0531557c7f 100644 --- a/app/models/concerns/hyrax/solr_document/export.rb +++ b/app/models/concerns/hyrax/solr_document/export.rb @@ -1,10 +1,28 @@ module Hyrax module SolrDocument module Export + END_NOTE_MAPPINGS = + { '%T' => [:title], + '%A' => [:creator], + '%C' => [:publication_place], + '%D' => [:date_created], + '%8' => [:date_uploaded], + '%E' => [:contributor], + '%I' => [:publisher], + '%J' => [:series_title], + '%@' => [:isbn], + '%U' => [:related_url], + '%7' => [:edition_statement], + '%R' => [:persistent_url], + '%X' => [:description], + '%G' => [:language], + '%[' => [:date_modified], + '%9' => [:resource_type] }.freeze + # MIME: 'application/x-endnote-refer' def export_as_endnote - text = [] - text << "%0 #{human_readable_type}" + text = ["%0 #{human_readable_type}"] + end_note_format.each do |endnote_key, mapping| if mapping.is_a? String values = [mapping] @@ -17,6 +35,7 @@ def export_as_endnote spaced_values = values.join("; ") text << "#{endnote_key} #{spaced_values}" end + text.join("\n") end @@ -31,27 +50,8 @@ def persistent_url end def end_note_format - { - '%T' => [:title], - # '%Q' => [:title, ->(x) { x.drop(1) }], # subtitles - '%A' => [:creator], - '%C' => [:publication_place], - '%D' => [:date_created], - '%8' => [:date_uploaded], - '%E' => [:contributor], - '%I' => [:publisher], - '%J' => [:series_title], - '%@' => [:isbn], - '%U' => [:related_url], - '%7' => [:edition_statement], - '%R' => [:persistent_url], - '%X' => [:description], - '%G' => [:language], - '%[' => [:date_modified], - '%9' => [:resource_type], - '%~' => I18n.t('hyrax.product_name'), - '%W' => Institution.name - } + END_NOTE_MAPPINGS.merge({ '%~' => I18n.t('hyrax.product_name'), + '%W' => Institution.name }) end end end diff --git a/app/services/hyrax/workflow/permission_query.rb b/app/services/hyrax/workflow/permission_query.rb index e75c9f2296..daf67d6c71 100644 --- a/app/services/hyrax/workflow/permission_query.rb +++ b/app/services/hyrax/workflow/permission_query.rb @@ -17,6 +17,8 @@ module Workflow # as understood as of the commit that has the @api tag. However, these are # public methods because they have been tested in isolation and are used # to help compose the `@api public` methods. + # + # @todo Refactor the large ABC methods in this module. module PermissionQuery module_function @@ -65,6 +67,8 @@ def scope_permitted_workflow_actions_available_for_current_state(user:, entity:) # @param entity [Object] that can be converted into a Sipity::Entity # @param role [Object] that can be converted into a Sipity::Role # @return [ActiveRecord::Relation] augmented with + # + # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/MethodLength def scope_agents_associated_with_entity_and_role(entity:, role:) entity = Sipity::Entity(entity) role = Sipity::Role(role) @@ -119,6 +123,7 @@ def scope_agents_associated_with_entity_and_role(entity:, role:) # name of the model that I'm using. Sipity::Agent.from(agents.create_table_alias(agents_select_manager, agents.table_name)).all end + # rubocop:enable Metrics/AbcSize, Metrics/MethodLength # @api public # @@ -186,6 +191,8 @@ def scope_processing_agents_for(user:) # @param [User] user # # @return [ActiveRecord::Relation] + # + # rubocop:disable Metrics/AbcSize, Metrics/MethodLength def scope_entities_for_the_user(user:) entities = Sipity::Entity.arel_table workflow_state_actions = Sipity::WorkflowStateAction.arel_table @@ -226,6 +233,7 @@ def scope_entities_for_the_user(user:) .or(entities[:id].in(workflow_specific_joins.where(workflow_specific_where))) ) end + # rubocop:enable Metrics/AbcSize, Metrics/MethodLength # @api public # @@ -239,6 +247,8 @@ def scope_entities_for_the_user(user:) # @param roles [Sipity::Role] # @param entity an object that can be converted into a Sipity::Entity # @return [ActiveRecord::Relation] + # + # rubocop:disable Metrics/AbcSize, Metrics/MethodLength def scope_users_for_entity_and_roles(entity:, roles:) entity = Sipity::Entity(entity) role_ids = Array.wrap(roles).map { |role| Sipity::Role(role).id } @@ -275,6 +285,7 @@ def scope_users_for_entity_and_roles(entity:, roles:) ::User.where(user_table[:id].in(sub_query_for_user)) end + # rubocop:enable Metrics/AbcSize, Metrics/MethodLength def user_emails_for_entity_and_roles(entity:, roles:) scope_users_for_entity_and_roles(entity: entity, roles: roles).pluck(:email) @@ -334,7 +345,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] - 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) @@ -372,7 +383,8 @@ def scope_processing_workflow_roles_for_user_and_entity_specific(user:, entity:) # @param user [User] # @param entity an object that can be converted into a Sipity::Entity # @return [ActiveRecord::Relation] - 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 diff --git a/app/views/hyrax/collections/show.html.erb b/app/views/hyrax/collections/show.html.erb index 11d513ad1f..b7903328e5 100644 --- a/app/views/hyrax/collections/show.html.erb +++ b/app/views/hyrax/collections/show.html.erb @@ -69,7 +69,7 @@