Skip to content

Commit

Permalink
Fix/preflightchecks (#1495)
Browse files Browse the repository at this point in the history
  • Loading branch information
lsat12357 committed Dec 17, 2021
1 parent bc47817 commit cd83626
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 36 deletions.
2 changes: 1 addition & 1 deletion lib/hyrax/migrator/crosswalk_metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def assemble_hash(data, object)
end

def find(predicate)
proc { |k| k[:predicate].casecmp(predicate).zero? }
proc { |k| k[:predicate] == predicate }
end

# Given an OD2 predicate, returns associated property data or nil
Expand Down
2 changes: 1 addition & 1 deletion lib/hyrax/migrator/preflight_checks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def cpds?

def visibility?
result = @results.delete :visibility
@counters[:visibility] += 1 unless result.value? 'open'
@counters[:visibility] += 1 unless result.include? 'open'
return unless result.include? 'error'

concat_errors(result)
Expand Down
32 changes: 1 addition & 31 deletions lib/hyrax/migrator/visibility_lookup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,12 @@
module Hyrax::Migrator
# A class to inspect the metadata and crosswalk the type to a model used for migration
class VisibilityLookup
include Hyrax::Migrator::VisibilityMethods
def lookup_visibility
result = lookup(read_groups)
return result if comparison_check(result)

nil
end

private

# this should provide access to the read_groups metadata
# in preflight, use the item
# in the migrator use the workflow metadata
def read_groups; end

# metadata field on asset.
# in preflight, use descMetadata
# in migrator, use work env attributes
def access_restrictions; end

def lookup(groups)
if groups.include? 'public'
{ visibility: 'open' }
elsif (groups.include? 'University-of-Oregon') || (groups.include? 'Oregon-State')
{ visibility: 'authenticated' }
else
{ visibility: 'restricted' }
end
end

def comparison_check(visibility)
unless access_restrictions.blank?
return true if visibility[:visibility] == 'authenticated'

return false
end
true
end
end
end
6 changes: 3 additions & 3 deletions lib/hyrax/migrator/visibility_lookup_preflight.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ class VisibilityLookupPreflight < Hyrax::Migrator::VisibilityLookup
attr_accessor :work

def lookup_visibility
result = lookup(read_groups)
return 'error: read_groups does not agree with access_restrictions' unless comparison_check(result)
result = super
return result[:visibility] unless result.nil?

result
'error: read_groups does not agree with access_restrictions'
end

private
Expand Down
37 changes: 37 additions & 0 deletions lib/hyrax/migrator/visibility_methods.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# frozen_string_literal:true

module Hyrax::Migrator
# methods for Visibility lookup services
module VisibilityMethods
# this should provide access to the read_groups metadata
# in preflight, use the item
# in the migrator use the workflow metadata
def read_groups; end

# metadata field on asset.
# in preflight, use descMetadata
# in migrator, use work env attributes
def access_restrictions; end

def lookup(groups)
if groups.include? 'public'
{ visibility: 'open' }
elsif groups.include? 'University-of-Oregon'
{ visibility: 'uo' }
elsif groups.include? 'Oregon-State'
{ visibility: 'osu' }
else
{ visibility: 'restricted' }
end
end

def comparison_check(visibility)
unless access_restrictions.blank?
return true if visibility[:visibility] != 'open'

return false
end
true
end
end
end

0 comments on commit cd83626

Please sign in to comment.