Skip to content

Commit

Permalink
sure thing rubocop fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
orangewolf committed Oct 1, 2023
1 parent 62942ab commit 415c9ca
Show file tree
Hide file tree
Showing 34 changed files with 214 additions and 182 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/build-test-lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ jobs:
confdir: '/app/samvera/hyrax-webapp/solr/conf'
webTarget: hyku-web
workerTarget: hyku-worker
rspec_cmd: "cd .. && gem install semaphore_test_boosters && rspec_booster --job $CI_NODE_INDEX/$CI_NODE_TOTAL"

lint:
needs: build
uses: scientist-softserv/actions/.github/workflows/[email protected]
with:
webTarget: hyku-web
workerTarget: hyku-worker
rubocop_cmd: "docker-compose run web sh -l -c 'cd .. && bundle exec rubocop --parallel --format progress'"
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

Expand Down
182 changes: 91 additions & 91 deletions app/actors/hyrax/actors/collections_membership_actor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,103 +30,103 @@ def update(env)

private

##
# Attaches any unattached members. Deletes those that are marked _delete
#
# @param env [Hyrax::Actors::Enviornment]
# @return [Boolean]
#
# rubocop:disable Metrics/MethodLength
# rubocop:disable Metrics/PerceivedComplexity
# rubocop:disable Metrics/CyclomaticComplexity
def assign_nested_attributes_for_collection(env)
attributes_collection = env.attributes.delete(:member_of_collections_attributes)
return true unless attributes_collection

# OVERRIDE Hyrax 3.5.0 to skip permission checks if importing
return false unless env.importing ||
valid_membership?(env, collection_ids: attributes_collection.map { |_, attributes| attributes['id'] })

attributes_collection = attributes_collection.sort_by { |i, _| i.to_i }.map { |_, attributes| attributes }
# checking for existing works to avoid rewriting/loading works that are already attached
existing_collections = env.curation_concern.member_of_collection_ids
boolean_type_caster = ActiveModel::Type::Boolean.new
attributes_collection.each do |attributes|
next if attributes['id'].blank?
if boolean_type_caster.cast(attributes['_destroy'])
# Likely someone in the UI sought to add the collection, then
# changed their mind and checked the "delete" checkbox and posted
# their update.
next unless existing_collections.include?(attributes['id'])
remove(env.curation_concern, attributes['id'])
else
# Let's not try to add an item already
next if existing_collections.include?(attributes['id'])
add(env, attributes['id'])
##
# Attaches any unattached members. Deletes those that are marked _delete
#
# @param env [Hyrax::Actors::Enviornment]
# @return [Boolean]
#
# rubocop:disable Metrics/MethodLength
# rubocop:disable Metrics/PerceivedComplexity
# rubocop:disable Metrics/CyclomaticComplexity
def assign_nested_attributes_for_collection(env)
attributes_collection = env.attributes.delete(:member_of_collections_attributes)
return true unless attributes_collection

# OVERRIDE Hyrax 3.5.0 to skip permission checks if importing
return false unless env.importing ||
valid_membership?(env, collection_ids: attributes_collection.map { |_, attributes| attributes['id'] })

attributes_collection = attributes_collection.sort_by { |i, _| i.to_i }.map { |_, attributes| attributes }
# checking for existing works to avoid rewriting/loading works that are already attached
existing_collections = env.curation_concern.member_of_collection_ids
boolean_type_caster = ActiveModel::Type::Boolean.new
attributes_collection.each do |attributes|
next if attributes['id'].blank?
if boolean_type_caster.cast(attributes['_destroy'])
# Likely someone in the UI sought to add the collection, then
# changed their mind and checked the "delete" checkbox and posted
# their update.
next unless existing_collections.include?(attributes['id'])
remove(env.curation_concern, attributes['id'])
else
# Let's not try to add an item already
next if existing_collections.include?(attributes['id'])
add(env, attributes['id'])
end
end
true
end
# rubocop:enable Metrics/MethodLength
# rubocop:enable Metrics/PerceivedComplexity
# rubocop:enable Metrics/CyclomaticComplexity

# Adds the item to the ordered members so that it displays in the items
# along side the FileSets on the show page
def add(env, id)
collection = Hyrax.config.collection_class.find(id)
collection.try(:reindex_extent=, Hyrax::Adapters::NestingIndexAdapter::LIMITED_REINDEX)

return unless env.current_ability.can?(:deposit, collection)
env.curation_concern.member_of_collections << collection
end
true
end
# rubocop:enable Metrics/MethodLength
# rubocop:enable Metrics/PerceivedComplexity
# rubocop:enable Metrics/CyclomaticComplexity

# Adds the item to the ordered members so that it displays in the items
# along side the FileSets on the show page
def add(env, id)
collection = Hyrax.config.collection_class.find(id)
collection.try(:reindex_extent=, Hyrax::Adapters::NestingIndexAdapter::LIMITED_REINDEX)

return unless env.current_ability.can?(:deposit, collection)
env.curation_concern.member_of_collections << collection
end

# Remove the object from the members set and the ordered members list
def remove(curation_concern, id)
collection = Hyrax.config.collection_class.find(id)
curation_concern.member_of_collections.delete(collection)
end
# Remove the object from the members set and the ordered members list
def remove(curation_concern, id)
collection = Hyrax.config.collection_class.find(id)
curation_concern.member_of_collections.delete(collection)
end

# Extact a singleton collection id from the collection attributes and save it in env. Later in the actor stack,
# in apply_permission_template_actor.rb, `env.attributes[:collection_id]` will be used to apply the
# permissions of the collection to the created work. With one and only one collection, the work is seen as
# being created directly in that collection. The permissions will not be applied to the work if the collection
# type is configured not to allow that or if the work is being created in more than one collection.
#
# @param env [Hyrax::Actors::Enviornment]
#
# Given an array of collection_attributes when it is size:
# * 0 do not set `env.attributes[:collection_id]`
# * 1 set `env.attributes[:collection_id]` to the one and only one collection
# * 2+ do not set `env.attributes[:collection_id]`
#
# NOTE: Only called from create. All collections are being added as parents of a work. None are being removed.
def extract_collection_id(env)
attributes_collection =
env.attributes.fetch(:member_of_collections_attributes) { nil }

# Determine if the work is being created in one and only one collection.
return unless attributes_collection && attributes_collection.size == 1

# Extract the collection id from attributes_collection,
collection_id = attributes_collection.first.second['id']

# Do not apply permissions to work if collection type is configured not to
collection = Hyrax.config.collection_class.find(collection_id)
return unless collection.share_applies_to_new_works?

# Save the collection id in env for use in apply_permission_template_actor
env.attributes[:collection_id] = collection_id
end
# Extact a singleton collection id from the collection attributes and save it in env. Later in the actor stack,
# in apply_permission_template_actor.rb, `env.attributes[:collection_id]` will be used to apply the
# permissions of the collection to the created work. With one and only one collection, the work is seen as
# being created directly in that collection. The permissions will not be applied to the work if the collection
# type is configured not to allow that or if the work is being created in more than one collection.
#
# @param env [Hyrax::Actors::Enviornment]
#
# Given an array of collection_attributes when it is size:
# * 0 do not set `env.attributes[:collection_id]`
# * 1 set `env.attributes[:collection_id]` to the one and only one collection
# * 2+ do not set `env.attributes[:collection_id]`
#
# NOTE: Only called from create. All collections are being added as parents of a work. None are being removed.
def extract_collection_id(env)
attributes_collection =
env.attributes.fetch(:member_of_collections_attributes) { nil }

# Determine if the work is being created in one and only one collection.
return unless attributes_collection && attributes_collection.size == 1

# Extract the collection id from attributes_collection,
collection_id = attributes_collection.first.second['id']

# Do not apply permissions to work if collection type is configured not to
collection = Hyrax.config.collection_class.find(collection_id)
return unless collection.share_applies_to_new_works?

# Save the collection id in env for use in apply_permission_template_actor
env.attributes[:collection_id] = collection_id
end

def valid_membership?(env, collection_ids:)
multiple_memberships = Hyrax::MultipleMembershipChecker.new(item: env.curation_concern).check(collection_ids: collection_ids)
if multiple_memberships
env.curation_concern.errors.add(:collections, multiple_memberships)
return false
def valid_membership?(env, collection_ids:)
multiple_memberships = Hyrax::MultipleMembershipChecker.new(item: env.curation_concern).check(collection_ids: collection_ids)
if multiple_memberships
env.curation_concern.errors.add(:collections, multiple_memberships)
return false
end
true
end
true
end
end
end
end
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# OVERRIDE Hyrax 3.6 to add custom default thumbnails

module Hyrax
Expand All @@ -24,7 +26,7 @@ def attach!
true
end

def create_file_from_url(uri, file_name, auth_header, default_thumbnail = nil)
def create_file_from_url(uri, file_name, auth_header, override_default_thumbnail = nil)
import_url = URI.decode_www_form_component(uri.to_s)
use_valkyrie = false
case curation_concern
Expand All @@ -37,7 +39,6 @@ def create_file_from_url(uri, file_name, auth_header, default_thumbnail = nil)
end
__create_file_from_url(file_set: file_set, uri: uri, auth_header: auth_header, use_valkyrie: use_valkyrie)
end

end
end
end
Expand Down
4 changes: 3 additions & 1 deletion app/actors/hyrax/actors/file_set_actor.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# OVERRIDE Hyrax 2.9.5 to override default_thumbnail

module Hyrax
Expand Down Expand Up @@ -137,7 +139,7 @@ def wrapper!(file:, relation:)
# @note This is only useful for labeling the file_set, because of the recourse to import_url
def label_for(file)
if file.is_a?(Hyrax::UploadedFile) # filename not present for uncached remote file!
file.uploader.filename.present? ? file.uploader.filename : File.basename(Addressable::URI.unencode(file.file_url))
file.uploader.filename.presence || File.basename(Addressable::URI.unencode(file.file_url))
elsif file.respond_to?(:original_name) # e.g. Hydra::Derivatives::IoDecorator
file.original_name
elsif file_set.import_url.present?
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/hyku_knapsack/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module HykuKnapsack
class ApplicationController < ActionController::Base
end
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/hyku_knapsack/pages_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module HykuKnapsack
class PagesController < ::Hyrax::PagesController
end
Expand Down
5 changes: 2 additions & 3 deletions app/forms/hyrax/forms/admin/appearance_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,11 @@ module AppearanceDecorator
'custom_adl_header_footer_color' => '#CE8C00'
}.freeze


# TODO do we need this adl_header_footer_color?
# TODO: do we need this adl_header_footer_color?
# 'custom_adl_header_footer_color' => '#CE8C00'
# OVERRIDE here to add adventist's custom header & footer
def custom_adl_header_footer_color
block_for('custom_adl_header_footer_color')
block_for('custom_adl_header_footer_color')
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/forms/hyrax/journal_article_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class JournalArticleForm < Hyrax::Forms::WorkForm
self.model_class = JournalArticle

self.terms -= DogBiscuits.config.base_properties
self.terms -= [:alternative_title, :access_right, :rights_notes]
self.terms -= %i[alternative_title access_right rights_notes]
self.terms += DogBiscuits.config.journal_article_properties

# Add any local properties here
Expand Down
4 changes: 3 additions & 1 deletion app/helpers/hyku_knapsack/application_helper.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# frozen_string_literal: true

module HykuKnapsack
module ApplicationHelper
include ::DogBiscuitsHelper
include IiifPrint::IiifPrintHelperBehavior

def video_embed_viewer_display(work_presenter, locals = {})
render video_embed_viewer_display_partial(work_presenter),
locals.merge(presenter: work_presenter)
locals.merge(presenter: work_presenter)
end

def video_embed_viewer_display_partial(work_presenter)
Expand Down
5 changes: 2 additions & 3 deletions app/indexers/app_indexer_decorator.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# frozen_string_literal: true

module AppIndexerDecorator

# rubocop:disable Metrics/AbcSize
def generate_solr_document
super.tap do |solr_doc|
Expand All @@ -14,8 +13,8 @@ def generate_solr_document
solr_doc[ActiveFedora.id_field.to_sym] = object.to_param
solr_doc['source_sim'] = solr_doc['source_tesim']
solr_doc['file_set_text_tsimv'] = child_works_file_sets(object: object).map { |fs| all_text(object: fs) }
.select(&:present?)
.join("\n---------------------------\n")
.select(&:present?)
.join("\n---------------------------\n")

if object.date_created.present?
# rubocop:disable Metrics/LineLength
Expand Down
8 changes: 4 additions & 4 deletions app/indexers/hyrax/file_set_indexer_decorator.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# OVERRIDE Hyrax 3.5.0 to override default_thumbnail and displaying human-readable titles on UV
module Hyrax
module FileSetIndexerDecorator
Expand Down Expand Up @@ -32,11 +34,10 @@ def generate_solr_document
solr_doc['override_default_thumbnail_ssi'] = object.override_default_thumbnail
# OVERRIDE Hyrax 3.5 to index the file set's parent work's title for displaying in the UV
solr_doc['parent_title_tesim'] = human_readable_label_name(object.parent)

end
end

private
private

def digest_from_content
return unless object.original_file
Expand All @@ -57,8 +58,7 @@ def file_format
"#{object.mime_type.split('/').last} (#{object.format_label.join(', ')})"
elsif object.mime_type.present?
object.mime_type.split('/').last
elsif object.format_label.present?
object.format_label
object.format_label.presence
end
end

Expand Down
2 changes: 2 additions & 0 deletions app/jobs/hyku_knapsack/application_job.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module HykuKnapsack
class ApplicationJob < ActiveJob::Base
end
Expand Down
2 changes: 2 additions & 0 deletions app/mailers/hyku_knapsack/application_mailer.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module HykuKnapsack
class ApplicationMailer < ActionMailer::Base
default from: "[email protected]"
Expand Down
7 changes: 3 additions & 4 deletions app/matchers/bulkrax/application_matcher_decorator.rb
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
# frozen_string_literal: true

# TODO look at this in the context of new BULKRAX version
# TODO: look at this in the context of new BULKRAX version
# OVERRIDE Bulkrax 1.0.2 to override default_thumbnail

module Bulkrax
module ApplicationMatcherDecorator

# OVERRIDE Bulkrax 1.0.2 to override default_thumbnail
def process_parse
# New parse methods will need to be added here
parsed_fields = ['remote_files', 'language', 'subject', 'types', 'model', 'resource_type', 'format_original', 'thumbnail_url']
# This accounts for prefixed matchers
parser = parsed_fields.find { |field| to&.include? field }

if @result.is_a?(Array) && self.parsed && self.respond_to?("parse_#{parser}")
if @result.is_a?(Array) && parsed && respond_to?("parse_#{parser}")
@result.each_with_index do |res, index|
@result[index] = send("parse_#{parser}", res.strip)
end
@result.delete(nil)
elsif self.parsed && self.respond_to?("parse_#{parser}")
elsif parsed && respond_to?("parse_#{parser}")
@result = send("parse_#{parser}", @result)
end
end
Expand Down
Loading

0 comments on commit 415c9ca

Please sign in to comment.