to_spotlight 0.2.5 → 0.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 42072bef23a9bedf75316257ef35e762377533a0a47eb9736cc301110760017f
4
- data.tar.gz: 12287d3718e9c835fe4e4de9451cb2320d7618062a4b2335ef81c79da3c23adb
3
+ metadata.gz: '0396d6c1545a7b42c6bc1598868019d0ff55e8a51c423e0657cbcfc6829902bd'
4
+ data.tar.gz: 0eee8724658d6492ef2ae51f4b5ec4462555b1bf448f2f8087e9ae35d0af5603
5
5
  SHA512:
6
- metadata.gz: d5b1cbeb353243a6bcdf333feaeee88c5e83a07973cef77c3b4c2bc9fcee5e97df779ee2fbe85a570163158dec377aff2a588dc105a2beba5ae89ad5a2328b5c
7
- data.tar.gz: edd17d9bc9b12b183f77320ae504953d8c753b3f6c0bffed75c79d0268067028effe8936bd3a8b3b1f43c3d498930b041f585970766ad37bfc835e34ccb4333d
6
+ metadata.gz: b74723ef303d5eaea2c5ca9953a88a88679048d1fdea86f759768b9bcf274a1c1ae35a55ca7625549767c018ff66ba18a856441ac057d2c133f52e845e885b4d
7
+ data.tar.gz: 0c41425fae0466f948a186426f732952308396fdbe572aef830a61bbffe7025c75ad1a736e30f8f3f1cdaa8ad45cbaa3464af020271f6af80052a88f50e7caeb
@@ -1,12 +1,12 @@
1
1
  module ToSpotlight
2
2
  class SpotlightTransferController < ApplicationController
3
3
  protect_from_forgery with: :exception
4
- before_action :authenticate_user!
4
+ before_action :authenticate_user!, except: [:api, :receive]
5
5
  skip_before_action :verify_authenticity_token, only: :receive
6
6
  helper_method :default_page_title, :admin_host?, :available_translations, :available_works
7
7
  include ActionView::Helpers::UrlHelper
8
8
  layout 'hyrax/dashboard' if Hyrax
9
- before_action :authenticate, except: :index
9
+ before_action :authenticate, except: [:index, :api, :receive]
10
10
  require 'json'
11
11
  require 'net/http'
12
12
 
@@ -26,7 +26,7 @@ module ToSpotlight
26
26
 
27
27
  def receive
28
28
  return unless params[:token] == token
29
- @transfer = ToSpotlight::SpotlightTransfer.new get_transfer_attributes
29
+ @transfer = ToSpotlight::SpotlightTransfer.new get_transfer_attributes
30
30
  @transfer.mappings = params[:mappings]
31
31
  if @transfer.save
32
32
  render plain: 'Transfer Request Received'
@@ -40,9 +40,9 @@ module ToSpotlight
40
40
  end
41
41
 
42
42
  def approve
43
- now = params[:commit].downcase.include?('now')
43
+ now = params[:commit].downcase.include?('now')
44
44
  transfer = ToSpotlight::SpotlightTransfer.find params[:transfer_id]
45
- works = ::ActiveFedora::Base.where member_of_collection_ids_ssim: transfer.collection_id
45
+ works = ::ActiveFedora::Base.where member_of_collection_ids_ssim: transfer.collection_id
46
46
  mappings = mapping_invert transfer.mappings
47
47
  if now
48
48
  SpotlightTransferJob.perform_later(works.to_a, mappings, transfer)
@@ -50,7 +50,7 @@ module ToSpotlight
50
50
  SpotlightTransferJob.set(wait_until: Date.today.end_of_day)
51
51
  .perform_later(works.to_a, mappings, transfer)
52
52
  end
53
-
53
+ redirect_to spotlight_transfer_index_path
54
54
  end
55
55
 
56
56
  private
@@ -61,7 +61,7 @@ module ToSpotlight
61
61
 
62
62
  def mapping_invert(hash)
63
63
  result = []
64
- test = hash.map { |h| {h['hyrax'] => h['spotlight'].values} }
64
+ test = hash.map { |h| { h['hyrax'] => h['spotlight'].values } }
65
65
  test.reduce({}, :merge).map { |k, v| v.map { |val| [val, k] } }.each { |a| a.each { |a2| result << a2 } }
66
66
  Hash[result]
67
67
  end
@@ -75,31 +75,21 @@ module ToSpotlight
75
75
  end
76
76
 
77
77
  def curated_fields
78
- {"common_fields" => (work_fields - excluded_fields - field_differences), "differences" => field_differences}
78
+ {
79
+ common_fields: (work_fields - excluded_fields - field_differences),
80
+ differences: field_differences
81
+ }
79
82
  end
80
83
 
81
84
  def work_fields
82
- curated_works.map { |work| work.constantize.new.attributes.keys }.flatten.uniq
83
- #%w[id head tail depositor title date_uploaded date_modified state
84
- # proxy_depositor on_behalf_of arkivo_checksum owner alternative_title
85
- # edition geographic_coverage coordinates chronological_coverage extent
86
- # additional_physical_characteristics has_format physical_repository
87
- # collection provenance provider sponsor genre format
88
- # archival_item_identifier fonds_title fonds_creator fonds_description
89
- # fonds_identifier is_referenced_by date_digitized transcript
90
- # technical_note year label relative_path import_url creator part_of
91
- # resource_type contributor description keyword license rights_statement
92
- # publisher date_created subject language identifier based_near
93
- # related_url bibliographic_citation source access_control_id
94
- # representative_id thumbnail_id rendering_ids admin_set_id
95
- # embargo_id lease_id]
85
+ @work_fields ||= curated_works.map { |work| work.constantize.new.attributes.keys }.flatten.uniq
96
86
  end
97
87
 
98
88
  def excluded_fields
99
89
  %w[id title head tail state proxy_depositor on_behalf_of arkivo_checksum label
100
- relative_path import_url part_of resource_type access_control_id
101
- representative_id thumbnail_id rendering_ids admin_set_id embargo_id
102
- lease_id]
90
+ relative_path import_url part_of resource_type access_control_id
91
+ representative_id thumbnail_id rendering_ids admin_set_id embargo_id
92
+ lease_id]
103
93
  end
104
94
 
105
95
  def field_differences
@@ -117,7 +107,7 @@ module ToSpotlight
117
107
  end
118
108
 
119
109
  def intersect a_of_a
120
- eval a_of_a.map{|a| a.inspect}.join(' & ')
110
+ eval a_of_a.map { |a| a.inspect }.join(' & ')
121
111
  end
122
112
 
123
113
  def get_transfer_attributes
@@ -127,7 +117,7 @@ module ToSpotlight
127
117
  :spotlight_url)
128
118
  end
129
119
 
130
- #helpers
120
+ #helpers
131
121
  def available_works
132
122
  @available_works ||= Hyrax::QuickClassificationQuery.new(current_user).authorized_models
133
123
  end
@@ -142,8 +132,8 @@ module ToSpotlight
142
132
 
143
133
  def available_translations
144
134
  {
145
- 'en' => 'English',
146
- 'fr' => 'French'
135
+ 'en' => 'English',
136
+ 'fr' => 'French'
147
137
  }
148
138
  end
149
139
  end
@@ -3,9 +3,9 @@ module ToSpotlight
3
3
  queue_as :default
4
4
 
5
5
  def perform(works, mappings, transfer)
6
- base_url = ::Account.where(tenant: Apartment::Tenant.current).first.cname
6
+ base_url = ::Account.where(tenant: Apartment::Tenant.current).first.cname
7
7
  csv_headers = %w[url full_title_tesim] + mappings.keys + %w[children]
8
- csv_array = [csv_headers.join(',')]
8
+ csv_array = [csv_headers.join(',')]
9
9
  #items = []
10
10
  works.each do |wk|
11
11
  #if comp
@@ -16,7 +16,7 @@ module ToSpotlight
16
16
  # next if wk.file_set_ids.length>1
17
17
  #end
18
18
  #index += 1
19
- comp = false #wk.file_set_ids.length > 1
19
+ comp = false #wk.file_set_ids.length > 1
20
20
  children = []
21
21
  if comp
22
22
  index = wk.ordered_file_set_ids.length * -1
@@ -29,8 +29,8 @@ module ToSpotlight
29
29
 
30
30
  doc = ::SolrDocument.find wk.id
31
31
 
32
- line_hash = {}
33
- line_hash['url'] = "http://#{base_url}/concern/#{underscore_name(wk)}/#{wk.id}/manifest.json" #url
32
+ line_hash = {}
33
+ line_hash['url'] = "http://#{base_url}/concern/#{underscore_name(wk)}/#{wk.id}/manifest.json" #url
34
34
  line_hash['full_title_tesim'] = (doc.title.length > 1 ? doc.title.join('; ') : doc.title.first) #full_title_tesim
35
35
 
36
36
  mappings.each do |skey, field|
@@ -39,30 +39,30 @@ module ToSpotlight
39
39
 
40
40
  line_hash['children'] = children.join('|')
41
41
 
42
- csv_array << line_hash.values_at(*csv_headers).map { |cell| cell = '' if cell.nil?; "\"#{cell.gsub("\"","\"\"")}\"" }.join(',')
42
+ csv_array << line_hash.values_at(*csv_headers).map { |cell| cell = '' if cell.nil?; "\"#{cell.gsub("\"", "\"\"")}\"" }.join(',')
43
43
 
44
44
  end
45
45
 
46
46
  dir = Rails.root.join('public', 'uploads', 'csvs')
47
47
  Dir.mkdir(dir) unless Dir.exist?(dir)
48
- time = DateTime.now.strftime('%s')
48
+ time = DateTime.now.strftime('%s')
49
49
  filename = "spotlight_export-#{time}.csv"
50
50
  File.open(dir.join(filename), 'wb') do |file|
51
51
  file.write(csv_array.join("\n"))
52
52
  end
53
53
  res = post_response URI("#{transfer.spotlight_url}/from_hyrax/receive"),
54
- csv_url: "https://#{base_url}/uploads/csvs/#{filename}",
55
- transfer: transfer.attributes.slice(:user, :exhibit), #only allow user+exhibit
56
- token: 'secret_token'
54
+ csv_url: "https://#{base_url}/uploads/csvs/#{filename}",
55
+ transfer: transfer.attributes.slice(:user, :exhibit), #only allow user+exhibit
56
+ token: 'secret_token'
57
57
 
58
58
  end
59
59
 
60
- def post_response uri, options={}
61
- http = Net::HTTP.new(uri.host, uri.port)
62
- http.use_ssl = true
60
+ def post_response uri, options = {}
61
+ http = Net::HTTP.new(uri.host, uri.port)
62
+ http.use_ssl = true
63
63
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE
64
- request = Net::HTTP::Post.new(uri.request_uri, 'Content-Type' => 'application/json')
65
- request.body = options.to_json
64
+ request = Net::HTTP::Post.new(uri.request_uri, 'Content-Type' => 'application/json')
65
+ request.body = options.to_json
66
66
  http.request(request)
67
67
  end
68
68
 
@@ -9,7 +9,7 @@
9
9
  </thead>
10
10
  <tbody>
11
11
  <% transfers.each do |transfer| %>
12
- <%= render 'list_transfers', transfer: transfer %>
12
+ <%= render 'list_transfers', transfer: transfer %>
13
13
  <% end %>
14
14
  </tbody>
15
15
  </table>
@@ -7,10 +7,10 @@
7
7
  <td><%= transfer.collection_title %></td>
8
8
 
9
9
  <td>
10
- <%= form_tag to_spotlight.approve_path, method: :post, class: "form-inline" do %>
10
+ <%= form_tag main_app.to_spotlight_approve_path, method: :post, class: "form-inline" do %>
11
11
  <%= hidden_field_tag 'transfer_id', transfer.id %>
12
12
  <%= submit_tag "Run Tonight", class: 'btn btn-primary' %>
13
- <% end %><%= form_tag to_spotlight.approve_path, method: :post, class: "form-inline" do %>
13
+ <% end %><%= form_tag main_app.to_spotlight_approve_path, method: :post, class: "form-inline" do %>
14
14
  <%= hidden_field_tag 'transfer_id', transfer.id %>
15
15
  <%= submit_tag "Run Now", class: 'btn btn-primary' %>
16
16
  <% end %>
@@ -1,4 +1,4 @@
1
- <% # container for all batches in index view -%>
1
+ <% # container for all batches in index view -%>
2
2
  <div class="table-responsive" id="transfers">
3
3
  <%= render 'default_group', transfers: @transfers %>
4
4
  </div>
data/config/routes.rb CHANGED
@@ -1,6 +1,6 @@
1
- ToSpotlight::Engine.routes.draw do
2
- get 'api/:request_type' => 'spotlight_transfer#api'
3
- post 'receive' => 'spotlight_transfer#receive'
4
- get 'index' => 'spotlight_transfer#index'
5
- post 'approve' => 'spotlight_transfer#approve'
1
+ Rails.application.routes.draw do
2
+ get '/to_spotlight/api/:request_type' => 'to_spotlight/spotlight_transfer#api', as: 'to_spotlight_api'
3
+ post '/to_spotlight/receive' => 'to_spotlight/spotlight_transfer#receive'
4
+ get '/to_spotlight' => 'to_spotlight/spotlight_transfer#index'
5
+ post '/to_spotlight/approve' => 'to_spotlight/spotlight_transfer#approve'
6
6
  end
@@ -3,10 +3,26 @@ module ToSpotlight
3
3
  isolate_namespace ToSpotlight
4
4
  initializer :append_migrations do |app|
5
5
  unless app.root.to_s.match root.to_s
6
- config.paths["db/migrate"].expanded.each do |expanded_path|
7
- app.config.paths["db/migrate"] << expanded_path
6
+ config.paths['db/migrate'].expanded.each do |expanded_path|
7
+ app.config.paths['db/migrate'] << expanded_path
8
8
  end
9
9
  end
10
10
  end
11
+
12
+ class << self
13
+
14
+ def config
15
+ file = File.open(File.join(::Rails.root, '/config/from_hyrax.yml'))
16
+ @config ||= YAML.safe_load(file)
17
+ end
18
+
19
+ # loads a yml file with the configuration options
20
+ #
21
+ # @param file [String] path to the yml file
22
+ #
23
+ def load_config(file)
24
+ @config = YAML.load_file(file)
25
+ end
26
+ end
11
27
  end
12
28
  end
@@ -1,3 +1,3 @@
1
1
  module ToSpotlight
2
- VERSION = '0.2.5'.freeze
2
+ VERSION = '0.2.6'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: to_spotlight
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - sephirothkod
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-05 00:00:00.000000000 Z
11
+ date: 2020-05-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -64,12 +64,9 @@ files:
64
64
  - app/views/to_spotlight/spotlight_transfer/_default_group.html.erb
65
65
  - app/views/to_spotlight/spotlight_transfer/_list_transfers.html.erb
66
66
  - app/views/to_spotlight/spotlight_transfer/_select.html.erb
67
- - app/views/to_spotlight/spotlight_transfer/_tabs.html.erb
68
67
  - app/views/to_spotlight/spotlight_transfer/_transfers_list.html.erb
69
- - app/views/to_spotlight/spotlight_transfer/approve.html.erb
70
68
  - app/views/to_spotlight/spotlight_transfer/index.html.erb
71
69
  - app/views/to_spotlight/spotlight_transfer/receive.html.erb
72
- - config/application.rb
73
70
  - config/routes.rb
74
71
  - db/migrate/20200310153953_create_to_spotlight_spotlight_transfers.rb
75
72
  - lib/generators/install/install_generator.rb
@@ -1,5 +0,0 @@
1
- <ul class="nav nav-tabs" id="my_nav" role="navigation">
2
- <li<%= ' class="active"'.html_safe %>>
3
- <%= link_to "All CSV Batches", to_spotlight.index_path %>
4
- </li>
5
- </ul>
@@ -1,5 +0,0 @@
1
- <%= params.inspect %>
2
-
3
- <br/>
4
-
5
- <%#= @res.body %>
@@ -1,10 +0,0 @@
1
- module ToSpotlight
2
- class Application < Rails::Application
3
- config.middleware.insert_before 0, Rack::Cors do
4
- allow do
5
- origins '*'
6
- resource '/to_spotlight/api/*', headers: :any, methods: %i[get post options]
7
- end
8
- end
9
- end
10
- end